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
8395static 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+
765782void MainWindow::on_action_about_triggered ()
766783{
767784 QMessageBox msgBox (this );
@@ -789,6 +806,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
789806
790807void 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);
0 commit comments