1// -*- c++ -*-
2
3#ifndef KSYSTRAYCMD_H
4#define KSYSTRAYCMD_H
5
6#include <KSystemTrayIcon>
7
8class KProcess;
9class KMenu;
10
11/**
12 * Provides a system tray icon for a normal window.
13 *
14 * @author Richard Moore, rich@kde.org
15 */
16class KSysTrayCmd : public KSystemTrayIcon
17{
18 Q_OBJECT
19public:
20 KSysTrayCmd();
21 ~KSysTrayCmd();
22
23 void setWindow( WId w ) { win = w; }
24 void setCommand( const QString &cmd ) { command = cmd; }
25 void setPattern( const QString &regexp ) { window = regexp; }
26 void setStartOnShow( bool enable ) { lazyStart = enable; isVisible = !enable; }
27 void setNoQuit( bool enable ) { noquit = enable; }
28 void setQuitOnHide( bool enable ) { quitOnHide = enable; }
29 void setOnTop( bool enable ) { onTop = enable; }
30 void setOwnIcon( bool enable ) { ownIcon = enable; }
31 void setDefaultTip( const QString &tip ) { tooltip = tip; }
32 bool hasTargetWindow() const { return (win != 0); }
33 bool hasRunningClient() const { return (client != 0); }
34 const QString &errorMsg() const { return errStr; }
35
36 bool start();
37
38 static WId findRealWindow( WId w, int depth = 0 );
39
40public Q_SLOTS:
41 void refresh();
42
43 void showWindow();
44 void hideWindow();
45 void toggleWindow() { if ( isVisible ) hideWindow(); else showWindow(); }
46
47 void setTargetWindow( WId w );
48 void execContextMenu( const QPoint &pos );
49
50 void quit();
51 void quitClient();
52
53protected Q_SLOTS:
54 void clientExited();
55
56 void windowAdded(WId w);
57 void windowChanged(WId w);
58 void mousePressEvent(QSystemTrayIcon::ActivationReason reason);
59
60protected:
61 bool startClient();
62 void checkExistingWindows();
63
64private:
65 QString command;
66 QString window;
67 QString tooltip;
68 bool isVisible;
69 bool lazyStart;
70 bool noquit;
71 bool quitOnHide;
72 bool onTop; ///< tells if window must stay on top or not
73 bool ownIcon; ///< tells if the ksystraycmd icon must be used in systray
74 bool waitingForWindow;
75 KMenu * menu;
76
77 WId win;
78 KProcess *client;
79 QString errStr;
80
81 /** Memorized 'top' position of the window*/
82 int top;
83 /** Memorized 'left' position of the window*/
84 int left;
85};
86
87#endif // KSYSTRAYCMD_H
88