Skip to content

Commit 29981a2

Browse files
committed
Create update action in mainwindow
1 parent e8adf16 commit 29981a2

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/mainwindow/mainwindow.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#include <QToolButton>
33
#include <QMessageBox>
44
#include <QFileDialog>
5+
#include <QProcess>
56
#include <QSettings>
67
#include <QMimeData>
78
#include <QCloseEvent>
89
#include <QDesktopServices>
910

11+
#include "updater/updaterconst.h"
1012
#include "common/global.h"
1113
#include "common/player.h"
1214
#include "common/problem.h"
@@ -66,6 +68,7 @@ MainWindow::MainWindow(QWidget* parent) :
6668

6769
CreateActions();
6870
UpdateRecentContest(true);
71+
CheckUpdates(true);
6972

7073
this->activateWindow();
7174
}
@@ -90,6 +93,15 @@ void MainWindow::UnlockTable()
9093
detail_table->Unlock();
9194
}
9295

96+
void MainWindow::CheckUpdates(bool dontShowError)
97+
{
98+
QString dir = QCoreApplication::applicationDirPath();
99+
QStringList arguments = { "-c", "-p" };
100+
arguments.append(QString("%1").arg(QCoreApplication::applicationPid()));
101+
if (dontShowError) arguments.append("-n");
102+
QProcess::startDetached(dir + "/" + Updater::UPDATER_NAME, arguments, dir);
103+
}
104+
93105
// Last contest path
94106
static QString lastContest;
95107

@@ -773,6 +785,11 @@ void MainWindow::on_action_help_triggered()
773785

774786
}
775787

788+
void MainWindow::on_action_update_triggered()
789+
{
790+
CheckUpdates(false);
791+
}
792+
776793
void MainWindow::on_action_about_triggered()
777794
{
778795
QMessageBox msgBox(this);

src/mainwindow/mainwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class MainWindow : public QMainWindow
4646
void LockTable();
4747
void UnlockTable();
4848

49+
/// 检查更新,是否只当有更新时才显示对话框
50+
void CheckUpdates(bool dontShowError);
51+
4952
/// 更新最近打开的竞赛列表,是否更新 listWidget_recent
5053
void UpdateRecentContest(bool);
5154

@@ -107,6 +110,7 @@ private slots:
107110

108111
// Help menu actions
109112
void on_action_help_triggered();
113+
void on_action_update_triggered();
110114
void on_action_about_triggered();
111115

112116
protected:

src/mainwindow/mainwindow.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ QMainWindow
200200
<string>帮助(&amp;H)</string>
201201
</property>
202202
<addaction name="action_help"/>
203+
<addaction name="action_update"/>
203204
<addaction name="separator"/>
204205
<addaction name="action_about"/>
205206
</widget>
@@ -338,6 +339,11 @@ QMainWindow
338339
<string>F1</string>
339340
</property>
340341
</action>
342+
<action name="action_update">
343+
<property name="text">
344+
<string>检查更新(&amp;U)...</string>
345+
</property>
346+
</action>
341347
</widget>
342348
<layoutdefault spacing="6" margin="11"/>
343349
<resources>

0 commit comments

Comments
 (0)