]> granicus.if.org Git - transmission/commitdiff
(trunk gtk) "Priority Selection in `Add' window" -- implemented for GTK+ client
authorCharles Kerr <charles@transmissionbt.com>
Tue, 2 Feb 2010 07:51:45 +0000 (07:51 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Tue, 2 Feb 2010 07:51:45 +0000 (07:51 +0000)
gtk/add-dialog.c
gtk/details.c
gtk/util.c
gtk/util.h

index e6dc2487796a389b6c3b9881c27e4798a93ed41e..f007f5e04d41bddb75c7acfeb254307c86e513cc 100644 (file)
@@ -87,6 +87,7 @@ struct AddData
     GtkWidget *  list;
     GtkWidget *  run_check;
     GtkWidget *  trash_check;
+    GtkWidget *  priority_combo;
     char *       filename;
     char *       downloadDir;
     TrTorrent *  gtor;
@@ -120,8 +121,12 @@ addResponseCB( GtkDialog * dialog,
         }
         else
         {
+            tr_torrent * tor = tr_torrent_handle( data->gtor );
+
+            tr_torrentSetPriority( tor, gtr_priority_combo_get_value( data->priority_combo ) );
+
             if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( data->run_check ) ) )
-                tr_torrentStart( tr_torrent_handle( data->gtor ) );
+                tr_torrentStart( tor );
 
             tr_core_add_torrent( data->core, data->gtor, FALSE );
 
@@ -203,8 +208,7 @@ sourceChanged( GtkFileChooserButton * b,
 }
 
 static void
