Skip to content

Commit

Permalink
Create update action in mainwindow
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Feb 21, 2017
1 parent e8adf16 commit 29981a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#include <QToolButton>
#include <QMessageBox>
#include <QFileDialog>
#include <QProcess>
#include <QSettings>
#include <QMimeData>
#include <QCloseEvent>
#include <QDesktopServices>

#include "updater/updaterconst.h"
#include "common/global.h"
#include "common/player.h"
#include "common/problem.h"
Expand Down Expand Up @@ -66,6 +68,7 @@ MainWindow::MainWindow(QWidget* parent) :

CreateActions();
UpdateRecentContest(true);
CheckUpdates(true);

this->activateWindow();
}
Expand All @@ -90,6 +93,15 @@ void MainWindow::UnlockTable()
detail_table->Unlock();
}

void MainWindow::CheckUpdates(bool dontShowError)
{
QString dir = QCoreApplication::applicationDirPath();
QStringList arguments = { "-c", "-p" };
arguments.append(QString("%1").arg(QCoreApplication::applicationPid()));
if (dontShowError) arguments.append("-n");
QProcess::startDetached(dir + "/" + Updater::UPDATER_NAME, arguments, dir);
}

// Last contest path
static QString lastContest;

Expand Down Expand Up @@ -773,6 +785,11 @@ void MainWindow::on_action_help_triggered()

}

void MainWindow::on_action_update_triggered()
{
CheckUpdates(false);
}

void MainWindow::on_action_about_triggered()
{
QMessageBox msgBox(this);
Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class MainWindow : public QMainWindow
void LockTable();
void UnlockTable();

/// 检查更新,是否只当有更新时才显示对话框
void CheckUpdates(bool dontShowError);

/// 更新最近打开的竞赛列表,是否更新 listWidget_recent
void UpdateRecentContest(bool);

Expand Down Expand Up @@ -107,6 +110,7 @@ private slots:

// Help menu actions
void on_action_help_triggered();
void on_action_update_triggered();
void on_action_about_triggered();

protected:
Expand Down
6 changes: 6 additions & 0 deletions src/mainwindow/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ QMainWindow
<string>帮助(&amp;H)</string>
</property>
<addaction name="action_help"/>
<addaction name="action_update"/>
<addaction name="separator"/>
<addaction name="action_about"/>
</widget>
Expand Down Expand Up @@ -338,6 +339,11 @@ QMainWindow
<string>F1</string>
</property>
</action>
<action name="action_update">
<property name="text">
<string>检查更新(&amp;U)...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
Expand Down

0 comments on commit 29981a2

Please sign in to comment.