From b7c4f5956529e04fc63a3b6f3ca544a47ee439d9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 14 Feb 2008 17:18:00 +0000 Subject: [PATCH] code cleanup --- gtk/hig.c | 16 +++--- gtk/hig.h | 94 ++++++++++++++-------------------- gtk/open.c | 44 +++++++++------- gtk/torrent-inspector.c | 3 +- gtk/tr_core.c | 109 ++++++++++++++++------------------------ gtk/tr_core.h | 39 ++++++-------- gtk/tr_prefs.c | 67 ++++++++++++------------ 7 files changed, 165 insertions(+), 207 deletions(-) diff --git a/gtk/hig.c b/gtk/hig.c index c138c4acd..449021500 100644 --- a/gtk/hig.c +++ b/gtk/hig.c @@ -17,9 +17,9 @@ GtkWidget* hig_workarea_create (void) { GtkWidget * t = gtk_table_new( 1, 2, FALSE ); - gtk_container_set_border_width( GTK_CONTAINER( t ), 12 ); - gtk_table_set_col_spacing( GTK_TABLE( t ), 0, 12 ); - gtk_table_set_row_spacings( GTK_TABLE( t ), 6 ); + gtk_container_set_border_width( GTK_CONTAINER( t ), GUI_PAD_BIG ); + gtk_table_set_col_spacing( GTK_TABLE( t ), 0, GUI_PAD_BIG ); + gtk_table_set_row_spacings( GTK_TABLE( t ), GUI_PAD ); return t; } @@ -45,12 +45,12 @@ hig_workarea_add_section_title( GtkWidget * t, l = gtk_label_new( buf ); gtk_misc_set_alignment( GTK_MISC( l ), 0.0f, 0.5f ); gtk_label_set_use_markup( GTK_LABEL( l ), TRUE ); - gtk_table_attach( GTK_TABLE( t ), l, 0, 2, *row, *row+1, GTK_FILL, 0, 0, 0 ); + gtk_table_attach( GTK_TABLE( t ), l, 0, 2, *row, *row+1, ~0, 0, 0, 0 ); ++*row; } static GtkWidget* -control_row_new( GtkWidget * w ) +rowNew( GtkWidget * w ) { GtkWidget * a; GtkWidget * h = gtk_hbox_new( FALSE, 0 ); @@ -75,7 +75,7 @@ hig_workarea_add_wide_control( GtkWidget * t, int * row, GtkWidget * w ) { - GtkWidget * r = control_row_new( w ); + GtkWidget * r = rowNew( w ); gtk_table_attach( GTK_TABLE( t ), r, 0, 2, *row, *row+1, GTK_FILL, 0, 0, 0 ); ++*row; } @@ -97,7 +97,7 @@ hig_workarea_add_label_w( GtkWidget * t, int row, GtkWidget * l ) { - GtkWidget * w = control_row_new( l ); + GtkWidget * w = rowNew( l ); gtk_table_attach( GTK_TABLE( t ), w, 0, 1, row, row+1, GTK_FILL, GTK_FILL, 0, 0 ); } @@ -117,7 +117,7 @@ hig_workarea_add_control( GtkWidget * t, GtkWidget * control ) { if ( GTK_IS_MISC( control ) ) - gtk_misc_set_alignment( GTK_MISC(control), 0.0f, 0.5f ); + gtk_misc_set_alignment( GTK_MISC( control ), 0.0f, 0.5f ); gtk_table_attach( GTK_TABLE( t ), control, 1, 2, row, row+1, diff --git a/gtk/hig.h b/gtk/hig.h index 3369f8530..a19662b50 100644 --- a/gtk/hig.h +++ b/gtk/hig.h @@ -16,74 +16,58 @@ #include /** -*** utility code to make it slightly less painful to create -*** dialogs compliant with Gnome's Human Interface Guidelines +*** utility code for making dialog layout that follows the Gnome HIG. +*** see section 8.2.2, Visual Design > Window Layout > Dialogs. **/ -GtkWidget* hig_workarea_create (void); +GtkWidget* hig_workarea_create( void ); -void -hig_workarea_add_section_divider (GtkWidget * table, - int * row); +void hig_workarea_add_section_divider( GtkWidget * table, + int * row ); -void -hig_workarea_add_section_title (GtkWidget * table, - int * row, - const char * section_title); +void hig_workarea_add_section_title( GtkWidget * table, + int * row, + const char * section_title ); -void -hig_workarea_add_wide_control (GtkWidget * table, - int * row, - GtkWidget * w); +void hig_workarea_add_wide_control( GtkWidget * table, + int * row, + GtkWidget * w ); -GtkWidget* -hig_workarea_add_wide_checkbutton (GtkWidget * table, - int * row, - const char * mnemonic_string, - gboolean is_active); +GtkWidget* hig_workarea_add_wide_checkbutton( GtkWidget * table, + int * row, + const char * mnemonic_string, + gboolean is_active ); -GtkWidget* -hig_workarea_add_label (GtkWidget * table, - int row, - const char * mnemonic_string); +GtkWidget* hig_workarea_add_label( GtkWidget * table, + int row, + const char * mnemonic_string ); -void -hig_workarea_add_label_w (GtkWidget * table, - int row, - GtkWidget * label_widget); +void hig_workarea_add_label_w( GtkWidget * table, + int row, + GtkWidget * label_widget ); -void -hig_workarea_add_control (GtkWidget * table, - int row, - GtkWidget * control); +void hig_workarea_add_control( GtkWidget * table, + int row, + GtkWidget * control ); -GtkWidget* -hig_workarea_add_row (GtkWidget * table, - int * row, - const char * mnemonic_string, - GtkWidget * control, - GtkWidget * mnemonic_or_null_if_control_is_mnemonic); +GtkWidget* hig_workarea_add_row (GtkWidget * table, + int * row, + const char * mnemonic_string, + GtkWidget * control, + GtkWidget * mnemonic_or_null_for_control ); -void -hig_workarea_add_row_w (GtkWidget * table, - int * row, - GtkWidget * label, - GtkWidget * control, - GtkWidget * mnemonic_or_null_if_control_is_mnemonic); +void hig_workarea_add_row_w( GtkWidget * table, + int * row, + GtkWidget * label, + GtkWidget * control, + GtkWidget * mnemonic_or_null_for_control ); -void -hig_workarea_finish (GtkWidget * table, - int * row); +void hig_workarea_finish( GtkWidget * table, + int * row ); -void -hig_message_dialog_set_text (GtkMessageDialog * dialog, - const char * primary, - const char * secondary); - - -/** -*** -**/ +void hig_message_dialog_set_text( GtkMessageDialog * dialog, + const char * primary, + const char * secondary ); enum { diff --git a/gtk/open.c b/gtk/open.c index 890d0b8fa..4d4c67a62 100644 --- a/gtk/open.c +++ b/gtk/open.c @@ -11,6 +11,7 @@ */ #include +#include #include #include "file-list.h" #include "hig.h" @@ -20,7 +21,8 @@ struct OpenData { TrCore * core; GtkWidget * list; - GtkWidget * run_check; + GtkToggleButton * run_check; + GtkToggleButton * delete_check; char * filename; char * destination; TrTorrent * gtor; @@ -50,9 +52,11 @@ openResponseCB( GtkDialog * dialog, gint response, gpointer gdata ) if( response != GTK_RESPONSE_ACCEPT ) deleteOldTorrent( data ); else { - if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->run_check ) ) ) + if( gtk_toggle_button_get_active( data->run_check ) ) tr_torrentStart( tr_torrent_handle( data->gtor ) ); tr_core_add_torrent( data->core, data->gtor ); + if( gtk_toggle_button_get_active( data->delete_check ) ) + g_unlink( data->filename ); } } @@ -64,12 +68,12 @@ openResponseCB( GtkDialog * dialog, gint response, gpointer gdata ) } static void -updateTorrent( struct OpenData * data ) +updateTorrent( struct OpenData * o ) { - if( data->gtor ) - tr_torrentSetFolder( tr_torrent_handle( data->gtor ), data->destination ); + if( o->gtor ) + tr_torrentSetFolder( tr_torrent_handle( o->gtor ), o->destination ); - file_list_set_torrent( data->list, data->gtor ); + file_list_set_torrent( o->list, o->gtor ); } static void @@ -79,7 +83,6 @@ sourceChanged( GtkFileChooserButton * b, gpointer gdata ) deleteOldTorrent( data ); - /* update the filename */ g_free( data->filename ); data->filename = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) ); @@ -89,8 +92,9 @@ sourceChanged( GtkFileChooserButton * b, gpointer gdata ) tr_torrent * torrent; tr_handle * handle = tr_core_handle( data->core ); tr_ctorSetMetainfoFromFile( data->ctor, data->filename ); - tr_ctorSetPaused( data->ctor, TR_FORCE, TRUE ); tr_ctorSetDestination( data->ctor, TR_FORCE, data->destination ); + tr_ctorSetPaused( data->ctor, TR_FORCE, TRUE ); + tr_ctorSetDeleteSource( data->ctor, FALSE ); if(( torrent = tr_torrentNew( handle, data->ctor, &err ))) data->gtor = tr_torrent_new_preexisting( torrent ); } @@ -110,6 +114,7 @@ static void destinationChanged( GtkFileChooserButton * b, gpointer gdata ) { struct OpenData * data = gdata; + g_free( data->destination ); data->destination = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( b ) ); @@ -138,12 +143,11 @@ makeaddwind( GtkWindow * parent, uint8_t flag; /* make the dialog */ - d = gtk_dialog_new_with_buttons( _( "Open Torrent" ), - parent, - GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL ); + d = gtk_dialog_new_with_buttons( _( "Open Torrent" ), parent, + GTK_DIALOG_DESTROY_WITH_PARENT|GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL ); if( tr_ctorGetDestination( ctor, TR_FORCE, &str ) ) g_assert_not_reached( ); @@ -152,7 +156,8 @@ makeaddwind( GtkWindow * parent, data->ctor = ctor; data->filename = g_strdup( tr_ctorGetSourceFile( ctor ) ); data->destination = g_strdup( str ); - g_signal_connect( G_OBJECT( d ), "response", G_CALLBACK( openResponseCB ), data ); + g_signal_connect( G_OBJECT( d ), "response", + G_CALLBACK( openResponseCB ), data ); t = gtk_table_new( 6, 2, FALSE ); gtk_container_set_border_width( GTK_CONTAINER( t ), GUI_PAD_BIG ); @@ -164,7 +169,8 @@ makeaddwind( GtkWindow * parent, gtk_misc_set_alignment( GTK_MISC( l ), 0.0f, 0.5f ); gtk_table_attach( GTK_TABLE( t ), l, col, col+1, row, row+1, GTK_FILL, 0, 0, 0 ); ++col; - w = gtk_file_chooser_button_new( _( "Select Torrent" ), GTK_FILE_CHOOSER_ACTION_OPEN ); + w = gtk_file_chooser_button_new( _( "Select Torrent" ), + GTK_FILE_CHOOSER_ACTION_OPEN ); gtk_table_attach( GTK_TABLE( t ), w, col, col+1, row, row+1, ~0, 0, 0, 0 ); gtk_label_set_mnemonic_widget( GTK_LABEL( l ), w ); filter = gtk_file_filter_new( ); @@ -175,7 +181,8 @@ makeaddwind( GtkWindow * parent, gtk_file_filter_set_name( filter, _( "All files" ) ); gtk_file_filter_add_pattern( filter, "*" ); gtk_file_chooser_add_filter( GTK_FILE_CHOOSER( w ), filter ); - g_signal_connect( w, "selection-changed", G_CALLBACK( sourceChanged ), data ); + g_signal_connect( w, "selection-changed", + G_CALLBACK( sourceChanged ), data ); if( data->filename ) if( !gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( w ), data->filename ) ) g_warning( "couldn't select '%s'", data->filename ); @@ -209,6 +216,7 @@ makeaddwind( GtkWindow * parent, ++row; col = 0; w = gtk_check_button_new_with_mnemonic( _( "_Delete original torrent file" ) ); + data->delete_check = GTK_TOGGLE_BUTTON( w ); if( tr_ctorGetDeleteSource( ctor, &flag ) ) g_assert_not_reached( ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), flag ); @@ -217,7 +225,7 @@ makeaddwind( GtkWindow * parent, ++row; col = 0; w = gtk_check_button_new_with_mnemonic( _( "_Start when added" ) ); - data->run_check = w; + data->run_check = GTK_TOGGLE_BUTTON( w ); if( tr_ctorGetPaused( ctor, TR_FORCE, &flag ) ) g_assert_not_reached( ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), !flag ); diff --git a/gtk/torrent-inspector.c b/gtk/torrent-inspector.c index c00034a43..082d7a4d5 100644 --- a/gtk/torrent-inspector.c +++ b/gtk/torrent-inspector.c @@ -698,7 +698,8 @@ static GtkWidget* info_page_new (tr_torrent * tor) g_snprintf (name, sizeof(name), namefmt, _("Comment")); b = gtk_text_buffer_new (NULL); - gtk_text_buffer_set_text (b, info->comment, -1); + if( info->comment ) + gtk_text_buffer_set_text (b, info->comment, -1); w = gtk_text_view_new_with_buffer (b); gtk_widget_set_size_request (w, 0u, 100u); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(w), GTK_WRAP_WORD); diff --git a/gtk/tr_core.c b/gtk/tr_core.c index 2046ede77..f103dc40b 100644 --- a/gtk/tr_core.c +++ b/gtk/tr_core.c @@ -22,15 +22,13 @@ * DEALINGS IN THE SOFTWARE. *****************************************************************************/ -#include -#include -#include +#include /* strcmp, strlen */ #include #include #include -#include +#include /* tr_strcmp */ #include "conf.h" #include "tr_core.h" @@ -43,14 +41,13 @@ struct TrCorePrivate GtkTreeModel * model; tr_handle * handle; int nextid; - gboolean quitting; struct core_stats stats; }; static void -tr_core_marshal_err( GClosure * closure, GValue * ret UNUSED, guint count, - const GValue * vals, gpointer hint UNUSED, - gpointer marshal ) +tr_core_marshal_err( GClosure * closure, GValue * ret UNUSED, + guint count, const GValue * vals, + gpointer hint UNUSED, gpointer marshal ) { typedef void (*TRMarshalErr) ( gpointer, enum tr_core_err, const char *, gpointer ); @@ -60,22 +57,21 @@ tr_core_marshal_err( GClosure * closure, GValue * ret UNUSED, guint count, const char * errstr; gpointer inst, gdata; - g_return_if_fail( 3 == count ); + g_return_if_fail( count == 3 ); inst = g_value_peek_pointer( vals ); errcode = g_value_get_int( vals + 1 ); errstr = g_value_get_string( vals + 2 ); gdata = closure->data; - callback = (TRMarshalErr) ( NULL == marshal ? - cclosure->callback : marshal ); + callback = (TRMarshalErr)( marshal ? marshal : cclosure->callback ); callback( inst, errcode, errstr, gdata ); } static void -tr_core_marshal_prompt( GClosure * closure, GValue * ret UNUSED, guint count, - const GValue * vals, gpointer hint UNUSED, - gpointer marshal ) +tr_core_marshal_prompt( GClosure * closure, GValue * ret UNUSED, + guint count, const GValue * vals, + gpointer hint UNUSED, gpointer marshal ) { typedef void (*TRMarshalPrompt)( gpointer, GList *, gpointer, gpointer ); TRMarshalPrompt callback; @@ -84,15 +80,14 @@ tr_core_marshal_prompt( GClosure * closure, GValue * ret UNUSED, guint count, gpointer ctor; gpointer inst, gdata; - g_return_if_fail( 3 == count ); + g_return_if_fail( count == 3 ); inst = g_value_peek_pointer( vals ); - paths = g_value_get_pointer( vals + 1 ); - ctor = g_value_get_pointer( vals + 2 ); + paths = g_value_peek_pointer( vals + 1 ); + ctor = g_value_peek_pointer( vals + 2 ); gdata = closure->data; - callback = (TRMarshalPrompt) ( NULL == marshal ? - cclosure->callback : marshal ); + callback = (TRMarshalPrompt)( marshal ? marshal : cclosure->callback ); callback( inst, paths, ctor, gdata ); } @@ -106,31 +101,30 @@ static void tr_core_dispose( GObject * obj ) { TrCore * core = TR_CORE( obj ); - GObjectClass * parent; if( !isDisposed( core ) ) { + GObjectClass * parent; + pref_save( NULL ); core->priv = NULL; + + parent = g_type_class_peek( g_type_parent( TR_CORE_TYPE ) ); + parent->dispose( obj ); } - - parent = g_type_class_peek( g_type_parent( TR_CORE_TYPE ) ); - parent->dispose( obj ); } - static void tr_core_class_init( gpointer g_class, gpointer g_class_data UNUSED ) { GObjectClass * gobject_class; TrCoreClass * core_class; + g_type_class_add_private( g_class, sizeof(struct TrCorePrivate) ); + gobject_class = G_OBJECT_CLASS( g_class ); gobject_class->dispose = tr_core_dispose; - g_type_class_add_private( g_class, - sizeof(struct TrCorePrivate) ); - core_class = TR_CORE_CLASS( g_class ); core_class->errsig = g_signal_new( "error", G_TYPE_FROM_CLASS( g_class ), @@ -153,11 +147,15 @@ tr_core_class_init( gpointer g_class, gpointer g_class_data UNUSED ) G_TYPE_NONE, 1, G_TYPE_STRING ); } +/*** +**** SORTING +***/ + static int compareDouble( double a, double b ) { if( a < b ) return -1; - if( b < a ) return 1; + if( a > b ) return 1; return 0; } @@ -187,15 +185,6 @@ compareByActivity( GtkTreeModel * model, return 0; } -static int -compareByDateAdded( GtkTreeModel * model UNUSED, - GtkTreeIter * a UNUSED, - GtkTreeIter * b UNUSED, - gpointer user_data UNUSED ) -{ - return 0; /* FIXME */ -} - static int compareByName( GtkTreeModel * model, GtkTreeIter * a, @@ -264,11 +253,6 @@ compareByTracker( GtkTreeModel * model, tr_torrentInfo(tb)->primaryAddress ); } -/*** -**** -***/ - - static void setSort( TrCore * core, const char * mode, gboolean isReversed ) { @@ -279,8 +263,6 @@ setSort( TrCore * core, const char * mode, gboolean isReversed ) if( !strcmp( mode, "sort-by-activity" ) ) gtk_tree_sortable_set_sort_func( sortable, col, compareByActivity, NULL, NULL ); - else if( !strcmp( mode, "sort-by-date-added" ) ) - gtk_tree_sortable_set_sort_func( sortable, col, compareByDateAdded, NULL, NULL ); else if( !strcmp( mode, "sort-by-progress" ) ) gtk_tree_sortable_set_sort_func( sortable, col, compareByProgress, NULL, NULL ); else if( !strcmp( mode, "sort-by-state" ) ) @@ -298,7 +280,8 @@ setSort( TrCore * core, const char * mode, gboolean isReversed ) static void prefsChanged( TrCore * core, const char * key, gpointer data UNUSED ) { - if( !strcmp( key, PREF_KEY_SORT_MODE ) || !strcmp( key, PREF_KEY_SORT_REVERSED ) ) + if( !strcmp( key, PREF_KEY_SORT_MODE ) || + !strcmp( key, PREF_KEY_SORT_REVERSED ) ) { char * mode = pref_string_get( PREF_KEY_SORT_MODE ); gboolean isReversed = pref_flag_get( PREF_KEY_SORT_REVERSED ); @@ -350,7 +333,7 @@ tr_core_init( GTypeInstance * instance, gpointer g_class UNUSED ) pref_int_get( PREF_KEY_DL_LIMIT ), pref_int_get( PREF_KEY_MAX_PEERS_GLOBAL ), pref_int_get( PREF_KEY_MSGLEVEL ), - TRUE ); + TRUE /* message queueing */ ); /* create the model used to store torrent data */ g_assert( ALEN( types ) == MC_ROW_COUNT ); @@ -359,7 +342,6 @@ tr_core_init( GTypeInstance * instance, gpointer g_class UNUSED ) p->model = GTK_TREE_MODEL( store ); p->handle = h; p->nextid = 1; - p->quitting = FALSE; } GType @@ -446,6 +428,7 @@ doCollate( const char * in ) casefold = g_utf8_casefold( in, end-in ); ret = g_utf8_collate_key( casefold, -1 ); g_free( casefold ); + return ret; } @@ -483,15 +466,14 @@ tr_core_load( TrCore * self, gboolean forcePaused ) char * path; tr_ctor * ctor; - TR_IS_CORE( self ); - path = getdownloaddir( ); ctor = tr_ctorNew( tr_core_handle( self ) ); if( forcePaused ) tr_ctorSetPaused( ctor, TR_FORCE, TRUE ); tr_ctorSetDestination( ctor, TR_FALLBACK, path ); - tr_ctorSetMaxConnectedPeers( ctor, TR_FALLBACK, pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) ); + tr_ctorSetMaxConnectedPeers( ctor, TR_FALLBACK, + pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) ); torrents = tr_loadTorrents ( tr_core_handle( self ), ctor, &count ); for( i=0; ierrsig, 0, type, msg ); } @@ -520,10 +500,12 @@ tr_core_apply_defaults( tr_ctor * ctor ) tr_ctorSetPaused( ctor, TR_FORCE, !pref_flag_get( PREF_KEY_START ) ); if( tr_ctorGetDeleteSource( ctor, NULL ) ) - tr_ctorSetDeleteSource( ctor, pref_flag_get( PREF_KEY_DELETE_ORIGINAL ) ); + tr_ctorSetDeleteSource( ctor, + pref_flag_get( PREF_KEY_DELETE_ORIGINAL ) ); if( tr_ctorGetMaxConnectedPeers( ctor, TR_FORCE, NULL ) ) - tr_ctorSetMaxConnectedPeers( ctor, TR_FORCE, pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) ); + tr_ctorSetMaxConnectedPeers( ctor, TR_FORCE, + pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) ); if( tr_ctorGetDestination( ctor, TR_FORCE, NULL ) ) { char * path = pref_string_get( PREF_KEY_DIR_DEFAULT ); @@ -536,22 +518,15 @@ void tr_core_add_ctor( TrCore * self, tr_ctor * ctor ) { TrTorrent * tor; - char * errstr; - - errstr = NULL; + char * errstr = NULL; tr_core_apply_defaults( ctor ); - tor = tr_torrent_new_ctor( tr_core_handle( self ), ctor, &errstr ); - if( !tor ) - { + + if(( tor = tr_torrent_new_ctor( tr_core_handle( self ), ctor, &errstr ))) + tr_core_add_torrent( self, tor ); + else{ tr_core_errsig( self, TR_CORE_ERR_ADD_TORRENT, errstr ); g_free( errstr ); - errstr = NULL; - } - else - { - g_assert( !errstr ); - tr_core_add_torrent( self, tor ); } } diff --git a/gtk/tr_core.h b/gtk/tr_core.h index e1727f638..e136ff57f 100644 --- a/gtk/tr_core.h +++ b/gtk/tr_core.h @@ -87,22 +87,16 @@ enum tr_core_err TR_CORE_ERR_SAVE_STATE /* error saving state */ }; -GType -tr_core_get_type( void ); +GType tr_core_get_type( void ); -TrCore * -tr_core_new( void ); +TrCore * tr_core_new( void ); /* Return the model used without incrementing the reference count */ -GtkTreeModel * -tr_core_model( TrCore * self ); +GtkTreeModel * tr_core_model( TrCore * self ); -/* Returns the libtransmission handle */ -tr_handle * -tr_core_handle( TrCore * self ); +tr_handle * tr_core_handle( TrCore * self ); -const struct core_stats* -tr_core_get_stats( const TrCore * self ); +const struct core_stats* tr_core_get_stats( const TrCore * self ); /****** ******* @@ -144,32 +138,29 @@ void tr_core_torrents_added( TrCore * self ); ******* ******/ -/* remove a torrent, waiting for it to pause if necessary */ -void -tr_core_delete_torrent( TrCore * self, GtkTreeIter * iter /* XXX */ ); +void tr_core_delete_torrent( TrCore * self, GtkTreeIter * iter ); /* update the model with current torrent status */ -void -tr_core_update( TrCore * self ); +void tr_core_update( TrCore * self ); /* emit the "quit" signal */ -void -tr_core_quit( TrCore * self ); +void tr_core_quit( TrCore * self ); /* Set a preference value, save the prefs file, and emit the "prefs-changed" signal */ -void -tr_core_set_pref( TrCore * self, const char * key, const char * val ); +void tr_core_set_pref( TrCore * self, const char * key, const char * val ); /* Set a boolean preference value, save the prefs file, and emit the "prefs-changed" signal */ -void -tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val ); +void tr_core_set_pref_bool( TrCore * self, const char * key, gboolean val ); /* Set an integer preference value, save the prefs file, and emit the "prefs-changed" signal */ -void -tr_core_set_pref_int( TrCore * self, const char * key, int val ); +void tr_core_set_pref_int( TrCore * self, const char * key, int val ); + +/** +*** +**/ /* column names for the model used to store torrent information */ /* keep this in sync with the type array in tr_core_init() in tr_core.c */ diff --git a/gtk/tr_prefs.c b/gtk/tr_prefs.c index 15f576833..a74efce28 100644 --- a/gtk/tr_prefs.c +++ b/gtk/tr_prefs.c @@ -69,7 +69,7 @@ tr_prefs_init_global( void ) *** **/ -#define PREFS_KEY "prefs-key" +#define PREF_KEY "pref-key" static void response_cb( GtkDialog * dialog, int response UNUSED, gpointer unused UNUSED ) @@ -80,7 +80,7 @@ response_cb( GtkDialog * dialog, int response UNUSED, gpointer unused UNUSED ) static void toggled_cb( GtkToggleButton * w, gpointer core ) { - const char * key = g_object_get_data( G_OBJECT(w), PREFS_KEY ); + const char * key = g_object_get_data( G_OBJECT(w), PREF_KEY ); const gboolean flag = gtk_toggle_button_get_active( w ); tr_core_set_pref_bool( TR_CORE(core), key, flag ); } @@ -89,7 +89,7 @@ static GtkWidget* new_check_button( const char * mnemonic, const char * key, gpointer core ) { GtkWidget * w = gtk_check_button_new_with_mnemonic( mnemonic ); - g_object_set_data_full( G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free ); + g_object_set_data_full( G_OBJECT(w), PREF_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; @@ -98,7 +98,7 @@ new_check_button( const char * mnemonic, const char * key, gpointer core ) static void spun_cb( GtkSpinButton * w, gpointer core ) { - const char * key = g_object_get_data( G_OBJECT(w), PREFS_KEY ); + const char * key = g_object_get_data( G_OBJECT(w), PREF_KEY ); const int value = gtk_spin_button_get_value_as_int( w ); tr_core_set_pref_int( TR_CORE(core), key, value ); } @@ -107,7 +107,7 @@ static GtkWidget* new_spin_button( const char * key, gpointer core, int low, int high, int step ) { GtkWidget * w = gtk_spin_button_new_with_range( low, high, step ); - g_object_set_data_full( G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free ); + g_object_set_data_full( G_OBJECT(w), PREF_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 ); @@ -117,7 +117,7 @@ new_spin_button( const char * key, gpointer core, int low, int high, int step ) static void chosen_cb( GtkFileChooser * w, gpointer core ) { - const char * key = g_object_get_data( G_OBJECT(w), PREFS_KEY ); + const char * key = g_object_get_data( G_OBJECT(w), PREF_KEY ); char * value = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER(w) ); tr_core_set_pref( TR_CORE(core), key, value ); g_free( value ); @@ -129,16 +129,17 @@ new_path_chooser_button( const char * key, gpointer core ) GtkWidget * w = gtk_file_chooser_button_new( NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ); char * path = pref_string_get( key ); - g_object_set_data_full( G_OBJECT(w), PREFS_KEY, g_strdup(key), g_free ); + g_object_set_data_full( G_OBJECT(w), PREF_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; } static void -target_cb( GtkWidget * widget, gpointer target ) +target_cb( GtkWidget * tb, gpointer target ) { - gtk_widget_set_sensitive( GTK_WIDGET(target), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ) ); + const gboolean b = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( tb ) ); + gtk_widget_set_sensitive( GTK_WIDGET(target), b ); } struct test_port_data @@ -155,7 +156,7 @@ test_port( gpointer data_gpointer ) if( *data->alive ) { GObject * o = G_OBJECT( data->label ); - GtkSpinButton * spin = GTK_SPIN_BUTTON( g_object_get_data( o, "tr-port-spin" ) ); + GtkSpinButton * spin = g_object_get_data( o, "tr-port-spin" ); const int port = gtk_spin_button_get_value_as_int( spin ); int isOpen; int size; @@ -202,9 +203,8 @@ generalPage( GObject * core ) GtkWidget * t; GtkWidget * w; - t = hig_workarea_create (); - - hig_workarea_add_section_title (t, &row, _("Windows")); + t = hig_workarea_create( ); + hig_workarea_add_section_title( t, &row, _( "Windows" ) ); s = _("Show an _icon in the system tray"); w = new_check_button( s, PREF_KEY_SYSTRAY, core ); @@ -214,7 +214,7 @@ generalPage( GObject * core ) w = new_check_button( s, PREF_KEY_ASKQUIT, core ); hig_workarea_add_wide_control( t, &row, w ); - hig_workarea_finish (t, &row); + hig_workarea_finish( t, &row ); return t; } @@ -226,8 +226,7 @@ torrentPage( GObject * core ) GtkWidget * t; GtkWidget * w; - t = hig_workarea_create (); - + t = hig_workarea_create( ); hig_workarea_add_section_title( t, &row, _( "Location" ) ); w = new_path_chooser_button( PREF_KEY_DIR_DEFAULT, core ); @@ -248,7 +247,7 @@ torrentPage( GObject * core ) w = new_check_button( s, PREF_KEY_DELETE_ORIGINAL, core ); hig_workarea_add_wide_control( t, &row, w ); - hig_workarea_finish (t, &row); + hig_workarea_finish( t, &row ); return t; } @@ -260,7 +259,7 @@ peerPage( GObject * core ) GtkWidget * t; GtkWidget * w; - t = hig_workarea_create (); + t = hig_workarea_create( ); hig_workarea_add_section_title (t, &row, _("Options")); s = _("Use peer _exchange if possible"); @@ -279,7 +278,7 @@ peerPage( GObject * core ) w = new_spin_button( PREF_KEY_MAX_PEERS_PER_TORRENT, core, 1, 300, 5 ); hig_workarea_add_row( t, &row, _( "Maximum peers per _torrent:" ), w, NULL ); - hig_workarea_finish (t, &row); + hig_workarea_finish( t, &row ); return t; } @@ -292,9 +291,8 @@ networkPage( GObject * core, gpointer alive ) GtkWidget * w, * w2; GtkWidget * l; GtkWidget * h; - GtkTooltips * tips = gtk_tooltips_new( ); - t = hig_workarea_create (); + t = hig_workarea_create( ); hig_workarea_add_section_title (t, &row, _("Bandwidth")); @@ -314,10 +312,9 @@ networkPage( GObject * core, gpointer alive ) hig_workarea_add_section_title (t, &row, _("Ports")); - s = _("Automatically _map port" ); + s = _("_Map port with UPnP or NAT-PMP" ); w = new_check_button( s, PREF_KEY_NAT, core ); hig_workarea_add_wide_control( t, &row, w ); - gtk_tooltips_set_tip( GTK_TOOLTIPS( tips ), w, _( "NAT traversal uses either NAT-PMP or UPnP" ), NULL ); h = gtk_hbox_new( FALSE, GUI_PAD ); w2 = new_spin_button( PREF_KEY_PORT, core, 1, INT_MAX, 1 ); @@ -334,7 +331,7 @@ networkPage( GObject * core, gpointer alive ) g_signal_connect( w, "toggled", G_CALLBACK(toggled_cb), l ); g_signal_connect( w2, "value-changed", G_CALLBACK(testing_port_cb), l ); - hig_workarea_finish (t, &row); + hig_workarea_finish( t, &row ); return t; } @@ -343,7 +340,6 @@ tr_prefs_dialog_new( GObject * core, GtkWindow * parent ) { GtkWidget * d; GtkWidget * n; - GtkWidget * w; gboolean * alive; alive = g_new( gboolean, 1 ); @@ -360,15 +356,18 @@ tr_prefs_dialog_new( GObject * core, GtkWindow * parent ) n = gtk_notebook_new( ); - w = torrentPage( core ); - gtk_notebook_append_page( GTK_NOTEBOOK( n ), w, gtk_label_new (_("Torrents")) ); - w = peerPage( core ); - gtk_notebook_append_page( GTK_NOTEBOOK( n ), w, gtk_label_new (_("Peers")) ); - w = networkPage( core, alive ); - gtk_notebook_append_page( GTK_NOTEBOOK( n ), w, gtk_label_new (_("Network")) ); - w = generalPage( core ); - gtk_notebook_append_page( GTK_NOTEBOOK( n ), w, gtk_label_new (_("General")) ); - + 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")) ); + gtk_notebook_append_page( GTK_NOTEBOOK( n ), + generalPage( core ), + gtk_label_new (_("General")) ); g_signal_connect( d, "response", G_CALLBACK(response_cb), core ); gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(d)->vbox), n );