1 | /* |
---|
2 | * This file Copyright (C) Mnemosyne LLC |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License version 2 |
---|
6 | * as published by the Free Software Foundation. |
---|
7 | * |
---|
8 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
9 | * |
---|
10 | * $Id: prefs.h 13667 2012-12-14 04:34:42Z jordan $ |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef QTR_PREFS_H |
---|
14 | #define QTR_PREFS_H |
---|
15 | |
---|
16 | #include <QDateTime> |
---|
17 | #include <QObject> |
---|
18 | #include <QSet> |
---|
19 | #include <QString> |
---|
20 | #include <QVariant> |
---|
21 | |
---|
22 | #include "filters.h" |
---|
23 | |
---|
24 | extern "C" |
---|
25 | { |
---|
26 | struct tr_variant; |
---|
27 | } |
---|
28 | |
---|
29 | class Prefs: public QObject |
---|
30 | { |
---|
31 | Q_OBJECT; |
---|
32 | |
---|
33 | public: |
---|
34 | |
---|
35 | enum |
---|
36 | { |
---|
37 | /* client prefs */ |
---|
38 | OPTIONS_PROMPT, |
---|
39 | OPEN_DIALOG_FOLDER, |
---|
40 | INHIBIT_HIBERNATION, |
---|
41 | DIR_WATCH, |
---|
42 | DIR_WATCH_ENABLED, |
---|
43 | SHOW_TRAY_ICON, |
---|
44 | SHOW_DESKTOP_NOTIFICATION, |
---|
45 | ASKQUIT, |
---|
46 | SORT_MODE, |
---|
47 | SORT_REVERSED, |
---|
48 | COMPACT_VIEW, |
---|
49 | FILTERBAR, |
---|
50 | STATUSBAR, |
---|
51 | STATUSBAR_STATS, |
---|
52 | SHOW_TRACKER_SCRAPES, |
---|
53 | SHOW_BACKUP_TRACKERS, |
---|
54 | TOOLBAR, |
---|
55 | BLOCKLIST_DATE, |
---|
56 | BLOCKLIST_UPDATES_ENABLED, |
---|
57 | MAIN_WINDOW_LAYOUT_ORDER, |
---|
58 | MAIN_WINDOW_HEIGHT, |
---|
59 | MAIN_WINDOW_WIDTH, |
---|
60 | MAIN_WINDOW_X, |
---|
61 | MAIN_WINDOW_Y, |
---|
62 | FILTER_MODE, |
---|
63 | FILTER_TRACKERS, |
---|
64 | FILTER_TEXT, |
---|
65 | SESSION_IS_REMOTE, |
---|
66 | SESSION_REMOTE_HOST, |
---|
67 | SESSION_REMOTE_PORT, |
---|
68 | SESSION_REMOTE_AUTH, |
---|
69 | SESSION_REMOTE_USERNAME, |
---|
70 | SESSION_REMOTE_PASSWORD, |
---|
71 | USER_HAS_GIVEN_INFORMED_CONSENT, |
---|
72 | |
---|
73 | /* core prefs */ |
---|
74 | FIRST_CORE_PREF, |
---|
75 | ALT_SPEED_LIMIT_UP = FIRST_CORE_PREF, |
---|
76 | ALT_SPEED_LIMIT_DOWN, |
---|
77 | ALT_SPEED_LIMIT_ENABLED, |
---|
78 | ALT_SPEED_LIMIT_TIME_BEGIN, |
---|
79 | ALT_SPEED_LIMIT_TIME_END, |
---|
80 | ALT_SPEED_LIMIT_TIME_ENABLED, |
---|
81 | ALT_SPEED_LIMIT_TIME_DAY, |
---|
82 | BLOCKLIST_ENABLED, |
---|
83 | BLOCKLIST_URL, |
---|
84 | DSPEED, |
---|
85 | DSPEED_ENABLED, |
---|
86 | DOWNLOAD_DIR, |
---|
87 | DOWNLOAD_QUEUE_ENABLED, |
---|
88 | DOWNLOAD_QUEUE_SIZE, |
---|
89 | ENCRYPTION, |
---|
90 | IDLE_LIMIT, |
---|
91 | IDLE_LIMIT_ENABLED, |
---|
92 | INCOMPLETE_DIR, |
---|
93 | INCOMPLETE_DIR_ENABLED, |
---|
94 | MSGLEVEL, |
---|
95 | PEER_LIMIT_GLOBAL, |
---|
96 | PEER_LIMIT_TORRENT, |
---|
97 | PEER_PORT, |
---|
98 | PEER_PORT_RANDOM_ON_START, |
---|
99 | PEER_PORT_RANDOM_LOW, |
---|
100 | PEER_PORT_RANDOM_HIGH, |
---|
101 | QUEUE_STALLED_MINUTES, |
---|
102 | SCRIPT_TORRENT_DONE_ENABLED, |
---|
103 | SCRIPT_TORRENT_DONE_FILENAME, |
---|
104 | SOCKET_TOS, |
---|
105 | START, |
---|
106 | TRASH_ORIGINAL, |
---|
107 | PEX_ENABLED, |
---|
108 | DHT_ENABLED, |
---|
109 | UTP_ENABLED, |
---|
110 | LPD_ENABLED, |
---|
111 | PORT_FORWARDING, |
---|
112 | PREALLOCATION, |
---|
113 | RATIO, |
---|
114 | RATIO_ENABLED, |
---|
115 | RENAME_PARTIAL_FILES, |
---|
116 | RPC_AUTH_REQUIRED, |
---|
117 | RPC_ENABLED, |
---|
118 | RPC_PASSWORD, |
---|
119 | RPC_PORT, |
---|
120 | RPC_USERNAME, |
---|
121 | RPC_WHITELIST_ENABLED, |
---|
122 | RPC_WHITELIST, |
---|
123 | USPEED_ENABLED, |
---|
124 | USPEED, |
---|
125 | UPLOAD_SLOTS_PER_TORRENT, |
---|
126 | LAST_CORE_PREF = UPLOAD_SLOTS_PER_TORRENT, |
---|
127 | |
---|
128 | PREFS_COUNT |
---|
129 | }; |
---|
130 | |
---|
131 | private: |
---|
132 | |
---|
133 | struct PrefItem { |
---|
134 | int id; |
---|
135 | const char * key; |
---|
136 | int type; |
---|
137 | }; |
---|
138 | |
---|
139 | static PrefItem myItems[]; |
---|
140 | |
---|
141 | private: |
---|
142 | QSet<int> myTemporaryPrefs; |
---|
143 | QString myConfigDir; |
---|
144 | mutable QVariant myValues[PREFS_COUNT]; |
---|
145 | void initDefaults( struct tr_variant* ); |
---|
146 | |
---|
147 | public: |
---|
148 | bool isCore( int key ) const { return FIRST_CORE_PREF<=key && key<=LAST_CORE_PREF; } |
---|
149 | bool isClient( int key ) const { return !isCore( key ); } |
---|
150 | const char * keyStr( int i ) const { return myItems[i].key; } |
---|
151 | int type( int i ) const { return myItems[i].type; } |
---|
152 | const QVariant& variant( int i ) const { return myValues[i]; } |
---|
153 | |
---|
154 | Prefs( const char * configDir ); |
---|
155 | ~Prefs( ); |
---|
156 | |
---|
157 | int getInt( int key ) const; |
---|
158 | bool getBool( int key) const; |
---|
159 | QString getString( int key ) const; |
---|
160 | double getDouble( int key) const; |
---|
161 | QDateTime getDateTime( int key ) const; |
---|
162 | |
---|
163 | template<typename T> T get( int key ) const { |
---|
164 | return myValues[key].value<T>(); |
---|
165 | } |
---|
166 | |
---|
167 | void set( int key, char * value ) { set( key, QString::fromUtf8(value) ); } |
---|
168 | void set( int key, const char * value ) { set( key, QString::fromUtf8(value) ); } |
---|
169 | |
---|
170 | template<typename T> void set( int key, const T& value ) { |
---|
171 | QVariant& v( myValues[key] ); |
---|
172 | const QVariant tmp = QVariant::fromValue(value); |
---|
173 | if( v.isNull() || (v!=tmp) ) { |
---|
174 | v = tmp; |
---|
175 | emit changed( key ); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | void toggleBool( int key ); |
---|
180 | |
---|
181 | signals: |
---|
182 | void changed( int key ); |
---|
183 | }; |
---|
184 | |
---|
185 | #endif |
---|