# HG changeset patch # User Andre Heinecke # Date 1407341003 -7200 # Node ID 4efd6378c0014dfaa0fa295a8e2a99861e00c1d1 # Parent e93ae52332172398bb834b63e2dd5368c0bee693 (issue51) Add fallback in case systemtray is unavailable. If no systemtray is available it will now show a message box as notification. diff -r e93ae5233217 -r 4efd6378c001 ui/CMakeLists.txt --- a/ui/CMakeLists.txt Wed Aug 06 11:55:02 2014 +0200 +++ b/ui/CMakeLists.txt Wed Aug 06 18:03:23 2014 +0200 @@ -41,6 +41,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/processwaitdialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/textoverlaybutton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/taskscheduler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/trayicon.cpp ${CERTIFICATELIST_SOURCES} ${DOWNLOADER_SOURCES} ) diff -r e93ae5233217 -r 4efd6378c001 ui/main.cpp --- a/ui/main.cpp Wed Aug 06 11:55:02 2014 +0200 +++ b/ui/main.cpp Wed Aug 06 18:03:23 2014 +0200 @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -107,7 +106,7 @@ QLocale::system().name(); } app.installTranslator(&translator); - +/* if ((!QSystemTrayIcon::isSystemTrayAvailable() || !QSystemTrayIcon::supportsMessages()) && trayMode) { QMessageBox::critical(0, QString::fromLatin1(APPNAME), @@ -116,7 +115,7 @@ "be used in a desktop environment.")); return 1; } - +*/ #ifdef Q_OS_WIN { TaskScheduler taskSched; diff -r e93ae5233217 -r 4efd6378c001 ui/mainwindow.cpp --- a/ui/mainwindow.cpp Wed Aug 06 11:55:02 2014 +0200 +++ b/ui/mainwindow.cpp Wed Aug 06 18:03:23 2014 +0200 @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -42,6 +41,7 @@ #include "binverify.h" #include "processhelp.h" #include "processwaitdialog.h" +#include "trayicon.h" // The amount of time in minutes stay silent if we have // something to say @@ -233,7 +233,11 @@ /* Retry the download again in 10 - 20 minutes */ QTimer::singleShot(600000 + (qrand() % 60000), this, SLOT(checkUpdates())); } else { - mCurMessage = tr("An updated certificate list is available. Click here to install."); + if (mTrayIcon->isAlternative()) { + mCurMessage = tr("An updated certificate list is available."); + } else { + mCurMessage = tr("An updated certificate list is available.") +" " + tr("Click here to install."); + } setState(NewListAvailable); showMessage(); loadCertificateList(); @@ -241,9 +245,14 @@ } void MainWindow::handleNewSW(const QString& fileName, const QDateTime& modDate) { - mCurMessage = tr("An update for %1 is available.\n" - "Click here to download and install the update.").arg( + if (mTrayIcon->isAlternative()) { + mCurMessage = tr("An update for %1 is available.").arg( QApplication::applicationName()); + } else { + mCurMessage = QString(tr("An update for %1 is available.") + "\n" + + tr("Click here to download and install the update.")).arg( + QApplication::applicationName()); + } setState(NewSoftwareAvailable); mSettings.setValue("Software/available", fileName); mSettings.setValue("Software/availableDate", modDate); @@ -437,7 +446,7 @@ mTrayMenu->addAction(mCheckUpdates); mTrayMenu->addAction(mQuitAction); - mTrayIcon = new QSystemTrayIcon(this); + mTrayIcon = new TrayIcon(this); mTrayIcon->setContextMenu(mTrayMenu); mTrayIcon->setIcon(trayImg); diff -r e93ae5233217 -r 4efd6378c001 ui/mainwindow.h --- a/ui/mainwindow.h Wed Aug 06 11:55:02 2014 +0200 +++ b/ui/mainwindow.h Wed Aug 06 18:03:23 2014 +0200 @@ -13,7 +13,6 @@ * @brief Main UI controller */ -#include #include #include #include @@ -28,6 +27,7 @@ #include "certificatelist.h" #include "certificatelistwidget.h" #include "textoverlaybutton.h" +#include "trayicon.h" class QMenu; class QAction; class QTimer; @@ -219,7 +219,7 @@ QSettings mSettings; - QSystemTrayIcon *mTrayIcon; + TrayIcon *mTrayIcon; QTimer *mMessageTimer; QMenu *mTrayMenu; QAction *mCheckUpdates; diff -r e93ae5233217 -r 4efd6378c001 ui/trayicon.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/trayicon.cpp Wed Aug 06 18:03:23 2014 +0200 @@ -0,0 +1,51 @@ +/* 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 "trayicon.h" + +#include +#include +#include +#include +#include + +TrayIcon::TrayIcon (QObject *parent) : + QSystemTrayIcon (parent), + useAlt(false) +{ + if (QSystemTrayIcon::isSystemTrayAvailable() && + qgetenv("XDG_CURRENT_DESKTOP") != "Unity") { + return; + } + qDebug() << "Platform is without systray. Using Alternative notifications"; + useAlt = true; + +} + +void TrayIcon::show() { + if (useAlt) { + qDebug() << "Would show"; + return; + } + QSystemTrayIcon::show(); +} + +void TrayIcon::showMessage(const QString &title, const QString &msg, + QSystemTrayIcon::MessageIcon msg_icon, int msecs) { + if (!useAlt) { + QSystemTrayIcon::showMessage(title, msg, msg_icon, msecs); + return; + } + QMessageBox *theMessage = new QMessageBox (QMessageBox::Information, + title, msg, QMessageBox::Ok | QMessageBox::No, qobject_cast(parent())); + theMessage->setIconPixmap (icon().pixmap(theMessage->iconPixmap().size())); + theMessage->button(QMessageBox::Ok)->setText (tr("Install update")); + theMessage->button(QMessageBox::No)->setText (tr("Remind me later")); + connect(theMessage->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked())); + theMessage->show(); +} diff -r e93ae5233217 -r 4efd6378c001 ui/trayicon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/trayicon.h Wed Aug 06 18:03:23 2014 +0200 @@ -0,0 +1,39 @@ +#ifndef TRAYICON_H +#define TRAYICON_H +/* 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 +#include + + +/**@brief Notification interface. + * + * This class provides an inherited implmentation of QSystemTrayIcon + * to be more flexible on platforms where no SystemTray is available. + * + * This class should become obsolete once Qt improves the support for + * StatusNotifier icons that are used in Plasma 5 and Unity. + */ +class TrayIcon : public QSystemTrayIcon +{ + Q_OBJECT +public: + TrayIcon (QObject *parent); + + void show(); + bool isAlternative() {return useAlt;} + +public Q_SLOTS: + void showMessage(const QString &title, const QString &msg, + QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 10000); +private: + bool useAlt; +}; + +#endif // TRAYICON_H