changeset 609:292c590ba9cb

Add warning dialog for running firefox and tunderbird processes
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 18 Jun 2014 14:40:06 +0200
parents 81a44b93229e
children f469fae3f2f1
files ui/CMakeLists.txt ui/mainwindow.cpp ui/mainwindow.h ui/processwaitdialog.cpp ui/processwaitdialog.h
diffstat 5 files changed, 146 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ui/CMakeLists.txt	Wed Jun 18 11:22:15 2014 +0200
+++ b/ui/CMakeLists.txt	Wed Jun 18 14:40:06 2014 +0200
@@ -20,8 +20,6 @@
     ${CMAKE_CURRENT_SOURCE_DIR}/downloader.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/sslconnection.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/sslhelp.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/processhelp_win.cpp
-    ${CMAKE_CURRENT_SOURCE_DIR}/processhelp_linux.cpp
 )
 
 # Cmake does not correctly identify gcc windres when cross compiling
@@ -37,6 +35,9 @@
     ${CMAKE_CURRENT_SOURCE_DIR}/separatoritemdelegate.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/installwrapper.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/aboutdialog.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/processhelp_win.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/processhelp_linux.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/processwaitdialog.cpp
     ${CERTIFICATELIST_SOURCES}
     ${DOWNLOADER_SOURCES}
 )
--- a/ui/mainwindow.cpp	Wed Jun 18 11:22:15 2014 +0200
+++ b/ui/mainwindow.cpp	Wed Jun 18 14:40:06 2014 +0200
@@ -27,6 +27,19 @@
 #include <QImage>
 #include <QCheckBox>
 
+#include "certificatelist.h"
+#include "downloader.h"
+#include "helpdialog.h"
+#include "aboutdialog.h"
+#include "certificateitemdelegate.h"
+#include "separatoritemdelegate.h"
+#include "installwrapper.h"
+#include "util.h"
+#include "logging.h"
+#include "binverify.h"
+#include "processhelp.h"
+#include "processwaitdialog.h"
+
 // The amount of time in minutes stay silent if we have
 // something to say
 #define NAG_INTERVAL_MINUTES 70
@@ -55,17 +68,6 @@
 # endif
 #endif
 
-#include "certificatelist.h"
-#include "downloader.h"
-#include "helpdialog.h"
-#include "aboutdialog.h"
-#include "certificateitemdelegate.h"
-#include "separatoritemdelegate.h"
-#include "installwrapper.h"
-#include "util.h"
-#include "logging.h"
-#include "binverify.h"
-
 MainWindow::MainWindow(bool trayMode):
     mTrayMode(trayMode)
 {
@@ -508,7 +510,7 @@
     installButton = new QPushButton(tr("Install selected"));
     installButton->setFixedHeight(80);
     connect(installButton, SIGNAL(clicked()), this, SLOT(resizeButtons()));
-    connect(installButton, SIGNAL(clicked()), this, SLOT(installCerts()));
+    connect(installButton, SIGNAL(clicked()), this, SLOT(checkAndInstallCerts()));
     quitButton = new QPushButton(tr("Quit"));
     quitButton->setFixedHeight(20);
     connect(quitButton, SIGNAL(clicked()), this, SLOT(closeApp()));
@@ -855,3 +857,27 @@
     saveUnselectedCertificates();
     qApp->quit();
 }
+
+void MainWindow::checkAndInstallCerts()
+{
+    /* Checking before opening the dialog should be cheaper */
+    QList<int> pids = ProcessHelp::getProcessesIdForName("firefox");
+    pids.append(ProcessHelp::getProcessesIdForName("thunderbird"));
+
+    if (pids.isEmpty()) {
+        installCerts();
+        return;
+    }
+
+    QStringList pNames;
+    pNames << "firefox" << "thunderbird";
+
+    ProcessWaitDialog *waitDialog = new ProcessWaitDialog(this, pNames);
+
+    connect(waitDialog, SIGNAL(accepted()), this, SLOT(installCerts()));
+    connect(waitDialog, SIGNAL(accepted()), waitDialog, SLOT(deleteLater()));
+
+    waitDialog->exec();
+
+    return;
+}
--- a/ui/mainwindow.h	Wed Jun 18 11:22:15 2014 +0200
+++ b/ui/mainwindow.h	Wed Jun 18 14:40:06 2014 +0200
@@ -81,6 +81,13 @@
     void saveAutoUpdate(int state);
     void saveAutoStart(int state);
 
