forked from Sorok-Dva/ScreenMe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
100 lines (79 loc) · 3.06 KB
/
main.cpp
File metadata and controls
100 lines (79 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <Windows.h>
#include <iostream>
#include <QApplication>
#include <QSystemTrayIcon>
#include <QDesktopServices>
#include <QMenu>
#include <QAction>
#include <include/options_window.h>
#include <include/config_manager.h>
#include "include/login_loader.h"
#include "include/login_server.h"
#include <include/main_window.h>
using namespace std;
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
ConfigManager configManager("resources/config.json");
QSystemTrayIcon trayIcon(QIcon("resources/icon.png"));
QMenu trayMenu;
QAction loginAction("Login to ScreenMe", &trayMenu);
QAction takeScreenshotAction("Take Screenshot", &trayMenu);
QAction takeFullscreenScreenshotAction("Take Fullscreen Screenshot", &trayMenu);
QAction optionsAction("Options", &trayMenu);
QAction exitAction("Exit", &trayMenu);
trayMenu.addAction(&loginAction);
trayMenu.addSeparator();
trayMenu.addAction(&takeScreenshotAction);
trayMenu.addAction(&takeFullscreenScreenshotAction);
trayMenu.addAction(&optionsAction);
trayMenu.addAction(&exitAction);
trayIcon.setContextMenu(&trayMenu);
trayIcon.setToolTip("Press the configured key combination to take a screenshot");
LoginLoader* loginLoader = new LoginLoader();
LoginServer* loginServer = new LoginServer();
QObject::connect(&loginAction, &QAction::triggered, [&]() {
LoginLoader* loader = new LoginLoader();
loader->show();
QDesktopServices::openUrl(QUrl("https://42-media.allods-developers.eu/login"));
});
QObject::connect(&exitAction, &QAction::triggered, &app, &QApplication::quit);
MainWindow mainWindow(&configManager);
mainWindow.hide(); // Ensure the main window is hidden
QObject::connect(&takeScreenshotAction, &QAction::triggered, [&]() {
mainWindow.takeScreenshot();
});
QObject::connect(&takeFullscreenScreenshotAction, &QAction::triggered, [&]() {
mainWindow.takeFullscreenScreenshot();
});
QObject::connect(&optionsAction, &QAction::triggered, [&]() {
OptionsWindow optionsWindow(&configManager);
optionsWindow.exec();
});
QObject::connect(&exitAction, &QAction::triggered, &app, &QApplication::quit);
trayIcon.show();
QObject::connect(&trayIcon, &QSystemTrayIcon::activated, [&](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::Trigger) {
mainWindow.takeScreenshot(); // Take screenshot on left-click
}
});
QObject::connect(&mainWindow, &MainWindow::screenshotClosed, [&]() {
mainWindow.handleScreenshotClosed();
});
/*MSG msg;
while (true)
{
// Wait for messages
if (GetMessage(&msg, nullptr, 0, 0))
{
// Check if the message is for a hotkey
if (msg.message == WM_HOTKEY)
{
std::cout << "Global hotkey pressed!" << std::endl;
}
// Translate and dispatch the message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}*/
return app.exec();
}