Skip to content

Commit 36f656a

Browse files
committed
新增 重启客户端 功能,修复 高dpi适配 不好看
1 parent e143476 commit 36f656a

File tree

7 files changed

+80
-43
lines changed

7 files changed

+80
-43
lines changed

DrCOM_JLU_Qt.pro

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ RESOURCES += \
6363
include(singleinstance/singleapplication.pri)
6464
DEFINES += QAPPLICATION_CLASS=QApplication
6565

66-
VERSION = 1.0.0.1
66+
VERSION = 1.0.0.2
67+
68+
# 更新日志:
69+
# v 0.0.0.0 实现基本功能
70+
# v 1.0.0.1 修复适配高DPI时只窗口大小适配但字号不适配的bug
71+
# v 1.0.0.2 增加重启功能(能解决一些网络的错误
72+
# 调整字体为微软雅黑10号(就是win下正常的字体
73+

dogcom.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ void DogCom::run()
9696
break;
9797
}
9898
} else {
99+
// 这个 keepalive_try_counter 在这里貌似没什么用,因为Qt的QUdpSocket有一个state特别敏感
100+
// 明明网线啥的都没问题就说当前是UnconnectedStat状态然后还不给你自动重连
101+
// 所以外层循环先给判断了一下当前状态,如果这玩意报告说掉线了那就直接退出循环发包
102+
// 另: 目前测试还没有遇到过外层state正常然后里边keepalive_try_counter增加计数的情况
99103
if (keepalive_try_counter > 3) {
100104
// 清理操作
101105
emit ReportOffline(OFF_TIMEOUT);

main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "mainwindow.h"
22
#include <singleapplication.h>
33
#include <QTranslator>
4+
#include <QDebug>
45

56
int main(int argc, char *argv[])
67
{
@@ -11,7 +12,8 @@ int main(int argc, char *argv[])
1112
SingleApplication::setQuitOnLastWindowClosed(false);
1213

1314
QFont font=a.font();
14-
font.setPointSize(12);
15+
font.setPointSize(10);
16+
font.setFamily("Microsoft YaHei");
1517
a.setFont(font);
1618

1719
QTranslator translator;
@@ -20,6 +22,7 @@ int main(int argc, char *argv[])
2022

2123
MainWindow w;
2224
QObject::connect(&a,&SingleApplication::instanceStarted,[&w](){
25+
qDebug()<<"One instance had started. Its window will be shown by the next line of the source code.";
2326
w.ShowLoginWindow();
2427
});
2528
w.show();

mainwindow.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QDesktopServices>
1515
#include <QUrl>
1616
#include <QCloseEvent>
17+
#include <QProcess>
1718

1819
MainWindow::MainWindow(QWidget *parent) :
1920
QDialog(parent),
@@ -35,6 +36,10 @@ MainWindow::MainWindow(QWidget *parent) :
3536
}
3637
ui->comboBoxMAC->addItem(CUSTOM_MAC);
3738

39+
// 重启功能
40+
restartAction=new QAction(tr("Re&start"),this);
41+
connect(restartAction,&QAction::triggered,this,&MainWindow::RestartDrcom);
42+
3843
// 创建托盘菜单和图标
3944
// 托盘菜单选项
4045
restoreAction=new QAction(tr("&Restore"),this);
@@ -49,6 +54,7 @@ MainWindow::MainWindow(QWidget *parent) :
4954
trayIconMenu->addSeparator();
5055
trayIconMenu->addAction(logOutAction);
5156
trayIconMenu->addSeparator();
57+
trayIconMenu->addAction(restartAction);
5258
trayIconMenu->addAction(quitAction);
5359
// 新建托盘图标
5460
trayIcon=new QSystemTrayIcon(this);
@@ -67,6 +73,8 @@ MainWindow::MainWindow(QWidget *parent) :
6773
windowMenu->addAction(aboutAction);
6874
windowMenu->addAction(logOutAction);
6975
ui->menuBar->addMenu(windowMenu);
76+
// 重启是个专门的菜单按钮
77+
ui->menuBar->addAction(restartAction);
7078

7179
// 读取配置文件
7280
LoadSettings();
@@ -116,6 +124,13 @@ void MainWindow::ShowLoginWindow(){
116124
}
117125
}
118126

127+
void MainWindow::RestartDrcom()
128+
{
129+
qDebug()<<"Restarting Drcom...";
130+
qApp->quit();
131+
QProcess::startDetached(qApp->arguments()[0],qApp->arguments());
132+
}
133+
119134
void MainWindow::IconActivated(QSystemTrayIcon::ActivationReason reason)
120135
{
121136
switch (reason) {

mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public slots:
3939
void HandleLoggedIn();
4040
void HandleIpAddress(const QString &ip);
4141
void ShowLoginWindow();
42+
void RestartDrcom();
4243

4344
private:
4445
Ui::MainWindow *ui;
@@ -71,6 +72,7 @@ public slots:
7172
void AboutDrcom();
7273

7374
// 托盘图标
75+
QAction *restartAction;
7476
QAction *restoreAction;
7577
QAction *logOutAction;
7678
QAction *quitAction;

ts/DrCOM_zh_CN.qm

65 Bytes
Binary file not shown.

ts/DrCOM_zh_CN.ts

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
</message>
3636
<message>
3737
<location filename="../mainwindow.ui" line="116"/>
38+
<location filename="../mainwindow.cpp" line="291"/>
3839
<source>Login</source>
3940
<translation>登录</translation>
4041
</message>
@@ -45,159 +46,164 @@
4546
</message>
4647
<message>
4748
<location filename="../mainwindow.cpp" line="40"/>
49+
<source>Re&amp;start</source>
50+
<translation>重启客户端(&amp;S)</translation>
51+
</message>
52+
<message>
53+
<location filename="../mainwindow.cpp" line="45"/>
4854
<source>&amp;Restore</source>
4955
<translation>显示窗口(&amp;R)</translation>
5056
</message>
5157
<message>
52-
<location filename="../mainwindow.cpp" line="42"/>
58+
<location filename="../mainwindow.cpp" line="47"/>
5359
<source>&amp;Logout</source>
5460
<translation>注销(&amp;L)</translation>
5561
</message>
5662
<message>
57-
<location filename="../mainwindow.cpp" line="44"/>
63+
<location filename="../mainwindow.cpp" line="49"/>
5864
<source>&amp;Quit</source>
5965
<translation>退出(&amp;Q)</translation>
6066
</message>
6167
<message>
62-
<location filename="../mainwindow.cpp" line="64"/>
68+
<location filename="../mainwindow.cpp" line="70"/>
6369
<source>&amp;About</source>
6470
<translation>关于(&amp;A)</translation>
6571
</message>
6672
<message>
67-
<location filename="../mainwindow.cpp" line="66"/>
73+
<location filename="../mainwindow.cpp" line="72"/>
6874
<source>&amp;Help</source>
6975
<translation>帮助(&amp;H)</translation>
7076
</message>
7177
<message>
72-
<location filename="../mainwindow.cpp" line="210"/>
78+
<location filename="../mainwindow.cpp" line="225"/>
7379
<source>Input can not be empty!</source>
7480
<translation>输入不能为空!</translation>
7581
</message>
7682
<message>
77-
<location filename="../mainwindow.cpp" line="214"/>
83+
<location filename="../mainwindow.cpp" line="229"/>
7884
<source>Illegal MAC address!</source>
7985
<translation>物理地址输入有误!</translation>
8086
</message>
8187
<message>
82-
<location filename="../mainwindow.cpp" line="249"/>
88+
<location filename="../mainwindow.cpp" line="264"/>
8389
<source>DrCOM JLU Qt -- online</source>
8490
<translation>吉大校园网 - 在线</translation>
8591
</message>
8692
<message>
87-
<location filename="../mainwindow.cpp" line="253"/>
93+
<location filename="../mainwindow.cpp" line="268"/>
8894
<source>DrCOM JLU Qt -- offline</source>
8995
<translation>吉大校园网 - 离线</translation>
9096
</message>
9197
<message>
92-
<location filename="../mainwindow.cpp" line="279"/>
98+
<location filename="../mainwindow.cpp" line="294"/>
9399
<source>Logout succeed</source>
94100
<translation>注销成功</translation>
95101
</message>
96102
<message>
97-
<location filename="../mainwindow.cpp" line="283"/>
98-
<location filename="../mainwindow.cpp" line="287"/>
99-
<location filename="../mainwindow.cpp" line="291"/>
100-
<location filename="../mainwindow.cpp" line="295"/>
101-
<location filename="../mainwindow.cpp" line="299"/>
102-
<location filename="../mainwindow.cpp" line="303"/>
103-
<location filename="../mainwindow.cpp" line="307"/>
104-
<location filename="../mainwindow.cpp" line="311"/>
105-
<location filename="../mainwindow.cpp" line="315"/>
106-
<location filename="../mainwindow.cpp" line="319"/>
107-
<location filename="../mainwindow.cpp" line="323"/>
108-
<location filename="../mainwindow.cpp" line="327"/>
109-
<location filename="../mainwindow.cpp" line="331"/>
103+
<location filename="../mainwindow.cpp" line="298"/>
104+
<location filename="../mainwindow.cpp" line="302"/>
105+
<location filename="../mainwindow.cpp" line="306"/>
106+
<location filename="../mainwindow.cpp" line="310"/>
107+
<location filename="../mainwindow.cpp" line="314"/>
108+
<location filename="../mainwindow.cpp" line="318"/>
109+
<location filename="../mainwindow.cpp" line="322"/>
110+
<location filename="../mainwindow.cpp" line="326"/>
111+
<location filename="../mainwindow.cpp" line="330"/>
112+
<location filename="../mainwindow.cpp" line="334"/>
113+
<location filename="../mainwindow.cpp" line="338"/>
114+
<location filename="../mainwindow.cpp" line="342"/>
115+
<location filename="../mainwindow.cpp" line="346"/>
110116
<source>Login failed</source>
111117
<translation>登录失败</translation>
112118
</message>
113119
<message>
114-
<location filename="../mainwindow.cpp" line="283"/>
120+
<location filename="../mainwindow.cpp" line="298"/>
115121
<source>Binding port failed. Please check if there are other clients occupying the port</source>
116122
<translation>绑定端口失败,请检查是否有其他客户端占用了端口</translation>
117123
</message>
118124
<message>
119-
<location filename="../mainwindow.cpp" line="287"/>
125+
<location filename="../mainwindow.cpp" line="302"/>
120126
<source>Challenge failed. Please check your connection:)</source>
121127
<translation>尝试连接服务器失败,请检查你的网络连接:)是不是wifi没连或者网线没插呀</translation>
122128
</message>
123129
<message>
124-
<location filename="../mainwindow.cpp" line="291"/>
130+
<location filename="../mainwindow.cpp" line="306"/>
125131
<source>Someone is using this account with wired</source>
126132
<translation>有人正在用这个账号</translation>
127133
</message>
128134
<message>
129-
<location filename="../mainwindow.cpp" line="295"/>
135+
<location filename="../mainwindow.cpp" line="310"/>
130136
<source>The server is busy, please log back in again</source>
131137
<translation>服务器繁忙,请稍后重试</translation>
132138
</message>
133139
<message>
134-
<location filename="../mainwindow.cpp" line="299"/>
140+
<location filename="../mainwindow.cpp" line="314"/>
135141
<source>Account and password not match</source>
136142
<translation>账号密码不匹配</translation>
137143
</message>
138144
<message>
139-
<location filename="../mainwindow.cpp" line="303"/>
145+
<location filename="../mainwindow.cpp" line="318"/>
140146
<source>The cumulative time or traffic for this account has exceeded the limit</source>
141147
<translation>该账户的网络时长或者流量超限了</translation>
142148
</message>
143149
<message>
144-
<location filename="../mainwindow.cpp" line="307"/>
150+
<location filename="../mainwindow.cpp" line="322"/>
145151
<source>This account is suspended</source>
146152
<translation>该账号被冻结</translation>
147153
</message>
148154
<message>
149-
<location filename="../mainwindow.cpp" line="311"/>
155+
<location filename="../mainwindow.cpp" line="326"/>
150156
<source>IP address does not match, this account can only be used in the specified IP address</source>
151157
<translation>IP地址不匹配,该账号只能用于指定的IP地址</translation>
152158
</message>
153159
<message>
154-
<location filename="../mainwindow.cpp" line="315"/>
160+
<location filename="../mainwindow.cpp" line="330"/>
155161
<source>MAC address does not match, this account can only be used in the specified IP and MAC address</source>
156162
<translation>物理地址不匹配,该账号只能用于指定的物理地址</translation>
157163
</message>
158164
<message>
159-
<location filename="../mainwindow.cpp" line="319"/>
165+
<location filename="../mainwindow.cpp" line="334"/>
160166
<source>This account has too many IP addresses</source>
161167
<translation>该账号的IP地址太多了</translation>
162168
</message>
163169
<message>
164-
<location filename="../mainwindow.cpp" line="323"/>
170+
<location filename="../mainwindow.cpp" line="338"/>
165171
<source>The client version is incorrect</source>
166172
<translation>登录客户端版本太老了,请更新您的客户端</translation>
167173
</message>
168174
<message>
169-
<location filename="../mainwindow.cpp" line="327"/>
175+
<location filename="../mainwindow.cpp" line="342"/>
170176
<source>This account can only be used on specified MAC and IP address</source>
171177
<translation>该账号只能用于指定的物理地址和IP地址</translation>
172178
</message>
173179
<message>
174-
<location filename="../mainwindow.cpp" line="331"/>
180+
<location filename="../mainwindow.cpp" line="346"/>
175181
<source>Your PC set up a static IP, please change to DHCP, and then re-login</source>
176182
<translation>你的电脑设置成了静态IP,请改为DHCP自动获取模式,然后重新登录</translation>
177183
</message>
178184
<message>
179-
<location filename="../mainwindow.cpp" line="335"/>
180-
<location filename="../mainwindow.cpp" line="340"/>
185+
<location filename="../mainwindow.cpp" line="350"/>
186+
<location filename="../mainwindow.cpp" line="355"/>
181187
<source>You have been offline</source>
182188
<translation>您已离线</translation>
183189
</message>
184190
<message>
185-
<location filename="../mainwindow.cpp" line="335"/>
191+
<location filename="../mainwindow.cpp" line="350"/>
186192
<source>Time out, please check your connection</source>
187193
<translation>连接超时,请检查您的网络连接:)是不是wifi没信号了</translation>
188194
</message>
189195
<message>
190-
<location filename="../mainwindow.cpp" line="340"/>
196+
<location filename="../mainwindow.cpp" line="355"/>
191197
<source>Unknow reason</source>
192198
<translation>未知错误</translation>
193199
</message>
194200
<message>
195-
<location filename="../mainwindow.h" line="46"/>
201+
<location filename="../mainwindow.h" line="47"/>
196202
<source>custom (format: 1A:2B:3C:4D:5E:6F case insensitive)</source>
197203
<translation>自定义(格式:1A:2B:3C:4D:5E:6F不区分大小写)</translation>
198204
</message>
199205
<message>
200-
<location filename="../mainwindow.h" line="47"/>
206+
<location filename="../mainwindow.h" line="48"/>
201207
<source>DrCOM JLU Qt version</source>
202208
<translation>吉大校园网客户端Qt版</translation>
203209
</message>

0 commit comments

Comments
 (0)