summaryrefslogtreecommitdiffstats
path: root/kshutdown/msystemtray.h
blob: db9fa66c7c09ed0f2b30c1bdc82e5d5beb09de14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
	msystemtray.h - A system tray icon
	Copyright (C) 2003  Konrad Twardowski <kdtonline@poczta.onet.pl>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef __MSYSTEMTRAY_H__
#define __MSYSTEMTRAY_H__

#include <ksystemtray.h>

class KPixmap;

#define ks_tray MSystemTray::getInstance()

/** @short A system tray icon. */
class MSystemTray: public KSystemTray
{
	Q_OBJECT
public:
	/**
	 * System tray icon modes.
	 */
	enum Mode {
		Always = 0, /**< Always visible. */
		IfActive = 1, /**< Visible if action is active. */
		Never = 2  /**< Always hidden. */
	};

	/**
	 * Destructor.
	 */
	virtual ~MSystemTray();

	/**
	 * Flashes the icon.
	 */
	void flashIcon();

	/**
	 * Constructs and returns a singleton instance
	 * of the system tray icon.
	 */
	inline static MSystemTray *getInstance()
	{
		if (!_instance)
			_instance = new MSystemTray();

		return _instance;
	}

	/**
	 * Returns @c true if the instance of
	 * the system tray was created.
	 */
	inline static bool isInstance() { return _instance; }

	/**
	 * Switches icon between idle and active states.
	 * @param yes If @c true the state is "idle" (normal icon);
	 * otherwise the state is "active" (highlighted icon)
	 */
	void setActive(const bool yes);

	/**
	 * Returns the system tray icon mode.
	 */
	static inline Mode mode() { return _mode; }

	/**
	 * Sets system tray icon mode to @p mode.
	 */
	static void setMode(const Mode mode);
protected:
	/**
	 * Overriden to handle middle button click; displays the actions menu.
	 * @param e A mouse event
	 */
	virtual void mousePressEvent(TQMouseEvent *e);
private:
	// icon stuff
	bool
		_active,
		_incFade;
	double _fadeValue;
	int _flashCount;
	KPixmap *_flashIcon;
	static Mode _mode;
	TQPixmap *_saveIcon;
	TQTimer
		*_fadeTimer,
		*_flashTimer;
	static MSystemTray *_instance;
	MSystemTray();
private slots:
	void slotFade();
	void slotFlashTimeout();
};

#endif // __MSYSTEMTRAY_H__