1 /***************************************************************************** 2 * trayicon.h - QStarDict, a StarDict clone written with using Qt * 3 * Copyright (C) 2008 Alexander Rodin * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License along * 16 * with this program; if not, write to the Free Software Foundation, Inc., * 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 18 *****************************************************************************/ 19 20 #ifndef TRAYICON_H 21 #define TRAYICON_H 22 23 #include <QSystemTrayIcon> 24 25 #include "../plugins/trayplugin.h" 26 27 class QAction; 28 class QTimer; 29 30 namespace QStarDict 31 { 32 33 34 class TrayIconDefaultImpl : public QObject, public TrayIconPlugin 35 { 36 Q_OBJECT 37 Q_INTERFACES(QStarDict::TrayIconPlugin) 38 39 QSystemTrayIcon *sti; 40 QWidget *associatedWidget; 41 QAction *actionMainWindow; 42 43 public: 44 TrayIconDefaultImpl(QObject *parent); 45 ~TrayIconDefaultImpl(); 46 47 TrayCompat isDECompatible(); 48 void initTray(); 49 void uninitTray(); 50 Features features() const; 51 void setContextMenu(QMenu *menu); 52 void setMainWindow(QWidget *w); 53 void setScanEnabled(bool enabled); 54 void setVisible(bool visible); 55 bool isVisible() const; 56 57 signals: 58 void translateClipboard(); 59 60 private slots: 61 void on_activated(QSystemTrayIcon::ActivationReason reason); 62 }; 63 64 class TrayIcon: public QObject 65 { 66 Q_OBJECT 67 68 public: 69 TrayIcon(QObject *parent = 0); 70 virtual ~TrayIcon(); 71 72 void saveSettings(); 73 void setMainWindow(QWidget *w); 74 void setVisible(bool visible); 75 bool isVisible() const; 76 77 public slots: 78 void reinit(); 79 80 private slots: 81 void on_actionSettings_triggered(); 82 void setScanEnabled(bool enabled); 83 void on_trayImplDestroyed(QObject *o); 84 void translateClipboard(); 85 void on_pluginLoaded(const QString &pluginId); 86 private: 87 void loadSettings(); 88 89 QWidget *_mainWindow; 90 QObject *_trayImpl; 91 QObject *_defaultTrayImpl; 92 QTimer *_initTrayTimer; 93 QObjectList _trayCandidat; 94 QObjectList _trayFallbackCandidat; 95 }; 96 97 } 98 99 #endif // TRAYICON_H 100 101 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent 102 103