add an RPC session callback for when queue order changes

This commit is contained in:
Mitchell Livingston 2011-08-27 23:54:10 +00:00
parent f2f0dc1861
commit 516164e78e
5 changed files with 28 additions and 6 deletions

View 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;
}

View 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;

View File

@ -261,5 +261,6 @@ typedef enum
- (void) rpcStartedStoppedTorrent: (Torrent *) torrent;
- (void) rpcChangedTorrent: (Torrent *) torrent;
- (void) rpcMovedTorrent: (Torrent *) torrent;
- (void) rpcUpdateQueue;
@end

View 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

View File

@ -346,7 +346,6 @@ int trashDataFile(const char * filename)
}
}
#warning remove
- (NSInteger) queuePosition
{
return fStat->queuePosition;