~vcs-imports/lince/trunk

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
 /***************************************************************************
 *            GuiSetupManager.h
 *
 *  Sun Dec 17 01:34:46 2006
 *  Copyright  2006  Fernando TarĂ­n Morales
 *  icemanf@gmail.com
 ****************************************************************************/

/*
 *  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 3 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., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */

#ifndef _GUISETUPMANAGER_H
#define _GUISETUPMANAGER_H

#include <iostream>
#include <string>

#include "XMLWriter.h"
#include "XMLReader.h"

#include "Lince/Utils.h"

class GuiSetupManager{
public:

	enum StrSetting { STR_FIRST,
		DEFAULT_FILE_DIRECTORY = STR_FIRST, DOWNLOAD_TORRENTS_DIRECTORY,
		LOAD_TORRENTS_DIRECTORY, LAST_LOAD_DIRECTORY, LAST_SAVE_DIRECTORY,
		STR_LAST };

	enum IntSetting { INT_FIRST = STR_LAST + 1,
		SHOW_TORRENTSTAB = INT_FIRST, SHOW_OPTIONSTAB, SHOW_STATISTICSTAB,
		SHOW_LOGTAB, SHOW_TOOLBAR, USE_DEFAULT_FILE_DIRECTORY,
		CONFIRM_DATA_ELIMINATION, ASK_WHEN_LOADING_FROM_DBUS_REQUEST,
		USE_DOWNLOAD_TORRENTS_DIRECTORY, USE_REMOVE_ORIGINAL_TORRENT,
		USE_REMOVE_TORRENT_WHEN_FINISHED, USE_LOAD_TORRENTS_DIRECTORY,
		ALLOW_CHANGE_LOAD_DIRECTORY, SHOW_GRAPHIC_STATISTICS,
		STATISTICS_TIME_UPDATE, USE_LOG_TAB, LOG_LEVEL, LOG_COLORED_OUTPUT,
		SAVE_LOG_TO_FILE, LOG_AUTO_SCROLL, LOG_SIZE, USE_BTJUNKIE, USE_ISOHUNT,
		USE_PIRATEBAY, USE_MININOVA, USE_TORRENTREACTOR, USE_VERTOR,
		USE_TORRENTDOWNLOADS, USE_EXTRATORRENT, USE_KICKASSTORRENTS, USE_BTDIGG,
		MAX_NUMBER_OF_SEARCHES, FILTER_RESULTS_WITHOUT_SEEDERS, SHOW_SEARCHTAB,
		USE_NOTIFICATIONS, NOTIFY_FINISHED_TORRENTS, NOTIFY_STOPPED_TORRENTS,
		NOTIFY_STARTED_TORRENTS, NOTIFY_ADDED_TORRENTS, NOTIFY_REMOVED_TORRENTS,
		NOTIFY_QUEUED_TORRENTS, NOTIFY_UNQUEUED_TORRENTS, TORRENTSTAB_PANE_POSITION,
		MAIN_WINDOW_MAXIMIZE, MAIN_WINDOW_POS_X, MAIN_WINDOW_POS_Y, MAIN_WINDOW_WIDTH,
		MAIN_WINDOW_HEIGHT, SHOW_DIALOGS_LOADING_A_TORRENT_FROM_SEARCH_RESULTS,
		INT_LAST };

	enum Int64Setting { INT64_FIRST = INT_LAST + 1,
		INT64_LAST = INT64_FIRST, SETTINGS_LAST = INT64_LAST };


	const std::string& get(StrSetting key, bool useDefault = true) const {
		return (isSet[key] || !useDefault) ? strSettings[key - STR_FIRST] : strDefaults[key - STR_FIRST];
	}

	int get(IntSetting key, bool useDefault = true) const {
		return (isSet[key] || !useDefault) ? intSettings[key - INT_FIRST] : intDefaults[key - INT_FIRST];
	}

	bool getBool(IntSetting key, bool useDefault = true) const {
		return (get(key, useDefault) != 0);
	}

	boost::int64_t get(Int64Setting key, bool useDefault = true) const {
		return (isSet[key] || !useDefault) ? int64Settings[key - INT64_FIRST] : int64Defaults[key - INT64_FIRST];
	}

	void set(StrSetting key, std::string const& value) {
		strSettings[key - STR_FIRST] = value;
		isSet[key] = !value.empty();
	}

	void set(IntSetting key, int value) {
		intSettings[key - INT_FIRST] = value;
		isSet[key] = true;
	}

	void set(IntSetting key, const std::string& value) {
		if(value.empty()) {
			intSettings[key - INT_FIRST] = 0;
			isSet[key] = false;
		}
		else {
			intSettings[key - INT_FIRST] = Lince::to_int(value);
			isSet[key] = true;
		}
	}

	void set(Int64Setting key, boost::int64_t value) {
		int64Settings[key - INT64_FIRST] = value;
		isSet[key] = true;
	}

	void set(Int64Setting key, int value) {
		int64Settings[key - INT64_FIRST] = static_cast<boost::int64_t>(value);
		isSet[key] = true;
	}

	void set(Int64Setting key, const std::string& value) {
		if(value.empty()) {
			int64Settings[key - INT64_FIRST] = 0;
			isSet[key] = false;
		}
		else {
			int64Settings[key - INT64_FIRST] = Lince::to_int64(value);
			isSet[key] = true;
		}
	}

	void set(IntSetting key, bool value) { set(key, (int)value); }

	void setDefault(StrSetting key, std::string const& value) {
		strDefaults[key - STR_FIRST] = value;
	}

	void setDefault(IntSetting key, int value) {
		intDefaults[key - INT_FIRST] = value;
	}

	void setDefault(Int64Setting key, boost::int64_t value) {
		int64Defaults[key - INT64_FIRST] = value;
	}

	void showDefaults();
	void showOptions();

	void load();
	void save();

	bool isDefault(int aSet) { return !isSet[aSet]; }

	void setFileName(const Glib::ustring conf_name) { config_file = conf_name; };

	GuiSetupManager & operator=(const GuiSetupManager &);

	GuiSetupManager();
	GuiSetupManager(const GuiSetupManager & s);
	~GuiSetupManager();

private:
	Glib::ustring config_file;

	XMLReader reader;
	XMLWriter writer;

	static const std::string settingTags[SETTINGS_LAST+1];

    std::string strSettings[STR_LAST - STR_FIRST];
	int    intSettings[INT_LAST - INT_FIRST];
	boost::int64_t int64Settings[INT64_LAST - INT64_FIRST];

	std::string strDefaults[STR_LAST - STR_FIRST];
	int    intDefaults[INT_LAST - INT_FIRST];
	boost::int64_t int64Defaults[INT64_LAST - INT64_FIRST];

	bool isSet[SETTINGS_LAST];
};

#endif /* _GUISETUPMANAGER_H */