Skip to content

Commit a9c4d41

Browse files
committed
Create update action in mainwindow
1 parent 353a9c7 commit a9c4d41

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/mainwindow/mainwindow.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
#include <QProcess>
12
#include <QSettings>
23
#include <QMimeData>
34
#include <QMessageBox>
45
#include <QFileDialog>
56
#include <QCloseEvent>
67
#include <QDesktopServices>
78

9+
#include "updater/updaterconst.h"
810
#include "common/global.h"
911
#include "common/version.h"
1012
#include "configure/configuredialog.h"
@@ -55,6 +57,7 @@ MainWindow::MainWindow(QWidget* parent) :
5557

5658
CreateActions();
5759
UpdateRecentContest(true);
60+
CheckUpdates(true);
5861

5962
this->activateWindow();
6063
}
@@ -79,6 +82,15 @@ void MainWindow::UnlockTable()
7982
detail_table->Unlock();
8083
}
8184

85+
void MainWindow::CheckUpdates(bool dontShowError)
86+
{
87+
QString dir = QCoreApplication::applicationDirPath();
88+
QStringList arguments = { "-c", "-p" };
89+
arguments.append(QString("%1").arg(QCoreApplication::applicationPid()));
90+
if (dontShowError) arguments.append("-n");
91+
QProcess::startDetached(dir + "/" + Updater::UPDATER_NAME, arguments, dir);
92+
}
93+
8294
// Last contest path
8395
static QString lastContest;
8496

@@ -762,6 +774,11 @@ void MainWindow::on_action_help_triggered()
762774

763775
}
764776

777+
void MainWindow::on_action_update_triggered()
778+
{
779+
CheckUpdates(false);
780+
}
781+
765782
void MainWindow::on_action_about_triggered()
766783
{
767784
QMessageBox msgBox(this);
@@ -789,6 +806,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
789806

790807
void MainWindow::keyPressEvent(QKeyEvent* event)
791808
{
809+
if (!ui->listWidget_recent->count()) return;
792810
if (!ui->action_close->isEnabled() && (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && ui->listWidget_recent->currentItem()->isSelected())
793811
on_listWidget_recent_itemDoubleClicked(ui->listWidget_recent->currentItem());
794812
else QWidget::keyPressEvent(event);

src/mainwindow/mainwindow.h

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

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

@@ -106,6 +109,7 @@ private slots:
106109

107110
// Help menu actions
108111
void on_action_help_triggered();
112+
void on_action_update_triggered();
109113
void on_action_about_triggered();
110114

111115
protected:

src/mainwindow/mainwindow.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ QMainWindow
205205
<string>帮助(&amp;H)</string>
206206
</property>
207207
<addaction name="action_help"/>
208+
<addaction name="action_update"/>
208209
<addaction name="separator"/>
209210
<addaction name="action_about"/>
210211
</widget>
@@ -343,6 +344,11 @@ QMainWindow
343344
<string>F1</string>
344345
</property>
345346
</action>
347+
<action name="action_update">
348+
<property name="text">
349+
<string>检查更新(&amp;U)...</string>
350+
</property>
351+
</action>
346352
</widget>
347353
<layoutdefault spacing="6" margin="11"/>
348354
<resources>

0 commit comments

Comments
 (0)