-verifyRequested( GtkButton * button UNUSED,
-                 gpointer           gdata )
+verifyRequested( GtkButton * button UNUSED, gpointer gdata )
 {
     struct AddData * data = gdata;
 
@@ -253,9 +257,7 @@ addTorrentFilters( GtkFileChooser * chooser )
 ****/
 
 GtkWidget*
-addSingleTorrentDialog( GtkWindow * parent,
-                        TrCore *    core,
-                        tr_ctor *   ctor )
+addSingleTorrentDialog( GtkWindow * parent, TrCore * core, tr_ctor * ctor )
 {
     int              row;
     int              col;
@@ -271,8 +273,7 @@ addSingleTorrentDialog( GtkWindow * parent,
     GSList *         walk;
 
     /* make the dialog */
-    d = gtk_dialog_new_with_buttons( _(
-                                         "Torrent Options" ), parent,
+    d = gtk_dialog_new_with_buttons( _( "Torrent Options" ), parent,
                                      GTK_DIALOG_DESTROY_WITH_PARENT |
                                      GTK_DIALOG_NO_SEPARATOR,
                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
@@ -300,6 +301,9 @@ addSingleTorrentDialog( GtkWindow * parent,
     str = _( "_Start when added" );
     data->run_check = gtk_check_button_new_with_mnemonic( str );
 
+    data->priority_combo = gtr_priority_combo_new( );
+    gtr_priority_combo_set_value( data->priority_combo, TR_PRI_NORMAL );
+
     g_signal_connect( G_OBJECT( d ), "response",
                       G_CALLBACK( addResponseCB ), data );
 
@@ -311,15 +315,12 @@ addSingleTorrentDialog( GtkWindow * parent,
     row = col = 0;
     l = gtk_label_new_with_mnemonic( _( "_Torrent file:" ) );
     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 );
+    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 Source File" ),
                                      GTK_FILE_CHOOSER_ACTION_OPEN );
     source_chooser = w;
-    gtk_table_attach( GTK_TABLE(
-                          t ), w, col, col + 1, row, row + 1, ~0, 0, 0, 0 );
+    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 );
     addTorrentFilters( GTK_FILE_CHOOSER( w ) );
     g_signal_connect( w, "selection-changed",
@@ -329,23 +330,18 @@ addSingleTorrentDialog( GtkWindow * parent,
     col = 0;
     l = gtk_label_new_with_mnemonic( _( "_Destination folder:" ) );
     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 );
+    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 Destination Folder" ),
+    w = gtk_file_chooser_button_new( _( "Select Destination Folder" ),
                                      GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER );
     if( !gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( w ),
                                         data->downloadDir ) )
         g_warning( "couldn't select '%s'", data->downloadDir );
     list = get_recent_destinations( );
     for( walk = list; walk; walk = walk->next )
-        gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER(
-                                                  w ), walk->data, NULL );
+        gtk_file_chooser_add_shortcut_folder( GTK_FILE_CHOOSER( w ), walk->data, NULL );
     g_slist_free( list );
-    gtk_table_attach( GTK_TABLE(
-                          t ), w, col, col + 1, row, row + 1, ~0, 0, 0, 0 );
+    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 );
     g_signal_connect( w, "selection-changed",
                       G_CALLBACK( downloadDirChanged ), data );
@@ -354,16 +350,16 @@ addSingleTorrentDialog( GtkWindow * parent,
     col = 0;
     w = data->list;
     gtk_widget_set_size_request ( w, 466u, 300u );
-    gtk_table_attach_defaults( GTK_TABLE(
-                                   t ), w, col, col + 2, row, row + 1 );
+    gtk_table_attach_defaults( GTK_TABLE( t ), w, col, col + 2, row, row + 1 );
 
     ++row;
     col = 0;
-    w = gtk_button_new_with_mnemonic( _( "_Verify Local Data" ) );
-    gtk_table_attach( GTK_TABLE(
-                          t ), w, col, col + 1, row, row + 1, GTK_FILL, 0,
-                      0, 0 );
-    g_signal_connect( w, "clicked", G_CALLBACK( verifyRequested ), data );
+    w = gtk_label_new_with_mnemonic( _( "Torrent _priority:" ) );
+    gtk_misc_set_alignment( GTK_MISC( w ), 0.0f, 0.5f );
+    gtk_table_attach_defaults( GTK_TABLE( t ), w, col, col + 1, row, row + 1 );
+    ++col;
+    gtk_table_attach_defaults( GTK_TABLE( t ), data->priority_combo, col, col + 1, row, row + 1 );
+    gtk_label_set_mnemonic_widget( GTK_LABEL( w ), data->priority_combo );
 
     ++row;
     col = 0;
@@ -371,9 +367,7 @@ addSingleTorrentDialog( GtkWindow * parent,
     if( tr_ctorGetPaused( ctor, TR_FORCE, &flag ) )
         g_assert_not_reached( );
     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), !flag );
-    gtk_table_attach( GTK_TABLE(
-                          t ), w, col, col + 2, row, row + 1, GTK_FILL, 0,
-                      0, 0 );
+    gtk_table_attach( GTK_TABLE( t ), w, col, col + 2, row, row + 1, GTK_FILL, 0, 0, 0 );
 
     ++row;
     col = 0;
@@ -381,9 +375,11 @@ addSingleTorrentDialog( GtkWindow * parent,
     if( tr_ctorGetDeleteSource( ctor, &flag ) )
         g_assert_not_reached( );
     gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( w ), flag );
-    gtk_table_attach( GTK_TABLE(
-                          t ), w, col, col + 2, row, row + 1, GTK_FILL, 0,
-                      0, 0 );
+    gtk_table_attach( GTK_TABLE( t ), w, col, col + 2, row, row + 1, GTK_FILL, 0, 0, 0 );
+
+    ++row;
+    col = 0;
+    w = data->priority_combo;
 
     /* trigger sourceChanged, either directly or indirectly,
      * so that it creates the tor/gtor objects */
index 731f88e54c6d170f2fa6b1fcb74160012123ab54..146df3e91f35385ac2c372d61824cffea83ecd5d 100644 (file)
@@ -175,35 +175,6 @@ set_double_spin_if_different( GtkWidget * w, guint tag, double value )
     }
 }
 
