aboutsummaryrefslogtreecommitdiff
path: root/lib/gui/actions.h
blob: 8cda4bc002f36f6b0a6aa46156f289d4025e38c0 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef __actions_h
#define __actions_h

#include <string.h>
#include <list>
#include <string>
#include <functional>
#include <set>

#include <libsig_comp.h>
#include <lib/base/i18n.h>
#include <lib/base/estring.h>
#include <lib/driver/rc.h>

class eActionMap;
class eActionMapList;

/**
 * \brief An action
 *
 * An action is an action of the user. It might raise by a keypress or otherwise. bla.
 */
class eAction
{
	typedef std::set<eRCKey> keylist;
	char *description, *identifier;
	eActionMap *map;
	friend struct priorityComperator;
	std::map<eString, keylist> keys;
	int priority;
public:
	typedef std::pair<void*,eAction*> directedAction;
	/**
	 * \brief Functor to compare by priority.
	 *
	 * This is useful in sorted priority lists.
	 */
	struct priorityComperator
	{
		bool operator()(const directedAction &a, const directedAction &b)
		{
			return a.second->priority > b.second->priority;
		}
	};

	enum
	{
		prioGlobal=0, prioDialog=10, prioWidget=20, prioDialogHi=30
	};
	/**
	 * \param priority The priority of this action. 0 should be used for
	 * global actions, 10 for dialog-local actions, 20 for widget-local actions,
	 * 30 for dialog-hi-priority actions.
	 */
	eAction(eActionMap &map, char *identifier, char *description, int priority=0 );
	~eAction();
	const char *getDescription() const { return description; }
	const char *getIdentifier() const { return identifier; }

	void insertKey(const eString& style, const eRCKey& key )
	{
		keys[style].insert(key);
	}

	Signal0<void> handler;

//	keylist &getKeyList();
	int containsKey(const eRCKey &key, const eString& style ) const;
};

typedef std::multiset<eAction::directedAction,eAction::priorityComperator> eActionPrioritySet;

class XMLTreeNode;
class XMLTreeParser;

class eActionMap
{
	typedef std::list<eAction*> actionList;
	actionList actions;
	const char *identifier, *description;
public:
	eActionMap(const char *identifier, char *description);
	~eActionMap();
	void add(eAction *action)
	{
		actions.push_back(action);
	}
	void remove(eAction *action)
	{
		actions.remove(action);
	}
	void findAction(eActionPrioritySet &list, const eRCKey &key, void *context, const eString &style) const;
	eAction *findAction(const char *id) const;
	const char *getDescription() const { return description; }
	const char *getIdentifier() const { return identifier; }
	void reloadConfig();
	void loadXML(eRCDevice *device, std::map<std::string,int> &keymap, const XMLTreeNode *node, const eString& s="");
	void saveConfig();
};

class eActionMapList
{
	struct lstr
	{
		bool operator()(const char *a, const char *b) const
		{
			return strcmp(a, b)<0;
		}
	};
	typedef std::map<const char*,eActionMap*,lstr> actionMapList;

	actionMapList actionmaps;

	std::map<eString, eString> existingStyles;
	eString currentStyle;
	
	ePtrList<XMLTreeParser> xmlfiles;
	XMLTreeNode *searchDevice(const eString &id);

	static eActionMapList *instance;
public:
	eActionMapList();
	~eActionMapList();
	const eString &getCurrentStyle() const { return currentStyle; }
	void setCurrentStyle( const eString& style ) { currentStyle = style; }
	eString getStyleDescription(const eString &style) const { std::map<eString, eString>::const_iterator i=existingStyles.find(style); if (i==existingStyles.end()) return ""; else return i->second; }
	const std::map<eString, eString> &getExistingStyles() const { return existingStyles; }
	void addActionMap(const char *, eActionMap * );
	void removeActionMap(const char *);
	int loadXML(const char *filename);
	int loadDevice(eRCDevice *device);
	eActionMap *findActionMap(const char *id) const;
	actionMapList &getActionMapList() { return actionmaps; }

	static eActionMapList *getInstance() { return instance; }
};

#endif