From a8f080968cb0c2dd1bf1affca161f44a6a137696 Mon Sep 17 00:00:00 2001 From: Weixuan XIAO Date: Sat, 16 Nov 2019 13:13:21 +0100 Subject: [PATCH] Indicator helper ready --- indicator/indicatorhelper.cpp | 54 ++++++++++++++++++++++++----------- indicator/indicatorhelper.h | 25 ++++++++++++++-- indicator/main.cpp | 11 ++++--- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/indicator/indicatorhelper.cpp b/indicator/indicatorhelper.cpp index e6da952c5..0b00b1afc 100644 --- a/indicator/indicatorhelper.cpp +++ b/indicator/indicatorhelper.cpp @@ -18,6 +18,18 @@ * along with this program. If not, see . */ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + #include "indicatorhelper.h" IndicatorHelper::IndicatorHelper() {} @@ -29,18 +41,22 @@ void IndicatorHelper::postInit() {} void IndicatorHelper::iconPathHook() {} -void IndicatorHelper::dbusHook() {} +void IndicatorHelper::daemonHook(QProcess &kdeconnectd) +{ + Q_UNUSED(kdeconnectd); +} -void IndicatorHelper::qSystemTrayIconHook(QSystemTrayIcon &systray) +#ifdef QSYSTRAY +void IndicatorHelper::systrayIconHook(QSystemTrayIcon &systray) { systray.setIcon(QIcon::fromTheme(QStringLiteral("kdeconnectindicatordark"))); } - -void IndicatorHelper::kStatusNotifierItemHook(KStatusNotifierItem &systray) +#else +void IndicatorHelper::systrayIconHook(KStatusNotifierItem &systray) { systray.setIconByName(QStringLiteral("kdeconnectindicatordark")); } - +#endif MacOSIndicatorHelper::MacOSIndicatorHelper() { @@ -54,10 +70,6 @@ MacOSIndicatorHelper::MacOSIndicatorHelper() MacOSIndicatorHelper::~MacOSIndicatorHelper() {} -void MacOSIndicatorHelper::preInit() {} - -void MacOSIndicatorHelper::postInit() {} - void MacOSIndicatorHelper::iconPathHook() { const QString iconPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("icons"), QStandardPaths::LocateDirectory); @@ -76,7 +88,6 @@ void MacOSIndicatorHelper::daemonHook(QProcess &kdeconnectd) // Start kdeconnectd m_splashScreen->showMessage(i18n("Launching daemon") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white); - QProcess kdeconnectd; if (QFile::exists(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd"))) { kdeconnectd.startDetached(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd")); } else if (QFile::exists(QString::fromLatin1(qgetenv("craftRoot")) + QStringLiteral("/../lib/libexec/kdeconnectd"))) { @@ -86,7 +97,6 @@ void MacOSIndicatorHelper::daemonHook(QProcess &kdeconnectd) i18n("Cannot find kdeconnectd"), QMessageBox::Abort, QMessageBox::Abort); - return -1; } // Wait for dbus daemon env @@ -115,8 +125,6 @@ void MacOSIndicatorHelper::daemonHook(QProcess &kdeconnectd) "KDE Connect will quit"), QMessageBox::Abort, QMessageBox::Abort); - - return -1; } else { QThread::sleep(3); // Retry after 3s retry++; @@ -126,8 +134,15 @@ void MacOSIndicatorHelper::daemonHook(QProcess &kdeconnectd) m_splashScreen->showMessage(i18n("Loading modules") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white); } -void MacOSIndicatorHelper::kStatusNotifierItemHook(KStatusNotifierItem &systray) +#ifdef QSYSTRAY +void MacOSIndicatorHelper::systrayIconHook(QSystemTrayIcon &systray) { + Q_UNUSED(systray); +} +#else +void MacOSIndicatorHelper::systrayIconHook(KStatusNotifierItem &systray) +{ + const QString iconPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("icons"), QStandardPaths::LocateDirectory); if (!iconPath.isNull()) { systray.setIconByName(QStringLiteral("kdeconnectindicatordark")); } else { @@ -135,6 +150,7 @@ void MacOSIndicatorHelper::kStatusNotifierItemHook(KStatusNotifierItem &systray) qWarning() << "Fail to find indicator icon, continue anyway"; } } +#endif WindowsIndicatorHelper::WindowsIndicatorHelper() {} WindowsIndicatorHelper::~WindowsIndicatorHelper() {} @@ -144,8 +160,14 @@ void WindowsIndicatorHelper::daemonHook(QProcess &kdeconnectd) kdeconnectd.start(QStringLiteral("kdeconnectd.exe")); } -void WindowsIndicatorHelper::qSystemTrayIconHook(QSystemTrayIcon &systray) +#ifdef QSYSTRAY +void WindowsIndicatorHelper::systrayIconHook(QSystemTrayIcon &systray) { systray.setIcon(QIcon(QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("icons/hicolor/scalable/apps/kdeconnectindicatorwin.svg")))); } - +#else +void WindowsIndicatorHelper::systrayIconHook(KStatusNotifierItem &systray) +{ + Q_UNUSED(systray); +} +#endif diff --git a/indicator/indicatorhelper.h b/indicator/indicatorhelper.h index 78342d6e0..26ddca48b 100644 --- a/indicator/indicatorhelper.h +++ b/indicator/indicatorhelper.h @@ -40,8 +40,11 @@ public: virtual void daemonHook(QProcess &kdeconnectd); - virtual void qSystemTrayIconHook(QSystemTrayIcon &systray); - virtual void kStatusNotifierItemHook(KStatusNotifierItem &systray); +#ifdef QSYSTRAY + virtual void systrayIconHook(QSystemTrayIcon &systray); +#else + virtual void systrayIconHook(KStatusNotifierItem &systray); +#endif }; @@ -50,6 +53,16 @@ class MacOSIndicatorHelper : public IndicatorHelper public: MacOSIndicatorHelper(); ~MacOSIndicatorHelper(); + + void iconPathHook(); + + void daemonHook(QProcess &kdeconnectd); + +#ifdef QSYSTRAY + void systrayIconHook(QSystemTrayIcon &systray); +#else + void systrayIconHook(KStatusNotifierItem &systray); +#endif private: QSplashScreen *m_splashScreen; }; @@ -60,4 +73,12 @@ class WindowsIndicatorHelper : public IndicatorHelper public: WindowsIndicatorHelper(); ~WindowsIndicatorHelper(); + + void daemonHook(QProcess &kdeconnectd); + +#ifdef QSYSTRAY + void systrayIconHook(QSystemTrayIcon &systray); +#else + void systrayIconHook(KStatusNotifierItem &systray); +#endif }; diff --git a/indicator/main.cpp b/indicator/main.cpp index 57d08f7d8..a09b4ff7c 100644 --- a/indicator/main.cpp +++ b/indicator/main.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #ifdef QSYSTRAY #include @@ -56,9 +55,9 @@ int main(int argc, char** argv) IndicatorHelper *helper; #ifdef Q_OS_WIN - -#elif (defined Q_OS_MAC) - + helper = new WindowsIndicatorHelper(); +#elif defined Q_OS_MAC + helper = new MacOSIndicatorHelper(); #else helper = new IndicatorHelper(); #endif @@ -130,7 +129,7 @@ int main(int argc, char** argv) #ifdef QSYSTRAY QSystemTrayIcon systray; - helper->qSystemTrayIconHook(systray); + helper->systrayIconHook(systray); systray.setVisible(true); systray.setToolTip(QStringLiteral("KDE Connect")); QObject::connect(&model, &DevicesModel::rowsChanged, &model, [&systray, &model]() { @@ -140,7 +139,7 @@ int main(int argc, char** argv) systray.setContextMenu(menu); #else KStatusNotifierItem systray; - helper->kStatusNotifierItemHook(systray); + helper->systrayIconHook(systray); systray.setToolTip(QStringLiteral("kdeconnect"), QStringLiteral("KDE Connect"), QStringLiteral("KDE Connect")); systray.setCategory(KStatusNotifierItem::Communications); systray.setStatus(KStatusNotifierItem::Passive);