2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2010-08-01 20:36:13 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib> // strtod
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/bencode.h>
|
|
|
|
#include <libtransmission/json.h>
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
#include "prefs.h"
|
2009-04-11 18:25:12 +00:00
|
|
|
#include "types.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
Prefs::PrefItem Prefs::myItems[] =
|
|
|
|
{
|
|
|
|
/* gui settings */
|
|
|
|
{ OPTIONS_PROMPT, "show-options-window", QVariant::Bool },
|
|
|
|
{ OPEN_DIALOG_FOLDER, "open-dialog-dir", QVariant::String },
|
|
|
|
{ INHIBIT_HIBERNATION, "inhibit-desktop-hibernation", QVariant::Bool },
|
|
|
|
{ DIR_WATCH, "watch-dir", QVariant::String },
|
|
|
|
{ DIR_WATCH_ENABLED, "watch-dir-enabled", QVariant::Bool },
|
|
|
|
{ SHOW_TRAY_ICON, "show-notification-area-icon", QVariant::Bool },
|
|
|
|
{ SHOW_DESKTOP_NOTIFICATION, "show-desktop-notification", QVariant::Bool },
|
|
|
|
{ ASKQUIT, "prompt-before-exit", QVariant::Bool },
|
2009-04-11 18:25:12 +00:00
|
|
|
{ SORT_MODE, "sort-mode", TrTypes::SortModeType },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ SORT_REVERSED, "sort-reversed", QVariant::Bool },
|
2010-03-15 14:42:56 +00:00
|
|
|
{ COMPACT_VIEW, "compact-view", QVariant::Bool },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ FILTERBAR, "show-filterbar", QVariant::Bool },
|
|
|
|
{ STATUSBAR, "show-statusbar", QVariant::Bool },
|
|
|
|
{ STATUSBAR_STATS, "statusbar-stats", QVariant::String },
|
2010-07-28 14:43:47 +00:00
|
|
|
{ SHOW_TRACKER_SCRAPES, "show-extra-peer-details", QVariant::Bool },
|
|
|
|
{ SHOW_BACKUP_TRACKERS, "show-backup-trackers", QVariant::Bool },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ TOOLBAR, "show-toolbar" , QVariant::Bool },
|
|
|
|
{ BLOCKLIST_DATE, "blocklist-date", QVariant::DateTime },
|
|
|
|
{ BLOCKLIST_UPDATES_ENABLED, "blocklist-updates-enabled" , QVariant::Bool },
|
2009-04-10 04:59:15 +00:00
|
|
|
{ MAIN_WINDOW_LAYOUT_ORDER, "main-window-layout-order", QVariant::String },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ MAIN_WINDOW_HEIGHT, "main-window-height", QVariant::Int },
|
|
|
|
{ MAIN_WINDOW_WIDTH, "main-window-width", QVariant::Int },
|
|
|
|
{ MAIN_WINDOW_X, "main-window-x", QVariant::Int },
|
|
|
|
{ MAIN_WINDOW_Y, "main-window-y", QVariant::Int },
|
2009-04-11 18:25:12 +00:00
|
|
|
{ FILTER_MODE, "filter-mode", TrTypes::FilterModeType },
|
2010-07-30 22:31:31 +00:00
|
|
|
{ FILTER_TRACKERS, "filter-trackers", QVariant::String },
|
|
|
|
{ FILTER_TEXT, "filter-text", QVariant::String },
|
2009-05-03 17:37:39 +00:00
|
|
|
{ SESSION_IS_REMOTE, "remote-session-enabled", QVariant::Bool },
|
|
|
|
{ SESSION_REMOTE_HOST, "remote-session-host", QVariant::String },
|
|
|
|
{ SESSION_REMOTE_PORT, "remote-session-port", QVariant::Int },
|
|
|
|
{ SESSION_REMOTE_AUTH, "remote-session-requres-authentication", QVariant::Bool },
|
|
|
|
{ SESSION_REMOTE_USERNAME, "remote-session-username", QVariant::String },
|
|
|
|
{ SESSION_REMOTE_PASSWORD, "remote-session-password", QVariant::String },
|
2009-10-02 22:53:19 +00:00
|
|
|
{ USER_HAS_GIVEN_INFORMED_CONSENT, "user-has-given-informed-consent", QVariant::Bool },
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/* libtransmission settings */
|
2010-07-04 06:07:21 +00:00
|
|
|
{ ALT_SPEED_LIMIT_UP, TR_PREFS_KEY_ALT_SPEED_UP_KBps, QVariant::Int },
|
|
|
|
{ ALT_SPEED_LIMIT_DOWN, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, QVariant::Int },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ ALT_SPEED_LIMIT_ENABLED, TR_PREFS_KEY_ALT_SPEED_ENABLED, QVariant::Bool },
|
|
|
|
{ ALT_SPEED_LIMIT_TIME_BEGIN, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, QVariant::Int },
|
|
|
|
{ ALT_SPEED_LIMIT_TIME_END, TR_PREFS_KEY_ALT_SPEED_TIME_END, QVariant::Int },
|
|
|
|
{ ALT_SPEED_LIMIT_TIME_ENABLED, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, QVariant::Bool },
|
|
|
|
{ ALT_SPEED_LIMIT_TIME_DAY, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, QVariant::Int },
|
|
|
|
{ BLOCKLIST_ENABLED, TR_PREFS_KEY_BLOCKLIST_ENABLED, QVariant::Bool },
|
2010-10-31 17:16:12 +00:00
|
|
|
{ BLOCKLIST_URL, TR_PREFS_KEY_BLOCKLIST_URL, QVariant::String },
|
2010-07-04 06:07:21 +00:00
|
|
|
{ DSPEED, TR_PREFS_KEY_DSPEED_KBps, QVariant::Int },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ DSPEED_ENABLED, TR_PREFS_KEY_DSPEED_ENABLED, QVariant::Bool },
|
|
|
|
{ DOWNLOAD_DIR, TR_PREFS_KEY_DOWNLOAD_DIR, QVariant::String },
|
|
|
|
{ ENCRYPTION, TR_PREFS_KEY_ENCRYPTION, QVariant::Int },
|
2010-07-24 02:57:39 +00:00
|
|
|
{ IDLE_LIMIT, TR_PREFS_KEY_IDLE_LIMIT, QVariant::Int },
|
|
|
|
{ IDLE_LIMIT_ENABLED, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, QVariant::Bool },
|
2009-10-19 05:25:50 +00:00
|
|
|
{ INCOMPLETE_DIR, TR_PREFS_KEY_INCOMPLETE_DIR, QVariant::String },
|
|
|
|
{ INCOMPLETE_DIR_ENABLED, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, QVariant::Bool },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ MSGLEVEL, TR_PREFS_KEY_MSGLEVEL, QVariant::Int },
|
|
|
|
{ OPEN_FILE_LIMIT, TR_PREFS_KEY_OPEN_FILE_LIMIT, QVariant::Int },
|
|
|
|
{ PEER_LIMIT_GLOBAL, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, QVariant::Int },
|
|
|
|
{ PEER_LIMIT_TORRENT, TR_PREFS_KEY_PEER_LIMIT_TORRENT, QVariant::Int },
|
|
|
|
{ PEER_PORT, TR_PREFS_KEY_PEER_PORT, QVariant::Int },
|
|
|
|
{ PEER_PORT_RANDOM_ON_START, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, QVariant::Bool },
|
|
|
|
{ PEER_PORT_RANDOM_LOW, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, QVariant::Int },
|
|
|
|
{ PEER_PORT_RANDOM_HIGH, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, QVariant::Int },
|
2010-05-08 22:42:28 +00:00
|
|
|
{ SCRIPT_TORRENT_DONE_ENABLED, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, QVariant::Bool },
|
|
|
|
{ SCRIPT_TORRENT_DONE_FILENAME, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, QVariant::String },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ SOCKET_TOS, TR_PREFS_KEY_PEER_SOCKET_TOS, QVariant::Int },
|
2010-03-17 19:23:03 +00:00
|
|
|
{ START, TR_PREFS_KEY_START, QVariant::Bool },
|
|
|
|
{ TRASH_ORIGINAL, TR_PREFS_KEY_TRASH_ORIGINAL, QVariant::Bool },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ PEX_ENABLED, TR_PREFS_KEY_PEX_ENABLED, QVariant::Bool },
|
2009-05-21 00:15:54 +00:00
|
|
|
{ DHT_ENABLED, TR_PREFS_KEY_DHT_ENABLED, QVariant::Bool },
|
2011-02-18 00:33:29 +00:00
|
|
|
{ UTP_ENABLED, TR_PREFS_KEY_UTP_ENABLED, QVariant::Bool },
|
2010-05-08 08:42:45 +00:00
|
|
|
{ LPD_ENABLED, TR_PREFS_KEY_LPD_ENABLED, QVariant::Bool },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ PORT_FORWARDING, TR_PREFS_KEY_PORT_FORWARDING, QVariant::Bool },
|
|
|
|
{ PREALLOCATION, TR_PREFS_KEY_PREALLOCATION, QVariant::Int },
|
|
|
|
{ RATIO, TR_PREFS_KEY_RATIO, QVariant::Double },
|
|
|
|
{ RATIO_ENABLED, TR_PREFS_KEY_RATIO_ENABLED, QVariant::Bool },
|
2010-02-01 04:43:10 +00:00
|
|
|
{ RENAME_PARTIAL_FILES, TR_PREFS_KEY_RENAME_PARTIAL_FILES, QVariant::Bool },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ RPC_AUTH_REQUIRED, TR_PREFS_KEY_RPC_AUTH_REQUIRED, QVariant::Bool },
|
|
|
|
{ RPC_ENABLED, TR_PREFS_KEY_RPC_ENABLED, QVariant::Bool },
|
|
|
|
{ RPC_PASSWORD, TR_PREFS_KEY_RPC_PASSWORD, QVariant::String },
|
|
|
|
{ RPC_PORT, TR_PREFS_KEY_RPC_PORT, QVariant::Int },
|
|
|
|
{ RPC_USERNAME, TR_PREFS_KEY_RPC_USERNAME, QVariant::String },
|
|
|
|
{ RPC_WHITELIST_ENABLED, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, QVariant::Bool },
|
|
|
|
{ RPC_WHITELIST, TR_PREFS_KEY_RPC_WHITELIST, QVariant::String },
|
|
|
|
{ USPEED_ENABLED, TR_PREFS_KEY_USPEED_ENABLED, QVariant::Bool },
|
2010-07-04 06:07:21 +00:00
|
|
|
{ USPEED, TR_PREFS_KEY_USPEED_KBps, QVariant::Int },
|
2009-04-09 18:55:47 +00:00
|
|
|
{ UPLOAD_SLOTS_PER_TORRENT, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, QVariant::Int }
|
|
|
|
};
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
Prefs :: Prefs( const char * configDir ):
|
|
|
|
myConfigDir( configDir )
|
|
|
|
{
|
|
|
|
assert( sizeof(myItems) / sizeof(myItems[0]) == PREFS_COUNT );
|
|
|
|
for( int i=0; i<PREFS_COUNT; ++i )
|
|
|
|
assert( myItems[i].id == i );
|
|
|
|
|
2010-07-30 22:31:31 +00:00
|
|
|
// these are the prefs that don't get saved to settings.json
|
|
|
|
// when the application exits.
|
|
|
|
myTemporaryPrefs << FILTER_TEXT;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
tr_benc top;
|
|
|
|
tr_bencInitDict( &top, 0 );
|
|
|
|
initDefaults( &top );
|
|
|
|
tr_sessionLoadSettings( &top, configDir, NULL );
|
|
|
|
for( int i=0; i<PREFS_COUNT; ++i )
|
|
|
|
{
|
|
|
|
double d;
|
2011-03-23 18:26:01 +00:00
|
|
|
bool boolVal;
|
2009-04-09 18:55:47 +00:00
|
|
|
int64_t intVal;
|
|
|
|
const char * str;
|
|
|
|
tr_benc * b( tr_bencDictFind( &top, myItems[i].key ) );
|
|
|
|
|
|
|
|
switch( myItems[i].type )
|
|
|
|
{
|
|
|
|
case QVariant::Int:
|
|
|
|
if( tr_bencGetInt( b, &intVal ) )
|
|
|
|
myValues[i].setValue( qlonglong(intVal) );
|
|
|
|
break;
|
2009-04-11 18:25:12 +00:00
|
|
|
case TrTypes::SortModeType:
|
|
|
|
if( tr_bencGetStr( b, &str ) )
|
|
|
|
myValues[i] = QVariant::fromValue( SortMode( str ) );
|
|
|
|
break;
|
|
|
|
case TrTypes::FilterModeType:
|
|
|
|
if( tr_bencGetStr( b, &str ) )
|
|
|
|
myValues[i] = QVariant::fromValue( FilterMode( str ) );
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
case QVariant::String:
|
|
|
|
if( tr_bencGetStr( b, &str ) )
|
|
|
|
myValues[i].setValue( QString::fromUtf8(str) );
|
|
|
|
break;
|
|
|
|
case QVariant::Bool:
|
|
|
|
if( tr_bencGetBool( b, &boolVal ) )
|
|
|
|
myValues[i].setValue( bool(boolVal) );
|
|
|
|
break;
|
|
|
|
case QVariant::Double:
|
|
|
|
if( tr_bencGetReal( b, &d ) )
|
|
|
|
myValues[i].setValue( d );
|
|
|
|
break;
|
|
|
|
case QVariant::DateTime:
|
|
|
|
if( tr_bencGetInt( b, &intVal ) )
|
|
|
|
myValues[i].setValue( QDateTime :: fromTime_t( intVal ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( "unhandled type" && 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_bencFree( &top );
|
|
|
|
}
|
|
|
|
|
|
|
|
Prefs :: ~Prefs( )
|
|
|
|
{
|
|
|
|
tr_benc top;
|
|
|
|
|
|
|
|
/* load in the existing preferences file */
|
|
|
|
QFile file( QDir( myConfigDir ).absoluteFilePath( "settings.json" ) );
|
|
|
|
file.open( QIODevice::ReadOnly | QIODevice::Text );
|
|
|
|
const QByteArray oldPrefs = file.readAll( );
|
|
|
|
file.close( );
|
2009-06-01 18:57:37 +00:00
|
|
|
if( tr_jsonParse( "settings.json", oldPrefs.data(), oldPrefs.length(), &top, NULL ) )
|
2009-04-09 18:55:47 +00:00
|
|
|
tr_bencInitDict( &top, PREFS_COUNT );
|
|
|
|
|
|
|
|
/* merge our own settings with the ones already in the file */
|
2010-07-30 22:31:31 +00:00
|
|
|
for( int i=0; i<PREFS_COUNT; ++i )
|
|
|
|
{
|
|
|
|
if( myTemporaryPrefs.contains( i ) )
|
|
|
|
continue;
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
const char * key = myItems[i].key;
|
|
|
|
const QVariant& val = myValues[i];
|
2010-07-30 22:31:31 +00:00
|
|
|
|
|
|
|
switch( myItems[i].type )
|
|
|
|
{
|
2009-04-09 18:55:47 +00:00
|
|
|
case QVariant::Int:
|
|
|
|
tr_bencDictAddInt( &top, key, val.toInt() );
|
|
|
|
break;
|
2009-04-11 18:25:12 +00:00
|
|
|
case TrTypes::SortModeType:
|
|
|
|
tr_bencDictAddStr( &top, key, val.value<SortMode>().name().toUtf8().constData() );
|
|
|
|
break;
|
|
|
|
case TrTypes::FilterModeType:
|
|
|
|
tr_bencDictAddStr( &top, key, val.value<FilterMode>().name().toUtf8().constData() );
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
case QVariant::String:
|
|
|
|
tr_bencDictAddStr( &top, key, val.toString().toUtf8().constData() );
|
|
|
|
break;
|
|
|
|
case QVariant::Bool:
|
|
|
|
tr_bencDictAddBool( &top, key, val.toBool() );
|
|
|
|
break;
|
|
|
|
case QVariant::Double:
|
|
|
|
tr_bencDictAddReal( &top, key, val.toDouble() );
|
|
|
|
break;
|
|
|
|
case QVariant::DateTime:
|
|
|
|
tr_bencDictAddInt( &top, key, val.toDateTime().toTime_t() );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( "unhandled type" && 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write back out the serialized preferences */
|
2009-06-02 01:48:48 +00:00
|
|
|
tr_bencToFile( &top, TR_FMT_JSON, file.fileName().toUtf8().constData() );
|
2009-04-09 18:55:47 +00:00
|
|
|
tr_bencFree( &top );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is where we initialize the preferences file with the default values.
|
|
|
|
* If you add a new preferences key, you /must/ add a default value here.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Prefs :: initDefaults( tr_benc * d )
|
|
|
|
{
|
2010-07-28 14:43:47 +00:00
|
|
|
tr_bencDictAddStr ( d, keyStr(DIR_WATCH), tr_getDefaultDownloadDir( ) );
|
|
|
|
tr_bencDictAddBool( d, keyStr(DIR_WATCH_ENABLED), false );
|
|
|
|
tr_bencDictAddBool( d, keyStr(INHIBIT_HIBERNATION), false );
|
|
|
|
tr_bencDictAddInt ( d, keyStr(BLOCKLIST_DATE), 0 );
|
|
|
|
tr_bencDictAddBool( d, keyStr(BLOCKLIST_UPDATES_ENABLED), true );
|
|
|
|
tr_bencDictAddStr ( d, keyStr(OPEN_DIALOG_FOLDER), QDir::home().absolutePath().toLatin1() );
|
|
|
|
tr_bencDictAddInt ( d, keyStr(SHOW_TRACKER_SCRAPES), false );
|
|
|
|
tr_bencDictAddBool( d, keyStr(TOOLBAR), true );
|
|
|
|
tr_bencDictAddBool( d, keyStr(FILTERBAR), true );
|
|
|
|
tr_bencDictAddBool( d, keyStr(STATUSBAR), true );
|
|
|
|
tr_bencDictAddBool( d, keyStr(SHOW_TRAY_ICON), false );
|
|
|
|
tr_bencDictAddBool( d, keyStr(SHOW_DESKTOP_NOTIFICATION), true );
|
|
|
|
tr_bencDictAddStr ( d, keyStr(STATUSBAR_STATS), "total-ratio" );
|
|
|
|
tr_bencDictAddBool( d, keyStr(SHOW_TRACKER_SCRAPES), false );
|
|
|
|
tr_bencDictAddBool( d, keyStr(SHOW_BACKUP_TRACKERS), false );
|
|
|
|
tr_bencDictAddBool( d, keyStr(OPTIONS_PROMPT), true );
|
|
|
|
tr_bencDictAddInt ( d, keyStr(MAIN_WINDOW_HEIGHT), 500 );
|
|
|
|
tr_bencDictAddInt ( d, keyStr(MAIN_WINDOW_WIDTH), 300 );
|
|
|
|
tr_bencDictAddInt ( d, keyStr(MAIN_WINDOW_X), 50 );
|
|
|
|
tr_bencDictAddInt ( d, keyStr(MAIN_WINDOW_Y), 50 );
|
|
|
|
tr_bencDictAddStr ( d, keyStr(FILTER_MODE), "all" );
|
|
|
|
tr_bencDictAddStr ( d, keyStr(MAIN_WINDOW_LAYOUT_ORDER), "menu,toolbar,filter,list,statusbar" );
|
|
|
|
tr_bencDictAddStr ( d, keyStr(DOWNLOAD_DIR), tr_getDefaultDownloadDir( ) );
|
|
|
|
tr_bencDictAddBool( d, keyStr(ASKQUIT), true );
|
|
|
|
tr_bencDictAddStr ( d, keyStr(SORT_MODE), "sort-by-name" );
|
|
|
|
tr_bencDictAddBool( d, keyStr(SORT_REVERSED), false );
|
|
|
|
tr_bencDictAddBool( d, keyStr(COMPACT_VIEW), false );
|
|
|
|
tr_bencDictAddStr ( d, keyStr(SESSION_REMOTE_HOST), "localhost" );
|
|
|
|
tr_bencDictAddInt ( d, keyStr(SESSION_REMOTE_PORT), atoi(TR_DEFAULT_RPC_PORT_STR) );
|
2009-05-03 17:37:39 +00:00
|
|
|
tr_bencDictAddBool( d, keyStr(SESSION_IS_REMOTE), false );
|
|
|
|
tr_bencDictAddBool( d, keyStr(SESSION_REMOTE_AUTH), false );
|
2009-10-02 22:53:19 +00:00
|
|
|
tr_bencDictAddBool( d, keyStr(USER_HAS_GIVEN_INFORMED_CONSENT), false );
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
bool
|
|
|
|
Prefs :: getBool( int key ) const
|
|
|
|
{
|
|
|
|
assert( myItems[key].type == QVariant::Bool );
|
|
|
|
return myValues[key].toBool( );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
Prefs :: getString( int key ) const
|
|
|
|
{
|
|
|
|
assert( myItems[key].type == QVariant::String );
|
|
|
|
return myValues[key].toString( );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
Prefs :: getInt( int key ) const
|
|
|
|
{
|
|
|
|
assert( myItems[key].type == QVariant::Int );
|
|
|
|
return myValues[key].toInt( );
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
Prefs :: getDouble( int key ) const
|
|
|
|
{
|
|
|
|
assert( myItems[key].type == QVariant::Double );
|
|
|
|
return myValues[key].toDouble( );
|
|
|
|
}
|
|
|
|
|
|
|
|
QDateTime
|
|
|
|
Prefs :: getDateTime( int key ) const
|
|
|
|
{
|
|
|
|
assert( myItems[key].type == QVariant::DateTime );
|
|
|
|
return myValues[key].toDateTime( );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
void
|
|
|
|
Prefs :: toggleBool( int key )
|
|
|
|
{
|
|
|
|
set( key, !getBool( key ) );
|
|
|
|
}
|