2007-09-27 20:57:58 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2007 Charles Kerr <charles@rebelbase.com>
|
2007-02-19 22:09:05 +00:00
|
|
|
*
|
2007-09-27 20:57:58 +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.
|
|
|
|
*
|
2007-09-28 00:46:22 +00:00
|
|
|
* $Id$
|
2007-09-27 20:57:58 +00:00
|
|
|
*/
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
2007-09-27 20:57:58 +00:00
|
|
|
#include <gtk/gtk.h>
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2007-02-19 22:09:05 +00:00
|
|
|
#include "conf.h"
|
2007-09-27 20:57:58 +00:00
|
|
|
#include "hig.h"
|
2007-05-24 13:55:57 +00:00
|
|
|
#include "tr_core.h"
|
2007-02-19 22:09:05 +00:00
|
|
|
#include "tr_prefs.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2007-09-27 20:57:58 +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.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
tr_prefs_init_global( void )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_DL_LIMIT_ENABLED, FALSE );
|
|
|
|
pref_int_set_default ( PREF_KEY_DL_LIMIT, 100 );
|
|
|
|
pref_flag_set_default ( PREF_KEY_UL_LIMIT_ENABLED, FALSE );
|
|
|
|
pref_int_set_default ( PREF_KEY_UL_LIMIT, 50 );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_DIR_ASK, FALSE );
|
|
|
|
pref_string_set_default ( PREF_KEY_DIR_DEFAULT, g_get_home_dir() );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_int_set_default ( PREF_KEY_PORT, TR_DEFAULT_PORT );
|
2007-05-24 13:55:57 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_NAT, TRUE );
|
|
|
|
pref_flag_set_default ( PREF_KEY_PEX, TRUE );
|
|
|
|
pref_flag_set_default ( PREF_KEY_SYSTRAY, TRUE );
|
|
|
|
pref_flag_set_default ( PREF_KEY_ASKQUIT, TRUE );
|
2007-09-28 00:46:22 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_ENCRYPTED_ONLY, FALSE );
|
2007-05-24 13:55:57 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_string_set_default ( PREF_KEY_ADDSTD, toractionname(TR_TOR_COPY) );
|
|
|
|
pref_string_set_default ( PREF_KEY_ADDIPC, toractionname(TR_TOR_COPY) );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_int_set_default ( PREF_KEY_MSGLEVEL, TR_MSG_INF );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-10-17 18:31:12 +00:00
|
|
|
pref_string_set_default ( PREF_KEY_SORT_COLUMN, "name" );
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_save( NULL );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
int
|
2007-09-27 20:57:58 +00:00
|
|
|
tr_prefs_get_action( const char * key )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
char * val = pref_string_get( key );
|
|
|
|
const int ret = toraddaction( val );
|
|
|
|
g_free( val );
|
2007-02-19 22:09:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
void
|
|
|
|
tr_prefs_set_action( const char * key, int action )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
pref_string_set( key, toractionname(action) );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
/**
|
|
|
|
***
|
|
|
|
**/
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
#define PREFS_KEY "prefs-key"
|
2007-02-19 22:09:05 +00:00
|
|
|
|
|
|
|
static void
|
2007-09-27 20:57:58 +00:00
|
|
|
response_cb( GtkDialog * dialog, int response UNUSED, gpointer unused UNUSED )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
gtk_widget_destroy( GTK_WIDGET(dialog) );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-27 20:57:58 +00:00
|
|
|
toggled_cb( GtkToggleButton * w, gpointer core )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
const char * key = g_object_get_data( G_OBJECT(w), PREFS_KEY );
|
|
|
|
const gboolean flag = gtk_toggle_button_get_active( w );
|
|
|
|
tr_core_set_pref_bool( TR_CORE(core), key, flag );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
static GtkWidget*
|
|
|
|
new_check_button( const char * mnemonic, const char * key, gpointer core )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
GtkWidget * w = gtk_check_button_new_with_mnemonic( mnemonic );
|
|
|
|
g_object_set_data_full( G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free );
|
|
|
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), pref_flag_get(key) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(toggled_cb), core );
|
|
|
|
return w;
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-27 20:57:58 +00:00
|
|
|
spun_cb( GtkSpinButton * w, gpointer core )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
const char * key = g_object_get_data( G_OBJECT(w), PREFS_KEY );
|
|
|
|
const int value = gtk_spin_button_get_value_as_int( w );
|
|
|
|
tr_core_set_pref_int( TR_CORE(core), key, value );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
static GtkWidget*
|
|
|
|
new_spin_button( const char * key, gpointer core, int low, int high )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
GtkWidget * w = gtk_spin_button_new_with_range( low, high, 1 );
|
|
|
|
g_object_set_data_full( G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free );
|
|
|
|
gtk_spin_button_set_digits( GTK_SPIN_BUTTON(w), 0 );
|
|
|
|
gtk_spin_button_set_value( GTK_SPIN_BUTTON(w), pref_int_get(key) );
|
|
|
|
g_signal_connect( w, "value-changed", G_CALLBACK(spun_cb), core );
|
|
|
|
return w;
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-27 20:57:58 +00:00
|
|
|
chosen_cb( GtkFileChooser * w, gpointer core )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
const char * key = g_object_get_data( G_OBJECT(w), PREFS_KEY );
|
|
|
|
char * value = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(w) );
|
|
|
|
tr_core_set_pref( TR_CORE(core), key, value );
|
|
|
|
g_free( value );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
static GtkWidget*
|
|
|
|
new_path_chooser_button( const char * key, gpointer core )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-28 00:46:22 +00:00
|
|
|
GtkWidget * w = gtk_file_chooser_button_new( NULL,
|
|
|
|
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
|
2007-09-27 20:57:58 +00:00
|
|
|
char * path = pref_string_get( key );
|
|
|
|
g_object_set_data_full( G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free );
|
|
|
|
g_signal_connect( w, "selection-changed", G_CALLBACK(chosen_cb), core );
|
|
|
|
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(w), path );
|
|
|
|
return w;
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-09-27 20:57:58 +00:00
|
|
|
action_cb( GtkComboBox * w, gpointer core )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
const char * key = g_object_get_data( G_OBJECT(w), PREFS_KEY );
|
|
|
|
GtkTreeIter iter;
|
|
|
|
if( gtk_combo_box_get_active_iter( GTK_COMBO_BOX(w), &iter ) )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-27 20:57:58 +00:00
|
|
|
int action;
|
|
|
|
GtkTreeModel * model = gtk_combo_box_get_model( GTK_COMBO_BOX(w) );
|
|
|
|
gtk_tree_model_get( model, &iter, 1, &action, -1 );
|
|
|
|
tr_core_set_pref( core, key, toractionname(action) );
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
static GtkWidget*
|
|
|
|
new_action_combo( const char * key, gpointer core )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-09-28 00:46:22 +00:00
|
|
|
const char * s;
|
2007-09-27 20:57:58 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkCellRenderer * rend;
|
|
|
|
GtkListStore * model;
|
|
|
|
GtkWidget * w;
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
|
2007-09-28 00:46:22 +00:00
|
|
|
|
|
|
|
s = _("Use the torrent file where it is");
|
2007-09-27 20:57:58 +00:00
|
|
|
gtk_list_store_append( model, &iter );
|
2007-09-28 00:46:22 +00:00
|
|
|
gtk_list_store_set( model, &iter, 1, TR_TOR_LEAVE, 0, s, -1 );
|
|
|
|
|
|
|
|
s = _("Keep a copy of the torrent file");
|
2007-09-27 20:57:58 +00:00
|
|
|
gtk_list_store_append( model, &iter );
|
2007-09-28 00:46:22 +00:00
|
|
|
gtk_list_store_set( model, &iter, 1, TR_TOR_COPY, 0, s, -1 );
|
|
|
|
|
|
|
|
s = _("Keep a copy and remove the original");
|
2007-09-27 20:57:58 +00:00
|
|
|
gtk_list_store_append( model, &iter );
|
2007-09-28 00:46:22 +00:00
|
|
|
gtk_list_store_set( model, &iter, 1, TR_TOR_MOVE, 0, s, -1 );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-09-27 20:57:58 +00:00
|
|
|
w = gtk_combo_box_new_with_model( GTK_TREE_MODEL(model) );
|
2007-09-28 00:46:22 +00:00
|
|
|
gtk_combo_box_set_active( GTK_COMBO_BOX(w), tr_prefs_get_action(key) );
|
2007-09-27 20:57:58 +00:00
|
|
|
g_object_set_data_full( G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free );
|
|
|
|
rend = gtk_cell_renderer_text_new( );
|
|
|
|
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(w), rend, TRUE );
|
|
|
|
gtk_cell_layout_add_attribute( GTK_CELL_LAYOUT(w), rend, "text", 0 );
|
|
|
|
g_signal_connect( w, "changed", G_CALLBACK(action_cb), core );
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
tr_prefs_dialog_new( GObject * core, GtkWindow * parent )
|
|
|
|
{
|
|
|
|
int row = 0;
|
2007-09-28 00:46:22 +00:00
|
|
|
const char * s;
|
2007-09-27 20:57:58 +00:00
|
|
|
GtkWidget * t;
|
|
|
|
GtkWidget * w;
|
|
|
|
GtkWidget * l;
|
2007-09-28 00:46:22 +00:00
|
|
|
GtkWidget * d;
|
|
|
|
|
2007-10-10 17:25:56 +00:00
|
|
|
d = gtk_dialog_new_with_buttons( _("Preferences"), parent,
|
2007-09-28 00:46:22 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL );
|
|
|
|
|
|
|
|
gtk_window_set_role( GTK_WINDOW(d), "transmission-preferences-dialog" );
|
|
|
|
g_signal_connect( d, "response", G_CALLBACK(response_cb), core );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
|
|
|
t = hig_workarea_create ();
|
|
|
|
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Speed Limits"));
|
|
|
|
hig_workarea_add_section_spacer (t, row, 4);
|
|
|
|
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("_Limit Upload Speed");
|
|
|
|
w = new_check_button( s, PREF_KEY_UL_LIMIT_ENABLED, core );
|
2007-09-27 20:57:58 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
w = new_spin_button( PREF_KEY_UL_LIMIT, core, 20, INT_MAX );
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("Maximum _Upload Speed (KiB/s)");
|
|
|
|
l = hig_workarea_add_row( t, &row, s, w, NULL );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("Li_mit Download Speed");
|
|
|
|
w = new_check_button( s, PREF_KEY_DL_LIMIT_ENABLED, core );
|
2007-09-27 20:57:58 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
w = new_spin_button( PREF_KEY_DL_LIMIT, core, 1, INT_MAX );
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("Maximum _Download Speed (KiB/s)");
|
|
|
|
l = hig_workarea_add_row( t, &row, s, w, NULL );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Downloads"));
|
|
|
|
hig_workarea_add_section_spacer (t, row, 4);
|
|
|
|
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("Al_ways prompt for download directory");
|
|
|
|
w = new_check_button( s, PREF_KEY_DIR_ASK, core );
|
2007-09-27 20:57:58 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
w = new_path_chooser_button( PREF_KEY_DIR_DEFAULT, core );
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("Download Di_rectory");
|
|
|
|
l = hig_workarea_add_row( t, &row, s, w, NULL );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
|
|
|
w = new_action_combo( PREF_KEY_ADDSTD, core );
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("For torrents added _normally:");
|
|
|
|
l = hig_workarea_add_row( t, &row, s, w, NULL );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
|
|
|
w = new_action_combo( PREF_KEY_ADDIPC, core );
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("For torrents added from _command-line:");
|
|
|
|
l = hig_workarea_add_row( t, &row, s, w, NULL );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Network"));
|
|
|
|
hig_workarea_add_section_spacer (t, row, 2);
|
|
|
|
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("_Automatic Port Mapping via NAT-PMP or UPnP");
|
|
|
|
w = new_check_button( s, PREF_KEY_NAT, core );
|
2007-09-27 20:57:58 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
w = new_spin_button( PREF_KEY_PORT, core, 1, INT_MAX );
|
|
|
|
l = hig_workarea_add_row( t, &row, _("Listening _Port"), w, NULL );
|
|
|
|
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
|
|
|
hig_workarea_add_section_title (t, &row, _("Options"));
|
|
|
|
hig_workarea_add_section_spacer (t, row, 3);
|
|
|
|
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("Use Peer _Exchange if Possible");
|
|
|
|
w = new_check_button( s, PREF_KEY_PEX, core );
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
s = _("_Ignore Unencrypted Peers");
|
|
|
|
w = new_check_button( s, PREF_KEY_ENCRYPTED_ONLY, core );
|
2007-09-27 20:57:58 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
2007-10-13 17:33:53 +00:00
|
|
|
s = _("Show an Icon in the System _Tray");
|
2007-09-28 00:46:22 +00:00
|
|
|
w = new_check_button( s, PREF_KEY_SYSTRAY, core );
|
2007-09-27 20:57:58 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
2007-09-28 00:46:22 +00:00
|
|
|
s = _("Confirm _quit");
|
|
|
|
w = new_check_button( s, PREF_KEY_ASKQUIT, core );
|
2007-09-27 20:57:58 +00:00
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
hig_workarea_finish (t, &row);
|
2007-09-28 00:46:22 +00:00
|
|
|
gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(d)->vbox), t );
|
|
|
|
gtk_widget_show_all( GTK_DIALOG(d)->vbox );
|
|
|
|
return d;
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|