-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmento.cpp
221 lines (182 loc) · 6.11 KB
/
mento.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
#include "mento.h"
Mento::Mento(QObject *parent) :
QObject(parent)
{
if(CocoaInitialize::DefaultApp()->checkRunning())
{
initsuccess=false;
QMessageBox::warning(0,"Warning","Cocoa Mento 正在运行当中!",QMessageBox::Ok,QMessageBox::Ok);
return;
}
else initsuccess=true;
log=new QTextBrowser();
log->setWindowModality(Qt::WindowModal);
log->setWindowFlags(Qt::WindowStaysOnTopHint|Qt::CustomizeWindowHint|Qt::WindowCloseButtonHint);
log->setGeometry(200,200,400,500);
log->setWindowTitle(tr("认证日志"));
gt=new Guite();
main=new Menu("Cocoa Mento");
sub=new Menu("Settings");
status=new MenuItem("[状态:正常] 未连接");
connectHandle=new MenuItem("开始认证");
settings=new MenuItem("偏好设置");
about=new MenuItem("关于CocoaMento");
aboutQt=new MenuItem("关于Qt");
help=new MenuItem("使用说明");
exit=new MenuItem("退出");
resetsettings=new MenuItem("重置偏好设置");
logs=new MenuItem("显示日志");
cv=new ConfigView();
cvcontainer=new MenuViewItem("Settings",cv);
cv->setPalette(Qt::white);
cv->show();
settings->setSubMenu(sub);
main->addMenuItem(status);
main->addMenuSeparator();
main->addMenuItem(connectHandle);
main->addMenuItem(settings);
main->addMenuItem(resetsettings);
main->addMenuItem(logs);
main->addMenuSeparator();
main->addMenuItem(help);
main->addMenuItem(about);
main->addMenuItem(aboutQt);
main->addMenuSeparator();
main->addMenuItem(exit);
sub->addMenuItem(cvcontainer);
icon=new StatusIcon();
icon->setMenu(main);
icon->showIcon();
mainthread=new MentoThread(cv->Config());
connect((QObject*)exit->port,SIGNAL(trigger()),this,SLOT(quitApp()));
connect((QObject*)resetsettings->port,SIGNAL(trigger()),cv,SLOT(resetConfig()));
connect((QObject*)connectHandle->port,SIGNAL(trigger()),this,SLOT(toggleConnect()));
connect((QObject*)logs->port,SIGNAL(trigger()),log,SLOT(show()));
connect((QObject*)about->port,SIGNAL(trigger()),gt,SLOT(showAbout()));
connect((QObject*)aboutQt->port,SIGNAL(trigger()),this,SLOT(showAboutQt()));
connect((QObject*)help->port,SIGNAL(trigger()),gt,SLOT(showHelp()));
connect(mainthread,SIGNAL(output(QString)),this,SLOT(outputHandle(QString)));
connect(mainthread,SIGNAL(exitSuccess()),this,SLOT(exitHandle()));
connect(mainthread,SIGNAL(statusChanged(QString,int)),this,SLOT(statusHandle(QString,int)));
connect(mainthread,SIGNAL(error(QString)),this,SLOT(errorHandle(QString)));
connect(mainthread,SIGNAL(authError()),this,SLOT(authMento()));
connect(mainthread,SIGNAL(noConfig()),this,SLOT(noconfigHandle()));
connect(mainthread,SIGNAL(notify(QString)),this,SLOT(notifyHandle(QString)));
if(cv->autoConnect()) toggleConnect();
}
void Mento::noconfigHandle()
{
QMessageBox::critical(0,tr("配置信息不全!"),tr("用户名密码、认证使用网卡等信息未设置,连接无法继续。\n请仔细阅读使用说明,对认证信息进行正确配置!"),QMessageBox::Ok,QMessageBox::NoButton);
gt->showHelp();
}
void Mento::exitHandle()
{
CocoaInitialize::growl("CocoaMento","链接已断开");
status->setTitle("[状态:正常] 连接已断开");
connectHandle->setTitle("开始认证");
icon->setIcon("normal.png");
}
void Mento::notifyHandle(QString str)
{
CocoaInitialize::growl("CocoaMento",str.toUtf8().data());
}
void Mento::statusHandle(QString str, int status)
{
if(status==0||status==2){
this->status->setTitle(tr("[状态:正常] %1").arg(str).toUtf8().data());
if(cv->growlStatus()) CocoaInitialize::growl("CocoaMento",str.toUtf8().data());
icon->setIcon((status==2)?"normal.png":"connecting.png");
}
else
{
this->status->setTitle(tr("[状态:警告] %1").arg(str).toUtf8().data());
icon->setIcon("warning.png");
}
}
void Mento::errorHandle(QString detail)
{
mainthread->terminate();
icon->setIcon("critical.png");
QMessageBox::critical(0,tr("错误!"),tr("Mentohust 遇到严重错误,已经终止认证!\n\n错误细节: %1").arg(detail),QMessageBox::Ok,QMessageBox::Ok);
}
void Mento::toggleConnect()
{
if(mainthread->isRunning())
{
mainthread->terminate();
}
else
{
status->setTitle("[状态:正常] 正在链接...");
connectHandle->setTitle("退出认证");
log->setTextColor(Qt::red);
log->setFontItalic(true);
log->append("\n\n");
log->append(QDateTime::currentDateTime().toString());
log->setTextColor(Qt::black);
mainthread->start();
}
}
void Mento::outputHandle(QString str)
{
log->append(str);
qDebug()<<str;
}
void Mento::quitApp()
{
if(mainthread->isRunning())
{
if(QMessageBox::Ok==QMessageBox::warning(
0,
tr("警告"),tr("Mentohust 正在运行,要退出认证么?"),
QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok))
mainthread->terminate();
else return;
}
cv->close();
log->close();
gt->close();
}
bool Mento::initSuccess()
{
return initsuccess;
}
void Mento::authMento()
{
icon->setIcon("warning.png");
mainthread->terminate();
if(CocoaInitialize::auth()==1)mainthread->start();
else
{
icon->setIcon("critical.png");
QMessageBox::warning(0,tr("获取权限失败"),tr("获取权限失败,认证无法继续,请正确授予 Cocoa Mento 系统权限!"));
this->connectHandle->setTitle("开始连接");
icon->setIcon("normal.png");
}
}
void Mento::showAboutQt()
{
QMessageBox::aboutQt(0);
}
Mento::~Mento()
{
if(initsuccess)
{
cv->deleteLater();
mainthread->deleteLater();
gt->deleteLater();
delete logs;
delete main;
delete sub;
delete status;
delete settings;
delete about;
delete aboutQt;
delete help;
delete exit;
delete cvcontainer;
delete icon;
delete resetsettings;
delete connectHandle;
}
}