[8188] | 1 | /* |
---|
| 2 | * This file Copyright (C) 2009 Charles Kerr <charles@transmissionbt.com> |
---|
| 3 | * |
---|
| 4 | * This file is licensed by the GPL version 2. Works owned by the |
---|
| 5 | * Transmission project are granted a special exemption to clause 2(b) |
---|
| 6 | * so that the bulk of its code can remain under the MIT license. |
---|
| 7 | * This exemption does not extend to derived works not owned by |
---|
| 8 | * the Transmission project. |
---|
| 9 | * |
---|
| 10 | * $Id:$ |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #ifndef QTR_PREFS_H |
---|
| 14 | #define QTR_PREFS_H |
---|
| 15 | |
---|
| 16 | #include <QDateTime> |
---|
| 17 | #include <QObject> |
---|
| 18 | #include <QString> |
---|
| 19 | #include <QVariant> |
---|
| 20 | |
---|
[8216] | 21 | #include "filters.h" |
---|
| 22 | |
---|
[8232] | 23 | extern "C" |
---|
| 24 | { |
---|
| 25 | struct tr_benc; |
---|
| 26 | } |
---|
| 27 | |
---|
[8188] | 28 | class Prefs: public QObject |
---|
| 29 | { |
---|
| 30 | Q_OBJECT; |
---|
| 31 | |
---|
| 32 | public: |
---|
| 33 | |
---|
| 34 | enum |
---|
| 35 | { |
---|
| 36 | /* client prefs */ |
---|
| 37 | OPTIONS_PROMPT, |
---|
| 38 | OPEN_DIALOG_FOLDER, |
---|
| 39 | INHIBIT_HIBERNATION, |
---|
| 40 | DIR_WATCH, |
---|
| 41 | DIR_WATCH_ENABLED, |
---|
| 42 | SHOW_TRAY_ICON, |
---|
| 43 | SHOW_DESKTOP_NOTIFICATION, |
---|
| 44 | START, |
---|
| 45 | TRASH_ORIGINAL, |
---|
| 46 | ASKQUIT, |
---|
| 47 | SORT_MODE, |
---|
| 48 | SORT_REVERSED, |
---|
| 49 | MINIMAL_VIEW, |
---|
| 50 | FILTERBAR, |
---|
| 51 | STATUSBAR, |
---|
| 52 | STATUSBAR_STATS, |
---|
| 53 | TOOLBAR, |
---|
| 54 | BLOCKLIST_DATE, |
---|
| 55 | BLOCKLIST_UPDATES_ENABLED, |
---|
| 56 | MAIN_WINDOW_LAYOUT_ORDER, |
---|
| 57 | MAIN_WINDOW_HEIGHT, |
---|
| 58 | MAIN_WINDOW_WIDTH, |
---|
| 59 | MAIN_WINDOW_X, |
---|
| 60 | MAIN_WINDOW_Y, |
---|
[8194] | 61 | FILTER_MODE, |
---|
[8323] | 62 | SESSION_IS_REMOTE, |
---|
| 63 | SESSION_REMOTE_HOST, |
---|
| 64 | SESSION_REMOTE_PORT, |
---|
| 65 | SESSION_REMOTE_AUTH, |
---|
| 66 | SESSION_REMOTE_USERNAME, |
---|
| 67 | SESSION_REMOTE_PASSWORD, |
---|
[8188] | 68 | |
---|
| 69 | /* core prefs */ |
---|
| 70 | FIRST_CORE_PREF, |
---|
| 71 | ALT_SPEED_LIMIT_UP = FIRST_CORE_PREF, |
---|
| 72 | ALT_SPEED_LIMIT_DOWN, |
---|
| 73 | ALT_SPEED_LIMIT_ENABLED, |
---|
| 74 | ALT_SPEED_LIMIT_TIME_BEGIN, |
---|
| 75 | ALT_SPEED_LIMIT_TIME_END, |
---|
| 76 | ALT_SPEED_LIMIT_TIME_ENABLED, |
---|
| 77 | ALT_SPEED_LIMIT_TIME_DAY, |
---|
| 78 | BLOCKLIST_ENABLED, |
---|
| 79 | DSPEED, |
---|
| 80 | DSPEED_ENABLED, |
---|
| 81 | DOWNLOAD_DIR, |
---|
| 82 | ENCRYPTION, |
---|
| 83 | LAZY_BITFIELD, |
---|
| 84 | MSGLEVEL, |
---|
| 85 | OPEN_FILE_LIMIT, |
---|
| 86 | PEER_LIMIT_GLOBAL, |
---|
| 87 | PEER_LIMIT_TORRENT, |
---|
| 88 | PEER_PORT, |
---|
| 89 | PEER_PORT_RANDOM_ON_START, |
---|
| 90 | PEER_PORT_RANDOM_LOW, |
---|
| 91 | PEER_PORT_RANDOM_HIGH, |
---|
| 92 | SOCKET_TOS, |
---|
| 93 | PEX_ENABLED, |
---|
| 94 | PORT_FORWARDING, |
---|
| 95 | PROXY_AUTH_ENABLED, |
---|
| 96 | PREALLOCATION, |
---|
| 97 | PROXY_ENABLED, |
---|
| 98 | PROXY_PASSWORD, |
---|
| 99 | PROXY_PORT, |
---|
| 100 | PROXY, |
---|
| 101 | PROXY_TYPE, |
---|
| 102 | PROXY_USERNAME, |
---|
| 103 | RATIO, |
---|
| 104 | RATIO_ENABLED, |
---|
| 105 | RPC_AUTH_REQUIRED, |
---|
| 106 | RPC_ENABLED, |
---|
| 107 | RPC_PASSWORD, |
---|
| 108 | RPC_PORT, |
---|
| 109 | RPC_USERNAME, |
---|
| 110 | RPC_WHITELIST_ENABLED, |
---|
| 111 | RPC_WHITELIST, |
---|
| 112 | USPEED_ENABLED, |
---|
| 113 | USPEED, |
---|
| 114 | UPLOAD_SLOTS_PER_TORRENT, |
---|
| 115 | LAST_CORE_PREF = UPLOAD_SLOTS_PER_TORRENT, |
---|
| 116 | |
---|
| 117 | PREFS_COUNT |
---|
| 118 | }; |
---|
| 119 | |
---|
| 120 | private: |
---|
| 121 | |
---|
| 122 | struct PrefItem { |
---|
| 123 | int id; |
---|
| 124 | const char * key; |
---|
[8216] | 125 | int type; |
---|
[8188] | 126 | }; |
---|
| 127 | |
---|
| 128 | static PrefItem myItems[]; |
---|
| 129 | |
---|
| 130 | private: |
---|
| 131 | QString myConfigDir; |
---|
| 132 | QVariant myValues[PREFS_COUNT]; |
---|
[8232] | 133 | void initDefaults( struct tr_benc* ); |
---|
[8188] | 134 | |
---|
| 135 | public: |
---|
| 136 | bool isCore( int key ) const { return FIRST_CORE_PREF<=key && key<=LAST_CORE_PREF; } |
---|
| 137 | bool isClient( int key ) const { return !isCore( key ); } |
---|
| 138 | const char * keyStr( int i ) const { return myItems[i].key; } |
---|
[8216] | 139 | int type( int i ) const { return myItems[i].type; } |
---|
[8188] | 140 | const QVariant& variant( int i ) const { return myValues[i]; } |
---|
| 141 | |
---|
| 142 | Prefs( const char * configDir ); |
---|
| 143 | ~Prefs( ); |
---|
| 144 | |
---|
| 145 | int getInt( int key ) const; |
---|
| 146 | bool getBool( int key) const; |
---|
| 147 | QString getString( int key ) const; |
---|
| 148 | double getDouble( int key) const; |
---|
| 149 | QDateTime getDateTime( int key ) const; |
---|
| 150 | |
---|
[8216] | 151 | template<typename T> T get( int key ) const { |
---|
| 152 | return myValues[key].value<T>(); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | void set( int key, char * value ) { set( key, QString::fromUtf8(value) ); } |
---|
| 156 | void set( int key, const char * value ) { set( key, QString::fromUtf8(value) ); } |
---|
| 157 | |
---|
[8188] | 158 | template<typename T> void set( int key, const T& value ) { |
---|
| 159 | QVariant& v( myValues[key] ); |
---|
[8216] | 160 | const QVariant tmp = QVariant::fromValue(value); |
---|
[8188] | 161 | if( v.isNull() || (v!=tmp) ) { |
---|
| 162 | v = tmp; |
---|
| 163 | emit changed( key ); |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | void toggleBool( int key ); |
---|
| 168 | |
---|
| 169 | signals: |
---|
| 170 | void changed( int key ); |
---|
| 171 | }; |
---|
| 172 | |
---|
| 173 | #endif |
---|