diff --git a/gtk/conf.c b/gtk/conf.c index 062f014cf..7485127d1 100644 --- a/gtk/conf.c +++ b/gtk/conf.c @@ -176,6 +176,14 @@ gboolean pref_flag_get ( const char * key ) { return g_key_file_get_boolean( getPrefsKeyFile( ), GROUP, key, NULL ); } +gboolean +pref_flag_eval( pref_flag_t val, const char * key ) { + switch( val ) { + case PREF_FLAG_TRUE: return TRUE; + case PREF_FLAG_FALSE: return FALSE; + default: return pref_flag_get( key ); + } +} void pref_flag_set( const char * key, gboolean value ) { g_key_file_set_boolean( getPrefsKeyFile( ), GROUP, key, value ); diff --git a/gtk/conf.h b/gtk/conf.h index 1918cbd6b..f9442900f 100644 --- a/gtk/conf.h +++ b/gtk/conf.h @@ -43,6 +43,22 @@ void pref_string_set_default ( const char * key, const char * value ); void pref_save ( char **errstr ); +/** +*** +**/ + +enum +{ + PREF_FLAG_DEFAULT = 0, + PREF_FLAG_FALSE = 1, + PREF_FLAG_TRUE = 2 +}; + +typedef int pref_flag_t; + +gboolean pref_flag_eval( pref_flag_t val, const char * key ); + + /** *** **/ diff --git a/gtk/ipc.c b/gtk/ipc.c index 5086dda51..5b130d688 100644 --- a/gtk/ipc.c +++ b/gtk/ipc.c @@ -513,7 +513,7 @@ smsg_add( enum ipc_msg id UNUSED, tr_benc * val, int64_t tag, void * arg ) if( list ) { list = g_slist_reverse( list ); - tr_core_add_list( srv->core, list, FALSE ); + tr_core_add_list_defaults( srv->core, list ); tr_core_torrents_added( TR_CORE( srv->core ) ); } diff --git a/gtk/main.c b/gtk/main.c index a310307ce..98f9abe71 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -355,6 +355,9 @@ appsetup( TrWindow * wind, GSList * torrentFiles, struct cbdata * cbdata, gboolean forcepause, gboolean minimized ) { + const pref_flag_t start = forcepause ? PREF_FLAG_FALSE : PREF_FLAG_DEFAULT; + const pref_flag_t prompt = PREF_FLAG_DEFAULT; + /* fill out cbdata */ cbdata->wind = NULL; cbdata->icon = NULL; @@ -378,7 +381,7 @@ appsetup( TrWindow * wind, GSList * torrentFiles, /* add torrents from command-line and saved state */ tr_core_load( cbdata->core, forcepause ); - tr_core_add_list( cbdata->core, torrentFiles, forcepause ); + tr_core_add_list( cbdata->core, torrentFiles, start, prompt ); torrentFiles = NULL; tr_core_torrents_added( cbdata->core ); @@ -694,7 +697,7 @@ gotdrag( GtkWidget * widget UNUSED, if( paths ) { paths = g_slist_reverse( paths ); - tr_core_add_list( data->core, paths, FALSE ); + tr_core_add_list_defaults( data->core, paths ); tr_core_torrents_added( data->core ); } diff --git a/gtk/open-dialog.c b/gtk/open-dialog.c index 54161f16b..f7cd9b9a8 100644 --- a/gtk/open-dialog.c +++ b/gtk/open-dialog.c @@ -252,13 +252,21 @@ openSingleTorrentDialog( GtkWindow * parent, static void onOpenDialogResponse( GtkDialog * dialog, int response, gpointer core ) { - char * folder = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER( dialog ) ); + char * folder; + + /* remember this folder the next time we use this dialog */ + folder = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER( dialog ) ); pref_string_set( PREF_KEY_OPEN_DIALOG_FOLDER, folder ); g_free( folder ); - if( response == GTK_RESPONSE_ACCEPT ) { + if( response == GTK_RESPONSE_ACCEPT ) + { + GtkWidget * w = gtk_file_chooser_get_extra_widget( GTK_FILE_CHOOSER( dialog ) ); + const gboolean showOptions = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( w ) ); + const pref_flag_t start = PREF_FLAG_DEFAULT; + const pref_flag_t prompt = showOptions ? PREF_FLAG_TRUE : PREF_FLAG_FALSE; GSList * l = gtk_file_chooser_get_filenames( GTK_FILE_CHOOSER( dialog ) ); - tr_core_add_list( core, l, FALSE ); + tr_core_add_list( core, l, start, prompt ); } gtk_widget_destroy( GTK_WIDGET( dialog ) ); @@ -269,6 +277,7 @@ openDialog( GtkWindow * parent, TrCore * core ) { GtkWidget * w; + GtkWidget * c; GtkFileFilter * filter; char * folder; @@ -299,7 +308,11 @@ openDialog( GtkWindow * parent, gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( w ), folder ); g_free( folder ); } - + + c = gtk_check_button_new_with_mnemonic( _( "Display _options dialog" ) ); + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( c ), pref_flag_get( PREF_KEY_OPTIONS_PROMPT ) ); + gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER( w ), c ); + gtk_widget_show( c ); gtk_widget_show( w ); return w; diff --git a/gtk/tr-core.c b/gtk/tr-core.c index 0806226b3..4631937bf 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -310,7 +310,7 @@ static gboolean watchFolderIdle( gpointer gcore ) { TrCore * core = TR_CORE( gcore ); - tr_core_add_list( core, core->priv->monitor_files, FALSE ); + tr_core_add_list_defaults( core, core->priv->monitor_files ); /* cleanup */ core->priv->monitor_files = NULL; @@ -643,22 +643,24 @@ tr_core_add_ctor( TrCore * self, tr_ctor * ctor ) } void -tr_core_add_list( TrCore * core, - GSList * torrentFiles, - gboolean forcePaused ) +tr_core_add_list( TrCore * core, + GSList * torrentFiles, + pref_flag_t start, + pref_flag_t prompt ) { + const gboolean doStart = pref_flag_eval( start, PREF_KEY_START ); + const gboolean doPrompt = pref_flag_eval( prompt, PREF_KEY_OPTIONS_PROMPT ); + if( torrentFiles && !isDisposed( core ) ) { GSList * l; - const gboolean doPrompt = pref_flag_get( PREF_KEY_OPTIONS_PROMPT ); tr_handle * handle = core->priv->handle; for( l=torrentFiles; l!=NULL; l=l->next ) { tr_ctor * ctor = tr_ctorNew( handle ); tr_core_apply_defaults( ctor ); - if( forcePaused ) - tr_ctorSetPaused( ctor, TR_FORCE, TRUE ); + tr_ctorSetPaused( ctor, TR_FORCE, !doStart ); if( tr_ctorSetMetainfoFromFile( ctor, l->data ) ) tr_ctorFree( ctor ); else if( tr_torrentParse( handle, ctor, NULL ) ) diff --git a/gtk/tr-core.h b/gtk/tr-core.h index 899a4e4be..750574c6a 100644 --- a/gtk/tr-core.h +++ b/gtk/tr-core.h @@ -31,9 +31,8 @@ #include #include - +#include "conf.h" /* pref_flag_t */ #include "tr-torrent.h" -#include "util.h" #define TR_CORE_TYPE (tr_core_get_type()) #define TR_CORE(o) G_TYPE_CHECK_INSTANCE_CAST((o),TR_CORE_TYPE,TrCore) @@ -124,9 +123,13 @@ void tr_core_add_ctor( TrCore * self, tr_ctor * ctor ); * May pop up dialogs for each torrent if that preference is enabled. * May trigger one or more "error" signals with TR_CORE_ERR_ADD_TORRENT */ -void tr_core_add_list( TrCore * self, - GSList * torrentFiles, - gboolean forcePaused ); +void tr_core_add_list( TrCore * self, + GSList * torrentFiles, + pref_flag_t start, + pref_flag_t prompt ); + +#define tr_core_add_list_defaults(c,l) \ + tr_core_add_list(c,l,PREF_FLAG_DEFAULT,PREF_FLAG_DEFAULT) /** * Add a torrent.