Author: cazfi
Date: Tue Apr 28 18:16:19 2015
New Revision: 28931

URL: http://svn.gna.org/viewcvs/freeciv?rev=28931&view=rev
Log:
Confirm Qt modpack installer quit if modpack download or installation is in 
progress.

See patch #6042

Modified:
    branches/S2_6/tools/mpgui_qt.cpp
    branches/S2_6/tools/mpgui_qt.h

Modified: branches/S2_6/tools/mpgui_qt.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpgui_qt.cpp?rev=28931&r1=28930&r2=28931&view=diff
==============================================================================
--- branches/S2_6/tools/mpgui_qt.cpp    (original)
+++ branches/S2_6/tools/mpgui_qt.cpp    Tue Apr 28 18:16:19 2015
@@ -17,11 +17,13 @@
 
 // Qt
 #include <QApplication>
+#include <QCloseEvent>
 #include <QHBoxLayout>
 #include <QHeaderView>
 #include <QLabel>
 #include <QLineEdit>
 #include <QMainWindow>
+#include <QMessageBox>
 #include <QProgressBar>
 #include <QPushButton>
 #include <QTableWidget>
@@ -106,15 +108,15 @@
 
   if (ui_options != -1) {
     QApplication *qapp;
-    QMainWindow *main_window;
+    mpgui_main *main_window;
     QWidget *central;
     const char *errmsg;
 
     load_install_info_lists(&fcmp);
 
     qapp = new QApplication(ui_options, argv);
-    main_window = new QMainWindow;
     central = new QWidget;
+    main_window = new mpgui_main(qapp, central);
 
     main_window->setGeometry(0, 30, 640, 60);
     main_window->setWindowTitle(QString::fromUtf8(_("Freeciv modpack installer 
(Qt)")));
@@ -455,3 +457,49 @@
 
   URL_given();
 }
+
+/**************************************************************************
+  Main window constructor
+**************************************************************************/
+mpgui_main::mpgui_main(QApplication *qapp_in, QWidget *central_in) : 
QMainWindow()
+{
+  qapp = qapp_in;
+  central = central_in;
+}
+
+/**************************************************************************
+  Open dialog to confirm that user wants to quit modpack installer.
+**************************************************************************/
+void mpgui_main::popup_quit_dialog()
+{
+  QMessageBox ask(central);
+  int ret;
+
+  ask.setText(_("Are you sure you want to quit?"));
+  ask.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
+  ask.setDefaultButton(QMessageBox::Cancel);
+  ask.setIcon(QMessageBox::Warning);
+  ask.setWindowTitle(_("Quit?"));
+  ret = ask.exec();
+
+  switch (ret) {
+  case QMessageBox::Cancel:
+    return;
+    break;
+  case QMessageBox::Ok:
+    qapp->quit();
+    break;
+  }
+}
+
+/**************************************************************************
+  User clicked windows close button.
+**************************************************************************/
+void mpgui_main::closeEvent(QCloseEvent *event)
+{
+  if (worker != nullptr && worker->isRunning()) {
+    // Download in progress. Confirm quit from user.
+    popup_quit_dialog();
+    event->ignore();
+  }
+}

Modified: branches/S2_6/tools/mpgui_qt.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/tools/mpgui_qt.h?rev=28931&r1=28930&r2=28931&view=diff
==============================================================================
--- branches/S2_6/tools/mpgui_qt.h      (original)
+++ branches/S2_6/tools/mpgui_qt.h      Tue Apr 28 18:16:19 2015
@@ -19,6 +19,7 @@
 #endif
 
 // Qt
+#include <QMainWindow>
 #include <QObject>
 
 // tools
@@ -28,6 +29,22 @@
 class QLineEdit;
 class QProgressBar;
 class QTableWidget;
+
+class mpgui_main : public QMainWindow
+{
+  Q_OBJECT
+
+public:
+  mpgui_main(QApplication *qapp_in, QWidget *central_in);
+
+private:
+  void popup_quit_dialog();
+  QApplication *qapp;
+  QWidget *central;
+
+protected:
+  void closeEvent(QCloseEvent *event);
+};
 
 class mpgui : public QObject
 {


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to