Changeset ac1552
- Timestamp:
- 08/13/09 19:57:32 (4 years ago)
- Branches:
- ('master', '668dd99ac278cfd419d67879b141678facea630a')('windows_service_fixes', 'df6bd2788365991d36d5af2a75833b8de2a5860f')
- Children:
- 691237fa8abff4f7260c14fc3a01346facd6653f
- Parents:
- ee5ec861334568fcceabfa5ea2c40f2b447bbbd8
- git-author:
- Micke Prag <micke.prag@telldus.se>2009-08-13 17:57:32+00:00
- git-committer:
- Micke Prag <micke.prag@telldus.se>2009-08-13 17:57:32+00:00
- Location:
- telldus-gui/Plugins/Systray
- Files:
-
- 3 edited
-
systrayobject.cpp (modified) (1 diff)
-
systrayobject.h (modified) (3 diffs)
-
systrayplugin.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
telldus-gui/Plugins/Systray/systrayobject.cpp
rd763b5 rac1552 1 1 #include "systrayobject.h" 2 2 #include <QApplication> 3 #include <QDebug> 3 4 4 SystrayObject::SystrayObject( QObject * parent ) 5 : QObject(parent), 6 icon( new SystrayIcon ) 5 class SystrayObjectPrivate { 6 public: 7 // SystrayIcon *icon; 8 QSystemTrayIcon *i; 9 QAction *menu; 10 QList<QAction *> menuItems; 11 QScriptEngine *engine; 12 }; 13 14 SystrayObject::SystrayObject( QScriptEngine *engine, QObject * parent ) 15 : QObject(parent) 7 16 { 8 connect(icon, SIGNAL(showEventMessage(QString,QString,QString)), qApp, SIGNAL(showMessage(QString,QString,QString))); 9 connect(icon, SIGNAL(triggered()), this, SIGNAL(triggered())); 17 d = new SystrayObjectPrivate; 18 d->engine = engine; 19 //d->icon = new SystrayIcon(); 20 d->menu = new QAction(0); 21 d->menu->setMenu( new QMenu() ); 22 23 d->i = new QSystemTrayIcon(); 24 d->i->setIcon(QIcon(":/images/TelldusCenter_128.png")); 25 d->i->setContextMenu(d->menu->menu()); 26 d->i->show(); 27 28 //connect(d->icon, SIGNAL(showEventMessage(QString,QString,QString)), qApp, SIGNAL(showMessage(QString,QString,QString))); 29 connect(d->i, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activated(QSystemTrayIcon::ActivationReason))); 10 30 } 11 31 12 32 SystrayObject::~SystrayObject() { 33 delete d->i; 34 delete d->menu; 35 delete d; 36 } 37 38 int SystrayObject::addMenuItem( const QString &name, int parent ) { 39 QMenu *menu = parentMenu(parent); 40 if (!menu) { 41 return -1; 42 } 43 QAction *item = menu->addAction( name ); 44 int index = d->menuItems.count(); 45 d->menuItems.append( item ); 46 return index; 47 } 48 49 void SystrayObject::addSeparator( int parent ) { 50 QMenu *menu = parentMenu(parent); 51 if (!menu) { 52 return; 53 } 54 menu->addSeparator(); 55 } 56 57 QScriptValue SystrayObject::menuItem( int id ) { 58 QScriptValue value = d->engine->newQObject(menuAction(id)); 59 return value; 13 60 } 14 61 15 62 void SystrayObject::showMessage ( const QString & title, const QString & message, QSystemTrayIcon::MessageIcon i, int millisecondsTimeoutHint ) { 16 icon->showMessage( title, message, i, millisecondsTimeoutHint );63 d->i->showMessage( title, message, i, millisecondsTimeoutHint ); 17 64 } 65 66 void SystrayObject::activated( QSystemTrayIcon::ActivationReason reason ) { 67 #if !defined(Q_WS_MAC) 68 if (reason == QSystemTrayIcon::Trigger) { 69 emit triggered(); 70 } 71 #endif 72 } 73 74 QAction *SystrayObject::menuAction( int index ) { 75 QAction *parentItem; 76 if (index < 0) { 77 return d->menu; 78 } 79 return d->menuItems.at(index); 80 } 81 82 QMenu *SystrayObject::parentMenu( int parentIndex ) { 83 QAction *parentItem = menuAction( parentIndex ); 84 if (!parentItem) { 85 return 0; 86 } 87 QMenu *menu = parentItem->menu(); 88 if (!menu) { 89 menu = new QMenu(); 90 parentItem->setMenu(menu); 91 } 92 return menu; 93 } -
telldus-gui/Plugins/Systray/systrayobject.h
rd763b5 rac1552 3 3 4 4 #include <QObject> 5 #include <QScriptEngine> 5 6 #include "systrayicon.h" 6 7 8 class SystrayObjectPrivate; 7 9 8 10 class SystrayObject : public QObject … … 10 12 Q_OBJECT 11 13 public: 12 SystrayObject( Q Object * parent = 0 );14 SystrayObject( QScriptEngine *engine, QObject * parent = 0 ); 13 15 virtual ~SystrayObject(); 14 16 … … 17 19 18 20 public slots: 21 int addMenuItem( const QString &name, int parent = -1 ); 22 void addSeparator( int parent = -1 ); 23 QScriptValue menuItem( int id ); 24 19 25 void showMessage ( const QString & title, const QString & message, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int millisecondsTimeoutHint = 10000 ); 20 26 27 private slots: 28 void activated( QSystemTrayIcon::ActivationReason reason ); 29 21 30 private: 22 SystrayIcon *icon; 31 QAction *menuAction( int index ); 32 QMenu *parentMenu( int parentIndex ); 33 SystrayObjectPrivate *d; 23 34 }; 24 35 -
telldus-gui/Plugins/Systray/systrayplugin.cpp
r961621 rac1552 22 22 void SystrayPlugin::initialize ( const QString & key, QScriptEngine * engine ) { 23 23 if (key == "com.telldus.systray") { 24 d->icon = new SystrayObject( this);24 d->icon = new SystrayObject(engine, this); 25 25 26 26 QScriptValue value = engine->newQObject(d->icon);
Note: See TracChangeset
for help on using the changeset viewer.
