Skip to content

Commit 9adfe9d

Browse files
committed
add hide window & hide popup welcome
1 parent 6f49e48 commit 9adfe9d

File tree

7 files changed

+129
-72
lines changed

7 files changed

+129
-72
lines changed

constants.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ ID_ACCOUNT = "account",
6262
ID_PASSWORD = "password",
6363
ID_MAC = "mac",
6464
ID_REMEMBER = "remember",
65-
ID_AUTO_LOGIN = "autoLogin";
65+
ID_AUTO_LOGIN = "autoLogin",
66+
ID_HIDE_WINDOW = "showWindow",
67+
ID_NOT_SHOW_WELCOME = "showWelcome";
6668
const QString ID_RESTART_TIMES = "restartTimes";
6769
const int RETRY_TIMES = 3;
6870

main.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,18 @@ int main(int argc, char *argv[])
9090
qDebug() << "One instance had started. Its window will be shown by the next line of the source code.";
9191
w.ShowLoginWindow();
9292
});
93+
94+
QSettings s(SETTINGS_FILE_NAME);
95+
bool bHideWindow=s.value(ID_HIDE_WINDOW, false).toBool();
9396
// 如果是软件自行重启的就不显示窗口
94-
QSettings s(SETTINGS_FILE_NAME);
9597
int restartTimes = s.value(ID_RESTART_TIMES, 0).toInt();
9698
qDebug() << "main: restartTimes=" << restartTimes;
97-
if (restartTimes > 0) {
98-
// 是自行重启
99-
qDebug() << "showMinimized caused by self-restart";
100-
w.showMinimized();
101-
}
102-
else {
99+
if(bHideWindow){
100+
qDebug()<<"not show window caused user settings";
101+
} else if (restartTimes > 0) {
102+
// 是自行重启不显示窗口
103+
qDebug()<<"not show window caused by self restart";
104+
} else {
103105
qDebug() << "show caused by normal start";
104106
w.show();
105107
}

mainwindow.cpp

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ MainWindow::MainWindow(QWidget *parent) :
100100
int restartTimes = s.value(ID_RESTART_TIMES, 0).toInt();
101101
qDebug() << "MainWindow constructor: restartTimes=" << restartTimes;
102102
if (restartTimes == 0) {
103-
if (auto_login) {
103+
if (bAutoLogin) {
104104
emit ui->pushButtonLogin->click();
105105
}
106106
}
@@ -196,28 +196,38 @@ void MainWindow::LoadSettings() {
196196
account = s.value(ID_ACCOUNT, "").toString();
197197
password = s.value(ID_PASSWORD, "").toString();
198198
mac_addr = s.value(ID_MAC, "").toString();
199-
remember = s.value(ID_REMEMBER, false).toBool();
200-
auto_login = s.value(ID_AUTO_LOGIN, false).toBool();
199+
bRemember = s.value(ID_REMEMBER, false).toBool();
200+
bAutoLogin = s.value(ID_AUTO_LOGIN, false).toBool();
201+
bHideWindow = s.value(ID_HIDE_WINDOW, false).toBool();
202+
bNotShowWelcome = s.value(ID_NOT_SHOW_WELCOME, false).toBool();
201203
ui->lineEditAccount->setText(account);
202204
ui->lineEditPass->setText(password);
203205
SetMAC(mac_addr);
204-
if (remember)
206+
if (bRemember)
205207
ui->checkBoxRemember->setCheckState(Qt::CheckState::Checked);
206208
else
207209
ui->checkBoxRemember->setCheckState(Qt::CheckState::Unchecked);
208-
if (auto_login)
210+
if (bAutoLogin)
209211
ui->checkBoxAutoLogin->setCheckState(Qt::CheckState::Checked);
210212
else
211213
ui->checkBoxAutoLogin->setCheckState(Qt::CheckState::Unchecked);
214+
if(bHideWindow)
215+
ui->checkBoxHideLoginWindow->setCheckState(Qt::CheckState::Checked);
216+
else
217+
ui->checkBoxHideLoginWindow->setCheckState(Qt::CheckState::Unchecked);
218+
if(bNotShowWelcome)
219+
ui->checkBoxNotShowWelcome->setCheckState(Qt::CheckState::Checked);
220+
else
221+
ui->checkBoxNotShowWelcome->setCheckState(Qt::CheckState::Unchecked);
212222
}
213223

214224
void MainWindow::SaveSettings() {
215225
QSettings s(SETTINGS_FILE_NAME);
216226
s.setValue(ID_ACCOUNT, account);
217227
s.setValue(ID_PASSWORD, password);
218228
s.setValue(ID_MAC, mac_addr);
219-
s.setValue(ID_REMEMBER, remember);
220-
s.setValue(ID_AUTO_LOGIN, auto_login);
229+
s.setValue(ID_REMEMBER, bRemember);
230+
s.setValue(ID_AUTO_LOGIN, bAutoLogin);
221231
}
222232

223233
void MainWindow::SetMAC(const QString &m)
@@ -342,8 +352,8 @@ void MainWindow::GetInputs() {
342352
mac_addr = ui->comboBoxMAC->currentText();
343353
}
344354
mac_addr = mac_addr.remove(17, mac_addr.length()).toUpper();
345-
remember = ui->checkBoxRemember->checkState();
346-
auto_login = ui->checkBoxAutoLogin->checkState();
355+
bRemember = ui->checkBoxRemember->checkState();
356+
bAutoLogin = ui->checkBoxAutoLogin->checkState();
347357
}
348358

349359
void MainWindow::HandleOffline(int reason)
@@ -432,7 +442,7 @@ void MainWindow::HandleOffline(int reason)
432442
case OFF_TIMEOUT: {
433443
// 先尝试自己重启若干次,自个重启还不行的话再提示用户
434444
// 自己重启的话需要用户提前勾选记住密码
435-
if (remember) {
445+
if (bRemember) {
436446
QSettings s(SETTINGS_FILE_NAME);
437447
int restartTimes = s.value(ID_RESTART_TIMES, 0).toInt();
438448
qDebug() << "case OFF_TIMEOUT: restartTimes=" << restartTimes;
@@ -471,8 +481,8 @@ void MainWindow::HandleOffline(int reason)
471481
// 清除已保存的密码
472482
account = "";
473483
password = "";
474-
remember = false;
475-
auto_login = false;
484+
bRemember = false;
485+
bAutoLogin = false;
476486
SaveSettings();
477487
}
478488
// 重新启用输入
@@ -492,14 +502,16 @@ void MainWindow::HandleLoggedIn()
492502

493503
CURR_STATE = STATE_ONLINE;
494504
// 显示欢迎页
495-
if (restartTimes == 0) {
505+
bool bNotShowWelcome = s.value(ID_NOT_SHOW_WELCOME, false).toBool();
506+
if (restartTimes == 0 && !bNotShowWelcome) {
507+
qDebug()<<"open welcome page";
496508
QDesktopServices::openUrl(QUrl("http://login.jlu.edu.cn/notice.php"));
497509
}
498510
else {
499511
// 自行尝试重启的,不显示欢迎页
500512
}
501513
// 登录成功,保存密码
502-
if (remember) {
514+
if (bRemember) {
503515
SaveSettings();
504516
}
505517
else {
@@ -538,3 +550,15 @@ void MainWindow::DisableLogOutButton(bool yes) {
538550
logOutAction->setEnabled(true);
539551
}
540552
}
553+
554+
void MainWindow::on_checkBoxNotShowWelcome_toggled(bool checked)
555+
{
556+
QSettings s(SETTINGS_FILE_NAME);
557+
s.setValue(ID_NOT_SHOW_WELCOME, checked);
558+
}
559+
560+
void MainWindow::on_checkBoxHideLoginWindow_toggled(bool checked)
561+
{
562+
QSettings s(SETTINGS_FILE_NAME);
563+
s.setValue(ID_HIDE_WINDOW, checked);
564+
}

mainwindow.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ private slots:
2929
void IconActivated(QSystemTrayIcon::ActivationReason reason);
3030
void UserLogOut();
3131

32+
void on_checkBoxNotShowWelcome_toggled(bool checked);
33+
34+
void on_checkBoxHideLoginWindow_toggled(bool checked);
35+
3236
public slots:
3337
void HandleOffline(int reason);
3438
void HandleLoggedIn();
@@ -49,7 +53,8 @@ public slots:
4953

5054
// 记录用户保存的信息
5155
QString account, password, mac_addr;
52-
bool remember, auto_login;
56+
bool bRemember, bAutoLogin;
57+
bool bHideWindow, bNotShowWelcome;
5358

5459
// 用于在未登录时关闭窗口就退出
5560
int CURR_STATE;

mainwindow.ui

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@
108108
</property>
109109
</widget>
110110
</item>
111+
<item row="1" column="0">
112+
<widget class="QCheckBox" name="checkBoxNotShowWelcome">
113+
<property name="text">
114+
<string>NotShowWelcomePage</string>
115+
</property>
116+
</widget>
117+
</item>
118+
<item row="1" column="1">
119+
<widget class="QCheckBox" name="checkBoxHideLoginWindow">
120+
<property name="text">
121+
<string>HideLoginWindow</string>
122+
</property>
123+
</widget>
124+
</item>
111125
</layout>
112126
</item>
113127
<item>

ts/DrCOM_zh_CN.qm

137 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)