Changeset 11586


Ignore:
Timestamp:
Dec 23, 2010, 10:31:28 PM (11 years ago)
Author:
charles
Message:

(trunk, gtk) some code cleanup: (1) details dialog handler, (2) selection change handler

Location:
trunk/gtk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/main.c

    r11573 r11586  
    2424
    2525#include <locale.h>
    26 #include <sys/param.h>
    2726#include <signal.h>
    2827#include <string.h>
    2928#include <stdio.h>
    3029#include <stdlib.h>
     30#include <sys/param.h>
    3131#include <time.h>
    3232#include <unistd.h>
     33
     34#include <curl/curl.h>
    3335
    3436#include <gtk/gtk.h>
     
    3638#include <glib/gstdio.h>
    3739
    38 #include <curl/curl.h>
     40#ifdef HAVE_GCONF2
     41 #include <gconf/gconf.h>
     42 #include <gconf/gconf-client.h>
     43#endif
    3944
    4045#include <libtransmission/transmission.h>
     
    8085    gboolean            isClosing;
    8186    guint               timer;
     87    guint               refresh_actions_tag;
    8288    gpointer            icon;
    8389    GtkWindow         * wind;
     
    8591    GtkWidget         * msgwin;
    8692    GtkWidget         * prefs;
    87     GSList            * errqueue;
    88     GSList            * dupqueue;
     93    GSList            * error_list;
     94    GSList            * duplicates_list;
    8995    GSList            * details;
    9096    GtkTreeSelection  * sel;
     
    9298};
    9399
    94 /**
    95 ***
    96 **/
     100/***
     101****
     102****  DETAILS DIALOGS MANAGEMENT
     103****
     104***/
     105
     106static void
     107gtr_window_present( GtkWindow * window )
     108{
     109#if GTK_CHECK_VERSION( 2, 8, 0 )
     110    gtk_window_present_with_time( window, gtk_get_current_event_time( ) );
     111#else
     112    gtk_window_present( window );
     113#endif
     114}
     115
     116/***
     117****
     118****  DETAILS DIALOGS MANAGEMENT
     119****
     120***/
    97121
    98122static int
    99 compareInts( const void * a, const void * b )
     123compare_integers( const void * a, const void * b )
    100124{
    101125    return *(int*)a - *(int*)b;
     
    103127
    104128static char*
    105 getDetailsDialogKey( GSList * id_list )
     129get_details_dialog_key( GSList * id_list )
    106130{
    107131    int i;
     
    117141        ids[i++] = GPOINTER_TO_INT( l->data );
    118142    g_assert( i == n );
    119     qsort( ids, n, sizeof(int), compareInts );
     143    qsort( ids, n, sizeof(int), compare_integers );
    120144
    121145    for( i=0; i<n; ++i )
     
    135159getSelectedTorrentIds( struct cbdata * data )
    136160{
    137     GtkTreeSelection * s;
     161    GList * l;
    138162    GtkTreeModel * model;
    139163    GSList * ids = NULL;
    140164    GList * paths = NULL;
    141     GList * l;
     165    GtkTreeSelection * s = data->sel;
    142166
    143167    /* build a list of the selected torrents' ids */
    144     s = gtr_window_get_selection( data->wind );
    145168    for( paths=l=gtk_tree_selection_get_selected_rows(s,&model); l; l=l->next ) {
    146169        GtkTreeIter iter;
     
    159182
    160183static struct DetailsDialogHandle*
    161 findDetailsDialogFromIds( struct cbdata * cbdata, GSList * ids )
     184find_details_dialog_from_ids( struct cbdata * cbdata, GSList * ids )
    162185{
    163186    GSList * l;
    164187    struct DetailsDialogHandle * ret = NULL;
    165     char * key = getDetailsDialogKey( ids );
     188    char * key = get_details_dialog_key( ids );
    166189
    167190    for( l=cbdata->details; l!=NULL && ret==NULL; l=l->next ) {
     
    176199
    177200static struct DetailsDialogHandle*
    178 findDetailsDialogFromWidget( struct cbdata * cbdata, gpointer w )
     201find_details_dialog_from_widget( struct cbdata * cbdata, gpointer w )
    179202{
    180203    GSList * l;
     
    190213}
    191214
     215static void
     216on_details_dialog_closed( gpointer gdata, GObject * dead )
     217{
     218    struct cbdata * data = gdata;
     219    struct DetailsDialogHandle * h = find_details_dialog_from_widget( data, dead );
     220
     221    if( h != NULL )
     222    {
     223        data->details = g_slist_remove( data->details, h );
     224        g_free( h->key );
     225        g_free( h );
     226    }
     227}
     228
     229static void
     230show_details_dialog_for_selected_torrents( struct cbdata * data )
     231{
     232    GtkWidget * w;
     233    GSList * ids = getSelectedTorrentIds( data );
     234    struct DetailsDialogHandle * h = find_details_dialog_from_ids( data, ids );
     235
     236    if( h != NULL )
     237        w = h->dialog;
     238    else {
     239        h = g_new( struct DetailsDialogHandle, 1 );
     240        h->key = get_details_dialog_key( ids );
     241        h->dialog = w = gtr_torrent_details_dialog_new( data->wind, data->core );
     242        gtr_torrent_details_dialog_set_torrents( w, ids );
     243        data->details = g_slist_append( data->details, h );
     244        g_object_weak_ref( G_OBJECT( w ), on_details_dialog_closed, data );
     245        gtk_widget_show( w );
     246    }
     247    gtr_window_present( GTK_WINDOW( w ) );
     248    g_slist_free( ids );
     249}
     250
     251/****
     252*****
     253*****  ON SELECTION CHANGED
     254*****
     255****/
     256
     257struct counts_data
     258{
     259    int total_count;
     260    int active_count;
     261    int inactive_count;
     262};
     263
     264static void
     265get_selected_torrent_counts_foreach( GtkTreeModel * model, GtkTreePath * path UNUSED,
     266                                     GtkTreeIter * iter, gpointer user_data )
     267{
     268    int activity = 0;
     269    struct counts_data * counts = user_data;
     270
     271    ++counts->total_count;
     272
     273    gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
     274
     275    if( activity == TR_STATUS_STOPPED )
     276        ++counts->inactive_count;
     277    else
     278        ++counts->active_count;
     279}
     280
     281static void
     282get_selected_torrent_counts( struct cbdata * data, struct counts_data * counts )
     283{
     284    counts->active_count = 0;
     285    counts->inactive_count = 0;
     286    counts->total_count = 0;
     287
     288    gtk_tree_selection_selected_foreach( data->sel, get_selected_torrent_counts_foreach, counts );
     289}
     290
     291static void
     292count_updatable_foreach( GtkTreeModel * model, GtkTreePath * path UNUSED,
     293                         GtkTreeIter * iter, gpointer accumulated_status )
     294{
     295    tr_torrent * tor;
     296    gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
     297    *(int*)accumulated_status |= tr_torrentCanManualUpdate( tor );
     298}
     299
     300static gboolean
     301refresh_actions( gpointer gdata )
     302{
     303    int canUpdate;
     304    struct counts_data sel_counts;
     305    struct cbdata * data = gdata;
     306    const size_t total = tr_core_get_torrent_count( data->core );
     307    const size_t active = tr_core_get_active_torrent_count( data->core );
     308    const int torrent_count = gtk_tree_model_iter_n_children( tr_core_model( data->core ), NULL );
     309
     310    gtr_action_set_sensitive( "select-all", torrent_count != 0 );
     311    gtr_action_set_sensitive( "deselect-all", torrent_count != 0 );
     312    gtr_action_set_sensitive( "pause-all-torrents", active != 0 );
     313    gtr_action_set_sensitive( "start-all-torrents", active != total );
     314
     315    get_selected_torrent_counts( data, &sel_counts );
     316    gtr_action_set_sensitive( "pause-torrent", sel_counts.active_count != 0 );
     317    gtr_action_set_sensitive( "start-torrent", sel_counts.inactive_count != 0 );
     318    gtr_action_set_sensitive( "remove-torrent", sel_counts.total_count != 0 );
     319    gtr_action_set_sensitive( "delete-torrent", sel_counts.total_count != 0 );
     320    gtr_action_set_sensitive( "verify-torrent", sel_counts.total_count != 0 );
     321    gtr_action_set_sensitive( "relocate-torrent", sel_counts.total_count != 0 );
     322    gtr_action_set_sensitive( "show-torrent-properties", sel_counts.total_count != 0 );
     323    gtr_action_set_sensitive( "open-torrent-folder", sel_counts.total_count == 1 );
     324    gtr_action_set_sensitive( "copy-magnet-link-to-clipboard", sel_counts.total_count == 1 );
     325
     326    canUpdate = 0;
     327    gtk_tree_selection_selected_foreach( data->sel, count_updatable_foreach, &canUpdate );
     328    gtr_action_set_sensitive( "update-tracker", canUpdate != 0 );
     329
     330    data->refresh_actions_tag = 0;
     331    return FALSE;
     332}
     333
     334static void
     335on_selection_changed( GtkTreeSelection * s UNUSED, gpointer gdata )
     336{
     337    struct cbdata * data = gdata;
     338
     339    if( data->refresh_actions_tag == 0 )
     340        data->refresh_actions_tag = gtr_idle_add( refresh_actions, data );
     341}
     342
    192343/***
     344****
    193345****
    194346***/
     
    204356static void wannaquit( gpointer vdata );
    205357
    206 static void coreerr( TrCore *, guint, const char *, struct cbdata * );
    207 
    208 static void onAddTorrent( TrCore *, tr_ctor *, gpointer );
    209 
    210 static void prefschanged( TrCore * core, const char * key, gpointer );
     358static void on_core_error( TrCore *, guint, const char *, struct cbdata * );
     359
     360static void on_add_torrent( TrCore *, tr_ctor *, gpointer );
     361
     362static void on_prefs_changed( TrCore * core, const char * key, gpointer );
    211363
    212364static gboolean updatemodel( gpointer gdata );
     
    215367****
    216368***/
    217 
    218 #ifdef HAVE_GCONF2
    219  #include <gconf/gconf.h>
    220  #include <gconf/gconf-client.h>
    221 #endif
    222369
    223370static void
     
    251398    }
    252399#endif
    253 }
    254 
    255 /***
    256 ****
    257 ***/
    258 
    259 struct counts_data
    260 {
    261     int    totalCount;
    262     int    activeCount;
    263     int    inactiveCount;
    264 };
    265 
    266 static void
    267 accumulateStatusForeach( GtkTreeModel *      model,
    268                          GtkTreePath  * path UNUSED,
    269                          GtkTreeIter *       iter,
    270                          gpointer            user_data )
    271 {
    272     int activity = 0;
    273     struct counts_data * counts = user_data;
    274 
    275     ++counts->totalCount;
    276 
    277     gtk_tree_model_get( model, iter, MC_ACTIVITY, &activity, -1 );
    278 
    279     if( activity == TR_STATUS_STOPPED )
    280         ++counts->inactiveCount;
    281     else
    282         ++counts->activeCount;
    283 }
    284 
    285 static void
    286 getTorrentCounts( struct cbdata * data, struct counts_data * counts )
    287 {
    288     counts->activeCount = 0;
    289     counts->inactiveCount = 0;
    290     counts->totalCount = 0;
    291 
    292     gtk_tree_selection_selected_foreach( data->sel, accumulateStatusForeach, counts );
    293 }
    294 
    295 static void
    296 accumulateCanUpdateForeach( GtkTreeModel *      model,
    297                             GtkTreePath  * path UNUSED,
    298                             GtkTreeIter *       iter,
    299                             gpointer            accumulated_status )
    300 {
    301     tr_torrent * tor;
    302     gtk_tree_model_get( model, iter, MC_TORRENT_RAW, &tor, -1 );
    303     *(int*)accumulated_status |= tr_torrentCanManualUpdate( tor );
    304 }
    305 
    306 static gboolean
    307 refreshActions( gpointer gdata )
    308 {
    309     int canUpdate;
    310     struct counts_data counts;
    311     struct cbdata * data = gdata;
    312 
    313     getTorrentCounts( data, &counts );
    314     gtr_action_set_sensitive( "pause-torrent", counts.activeCount != 0 );
    315     gtr_action_set_sensitive( "start-torrent", counts.inactiveCount != 0 );
    316     gtr_action_set_sensitive( "remove-torrent", counts.totalCount != 0 );
    317     gtr_action_set_sensitive( "delete-torrent", counts.totalCount != 0 );
    318     gtr_action_set_sensitive( "verify-torrent", counts.totalCount != 0 );
    319     gtr_action_set_sensitive( "relocate-torrent", counts.totalCount != 0 );
    320     gtr_action_set_sensitive( "show-torrent-properties", counts.totalCount != 0 );
    321     gtr_action_set_sensitive( "open-torrent-folder", counts.totalCount == 1 );
    322     gtr_action_set_sensitive( "copy-magnet-link-to-clipboard", counts.totalCount == 1 );
    323 
    324     canUpdate = 0;
    325     gtk_tree_selection_selected_foreach( data->sel, accumulateCanUpdateForeach, &canUpdate );
    326     gtr_action_set_sensitive( "update-tracker", canUpdate != 0 );
    327 
    328     {
    329         GtkTreeView * view = gtk_tree_selection_get_tree_view( data->sel );
    330         GtkTreeModel * model = gtk_tree_view_get_model( view );
    331         const int torrentCount = gtk_tree_model_iter_n_children( model, NULL ) != 0;
    332         gtr_action_set_sensitive( "select-all", torrentCount != 0 );
    333         gtr_action_set_sensitive( "deselect-all", torrentCount != 0 );
    334     }
    335 
    336     {
    337         const size_t total = tr_core_get_torrent_count( data->core );
    338         const size_t active = tr_core_get_active_torrent_count( data->core );
    339         gtr_action_set_sensitive( "pause-all-torrents", active != 0 );
    340         gtr_action_set_sensitive( "start-all-torrents", active != total );
    341     }
    342 
    343     return FALSE;
    344 }
    345 
    346 static void
    347 selectionChangedCB( GtkTreeSelection * s UNUSED, gpointer data )
    348 {
    349     gtr_idle_add( refreshActions, data );
    350400}
    351401
     
    475525
    476526            for( l=changed_keys; l!=NULL; l=l->next )
    477                 prefschanged( cbdata->core, key, cbdata );
     527                on_prefs_changed( cbdata->core, key, cbdata );
    478528
    479529            g_slist_free( changed_keys );
     
    833883
    834884static void
    835 onCoreBusy( TrCore * core UNUSED, gboolean busy, struct cbdata * c )
     885on_core_busy( TrCore * core UNUSED, gboolean busy, struct cbdata * c )
    836886{
    837887    gtr_window_set_busy( c->wind, busy );
     
    839889
    840890static void
    841 appsetup( TrWindow *      wind,
    842           GSList *        torrentFiles,
     891appsetup( TrWindow      * wind,
     892          GSList        * torrentFiles,
    843893          struct cbdata * cbdata,
    844894          gboolean        forcepause,
     
    849899    const gboolean doNotify = TRUE;
    850900
    851     /* fill out cbdata */
    852     cbdata->wind         = NULL;
    853     cbdata->icon         = NULL;
    854     cbdata->msgwin       = NULL;
    855     cbdata->prefs        = NULL;
    856     cbdata->timer        = 0;
    857     cbdata->isClosing    = 0;
    858     cbdata->errqueue     = NULL;
    859     cbdata->dupqueue     = NULL;
    860901    cbdata->isIconified  = isIconified;
    861902
     
    866907
    867908    /* set up core handlers */
    868     g_signal_connect( cbdata->core, "busy", G_CALLBACK( onCoreBusy ), cbdata );
    869     g_signal_connect( cbdata->core, "add-error", G_CALLBACK( coreerr ), cbdata );
    870     g_signal_connect( cbdata->core, "add-prompt", G_CALLBACK( onAddTorrent ), cbdata );
    871     g_signal_connect( cbdata->core, "prefs-changed", G_CALLBACK( prefschanged ), cbdata );
    872     g_signal_connect_swapped( cbdata->core, "quit", G_CALLBACK( wannaquit ), cbdata );
     909    g_signal_connect( cbdata->core, "busy", G_CALLBACK( on_core_busy ), cbdata );
     910    g_signal_connect( cbdata->core, "add-error", G_CALLBACK( on_core_error ), cbdata );
     911    g_signal_connect( cbdata->core, "add-prompt", G_CALLBACK( on_add_torrent ), cbdata );
     912    g_signal_connect( cbdata->core, "prefs-changed", G_CALLBACK( on_prefs_changed ), cbdata );
    873913
    874914    /* add torrents from command-line and saved state */
     
    882922
    883923    /* set up the icon */
    884     prefschanged( cbdata->core, PREF_KEY_SHOW_TRAY_ICON, cbdata );
     924    on_prefs_changed( cbdata->core, PREF_KEY_SHOW_TRAY_ICON, cbdata );
    885925
    886926    /* start model update timer */
     
    923963
    924964static void
    925 tr_window_present( GtkWindow * window )
    926 {
    927 #if GTK_CHECK_VERSION( 2, 8, 0 )
    928     gtk_window_present_with_time( window, gtk_get_current_event_time( ) );
    929 #else
    930     gtk_window_present( window );
    931 #endif
    932 }
    933 
    934 static void
    935965toggleMainWindow( struct cbdata * cbdata )
    936966{
     
    946976        gtk_window_move( window, x, y );
    947977        gtr_widget_set_visible( GTK_WIDGET( window ), TRUE );
    948         tr_window_present( window );
     978        gtr_window_present( window );
    949979    }
    950980    else
     
    9741004            g_object_add_weak_pointer( G_OBJECT( cbdata->quit_dialog ), &cbdata->quit_dialog );
    9751005        }
    976         gtk_window_present( GTK_WINDOW( cbdata->quit_dialog ) );
     1006        gtr_window_present( GTK_WINDOW( cbdata->quit_dialog ) );
    9771007    }
    9781008}
     
    10011031    struct cbdata * data = gdata;
    10021032    if( gtk_tree_selection_path_is_selected ( data->sel, path ) )
    1003         refreshActions( gdata );
     1033        refresh_actions( gdata );
    10041034}
    10051035
     
    10591089    cbdata->sel = sel = GTK_TREE_SELECTION( gtr_window_get_selection( cbdata->wind ) );
    10601090
    1061     g_signal_connect( sel, "changed", G_CALLBACK( selectionChangedCB ), cbdata );
    1062     selectionChangedCB( sel, cbdata );
     1091    g_signal_connect( sel, "changed", G_CALLBACK( on_selection_changed ), cbdata );
     1092    on_selection_changed( sel, cbdata );
    10631093    model = tr_core_model( cbdata->core );
    10641094    g_signal_connect( model, "row-changed", G_CALLBACK( rowChangedCB ), cbdata );
    10651095    g_signal_connect( wind, "delete-event", G_CALLBACK( winclose ), cbdata );
    1066     refreshActions( cbdata );
     1096    refresh_actions( cbdata );
    10671097
    10681098    /* register to handle URIs that get dragged onto our main window */
     
    10911121    if( cbdata->icon )
    10921122        g_object_unref( cbdata->icon );
    1093     if( cbdata->errqueue ) {
    1094         g_slist_foreach( cbdata->errqueue, (GFunc)g_free, NULL );
    1095         g_slist_free( cbdata->errqueue );
    1096     }
    1097     if( cbdata->dupqueue ) {
    1098         g_slist_foreach( cbdata->dupqueue, (GFunc)g_free, NULL );
    1099         g_slist_free( cbdata->dupqueue );
    1100     }
     1123    g_slist_foreach( cbdata->error_list, (GFunc)g_free, NULL );
     1124    g_slist_free( cbdata->error_list );
     1125    g_slist_foreach( cbdata->duplicates_list, (GFunc)g_free, NULL );
     1126    g_slist_free( cbdata->duplicates_list );
    11011127    g_free( cbdata );
    11021128
     
    11861212
    11871213static void
    1188 flushAddTorrentErrors( GtkWindow * window, const char * primary, GSList ** files )
     1214show_torrent_errors( GtkWindow * window, const char * primary, GSList ** files )
    11891215{
    11901216    GSList * l;
     
    12161242
    12171243static void
    1218 showTorrentErrors( struct cbdata * cbdata )
    1219 {
    1220     if( cbdata->errqueue )
    1221         flushAddTorrentErrors( cbdata->wind,
    1222                                gtr_ngettext( "Couldn't add corrupt torrent",
    1223                                              "Couldn't add corrupt torrents",
    1224                                              g_slist_length( cbdata->errqueue ) ),
    1225                                &cbdata->errqueue );
    1226 
    1227     if( cbdata->dupqueue )
    1228         flushAddTorrentErrors( cbdata->wind,
    1229                                gtr_ngettext( "Couldn't add duplicate torrent",
    1230                                              "Couldn't add duplicate torrents",
    1231                                              g_slist_length( cbdata->dupqueue ) ),
    1232                                &cbdata->dupqueue );
    1233 }
    1234 
    1235 static void
    1236 coreerr( TrCore * core UNUSED, guint code, const char * msg, struct cbdata * c )
     1244flush_torrent_errors( struct cbdata * cbdata )
     1245{
     1246    if( cbdata->error_list )
     1247        show_torrent_errors( cbdata->wind,
     1248                              gtr_ngettext( "Couldn't add corrupt torrent",
     1249                                            "Couldn't add corrupt torrents",
     1250                                            g_slist_length( cbdata->error_list ) ),
     1251                              &cbdata->error_list );
     1252
     1253    if( cbdata->duplicates_list )
     1254        show_torrent_errors( cbdata->wind,
     1255                              gtr_ngettext( "Couldn't add duplicate torrent",
     1256                                            "Couldn't add duplicate torrents",
     1257                                            g_slist_length( cbdata->duplicates_list ) ),
     1258                              &cbdata->duplicates_list );
     1259}
     1260
     1261static void
     1262on_core_error( TrCore * core UNUSED, guint code, const char * msg, struct cbdata * c )
    12371263{
    12381264    switch( code )
    12391265    {
    12401266        case TR_PARSE_ERR:
    1241             c->errqueue =
    1242                 g_slist_append( c->errqueue, g_path_get_basename( msg ) );
     1267            c->error_list =
     1268                g_slist_append( c->error_list, g_path_get_basename( msg ) );
    12431269            break;
    12441270
    12451271        case TR_PARSE_DUPLICATE:
    1246             c->dupqueue = g_slist_append( c->dupqueue, g_strdup( msg ) );
     1272            c->duplicates_list = g_slist_append( c->duplicates_list, g_strdup( msg ) );
    12471273            break;
    12481274
    12491275        case TR_CORE_ERR_NO_MORE_TORRENTS:
    1250             showTorrentErrors( c );
     1276            flush_torrent_errors( c );
    12511277            break;
    12521278
     
    12721298
    12731299static void
    1274 onAddTorrent( TrCore * core, tr_ctor * ctor, gpointer gdata )
     1300on_add_torrent( TrCore * core, tr_ctor * ctor, gpointer gdata )
    12751301{
    12761302    struct cbdata * cbdata = gdata;
     
    12881314
    12891315static void
    1290 prefschanged( TrCore * core UNUSED, const char * key, gpointer data )
     1316on_prefs_changed( TrCore * core UNUSED, const char * key, gpointer data )
    12911317{
    12921318    struct cbdata * cbdata = data;
     
    14831509
    14841510        /* update the actions */
    1485         refreshActions( data );
     1511        refresh_actions( data );
    14861512
    14871513        /* update the status tray icon */
     
    15491575    tr_benc top, *args, *ids;
    15501576    gboolean invoked = FALSE;
     1577    GtkTreeSelection * s = data->sel;
    15511578    tr_session * session = tr_core_session( data->core );
    1552     GtkTreeSelection * s = gtr_window_get_selection( data->wind );
    15531579
    15541580    tr_bencInitDict( &top, 2 );
     
    15721598
    15731599static void
    1574 openFolderForeach( GtkTreeModel *           model,
    1575                    GtkTreePath  * path      UNUSED,
    1576                    GtkTreeIter *            iter,
    1577                    gpointer       user_data UNUSED )
     1600openFolderForeach( GtkTreeModel * model, GtkTreePath * path UNUSED,
     1601                   GtkTreeIter * iter, gpointer user_data UNUSED )
    15781602{
    15791603    TrTorrent * gtor = NULL;
     
    15921616
    15931617static void
    1594 accumulateSelectedTorrents( GtkTreeModel * model,
    1595                             GtkTreePath  * path UNUSED,
    1596                             GtkTreeIter  * iter,
    1597                             gpointer       gdata )
     1618accumulateSelectedTorrents( GtkTreeModel * model, GtkTreePath * path UNUSED,
     1619                            GtkTreeIter * iter, gpointer gdata )
    15981620{
    15991621    GSList ** data = ( GSList** ) gdata;
     
    16011623
    16021624    gtk_tree_model_get( model, iter, MC_TORRENT, &gtor, -1 );
    1603     *data = g_slist_prepend( *data, gtor );
     1625    *data = g_slist_append( *data, gtor );
    16041626    g_object_unref( G_OBJECT( gtor ) );
    16051627}
     
    16091631{
    16101632    GSList * l = NULL;
    1611     GtkTreeSelection * s = gtr_window_get_selection( data->wind );
    1612 
    1613     gtk_tree_selection_selected_foreach( s, accumulateSelectedTorrents, &l );
    1614 
    1615     if( l != NULL ) {
    1616         l = g_slist_reverse( l );
     1633
     1634    gtk_tree_selection_selected_foreach( data->sel, accumulateSelectedTorrents, &l );
     1635
     1636    if( l != NULL )
    16171637        gtr_confirm_remove( data->wind, data->core, l, delete_files );
    1618     }
    16191638}
    16201639
     
    16391658{
    16401659    tr_torrent * tor = NULL;
    1641     GtkTreeSelection * s = gtr_window_get_selection( data->wind );
    16421660    GtkTreeModel * m;
    1643     GList * l = gtk_tree_selection_get_selected_rows( s, &m );
     1661    GList * l = gtk_tree_selection_get_selected_rows( data->sel, &m );
    16441662    if( l != NULL ) {
    16451663        GtkTreePath * p = l->data;
     
    16511669    g_list_free( l );
    16521670    return tor;
    1653 }
    1654 
    1655 static void
    1656 detailsClosed( gpointer gdata, GObject * dead )
    1657 {
    1658     struct cbdata * data = gdata;
    1659     struct DetailsDialogHandle * h = findDetailsDialogFromWidget( data, dead );
    1660 
    1661     if( h != NULL )
    1662     {
    1663         data->details = g_slist_remove( data->details, h );
    1664         g_free( h->key );
    1665         g_free( h );
    1666     }
    16671671}
    16681672
     
    17591763    else if( !strcmp( action_name, "open-torrent-folder" ) )
    17601764    {
    1761         GtkTreeSelection * s = gtr_window_get_selection( data->wind );
    1762         gtk_tree_selection_selected_foreach( s, openFolderForeach, data );
     1765        gtk_tree_selection_selected_foreach( data->sel, openFolderForeach, data );
    17631766    }
    17641767    else if( !strcmp( action_name, "show-torrent-properties" ) )
    17651768    {
    1766         GtkWidget * w;
    1767         GSList * ids = getSelectedTorrentIds( data );
    1768         struct DetailsDialogHandle * h = findDetailsDialogFromIds( data, ids );
    1769         if( h != NULL )
    1770             w = h->dialog;
    1771         else {
    1772             h = g_new( struct DetailsDialogHandle, 1 );
    1773             h->key = getDetailsDialogKey( ids );
    1774             h->dialog = w = gtr_torrent_details_dialog_new( data->wind, data->core );
    1775             gtr_torrent_details_dialog_set_torrents( w, ids );
    1776             data->details = g_slist_append( data->details, h );
    1777             g_object_weak_ref( G_OBJECT( w ), detailsClosed, data );
    1778             gtk_widget_show( w );
    1779         }
    1780         gtk_window_present( GTK_WINDOW( w ) );
    1781         g_slist_free( ids );
     1769        show_details_dialog_for_selected_torrents( data );
    17821770    }
    17831771    else if( !strcmp( action_name, "new-torrent" ) )
     
    18001788    else if( !strcmp( action_name, "select-all" ) )
    18011789    {
    1802         GtkTreeSelection * s = gtr_window_get_selection( data->wind );
    1803         gtk_tree_selection_select_all( s );
     1790        gtk_tree_selection_select_all( data->sel );
    18041791    }
    18051792    else if( !strcmp( action_name, "deselect-all" ) )
    18061793    {
    1807         GtkTreeSelection * s = gtr_window_get_selection( data->wind );
    1808         gtk_tree_selection_unselect_all( s );
     1794        gtk_tree_selection_unselect_all( data->sel );
    18091795    }
    18101796    else if( !strcmp( action_name, "edit-preferences" ) )
  • trunk/gtk/util.c

    r11573 r11586  
    820820#endif
    821821
    822 void
     822guint
    823823gtr_idle_add( GSourceFunc function, gpointer data )
    824824{
    825825#if GTK_CHECK_VERSION( 2,12,0 )
    826     gdk_threads_add_idle( function, data );
    827 #else
    828     g_idle_add_full( G_PRIORITY_DEFAULT,
    829                      gtr_thread_func,
    830                      gtr_func_data_new( function, data ),
    831                      gtr_func_data_free );
     826    return gdk_threads_add_idle( function, data );
     827#else
     828    return g_idle_add_full( G_PRIORITY_DEFAULT,
     829                            gtr_thread_func,
     830                            gtr_func_data_new( function, data ),
     831                            gtr_func_data_free );
    832832#endif
    833833}
  • trunk/gtk/util.h

    r11573 r11586  
    132132
    133133/* backwards-compatible wrapper around gdk_threads_add_idle() */
    134 void gtr_idle_add( GSourceFunc  func, gpointer data );
     134guint gtr_idle_add( GSourceFunc  func, gpointer data );
    135135
    136136/* backwards-compatible wrapper around gtk_widget_set_tooltip_text() */
Note: See TracChangeset for help on using the changeset viewer.