2007-09-27 20:57:58 +00:00
|
|
|
/*
|
2008-01-01 17:20:20 +00:00
|
|
|
* This file Copyright (C) 2007-2008 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
|
|
|
|
2008-03-18 01:22:11 +00:00
|
|
|
#include <stdlib.h> /* free() */
|
2008-03-30 00:21:46 +00:00
|
|
|
#include <unistd.h>
|
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-12-15 22:24:16 +00:00
|
|
|
#include <third-party/miniupnp/miniwget.h>
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2008-03-30 03:20:18 +00:00
|
|
|
#include <libtransmission/utils.h>
|
2007-02-19 22:09:05 +00:00
|
|
|
#include "conf.h"
|
2007-09-27 20:57:58 +00:00
|
|
|
#include "hig.h"
|
2008-02-26 19:58:03 +00:00
|
|
|
#include "tr-core.h"
|
|
|
|
#include "tr-prefs.h"
|
2007-02-19 22:09:05 +00:00
|
|
|
#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
|
|
|
{
|
2008-03-07 16:30:44 +00:00
|
|
|
const char * str;
|
|
|
|
|
2007-12-01 01:41:10 +00:00
|
|
|
cf_check_older_configs( );
|
|
|
|
|
2008-03-09 15:27:08 +00:00
|
|
|
#if HAVE_GIO
|
|
|
|
str = NULL;
|
|
|
|
if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP );
|
|
|
|
if( !str ) str = g_get_home_dir( );
|
|
|
|
pref_string_set_default ( PREF_KEY_DIR_WATCH, str );
|
|
|
|
pref_flag_set_default ( PREF_KEY_DIR_WATCH_ENABLED, FALSE );
|
|
|
|
#endif
|
|
|
|
|
2008-03-30 00:21:46 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_BLOCKLIST_ENABLED, FALSE );
|
|
|
|
|
2008-03-18 20:41:27 +00:00
|
|
|
pref_string_set_default ( PREF_KEY_OPEN_DIALOG_FOLDER, g_get_home_dir( ) );
|
|
|
|
|
2008-01-20 00:40:41 +00:00
|
|
|
pref_int_set_default ( PREF_KEY_MAX_PEERS_GLOBAL, 200 );
|
|
|
|
pref_int_set_default ( PREF_KEY_MAX_PEERS_PER_TORRENT, 50 );
|
2007-12-22 00:06:38 +00:00
|
|
|
|
2007-12-20 02:56:47 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_TOOLBAR, TRUE );
|
2008-03-19 19:30:03 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_FILTERBAR, TRUE );
|
|
|
|
pref_flag_set_default ( PREF_KEY_STATUSBAR, TRUE );
|
|
|
|
pref_string_set_default ( PREF_KEY_STATUSBAR_STATS, "total-ratio" );
|
2007-12-20 02:56:47 +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 );
|
2008-02-13 03:00:21 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_OPTIONS_PROMPT, TRUE );
|
2008-03-07 16:30:44 +00:00
|
|
|
|
|
|
|
str = NULL;
|
2008-02-19 19:22:15 +00:00
|
|
|
#if GLIB_CHECK_VERSION(2,14,0)
|
2008-03-09 15:27:08 +00:00
|
|
|
if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DOWNLOAD );
|
2008-02-19 19:22:15 +00:00
|
|
|
#endif
|
2008-03-09 15:27:08 +00:00
|
|
|
if( !str ) str = g_get_home_dir( );
|
2008-03-07 16:30:44 +00:00
|
|
|
pref_string_set_default ( PREF_KEY_DIR_DEFAULT, str );
|
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
|
|
|
|
2008-02-24 16:10:18 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_NOTIFY, TRUE );
|
|
|
|
|
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_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_int_set_default ( PREF_KEY_MSGLEVEL, TR_MSG_INF );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2007-12-19 02:46:30 +00:00
|
|
|
pref_string_set_default ( PREF_KEY_SORT_MODE, "sort-by-name" );
|
|
|
|
pref_flag_set_default ( PREF_KEY_SORT_REVERSED, FALSE );
|
|
|
|
pref_flag_set_default ( PREF_KEY_MINIMAL_VIEW, FALSE );
|
2007-10-17 18:31:12 +00:00
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_START, TRUE );
|
2008-03-09 15:27:08 +00:00
|
|
|
pref_flag_set_default ( PREF_KEY_TRASH_ORIGINAL, FALSE );
|
2007-02-19 22:09:05 +00:00
|
|
|
|
2008-02-13 03:00:21 +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
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
#define PREF_KEY "pref-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
|
|
|
{
|
2008-02-14 17:18:00 +00:00
|
|
|
const char * key = g_object_get_data( G_OBJECT(w), PREF_KEY );
|
2007-09-27 20:57:58 +00:00
|
|
|
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 );
|
2008-02-14 17:18:00 +00:00
|
|
|
g_object_set_data_full( G_OBJECT(w), PREF_KEY, g_strdup(key), g_free );
|
2007-09-27 20:57:58 +00:00
|
|
|
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
|
|
|
{
|
2008-02-14 17:18:00 +00:00
|
|
|
const char * key = g_object_get_data( G_OBJECT(w), PREF_KEY );
|
2007-09-27 20:57:58 +00:00
|
|
|
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*
|
2007-12-26 10:39:10 +00:00
|
|
|
new_spin_button( const char * key, gpointer core, int low, int high, int step )
|
2007-02-19 22:09:05 +00:00
|
|
|
{
|
2007-12-26 10:39:10 +00:00
|
|
|
GtkWidget * w = gtk_spin_button_new_with_range( low, high, step );
|
2008-02-14 17:18:00 +00:00
|
|
|
g_object_set_data_full( G_OBJECT(w), PREF_KEY, g_strdup(key), g_free );
|
2007-09-27 20:57:58 +00:00
|
|
|
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
|
|
|
{
|
2008-02-14 17:18:00 +00:00
|
|
|
const char * key = g_object_get_data( G_OBJECT(w), PREF_KEY );
|
2007-09-27 20:57:58 +00:00
|
|
|
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 );
|
2008-02-14 17:18:00 +00:00
|
|
|
g_object_set_data_full( G_OBJECT(w), PREF_KEY, g_strdup(key), g_free );
|
2007-09-27 20:57:58 +00:00
|
|
|
g_signal_connect( w, "selection-changed", G_CALLBACK(chosen_cb), core );
|
|
|
|
gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(w), path );
|
2008-03-18 01:06:06 +00:00
|
|
|
g_free( path );
|
2007-09-27 20:57:58 +00:00
|
|
|
return w;
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|
|
|
|
|
2007-12-13 20:46:19 +00:00
|
|
|
static void
|
2008-02-14 17:18:00 +00:00
|
|
|
target_cb( GtkWidget * tb, gpointer target )
|
2007-12-13 20:46:19 +00:00
|
|
|
{
|
2008-02-14 17:18:00 +00:00
|
|
|
const gboolean b = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( tb ) );
|
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET(target), b );
|
2007-12-13 20:46:19 +00:00
|
|
|
}
|
|
|
|
|
2008-02-07 16:17:52 +00:00
|
|
|
struct test_port_data
|
|
|
|
{
|
|
|
|
GtkWidget * label;
|
|
|
|
gboolean * alive;
|
|
|
|
};
|
|
|
|
|
2007-12-15 22:24:16 +00:00
|
|
|
static gpointer
|
2008-02-07 16:17:52 +00:00
|
|
|
test_port( gpointer data_gpointer )
|
2007-12-15 22:24:16 +00:00
|
|
|
{
|
2008-02-07 16:17:52 +00:00
|
|
|
struct test_port_data * data = data_gpointer;
|
|
|
|
|
|
|
|
if( *data->alive )
|
|
|
|
{
|
|
|
|
GObject * o = G_OBJECT( data->label );
|
2008-02-14 17:18:00 +00:00
|
|
|
GtkSpinButton * spin = g_object_get_data( o, "tr-port-spin" );
|
2008-02-07 16:17:52 +00:00
|
|
|
const int port = gtk_spin_button_get_value_as_int( spin );
|
|
|
|
int isOpen;
|
|
|
|
int size;
|
|
|
|
char * text;
|
|
|
|
char url[256];
|
|
|
|
|
|
|
|
g_usleep( G_USEC_PER_SEC * 3 ); /* give portmapping time to kick in */
|
|
|
|
snprintf( url, sizeof(url), "http://portcheck.transmissionbt.com/%d", port );
|
|
|
|
text = miniwget( url, &size );
|
|
|
|
/*g_message(" got len %d, [%*.*s]", size, size, size, text );*/
|
|
|
|
isOpen = text && *text=='1';
|
2008-03-18 01:06:06 +00:00
|
|
|
free( text );
|
2008-02-07 16:17:52 +00:00
|
|
|
|
|
|
|
if( *data->alive )
|
|
|
|
gtk_label_set_markup( GTK_LABEL(data->label), isOpen
|
|
|
|
? _("Port is <b>open</b>")
|
|
|
|
: _("Port is <b>closed</b>") );
|
|
|
|
}
|
2007-12-15 22:24:16 +00:00
|
|
|
|
2008-02-07 16:17:52 +00:00
|
|
|
g_free( data );
|
2007-12-15 22:24:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
testing_port_cb( GtkWidget * unused UNUSED, gpointer l )
|
|
|
|
{
|
2008-02-07 16:17:52 +00:00
|
|
|
struct test_port_data * data = g_new0( struct test_port_data, 1 );
|
|
|
|
data->alive = g_object_get_data( G_OBJECT( l ), "alive" );
|
|
|
|
data->label = l;
|
2007-12-15 22:24:16 +00:00
|
|
|
gtk_label_set_markup( GTK_LABEL(l), _( "<i>Testing port...</i>" ) );
|
2008-02-07 16:17:52 +00:00
|
|
|
g_thread_create( test_port, data, FALSE, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dialogDestroyed( gpointer alive, GObject * dialog UNUSED )
|
|
|
|
{
|
|
|
|
*(gboolean*)alive = FALSE;
|
2007-12-15 22:24:16 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
static GtkWidget*
|
|
|
|
torrentPage( GObject * core )
|
|
|
|
{
|
|
|
|
int row = 0;
|
|
|
|
const char * s;
|
|
|
|
GtkWidget * t;
|
|
|
|
GtkWidget * w;
|
2008-03-18 19:14:21 +00:00
|
|
|
#ifdef HAVE_GIO
|
2008-03-09 15:27:08 +00:00
|
|
|
GtkWidget * l;
|
2008-03-18 19:14:21 +00:00
|
|
|
#endif
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
t = hig_workarea_create( );
|
2008-03-18 19:14:21 +00:00
|
|
|
hig_workarea_add_section_title( t, &row, _( "Opening Torrents" ) );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-03-09 15:27:08 +00:00
|
|
|
#ifdef HAVE_GIO
|
|
|
|
s = _( "Automatically add torrents from:" );
|
|
|
|
l = new_check_button( s, PREF_KEY_DIR_WATCH_ENABLED, core );
|
|
|
|
w = new_path_chooser_button( PREF_KEY_DIR_WATCH, core );
|
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET(w), pref_flag_get( PREF_KEY_DIR_WATCH_ENABLED ) );
|
|
|
|
g_signal_connect( l, "toggled", G_CALLBACK(target_cb), w );
|
|
|
|
hig_workarea_add_row_w( t, &row, l, w, NULL );
|
|
|
|
#endif
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-03-18 19:14:21 +00:00
|
|
|
s = _( "Display _options dialog" );
|
2008-02-13 03:00:21 +00:00
|
|
|
w = new_check_button( s, PREF_KEY_OPTIONS_PROMPT, core );
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
2008-03-18 19:14:21 +00:00
|
|
|
s = _( "_Start when opened" );
|
2008-02-13 03:00:21 +00:00
|
|
|
w = new_check_button( s, PREF_KEY_START, core );
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
2008-03-18 19:14:21 +00:00
|
|
|
s = _( "Mo_ve source files to Trash" );
|
2008-03-09 15:27:08 +00:00
|
|
|
w = new_check_button( s, PREF_KEY_TRASH_ORIGINAL, core );
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
w = new_path_chooser_button( PREF_KEY_DIR_DEFAULT, core );
|
2008-03-19 17:14:47 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "_Destination folder:" ), w, NULL );
|
2008-03-09 15:27:08 +00:00
|
|
|
|
2008-02-24 16:10:18 +00:00
|
|
|
#ifdef HAVE_LIBNOTIFY
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
|
|
|
hig_workarea_add_section_title( t, &row, _( "Notification" ) );
|
|
|
|
|
2008-03-09 15:27:08 +00:00
|
|
|
s = _( "_Display a message when torrents finish" );
|
2008-02-24 16:10:18 +00:00
|
|
|
w = new_check_button( s, PREF_KEY_NOTIFY, core );
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
#endif
|
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
hig_workarea_finish( t, &row );
|
2008-02-13 03:00:21 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2008-03-30 00:21:46 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
struct blocklist_data
|
|
|
|
{
|
|
|
|
GtkWidget * dialog;
|
|
|
|
TrCore * core;
|
|
|
|
int abortFlag;
|
|
|
|
char secondary[512];
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
blocklistDialogSetSecondary( gpointer vdata )
|
|
|
|
{
|
|
|
|
struct blocklist_data * data = vdata;
|
|
|
|
GtkMessageDialog * md = GTK_MESSAGE_DIALOG( data->dialog );
|
|
|
|
gtk_message_dialog_format_secondary_text( md, data->secondary );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
blocklistDialogAllowClose( gpointer dialog )
|
|
|
|
{
|
|
|
|
GtkDialog * d = GTK_DIALOG( dialog );
|
|
|
|
gtk_dialog_set_response_sensitive( GTK_DIALOG( d ), GTK_RESPONSE_CANCEL, FALSE );
|
|
|
|
gtk_dialog_set_response_sensitive( GTK_DIALOG( d ), GTK_RESPONSE_CLOSE, TRUE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
updateBlocklist( gpointer vdata )
|
|
|
|
{
|
|
|
|
struct blocklist_data * data = vdata;
|
|
|
|
int size = 0;
|
|
|
|
int rules = 0;
|
|
|
|
const char * url;
|
|
|
|
char * text = NULL;
|
|
|
|
gchar * filename = NULL;
|
2008-03-30 03:20:18 +00:00
|
|
|
gchar * filename2 = NULL;
|
2008-03-30 00:21:46 +00:00
|
|
|
int fd = -1;
|
|
|
|
int ok = 1;
|
|
|
|
|
|
|
|
url = "http://download.m0k.org/transmission/files/level1.gz";
|
|
|
|
|
|
|
|
if( ok && !data->abortFlag )
|
|
|
|
{
|
|
|
|
g_snprintf( data->secondary, sizeof( data->secondary ),
|
|
|
|
_( "Retrieving blocklist..." ) );
|
|
|
|
g_idle_add( blocklistDialogSetSecondary, data );
|
|
|
|
text = miniwget( url, &size );
|
|
|
|
if( !data->abortFlag && ( !text || !size ) ) {
|
|
|
|
ok = FALSE;
|
|
|
|
g_snprintf( data->secondary, sizeof( data->secondary ),
|
|
|
|
_( "Unable to get blocklist." ) );
|
2008-03-30 03:03:42 +00:00
|
|
|
g_message( data->secondary );
|
2008-03-30 00:21:46 +00:00
|
|
|
g_idle_add( blocklistDialogSetSecondary, data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ok && !data->abortFlag )
|
|
|
|
{
|
2008-03-30 03:03:42 +00:00
|
|
|
GError * err = NULL;
|
2008-03-30 03:20:18 +00:00
|
|
|
fd = g_file_open_tmp( "transmission-blockfile-XXXXXX", &filename, &err );
|
2008-03-30 00:21:46 +00:00
|
|
|
if( err ) {
|
|
|
|
g_snprintf( data->secondary, sizeof( data->secondary ),
|
|
|
|
_( "Unable to get blocklist: %s" ), err->message );
|
2008-03-30 03:03:42 +00:00
|
|
|
g_warning( data->secondary );
|
2008-03-30 00:21:46 +00:00
|
|
|
g_idle_add( blocklistDialogSetSecondary, data );
|
|
|
|
g_clear_error( &err );
|
2008-03-30 03:03:42 +00:00
|
|
|
ok = FALSE;
|
2008-03-30 00:21:46 +00:00
|
|
|
} else {
|
|
|
|
write( fd, text, size );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( ok && !data->abortFlag )
|
|
|
|
{
|
2008-03-30 03:20:18 +00:00
|
|
|
filename2 = g_strdup_printf( "%s.txt", filename );
|
2008-03-30 00:21:46 +00:00
|
|
|
g_snprintf( data->secondary, sizeof( data->secondary ),
|
|
|
|
_( "Uncompressing blocklist..." ) );
|
|
|
|
g_idle_add( blocklistDialogSetSecondary, data );
|
2008-03-30 03:20:18 +00:00
|
|
|
char * cmd = g_strdup_printf( "zcat %s > %s ", filename, filename2 );
|
|
|
|
tr_dbg( "%s", cmd );
|
2008-03-30 00:21:46 +00:00
|
|
|
system( cmd );
|
|
|
|
g_free( cmd );
|
|
|
|
}
|
|
|
|
if( ok && !data->abortFlag )
|
|
|
|
{
|
|
|
|
g_snprintf( data->secondary, sizeof( data->secondary ),
|
|
|
|
_( "Parsing blocklist..." ) );
|
|
|
|
g_idle_add( blocklistDialogSetSecondary, data );
|
2008-03-30 03:20:18 +00:00
|
|
|
rules = tr_blocklistSetContent( tr_core_handle( data->core ), filename2 );
|
2008-03-30 00:21:46 +00:00
|
|
|
}
|
|
|
|
if( ok && !data->abortFlag )
|
|
|
|
{
|
|
|
|
g_snprintf( data->secondary, sizeof( data->secondary ),
|
|
|
|
_( "Blocklist now has %'d rules" ), rules );
|
|
|
|
g_idle_add( blocklistDialogSetSecondary, data );
|
|
|
|
g_idle_add( blocklistDialogAllowClose, data->dialog );
|
|
|
|
}
|
|
|
|
|
|
|
|
free( text );
|
|
|
|
/* g_free( data ); */
|
2008-03-30 03:20:18 +00:00
|
|
|
if( filename2 ) {
|
|
|
|
unlink( filename2 );
|
|
|
|
g_free( filename2 );
|
|
|
|
}
|
|
|
|
if( filename ) {
|
|
|
|
unlink( filename );
|
|
|
|
g_free( filename );
|
|
|
|
}
|
2008-03-30 00:21:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
onUpdateBlocklistResponseCB( GtkDialog * dialog, int response, gpointer vdata )
|
|
|
|
{
|
|
|
|
struct blocklist_data * data = vdata;
|
|
|
|
|
|
|
|
if( response == GTK_RESPONSE_CANCEL )
|
|
|
|
data->abortFlag = 1;
|
|
|
|
|
|
|
|
data->dialog = NULL;
|
|
|
|
gtk_widget_destroy( GTK_WIDGET( dialog ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
onUpdateBlocklistCB( GtkButton * w, gpointer core )
|
|
|
|
{
|
|
|
|
GtkWidget * d;
|
|
|
|
struct blocklist_data * data;
|
|
|
|
|
|
|
|
d = gtk_message_dialog_new( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( w ) ) ),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_INFO,
|
|
|
|
GTK_BUTTONS_NONE,
|
|
|
|
_( "Updating Blocklist" ) );
|
|
|
|
gtk_dialog_add_buttons( GTK_DIALOG( d ),
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
|
|
|
NULL );
|
|
|
|
gtk_dialog_set_response_sensitive( GTK_DIALOG( d ), GTK_RESPONSE_CLOSE, FALSE );
|
|
|
|
|
|
|
|
data = g_new0( struct blocklist_data, 1 );
|
|
|
|
data->dialog = d;
|
|
|
|
data->core = core;
|
|
|
|
|
|
|
|
g_signal_connect( d, "response", G_CALLBACK(onUpdateBlocklistResponseCB), data );
|
|
|
|
gtk_widget_show( d );
|
|
|
|
g_thread_create( updateBlocklist, data, FALSE, NULL );
|
|
|
|
}
|
|
|
|
|
2008-02-13 03:00:21 +00:00
|
|
|
static GtkWidget*
|
|
|
|
peerPage( GObject * core )
|
|
|
|
{
|
|
|
|
int row = 0;
|
|
|
|
const char * s;
|
|
|
|
GtkWidget * t;
|
|
|
|
GtkWidget * w;
|
2008-03-30 00:21:46 +00:00
|
|
|
GtkWidget * b;
|
|
|
|
GtkWidget * h;
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
t = hig_workarea_create( );
|
2008-02-13 03:00:21 +00:00
|
|
|
hig_workarea_add_section_title (t, &row, _("Options"));
|
|
|
|
|
2008-03-08 01:43:20 +00:00
|
|
|
s = _("Use peer e_xchange");
|
2008-02-13 03:00:21 +00:00
|
|
|
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 );
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
hig_workarea_add_section_divider( t, &row );
|
2008-03-08 01:43:20 +00:00
|
|
|
/* section header for the "maximum number of peers" section */
|
2008-02-13 03:00:21 +00:00
|
|
|
hig_workarea_add_section_title( t, &row, _( "Limits" ) );
|
|
|
|
|
|
|
|
w = new_spin_button( PREF_KEY_MAX_PEERS_GLOBAL, core, 1, 3000, 5 );
|
2008-02-13 15:23:16 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Maximum peers _overall:" ), w, NULL );
|
2008-02-13 03:00:21 +00:00
|
|
|
w = new_spin_button( PREF_KEY_MAX_PEERS_PER_TORRENT, core, 1, 300, 5 );
|
2008-02-13 15:23:16 +00:00
|
|
|
hig_workarea_add_row( t, &row, _( "Maximum peers per _torrent:" ), w, NULL );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
2008-03-30 00:21:46 +00:00
|
|
|
hig_workarea_add_section_divider( t, &row );
|
|
|
|
hig_workarea_add_section_title( t, &row, _( "Blocklist" ) );
|
|
|
|
|
2008-03-30 02:23:28 +00:00
|
|
|
s = _( "Prevent peers in the _blocklist from connecting" );
|
2008-03-30 00:21:46 +00:00
|
|
|
w = new_check_button( s, PREF_KEY_BLOCKLIST_ENABLED, core );
|
|
|
|
hig_workarea_add_wide_control( t, &row, w );
|
|
|
|
|
|
|
|
b = gtk_button_new_with_mnemonic( _( "_Update Blocklist" ) );
|
|
|
|
g_signal_connect( b, "clicked", G_CALLBACK(onUpdateBlocklistCB), core );
|
|
|
|
h = gtk_hbox_new( FALSE, GUI_PAD_BIG );
|
|
|
|
gtk_box_pack_start( GTK_BOX(h), b, FALSE, FALSE, 0 );
|
|
|
|
hig_workarea_add_wide_control( t, &row, h );
|
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
hig_workarea_finish( t, &row );
|
2008-02-13 03:00:21 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
2008-02-13 03:33:01 +00:00
|
|
|
networkPage( GObject * core, gpointer alive )
|
2008-02-13 03:00:21 +00:00
|
|
|
{
|
|
|
|
int row = 0;
|
|
|
|
const char * s;
|
|
|
|
GtkWidget * t;
|
|
|
|
GtkWidget * w, * w2;
|
2008-02-13 03:33:01 +00:00
|
|
|
GtkWidget * l;
|
|
|
|
GtkWidget * h;
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
t = hig_workarea_create( );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2008-02-13 03:33:01 +00:00
|
|
|
hig_workarea_add_section_title (t, &row, _("Bandwidth"));
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2008-03-07 20:48:36 +00:00
|
|
|
s = _("Limit _download speed (KB/s):");
|
2007-09-28 00:46:22 +00:00
|
|
|
w = new_check_button( s, PREF_KEY_DL_LIMIT_ENABLED, core );
|
2007-12-26 10:39:10 +00:00
|
|
|
w2 = new_spin_button( PREF_KEY_DL_LIMIT, core, 0, INT_MAX, 5 );
|
2007-12-13 20:46:19 +00:00
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET(w2), pref_flag_get( PREF_KEY_DL_LIMIT_ENABLED ) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(target_cb), w2 );
|
2008-02-12 16:56:44 +00:00
|
|
|
hig_workarea_add_row_w( t, &row, w, w2, NULL );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2008-03-11 04:19:50 +00:00
|
|
|
s = _("Limit _upload speed (KB/s):");
|
|
|
|
w = new_check_button( s, PREF_KEY_UL_LIMIT_ENABLED, core );
|
|
|
|
w2 = new_spin_button( PREF_KEY_UL_LIMIT, core, 0, INT_MAX, 5 );
|
|
|
|
gtk_widget_set_sensitive( GTK_WIDGET(w2), pref_flag_get( PREF_KEY_UL_LIMIT_ENABLED ) );
|
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(target_cb), w2 );
|
|
|
|
hig_workarea_add_row_w( t, &row, w, w2, NULL );
|
|
|
|
|
2008-02-13 03:33:01 +00:00
|
|
|
hig_workarea_add_section_title (t, &row, _("Ports"));
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2008-03-18 19:14:21 +00:00
|
|
|
s = _("_Forward port from router" );
|
2007-09-28 00:46:22 +00:00
|
|
|
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 );
|
2007-12-15 22:24:16 +00:00
|
|
|
|
2008-03-18 19:14:21 +00:00
|
|
|
h = gtk_hbox_new( FALSE, GUI_PAD_BIG );
|
2007-12-26 10:39:10 +00:00
|
|
|
w2 = new_spin_button( PREF_KEY_PORT, core, 1, INT_MAX, 1 );
|
2007-12-15 22:24:16 +00:00
|
|
|
gtk_box_pack_start( GTK_BOX(h), w2, FALSE, FALSE, 0 );
|
|
|
|
l = gtk_label_new( NULL );
|
|
|
|
gtk_misc_set_alignment( GTK_MISC(l), 0.0f, 0.5f );
|
|
|
|
gtk_box_pack_start( GTK_BOX(h), l, FALSE, FALSE, 0 );
|
2008-03-19 17:14:47 +00:00
|
|
|
hig_workarea_add_row( t, &row, _("Incoming _port:"), h, w );
|
2007-12-15 22:24:16 +00:00
|
|
|
|
|
|
|
g_object_set_data( G_OBJECT(l), "tr-port-spin", w2 );
|
2008-02-07 16:17:52 +00:00
|
|
|
g_object_set_data( G_OBJECT(l), "alive", alive );
|
2007-12-15 22:24:16 +00:00
|
|
|
testing_port_cb( NULL, l );
|
|
|
|
|
2008-02-27 18:45:06 +00:00
|
|
|
g_signal_connect( w, "toggled", G_CALLBACK(testing_port_cb), l );
|
2007-12-15 22:24:16 +00:00
|
|
|
g_signal_connect( w2, "value-changed", G_CALLBACK(testing_port_cb), l );
|
2007-09-27 20:57:58 +00:00
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
hig_workarea_finish( t, &row );
|
2008-02-13 03:00:21 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
tr_prefs_dialog_new( GObject * core, GtkWindow * parent )
|
|
|
|
{
|
|
|
|
GtkWidget * d;
|
|
|
|
GtkWidget * n;
|
|
|
|
gboolean * alive;
|
|
|
|
|
|
|
|
alive = g_new( gboolean, 1 );
|
|
|
|
*alive = TRUE;
|
|
|
|
|
|
|
|
d = gtk_dialog_new_with_buttons( _("Preferences"), parent,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
|
|
|
NULL );
|
|
|
|
gtk_window_set_role( GTK_WINDOW(d), "transmission-preferences-dialog" );
|
|
|
|
gtk_dialog_set_has_separator( GTK_DIALOG( d ), FALSE );
|
|
|
|
gtk_container_set_border_width( GTK_CONTAINER( d ), GUI_PAD );
|
|
|
|
g_object_weak_ref( G_OBJECT( d ), dialogDestroyed, alive );
|
|
|
|
|
|
|
|
n = gtk_notebook_new( );
|
|
|
|
|
2008-02-14 17:18:00 +00:00
|
|
|
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
|
|
|
|
torrentPage( core ),
|
|
|
|
gtk_label_new (_("Torrents")) );
|
|
|
|
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
|
|
|
|
peerPage( core ),
|
|
|
|
gtk_label_new (_("Peers")) );
|
|
|
|
gtk_notebook_append_page( GTK_NOTEBOOK( n ),
|
|
|
|
networkPage( core, alive ),
|
|
|
|
gtk_label_new (_("Network")) );
|
2008-02-13 03:00:21 +00:00
|
|
|
|
|
|
|
g_signal_connect( d, "response", G_CALLBACK(response_cb), core );
|
|
|
|
gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(d)->vbox), n );
|
2007-09-28 00:46:22 +00:00
|
|
|
gtk_widget_show_all( GTK_DIALOG(d)->vbox );
|
|
|
|
return d;
|
2007-02-19 22:09:05 +00:00
|
|
|
}
|