summaryrefslogtreecommitdiffstats
path: root/kshutdown/extras.h
blob: 365b45c6a6b75ca805e5c1a827710549fca35407 (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
114
115
/*
	extras.h - Extras
	Copyright (C) 2004  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 __EXTRAS_H__
#define __EXTRAS_H__

#include <ntqobject.h>
#include <ntqiconset.h>

class TDEPopupMenu;
class KPushButton;

#define ks_extras Extras::getInstance()

/** @short Extras - user commands stored in "extras" directory. */
class Extras: public TQObject
{
	Q_OBJECT
public:
	/**
	 * Destructor.
	 */
	virtual ~Extras();

	/**
	 * Returns the @b Extras button.
	 */
	inline KPushButton *button() const { return _button; }

	/**
	 * Creates the @b Extras button.
	 * @param parent A parent widget
	 */
	void createButton(TQWidget *parent);

	/**
	 * Executes an "extras" action previously selected from the menu.
	 * @return @c false if error; otherwise @c true
	 */
	bool execAction() const;

	/**
	 * Returns a file name which will be executed by @ref execAction.
	 */
	inline TQString fileToExecute() const { return _fileToExecute; }

	/**
	 * Returns a full description of the action,
	 * or @c TQString::null if no action.
	 */
	TQString getActionDescription() const;

	/**
	 * Initializes and returns the instance of the "extras" manager.
	 */
	inline static Extras *getInstance()
	{
		if (!_instance)
			_instance = new Extras();

		return _instance;
	}
	
	void setAction(const TQString &fileToExecute, const TQString &description, TQIconSet *icon = 0);
private:
	static Extras *_instance;
	TDEPopupMenu *_menu;
	KPushButton *_button;
	TQMap<int, TQString> *_idToFileMap;
	TQString
		_description,
		_fileToExecute;
	Extras();

	/**
	 * Reads "extras" directory and creates menu items.
	 * @param parentMenu A parent menu
	 * @param subdir A subdirectory
	 */
	void buildMenu(TDEPopupMenu *parentMenu, const TQString &subdir);

	bool execFile() const;
	TQMap<int, TQString> *getIdToFileMap();
public slots:
	/**
	 * Opens the "extras" directory in the @b Konqueror.
	 */
	void slotModify();
private slots:
	void slotActivated(int id);

	/**
	 * Called before the popup menu is displayed.
	 * All the menu items are initialized here.
	 */
	void slotShowMenu();
};

#endif // __EXTRAS_H__