From ee787dab46b8921e3db7c3c7f911f8f3d40b3b5e Mon Sep 17 00:00:00 2001 From: codestation Date: Fri, 3 Jan 2014 00:57:07 -0430 Subject: [PATCH] Added support for native KDE notifier icon. --- qcma.pro | 10 +++++++ resources/translations/qcma.es.ts | 47 +++++++++++++++++++------------ resources/translations/qcma.ja.ts | 47 +++++++++++++++++++------------ src/kdenotifier.cpp | 25 ++++++++++++++++ src/kdenotifier.h | 41 +++++++++++++++++++++++++++ src/mainwidget.cpp | 43 ++++++++++++++++++++++++++-- src/mainwidget.h | 9 ++++++ 7 files changed, 184 insertions(+), 38 deletions(-) create mode 100644 src/kdenotifier.cpp create mode 100644 src/kdenotifier.h diff --git a/qcma.pro b/qcma.pro index 7e5e6ff..10de49d 100644 --- a/qcma.pro +++ b/qcma.pro @@ -122,6 +122,16 @@ unix { unix:!macx:DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE +unix:!macx:ENABLE_KDE { + greaterThan(QT_MAJOR_VERSION, 4) { + error("ENABLE_KDE can only be used with Qt4") + } + LIBS += -lkdeui + DEFINES += "ENABLE_KDE_NOTIFIER=1" + SOURCES += src/kdenotifier.cpp + HEADERS += src/kdenotifier.h +} + win32:RC_FILE = qcma.rc win32:QMAKE_CXXFLAGS += -mno-ms-bitfields diff --git a/resources/translations/qcma.es.ts b/resources/translations/qcma.es.ts index 5f0f9c5..4f5542c 100644 --- a/resources/translations/qcma.es.ts +++ b/resources/translations/qcma.es.ts @@ -1,6 +1,6 @@ - + BackupItem @@ -134,7 +134,7 @@ CmaClient Connected to - Conectado a + Conectado a @@ -316,8 +316,8 @@ FilterLineEdit - - + + Filter Filtro @@ -325,37 +325,38 @@ MainWidget - + Shutting down... Cerrando... - + Stopping QCMA... Deteniendo QCMA... - + + Disconnected Desconectado - + The device has been disconnected El dispositivo se ha desconectado - + About QCMA Acerca de QCMA - + Copyright (C) 2013 Codestation Copyright (C) 2013 Codestation - + Copyright (C) 2013 Codestation build hash: %1 @@ -366,17 +367,22 @@ Hash de compilación: %1 Rama de compilación: %2 - + &About QCMA &Acerca de QCMA + + + Qcma - Information + Qcma - Información + Copyright (C) 2013 Codestation Copyright (C) 2013 Codestation\n - + &Backup Manager &Gestor de Respaldos @@ -385,7 +391,7 @@ Rama de compilación: %2 &Acerca de - + Abou&t Qt A&cerca de Qt @@ -394,12 +400,12 @@ Rama de compilación: %2 PIN recibido: %1 - + &Settings &Ajustes - + &Refresh database &Refrescar base de datos @@ -408,12 +414,17 @@ Rama de compilación: %2 Gestor de Respaldos - + &Quit &Salir - + + Qcma status + Estado de Qcma + + + Information Información diff --git a/resources/translations/qcma.ja.ts b/resources/translations/qcma.ja.ts index 1dad9d2..d4899eb 100644 --- a/resources/translations/qcma.ja.ts +++ b/resources/translations/qcma.ja.ts @@ -1,6 +1,6 @@ - + BackupItem @@ -134,7 +134,7 @@ CmaClient Connected to - 次のデバイスに接続しました + 次のデバイスに接続しました @@ -317,8 +317,8 @@ FilterLineEdit - - + + Filter @@ -326,37 +326,38 @@ MainWidget - + Shutting down... 終了しています... - + Stopping QCMA... QCMAを停止しています... - + + Disconnected 切断されました - + The device has been disconnected デバイスが切断されました - + About QCMA - + Copyright (C) 2013 Codestation - + Copyright (C) 2013 Codestation build hash: %1 @@ -364,31 +365,36 @@ build branch: %2 - + &Backup Manager - + &About QCMA - + Abou&t Qt + + + Qcma - Information + + Received PIN: %1 受信したPIN: %1 - + &Settings &設定 - + &Refresh database &データベースを更新する @@ -397,12 +403,17 @@ build branch: %2 バックアップマネージャー - + &Quit &終了 - + + Qcma status + + + + Information 情報 diff --git a/src/kdenotifier.cpp b/src/kdenotifier.cpp new file mode 100644 index 0000000..cc5940f --- /dev/null +++ b/src/kdenotifier.cpp @@ -0,0 +1,25 @@ +/* + * QCMA: Cross-platform content manager assistant for the PS Vita + * + * Copyright (C) 2014 Codestation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "kdenotifier.h" + +KDENotifier::KDENotifier(const QString &id, QObject *parent) : + KStatusNotifierItem(id, parent) +{ +} diff --git a/src/kdenotifier.h b/src/kdenotifier.h new file mode 100644 index 0000000..abc87b4 --- /dev/null +++ b/src/kdenotifier.h @@ -0,0 +1,41 @@ +/* + * QCMA: Cross-platform content manager assistant for the PS Vita + * + * Copyright (C) 2014 Codestation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KDENOTIFIER_H +#define KDENOTIFIER_H + +#include +#include + +class KDENotifier : public KStatusNotifierItem +{ + Q_OBJECT +public: + explicit KDENotifier(const QString &id, QObject *parent = 0); + +signals: + +public slots: + // block left click because it shows the default widget + virtual void activate (const QPoint &pos=QPoint()) { + Q_UNUSED(pos); + } +}; + +#endif // KDENOTIFIER_H diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index ef9f230..a334d3f 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -34,6 +34,10 @@ #include #include +#ifdef ENABLE_KDE_NOTIFIER +#include +#endif + const QStringList MainWidget::path_list = QStringList() << "photoPath" << "musicPath" << "videoPath" << "appsPath" << "urlPath"; bool sleptOnce = false; @@ -79,10 +83,14 @@ void MainWidget::stopServer() void MainWidget::deviceDisconnect() { +#ifndef ENABLE_KDE_NOTIFIER #ifndef Q_OS_WIN32 trayIcon->setIcon(QIcon(":/main/resources/images/psv_icon_dc.png")); #else trayIcon->setIcon(QIcon(":/main/resources/images/psv_icon_16_dc.png")); +#endif +#else + notifierItem->setIconByPixmap(QIcon(":/main/resources/images/psv_icon_dc.png")); #endif qDebug("Icon changed - disconnected"); setTrayTooltip(tr("Disconnected")); @@ -91,10 +99,14 @@ void MainWidget::deviceDisconnect() void MainWidget::deviceConnected(QString message) { +#ifndef ENABLE_KDE_NOTIFIER #ifndef Q_OS_WIN32 trayIcon->setIcon(QIcon(":/main/resources/images/psv_icon.png")); #else trayIcon->setIcon(QIcon(":/main/resources/images/psv_icon_16.png")); +#endif +#else + notifierItem->setIconByPixmap(QIcon(":/main/resources/images/psv_icon.png")); #endif qDebug("Icon changed - connected"); setTrayTooltip(message); @@ -121,7 +133,11 @@ void MainWidget::connectSignals() void MainWidget::setTrayTooltip(QString message) { +#ifndef ENABLE_KDE_NOTIFIER trayIcon->setToolTip(message); +#else + notifierItem->setToolTipSubTitle(message); +#endif } void MainWidget::openManager() @@ -175,7 +191,12 @@ void MainWidget::createTrayIcon() connect(about_qt, SIGNAL(triggered()), this, SLOT(showAboutQt())); connect(quit, SIGNAL(triggered()), this, SLOT(stopServer())); +#ifndef ENABLE_KDE_NOTIFIER QMenu *trayIconMenu = new QMenu(this); +#else + KMenu *trayIconMenu = new KMenu(this); +#endif + trayIconMenu->addAction(options); trayIconMenu->addAction(reload); trayIconMenu->addAction(backup); @@ -185,6 +206,7 @@ void MainWidget::createTrayIcon() trayIconMenu->addSeparator(); trayIconMenu->addAction(quit); +#ifndef ENABLE_KDE_NOTIFIER trayIcon = new QSystemTrayIcon(this); trayIcon->setContextMenu(trayIconMenu); #ifndef Q_OS_WIN32 @@ -193,8 +215,18 @@ void MainWidget::createTrayIcon() trayIcon->setIcon(QIcon(":/main/resources/images/psv_icon_16_dc.png")); #endif trayIcon->show(); - // try to avoid the iconTray Qt bug - //Sleeper::sleep(1); +#else + notifierItem = new KDENotifier("QcmaNotifier", this); + notifierItem->setContextMenu(trayIconMenu); + notifierItem->setTitle("Qcma"); + notifierItem->setCategory(KStatusNotifierItem::ApplicationStatus); + notifierItem->setIconByPixmap(QIcon(":/main/resources/images/psv_icon_dc.png")); + notifierItem->setStatus(KStatusNotifierItem::Active); + notifierItem->setToolTipTitle(tr("Qcma status")); + notifierItem->setToolTipIconByPixmap(QIcon(":/main/resources/images/qcma.png")); + notifierItem->setToolTipSubTitle(tr("Disconnected")); + notifierItem->setStandardActionsEnabled(false); +#endif } void MainWidget::receiveMessage(QString message) @@ -206,12 +238,19 @@ void MainWidget::receiveMessage(QString message) sleptOnce = true; } +#ifndef ENABLE_KDE_NOTIFIER if(trayIcon->isVisible()) { trayIcon->showMessage(tr("Information"), message); } +#else + notifierItem->showMessage(tr("Qcma - Information"), message, "dialog-information", 3000); +#endif + } MainWidget::~MainWidget() { +#ifndef ENABLE_KDE_NOTIFIER trayIcon->hide(); +#endif } diff --git a/src/mainwidget.h b/src/mainwidget.h index 605b26f..2d0080f 100644 --- a/src/mainwidget.h +++ b/src/mainwidget.h @@ -28,7 +28,11 @@ #include #include + #include +#ifdef ENABLE_KDE_NOTIFIER +#include "kdenotifier.h" +#endif #include @@ -60,7 +64,12 @@ private: QAction *backup; QAction *about; QAction *about_qt; + +#ifndef ENABLE_KDE_NOTIFIER QSystemTrayIcon *trayIcon; +#else + KDENotifier *notifierItem; +#endif const static QStringList path_list;