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 20, 2017
1 parent 8721b9a commit 30e0f37
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <QProcess>
#include <QSettings>
#include <QMimeData>
#include <QMessageBox>
#include <QFileDialog>
#include <QCloseEvent>
#include <QDesktopServices>

#include "updater/updaterconst.h"
#include "common/global.h"
#include "common/version.h"
#include "configure/configuredialog.h"
Expand Down Expand Up @@ -55,6 +57,7 @@ MainWindow::MainWindow(QWidget* parent) :

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

this->activateWindow();
}
Expand All @@ -79,6 +82,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 @@ -762,6 +774,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 Expand Up @@ -789,6 +806,7 @@ void MainWindow::closeEvent(QCloseEvent* event)

void MainWindow::keyPressEvent(QKeyEvent* event)
{
if (!ui->listWidget_recent->count()) return;
if (!ui->action_close->isEnabled() && (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) && ui->listWidget_recent->currentItem()->isSelected())
on_listWidget_recent_itemDoubleClicked(ui->listWidget_recent->currentItem());
else QWidget::keyPressEvent(event);
Expand Down
4 changes: 4 additions & 0 deletions src/mainwindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class MainWindow : public QMainWindow
void LockTable();
void UnlockTable();

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

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

Expand Down Expand Up @@ -106,6 +109,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 @@ -205,6 +205,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 @@ -343,6 +344,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 30e0f37

Please sign in to comment.