From a50ac18cbdb3a92fb3eee480f7a67afc3081db64 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 21 Jun 2006 14:07:56 +0000 Subject: [PATCH] A lot of cleanup; remove cantfindaname once and for all. --- macosx/Controller.m | 87 +++++++++++++++------------------------ macosx/FileTableView.m | 3 +- macosx/PrefsController.m | 68 ++++++++++++------------------ macosx/StringAdditions.m | 9 ++-- macosx/Torrent.h | 2 + macosx/Torrent.m | 74 +++++++++++++++------------------ macosx/TorrentTableView.m | 83 +++++++++++++++---------------------- 7 files changed, 132 insertions(+), 194 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index e0a2202b2..f2edf61db 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -45,8 +45,8 @@ #define GROWL_PATH @"/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app" -static void sleepCallBack( void * controller, io_service_t y, - natural_t messageType, void * messageArgument ) +static void sleepCallBack(void * controller, io_service_t y, + natural_t messageType, void * messageArgument) { Controller * c = controller; [c sleepCallBack: messageType argument: messageArgument]; @@ -134,15 +134,13 @@ static void sleepCallBack( void * controller, io_service_t y, [fTableView registerForDraggedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]]; - //Register for sleep notifications + //register for sleep notifications IONotificationPortRef notify; - io_object_t anIterator; - if (fRootPort = IORegisterForSystemPower(self, & notify, - sleepCallBack, & anIterator)) + io_object_t iterator; + if (fRootPort = IORegisterForSystemPower(self, & notify, sleepCallBack, & iterator)) { - CFRunLoopAddSource( CFRunLoopGetCurrent(), - IONotificationPortGetRunLoopSource( notify ), - kCFRunLoopCommonModes ); + CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notify), + kCFRunLoopCommonModes); } else NSLog(@"Could not IORegisterForSystemPower"); @@ -259,9 +257,7 @@ static void sleepCallBack( void * controller, io_service_t y, : [NSString stringWithFormat: @"There are %d active transfers. Do you really want to quit?", active]; - NSBeginAlertSheet(@"Confirm Quit", - @"Quit", @"Cancel", nil, - fWindow, self, + NSBeginAlertSheet(@"Confirm Quit", @"Quit", @"Cancel", nil, fWindow, self, @selector(quitSheetDidEnd:returnCode:contextInfo:), nil, nil, message); return NSTerminateLater; @@ -316,12 +312,12 @@ static void sleepCallBack( void * controller, io_service_t y, } } -- (void) folderChoiceClosed: (NSOpenPanel *) s returnCode: (int) code +- (void) folderChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (Torrent *) torrent { if (code == NSOKButton) { - [torrent setDownloadFolder: [[s filenames] objectAtIndex: 0]]; + [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]]; if ([fDefaults boolForKey: @"AutoStartDownload"]) [torrent start]; [fTorrents addObject: torrent]; @@ -422,8 +418,7 @@ static void sleepCallBack( void * controller, io_service_t y, //called on by applescript - (void) open: (NSArray *) files { - [self performSelectorOnMainThread: @selector(cantFindAName:) - withObject: files waitUntilDone: NO]; + [self performSelectorOnMainThread: @selector(openFromSheet:) withObject: files waitUntilDone: NO]; } - (void) openShowSheet: (id) sender @@ -469,10 +464,7 @@ static void sleepCallBack( void * controller, io_service_t y, Torrent * torrent; unsigned int i; for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) - { - torrent = [fTorrents objectAtIndex: i]; - [torrent start]; - } + [[fTorrents objectAtIndex: i] start]; [self updateUI: nil]; [self updateTorrentHistory]; @@ -491,8 +483,8 @@ static void sleepCallBack( void * controller, io_service_t y, - (void) stopTorrentWithIndex: (NSIndexSet *) indexSet { - Torrent * torrent; unsigned int i; + Torrent * torrent; for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) { torrent = [fTorrents objectAtIndex: i]; @@ -520,8 +512,7 @@ static void sleepCallBack( void * controller, io_service_t y, NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: torrents, @"Torrents", [NSNumber numberWithBool: deleteData], @"DeleteData", - [NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent", - nil]; + [NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent", nil]; NSString * title, * message; @@ -550,8 +541,7 @@ static void sleepCallBack( void * controller, io_service_t y, NSBeginAlertSheet(title, @"Remove", @"Cancel", nil, fWindow, self, - @selector(removeSheetDidEnd:returnCode:contextInfo:), - nil, dict, message); + @selector(removeSheetDidEnd:returnCode:contextInfo:), nil, dict, message); } else [self confirmRemove: torrents deleteData: deleteData deleteTorrent: deleteTorrent]; @@ -722,15 +712,15 @@ static void sleepCallBack( void * controller, io_service_t y, { NSEnumerator * enumerator = [fTorrents objectEnumerator]; Torrent * torrent; - while( ( torrent = [enumerator nextObject] ) ) + while ((torrent = [enumerator nextObject])) { [torrent update]; - if( [torrent justFinished] ) + if ([torrent justFinished]) { - /* Notifications */ + //notifications [self notifyGrowl: [torrent name]]; - if( ![fWindow isKeyWindow] ) + if (![fWindow isKeyWindow]) fCompleted++; } } @@ -740,7 +730,7 @@ static void sleepCallBack( void * controller, io_service_t y, else [fTableView reloadData]; - //Update the global DL/UL rates + //update the global DL/UL rates float downloadRate, uploadRate; tr_torrentRates(fLib, & downloadRate, & uploadRate); if (fStatusBarVisible) @@ -1126,8 +1116,8 @@ static void sleepCallBack( void * controller, io_service_t y, { Torrent * torrent; NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while( ( torrent = [enumerator nextObject] ) ) - if( [torrent isActive] ) + while ((torrent = [enumerator nextObject])) + if ([torrent isActive]) return YES; return NO; } @@ -1137,8 +1127,8 @@ static void sleepCallBack( void * controller, io_service_t y, { Torrent * torrent; NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while( ( torrent = [enumerator nextObject] ) ) - if( [torrent isPaused] ) + while ((torrent = [enumerator nextObject])) + if ([torrent isPaused]) return YES; return NO; } @@ -1151,27 +1141,20 @@ static void sleepCallBack( void * controller, io_service_t y, unsigned int i; for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) - { - torrent = [fTorrents objectAtIndex: i]; - if ([torrent isActive]) + if ([[fTorrents objectAtIndex: i] isActive]) return YES; - } return NO; } //enable resume item if ([ident isEqualToString: TOOLBAR_RESUME_SELECTED]) { - Torrent * torrent; NSIndexSet * indexSet = [fTableView selectedRowIndexes]; unsigned int i; for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) - { - torrent = [fTorrents objectAtIndex: i]; - if ([torrent isPaused]) + if ([[fTorrents objectAtIndex: i] isPaused]) return YES; - } return NO; } @@ -1214,8 +1197,8 @@ static void sleepCallBack( void * controller, io_service_t y, { Torrent * torrent; NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while( ( torrent = [enumerator nextObject] ) ) - if( [torrent isPaused] ) + while ((torrent = [enumerator nextObject])) + if ([torrent isPaused]) return YES; return NO; } @@ -1225,8 +1208,8 @@ static void sleepCallBack( void * controller, io_service_t y, { Torrent * torrent; NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while( ( torrent = [enumerator nextObject] ) ) - if( [torrent isActive] ) + while ((torrent = [enumerator nextObject])) + if ([torrent isActive]) return YES; return NO; } @@ -1241,8 +1224,7 @@ static void sleepCallBack( void * controller, io_service_t y, || action == @selector(removeDeleteTorrent:) || action == @selector(removeDeleteBoth:)) { BOOL active = NO, - canDelete = !(action == @selector(removeDeleteTorrent:) - || action == @selector(removeDeleteBoth:)); + canDelete = action != @selector(removeDeleteTorrent:) && action != @selector(removeDeleteBoth:); Torrent * torrent; NSIndexSet * indexSet = [fTableView selectedRowIndexes]; unsigned int i; @@ -1274,8 +1256,7 @@ static void sleepCallBack( void * controller, io_service_t y, else { if ([title hasSuffix: ellipsis]) - [menuItem setTitle: [title substringToIndex: - [title rangeOfString: ellipsis].location]]; + [menuItem setTitle: [title substringToIndex: [title rangeOfString: ellipsis].location]]; } return canUseMenu && canDelete && [fTableView numberOfSelectedRows] > 0; @@ -1440,7 +1421,7 @@ static void sleepCallBack( void * controller, io_service_t y, NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript]; NSDictionary * error; - if (![appleScript executeAndReturnError: &error]) + if (![appleScript executeAndReturnError: & error]) NSLog(@"Growl notify failed"); [appleScript release]; } @@ -1464,7 +1445,7 @@ static void sleepCallBack( void * controller, io_service_t y, NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript]; NSDictionary * error; - if (![appleScript executeAndReturnError: &error]) + if (![appleScript executeAndReturnError: & error]) NSLog(@"Growl registration failed"); [appleScript release]; } diff --git a/macosx/FileTableView.m b/macosx/FileTableView.m index 656bfbcb7..32f130c72 100644 --- a/macosx/FileTableView.m +++ b/macosx/FileTableView.m @@ -39,8 +39,7 @@ if (row >= 0) { if (![self isRowSelected: row]) - [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] - byExtendingSelection: NO]; + [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO]; } else [self deselectAll: self]; diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 3be376865..43d038430 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -25,16 +25,16 @@ #import "PrefsController.h" #import "StringAdditions.h" -#define MIN_PORT 1 -#define MAX_PORT 65535 +#define MIN_PORT 1 +#define MAX_PORT 65535 #define DOWNLOAD_FOLDER 0 #define DOWNLOAD_TORRENT 2 #define DOWNLOAD_ASK 3 -#define UPDATE_DAILY 0 -#define UPDATE_WEEKLY 1 -#define UPDATE_NEVER 2 +#define UPDATE_DAILY 0 +#define UPDATE_WEEKLY 1 +#define UPDATE_NEVER 2 #define TOOLBAR_GENERAL @"General" #define TOOLBAR_TRANSFERS @"Transfers" @@ -48,8 +48,7 @@ - (void) setPrefView: (NSView *) view; -- (void) folderSheetClosed: (NSOpenPanel *) s returnCode: (int) code - contextInfo: (void *) info; +- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info; - (void) updatePopUp; @end @@ -85,7 +84,7 @@ fHandle = handle; //set download folder - NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; + NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]; [fDownloadFolder retain]; @@ -100,8 +99,7 @@ //set bind port int bindPort = [fDefaults integerForKey: @"BindPort"]; [fPortField setIntValue: bindPort]; - fHandle = handle; - tr_setBindPort( fHandle, bindPort ); + tr_setBindPort(fHandle, bindPort); //checks for old version upload speed of -1 if ([fDefaults integerForKey: @"UploadLimit"] < 0) @@ -118,7 +116,7 @@ [fUploadField setIntValue: uploadLimit]; [fUploadField setEnabled: checkUpload]; - tr_setUploadLimit( fHandle, checkUpload ? uploadLimit : -1 ); + tr_setUploadLimit(fHandle, checkUpload ? uploadLimit : -1); //set download limit BOOL checkDownload = [fDefaults boolForKey: @"CheckDownload"]; @@ -128,7 +126,7 @@ [fDownloadField setIntValue: downloadLimit]; [fDownloadField setEnabled: checkDownload]; - tr_setDownloadLimit( fHandle, checkDownload ? downloadLimit : -1 ); + tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1); //set ratio limit BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"]; @@ -253,8 +251,7 @@ } int limit = [sender intValue]; - if (![[sender stringValue] isEqualToString: - [NSString stringWithFormat: @"%d", limit]] + if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%d", limit]] || limit < 0) { NSBeep(); @@ -263,12 +260,10 @@ } else { - if( sender == fUploadField ) - tr_setUploadLimit( fHandle, - ( [fUploadCheck state] == NSOffState ) ? -1 : limit ); + if (sender == fUploadField) + tr_setUploadLimit(fHandle, [fUploadCheck state] == NSOffState ? -1 : limit); else - tr_setDownloadLimit( fHandle, - ( [fDownloadCheck state] == NSOffState ) ? -1 : limit ); + tr_setDownloadLimit(fHandle, [fDownloadCheck state] == NSOffState ? -1 : limit); [fDefaults setInteger: limit forKey: key]; } @@ -277,8 +272,7 @@ [NSNumber numberWithBool: [check state]], @"Enable", [NSNumber numberWithInt: limit], @"Limit", type, @"Type", nil]; - [[NSNotificationCenter defaultCenter] postNotificationName: - @"LimitGlobalChange" object: dict]; + [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange" object: dict]; } - (void) setLimitCheck: (id) sender @@ -305,8 +299,7 @@ - (void) setLimitEnabled: (BOOL) enable type: (NSString *) type { - NSButton * check = [type isEqualToString: @"Upload"] - ? fUploadCheck : fDownloadCheck; + NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck; [check setState: enable ? NSOnState : NSOffState]; [self setLimitCheck: check]; } @@ -331,8 +324,7 @@ - (void) setRatio: (id) sender { float ratioLimit = [sender floatValue]; - if (![[sender stringValue] isEqualToString: - [NSString stringWithFormat: @"%.2f", ratioLimit]] + if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]] || ratioLimit < 0) { NSBeep(); @@ -345,8 +337,7 @@ NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithBool: [fRatioCheck state]], @"Enable", [NSNumber numberWithFloat: ratioLimit], @"Ratio", nil]; - [[NSNotificationCenter defaultCenter] postNotificationName: - @"RatioGlobalChange" object: dict]; + [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: dict]; } - (void) setRatioCheck: (id) sender @@ -442,7 +433,7 @@ - (void) setDownloadLocation: (id) sender { //Download folder - switch( [fFolderPopUp indexOfSelectedItem] ) + switch ([fFolderPopUp indexOfSelectedItem]) { case DOWNLOAD_FOLDER: [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; @@ -465,10 +456,10 @@ { NSOpenPanel * panel = [NSOpenPanel openPanel]; - [panel setPrompt: @"Select"]; - [panel setAllowsMultipleSelection: NO]; - [panel setCanChooseFiles: NO]; - [panel setCanChooseDirectories: YES]; + [panel setPrompt: @"Select"]; + [panel setAllowsMultipleSelection: NO]; + [panel setCanChooseFiles: NO]; + [panel setCanChooseDirectories: YES]; [panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: [self window] modalDelegate: self didEndSelector: @@ -512,8 +503,7 @@ [view setHidden: NO]; } -- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code - contextInfo: (void *) info +- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info { if (code == NSOKButton) { @@ -531,18 +521,12 @@ { //reset if cancelled NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; - if( [downloadChoice isEqualToString: @"Constant"] ) - { + if ([downloadChoice isEqualToString: @"Constant"]) [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER]; - } - else if( [downloadChoice isEqualToString: @"Torrent"] ) - { + else if ([downloadChoice isEqualToString: @"Torrent"]) [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT]; - } else - { [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK]; - } } } diff --git a/macosx/StringAdditions.m b/macosx/StringAdditions.m index 224278a76..42107cd0f 100644 --- a/macosx/StringAdditions.m +++ b/macosx/StringAdditions.m @@ -68,12 +68,10 @@ NSString * value; if (size < 10240) /* 1.00 to 9.99 XB */ - value = [NSString stringWithFormat: @"%lld.%02lld", - size / 1024, ( size % 1024 ) * 100 / 1024]; + value = [NSString stringWithFormat: @"%lld.%02lld", size / 1024, ( size % 1024 ) * 100 / 1024]; else if (size < 102400) /* 10.0 to 99.9 XB */ - value = [NSString stringWithFormat: @"%lld.%lld", - size / 1024, ( size % 1024 ) * 10 / 1024]; + value = [NSString stringWithFormat: @"%lld.%lld", size / 1024, ( size % 1024 ) * 10 / 1024]; else /* 100+ XB */ value = [NSString stringWithFormat: @"%lld", size / 1024]; @@ -83,8 +81,7 @@ + (NSString *) stringForSpeed: (float) speed { - return [[self stringForSpeedAbbrev: speed] - stringByAppendingString: @"B/s"]; + return [[self stringForSpeedAbbrev: speed] stringByAppendingString: @"B/s"]; } + (NSString *) stringForSpeedAbbrev: (float) speed diff --git a/macosx/Torrent.h b/macosx/Torrent.h index e1585aefd..32df80fc4 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -100,6 +100,8 @@ //- (NSString *) state; - (float) progress; +- (int) eta; + - (BOOL) isActive; - (BOOL) isSeeding; - (BOOL) isPaused; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index c1999ba36..084e72335 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -41,8 +41,7 @@ - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib { - self = [self initWithHash: nil path: path lib: lib - privateTorrent: nil publicTorrent: nil + self = [self initWithHash: nil path: path lib: lib privateTorrent: nil publicTorrent: nil date: nil stopRatioSetting: nil ratioLimit: nil]; if (self) @@ -67,8 +66,7 @@ { NSString * downloadFolder; if (!(downloadFolder = [history objectForKey: @"DownloadFolder"])) - downloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] - stringByExpandingTildeInPath]; + downloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]; [self setDownloadFolder: downloadFolder]; NSString * paused; @@ -100,9 +98,9 @@ - (void) dealloc { - if( fHandle ) + if (fHandle) { - tr_torrentClose( fLib, fHandle ); + tr_torrentClose(fLib, fHandle); if (fPublicTorrentLocation) [fPublicTorrentLocation release]; @@ -118,25 +116,24 @@ - (void) setDownloadFolder: (NSString *) path { - tr_torrentSetFolder( fHandle, [path UTF8String] ); + tr_torrentSetFolder(fHandle, [path UTF8String]); } - (NSString *) downloadFolder { - return [NSString stringWithUTF8String: tr_torrentGetFolder( fHandle )]; + return [NSString stringWithUTF8String: tr_torrentGetFolder(fHandle)]; } - (void) getAvailability: (int8_t *) tab size: (int) size { - tr_torrentAvailability( fHandle, tab, size ); + tr_torrentAvailability(fHandle, tab, size); } - (void) update { - fStat = tr_torrentStat( fHandle ); + fStat = tr_torrentStat(fHandle); - if ([self isSeeding] - && ((fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit) + if ([self isSeeding] && ((fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit) || (fStopRatioSetting == RATIO_GLOBAL && [fDefaults boolForKey: @"RatioCheck"] && [self ratio] >= [fDefaults floatForKey: @"RatioLimit"]))) { @@ -144,7 +141,7 @@ [self setStopRatioSetting: RATIO_NO_CHECK]; fFinishedSeeding = YES; - fStat = tr_torrentStat( fHandle ); + fStat = tr_torrentStat(fHandle); [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentRatioChanged" object: self]; } @@ -158,7 +155,7 @@ [self size]], [NSString stringForFileSize: [self uploadedTotal]], [NSString stringForRatioWithDownload: [self downloadedTotal] upload: [self uploadedTotal]]]; - switch( fStat->status ) + switch (fStat->status) { case TR_STATUS_PAUSE: [fStatusString setString: fFinishedSeeding ? @"Seeding Complete" : @"Paused"]; @@ -171,11 +168,10 @@ case TR_STATUS_DOWNLOAD: [fStatusString setString: @""]; [fStatusString appendFormat: - @"Downloading from %d of %d peer%s", - [self peersUploading], [self totalPeers], + @"Downloading from %d of %d peer%s", [self peersUploading], [self totalPeers], ([self totalPeers] == 1) ? "" : "s"]; - int eta = fStat->eta; + int eta = [self eta]; if (eta < 0) [fProgressString appendString: @" - remaining time unknown"]; else @@ -222,19 +218,17 @@ - (void) start { - if( fStat->status & TR_STATUS_INACTIVE ) + if (![self isActive]) { - tr_torrentStart( fHandle ); + tr_torrentStart(fHandle); fFinishedSeeding = NO; } } - (void) stop { - if( fStat->status & TR_STATUS_ACTIVE ) - { - tr_torrentStop( fHandle ); - } + if ([self isActive]) + tr_torrentStop(fHandle); } - (void) removeForever @@ -245,18 +239,14 @@ - (void) sleep { - if( ( fResumeOnWake = ( fStat->status & TR_STATUS_ACTIVE ) ) ) - { + if ((fResumeOnWake = [self isActive])) [self stop]; - } } - (void) wakeUp { - if( fResumeOnWake ) - { + if (fResumeOnWake) [self start]; - } } - (float) ratio @@ -288,8 +278,7 @@ - (void) reveal { - [[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] - inFileViewerRootedAtPath: nil]; + [[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] inFileViewerRootedAtPath: nil]; } - (void) trashData @@ -325,8 +314,7 @@ - (NSString *) tracker { - return [NSString stringWithFormat: @"%s:%d", - fInfo->trackerAddress, fInfo->trackerPort]; + return [NSString stringWithFormat: @"%s:%d", fInfo->trackerAddress, fInfo->trackerPort]; } - (NSString *) announce @@ -414,24 +402,29 @@ return fStat->progress; } +- (int) eta +{ + return fStat->eta; +} + - (BOOL) isActive { - return ( fStat->status & TR_STATUS_ACTIVE ); + return fStat->status & TR_STATUS_ACTIVE; } - (BOOL) isSeeding { - return ( fStat->status == TR_STATUS_SEED ); + return fStat->status == TR_STATUS_SEED; } - (BOOL) isPaused { - return ( fStat->status == TR_STATUS_PAUSE ); + return fStat->status == TR_STATUS_PAUSE; } - (BOOL) justFinished { - return tr_getFinished( fHandle ); + return tr_getFinished(fHandle); } - (NSString *) progressString @@ -513,9 +506,9 @@ - (NSNumber *) stateSortKey { - if (fStat->status & TR_STATUS_INACTIVE) + if (![self isActive]) return [NSNumber numberWithInt: 0]; - else if (fStat->status == TR_STATUS_SEED) + else if ([self isSeeding]) return [NSNumber numberWithInt: 1]; else return [NSNumber numberWithInt: 2]; @@ -571,8 +564,7 @@ fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"]; fFinishedSeeding = NO; - NSString * fileType = fInfo->multifile ? - NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension]; + NSString * fileType = fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension]; fIcon = [[NSWorkspace sharedWorkspace] iconForFileType: fileType]; [fIcon retain]; diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 160adfdca..b3ee435e0 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -70,50 +70,41 @@ fTorrents = torrents; } -- (void) mouseDown: (NSEvent *) e +- (void) mouseDown: (NSEvent *) event { - fClickPoint = [self convertPoint: [e locationInWindow] fromView: nil]; - int row = [self rowAtPoint: fClickPoint]; + fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil]; - if( [e modifierFlags] & NSAlternateKeyMask ) + if ([event modifierFlags] & NSAlternateKeyMask) { [fController advancedChanged: self]; - fClickPoint = NSMakePoint( 0, 0 ); + fClickPoint = NSZeroPoint; } - else if( ![self pointInPauseRect: fClickPoint] && - ![self pointInRevealRect: fClickPoint] ) - [super mouseDown: e]; + else if (![self pointInPauseRect: fClickPoint] && ![self pointInRevealRect: fClickPoint]) + [super mouseDown: event]; else; [self display]; } -- (void) mouseUp: (NSEvent *) e +- (void) mouseUp: (NSEvent *) event { - NSPoint point; - int row; - bool sameRow; - Torrent * torrent; - - point = [self convertPoint: [e locationInWindow] fromView: nil]; - row = [self rowAtPoint: point]; - sameRow = row == [self rowAtPoint: fClickPoint]; + NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil]; + int row = [self rowAtPoint: point]; + BOOL sameRow = row == [self rowAtPoint: fClickPoint]; - if( sameRow && [self pointInPauseRect: point] - && [self pointInPauseRect: fClickPoint] ) + if (sameRow && [self pointInPauseRect: point] && [self pointInPauseRect: fClickPoint]) { - torrent = [fTorrents objectAtIndex: row]; + Torrent * torrent = [fTorrents objectAtIndex: row]; - if( [torrent isPaused] ) + if ([torrent isPaused]) [fController resumeTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]]; - else if( [torrent isActive] ) + else if ([torrent isActive]) [fController stopTorrentWithIndex: [NSIndexSet indexSetWithIndex: row]]; else; } - else if( sameRow && [self pointInRevealRect: point] - && [self pointInRevealRect: fClickPoint] ) + else if (sameRow && [self pointInRevealRect: point] && [self pointInRevealRect: fClickPoint]) [[fTorrents objectAtIndex: row] reveal]; - else if ([e clickCount] == 2) + else if ([event clickCount] == 2) { if ([self pointInIconRect: point]) [[fTorrents objectAtIndex: row] reveal]; @@ -122,21 +113,20 @@ } else; - [super mouseUp: e]; + [super mouseUp: event]; - fClickPoint = NSMakePoint( 0, 0 ); + fClickPoint = NSZeroPoint; [self display]; } -- (NSMenu *) menuForEvent: (NSEvent *) e +- (NSMenu *) menuForEvent: (NSEvent *) event { - int row = [self rowAtPoint: [self convertPoint: [e locationInWindow] fromView: nil]]; + int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]]; if (row >= 0) { if (![self isRowSelected: row]) - [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] - byExtendingSelection: NO]; + [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO]; return fContextRow; } @@ -149,14 +139,14 @@ - (void) drawRect: (NSRect) r { - unsigned i; NSRect rect; - NSImage * image; Torrent * torrent; + NSImage * image; [super drawRect: r]; - for( i = 0; i < [fTorrents count]; i++ ) + int i; + for (i = 0; i < [fTorrents count]; i++) { torrent = [fTorrents objectAtIndex: i]; rect = [self pauseRectForRow: i]; @@ -171,17 +161,15 @@ if (image) { [image setFlipped: YES]; - [image drawAtPoint: rect.origin fromRect: - NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) operation: - NSCompositeSourceOver fraction: 1.0]; + [image drawAtPoint: rect.origin fromRect: NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) + operation: NSCompositeSourceOver fraction: 1.0]; } rect = [self revealRectForRow: i]; image = NSPointInRect(fClickPoint, rect) ? fRevealOnIcon : fRevealOffIcon; [image setFlipped: YES]; - [image drawAtPoint: rect.origin fromRect: - NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) operation: - NSCompositeSourceOver fraction: 1.0]; + [image drawAtPoint: rect.origin fromRect: NSMakeRect(0, 0, BUTTON_WIDTH, BUTTON_WIDTH) + operation: NSCompositeSourceOver fraction: 1.0]; } } @@ -191,8 +179,7 @@ - (NSRect) pauseRectForRow: (int) row { - NSRect cellRect = [self frameOfCellAtColumn: - [self columnWithIdentifier: @"Torrent"] row: row]; + NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; return NSMakeRect(cellRect.origin.x + cellRect.size.width - AREA_CENTER - DISTANCE_FROM_CENTER - BUTTON_WIDTH, @@ -201,11 +188,9 @@ - (NSRect) revealRectForRow: (int) row { - NSRect cellRect = [self frameOfCellAtColumn: - [self columnWithIdentifier: @"Torrent"] row: row]; + NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; - return NSMakeRect(cellRect.origin.x + cellRect.size.width - - AREA_CENTER + DISTANCE_FROM_CENTER, + return NSMakeRect(cellRect.origin.x + cellRect.size.width - AREA_CENTER + DISTANCE_FROM_CENTER, cellRect.origin.y + BUTTON_TO_TOP, BUTTON_WIDTH, BUTTON_WIDTH); } @@ -215,13 +200,11 @@ if (row < 0) return NO; - NSRect cellRect = [self frameOfCellAtColumn: - [self columnWithIdentifier: @"Torrent"] row: row]; + NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row]; NSSize iconSize = [[[fTorrents objectAtIndex: row] iconFlipped] size]; NSRect iconRect = NSMakeRect(cellRect.origin.x + 3.0, cellRect.origin.y - + (cellRect.size.height - iconSize.height) * 0.5, - iconSize.width, iconSize.height); + + (cellRect.size.height - iconSize.height) * 0.5, iconSize.width, iconSize.height); return NSPointInRect(point, iconRect); }