2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2015-06-10 21:27:11 +00:00
|
|
|
* This file Copyright (C) 2009-2015 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
#include <array>
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QObject>
|
2010-07-30 22:31:31 +00:00
|
|
|
#include <QSet>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
#include <libtransmission/quark.h>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Filters.h"
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "Macros.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
class QDateTime;
|
|
|
|
|
2009-04-13 18:21:22 +00:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_variant;
|
2009-04-13 18:21:22 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
class Prefs : public QObject
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2014-12-11 05:11:02 +00:00
|
|
|
Q_OBJECT
|
2020-08-11 18:11:55 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Prefs)
|
2013-01-26 01:19:54 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2013-01-26 01:19:54 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* client prefs */
|
|
|
|
OPTIONS_PROMPT,
|
|
|
|
OPEN_DIALOG_FOLDER,
|
|
|
|
INHIBIT_HIBERNATION,
|
|
|
|
DIR_WATCH,
|
|
|
|
DIR_WATCH_ENABLED,
|
|
|
|
SHOW_TRAY_ICON,
|
|
|
|
START_MINIMIZED,
|
|
|
|
SHOW_NOTIFICATION_ON_ADD,
|
|
|
|
SHOW_NOTIFICATION_ON_COMPLETE,
|
|
|
|
ASKQUIT,
|
|
|
|
SORT_MODE,
|
|
|
|
SORT_REVERSED,
|
|
|
|
COMPACT_VIEW,
|
|
|
|
FILTERBAR,
|
|
|
|
STATUSBAR,
|
|
|
|
STATUSBAR_STATS,
|
|
|
|
SHOW_TRACKER_SCRAPES,
|
|
|
|
SHOW_BACKUP_TRACKERS,
|
|
|
|
TOOLBAR,
|
|
|
|
BLOCKLIST_DATE,
|
|
|
|
BLOCKLIST_UPDATES_ENABLED,
|
|
|
|
MAIN_WINDOW_LAYOUT_ORDER,
|
|
|
|
MAIN_WINDOW_HEIGHT,
|
|
|
|
MAIN_WINDOW_WIDTH,
|
|
|
|
MAIN_WINDOW_X,
|
|
|
|
MAIN_WINDOW_Y,
|
|
|
|
FILTER_MODE,
|
|
|
|
FILTER_TRACKERS,
|
|
|
|
FILTER_TEXT,
|
|
|
|
SESSION_IS_REMOTE,
|
|
|
|
SESSION_REMOTE_HOST,
|
|
|
|
SESSION_REMOTE_PORT,
|
|
|
|
SESSION_REMOTE_AUTH,
|
|
|
|
SESSION_REMOTE_USERNAME,
|
|
|
|
SESSION_REMOTE_PASSWORD,
|
|
|
|
COMPLETE_SOUND_COMMAND,
|
|
|
|
COMPLETE_SOUND_ENABLED,
|
|
|
|
USER_HAS_GIVEN_INFORMED_CONSENT,
|
|
|
|
/* 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,
|
|
|
|
BLOCKLIST_URL,
|
|
|
|
DSPEED,
|
|
|
|
DSPEED_ENABLED,
|
|
|
|
DOWNLOAD_DIR,
|
|
|
|
DOWNLOAD_QUEUE_ENABLED,
|
|
|
|
DOWNLOAD_QUEUE_SIZE,
|
|
|
|
ENCRYPTION,
|
|
|
|
IDLE_LIMIT,
|
|
|
|
IDLE_LIMIT_ENABLED,
|
|
|
|
INCOMPLETE_DIR,
|
|
|
|
INCOMPLETE_DIR_ENABLED,
|
|
|
|
MSGLEVEL,
|
|
|
|
PEER_LIMIT_GLOBAL,
|
|
|
|
PEER_LIMIT_TORRENT,
|
|
|
|
PEER_PORT,
|
|
|
|
PEER_PORT_RANDOM_ON_START,
|
|
|
|
PEER_PORT_RANDOM_LOW,
|
|
|
|
PEER_PORT_RANDOM_HIGH,
|
|
|
|
QUEUE_STALLED_MINUTES,
|
|
|
|
SCRIPT_TORRENT_DONE_ENABLED,
|
|
|
|
SCRIPT_TORRENT_DONE_FILENAME,
|
|
|
|
SOCKET_TOS,
|
|
|
|
START,
|
|
|
|
TRASH_ORIGINAL,
|
|
|
|
PEX_ENABLED,
|
|
|
|
DHT_ENABLED,
|
|
|
|
UTP_ENABLED,
|
|
|
|
LPD_ENABLED,
|
|
|
|
PORT_FORWARDING,
|
|
|
|
PREALLOCATION,
|
|
|
|
RATIO,
|
|
|
|
RATIO_ENABLED,
|
|
|
|
RENAME_PARTIAL_FILES,
|
|
|
|
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
|
2013-01-26 01:19:54 +00:00
|
|
|
};
|
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
explicit Prefs(QString config_dir);
|
2020-09-09 14:24:39 +00:00
|
|
|
~Prefs() override;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool isCore(int key) const
|
|
|
|
{
|
|
|
|
return FIRST_CORE_PREF <= key && key <= LAST_CORE_PREF;
|
|
|
|
}
|
2013-01-26 01:19:54 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool isClient(int key) const
|
|
|
|
{
|
|
|
|
return !isCore(key);
|
|
|
|
}
|
2013-01-26 01:19:54 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_quark getKey(int i) const
|
2013-01-26 01:19:54 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return Items[i].key;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int type(int i) const
|
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
return Items[i].type;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QVariant const& variant(int i) const
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return values_[i];
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T get(int key) const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return values_[key].value<T>();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2017-04-20 16:02:19 +00:00
|
|
|
void set(int key, T const& value)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QVariant& v(values_[key]);
|
2017-04-20 16:02:19 +00:00
|
|
|
QVariant const tmp = QVariant::fromValue(value);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (v.isNull() || v != tmp)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
v = tmp;
|
|
|
|
emit changed(key);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-01-26 01:19:54 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void toggleBool(int key);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
signals:
|
|
|
|
void changed(int key);
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private:
|
2015-06-12 22:12:12 +00:00
|
|
|
struct PrefItem
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int id;
|
|
|
|
tr_quark key;
|
|
|
|
int type;
|
2015-06-12 22:12:12 +00:00
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void initDefaults(tr_variant*);
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2020-07-27 04:30:58 +00:00
|
|
|
void set(int key, char const* value) = delete;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const config_dir_;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
QSet<int> temporary_prefs_;
|
2020-11-02 01:13:32 +00:00
|
|
|
std::array<QVariant, PREFS_COUNT> mutable values_;
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
static std::array<PrefItem, PREFS_COUNT> const Items;
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|