The quit dialog now displays the number of active torrents
Disables idle sleep if at least one torrent is active Cosmetic changes
This commit is contained in:
parent
e5949bf6e2
commit
0ed06f109d
|
@ -33,7 +33,7 @@
|
||||||
@interface Controller : NSObject
|
@interface Controller : NSObject
|
||||||
{
|
{
|
||||||
tr_handle_t * fHandle;
|
tr_handle_t * fHandle;
|
||||||
int fCount, fCompleted;
|
int fCount, fSeeding, fDownloading, fCompleted;
|
||||||
tr_stat_t * fStat;
|
tr_stat_t * fStat;
|
||||||
int fResumeOnWake[TR_MAX_TORRENT_COUNT];
|
int fResumeOnWake[TR_MAX_TORRENT_COUNT];
|
||||||
|
|
||||||
|
|
|
@ -136,11 +136,14 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
|
|
||||||
//initialize badging
|
//initialize badging
|
||||||
fBadger = [[Badger alloc] init];
|
fBadger = [[Badger alloc] init];
|
||||||
fCompleted = 0;
|
|
||||||
|
|
||||||
//update the interface every 500 ms
|
//update the interface every 500 ms
|
||||||
fCount = 0;
|
fCount = 0;
|
||||||
fStat = NULL;
|
fDownloading = 0;
|
||||||
|
fSeeding = 0;
|
||||||
|
fCompleted = 0;
|
||||||
|
|
||||||
|
fStat = nil;
|
||||||
fTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self
|
fTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self
|
||||||
selector: @selector( updateUI: ) userInfo: NULL repeats: YES];
|
selector: @selector( updateUI: ) userInfo: NULL repeats: YES];
|
||||||
[[NSRunLoop currentRunLoop] addTimer: fTimer
|
[[NSRunLoop currentRunLoop] addTimer: fTimer
|
||||||
|
@ -173,23 +176,21 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
|
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
|
||||||
{
|
{
|
||||||
if ([[fDefaults stringForKey: @"CheckQuit"] isEqualToString:@"YES"])
|
int active = fDownloading + fSeeding;
|
||||||
|
if (active > 0 && [[NSUserDefaults standardUserDefaults] boolForKey: @"CheckQuit"])
|
||||||
{
|
{
|
||||||
int i;
|
NSString * message = active == 1
|
||||||
for( i = 0; i < fCount; i++ )
|
? @"There is an active torrent. Do you really want to quit?"
|
||||||
{
|
: [NSString stringWithFormat:
|
||||||
if( fStat[i].status & ( TR_STATUS_CHECK |
|
@"There are %d active torrents. Do you really want to quit?", fDownloading];
|
||||||
TR_STATUS_DOWNLOAD ) )
|
|
||||||
{
|
NSBeginAlertSheet(@"Confirm Quit",
|
||||||
NSBeginAlertSheet(@"Confirm Quit",
|
@"Quit", @"Cancel", nil,
|
||||||
@"Quit", @"Cancel", nil,
|
fWindow, self,
|
||||||
fWindow, self,
|
@selector(quitSheetDidEnd:returnCode:contextInfo:),
|
||||||
@selector(quitSheetDidEnd:returnCode:contextInfo:),
|
nil, nil, message);
|
||||||
NULL, NULL, @"There are active torrents. Do you really want to quit?");
|
return NSTerminateLater;
|
||||||
return NSTerminateLater;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[self quitProcedure];
|
[self quitProcedure];
|
||||||
return NSTerminateNow;
|
return NSTerminateNow;
|
||||||
|
@ -453,9 +454,9 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
deleteData: (BOOL) deleteData
|
deleteData: (BOOL) deleteData
|
||||||
{
|
{
|
||||||
if ( fStat[idx].status & ( TR_STATUS_CHECK
|
if ( fStat[idx].status & ( TR_STATUS_CHECK
|
||||||
| TR_STATUS_DOWNLOAD) )
|
| TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
|
||||||
{
|
{
|
||||||
if ([[fDefaults stringForKey: @"CheckRemove"] isEqualToString:@"YES"])
|
if ([fDefaults boolForKey: @"CheckRemove"])
|
||||||
{
|
{
|
||||||
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
[NSString stringWithFormat: @"%d", idx], @"Index",
|
[NSString stringWithFormat: @"%d", idx], @"Index",
|
||||||
|
@ -563,6 +564,8 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
free(fStat);
|
free(fStat);
|
||||||
|
|
||||||
fCount = tr_torrentStat( fHandle, &fStat );
|
fCount = tr_torrentStat( fHandle, &fStat );
|
||||||
|
fDownloading = 0;
|
||||||
|
fSeeding = 0;
|
||||||
[fTableView updateUI: fStat];
|
[fTableView updateUI: fStat];
|
||||||
|
|
||||||
//Update the global DL/UL rates
|
//Update the global DL/UL rates
|
||||||
|
@ -585,6 +588,11 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
//check if torrents have recently ended.
|
//check if torrents have recently ended.
|
||||||
for (i = 0; i < fCount; i++)
|
for (i = 0; i < fCount; i++)
|
||||||
{
|
{
|
||||||
|
if (fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD))
|
||||||
|
fDownloading++;
|
||||||
|
else if (fStat[i].status & TR_STATUS_SEED)
|
||||||
|
fSeeding++;
|
||||||
|
|
||||||
if( !tr_getFinished( fHandle, i ) )
|
if( !tr_getFinished( fHandle, i ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -798,49 +806,61 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
|
|
||||||
- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem
|
- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem
|
||||||
{
|
{
|
||||||
|
SEL action = [toolbarItem action];
|
||||||
|
|
||||||
//enable remove item
|
//enable remove item
|
||||||
if ([toolbarItem action] == @selector(removeTorrent:))
|
if (action == @selector(removeTorrent:))
|
||||||
return [fTableView selectedRow] >= 0;
|
return [fTableView selectedRow] >= 0;
|
||||||
|
|
||||||
//enable pause all and resume all items
|
|
||||||
if ([toolbarItem action] == @selector(stopAllTorrents:)
|
//enable resume all item
|
||||||
|| [toolbarItem action] == @selector(resumeAllTorrents:))
|
if (action == @selector(resumeAllTorrents:))
|
||||||
return fCount > 0;
|
return fCount > fDownloading + fSeeding;
|
||||||
|
|
||||||
|
//enable pause all item
|
||||||
|
if (action == @selector(stopAllTorrents:))
|
||||||
|
return fDownloading > 0 || fSeeding > 0;
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
|
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
|
||||||
{
|
{
|
||||||
|
SEL action = [menuItem action];
|
||||||
|
|
||||||
//disable menus if customize sheet is active
|
//disable menus if customize sheet is active
|
||||||
if ([fToolbar customizationPaletteIsRunning])
|
if ([fToolbar customizationPaletteIsRunning])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
//enable customize toolbar item
|
//enable customize toolbar item
|
||||||
if ([menuItem action] == @selector(showHideToolbar:))
|
if (action == @selector(showHideToolbar:))
|
||||||
{
|
{
|
||||||
[menuItem setTitle: [fToolbar isVisible] ? @"Hide Toolbar" : @"Show Toolbar"];
|
[menuItem setTitle: [fToolbar isVisible] ? @"Hide Toolbar" : @"Show Toolbar"];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
//enable show info
|
//enable show info
|
||||||
if ([menuItem action] == @selector(showInfo:))
|
if (action == @selector(showInfo:))
|
||||||
{
|
{
|
||||||
[menuItem setTitle: [fInfoPanel isVisible] ? @"Hide Info" : @"Show Info"];
|
[menuItem setTitle: [fInfoPanel isVisible] ? @"Hide Info" : @"Show Info"];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//enable resume all item
|
||||||
|
if (action == @selector(resumeAllTorrents:))
|
||||||
|
return fCount > fDownloading + fSeeding;
|
||||||
|
|
||||||
|
//enable pause all item
|
||||||
|
if (action == @selector(stopAllTorrents:))
|
||||||
|
return fDownloading > 0 || fSeeding > 0;
|
||||||
|
|
||||||
//enable pause all and resume all
|
|
||||||
if ([menuItem action] == @selector(stopAllTorrents:) || [menuItem action] == @selector(resumeAllTorrents:))
|
|
||||||
return fCount > 0;
|
|
||||||
|
|
||||||
int row = [fTableView selectedRow];
|
int row = [fTableView selectedRow];
|
||||||
|
|
||||||
//enable remove items
|
//enable remove items
|
||||||
if ([menuItem action] == @selector(removeTorrent:)
|
if (action == @selector(removeTorrent:)
|
||||||
|| [menuItem action] == @selector(removeTorrentDeleteFile:)
|
|| action == @selector(removeTorrentDeleteFile:)
|
||||||
|| [menuItem action] == @selector(removeTorrentDeleteData:)
|
|| action == @selector(removeTorrentDeleteData:)
|
||||||
|| [menuItem action] == @selector(removeTorrentDeleteBoth:))
|
|| action == @selector(removeTorrentDeleteBoth:))
|
||||||
{
|
{
|
||||||
//append or remove ellipsis when needed
|
//append or remove ellipsis when needed
|
||||||
if (row >= 0 && fStat[row].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD)
|
if (row >= 0 && fStat[row].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD)
|
||||||
|
@ -858,11 +878,11 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
}
|
}
|
||||||
|
|
||||||
//enable reveal in finder item
|
//enable reveal in finder item
|
||||||
if ([menuItem action] == @selector(revealFromMenu:))
|
if (action == @selector(revealFromMenu:))
|
||||||
return row >= 0;
|
return row >= 0;
|
||||||
|
|
||||||
//enable and change pause / remove item
|
//enable and change pause / remove item
|
||||||
if ([menuItem action] == @selector(resumeTorrent:) || [menuItem action] == @selector(stopTorrent:))
|
if (action == @selector(resumeTorrent:) || action == @selector(stopTorrent:))
|
||||||
{
|
{
|
||||||
if (row >= 0 && fStat[row].status & TR_STATUS_PAUSE)
|
if (row >= 0 && fStat[row].status & TR_STATUS_PAUSE)
|
||||||
{
|
{
|
||||||
|
@ -911,9 +931,11 @@ static void sleepCallBack( void * controller, io_service_t y,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kIOMessageCanSystemSleep:
|
case kIOMessageCanSystemSleep:
|
||||||
/* Do not prevent idle sleep */
|
/* Prevent idle sleep unless all paused */
|
||||||
/* TODO: prevent it unless there are all paused? */
|
if (fDownloading > 0 || fSeeding > 0)
|
||||||
IOAllowPowerChange( fRootPort, (long) messageArgument );
|
IOCancelPowerChange( fRootPort, (long) messageArgument );
|
||||||
|
else
|
||||||
|
IOAllowPowerChange( fRootPort, (long) messageArgument );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kIOMessageSystemHasPoweredOn:
|
case kIOMessageSystemHasPoweredOn:
|
||||||
|
|
Loading…
Reference in New Issue