+    /** @brief check for running software that needs to close before installing
+     *
+     * This function calls installCerts if no software is running otherwise
+     * it informs the user about the software that still needs to be closed.
+     */
+    void checkAndInstallCerts();
+
     /** @brief get the last modified date on the download server for
      * the current version.
      *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/processwaitdialog.cpp	Wed Jun 18 14:40:06 2014 +0200
@@ -0,0 +1,53 @@
+/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=2)
+ * and comes with ABSOLUTELY NO WARRANTY!
+ * See LICENSE.txt for details.
+ */
+#include <QHBoxLayout>
+#include <QListWidget>
+#include <QTimer>
+#include <QList>
+#include <QLabel>
+#include <QApplication>
+
+#include "processwaitdialog.h"
+#include "processhelp.h"
+
+ProcessWaitDialog::ProcessWaitDialog(QWidget *parent, const QStringList& processNames) :
+    QDialog(parent),
+    mProcessNames(processNames) {
+    QHBoxLayout *theLayout = new QHBoxLayout(this);
+
+    setWindowTitle(tr("Applications need to be closed."));
+
+    QLabel *warnLabel = new QLabel(tr("Close all running firefox and thunderbird instances to continue installation"));
+    QLabel *warnIcon = new QLabel();
+    warnIcon->setPixmap(QApplication::style()->standardPixmap(QStyle::SP_MessageBoxWarning));
+
+    theLayout->addWidget(warnIcon);
+    theLayout->addWidget(warnLabel);
+ //   mProcessList = new QListWidget();
+//    theLayout->addWidget(mProcessList);
+    updateProcesses();
+}
+
+void ProcessWaitDialog::updateProcesses() {
+    QList<int> pids;
+    foreach (const QString& pName, mProcessNames) {
+        pids.append(ProcessHelp::getProcessesIdForName(pName));
+    }
+    if (pids.isEmpty()) {
+        accept();
+        return;
+    }
+
+  /*  mProcessList->clear();
+
+    foreach (int pId, pids) {
+        mProcessList->addItem(QString::fromLatin1("Pid ") + pId);
+    }
+*/
+    QTimer::singleShot(500, this, SLOT(updateProcesses()));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/processwaitdialog.h	Wed Jun 18 14:40:06 2014 +0200
@@ -0,0 +1,45 @@
+/* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=2)
+ * and comes with ABSOLUTELY NO WARRANTY!
+ * See LICENSE.txt for details. */
+#ifndef PROCESSWAITDIALOG_H
+#define PROCESSWAITDIALOG_H
+
+#include <QDialog>
+#include <QStringList>
+
+/** @file Dialog to show that some processes need to be closed
+ *
+ * This dialog informs about processes that are still running and
+ * need to be closed.
+ */
+
+class ProcessWaitDialog : public QDialog
+{
+    Q_OBJECT
+
+public:
+    /** @brief create the dialog
+     *
+     * The dialog is modal and will stay open until no more processes
+     * with names from processnames exist.
+     *
+     * @param[in] parent the parent dialog
+     * @param[in] processNames the names of the processes to wait for.
+     */
+    ProcessWaitDialog(QWidget *parent, const QStringList& processNames);
+
+private slots:
+
+    /** @brief update the process list */
+    void updateProcesses();
+
+private:
+
+    QListWidget *mProcessList;
+    const QStringList mProcessNames;
+};
+
+#endif // PROCESSWAITDIALOG_H

http://wald.intevation.org/projects/trustbridge/