forked from easysoft/zenshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starterui.cpp
270 lines (227 loc) · 8.62 KB
/
starterui.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#include "starterui.h"
#include "starter.h"
#include "config/xmlconfig.h"
#include "spdlogwrapper.hpp"
#include "usrmetatype.h"
#include <QMenu>
#include <QDir>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#include <Windowsx.h>
#include <shlobj.h>
#endif // Q_OS_WIN
StarterUI* g_start_ui_;
extern std::string SETTING_XML_NAME;
StarterUI::StarterUI()
: QDialog(0)
, trayIcon(new QSystemTrayIcon(this))
, trayIconMenu(new QMenu(this))
, m_SettingDlg(this)
#if !NZENTAO_VER_
, m_ZTSettingDlg(this)
, m_ZTSubmitDlg(this)
, m_ZTTipsDlg(this)
, m_HttpReq()
, m_CurrentShot(nullptr)
, m_CurrentStarter(nullptr)
, m_CurrentUsr()
, m_CurrentUrl()
, m_LastSubmitUrl()
#endif // NZENTAO_VER_
, m_Shotting(false)
{
g_start_ui_ = this;
qRegisterMetaType<Starter*>("Starter*");
qRegisterMetaType<int32_t>("int32_t");
qRegisterMetaType<uint32_t>("uint32_t");
qRegisterMetaType<string_ptr>("string_ptr");
qRegisterMetaType<Workspace*>("Workspace*");
#if !NZENTAO_VER_
qRegisterMetaType<std::shared_ptr<QPixmap>>("std::shared_ptr<QPixmap>");
qRegisterMetaType<zproduct_item_vec_ptr>("zproduct_item_vec_ptr");
qRegisterMetaType<zmodule_item_vec_ptr>("zmodule_item_vec_ptr");
qRegisterMetaType<zversion_item_vec_ptr>("zversion_item_vec_ptr");
qRegisterMetaType<ztype_item_vec_ptr>("ztype_item_vec_ptr");
qRegisterMetaType<zos_item_vec_ptr>("zos_item_vec_ptr");
qRegisterMetaType<zbrowser_item_vec_ptr>("zbrowser_item_vec_ptr");
qRegisterMetaType<zseverity_item_vec_ptr>("zseverity_item_vec_ptr");
qRegisterMetaType<zpri_item_vec_ptr>("zpri_item_vec_ptr");
#endif // NZENTAO_VER_
createActions();
createTrayIcon();
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
setAttribute(Qt::WA_TranslucentBackground, true);
SetupSignal();
trayIcon->show();
#ifdef Q_OS_WIN
char config_path[MAX_PATH] = { 0 };
if (SHGetSpecialFolderPathA(0, config_path, CSIDL_LOCAL_APPDATA, FALSE)) {
SETTING_XML_NAME = config_path;
SETTING_XML_NAME.append("/ZenShot/");
QDir dir;
if (!dir.exists(SETTING_XML_NAME.c_str())) {
dir.mkdir(SETTING_XML_NAME.c_str());
}
SETTING_XML_NAME.append("setting.xml");
}
#endif // Q_OS_WIN
GetXMLConfig().LoadConfig(SETTING_XML_NAME);
uint32_t value = GetXMLConfig().GetConfigNum2("config", "hotkey");
if (value)
{
emit CheckHotKey(value);
}
resize(0, 0);
hide();
}
StarterUI::~StarterUI()
{
}
void StarterUI::createActions()
{
settingAction = new QAction(tr("S&eeting"), this);
QIcon settingIcon(":/images/menu-setting.png");
settingAction->setIcon(settingIcon);
connect(settingAction, &QAction::triggered, this, &StarterUI::OnShowSetting);
#if !NZENTAO_VER_
zentaoSettingAction = new QAction(tr("Z&enTaoSeeting"), this);
QIcon zentaosettingIcon(":/images/menu-ztsetting.png");
zentaoSettingAction->setIcon(zentaosettingIcon);
connect(zentaoSettingAction, &QAction::triggered, this, &StarterUI::OnShowZenTaoSetting);
#endif // NZENTAO_VER_
shotAction = new QAction(tr("S&hot"), this);
QIcon shotIcon(":/images/menu-shot.png");
shotAction->setIcon(shotIcon);
connect(shotAction, &QAction::triggered, this, &StarterUI::OnStartShot);
quitAction = new QAction(tr("&Quit"), this);
QIcon quitIcon(":/images/menu-exit.png");
quitAction->setIcon(quitIcon);
connect(quitAction, &QAction::triggered, this, &StarterUI::OnExitShot);
}
void StarterUI::createTrayIcon()
{
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(shotAction);
trayIconMenu->addAction(settingAction);
#if !NZENTAO_VER_
trayIconMenu->addAction(zentaoSettingAction);
#endif // NZENTAO_VER_
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/zenshot.png"));
trayIcon->setToolTip(tr("zenshot"));
}
void StarterUI::SetupSignal()
{
connect(this, SIGNAL(SatrtShot()), this, SLOT(OnStartShot()));
connect(this, SIGNAL(CheckHotKey(uint32_t)), &m_SettingDlg, SIGNAL(InitHotKeyValue(uint32_t)));
connect(trayIcon, &QSystemTrayIcon::activated, this, &StarterUI::OnIconActivated);
#if !NZENTAO_VER_
connect(this, SIGNAL(Thumbnail(std::shared_ptr<QPixmap>)), &m_ZTSubmitDlg, SIGNAL(ShowThumbnail(std::shared_ptr<QPixmap>)));
connect(this, SIGNAL(Login(string_ptr, string_ptr, string_ptr)), this, SLOT(OnLogin(string_ptr, string_ptr, string_ptr)));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitLogin(string_ptr)), this, SLOT(OnSubmitLogin(string_ptr)));
connect(this, SIGNAL(SubmitLoginResult(bool)), &m_ZTSubmitDlg, SLOT(OnSubmitLoginResult(bool)));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitReqProduct()), this, SIGNAL(ReqProduct()));
connect(this, SIGNAL(ReqProduct()), this, SLOT(OnHttpProduct()));
connect(this, SIGNAL(ProductItems(zproduct_item_vec_ptr)), &m_ZTSubmitDlg, SLOT(OnSubmitProductItems(zproduct_item_vec_ptr)));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitReqModule(uint32_t, string_ptr)), this, SIGNAL(ReqModule(uint32_t, string_ptr)));
connect(this, SIGNAL(ReqModule(uint32_t, string_ptr)), this, SLOT(OnHttpModule(uint32_t, string_ptr)));
connect(this, SIGNAL(ModuleItems(zmodule_item_vec_ptr)), &m_ZTSubmitDlg, SLOT(OnSubmitModuleItems(zmodule_item_vec_ptr)));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitReqVersion(uint32_t, string_ptr)), this, SIGNAL(ReqVersion(uint32_t, string_ptr)));
connect(this, SIGNAL(ReqVersion(uint32_t, string_ptr)), this, SLOT(OnHttpVersion(uint32_t, string_ptr)));
connect(this, SIGNAL(VersionItems(zversion_item_vec_ptr)), &m_ZTSubmitDlg, SLOT(OnSubmitVersionItems(zversion_item_vec_ptr)));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitReqModules(string_ptr)), this, SIGNAL(ReqModules(string_ptr)));
connect(this, SIGNAL(ReqModules(string_ptr)), this, SLOT(OnHttpModules(string_ptr)));
connect(this, SIGNAL(ModulesItems(zpri_item_vec_ptr, zseverity_item_vec_ptr, zos_item_vec_ptr, zbrowser_item_vec_ptr, ztype_item_vec_ptr)), &m_ZTSubmitDlg, SLOT(OnSubmitModulesItems(zpri_item_vec_ptr, zseverity_item_vec_ptr, zos_item_vec_ptr, zbrowser_item_vec_ptr, ztype_item_vec_ptr)));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitDemandJson(uint32_t, string_ptr)), this, SLOT(OnSubmitDemandJson(uint32_t, string_ptr)));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitBugJson(uint32_t, string_ptr)), this, SLOT(OnSubmitBugJson(uint32_t, string_ptr)));
connect(&m_ZTSubmitDlg, SIGNAL(UploadImage()), this, SLOT(OnUploadImage()));
connect(this, SIGNAL(UploadImageDone(bool, string_ptr)), &m_ZTSubmitDlg, SLOT(OnUploadImageDone(bool, string_ptr)));
connect(&m_ZTTipsDlg, SIGNAL(OpenZentaoUrl()), this, SLOT(OnOpenZentaoUrl()));
connect(&m_ZTSettingDlg, SIGNAL(SettingZentaoHide()), this, SLOT(OnSubmitZentaoHide()));
connect(&m_ZTTipsDlg, SIGNAL(TipsZentaoHide()), this, SLOT(OnTipZentaoHide()));
connect(&m_ZTSubmitDlg, SIGNAL(SubmitZentaoHide()), this, SLOT(OnSubmitZentaoHide()));
#endif // NZENTAO_VER_
}
void StarterUI::OnStartShot()
{
if (m_Shotting)
{
return;
}
L_DEBUG(">>>>>>>>>>>>>>>>>>>>>>>>>> GAME START <<<<<<<<<<<<<<<<<<<<<<<<<<<<");
m_Shotting = true;
Starter* starter = nullptr;
if (m_Starer.empty())
{
starter = new Starter(false);
connect(this, SIGNAL(StopShot(Starter*)), starter, SIGNAL(ShotDone(Starter*)));
connect(starter, SIGNAL(ShotDone(Starter*)), this, SLOT(OnShotDone(Starter*)));
}
else
{
starter = m_Starer.back();
m_Starer.pop_back();
}
#if !NZENTAO_VER_
m_CurrentStarter = starter;
#endif // NZENTAO_VER_
starter->init();
L_TRACE("============= m_Starer size = {0}", m_Starer.size());
}
void StarterUI::OnShotDone(Starter* starter)
{
#if !NZENTAO_VER_
m_CurrentShot = nullptr;
m_CurrentStarter = nullptr;
#endif // NZENTAO_VER_
m_Shotting = false;
starter->cleanup();
m_Starer.push_back(starter);
L_TRACE("!!!!!!!!!!!!! m_Starer size = {0}", m_Starer.size());
L_DEBUG("@@@@@@@@@@@@@@@@@@@@@@@@ GAME END @@@@@@@@@@@@@@@@@@@@@@@@@@@@");
}
void StarterUI::OnExitShot()
{
trayIcon->hide();
QApplication::exit(0);
}
void StarterUI::closeEvent(QCloseEvent*)
{
trayIcon->hide();
QApplication::exit(0);
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool StarterUI::nativeEvent(const QByteArray& eventType, void* message, qintptr* result)
#else
bool StarterUI::nativeEvent(const QByteArray& eventType, void* message, long* result)
#endif
{
#ifdef Q_OS_WIN
MSG* msg = static_cast<MSG*>(message);
if (msg->message == WM_HOTKEY)
{
emit SatrtShot();
}
#endif // Q_OS_WIN
return QDialog::nativeEvent(eventType, message, result);
}
void StarterUI::OnIconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger: /* À´×ÔÓÚµ¥»÷¼¤»î¡£ */
emit SatrtShot();
break;
}
}
void StarterUI::OnShowSetting()
{
if (!m_SettingDlg.isVisible())
{
m_SettingDlg.show();
}
m_SettingDlg.raise();
m_SettingDlg.activateWindow();
}