-static void
-set_int_combo_if_different( GtkWidget * w, guint tag, int column, int value )
-{
-    int i;
-    int currentValue;
-    GtkTreeIter iter;
-    GtkComboBox * combobox = GTK_COMBO_BOX( w );
-    GtkTreeModel * model = gtk_combo_box_get_model( combobox );
-
-    /* do the value and current value match? */
-    if( gtk_combo_box_get_active_iter( combobox, &iter ) ) {
-        gtk_tree_model_get( model, &iter, column, &currentValue, -1 );
-        if( currentValue == value )
-            return;
-    }
-
-    /* find the one to select */
-    i = 0;
-    while(( gtk_tree_model_iter_nth_child( model, &iter, NULL, i++ ))) {
-        gtk_tree_model_get( model, &iter, column, &currentValue, -1 );
-        if( currentValue == value ) {
-            g_signal_handler_block( combobox, tag );
-            gtk_combo_box_set_active_iter( combobox, &iter );
-            g_signal_handler_unblock( combobox, tag );
-            return;
-        }
-    }
-}
-
 static void
 unset_combo( GtkWidget * w, guint tag )
 {
@@ -288,9 +259,11 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n )
         for( i=1; i<n; ++i )
             if( baseline != tr_torrentGetPriority( torrents[i] ) )
                 break;
-        if( i == n )
-            set_int_combo_if_different( di->bandwidthCombo,
-                                        di->bandwidthComboTag, 0, baseline );
+        if( i == n ) {
+            g_signal_handler_block( di->bandwidthCombo, di->bandwidthComboTag );
+            gtr_priority_combo_set_value( di->bandwidthCombo, baseline );
+            g_signal_handler_unblock( di->bandwidthCombo, di->bandwidthComboTag );
+        }
         else
             unset_combo( di->bandwidthCombo, di->bandwidthComboTag );
     }
@@ -447,51 +420,15 @@ max_peers_spun_cb( GtkSpinButton * s, struct DetailsImpl * di )
 static void
 onPriorityChanged( GtkComboBox * w, struct DetailsImpl * di )
 {
-    GtkTreeIter iter;
-
-    if( gtk_combo_box_get_active_iter( w, &iter ) )
-    {
-        int val = 0;
-        gtk_tree_model_get( gtk_combo_box_get_model( w ), &iter, 0, &val, -1 );
-        torrent_set_int( di, "bandwidthPriority", val );
-    }
+    const tr_priority_t priority = gtr_priority_combo_get_value( GTK_WIDGET( w ) );
+    torrent_set_int( di, "bandwidthPriority", priority );
 }
 
 static GtkWidget*
 new_priority_combo( struct DetailsImpl * di )
 {
-    int i;
-    guint tag;
-    GtkWidget * w;
-    GtkCellRenderer * r;
-    GtkListStore * store;
-    const struct {
-        int value;
-        const char * text;
-    } items[] = {
-        { TR_PRI_HIGH,   N_( "High" )  },
-        { TR_PRI_NORMAL, N_( "Normal" ) },
-        { TR_PRI_LOW,    N_( "Low" )  }
-    };
-
-    store = gtk_list_store_new( 2, G_TYPE_INT, G_TYPE_STRING );
-    for( i=0; i<(int)G_N_ELEMENTS(items); ++i ) {
-        GtkTreeIter iter;
-        gtk_list_store_append( store, &iter );
-        gtk_list_store_set( store, &iter, 0, items[i].value,
-                                          1, _( items[i].text ),
-                                         -1 );
-    }
-
-    w = gtk_combo_box_new_with_model( GTK_TREE_MODEL( store ) );
-    r = gtk_cell_renderer_text_new( );
-    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( w ), r, TRUE );
-    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( w ), r, "text", 1, NULL );
-    tag = g_signal_connect( w, "changed", G_CALLBACK( onPriorityChanged ), di );
-    di->bandwidthComboTag = tag;
-
-    /* cleanup */
-    g_object_unref( store );
+    GtkWidget * w = gtr_priority_combo_new( );
+    di->bandwidthComboTag = g_signal_connect( w, "changed", G_CALLBACK( onPriorityChanged ), di );
     return w;
 }
 
