changeset 365:75f7288ad67b

Switch from listupdatedialog to installwrapper. Minor UI improvements
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 14 Apr 2014 16:59:08 +0000
parents dc4efb0a70cb
children c0d63a7f270e
files ui/main.cpp ui/mainwindow.cpp ui/mainwindow.h
diffstat 3 files changed, 79 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ui/main.cpp	Mon Apr 14 16:58:20 2014 +0000
+++ b/ui/main.cpp	Mon Apr 14 16:59:08 2014 +0000
@@ -46,10 +46,7 @@
     QApplication::setApplicationVersion(QString::fromLatin1(VERSION));
     QSettings::setDefaultFormat(QSettings::IniFormat);
 
-    MainWindow mainWin;
-    if (!trayMode) {
-        mainWin.show();
-    }
+    MainWindow mainWin(trayMode);
 
     return app.exec();
 }
--- a/ui/mainwindow.cpp	Mon Apr 14 16:58:20 2014 +0000
+++ b/ui/mainwindow.cpp	Mon Apr 14 16:59:08 2014 +0000
@@ -1,6 +1,7 @@
 #include "mainwindow.h"
 
 #include <QDebug>
+#include <QProgressDialog>
 #include <QMessageBox>
 #include <QSystemTrayIcon>
 #include <QAction>
@@ -19,7 +20,7 @@
 
 // The amount of time in minutes stay silent if we have
 // something to say
-#define NAG_INTERVAL_MINUTES 2
+#define NAG_INTERVAL_MINUTES 60
 
 #define SERVER_URL "https://files.kolab.org:443"
 #define LIST_RESOURCE "/incoming/aheinecke/test"
@@ -27,14 +28,16 @@
 
 #include "certificatelist.h"
 #include "downloader.h"
-#include "listupdatedialog.h"
 #include "helpdialog.h"
 #include "aboutdialog.h"
 #include "statusdialog.h"
 #include "certificateitemdelegate.h"
 #include "separatoritemdelegate.h"
+#include "installwrapper.h"
 
-MainWindow::MainWindow() {
+MainWindow::MainWindow(bool trayMode):
+    mTrayMode(trayMode)
+{
     createActions();
     createTrayIcon();
     createMenuBar();
@@ -50,6 +53,9 @@
     mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000);
     mMessageTimer->start();
     checkUpdates();
+    if (!trayMode) {
+        show();
+    }
 }
 
 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
@@ -60,7 +66,7 @@
         showMessage();
         break;
     case QSystemTrayIcon::DoubleClick:
-        // TODO show menu
+        show();
         break;
     default:
         ;
@@ -70,16 +76,13 @@
 void MainWindow::messageClicked()
 {
     if (mCurState == NewListAvailable) {
-        ListUpdateDialog *listUpdateDialog = new ListUpdateDialog(this,
-                mListToInstall);
-        listUpdateDialog->show();
-        qDebug() << "NewListAvailable";
+        show();
     }
 }
 
 void MainWindow::showMessage()
 {
-    if (!mCurMessage.isEmpty()) {
+    if (!isVisible() && !mCurMessage.isEmpty()) {
         mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage,
                                QSystemTrayIcon::Information, 5000);
         mMessageTimer->start(); // Restart the timer so that we don't spam
@@ -247,11 +250,11 @@
 
     // The certificate list
     QGroupBox *certBox = new QGroupBox(tr("Managed Certificates"));
-    certificateList = new QListWidget;
-    certificateList->setItemDelegate(new CertificateItemDelegate);
-    connect(certificateList, SIGNAL(itemClicked(QListWidgetItem*)),
+    mCertListWidget = new QListWidget;
+    mCertListWidget->setItemDelegate(new CertificateItemDelegate);
+    connect(mCertListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
         this, SLOT(showDetails(QListWidgetItem*)));
-    certLayout->addWidget(certificateList);
+    certLayout->addWidget(mCertListWidget);
     certBox->setLayout(certLayout);
 
     // The header (icon, about text)
@@ -278,6 +281,7 @@
     installButton = new QPushButton(tr("Install selected"));
     installButton->setFixedHeight(80);
     connect(installButton, SIGNAL(clicked()), this, SLOT(resizeButtons()));
+    connect(installButton, SIGNAL(clicked()), this, SLOT(installCerts()));
     quitButton = new QPushButton(tr("Quit"));
     quitButton->setFixedHeight(20);
     connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
@@ -313,7 +317,7 @@
 void MainWindow::loadCertificateList()
 {
     qDebug() << "display certificates";
-    certificateList->clear();
+    mCertListWidget->clear();
     int i = 0;
     foreach (const Certificate &cert, mListToInstall.getCertificates()) {
         if (!cert.isValid()) {
@@ -337,8 +341,8 @@
             }
             if (i == 3) {
                 QListWidgetItem *sep = new QListWidgetItem("New certificates");
-                certificateList->setItemDelegateForRow(i, separator);
-                certificateList->addItem(sep);
+                mCertListWidget->setItemDelegateForRow(i, separator);
+                mCertListWidget->addItem(sep);
                 i++;
             }
         }
@@ -354,7 +358,7 @@
                 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
             }
         }
-        certificateList->addItem(item);
+        mCertListWidget->addItem(item);
         i++;
     }
 }
