File: settings.h

package info (click to toggle)
xfce4-whiskermenu-plugin 2.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,616 kB
  • sloc: cpp: 8,368; ansic: 25; makefile: 9
file content (381 lines) | stat: -rw-r--r-- 7,010 bytes parent folder | download | duplicates (2)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/*
 * Copyright (C) 2013-2023 Graeme Gott <graeme@gottcode.org>
 *
 * This library 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 library 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 library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef WHISKERMENU_SETTINGS_H
#define WHISKERMENU_SETTINGS_H

#include "icon-size.h"

#include <xfconf/xfconf.h>

namespace WhiskerMenu
{

class Command;
class Plugin;
class SearchAction;


// Boolean setting
class Boolean
{
public:
	explicit Boolean(const gchar* property, bool data);

	operator bool() const
	{
		return m_data;
	}

	Boolean& operator=(bool data)
	{
		set(data, true);
		return *this;
	}

	void load(XfceRc* rc, bool is_default);
	bool load(const gchar* property, const GValue* value);

private:
	void set(bool data, bool store);

private:
	const gchar* const m_property;
	bool m_default;
	bool m_data;
};


// Integer setting
class Integer
{
public:
	explicit Integer(const gchar* property, int data, int min, int max);

	operator int() const
	{
		return m_data;
	}

	Integer& operator=(int data)
	{
		set(data, true);
		return *this;
	}

	void load(XfceRc* rc, bool is_default);
	bool load(const gchar* property, const GValue* value);

private:
	void set(int data, bool store);

private:
	const gchar* const m_property;
	const int m_min;
	const int m_max;
	int m_default;
	int m_data;
};


// String setting
class String
{
public:
	explicit String(const gchar* property, const std::string& data = std::string());

	bool empty() const
	{
		return m_data.empty();
	}

	operator const char*() const
	{
		return m_data.c_str();
	}

	bool operator==(const char* data) const
	{
		return data ? (m_data == data) : m_data.empty();
	}

	String& operator=(const std::string& data)
	{
		set(data, true);
		return *this;
	}

	String& operator=(const char* data)
	{
		return *this = std::string(data ? data : "");
	}

	void load(XfceRc* rc, bool is_default);
	bool load(const gchar* property, const GValue* value);

private:
	void set(const std::string& data, bool store);

private:
	const gchar* const m_property;
	std::string m_default;
	std::string m_data;
};


// String list setting
class StringList
{
public:
	explicit StringList(const gchar* property, std::initializer_list<std::string> data);

	bool empty() const
	{
		return m_data.empty();
	}

	std::vector<std::string>::const_iterator begin() const
	{
		return m_data.cbegin();
	}

	std::vector<std::string>::const_iterator end() const
	{
		return m_data.cend();
	}

	const std::string& operator[](int pos) const
	{
		return m_data[pos];
	}

	int size() const
	{
		return m_data.size();
	}

	void clear();
	void erase(int pos);
	void insert(int pos, const std::string& value);
	void push_back(const std::string& value);
	void resize(int count);
	void set(int pos, const std::string& value);

	bool is_order_unchanged() const
	{
		return m_order_unchanged;
	}

	void set_order_unchaged()
	{
		m_order_unchanged = true;
	}

	void load(XfceRc* rc, bool is_default);
	bool load(const gchar* property, const GValue* value, bool& reload_menu);
	void save();

private:
	void set(std::vector<std::string>& data, bool store);

private:
	const gchar* const m_property;
	std::vector<std::string> m_default;
	std::vector<std::string> m_data;
	bool m_modified;
	bool m_saved;
	bool m_order_unchanged;
};


// SearchAction list setting
class SearchActionList
{
public:
	explicit SearchActionList(std::initializer_list<SearchAction*> data);
	~SearchActionList();

	bool empty() const
	{
		return m_data.empty();
	}

	std::vector<SearchAction*>::const_iterator begin() const
	{
		return m_data.cbegin();
	}

	std::vector<SearchAction*>::const_iterator end() const
	{
		return m_data.cend();
	}

	SearchAction* operator[](int pos) const
	{
		return m_data[pos];
	}

	int size() const
	{
		return m_data.size();
	}

	void erase(SearchAction* value);
	void push_back(SearchAction* value);

	void set_modified()
	{
		m_modified = true;
	}

	void load(XfceRc* rc, bool is_default);
	void load();
	bool load(const gchar* property, const GValue* value);
	void save();

private:
	void clone(const std::vector<SearchAction*>& in, std::vector<SearchAction*>& out) const;

private:
	std::vector<SearchAction*> m_default;
	std::vector<SearchAction*> m_data;
	bool m_modified;
};


// Settings class
class Settings
{
	Settings(Plugin* plugin);
	~Settings();

	Settings(const Settings&) = delete;
	Settings(Settings&&) = delete;
	Settings& operator=(const Settings&) = delete;
	Settings& operator=(Settings&&) = delete;

	void load(const gchar* file, bool is_default);
	void load(const gchar* base);

	void prevent_invalid();
	void property_changed(const gchar* property, const GValue* value);

	Plugin* m_plugin;
	gulong m_change_slot;
	std::string m_button_title_default;

public:
	void begin_property_update()
	{
		g_signal_handler_block(channel, m_change_slot);
	}

	void end_property_update()
	{
		g_signal_handler_unblock(channel, m_change_slot);
	}

public:
	XfconfChannel* channel;

	StringList favorites;
	StringList recent;

	String custom_menu_file;

	String button_title;
	String button_icon_name;
	Boolean button_title_visible;
	Boolean button_icon_visible;
	Boolean button_single_row;

	Boolean launcher_show_name;
	Boolean launcher_show_description;
	Boolean launcher_show_tooltip;
	IconSize launcher_icon_size;

	Boolean category_hover_activate;
	Boolean category_show_name;
	Boolean sort_categories;
	IconSize category_icon_size;

	enum ViewMode
	{
		ViewAsIcons = 0,
		ViewAsList,
		ViewAsTree
	};
	Integer view_mode;

	enum DefaultCategory
	{
		CategoryFavorites = 0,
		CategoryRecent,
		CategoryAll
	};
	Integer default_category;

	Integer recent_items_max;
	Boolean favorites_in_recent;

	Boolean position_profile_alternate;
	Boolean position_search_alternate;
	Boolean position_commands_alternate;
	Boolean position_categories_alternate;
	Boolean position_categories_horizontal;
	Boolean stay_on_focus_out;

	enum ProfileShape
	{
		ProfileRound = 0,
		ProfileSquare,
		ProfileHidden
	};
	Integer profile_shape;

	enum Commands
	{
		CommandSettings = 0,
		CommandLockScreen,
		CommandSwitchUser,
		CommandLogOutUser,
		CommandRestart,
		CommandShutDown,
		CommandSuspend,
		CommandHibernate,
		CommandLogOut,
		CommandMenuEditor,
		CommandProfile,
		CountCommands
	};
	Command* command[CountCommands];
	Boolean confirm_session_command;

	SearchActionList search_actions;

	Integer menu_width;
	Integer menu_height;
	Integer menu_opacity;

	friend class Plugin;
};

extern Settings* wm_settings;

}

#endif // WHISKERMENU_SETTINGS_H