From 2e79d68ee3f9685216f133dc288c53bf6de7ae2d Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Tue, 24 Mar 2009 21:49:48 +0000 Subject: [PATCH] Moved systray-icon to its own plugin --- telldus-gui/Plugins/Plugins.pro | 1 + telldus-gui/Plugins/Systray/Systray.pro | 21 ++++++++++ .../Systray}/systrayicon.cpp | 2 +- .../Systray}/systrayicon.h | 0 telldus-gui/Plugins/Systray/systrayplugin.cpp | 42 +++++++++++++++++++ telldus-gui/Plugins/Systray/systrayplugin.h | 28 +++++++++++++ telldus-gui/TelldusCenter/TelldusCenter.pro | 13 +++--- telldus-gui/TelldusCenter/main.cpp | 8 +++- telldus-gui/TelldusCenter/mainwindow.cpp | 4 +- .../tellduscenterapplication.cpp | 13 +++--- .../TelldusCenter/tellduscenterapplication.h | 6 +-- 11 files changed, 116 insertions(+), 22 deletions(-) create mode 100644 telldus-gui/Plugins/Systray/Systray.pro rename telldus-gui/{TelldusCenter => Plugins/Systray}/systrayicon.cpp (99%) rename telldus-gui/{TelldusCenter => Plugins/Systray}/systrayicon.h (100%) create mode 100644 telldus-gui/Plugins/Systray/systrayplugin.cpp create mode 100644 telldus-gui/Plugins/Systray/systrayplugin.h diff --git a/telldus-gui/Plugins/Plugins.pro b/telldus-gui/Plugins/Plugins.pro index 14bc3e92..d7a26c19 100644 --- a/telldus-gui/Plugins/Plugins.pro +++ b/telldus-gui/Plugins/Plugins.pro @@ -1,4 +1,5 @@ TEMPLATE=subdirs SUBDIRS = Devices \ + Systray \ TouchInterface diff --git a/telldus-gui/Plugins/Systray/Systray.pro b/telldus-gui/Plugins/Systray/Systray.pro new file mode 100644 index 00000000..7c2616e0 --- /dev/null +++ b/telldus-gui/Plugins/Systray/Systray.pro @@ -0,0 +1,21 @@ +# ------------------------------------------------- +# Project created by QtCreator 2009-03-10T12:16:44 +# ------------------------------------------------- +QT += core \ + gui +TARGET = SystrayIcon +TEMPLATE = lib +CONFIG += plugin +SOURCES += systrayicon.cpp \ + systrayplugin.cpp +HEADERS += systrayplugin.h \ + systrayicon.h +macx { + LIBS += -framework TelldusCore + DESTDIR = ../../TelldusCenter/TelldusCenter.app/Contents/Plugins +} +!macx { + LIBS += -ltelldus-core + DESTDIR = ../../TelldusCenter/Plugins +} + diff --git a/telldus-gui/TelldusCenter/systrayicon.cpp b/telldus-gui/Plugins/Systray/systrayicon.cpp similarity index 99% rename from telldus-gui/TelldusCenter/systrayicon.cpp rename to telldus-gui/Plugins/Systray/systrayicon.cpp index d966edbc..f20f8839 100644 --- a/telldus-gui/TelldusCenter/systrayicon.cpp +++ b/telldus-gui/Plugins/Systray/systrayicon.cpp @@ -1,6 +1,6 @@ #include "systrayicon.h" #include "telldus-core.h" -#include "tellduscenterapplication.h" +//#include "tellduscenterapplication.h" #include #include diff --git a/telldus-gui/TelldusCenter/systrayicon.h b/telldus-gui/Plugins/Systray/systrayicon.h similarity index 100% rename from telldus-gui/TelldusCenter/systrayicon.h rename to telldus-gui/Plugins/Systray/systrayicon.h diff --git a/telldus-gui/Plugins/Systray/systrayplugin.cpp b/telldus-gui/Plugins/Systray/systrayplugin.cpp new file mode 100644 index 00000000..cba088b5 --- /dev/null +++ b/telldus-gui/Plugins/Systray/systrayplugin.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include "systrayplugin.h" + +#include "../../TelldusGui/telldusgui.h" +#include "systrayicon.h" + +class SystrayPluginPrivate { +public: + SystrayIcon *icon; +}; + +SystrayPlugin::SystrayPlugin( ) + : QObject(), + TelldusCenterPlugin() +{ + d = new SystrayPluginPrivate; + d->icon = new SystrayIcon(this); +} + +SystrayPlugin::~SystrayPlugin() { + delete d; +} + +QIcon SystrayPlugin::iconForPage( const QString &page ) const { + return QIcon(":/images/devices.png"); +} + +QString SystrayPlugin::pluginName() const { + return "Systray icon"; +} + +QWidget *SystrayPlugin::widget( const QString &page, QWidget *parent ) const { + return 0; +} + +QStringList SystrayPlugin::widgets() const { + return QStringList(); +} + +Q_EXPORT_PLUGIN2(SystrayInterface, SystrayPlugin) diff --git a/telldus-gui/Plugins/Systray/systrayplugin.h b/telldus-gui/Plugins/Systray/systrayplugin.h new file mode 100644 index 00000000..22c07491 --- /dev/null +++ b/telldus-gui/Plugins/Systray/systrayplugin.h @@ -0,0 +1,28 @@ +#ifndef SYSTRAYPLUGIN_H +#define SYSTRAYPLUGIN_H + +#include +#include +#include "../../TelldusCenter/tellduscenterplugin.h" + +class SystrayPluginPrivate; + +class SystrayPlugin : public QObject, public TelldusCenterPlugin +{ + Q_OBJECT + Q_INTERFACES(TelldusCenterPlugin) +public: + SystrayPlugin( ); + virtual ~SystrayPlugin(); + + virtual QIcon iconForPage( const QString &page ) const; + virtual QString pluginName() const; + + virtual QWidget *widget( const QString &page, QWidget *parent ) const; + virtual QStringList widgets() const; + +private: + SystrayPluginPrivate *d; +}; + +#endif // SYSTRAYPLUGIN_H diff --git a/telldus-gui/TelldusCenter/TelldusCenter.pro b/telldus-gui/TelldusCenter/TelldusCenter.pro index 80516124..6e004ffd 100644 --- a/telldus-gui/TelldusCenter/TelldusCenter.pro +++ b/telldus-gui/TelldusCenter/TelldusCenter.pro @@ -8,25 +8,24 @@ SOURCES += main.cpp \ mainwindow.cpp \ tellduscenterapplication.cpp \ autoupdater.cpp \ - systrayicon.cpp \ message.cpp HEADERS += mainwindow.h \ tellduscenterapplication.h \ autoupdater.h \ CocoaInitializer.h \ - systrayicon.h \ message.h \ tellduscenterplugin.h RESOURCES += resource.qrc TARGET = TelldusCenter macx { -# HEADERS += sparkleautoupdater.h + # HEADERS += sparkleautoupdater.h LIBS += -framework \ TelldusCore -# -framework \ -# Sparkle -# OBJECTIVE_SOURCES += SparkleAutoUpdater.mm \ -# CocoaInitializer.mm + + # -framework \ + # Sparkle + # OBJECTIVE_SOURCES += SparkleAutoUpdater.mm \ + # CocoaInitializer.mm QMAKE_INFO_PLIST = Info.plist ICON = TelldusCenter.icns } diff --git a/telldus-gui/TelldusCenter/main.cpp b/telldus-gui/TelldusCenter/main.cpp index 3adc6cd9..6520575d 100644 --- a/telldus-gui/TelldusCenter/main.cpp +++ b/telldus-gui/TelldusCenter/main.cpp @@ -15,15 +15,19 @@ int main(int argc, char *argv[]) TelldusCenterApplication application(argc, argv); + QCoreApplication::setLibraryPaths( QStringList( QCoreApplication::applicationDirPath() ) ); + application.loadPlugins(); + application.loadScripts(); + application.showMainWindow(); #ifdef Q_WS_MAC - AutoUpdater* updater = 0; +/* AutoUpdater* updater = 0; CocoaInitializer initializer; updater = new SparkleAutoUpdater("file:///Users/micke/Documents/dev/appcast.xml"); if (updater) { //updater->checkForUpdates(); - } + }*/ #endif return application.exec(); diff --git a/telldus-gui/TelldusCenter/mainwindow.cpp b/telldus-gui/TelldusCenter/mainwindow.cpp index c6cd8f51..215e5860 100644 --- a/telldus-gui/TelldusCenter/mainwindow.cpp +++ b/telldus-gui/TelldusCenter/mainwindow.cpp @@ -118,7 +118,9 @@ void MainWindow::setupToolBar() } } - ag->actions().first()->setChecked( true ); + if (!ag->actions().empty()) { + ag->actions().first()->setChecked( true ); + } d->pagesBar->addActions( ag->actions() ); } } diff --git a/telldus-gui/TelldusCenter/tellduscenterapplication.cpp b/telldus-gui/TelldusCenter/tellduscenterapplication.cpp index 02471096..b6e9ed3b 100644 --- a/telldus-gui/TelldusCenter/tellduscenterapplication.cpp +++ b/telldus-gui/TelldusCenter/tellduscenterapplication.cpp @@ -16,7 +16,6 @@ typedef QList PluginList; class TelldusCenterApplicationPrivate { public: - SystrayIcon *systrayIcon; PluginList plugins; QPointer mainWindow; QScriptEngine scriptEngine; @@ -26,9 +25,6 @@ TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv) :QApplication(argc, argv) { d = new TelldusCenterApplicationPrivate; - d->systrayIcon = new SystrayIcon( this ); - - connect(d->systrayIcon, SIGNAL(showEventMessage(const QString &, const QString &, const QString &)), this, SLOT(showMessage(QString,QString,QString))); setQuitOnLastWindowClosed( false ); @@ -37,8 +33,6 @@ TelldusCenterApplication::TelldusCenterApplication(int &argc, char **argv) tdInit(); tdRegisterDeviceEvent( &TelldusCenterApplication::deviceEvent, 0 ); - loadPlugins(); - loadScripts(); } TelldusCenterApplication::~TelldusCenterApplication() { @@ -48,6 +42,9 @@ TelldusCenterApplication::~TelldusCenterApplication() { } PluginList TelldusCenterApplication::plugins() const { + if (d->plugins.empty()) { + return PluginList(); + } return d->plugins; } @@ -85,7 +82,7 @@ void TelldusCenterApplication::showMessage( const QString &title, const QString if (isMainWindowShown()) { d->mainWindow->showMessage(title, message, detailedMessage); } else { - d->systrayIcon->showMessage((title != "" ? title : "Telldus Center"), message, QSystemTrayIcon::Warning); + //d->systrayIcon->showMessage((title != "" ? title : "Telldus Center"), message, QSystemTrayIcon::Warning); } } @@ -108,7 +105,7 @@ void TelldusCenterApplication::loadPlugins() { if (!pluginsDir.cd("plugins")) { return; } - this->addLibraryPath( pluginsDir.absolutePath() ); + this->setLibraryPaths( QStringList(pluginsDir.absolutePath()) ); foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); diff --git a/telldus-gui/TelldusCenter/tellduscenterapplication.h b/telldus-gui/TelldusCenter/tellduscenterapplication.h index d9e7d7f7..67a33d98 100644 --- a/telldus-gui/TelldusCenter/tellduscenterapplication.h +++ b/telldus-gui/TelldusCenter/tellduscenterapplication.h @@ -5,7 +5,6 @@ #include //#incldue -#include "systrayicon.h" #include "mainwindow.h" class TelldusCenterPlugin; @@ -28,6 +27,9 @@ public: void showMainWindow(); bool isMainWindowShown(); + void loadPlugins(); + void loadScripts(); + static TelldusCenterApplication *instance(); signals: @@ -42,9 +44,7 @@ private slots: private: static void deviceEvent(int deviceId, int method, const char *data, int callbackId, void *context); - void loadPlugins(); void loadPlugin(QObject *plugin); - void loadScripts(); TelldusCenterApplicationPrivate *d; };