comparison ui/mainwindow.cpp @ 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 90432cb1f374
children 6cc124e79066
comparison
equal deleted inserted replaced
364:dc4efb0a70cb 365:75f7288ad67b
1 #include "mainwindow.h" 1 #include "mainwindow.h"
2 2
3 #include <QDebug> 3 #include <QDebug>
4 #include <QProgressDialog>
4 #include <QMessageBox> 5 #include <QMessageBox>
5 #include <QSystemTrayIcon> 6 #include <QSystemTrayIcon>
6 #include <QAction> 7 #include <QAction>
7 #include <QDialog> 8 #include <QDialog>
8 #include <QMenu> 9 #include <QMenu>
17 #include <QImage> 18 #include <QImage>
18 #include <QCheckBox> 19 #include <QCheckBox>
19 20
20 // The amount of time in minutes stay silent if we have 21 // The amount of time in minutes stay silent if we have
21 // something to say 22 // something to say
22 #define NAG_INTERVAL_MINUTES 2 23 #define NAG_INTERVAL_MINUTES 60
23 24
24 #define SERVER_URL "https://files.kolab.org:443" 25 #define SERVER_URL "https://files.kolab.org:443"
25 #define LIST_RESOURCE "/incoming/aheinecke/test" 26 #define LIST_RESOURCE "/incoming/aheinecke/test"
26 #define SW_RESOURCE "/incoming/aheinecke/test" 27 #define SW_RESOURCE "/incoming/aheinecke/test"
27 28
28 #include "certificatelist.h" 29 #include "certificatelist.h"
29 #include "downloader.h" 30 #include "downloader.h"
30 #include "listupdatedialog.h"
31 #include "helpdialog.h" 31 #include "helpdialog.h"
32 #include "aboutdialog.h" 32 #include "aboutdialog.h"
33 #include "statusdialog.h" 33 #include "statusdialog.h"
34 #include "certificateitemdelegate.h" 34 #include "certificateitemdelegate.h"
35 #include "separatoritemdelegate.h" 35 #include "separatoritemdelegate.h"
36 36 #include "installwrapper.h"
37 MainWindow::MainWindow() { 37
38 MainWindow::MainWindow(bool trayMode):
39 mTrayMode(trayMode)
40 {
38 createActions(); 41 createActions();
39 createTrayIcon(); 42 createTrayIcon();
40 createMenuBar(); 43 createMenuBar();
41 createContent(); 44 createContent();
42 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode"); 45 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode");
48 mMessageTimer = new QTimer(this); 51 mMessageTimer = new QTimer(this);
49 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage())); 52 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage()));
50 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); 53 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000);
51 mMessageTimer->start(); 54 mMessageTimer->start();
52 checkUpdates(); 55 checkUpdates();
56 if (!trayMode) {
57 show();
58 }
53 } 59 }
54 60
55 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) 61 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
56 { 62 {
57 switch (reason) { 63 switch (reason) {
58 case QSystemTrayIcon::Trigger: 64 case QSystemTrayIcon::Trigger:
59 case QSystemTrayIcon::MiddleClick: 65 case QSystemTrayIcon::MiddleClick:
60 showMessage(); 66 showMessage();
61 break; 67 break;
62 case QSystemTrayIcon::DoubleClick: 68 case QSystemTrayIcon::DoubleClick:
63 // TODO show menu 69 show();
64 break; 70 break;
65 default: 71 default:
66 ; 72 ;
67 } 73 }
68 } 74 }
69 75
70 void MainWindow::messageClicked() 76 void MainWindow::messageClicked()
71 { 77 {
72 if (mCurState == NewListAvailable) { 78 if (mCurState == NewListAvailable) {
73 ListUpdateDialog *listUpdateDialog = new ListUpdateDialog(this, 79 show();
74 mListToInstall);
75 listUpdateDialog->show();
76 qDebug() << "NewListAvailable";
77 } 80 }
78 } 81 }
79 82
80 void MainWindow::showMessage() 83 void MainWindow::showMessage()
81 { 84 {
82 if (!mCurMessage.isEmpty()) { 85 if (!isVisible() && !mCurMessage.isEmpty()) {
83 mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage, 86 mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage,
84 QSystemTrayIcon::Information, 5000); 87 QSystemTrayIcon::Information, 5000);
85 mMessageTimer->start(); // Restart the timer so that we don't spam 88 mMessageTimer->start(); // Restart the timer so that we don't spam
86 } 89 }
87 } 90 }
245 QVBoxLayout *toolLayout = new QVBoxLayout; 248 QVBoxLayout *toolLayout = new QVBoxLayout;
246 QHBoxLayout *bottomLayout = new QHBoxLayout; 249 QHBoxLayout *bottomLayout = new QHBoxLayout;
247 250
248 // The certificate list 251 // The certificate list
249 QGroupBox *certBox = new QGroupBox(tr("Managed Certificates")); 252 QGroupBox *certBox = new QGroupBox(tr("Managed Certificates"));
250 certificateList = new QListWidget; 253 mCertListWidget = new QListWidget;
251 certificateList->setItemDelegate(new CertificateItemDelegate); 254 mCertListWidget->setItemDelegate(new CertificateItemDelegate);
252 connect(certificateList, SIGNAL(itemClicked(QListWidgetItem*)), 255 connect(mCertListWidget, SIGNAL(itemClicked(QListWidgetItem*)),
253 this, SLOT(showDetails(QListWidgetItem*))); 256 this, SLOT(showDetails(QListWidgetItem*)));
254 certLayout->addWidget(certificateList); 257 certLayout->addWidget(mCertListWidget);
255 certBox->setLayout(certLayout); 258 certBox->setLayout(certLayout);
256 259
257 // The header (icon, about text) 260 // The header (icon, about text)
258 QImage *logoImage = new QImage(":/img/logo.png"); 261 QImage *logoImage = new QImage(":/img/logo.png");
259 QLabel *logo = new QLabel; 262 QLabel *logo = new QLabel;
276 // The buttons. 279 // The buttons.
277 bottomLayout->setAlignment(Qt::AlignBottom); 280 bottomLayout->setAlignment(Qt::AlignBottom);
278 installButton = new QPushButton(tr("Install selected")); 281 installButton = new QPushButton(tr("Install selected"));
279 installButton->setFixedHeight(80); 282 installButton->setFixedHeight(80);
280 connect(installButton, SIGNAL(clicked()), this, SLOT(resizeButtons())); 283 connect(installButton, SIGNAL(clicked()), this, SLOT(resizeButtons()));
284 connect(installButton, SIGNAL(clicked()), this, SLOT(installCerts()));
281 quitButton = new QPushButton(tr("Quit")); 285 quitButton = new QPushButton(tr("Quit"));
282 quitButton->setFixedHeight(20); 286 quitButton->setFixedHeight(20);
283 connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); 287 connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
284 bottomLayout->insertStretch(0, 10); 288 bottomLayout->insertStretch(0, 10);
285 bottomLayout->addWidget(installButton); 289 bottomLayout->addWidget(installButton);
311 } 315 }
312 316
313 void MainWindow::loadCertificateList() 317 void MainWindow::loadCertificateList()
314 { 318 {
315 qDebug() << "display certificates"; 319 qDebug() << "display certificates";
316 certificateList->clear(); 320 mCertListWidget->clear();
317 int i = 0; 321 int i = 0;
318 foreach (const Certificate &cert, mListToInstall.getCertificates()) { 322 foreach (const Certificate &cert, mListToInstall.getCertificates()) {
319 if (!cert.isValid()) { 323 if (!cert.isValid()) {
320 qWarning() << "Invalid certificate in list"; 324 qWarning() << "Invalid certificate in list";
321 continue; 325 continue;
335 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); 339 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
336 item->setCheckState(Qt::Checked); 340 item->setCheckState(Qt::Checked);
337 } 341 }
338 if (i == 3) { 342 if (i == 3) {
339 QListWidgetItem *sep = new QListWidgetItem("New certificates"); 343 QListWidgetItem *sep = new QListWidgetItem("New certificates");
340 certificateList->setItemDelegateForRow(i, separator); 344 mCertListWidget->setItemDelegateForRow(i, separator);
341 certificateList->addItem(sep); 345 mCertListWidget->addItem(sep);
342 i++; 346 i++;
343 } 347 }
344 } 348 }
345 else { 349 else {
346 // This if statements is for testing! @TODO Remove this! 350 // This if statements is for testing! @TODO Remove this!
352 else { 356 else {
353 item->setData(Qt::UserRole + 1, Certificate::RemoveOld); 357 item->setData(Qt::UserRole + 1, Certificate::RemoveOld);
354 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); 358 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
355 } 359 }
356 } 360 }
357 certificateList->addItem(item); 361 mCertListWidget->addItem(item);
358 i++; 362 i++;
359 } 363 }
360 } 364 }
361 365
362 void MainWindow::showSettings() 366 void MainWindow::showSettings()
385 about->show(); 389 about->show();
386 } 390 }
387 391
388 void MainWindow::showDetails(QListWidgetItem *item) 392 void MainWindow::showDetails(QListWidgetItem *item)
389 { 393 {
390 qDebug() << "show details";
391 QString details = item->data(Qt::UserRole).toString(); 394 QString details = item->data(Qt::UserRole).toString();
392 details.append("\rInstalled: 1.1.1971\rRemoved: 1.1.1971");
393 certificateDetails->setPlainText(details); 395 certificateDetails->setPlainText(details);
394 } 396 }
395 397
396 void MainWindow::resizeButtons() 398 void MainWindow::resizeButtons()
397 { 399 {
398 installButton->setFixedHeight(20); 400 installButton->setFixedHeight(20);
399 quitButton->setFixedHeight(80); 401 quitButton->setFixedHeight(80);
400 } 402 }
403
404 void MainWindow::installerError(const QString& errMsg) {
405 QMessageBox::warning(this, tr("Error executing update"), errMsg);
406 }
407
408 void MainWindow::installCerts() {
409 QStringList choices;
410
411 for (int i = 0; i < mCertListWidget->count(); i++) {
412 QListWidgetItem *item = mCertListWidget->item(i);
413 if (item->checkState() == Qt::Checked) {
414 choices << item->data(Qt::UserRole).toString();
415 continue;
416 }
417 QString certLine = item->data(Qt::UserRole).toString();
418 if (certLine.startsWith("I:")) {
419 certLine[0] = 'R';
420 choices << certLine;
421 }
422 }
423
424 QProgressDialog *progress = new QProgressDialog(this);
425 progress->setWindowModality(Qt::WindowModal);
426 progress->setLabelText(tr("Installing certificates..."));
427 progress->setCancelButton(0);
428 progress->setRange(0,0);
429 progress->setMinimumDuration(0);
430 progress->show();
431
432 InstallWrapper *instWrap = new InstallWrapper(this,
433 mListToInstall.fileName(),
434 choices);
435 /* Clean up object and progress dialog */
436 connect(instWrap, SIGNAL(finished()), instWrap, SLOT(deleteLater()));
437 connect(instWrap, SIGNAL(finished()), progress, SLOT(deleteLater()));
438 connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel()));
439 connect(instWrap, SIGNAL(error(const QString &)),
440 this, SLOT(installerError(const QString &)));
441 instWrap->start();
442
443 }

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