@@ -387,9 +391,7 @@
 
 void MainWindow::showDetails(QListWidgetItem *item)
 {
-    qDebug() << "show details";
     QString details = item->data(Qt::UserRole).toString();
-    details.append("\rInstalled: 1.1.1971\rRemoved: 1.1.1971");
     certificateDetails->setPlainText(details);
 }
 
@@ -398,3 +400,44 @@
     installButton->setFixedHeight(20);
     quitButton->setFixedHeight(80);
 }
+
+void MainWindow::installerError(const QString& errMsg) {
+    QMessageBox::warning(this, tr("Error executing update"), errMsg);
+}
+
+void MainWindow::installCerts() {
+    QStringList choices;
+
+    for (int i = 0; i < mCertListWidget->count(); i++) {
+        QListWidgetItem *item = mCertListWidget->item(i);
+        if (item->checkState() == Qt::Checked) {
+            choices << item->data(Qt::UserRole).toString();
+            continue;
+        }
+        QString certLine = item->data(Qt::UserRole).toString();
+        if (certLine.startsWith("I:")) {
+            certLine[0] = 'R';
+            choices << certLine;
+        }
+    }
+
+    QProgressDialog *progress = new QProgressDialog(this);
+    progress->setWindowModality(Qt::WindowModal);
+    progress->setLabelText(tr("Installing certificates..."));
+    progress->setCancelButton(0);
+    progress->setRange(0,0);
+    progress->setMinimumDuration(0);
+    progress->show();
+
+    InstallWrapper *instWrap = new InstallWrapper(this,
+                                                  mListToInstall.fileName(),
+                                                  choices);
+    /* Clean up object and progress dialog */
+    connect(instWrap, SIGNAL(finished()), instWrap, SLOT(deleteLater()));
+    connect(instWrap, SIGNAL(finished()), progress, SLOT(deleteLater()));
+    connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel()));
+    connect(instWrap, SIGNAL(error(const QString &)),
+        this, SLOT(installerError(const QString &)));
+    instWrap->start();
+
+}
--- a/ui/mainwindow.h	Mon Apr 14 16:58:20 2014 +0000
+++ b/ui/mainwindow.h	Mon Apr 14 16:59:08 2014 +0000
@@ -25,7 +25,16 @@
     Q_OBJECT
 
 public:
-    MainWindow();
+    /**@brief create a new Main Window object
+     *
+     * In tray mode this window is not shown and only shows
+     * notification messages if there is some actionable state
+     * reached. If tray mode is true it also exits after
+     * an update check.
+     *
+     * @param[in] trayMode set the tray mode
+     * */
+    MainWindow(bool trayMode);
 
     void setMessage(const QString message) {mCurMessage = message;}
     QString getMessage() {return mCurMessage;}
@@ -55,6 +64,8 @@
     void showAbout();
     void showDetails(QListWidgetItem*);
     void resizeButtons();
+    void installerError(const QString& errMsg);
+    void installCerts();
 
 private:
     /** @brief check the integrity of available files.
@@ -72,6 +83,9 @@
     void createContent();
     void loadCertificateList();
 
+    /* Are we running in tray mode ?*/
+    const bool mTrayMode;
+    /* The message currently shown at intervals */
     QString mCurMessage;
     QString mInstalledSWVersion;
     QString mInstalledListVersion;
@@ -88,7 +102,7 @@
 
     CertificateList mListToInstall;
 
-    QListWidget *certificateList;
+    QListWidget *mCertListWidget;
     QTextEdit *certificateDetails;
     QPushButton *installButton;
     QPushButton *quitButton;

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