diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index b684013..59caba1 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,6 +6,7 @@ #include #include +#include "updater/updaterconst.h" #include "common/global.h" #include "common/version.h" #include "configure/configuredialog.h" @@ -55,6 +57,7 @@ MainWindow::MainWindow(QWidget* parent) : CreateActions(); UpdateRecentContest(true); + CheckUpdates(true); this->activateWindow(); } @@ -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; @@ -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); @@ -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); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 74864df..b41c99d 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -45,6 +45,9 @@ class MainWindow : public QMainWindow void LockTable(); void UnlockTable(); + /// 检查更新,是否只当有更新时才显示对话框 + void CheckUpdates(bool dontShowError); + /// 更新最近打开的竞赛列表,是否更新 listWidget_recent void UpdateRecentContest(bool); @@ -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: diff --git a/src/mainwindow/mainwindow.ui b/src/mainwindow/mainwindow.ui index f8b24df..9be1d33 100644 --- a/src/mainwindow/mainwindow.ui +++ b/src/mainwindow/mainwindow.ui @@ -205,6 +205,7 @@ QMainWindow 帮助(&H) + @@ -343,6 +344,11 @@ QMainWindow F1 + + + 检查更新(&U)... + +