comparison ui/mainwindow.cpp @ 978:d92b1594e974

Merged.
author Emanuel Schuetze <emanuel@intevation.de>
date Fri, 29 Aug 2014 13:10:11 +0200
parents c80777457133
children b8ae69bcc540
comparison
equal deleted inserted replaced
977:9ad1f18799fb 978:d92b1594e974
41 #include "logging.h" 41 #include "logging.h"
42 #include "binverify.h" 42 #include "binverify.h"
43 #include "processhelp.h" 43 #include "processhelp.h"
44 #include "processwaitdialog.h" 44 #include "processwaitdialog.h"
45 #include "trayicon.h" 45 #include "trayicon.h"
46 #include "proxysettingsdlg.h"
46 47
47 // The amount of time in minutes stay silent if we have 48 // The amount of time in minutes stay silent if we have
48 // something to say 49 // something to say
49 #define NAG_INTERVAL_MINUTES 70 50 #define NAG_INTERVAL_MINUTES 70
50 51
131 } 132 }
132 } 133 }
133 134
134 void MainWindow::messageClicked() 135 void MainWindow::messageClicked()
135 { 136 {
136 if (mCurState == NewListAvailable) {
137 show();
138 }
139
140 if (mCurState == NewSoftwareAvailable) { 137 if (mCurState == NewSoftwareAvailable) {
141 hide(); 138 hide();
142 verifySWData(); 139 verifySWData();
143 QString swFileName = mSettings.value("Software/available").toString(); 140 QString swFileName = mSettings.value("Software/available").toString();
144 if (swFileName.isEmpty()) { 141 if (swFileName.isEmpty()) {
146 mCurState = DownloadingSW; 143 mCurState = DownloadingSW;
147 return; 144 return;
148 } 145 }
149 installNewSW(swFileName, 146 installNewSW(swFileName,
150 mSettings.value("Software/availableDate").toDateTime()); 147 mSettings.value("Software/availableDate").toDateTime());
148 } else {
149 show();
151 } 150 }
152 } 151 }
153 152
154 void MainWindow::showMessage() 153 void MainWindow::showMessage()
155 { 154 {
156 if (mCurMessage.isEmpty()) { 155 if (mCurMessage.isEmpty()) {
157 return; 156 return;
158 } 157 }
159 if (mCurState == NewSoftwareAvailable || !isVisible()) { 158
159 if (!mTrayIcon->isVisible() && !mTrayIcon->isAlternative()) {
160 mTrayIcon->show();
161 /* When the message is shown before the tray icon is fully visble
162 * and becoming visible may be delayed on some desktop environments
163 * the message will pop up somehere on the screen and not over
164 * the trayicon. So we delay here.*/
165 QTimer::singleShot(2000, this, SLOT(showMessage()));
166 } else if (mCurState == NewSoftwareAvailable || !isVisible()) {
160 mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage, 167 mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage,
161 QSystemTrayIcon::Information, 10000); 168 QSystemTrayIcon::Information, 10000);
162 mMessageTimer->start(); // Restart the timer so that we don't spam 169 mMessageTimer->start(); // Restart the timer so that we don't spam
163 } 170 }
164 } 171 }
443 void MainWindow::downloaderError(const QString &message, SSLConnection::ErrorCode error) 450 void MainWindow::downloaderError(const QString &message, SSLConnection::ErrorCode error)
444 { 451 {
445 /* TODO logging and handle error according to a plan */ 452 /* TODO logging and handle error according to a plan */
446 syslog_error_printf ("Failed to check for updates: %s", message.toUtf8().constData()); 453 syslog_error_printf ("Failed to check for updates: %s", message.toUtf8().constData());
447 mCurMessage = message; 454 mCurMessage = message;
455 mTrayIcon->show();
448 showMessage(); 456 showMessage();
449 setState(TransferError); 457 setState(TransferError);
450 } 458 }
451 459
452 void MainWindow::createActions() 460 void MainWindow::createActions()
458 } 466 }
459 467
460 void MainWindow::createTrayIcon() 468 void MainWindow::createTrayIcon()
461 { 469 {
462 QIcon trayImg(":/img/tray_22.png"); 470 QIcon trayImg(":/img/tray_22.png");
471 trayImg.addFile(":/img/tray_48.png", QSize(48,48));
463 472
464 mTrayMenu = new QMenu(this); 473 mTrayMenu = new QMenu(this);
465 mTrayMenu->addAction(mCheckUpdates); 474 mTrayMenu->addAction(mCheckUpdates);
466 mTrayMenu->addAction(mQuitAction); 475 mTrayMenu->addAction(mQuitAction);
467 476
468 mTrayIcon = new TrayIcon(this); 477 mTrayIcon = new TrayIcon(this);
469 mTrayIcon->setContextMenu(mTrayMenu); 478 mTrayIcon->setContextMenu(mTrayMenu);
470 479
471 mTrayIcon->setIcon(trayImg); 480 mTrayIcon->setIcon(trayImg);
472 setWindowIcon(trayImg); 481 setWindowIcon(trayImg);
473 mTrayIcon->show();
474 mTrayIcon->setToolTip(tr("TrustBridge")); 482 mTrayIcon->setToolTip(tr("TrustBridge"));
475 483
476 connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); 484 connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
477 } 485 }
478 486
524 infoCenterLayout->insertSpacing(4, 10); 532 infoCenterLayout->insertSpacing(4, 10);
525 infoCenterLayout->insertSpacing(6, 10); 533 infoCenterLayout->insertSpacing(6, 10);
526 534
527 QHBoxLayout *helpButtonLayout = new QHBoxLayout(); 535 QHBoxLayout *helpButtonLayout = new QHBoxLayout();
528 QPushButton *helpButton = new QPushButton(tr("Show Help")); 536 QPushButton *helpButton = new QPushButton(tr("Show Help"));
537 helpButton->setIcon(QIcon(":/img/show-help_16.png"));
529 connect(helpButton, SIGNAL(clicked()), this, SLOT(showHelp())); 538 connect(helpButton, SIGNAL(clicked()), this, SLOT(showHelp()));
530 helpButtonLayout->addWidget(helpButton); 539 helpButtonLayout->addWidget(helpButton);
540 #ifdef USE_CURL
541 QPushButton *proxySettingsButton = new QPushButton(tr("Proxy settings"));
542 proxySettingsButton->setIcon(QIcon(":/img/preferences-network_16.png"));
543 connect(proxySettingsButton, SIGNAL(clicked()), this, SLOT(showProxySettings()));
544 helpButtonLayout->addWidget(proxySettingsButton);
545 #endif
531 helpButtonLayout->addStretch(); 546 helpButtonLayout->addStretch();
532 infoCenterLayout->addLayout(helpButtonLayout); 547 infoCenterLayout->addLayout(helpButtonLayout);
533 548
534 infoCenterLayout->insertStretch(8, 10); 549 infoCenterLayout->insertStretch(8, 10);
535 550
1361 void MainWindow::closeEvent(QCloseEvent *event) 1376 void MainWindow::closeEvent(QCloseEvent *event)
1362 { 1377 {
1363 if (getState() == NewListAvailable) { 1378 if (getState() == NewListAvailable) {
1364 /* Only minimize to tray if there is a new list */ 1379 /* Only minimize to tray if there is a new list */
1365 QMainWindow::closeEvent(event); 1380 QMainWindow::closeEvent(event);
1381 mTrayIcon->show();
1366 return; 1382 return;
1367 } 1383 }
1368 return closeApp(); 1384 return closeApp();
1369 } 1385 }
1370 1386
1376 mLastUpdateCheckContents->setText(QLocale::system().toString(now, DATETIME_FORMAT)); 1392 mLastUpdateCheckContents->setText(QLocale::system().toString(now, DATETIME_FORMAT));
1377 mLastUpdateCheckContents->show(); 1393 mLastUpdateCheckContents->show();
1378 mLastUpdateCheck->show(); 1394 mLastUpdateCheck->show();
1379 syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData()); 1395 syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData());
1380 } 1396 }
1397 if (getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode) {
1398 qDebug() << "Shutting down as no list or Software is available.";
1399 closeApp();
1400 } else {
1401 mTrayIcon->show();
1402 }
1381 } 1403 }
1382 1404
1383 int MainWindow::changeCount() 1405 int MainWindow::changeCount()
1384 { 1406 {
1385 return mChangeCount; 1407 return mChangeCount;
1389 { 1411 {
1390 if (mChangeCount != cnt) { 1412 if (mChangeCount != cnt) {
1391 mChangeCount = cnt; 1413 mChangeCount = cnt;
1392 emit changesChanged(QString("%1").arg(cnt)); 1414 emit changesChanged(QString("%1").arg(cnt));
1393 } 1415 }
1416 }
1417
1418 void MainWindow::showProxySettings()
1419 {
1420 ProxySettingsDlg *dlg = new ProxySettingsDlg(this);
1421 dlg->exec();
1394 } 1422 }
1395 1423
1396 void MainWindow::showHelp() 1424 void MainWindow::showHelp()
1397 { 1425 {
1398 char *inst_dir = get_install_dir(); 1426 char *inst_dir = get_install_dir();
1406 qDebug() << "Opening help: " << fiHelp.absoluteFilePath(); 1434 qDebug() << "Opening help: " << fiHelp.absoluteFilePath();
1407 if (!fiHelp.exists()) { 1435 if (!fiHelp.exists()) {
1408 QMessageBox::warning(this, tr("Error!"), tr ("Failed to find the manual")); 1436 QMessageBox::warning(this, tr("Error!"), tr ("Failed to find the manual"));
1409 return; 1437 return;
1410 } 1438 }
1439 #ifdef Q_OS_WIN
1440 QDesktopServices::openUrl(QUrl("file:///" + fiHelp.absoluteFilePath()));
1441 #else
1411 QDesktopServices::openUrl(QUrl(fiHelp.absoluteFilePath())); 1442 QDesktopServices::openUrl(QUrl(fiHelp.absoluteFilePath()));
1443 #endif
1412 free (inst_dir); 1444 free (inst_dir);
1413 return; 1445 return;
1414 } 1446 }

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