]> granicus.if.org Git - transmission/commitdiff
add an RPC session callback for when queue order changes
authorMitchell Livingston <livings124@transmissionbt.com>
Sat, 27 Aug 2011 23:54:10 +0000 (23:54 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sat, 27 Aug 2011 23:54:10 +0000 (23:54 +0000)
libtransmission/rpcimpl.c
libtransmission/transmission.h
macosx/Controller.h
macosx/Controller.m
macosx/Torrent.m

index 6f302f652fdb2e9029f7afd692c1e7bd8aeb46c6..16ef3f7d90feb4778fbdafe0debffb4ee472ab11 100644 (file)
@@ -187,11 +187,12 @@ getTorrents( tr_session * session,
 }
 
 static void
-notifyBatchChange( tr_session * session, tr_torrent ** torrents, int n )
+notifyBatchQueueChange( tr_session * session, tr_torrent ** torrents, int n )
 {
     int i;
     for( i=0; i<n; ++i )
         notify( session, TR_RPC_TORRENT_CHANGED, torrents[i] );
+    notify( session, TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED, NULL );
 }
 
 static const char*
@@ -203,7 +204,7 @@ queueMoveTop( tr_session               * session,
     int n;
     tr_torrent ** torrents = getTorrents( session, args_in, &n );
     tr_torrentsQueueMoveTop( torrents, n );
-    notifyBatchChange( session, torrents, n );
+    notifyBatchQueueChange( session, torrents, n );
     tr_free( torrents );
     return NULL;
 }
@@ -217,7 +218,7 @@ queueMoveUp( tr_session               * session,
     int n;
     tr_torrent ** torrents = getTorrents( session, args_in, &n );
     tr_torrentsQueueMoveUp( torrents, n );
-    notifyBatchChange( session, torrents, n );
+    notifyBatchQueueChange( session, torrents, n );
     tr_free( torrents );
     return NULL;
 }
@@ -231,7 +232,7 @@ queueMoveDown( tr_session               * session,
     int n;
     tr_torrent ** torrents = getTorrents( session, args_in, &n );
     tr_torrentsQueueMoveDown( torrents, n );
-    notifyBatchChange( session, torrents, n );
+    notifyBatchQueueChange( session, torrents, n );
     tr_free( torrents );
     return NULL;
 }
@@ -245,7 +246,7 @@ queueMoveBottom( tr_session               * session,
     int n;
     tr_torrent ** torrents = getTorrents( session, args_in, &n );
     tr_torrentsQueueMoveBottom( torrents, n );
-    notifyBatchChange( session, torrents, n );
+    notifyBatchQueueChange( session, torrents, n );
     tr_free( torrents );
     return NULL;
 }
index 6e764d9285b0556100c2083a2ede54d493fc9545..4ccfcc177d6ac2936aafd1f3c384e48d79cb8835 100644 (file)
@@ -517,6 +517,7 @@ typedef enum
     TR_RPC_TORRENT_CHANGED, /* catch-all for the "torrent-set" rpc method */
     TR_RPC_TORRENT_MOVED,
     TR_RPC_SESSION_CHANGED,
+    TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED, /* catch potentially multiple torrents being moved in the queue */
     TR_RPC_SESSION_CLOSE
 }
 tr_rpc_callback_type;
index 5a7770b9a9414bd1e903fe5c36eb097d5f10214c..b9f762a35f0f8e2cc7b83b1209c26543a3492b61 100644 (file)
@@ -261,5 +261,6 @@ typedef enum
 - (void) rpcStartedStoppedTorrent: (Torrent *) torrent;
 - (void) rpcChangedTorrent: (Torrent *) torrent;
 - (void) rpcMovedTorrent: (Torrent *) torrent;
+- (void) rpcUpdateQueue;
 
 @end
index e054e6e4a5ada74b5b50c5a4503cb44f97bd78b1..bafb81eb3089b036f434e1f2f8761d5d96a93de7 100644 (file)
@@ -4143,6 +4143,10 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
             [self performSelectorOnMainThread: @selector(rpcMovedTorrent:) withObject: torrent waitUntilDone: NO];
             break;
         
+        case TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED:
+            [self performSelectorOnMainThread: @selector(rpcUpdateQueue) withObject: nil waitUntilDone: NO];
+            break;
+        
         case TR_RPC_SESSION_CHANGED:
             [fPrefsController performSelectorOnMainThread: @selector(rpcUpdatePrefs) withObject: nil waitUntilDone: NO];
             break;
@@ -4224,4 +4228,20 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
     [torrent release];
 }
 
+- (void) rpcUpdateQueue
+{
+    NSLog(@"rpcUpdateQueue");
+    
+    for (Torrent * torrent in fTorrents)
+        [torrent update];
+    
+    NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey: @"queuePosition" ascending: YES];
+    NSArray * descriptors = [NSArray arrayWithObject: descriptor];
+    [descriptor release];
+    
+    [fTorrents sortUsingDescriptors: descriptors];
+    
+    [self fullUpdateUI];
+}
+
 @end
index 5eb33923867868e80f2a212fca63b2afd9a1ac13..dbad0a16116f8cee55e6b01dbb94c8a63c1ba19a 100644 (file)
@@ -346,7 +346,6 @@ int trashDataFile(const char * filename)
     }
 }
 
-#warning remove
 - (NSInteger) queuePosition
 {
     return fStat->queuePosition;