2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2010-01-04 21:00:47 +00:00
|
|
|
* This file Copyright (C) 2009-2010 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QTR_PREFS_H
|
|
|
|
#define QTR_PREFS_H
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2009-04-11 18:25:12 +00:00
|
|
|
#include "filters.h"
|
|
|
|
|
2009-04-13 18:21:22 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
struct tr_benc;
|
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
class Prefs: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* client prefs */
|
|
|
|
OPTIONS_PROMPT,
|
|
|
|
OPEN_DIALOG_FOLDER,
|
|
|
|
INHIBIT_HIBERNATION,
|
|
|
|
DIR_WATCH,
|
|
|
|
DIR_WATCH_ENABLED,
|
|
|
|
SHOW_TRAY_ICON,
|
|
|
|
SHOW_DESKTOP_NOTIFICATION,
|
|
|
|
ASKQUIT,
|
|
|
|
SORT_MODE,
|
|
|
|
SORT_REVERSED,
|
2010-03-15 14:42:56 +00:00
|
|
|
COMPACT_VIEW,
|
2010-04-03 14:23:29 +00:00
|
|
|
SHOW_BACKUP_TRACKERS,
|
2009-04-09 18:55:47 +00:00
|
|
|
FILTERBAR,
|
|
|
|
STATUSBAR,
|
|
|
|
STATUSBAR_STATS,
|
2010-04-03 14:23:29 +00:00
|
|
|
SHOW_TRACKER_SCRAPES,
|
2009-04-09 18:55:47 +00:00
|
|
|
TOOLBAR,
|
|
|
|
BLOCKLIST_DATE,
|
|
|
|
BLOCKLIST_UPDATES_ENABLED,
|
|
|
|
MAIN_WINDOW_LAYOUT_ORDER,
|
|
|
|
MAIN_WINDOW_HEIGHT,
|
|
|
|
MAIN_WINDOW_WIDTH,
|
|
|
|
MAIN_WINDOW_X,
|
|
|
|
MAIN_WINDOW_Y,
|
2009-04-10 03:48:19 +00:00
|
|
|
FILTER_MODE,
|
2009-05-03 17:37:39 +00:00
|
|
|
SESSION_IS_REMOTE,
|
|
|
|
SESSION_REMOTE_HOST,
|
|
|
|
SESSION_REMOTE_PORT,
|
|
|
|
SESSION_REMOTE_AUTH,
|
|
|
|
SESSION_REMOTE_USERNAME,
|
|
|
|
SESSION_REMOTE_PASSWORD,
|
2009-10-02 22:53:19 +00:00
|
|
|
USER_HAS_GIVEN_INFORMED_CONSENT,
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/* core prefs */
|
|
|
|
FIRST_CORE_PREF,
|
|
|
|
ALT_SPEED_LIMIT_UP = FIRST_CORE_PREF,
|
|
|
|
ALT_SPEED_LIMIT_DOWN,
|
|
|
|
ALT_SPEED_LIMIT_ENABLED,
|
|
|
|
ALT_SPEED_LIMIT_TIME_BEGIN,
|
|
|
|
ALT_SPEED_LIMIT_TIME_END,
|
|
|
|
ALT_SPEED_LIMIT_TIME_ENABLED,
|
|
|
|
ALT_SPEED_LIMIT_TIME_DAY,
|
|
|
|
BLOCKLIST_ENABLED,
|
|
|
|
DSPEED,
|
|
|
|
DSPEED_ENABLED,
|
|
|
|
DOWNLOAD_DIR,
|
|
|
|
ENCRYPTION,
|
2009-10-19 05:25:50 +00:00
|
|
|
INCOMPLETE_DIR,
|
|
|
|
INCOMPLETE_DIR_ENABLED,
|
2009-04-09 18:55:47 +00:00
|
|
|
LAZY_BITFIELD,
|
|
|
|
MSGLEVEL,
|
|
|
|
OPEN_FILE_LIMIT,
|
|
|
|
PEER_LIMIT_GLOBAL,
|
|
|
|
PEER_LIMIT_TORRENT,
|
|
|
|
PEER_PORT,
|
|
|
|
PEER_PORT_RANDOM_ON_START,
|
|
|
|
PEER_PORT_RANDOM_LOW,
|
|
|
|
PEER_PORT_RANDOM_HIGH,
|
2010-05-08 22:42:28 +00:00
|
|
|
SCRIPT_TORRENT_DONE_ENABLED,
|
|
|
|
SCRIPT_TORRENT_DONE_FILENAME,
|
2009-04-09 18:55:47 +00:00
|
|
|
SOCKET_TOS,
|
2010-03-17 19:23:03 +00:00
|
|
|
START,
|
|
|
|
TRASH_ORIGINAL,
|
2009-04-09 18:55:47 +00:00
|
|
|
PEX_ENABLED,
|
2009-05-21 00:15:54 +00:00
|
|
|
DHT_ENABLED,
|
2010-05-08 08:42:45 +00:00
|
|
|
LPD_ENABLED,
|
2009-04-09 18:55:47 +00:00
|
|
|
PORT_FORWARDING,
|
|
|
|
PROXY_AUTH_ENABLED,
|
|
|
|
PREALLOCATION,
|
|
|
|
PROXY_ENABLED,
|
|
|
|
PROXY_PASSWORD,
|
|
|
|
PROXY_PORT,
|
|
|
|
PROXY,
|
|
|
|
PROXY_TYPE,
|
|
|
|
PROXY_USERNAME,
|
|
|
|
RATIO,
|
|
|
|
RATIO_ENABLED,
|
2010-02-01 04:43:10 +00:00
|
|
|
RENAME_PARTIAL_FILES,
|
2009-04-09 18:55:47 +00:00
|
|
|
RPC_AUTH_REQUIRED,
|
|
|
|
RPC_ENABLED,
|
|
|
|
RPC_PASSWORD,
|
|
|
|
RPC_PORT,
|
|
|
|
RPC_USERNAME,
|
|
|
|
RPC_WHITELIST_ENABLED,
|
|
|
|
RPC_WHITELIST,
|
|
|
|
USPEED_ENABLED,
|
|
|
|
USPEED,
|
|
|
|
UPLOAD_SLOTS_PER_TORRENT,
|
|
|
|
LAST_CORE_PREF = UPLOAD_SLOTS_PER_TORRENT,
|
|
|
|
|
|
|
|
PREFS_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
struct PrefItem {
|
|
|
|
int id;
|
|
|
|
const char * key;
|
2009-04-11 18:25:12 +00:00
|
|
|
int type;
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static PrefItem myItems[];
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString myConfigDir;
|
|
|
|
QVariant myValues[PREFS_COUNT];
|
2009-04-13 18:21:22 +00:00
|
|
|
void initDefaults( struct tr_benc* );
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool isCore( int key ) const { return FIRST_CORE_PREF<=key && key<=LAST_CORE_PREF; }
|
|
|
|
bool isClient( int key ) const { return !isCore( key ); }
|
|
|
|
const char * keyStr( int i ) const { return myItems[i].key; }
|
2009-04-11 18:25:12 +00:00
|
|
|
int type( int i ) const { return myItems[i].type; }
|
2009-04-09 18:55:47 +00:00
|
|
|
const QVariant& variant( int i ) const { return myValues[i]; }
|
|
|
|
|
|
|
|
Prefs( const char * configDir );
|
|
|
|
~Prefs( );
|
|
|
|
|
|
|
|
int getInt( int key ) const;
|
|
|
|
bool getBool( int key) const;
|
|
|
|
QString getString( int key ) const;
|
|
|
|
double getDouble( int key) const;
|
|
|
|
QDateTime getDateTime( int key ) const;
|
|
|
|
|
2009-04-11 18:25:12 +00:00
|
|
|
template<typename T> T get( int key ) const {
|
|
|
|
return myValues[key].value<T>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set( int key, char * value ) { set( key, QString::fromUtf8(value) ); }
|
|
|
|
void set( int key, const char * value ) { set( key, QString::fromUtf8(value) ); }
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
template<typename T> void set( int key, const T& value ) {
|
|
|
|
QVariant& v( myValues[key] );
|
2009-04-11 18:25:12 +00:00
|
|
|
const QVariant tmp = QVariant::fromValue(value);
|
2009-04-09 18:55:47 +00:00
|
|
|
if( v.isNull() || (v!=tmp) ) {
|
|
|
|
v = tmp;
|
|
|
|
emit changed( key );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleBool( int key );
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void changed( int key );
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|