index 22717c3f46f6728e4ecb4d69d0446ca3614996c9..db055aa0aca300b71d25d7ace97a0c2cf5ef6ba2 100644 (file)
@@ -626,6 +626,86 @@ gtr_button_new_from_stock( const char * stock,
 ****
 ***/
 
+void
+gtr_priority_combo_set_value( GtkWidget * w, tr_priority_t value )
+{
+    int i;
+    int currentValue;
+    const int column = 0;
+    GtkTreeIter iter;
+    GtkComboBox * combobox = GTK_COMBO_BOX( w );
+    GtkTreeModel * model = gtk_combo_box_get_model( combobox );
+
+    /* do the value and current value match? */
+    if( gtk_combo_box_get_active_iter( combobox, &iter ) ) {
+        gtk_tree_model_get( model, &iter, column, &currentValue, -1 );
+        if( currentValue == value )
+            return;
+    }
+
+    /* find the one to select */
+    i = 0;
+    while(( gtk_tree_model_iter_nth_child( model, &iter, NULL, i++ ))) {
+        gtk_tree_model_get( model, &iter, column, &currentValue, -1 );
+        if( currentValue == value ) {
+            gtk_combo_box_set_active_iter( combobox, &iter );
+            return;
+        }
+    }
+}
+tr_priority_t
+gtr_priority_combo_get_value( GtkWidget * w )
+{
+    int value = 0;
+    GtkTreeIter iter;
+    GtkComboBox * combo_box = GTK_COMBO_BOX( w );
+
+    if( gtk_combo_box_get_active_iter( combo_box, &iter ) )
+        gtk_tree_model_get( gtk_combo_box_get_model( combo_box ), &iter, 0, &value, -1 );
+
+    return value;
+}
+
+GtkWidget *
+gtr_priority_combo_new( void )
+{
+    int i;
+    GtkWidget * w;
+    GtkCellRenderer * r;
+    GtkListStore * store;
+    const struct {
+        int value;
+        const char * text;
+    } items[] = {
+        { TR_PRI_HIGH,   N_( "High" )  },
+        { TR_PRI_NORMAL, N_( "Normal" ) },
+        { TR_PRI_LOW,    N_( "Low" )  }
+    };
+
+    store = gtk_list_store_new( 2, G_TYPE_INT, G_TYPE_STRING );
+    for( i=0; i<(int)G_N_ELEMENTS(items); ++i ) {
+        GtkTreeIter iter;
+        gtk_list_store_append( store, &iter );
+        gtk_list_store_set( store, &iter, 0, items[i].value,
+                                          1, _( items[i].text ),
+                                         -1 );
+    }
+
+    w = gtk_combo_box_new_with_model( GTK_TREE_MODEL( store ) );
+    r = gtk_cell_renderer_text_new( );
+    gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( w ), r, TRUE );
+    gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( w ), r, "text", 1, NULL );
+
+    /* cleanup */
+    g_object_unref( store );
+    return w;
+}
+
+/***
+****
+***/
+
 void
 gtr_widget_set_tooltip_text( GtkWidget * w, const char * tip )
 {
index 637a0002426c419468305c8d359843f11bd83ff1..b08806286c4bc9bd7123e2b5feabd25ac1fd80ab 100644 (file)
@@ -118,6 +118,21 @@ gpointer tr_object_ref_sink( gpointer object );
 GtkWidget * gtr_button_new_from_stock( const char * stock,
                                        const char * mnemonic );
 
+
+/***
+****
+***/
+
+void gtr_priority_combo_set_value( GtkWidget * w, tr_priority_t );
+
+tr_priority_t gtr_priority_combo_get_value( GtkWidget * w );
+
+GtkWidget * gtr_priority_combo_new( void );
+
+/***
+****
+***/
+
 void addTorrentErrorDialog( GtkWidget  * window_or_child,
                             int          err,
                             const char * filename );