2006-08-13 00:26:52 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2011-01-19 13:48:47 +00:00
|
|
|
* Copyright (c) Transmission authors and contributors
|
2006-08-13 00:26:52 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2012-12-05 17:29:46 +00:00
|
|
|
#include <stdlib.h> /* strtol () */
|
2006-07-16 19:39:23 +00:00
|
|
|
#include <string.h>
|
2007-10-13 03:15:02 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gi18n.h>
|
2007-09-28 00:46:22 +00:00
|
|
|
#include <glib/gstdio.h>
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2012-12-14 04:34:42 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "conf.h"
|
2009-03-10 15:24:40 +00:00
|
|
|
#include "tr-prefs.h"
|
2006-07-16 19:39:23 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2010-08-05 13:24:46 +00:00
|
|
|
#define MY_CONFIG_NAME "transmission"
|
|
|
|
#define MY_READABLE_NAME "transmission-gtk"
|
2008-12-13 23:17:36 +00:00
|
|
|
|
2007-10-13 03:15:02 +00:00
|
|
|
static char * gl_confdir = NULL;
|
2007-10-12 20:50:03 +00:00
|
|
|
|
2011-08-09 02:30:31 +00:00
|
|
|
void
|
2012-12-05 17:29:46 +00:00
|
|
|
gtr_pref_init (const char * config_dir)
|
2007-10-13 03:15:02 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
gl_confdir = g_strdup (config_dir);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 20:50:03 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
**** Preferences
|
|
|
|
****
|
|
|
|
***/
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2009-03-10 15:24:40 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static void
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_prefs_init_defaults (tr_variant * d)
|
2009-03-10 15:24:40 +00:00
|
|
|
{
|
2013-06-12 00:22:41 +00:00
|
|
|
const char * dir;
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2013-06-12 00:22:41 +00:00
|
|
|
dir = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
|
|
|
|
if (dir == NULL)
|
|
|
|
dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
|
|
|
if (dir == NULL)
|
|
|
|
dir = tr_getDefaultDownloadDir ();
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantDictReserve (d, 29);
|
2013-06-12 00:22:41 +00:00
|
|
|
tr_variantDictAddStr (d, TR_KEY_watch_dir, dir);
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_variantDictAddBool (d, TR_KEY_watch_dir_enabled, FALSE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_user_has_given_informed_consent, FALSE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_inhibit_desktop_hibernation, FALSE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_blocklist_updates_enabled, TRUE);
|
|
|
|
tr_variantDictAddStr (d, TR_KEY_open_dialog_dir, g_get_home_dir ());
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_toolbar, TRUE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_filterbar, TRUE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_statusbar, TRUE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_trash_can_enabled, TRUE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_notification_area_icon, FALSE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_tracker_scrapes, FALSE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_extra_peer_details, FALSE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_backup_trackers, FALSE);
|
|
|
|
tr_variantDictAddStr (d, TR_KEY_statusbar_stats, "total-ratio");
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_torrent_added_notification_enabled, true);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_torrent_complete_notification_enabled, true);
|
|
|
|
tr_variantDictAddStr (d, TR_KEY_torrent_complete_sound_command, "canberra-gtk-play -i complete-download -d 'transmission torrent downloaded'");
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_torrent_complete_sound_enabled, true);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_show_options_window, TRUE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_main_window_is_maximized, FALSE);
|
|
|
|
tr_variantDictAddInt (d, TR_KEY_main_window_height, 500);
|
|
|
|
tr_variantDictAddInt (d, TR_KEY_main_window_width, 300);
|
|
|
|
tr_variantDictAddInt (d, TR_KEY_main_window_x, 50);
|
|
|
|
tr_variantDictAddInt (d, TR_KEY_main_window_y, 50);
|
2013-06-12 00:22:41 +00:00
|
|
|
tr_variantDictAddStr (d, TR_KEY_download_dir, dir);
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_variantDictAddStr (d, TR_KEY_sort_mode, "sort-by-name");
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_sort_reversed, FALSE);
|
|
|
|
tr_variantDictAddBool (d, TR_KEY_compact_view, FALSE);
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
static tr_variant*
|
2012-12-05 17:29:46 +00:00
|
|
|
getPrefs (void)
|
2007-09-27 20:57:58 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
static tr_variant settings;
|
2012-12-05 17:29:46 +00:00
|
|
|
static gboolean loaded = FALSE;
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
if (!loaded)
|
2007-09-27 20:57:58 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantInitDict (&settings, 0);
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_prefs_init_defaults (&settings);
|
|
|
|
tr_sessionLoadSettings (&settings, gl_confdir, MY_CONFIG_NAME);
|
|
|
|
loaded = TRUE;
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
return &settings;
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2008-06-12 16:25:36 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variant*
|
2012-12-05 17:29:46 +00:00
|
|
|
gtr_pref_get_all (void)
|
2008-12-13 23:17:36 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
return getPrefs ();
|
2008-12-13 23:17:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-02 20:59:00 +00:00
|
|
|
int64_t
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_int_get (const tr_quark key)
|
2008-06-12 16:25:36 +00:00
|
|
|
{
|
2015-05-09 11:56:35 +00:00
|
|
|
int64_t i;
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2015-05-09 11:56:35 +00:00
|
|
|
return tr_variantDictFindInt (getPrefs (), key, &i) ? i : 0;
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
void
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_int_set (const tr_quark key, int64_t value)
|
2008-06-12 16:25:36 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantDictAddInt (getPrefs (), key, value);
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-02-13 18:23:56 +00:00
|
|
|
double
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_double_get (const tr_quark key)
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2015-05-09 11:56:35 +00:00
|
|
|
double d;
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2015-05-09 11:56:35 +00:00
|
|
|
return tr_variantDictFindReal (getPrefs (), key, &d) ? d : 0.0;
|
2009-02-13 18:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_double_set (const tr_quark key, double value)
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantDictAddReal (getPrefs (), key, value);
|
2009-02-13 18:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-12 16:25:36 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
gboolean
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_flag_get (const tr_quark key)
|
2008-06-12 16:25:36 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
bool boolVal;
|
|
|
|
|
2015-05-09 11:56:35 +00:00
|
|
|
return tr_variantDictFindBool (getPrefs (), key, &boolVal) ? boolVal : false;
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
void
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_flag_set (const tr_quark key, gboolean value)
|
2008-06-12 16:25:36 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantDictAddBool (getPrefs (), key, value);
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2008-06-12 16:25:36 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
const char*
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_string_get (const tr_quark key)
|
2008-06-12 16:25:36 +00:00
|
|
|
{
|
2015-05-09 11:56:35 +00:00
|
|
|
const char * str;
|
2012-12-05 17:29:46 +00:00
|
|
|
|
2015-05-09 11:56:35 +00:00
|
|
|
return tr_variantDictFindStr (getPrefs (), key, &str, NULL) ? str : NULL;
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2008-06-12 16:25:36 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
void
|
2012-12-22 20:35:19 +00:00
|
|
|
gtr_pref_string_set (const tr_quark key, const char * value)
|
2008-06-12 16:25:36 +00:00
|
|
|
{
|
2012-12-14 04:34:42 +00:00
|
|
|
tr_variantDictAddStr (getPrefs (), key, value);
|
2007-09-27 20:57:58 +00:00
|
|
|
}
|
2008-06-12 16:25:36 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
void
|
2012-12-05 17:29:46 +00:00
|
|
|
gtr_pref_save (tr_session * session)
|
2007-09-27 20:57:58 +00:00
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
tr_sessionSaveSettings (session, gl_confdir, getPrefs ());
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2007-12-01 01:41:10 +00:00
|
|
|
|