From 4acfe5e1b58906d02fdc110b5c356bd2549fcc2b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 19 Oct 2007 23:44:01 +0000 Subject: [PATCH] have gtk+ use the batch form of setFilePriorities(). remove saveFastResumeSoon(). --- gtk/torrent-inspector.c | 64 +++++++++++++++++++++------------- libtransmission/internal.h | 2 -- libtransmission/torrent.c | 43 ++++++++--------------- libtransmission/transmission.h | 8 ++--- 4 files changed, 56 insertions(+), 61 deletions(-) diff --git a/gtk/torrent-inspector.c b/gtk/torrent-inspector.c index 7d63f1448..28a01c335 100644 --- a/gtk/torrent-inspector.c +++ b/gtk/torrent-inspector.c @@ -1198,10 +1198,10 @@ subtree_walk_dnd( GtkTreeStore * store, } static void -set_subtree_dnd( GtkTreeStore * store, - GtkTreeIter * iter, - tr_torrent * tor, - gboolean enabled ) +set_subtree_dnd( GtkTreeStore * store, + GtkTreeIter * iter, + tr_torrent * tor, + gboolean enabled ) { GArray * indices = g_array_new( FALSE, FALSE, sizeof(int) ); subtree_walk_dnd( store, iter, tor, enabled, indices ); @@ -1210,25 +1210,40 @@ set_subtree_dnd( GtkTreeStore * store, } static void -set_priority (GtkTreeSelection * selection, - GtkTreeStore * store, - GtkTreeIter * iter, - tr_torrent * tor, - int priority_val, - const char * priority_str) +subtree_walk_priority( GtkTreeStore * store, + GtkTreeIter * iter, + tr_torrent * tor, + int priority, + GArray * indices ) { int index; GtkTreeIter child; + /* update this node */ gtk_tree_model_get( GTK_TREE_MODEL(store), iter, FC_INDEX, &index, -1 ); - if (index >= 0) - tr_torrentSetFilePriority( tor, index, priority_val ); - gtk_tree_store_set( store, iter, FC_PRIORITY, priority_str, -1 ); + if( index >= 0 ) + g_array_append_val( indices, index ); + gtk_tree_store_set( store, iter, FC_PRIORITY, priorityToString(priority), -1 ); + /* visit the children */ if( gtk_tree_model_iter_children( GTK_TREE_MODEL(store), &child, iter ) ) do - set_priority( selection, store, &child, tor, priority_val, priority_str ); + subtree_walk_priority( store, &child, tor, priority, indices ); while( gtk_tree_model_iter_next( GTK_TREE_MODEL(store), &child ) ); +} + +static void +set_subtree_priority( GtkTreeStore * store, + GtkTreeIter * iter, + tr_torrent * tor, + int priority, + GtkTreeSelection * selection ) +{ + GArray * indices = g_array_new( FALSE, FALSE, sizeof(int) ); + subtree_walk_priority( store, iter, tor, priority, indices ); + tr_torrentSetFilePriorities( tor, (int*)indices->data, (int)indices->len, priority ); + g_array_free( indices, TRUE ); + refreshPriorityActions( selection ); } @@ -1238,14 +1253,14 @@ priority_changed_cb (GtkCellRendererText * cell UNUSED, const gchar * value, void * file_data) { - GtkTreeIter iter; - FileData * d = (FileData*) file_data; - if (gtk_tree_model_get_iter_from_string (d->model, &iter, path)) - { - tr_torrent * tor = tr_torrent_handle( d->gtor ); - const tr_priority_t priority = stringToPriority( value ); - set_priority( d->selection, d->store, &iter, tor, priority, value ); - } + GtkTreeIter iter; + FileData * d = (FileData*) file_data; + if (gtk_tree_model_get_iter_from_string (d->model, &iter, path)) + { + tr_torrent * tor = tr_torrent_handle( d->gtor ); + const tr_priority_t priority = stringToPriority( value ); + set_subtree_priority( d->store, &iter, tor, priority, d->selection ); + } } /* FIXME: NULL this back out when popup goes down */ @@ -1274,14 +1289,13 @@ set_selected_file_priority ( tr_priority_t priority_val ) { GtkTreeView * view = GTK_TREE_VIEW( popupView ); tr_torrent * tor = g_object_get_data (G_OBJECT(view), "torrent-handle"); - const char * priority_str = priorityToString( priority_val ); GtkTreeModel * model; GtkTreeIter iter; GtkTreeSelection * sel = gtk_tree_view_get_selection (view); gtk_tree_selection_get_selected( sel, &model, &iter ); - set_priority( sel, GTK_TREE_STORE(model), &iter, - tor, priority_val, priority_str ); + set_subtree_priority( GTK_TREE_STORE(model), &iter, + tor, priority_val, sel ); } } diff --git a/libtransmission/internal.h b/libtransmission/internal.h index 2f1f12ceb..0ea4f91aa 100644 --- a/libtransmission/internal.h +++ b/libtransmission/internal.h @@ -113,8 +113,6 @@ struct tr_torrent struct tr_ratecontrol * download; struct tr_ratecontrol * swarmspeed; - struct tr_timer * saveTimer; - int error; char errorString[128]; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 7c8e8a5f1..36c5dac58 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -589,22 +589,10 @@ tr_torrentInfo( const tr_torrent * tor ) **** ***/ -static int -saveFastResumeNow( void * vtor ) -{ - tr_torrent * tor = (tr_torrent *) vtor; - tr_fastResumeSave( tor ); - tor->saveTimer = NULL; - return FALSE; -} - static void -saveFastResumeSoon( void * vtor ) +saveFastResumeNow( tr_torrent * tor ) { - tr_torrent * tor = (tr_torrent *) vtor; - - if( tor->saveTimer == NULL ) - tor->saveTimer = tr_timerNew( tor->handle, saveFastResumeNow, tor, 100 ); + tr_fastResumeSave( tor ); } /** @@ -616,7 +604,7 @@ tr_torrentSetFolder( tr_torrent * tor, const char * path ) { tr_free( tor->destination ); tor->destination = tr_strdup( path ); - saveFastResumeSoon( tor ); + saveFastResumeNow( tor ); } const char* @@ -994,7 +982,7 @@ checkAndStartCB( tr_torrent * tor ) *tor->errorString = '\0'; tr_torrentResetTransferStats( tor ); tor->cpStatus = tr_cpGetStatus( tor->completion ); - saveFastResumeSoon( tor ); + saveFastResumeNow( tor ); tor->startDate = tr_date( ); tr_trackerStart( tor->tracker ); tr_peerMgrStartTorrent( tor->handle->peerMgr, tor->info.hash ); @@ -1119,7 +1107,7 @@ tr_torrentRecheckCompleteness( tr_torrent * tor ) tr_trackerCompleted( tor->tracker ); /* tell the tracker */ } tr_ioClose( tor ); - saveFastResumeSoon( tor ); + saveFastResumeNow( tor ); } tr_torrentUnlock( tor ); } @@ -1134,16 +1122,14 @@ tr_torrentIsSeed( const tr_torrent * tor ) *** File priorities **/ -void -tr_torrentSetFilePriority( tr_torrent * tor, - int fileIndex, - tr_priority_t priority ) +static void +setFilePriority( tr_torrent * tor, + int fileIndex, + tr_priority_t priority ) { int i; tr_file * file; - tr_torrentLock( tor ); - assert( tor != NULL ); assert( 0<=fileIndex && fileIndexinfo.fileCount ); assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL || priority==TR_PRI_HIGH ); @@ -1156,10 +1142,6 @@ tr_torrentSetFilePriority( tr_torrent * tor, tr_dbg ( "Setting file #%d (pieces %d-%d) priority to %d (%s)", fileIndex, file->firstPiece, file->lastPiece, priority, tor->info.files[fileIndex].name ); - - saveFastResumeSoon( tor ); - - tr_torrentUnlock( tor ); } void @@ -1169,8 +1151,13 @@ tr_torrentSetFilePriorities( tr_torrent * tor, tr_priority_t priority ) { int i; + tr_torrentLock( tor ); + for( i=0; iinfo.fileCount items, * each holding a value of TR_PRI_NORMAL, _HIGH, or _LOW. free the array when done. */