Changeset 19
- Timestamp:
- Jan 12, 2006, 6:57:23 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Jamrules
r14 r19 9 9 VERSION_MINOR = 4 ; 10 10 # VERSION_STRING = $(VERSION_MAJOR).$(VERSION_MINOR) ; 11 VERSION_STRING = CVS-200512 13;11 VERSION_STRING = CVS-20051221 ; 12 12 13 13 DEFINES += VERSION_MAJOR=$(VERSION_MAJOR) … … 50 50 { 51 51 $(RM) $(1) 52 sed "s/%%VERSION%%/$(VERSION_STRING)/ " < $(2) > $(1)52 sed "s/%%VERSION%%/$(VERSION_STRING)/g" < $(2) > $(1) 53 53 } 54 54 -
trunk/macosx/Controller.h
r16 r19 32 32 @interface Controller : NSObject 33 33 { 34 tr_handle_t 35 int 36 tr_stat_t 37 int 34 tr_handle_t * fHandle; 35 int fCount; 36 tr_stat_t * fStat; 37 int fResumeOnWake[TR_MAX_TORRENT_COUNT]; 38 38 39 NSToolbar 39 NSToolbar * fToolbar; 40 40 41 IBOutlet PrefsController * fPrefsController; 41 IBOutlet NSMenuItem * fAdvancedBarItem; 42 IBOutlet NSMenuItem * fPauseResumeItem; 43 IBOutlet NSMenuItem * fRemoveItem; 44 IBOutlet NSMenuItem * fRemoveTorrentItem; 45 IBOutlet NSMenuItem * fRemoveDataItem; 46 IBOutlet NSMenuItem * fRemoveBothItem; 47 IBOutlet NSMenuItem * fRevealItem; 48 IBOutlet NSMenuItem * fShowHideToolbar; 42 49 43 IBOutlet NSMenuItem * fAdvancedBarItem; 44 IBOutlet NSMenuItem * fPauseResumeItem; 45 IBOutlet NSMenuItem * fRemoveItem; 46 IBOutlet NSMenuItem * fRemoveTorrentItem; 47 IBOutlet NSMenuItem * fRemoveDataItem; 48 IBOutlet NSMenuItem * fRemoveBothItem; 49 IBOutlet NSMenuItem * fRevealItem; 50 IBOutlet NSMenuItem * fShowHideToolbar; 50 IBOutlet NSWindow * fWindow; 51 IBOutlet TorrentTableView * fTableView; 52 IBOutlet NSTextField * fTotalDLField; 53 IBOutlet NSTextField * fTotalULField; 51 54 52 IBOutlet NSWindow * fWindow; 53 IBOutlet TorrentTableView * fTableView; 54 IBOutlet NSTextField * fTotalDLField; 55 IBOutlet NSTextField * fTotalULField; 56 IBOutlet NSMenu * fContextMenu; 55 IBOutlet NSPanel * fInfoPanel; 56 IBOutlet NSTextField * fInfoTitle; 57 IBOutlet NSTextField * fInfoTracker; 58 IBOutlet NSTextField * fInfoAnnounce; 59 IBOutlet NSTextField * fInfoSize; 60 IBOutlet NSTextField * fInfoPieces; 61 IBOutlet NSTextField * fInfoPieceSize; 62 IBOutlet NSTextField * fInfoSeeders; 63 IBOutlet NSTextField * fInfoLeechers; 64 IBOutlet NSTextField * fInfoFolder; 65 IBOutlet NSTextField * fInfoDownloaded; 66 IBOutlet NSTextField * fInfoUploaded; 57 67 58 IBOutlet NSPanel * fInfoPanel; 59 IBOutlet NSTextField * fInfoTitle; 60 IBOutlet NSTextField * fInfoTracker; 61 IBOutlet NSTextField * fInfoAnnounce; 62 IBOutlet NSTextField * fInfoSize; 63 IBOutlet NSTextField * fInfoPieces; 64 IBOutlet NSTextField * fInfoPieceSize; 65 IBOutlet NSTextField * fInfoSeeders; 66 IBOutlet NSTextField * fInfoLeechers; 67 IBOutlet NSTextField * fInfoFolder; 68 IBOutlet NSTextField * fInfoDownloaded; 69 IBOutlet NSTextField * fInfoUploaded; 70 71 io_connect_t fRootPort; 72 NSArray * fFilenames; 73 NSTimer * fTimer; 68 io_connect_t fRootPort; 69 NSArray * fFilenames; 70 NSTimer * fTimer; 71 72 IBOutlet NSPanel * fPrefsWindow; 73 IBOutlet PrefsController * fPrefsController; 74 NSUserDefaults * fDefaults; 75 76 BOOL fHasGrowl; 74 77 } 75 78 … … 77 80 - (void) openShowSheet: (id) sender; 78 81 - (void) openSheetClosed: (NSOpenPanel *) s returnCode: (int) code 79 contextInfo: (void *) info; 80 - (void) stopTorrent: (id) sender; 81 - (void) stopAllTorrents: (id) sender; 82 - (void) stopTorrentWithIndex: (int) index; 83 - (void) resumeTorrent: (id) sender; 84 - (void) resumeAllTorrents: (id) sender; 85 - (void) resumeTorrentWithIndex: (int) index; 86 - (void) removeTorrent: (id) sender; 87 - (void) removeTorrentDeleteFile: (id) sender; 88 - (void) removeTorrentDeleteData: (id) sender; 89 - (void) removeTorrentDeleteBoth: (id) sender; 90 - (void) removeTorrentWithIndex: (int) idx 91 deleteTorrent: (BOOL) deleteTorrent 92 deleteData: (BOOL) deleteData; 82 contextInfo: (void *) info; 83 84 - (void) quitSheetDidEnd: (NSWindow *)sheet returnCode:(int)returnCode 85 contextInfo:(void *)contextInfo; 86 - (void) quitProcedure; 87 88 - (void) stopTorrent: (id) sender; 89 - (void) stopAllTorrents: (id) sender; 90 - (void) stopTorrentWithIndex: (int) index; 91 - (void) resumeTorrent: (id) sender; 92 - (void) resumeAllTorrents: (id) sender; 93 - (void) resumeTorrentWithIndex: (int) index; 94 95 - (void) removeTorrent: (id) sender; 96 - (void) removeTorrentDeleteFile: (id) sender; 97 - (void) removeTorrentDeleteData: (id) sender; 98 - (void) removeTorrentDeleteBoth: (id) sender; 99 - (void) removeTorrentWithIndex: (int) idx 100 deleteTorrent: (BOOL) deleteTorrent 101 deleteData: (BOOL) deleteData; 102 103 - (void) removeSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode 104 contextInfo:(NSDictionary *)dict; 105 - (void) confirmRemoveTorrentWithIndex: (int) idx 106 deleteTorrent: (BOOL) deleteTorrent 107 deleteData: (BOOL) deleteData; 108 93 109 - (void) showInfo: (id) sender; 94 110 95 111 - (void) updateUI: (NSTimer *) timer; 96 112 - (void) sleepCallBack: (natural_t) messageType argument: 97 (void *) messageArgument; 98 99 - (NSMenu *) menuForIndex: (int) idx; 113 (void *) messageArgument; 100 114 101 115 - (void) runCustomizationPalette: (id) sender; 102 116 - (void) showHideToolbar: (id) sender; 103 117 104 - (void) showMainWindow: (id) sender; 105 - (void) linkHomepage: (id) sender; 106 - (void) linkForums: (id) sender; 107 - (void) notifyGrowl: (NSString *) file; 108 - (void) finderReveal: (NSString *) path; 109 - (void) finderTrash: (NSString *) path; 110 - (void) growlRegister: (id) sender; 118 - (void) showPreferenceWindow: (id) sender; 119 120 - (void) showMainWindow: (id) sender; 121 - (void) linkHomepage: (id) sender; 122 - (void) linkForums: (id) sender; 123 - (void) notifyGrowl: (NSString *) file; 124 - (void) revealFromMenu: (id) sender; 125 - (void) finderReveal: (NSString *) path; 126 - (void) finderTrash: (NSString *) path; 127 - (void) growlRegister: (id) sender; 111 128 112 129 @end -
trunk/macosx/Controller.m
r16 r19 28 28 #include "TorrentTableView.h" 29 29 30 #import "PrefsController.h" 31 30 32 #define TOOLBAR_OPEN @"Toolbar Open" 31 33 #define TOOLBAR_REMOVE @"Toolbar Remove" 32 #define TOOLBAR_PREFS @"Toolbar Preferences"33 34 #define TOOLBAR_INFO @"Toolbar Info" 34 35 #define TOOLBAR_PAUSE_ALL @"Toolbar Pause All" 35 36 #define TOOLBAR_RESUME_ALL @"Toolbar Resume All" 36 37 37 #define CONTEXT_PAUSE 1 38 #define CONTEXT_REMOVE 2 39 #define CONTEXT_REMOVE_TORRENT 3 40 #define CONTEXT_REMOVE_DATA 4 41 #define CONTEXT_REMOVE_BOTH 5 42 #define CONTEXT_INFO 6 38 #define WEBSITE_URL @"http://transmission.m0k.org/" 39 #define FORUM_URL @"http://transmission.m0k.org/forum/" 40 41 #define GROWL_PATH @"/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app" 43 42 44 43 static void sleepCallBack( void * controller, io_service_t y, … … 53 52 - (void) awakeFromNib 54 53 { 54 [fWindow setContentMinSize: NSMakeSize( 400, 120 )]; 55 55 56 fHandle = tr_init(); 56 57 57 [fPrefsController setHandle: fHandle]; 58 59 [fWindow setContentMinSize: NSMakeSize( 400, 120 )]; 60 61 /* Check or uncheck menu item in respect to current preferences */ 62 [fAdvancedBarItem setState: [[NSUserDefaults standardUserDefaults] 58 [fPrefsController setPrefsWindow: fHandle]; 59 fDefaults = [NSUserDefaults standardUserDefaults]; 60 61 [fInfoPanel setFrameAutosaveName:@"InfoPanel"]; 62 63 //check advanced bar menu item 64 [fAdvancedBarItem setState: [fDefaults 63 65 boolForKey:@"UseAdvancedBar"] ? NSOnState : NSOffState]; 64 66 … … 67 69 [fToolbar setAllowsUserCustomization: YES]; 68 70 [fToolbar setAutosavesConfiguration: YES]; 69 [fWindow setToolbar:fToolbar];70 [fWindow 71 [fWindow setToolbar: fToolbar]; 72 [fWindow setDelegate: self]; 71 73 72 74 NSTableColumn * tableColumn; 73 NameCell * nameCell; 74 ProgressCell * progressCell; 75 76 nameCell = [[NameCell alloc] init]; 77 progressCell = [[ProgressCell alloc] init]; 75 NameCell * nameCell = [[NameCell alloc] init]; 76 ProgressCell * progressCell = [[ProgressCell alloc] init]; 77 78 78 tableColumn = [fTableView tableColumnWithIdentifier: @"Name"]; 79 79 [tableColumn setDataCell: nameCell]; 80 [tableColumn setMinWidth: 10.0];81 [tableColumn setMaxWidth: 3000.0];82 80 83 81 tableColumn = [fTableView tableColumnWithIdentifier: @"Progress"]; 84 82 [tableColumn setDataCell: progressCell]; 85 [tableColumn setMinWidth: 134.0];86 [tableColumn setMaxWidth: 134.0];87 83 88 84 [fTableView setAutosaveTableColumns: YES]; 89 [fTableView sizeToFit];85 //[fTableView sizeToFit]; 90 86 91 87 [fTableView registerForDraggedTypes: [NSArray arrayWithObjects: 92 88 NSFilenamesPboardType, NULL]]; 93 89 90 //Register for sleep notifications 94 91 IONotificationPortRef notify; 95 92 io_object_t anIterator; 96 93 97 /* Register for sleep notifications */ 98 fRootPort = IORegisterForSystemPower( self, ¬ify, sleepCallBack, 99 &anIterator); 100 if( !fRootPort ) 101 { 102 printf( "Could not IORegisterForSystemPower\n" ); 103 } 104 else 94 fRootPort = IORegisterForSystemPower( self, & notify, sleepCallBack, 95 & anIterator); 96 if (fRootPort) 105 97 { 106 98 CFRunLoopAddSource( CFRunLoopGetCurrent(), … … 108 100 kCFRunLoopCommonModes ); 109 101 } 110 111 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; 112 113 NSArray * history = [defaults arrayForKey: @"History"]; 114 if( history ) 115 { 116 unsigned i; 117 NSDictionary * dic; 118 NSString * torrentPath, * downloadFolder, * paused; 119 120 for( i = 0; i < [history count]; i++ ) 121 { 122 dic = [history objectAtIndex: i]; 123 124 torrentPath = [dic objectForKey: @"TorrentPath"]; 125 downloadFolder = [dic objectForKey: @"DownloadFolder"]; 126 paused = [dic objectForKey: @"Paused"]; 127 128 if( !torrentPath || !downloadFolder || !paused ) 129 { 130 continue; 131 } 132 133 if( tr_torrentInit( fHandle, [torrentPath UTF8String] ) ) 134 { 135 continue; 136 } 137 138 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 139 [downloadFolder UTF8String] ); 140 141 if( [paused isEqualToString: @"NO"] ) 142 { 143 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); 144 } 145 } 146 } 147 148 /* Register with the growl system */ 102 else 103 printf( "Could not IORegisterForSystemPower\n" ); 104 105 NSString * torrentPath, * downloadFolder, * paused; 106 NSDictionary * dic; 107 108 NSEnumerator * enumerator = [[fDefaults arrayForKey: @"History"] objectEnumerator]; 109 while ((dic = [enumerator nextObject])) 110 { 111 torrentPath = [dic objectForKey: @"TorrentPath"]; 112 downloadFolder = [dic objectForKey: @"DownloadFolder"]; 113 paused = [dic objectForKey: @"Paused"]; 114 115 if (!torrentPath || !downloadFolder || !paused) 116 continue; 117 118 if (tr_torrentInit(fHandle, [torrentPath UTF8String])) 119 continue; 120 121 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 122 [downloadFolder UTF8String] ); 123 124 if ([paused isEqualToString: @"NO"]) 125 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); 126 } 127 128 //check and register Growl if it is installed for this user or all users 129 NSFileManager * manager = [NSFileManager defaultManager]; 130 fHasGrowl = [manager fileExistsAtPath: GROWL_PATH] 131 || [manager fileExistsAtPath: [[NSString stringWithFormat: @"~%@", 132 GROWL_PATH] stringByExpandingTildeInPath]]; 149 133 [self growlRegister: self]; 150 134 151 / * Update the interface every 500 ms */135 //update the interface every 500 ms 152 136 fCount = 0; 153 137 fStat = NULL; … … 176 160 } 177 161 178 - (NSApplicationTerminateReply) applicationShouldTerminate: 179 (NSApplication *) app 180 { 162 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender 163 { 164 if ([[fDefaults stringForKey: @"CheckQuit"] isEqualToString:@"YES"]) 165 { 166 int i; 167 for( i = 0; i < fCount; i++ ) 168 { 169 if( fStat[i].status & ( TR_STATUS_CHECK | 170 TR_STATUS_DOWNLOAD ) ) 171 { 172 NSBeginAlertSheet(@"Confirm Quit", 173 @"Quit", @"Cancel", nil, 174 fWindow, self, 175 @selector(quitSheetDidEnd:returnCode:contextInfo:), 176 NULL, NULL, @"There are active torrents. Do you really want to quit?"); 177 return NSTerminateLater; 178 } 179 } 180 } 181 182 [self quitProcedure]; 183 return NSTerminateNow; 184 } 185 186 - (void) quitSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode 187 contextInfo:(void *)contextInfo 188 { 189 if (returnCode == NSAlertDefaultReturn) 190 [self quitProcedure]; 191 192 [NSApp stopModal]; 193 [NSApp replyToApplicationShouldTerminate: (returnCode == NSAlertDefaultReturn)]; 194 } 195 196 - (void) quitProcedure 197 { 198 int i; 181 199 NSMutableArray * history = [NSMutableArray 182 200 arrayWithCapacity: TR_MAX_TORRENT_COUNT]; 183 int i; 184 185 /* Stop updating the interface */ 201 202 // Stop updating the interface 186 203 [fTimer invalidate]; 187 204 188 / * Save history and stop running torrents */205 // Save history and stop running torrents 189 206 for( i = 0; i < fCount; i++ ) 190 207 { … … 206 223 } 207 224 208 / * Wait for torrents to stop (5 seconds timeout) */225 // Wait for torrents to stop (5 seconds timeout) 209 226 NSDate * start = [NSDate date]; 210 227 while( fCount > 0 ) … … 225 242 tr_close( fHandle ); 226 243 227 [[NSUserDefaults standardUserDefaults] 228 setObject: history forKey: @"History"]; 229 230 return NSTerminateNow; 244 [fDefaults setObject: history forKey: @"History"]; 245 } 246 247 - (void) showPreferenceWindow: (id) sender 248 { 249 NSRect mainFrame; 250 NSRect prefsFrame; 251 NSRect screenRect; 252 NSPoint point; 253 254 /* Place the window */ 255 mainFrame = [fWindow frame]; 256 prefsFrame = [fPrefsWindow frame]; 257 screenRect = [[NSScreen mainScreen] visibleFrame]; 258 point.x = mainFrame.origin.x + mainFrame.size.width / 2 - 259 prefsFrame.size.width / 2; 260 point.y = mainFrame.origin.y + mainFrame.size.height - 30; 261 262 /* Make sure it is in the screen */ 263 if( point.x < screenRect.origin.x ) 264 { 265 point.x = screenRect.origin.x; 266 } 267 if( point.x + prefsFrame.size.width > 268 screenRect.origin.x + screenRect.size.width ) 269 { 270 point.x = screenRect.origin.x + 271 screenRect.size.width - prefsFrame.size.width; 272 } 273 if( point.y - prefsFrame.size.height < screenRect.origin.y ) 274 { 275 point.y = screenRect.origin.y + prefsFrame.size.height; 276 } 277 278 [fPrefsWindow setFrameTopLeftPoint: point]; 279 [fPrefsWindow makeKeyAndOrderFront:NULL]; 231 280 } 232 281 … … 234 283 contextInfo: (void *) info 235 284 { 236 if( code != NSOKButton ) 285 if (code == NSOKButton) 286 { 287 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 288 [[[s filenames] objectAtIndex: 0] UTF8String] ); 289 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); 290 } 291 else 237 292 { 238 293 tr_torrentClose( fHandle, tr_torrentCount( fHandle ) - 1 ); 239 [NSApp stopModal]; 240 return; 241 } 242 243 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 244 [[[s filenames] objectAtIndex: 0] UTF8String] ); 245 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); 294 } 246 295 [NSApp stopModal]; 247 296 } 248 249 297 250 298 - (void) application: (NSApplication *) sender 251 299 openFiles: (NSArray *) filenames 252 300 { 253 unsigned i;254 NSUserDefaults * defaults;255 301 NSString * downloadChoice, * downloadFolder, * torrentPath; 256 302 257 defaults = [NSUserDefaults standardUserDefaults]; 258 downloadChoice = [defaults stringForKey: @"DownloadChoice"]; 259 downloadFolder = [defaults stringForKey: @"DownloadFolder"]; 260 261 for( i = 0; i < [filenames count]; i++ ) 262 { 263 torrentPath = [filenames objectAtIndex: i]; 264 303 downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; 304 downloadFolder = [fDefaults stringForKey: @"DownloadFolder"]; 305 306 NSEnumerator * enumerator = [filenames objectEnumerator]; 307 while ((torrentPath = [enumerator nextObject])) 308 { 265 309 if( tr_torrentInit( fHandle, [torrentPath UTF8String] ) ) 266 {267 310 continue; 268 }269 311 270 312 if( [downloadChoice isEqualToString: @"Constant"] ) … … 284 326 } 285 327 286 NSOpenPanel * panel; 287 NSString * message; 288 289 panel = [NSOpenPanel openPanel]; 290 message = [NSString stringWithFormat: 291 @"Select the download folder for %@", 292 [torrentPath lastPathComponent]]; 293 294 [panel setPrompt: @"Select"]; 295 [panel setMessage: message]; 296 [panel setAllowsMultipleSelection: NO]; 297 [panel setCanChooseFiles: NO]; 298 [panel setCanChooseDirectories: YES]; 328 NSOpenPanel * panel = [NSOpenPanel openPanel]; 329 330 [panel setPrompt: @"Select Download Folder"]; 331 [panel setMessage: [NSString stringWithFormat: 332 @"Select the download folder for %@", 333 [torrentPath lastPathComponent]]]; 334 [panel setAllowsMultipleSelection: NO]; 335 [panel setCanChooseFiles: NO]; 336 [panel setCanChooseDirectories: YES]; 299 337 300 338 [panel beginSheetForDirectory: NULL file: NULL types: NULL … … 310 348 - (void) advancedChanged: (id) sender 311 349 { 312 NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; 313 if( [fAdvancedBarItem state] == NSOnState ) 314 { 315 [fAdvancedBarItem setState: NSOffState]; 316 [defaults setObject:@"NO" forKey:@"UseAdvancedBar"]; 317 } 318 else 319 { 320 [fAdvancedBarItem setState: NSOnState]; 321 [defaults setObject:@"YES" forKey:@"UseAdvancedBar"]; 322 } 350 [fAdvancedBarItem setState: ![fAdvancedBarItem state]]; 351 [fDefaults setObject: [fAdvancedBarItem state] == NSOffState ? @"NO" : @"YES" 352 forKey:@"UseAdvancedBar"]; 353 323 354 [fTableView display]; 324 355 } 325 356 326 / * called on by applescript */357 //called on by applescript 327 358 - (void) open: (NSArray *) files 328 359 { … … 418 449 } 419 450 420 421 451 - (void) removeTorrentWithIndex: (int) idx 422 452 deleteTorrent: (BOOL) deleteTorrent 423 453 deleteData: (BOOL) deleteData 424 454 { 455 if ( fStat[idx].status & ( TR_STATUS_CHECK 456 | TR_STATUS_DOWNLOAD) ) 457 { 458 if ([[fDefaults stringForKey: @"CheckRemove"] isEqualToString:@"YES"]) 459 { 460 NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys: 461 [NSString stringWithFormat: @"%d", idx], @"Index", 462 [NSString stringWithFormat: @"%d", deleteTorrent], @"DeleteTorrent", 463 [NSString stringWithFormat: @"%d", deleteData], @"DeleteData", 464 nil]; 465 [dict retain]; 466 467 NSBeginAlertSheet(@"Confirm Remove", 468 @"Remove", @"Cancel", nil, 469 fWindow, self, 470 @selector(removeSheetDidEnd:returnCode:contextInfo:), 471 NULL, dict, @"This torrent is active. Do you really want to remove it?"); 472 return; 473 } 474 //stop if not stopped 475 else 476 [self stopTorrentWithIndex:idx]; 477 } 478 479 [self confirmRemoveTorrentWithIndex: idx 480 deleteTorrent: deleteTorrent 481 deleteData: deleteData]; 482 } 483 484 - (void) removeSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode 485 contextInfo:(NSDictionary *)dict 486 { 487 [NSApp stopModal]; 488 if (returnCode != NSAlertDefaultReturn) 489 { 490 [dict release]; 491 return; 492 } 493 494 int idx = [[dict objectForKey:@"Index"] intValue]; 495 496 [self stopTorrentWithIndex:idx]; 497 498 [self confirmRemoveTorrentWithIndex: idx 499 deleteTorrent: [[dict objectForKey:@"DeleteTorrent"] intValue] 500 deleteData: [[dict objectForKey:@"DeleteData"] intValue]]; 501 [dict release]; 502 } 503 504 - (void) confirmRemoveTorrentWithIndex: (int) idx 505 deleteTorrent: (BOOL) deleteTorrent 506 deleteData: (BOOL) deleteData 507 { 425 508 if( deleteData ) 426 509 { … … 476 559 int row, i; 477 560 478 /* Update the NSTableView */ 479 if( fStat ) 480 { 481 free( fStat ); 482 } 561 //Update the NSTableView 562 if (fStat) 563 free(fStat); 564 483 565 fCount = tr_torrentStat( fHandle, &fStat ); 484 566 [fTableView updateUI: fStat]; 485 567 486 / * Update the global DL/UL rates */568 //Update the global DL/UL rates 487 569 tr_torrentRates( fHandle, &dl, &ul ); 488 570 [fTotalDLField setStringValue: [NSString stringWithFormat: … … 491 573 @"Total UL: %.2f KB/s", ul]]; 492 574 493 / * Update DL/UL totals in the Info panel */575 //Update DL/UL totals in the Info panel 494 576 row = [fTableView selectedRow]; 495 if( row > -1)577 if( row >= 0 ) 496 578 { 497 579 [fInfoDownloaded setStringValue: … … 501 583 } 502 584 503 / * check if torrents have recently ended. */585 //check if torrents have recently ended. 504 586 for (i = 0; i < fCount; i++) 505 587 { 506 588 if( !tr_getFinished( fHandle, i ) ) 507 {508 589 continue; 509 }590 510 591 [self notifyGrowl: [NSString stringWithUTF8String: 511 592 fStat[i].info.name]]; 512 593 tr_setFinished( fHandle, i, 0 ); 513 594 } 514 }515 516 517 - (NSMenu *) menuForIndex: (int) idx518 {519 if ( idx < 0 || idx >= fCount )520 {521 return nil;522 }523 524 int status = fStat[idx].status;525 526 NSMenuItem *pauseItem = [fContextMenu itemWithTag: CONTEXT_PAUSE];527 NSMenuItem *removeItem = [fContextMenu itemAtIndex: 1];528 NSMenuItem *infoItem = [fContextMenu itemAtIndex: 2];529 530 [pauseItem setTarget: self];531 532 if ( status & TR_STATUS_CHECK ||533 status & TR_STATUS_DOWNLOAD ||534 status & TR_STATUS_SEED )535 {536 /* we can stop */537 [removeItem setEnabled: NO];538 [pauseItem setTitle: @"Pause"];539 [pauseItem setAction: @selector(stopTorrent:)];540 [pauseItem setEnabled: YES];541 } else {542 /* we are stopped */543 [removeItem setEnabled: YES];544 [pauseItem setTitle: @"Resume"];545 [pauseItem setAction: @selector(resumeTorrent:)];546 /* don't allow resuming if we aren't in PAUSE */547 if ( !(status & TR_STATUS_PAUSE) )548 [pauseItem setEnabled: NO];549 }550 551 if( [fInfoPanel isVisible] )552 {553 [infoItem setTitle: @"Hide Info"];554 } else {555 [infoItem setTitle: @"Show Info"];556 }557 558 return fContextMenu;559 595 } 560 596 … … 664 700 (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag 665 701 { 666 NSToolbarItem * item; 667 item = [[NSToolbarItem alloc] initWithItemIdentifier: ident]; 702 NSToolbarItem * item = [[NSToolbarItem alloc] initWithItemIdentifier: ident]; 668 703 669 704 if( [ident isEqualToString: TOOLBAR_OPEN] ) … … 685 720 [item setAction: @selector( removeTorrent: )]; 686 721 } 687 else if( [ident isEqualToString: TOOLBAR_PREFS] )688 {689 [item setLabel: @"Preferences"];690 [item setPaletteLabel: [item label]];691 [item setToolTip: @"Show the Preferences panel"];692 [item setImage: [NSImage imageNamed: @"Preferences.png"]];693 [item setTarget: fPrefsController];694 [item setAction: @selector( show: )];695 }696 722 else if( [ident isEqualToString: TOOLBAR_INFO] ) 697 723 { … … 734 760 return [NSArray arrayWithObjects: 735 761 TOOLBAR_OPEN, TOOLBAR_REMOVE, 736 /* TOOLBAR_RESUME_ALL, TOOLBAR_PAUSE_ALL, */737 TOOLBAR_ PREFS, TOOLBAR_INFO,762 TOOLBAR_RESUME_ALL, TOOLBAR_PAUSE_ALL, 763 TOOLBAR_INFO, 738 764 NSToolbarSeparatorItemIdentifier, 739 765 NSToolbarSpaceItemIdentifier, … … 747 773 return [NSArray arrayWithObjects: 748 774 TOOLBAR_OPEN, TOOLBAR_REMOVE, 749 /*NSToolbarSeparatorItemIdentifier,750 TOOLBAR_RESUME_ALL, TOOLBAR_PAUSE_ALL, */775 NSToolbarSeparatorItemIdentifier, 776 TOOLBAR_RESUME_ALL, TOOLBAR_PAUSE_ALL, 751 777 NSToolbarFlexibleSpaceItemIdentifier, 752 TOOLBAR_ PREFS, TOOLBAR_INFO,778 TOOLBAR_INFO, 753 779 NULL]; 754 780 } 755 781 782 - (void) runCustomizationPalette: (id) sender 783 { 784 [fToolbar runCustomizationPalette:sender]; 785 } 786 787 - (void) showHideToolbar: (id) sender 788 { 789 [fWindow toggleToolbarShown:sender]; 790 } 791 756 792 - (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem 757 793 { 758 // checkremove item794 //enable remove item 759 795 if ([toolbarItem action] == @selector(removeTorrent:)) 760 { 761 int row = [fTableView selectedRow]; 762 return ( row >= 0 ) && ( fStat[row].status & 763 ( TR_STATUS_STOPPING | TR_STATUS_PAUSE ) ); 764 } 765 766 return true; 767 } 768 769 - (void) runCustomizationPalette: (id) sender 770 { 771 [fToolbar runCustomizationPalette:sender]; 772 } 773 774 - (void) showHideToolbar: (id) sender 775 { 776 [fWindow toggleToolbarShown:sender]; 796 return [fTableView selectedRow] >= 0; 797 798 //enable pause all and resume all items 799 if ([toolbarItem action] == @selector(stopAllTorrents:) 800 || [toolbarItem action] == @selector(resumeAllTorrents:)) 801 return fCount > 0; 802 803 return YES; 777 804 } 778 805 779 806 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem 780 807 { 808 //disable menus if customize sheet is active 809 if ([fToolbar customizationPaletteIsRunning]) 810 return NO; 811 781 812 //enable customize toolbar item 782 813 if ([menuItem action] == @selector(showHideToolbar:)) 814 { 783 815 [menuItem setTitle: [fToolbar isVisible] ? @"Hide Toolbar" : @"Show Toolbar"]; 784 785 if ([fToolbar customizationPaletteIsRunning]) 786 return false; 816 return YES; 817 } 787 818 788 819 //enable show info … … 790 821 { 791 822 [menuItem setTitle: [fInfoPanel isVisible] ? @"Hide Info" : @"Show Info"]; 792 return true; 793 } 823 return YES; 824 } 825 826 //enable pause all and resume all 827 if ([menuItem action] == @selector(stopAllTorrents:) || [menuItem action] == @selector(resumeAllTorrents:)) 828 return fCount > 0; 794 829 795 830 int row = [fTableView selectedRow]; 796 831 797 832 //enable remove items 798 if ([menuItem action] == @selector(removeTorrent:) || [menuItem action] == @selector(removeTorrentDeleteFile:) 799 || [menuItem action] == @selector(removeTorrentDeleteData:) || [menuItem action] == @selector(removeTorrentDeleteBoth:)) { 800 /* Can we remove it ? */ 801 return ( row >= 0 ) && ( fStat[row].status & 802 ( TR_STATUS_STOPPING | TR_STATUS_PAUSE ) ); 833 if ([menuItem action] == @selector(removeTorrent:) 834 || [menuItem action] == @selector(removeTorrentDeleteFile:) 835 || [menuItem action] == @selector(removeTorrentDeleteData:) 836 || [menuItem action] == @selector(removeTorrentDeleteBoth:)) 837 { 838 //append or remove ellipsis when needed 839 if (row >= 0 && fStat[row].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD) 840 && [[fDefaults stringForKey: @"CheckRemove"] isEqualToString:@"YES"]) 841 { 842 if (![[menuItem title] hasSuffix:NS_ELLIPSIS]) 843 [menuItem setTitle:[[menuItem title] stringByAppendingString:NS_ELLIPSIS]]; 844 } 845 else 846 { 847 if ([[menuItem title] hasSuffix:NS_ELLIPSIS]) 848 [menuItem setTitle:[[menuItem title] substringToIndex:[[menuItem title] length]-[NS_ELLIPSIS length]]]; 849 } 850 return row >= 0; 803 851 } 804 852 … … 807 855 return row >= 0; 808 856 809 //enable and change pause andremove item857 //enable and change pause / remove item 810 858 if ([menuItem action] == @selector(resumeTorrent:) || [menuItem action] == @selector(stopTorrent:)) 811 859 { … … 823 871 } 824 872 825 return true;873 return YES; 826 874 } 827 875 … … 894 942 - (void) showMainWindow: (id) sender 895 943 { 896 [fWindow makeKeyAndOrderFront: NULL];944 [fWindow makeKeyAndOrderFront: nil]; 897 945 } 898 946 … … 900 948 { 901 949 [[NSWorkspace sharedWorkspace] openURL: [NSURL 902 URLWithString: @"http://transmission.m0k.org/"]];950 URLWithString: WEBSITE_URL]]; 903 951 } 904 952 … … 906 954 { 907 955 [[NSWorkspace sharedWorkspace] openURL: [NSURL 908 URLWithString:@"http://transmission.m0k.org/forum/"]]; 909 } 910 911 - (BOOL) hasGrowl 912 { 913 NSFileManager * manager = [NSFileManager defaultManager]; 914 NSString * helper = @"/Library/PreferencePanes/Growl.prefPane/" 915 "Contents/Resources/GrowlHelperApp.app"; 916 917 if( [manager fileExistsAtPath: helper] ) 918 { 919 /* Growl was installed for all users */ 920 return YES; 921 } 922 if( [manager fileExistsAtPath: [[NSString stringWithFormat: @"~%@", 923 helper] stringByExpandingTildeInPath]] ) 924 { 925 /* Growl was installed for this user only */ 926 return YES; 927 } 928 929 return NO; 956 URLWithString: FORUM_URL]]; 930 957 } 931 958 … … 936 963 NSDictionary * error; 937 964 938 if( ![self hasGrowl] ) 939 { 965 if( !fHasGrowl ) 940 966 return; 941 }942 967 943 968 growlScript = [NSString stringWithFormat: … … 966 991 NSDictionary * error; 967 992 968 if( ![self hasGrowl] ) 969 { 993 if( !fHasGrowl ) 970 994 return; 971 }972 995 973 996 growlScript = [NSString stringWithFormat: … … 982 1005 " end if\n" 983 1006 "end tell"]; 1007 984 1008 appleScript = [[NSAppleScript alloc] initWithSource: growlScript]; 985 1009 if( ![appleScript executeAndReturnError: &error] ) … … 990 1014 } 991 1015 992 993 1016 - (void) revealFromMenu: (id) sender 994 1017 { 995 int row; 996 997 row = [fTableView selectedRow]; 998 if( row < 0 ) 999 { 1000 return; 1001 } 1002 [self finderReveal: [NSString stringWithFormat: @"%@/%@", 1003 [NSString stringWithUTF8String: fStat[row].folder], 1004 [NSString stringWithUTF8String: fStat[row].info.name]]]; 1018 int row = [fTableView selectedRow]; 1019 if (row >= 0) 1020 { 1021 [self finderReveal: [NSString stringWithFormat: @"%@/%@", 1022 [NSString stringWithUTF8String: fStat[row].folder], 1023 [NSString stringWithUTF8String: fStat[row].info.name]]]; 1024 } 1005 1025 } 1006 1026 -
trunk/macosx/English.lproj/MainMenu.nib/classes.nib
r16 r19 19 19 showInfo = id; 20 20 showMainWindow = id; 21 showPreferenceWindow = id; 21 22 stopAllTorrents = id; 22 23 stopTorrent = id; … … 26 27 OUTLETS = { 27 28 fAdvancedBarItem = NSMenuItem; 28 fContextMenu = NSMenu;29 29 fInfoAnnounce = NSTextField; 30 30 fInfoDownloaded = NSTextField; … … 41 41 fPauseResumeItem = NSMenuItem; 42 42 fPrefsController = PrefsController; 43 fPrefsWindow = NSPanel; 43 44 fRemoveBothItem = NSMenuItem; 44 45 fRemoveDataItem = NSMenuItem; … … 55 56 }, 56 57 {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 58 {CLASS = NameCell; LANGUAGE = ObjC; SUPERCLASS = NSCell; }, 57 59 { 58 ACTIONS = {cancel = id; check = id; ratio = id; save = id; show = id; }; 60 ACTIONS = { 61 folderSheetShow = id; 62 setDownloadLocation = id; 63 setLimitUploadCheck = id; 64 setPort = id; 65 setQuitMessage = id; 66 setRemoveMessage = id; 67 setUploadLimit = id; 68 }; 59 69 CLASS = PrefsController; 60 70 LANGUAGE = ObjC; 61 71 OUTLETS = { 72 fBlankView = NSView; 62 73 fFolderMatrix = NSMatrix; 63 74 fFolderPopUp = NSPopUpButton; 75 fGeneralView = NSView; 76 fNetworkView = NSView; 64 77 fPortField = NSTextField; 65 fPrefsWindow = NSWindow; 78 fPrefsWindow = NSPanel; 79 fQuitCheck = NSButton; 80 fRemoveCheck = NSButton; 66 81 fUploadCheck = NSButton; 67 82 fUploadField = NSTextField; … … 70 85 SUPERCLASS = NSObject; 71 86 }, 87 {CLASS = ProgressCell; LANGUAGE = ObjC; SUPERCLASS = NSCell; }, 72 88 { 73 89 CLASS = TorrentTableView; 74 90 LANGUAGE = ObjC; 75 OUTLETS = {fCont roller = Controller; };91 OUTLETS = {fContextNoRow = NSMenu; fContextRow = NSMenu; fController = Controller; }; 76 92 SUPERCLASS = NSTableView; 77 93 } -
trunk/macosx/English.lproj/MainMenu.nib/info.nib
r16 r19 4 4 <dict> 5 5 <key>IBDocumentLocation</key> 6 <string> 416 137 361 432 0 0 1152 842 </string>6 <string>62 66 426 365 0 0 1280 832 </string> 7 7 <key>IBEditorPositions</key> 8 8 <dict> 9 9 <key>29</key> 10 <string> 79 779 371 44 0 0 1152 842 </string>10 <string>92 768 371 44 0 0 1280 832 </string> 11 11 <key>456</key> 12 <string>134 408 144 106 0 0 1152 842 </string> 12 <string>212 488 144 118 0 0 1152 842 </string> 13 <key>581</key> 14 <string>324 628 112 68 0 0 1152 842 </string> 15 <key>589</key> 16 <string>54 521 112 118 0 0 1152 842 </string> 17 <key>783</key> 18 <string>428 442 385 225 0 0 1280 832 </string> 19 <key>796</key> 20 <string>479 490 282 129 0 0 1280 832 </string> 21 <key>825</key> 22 <string>498 523 155 107 0 0 1152 842 </string> 13 23 </dict> 14 24 <key>IBFramework Version</key> … … 19 29 <array> 20 30 <integer>29</integer> 31 <integer>783</integer> 32 <integer>796</integer> 33 <integer>21</integer> 21 34 </array> 22 35 <key>IBSystem Version</key> -
trunk/macosx/Info.plist.in
r6 r19 38 38 <key>CFBundleVersion</key> 39 39 <string>%%VERSION%%</string> 40 <key>CFBundleShortVersionString</key> 41 <string>%%VERSION%%</string> 40 42 <key>NSMainNibFile</key> 41 43 <string>MainMenu</string> -
trunk/macosx/PrefsController.h
r1 r19 28 28 { 29 29 tr_handle_t * fHandle; 30 31 IBOutlet NSPanel * fPrefsWindow; 32 NSToolbar * fToolbar; 33 IBOutlet NSView * fGeneralView; 34 IBOutlet NSView * fNetworkView; 35 IBOutlet NSView * fBlankView; 36 37 IBOutlet NSMatrix * fFolderMatrix; 38 IBOutlet NSPopUpButton * fFolderPopUp; 39 IBOutlet NSTextField * fPortField; 40 IBOutlet NSButton * fUploadCheck; 41 IBOutlet NSTextField * fUploadField; 42 IBOutlet NSButton * fQuitCheck; 43 IBOutlet NSButton * fRemoveCheck; 44 45 IBOutlet NSWindow * fWindow; 30 46 31 IBOutlet NSWindow * fWindow; 32 IBOutlet NSWindow * fPrefsWindow; 33 IBOutlet NSMatrix * fFolderMatrix; 34 IBOutlet NSPopUpButton * fFolderPopUp; 35 IBOutlet NSTextField * fPortField; 36 IBOutlet NSButton * fUploadCheck; 37 IBOutlet NSTextField * fUploadField; 38 39 NSString * fDownloadFolder; 47 NSString * fDownloadFolder; 48 NSUserDefaults * fDefaults; 40 49 } 41 50 42 - (void) setHandle: (tr_handle_t *) handle; 43 - (void) show: (id) sender; 44 - (void) ratio: (id) sender; 45 - (void) check: (id) sender; 46 - (void) cancel: (id) sender; 47 - (void) save: (id) sender; 51 - (void) setPrefsWindow: (tr_handle_t *) handle; 52 53 - (void) setLimitUploadCheck: (id) sender; 54 - (void) setPort: (id) sender; 55 - (void) setUploadLimit: (id) sender; 56 - (void) setQuitMessage: (id) sender; 57 - (void) setRemoveMessage: (id) sender; 58 - (void) setDownloadLocation: (id) sender; 59 - (void) folderSheetShow: (id) sender; 48 60 49 61 @end -
trunk/macosx/PrefsController.m
r7 r19 23 23 #include "PrefsController.h" 24 24 25 #define DEFAULT_UPLOAD @"20" 26 #define MIN_PORT 1 27 #define MAX_PORT 65535 28 29 #define DOWNLOAD_FOLDER 0 30 #define DOWNLOAD_TORRENT 1 31 #define DOWNLOAD_ASK 2 32 33 #define TOOLBAR_GENERAL @"General" 34 #define TOOLBAR_NETWORK @"Network" 35 25 36 @interface PrefsController (Private) 26 37 27 - (void) folderSheetShow: (id) sender; 38 - (void) showGeneralPref: (id) sender; 39 - (void) showNetworkPref: (id) sender; 40 41 - (void) setPrefView: (NSView *) view; 42 28 43 - (void) folderSheetClosed: (NSOpenPanel *) s returnCode: (int) code 29 44 contextInfo: (void *) info; 30 - (void) loadSettings;31 - (void) saveSettings;32 45 - (void) updatePopUp; 33 46 … … 36 49 @implementation PrefsController 37 50 38 /*********************************************************************** 39 * setHandle 40 *********************************************************************** 41 * 42 **********************************************************************/ 43 - (void) setHandle: (tr_handle_t *) handle 44 { 45 NSUserDefaults * defaults; 51 + (void) initialize 52 { 46 53 NSDictionary * appDefaults; 47 54 NSString * desktop, * port; 48 49 fHandle = handle;50 55 51 56 /* Register defaults settings: … … 53 58 - Always download to Desktop 54 59 - Port TR_DEFAULT_PORT 55 - 20 KB/s upload limit */ 60 - Upload limit DEFAULT_UPLOAD 61 - Do not limit upload 62 - Ask before quitting 63 - Ask before removing */ 56 64 desktop = [NSHomeDirectory() stringByAppendingString: @"/Desktop"]; 57 port = [NSString stringWithFormat: @"%d", TR_DEFAULT_PORT]; 58 59 defaults = [NSUserDefaults standardUserDefaults]; 65 port = [NSString stringWithFormat: @"%d", TR_DEFAULT_PORT]; 66 60 67 appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: 61 @"NO", @"UseAdvancedBar", 62 @"Constant", @"DownloadChoice", 63 desktop, @"DownloadFolder", 64 port, @"BindPort", 65 @"20", @"UploadLimit", 68 @"NO", @"UseAdvancedBar", 69 @"Constant", @"DownloadChoice", 70 desktop, @"DownloadFolder", 71 port, @"BindPort", 72 DEFAULT_UPLOAD, @"UploadLimit", 73 @"YES", @"CheckUpload", 74 @"YES", @"CheckQuit", 75 @"YES", @"CheckRemove", 66 76 NULL]; 67 [defaults registerDefaults: appDefaults]; 68 69 /* Apply settings */ 70 tr_setBindPort( fHandle, [defaults integerForKey: @"BindPort"] ); 71 tr_setUploadLimit( fHandle, [defaults integerForKey: @"UploadLimit"] ); 72 } 73 74 /*********************************************************************** 75 * show 76 *********************************************************************** 77 * 78 **********************************************************************/ 79 - (void) show: (id) sender 80 { 81 NSRect mainFrame; 82 NSRect prefsFrame; 83 NSRect screenRect; 84 NSPoint point; 85 86 [self loadSettings]; 87 88 /* Place the window */ 89 mainFrame = [fWindow frame]; 90 prefsFrame = [fPrefsWindow frame]; 91 screenRect = [[NSScreen mainScreen] visibleFrame]; 92 point.x = mainFrame.origin.x + mainFrame.size.width / 2 - 93 prefsFrame.size.width / 2; 94 point.y = mainFrame.origin.y + mainFrame.size.height - 30; 95 96 /* Make sure it is in the screen */ 97 if( point.x < screenRect.origin.x ) 98 { 99 point.x = screenRect.origin.x; 100 } 101 if( point.x + prefsFrame.size.width > 102 screenRect.origin.x + screenRect.size.width ) 103 { 104 point.x = screenRect.origin.x + 105 screenRect.size.width - prefsFrame.size.width; 106 } 107 if( point.y - prefsFrame.size.height < screenRect.origin.y ) 108 { 109 point.y = screenRect.origin.y + prefsFrame.size.height; 110 } 111 112 [fPrefsWindow setFrameTopLeftPoint: point]; 113 [fPrefsWindow makeKeyAndOrderFront: NULL]; 114 } 115 116 /*********************************************************************** 117 * ratio 118 *********************************************************************** 119 * 120 **********************************************************************/ 121 - (void) ratio: (id) sender 122 { 123 [fFolderPopUp setEnabled: ![fFolderMatrix selectedRow]]; 124 } 125 126 /*********************************************************************** 127 * check 128 *********************************************************************** 129 * 130 **********************************************************************/ 131 - (void) check: (id) sender 132 { 133 if( [fUploadCheck state] == NSOnState ) 134 { 135 [fUploadField setEnabled: YES]; 77 [[NSUserDefaults standardUserDefaults] registerDefaults: appDefaults]; 78 } 79 80 - (void)dealloc 81 { 82 [fDownloadFolder release]; 83 [super dealloc]; 84 } 85 86 - (void) setPrefsWindow: (tr_handle_t *) handle 87 { 88 fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"]; 89 [fToolbar setDelegate: self]; 90 [fToolbar setAllowsUserCustomization: NO]; 91 [fPrefsWindow setToolbar: fToolbar]; 92 [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel]; 93 [fToolbar setSizeMode: NSToolbarSizeModeRegular]; 94 [fPrefsWindow setShowsToolbarButton: NO]; 95 96 [fToolbar setSelectedItemIdentifier: TOOLBAR_GENERAL]; 97 [self setPrefView: fGeneralView]; 98 99 fDefaults = [NSUserDefaults standardUserDefaults]; 100 101 //set download folder 102 NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; 103 fDownloadFolder = [fDefaults stringForKey: @"DownloadFolder"]; 104 [fDownloadFolder retain]; 105 106 if( [downloadChoice isEqualToString: @"Constant"] ) 107 { 108 [fFolderMatrix selectCellAtRow: DOWNLOAD_FOLDER column: 0]; 109 } 110 else if( [downloadChoice isEqualToString: @"Torrent"] ) 111 { 112 [fFolderMatrix selectCellAtRow: DOWNLOAD_TORRENT column: 0]; 136 113 } 137 114 else 138 115 { 139 [fUploadField setEnabled: NO]; 140 [fUploadField setStringValue: @""]; 141 } 142 } 143 144 /*********************************************************************** 145 * cancel 146 *********************************************************************** 147 * Discards changes and closes the Preferences window 148 **********************************************************************/ 149 - (void) cancel: (id) sender 150 { 151 [fDownloadFolder release]; 152 [fPrefsWindow close]; 153 } 154 155 /*********************************************************************** 156 * save 157 *********************************************************************** 158 * Checks the user-defined options. If they are correct, saves settings 159 * and closes the Preferences window. Otherwise corrects them and leaves 160 * the window open 161 **********************************************************************/ 162 - (void) save: (id) sender 163 { 164 int bindPort; 165 int uploadLimit; 166 167 /* Bind port */ 168 bindPort = [fPortField intValue]; 169 bindPort = MAX( 1, bindPort ); 170 bindPort = MIN( bindPort, 65535 ); 171 172 if( ![[fPortField stringValue] isEqualToString: 173 [NSString stringWithFormat: @"%d", bindPort]] ) 174 { 116 [fFolderMatrix selectCellAtRow: DOWNLOAD_ASK column: 0]; 117 } 118 [self updatePopUp]; 119 [fFolderPopUp setEnabled: [fFolderMatrix selectedRow] == 0]; 120 121 //set bind port 122 int bindPort = [fDefaults integerForKey: @"BindPort"]; 123 [fPortField setIntValue: bindPort]; 124 fHandle = handle; 125 tr_setBindPort( fHandle, bindPort ); 126 127 //checks for old version upload speed of -1 128 if ([fDefaults integerForKey: @"UploadLimit"] < 0) 129 { 130 [fDefaults setObject: DEFAULT_UPLOAD forKey: @"UploadLimit"]; 131 [fDefaults setObject: @"NO" forKey: @"CheckUpload"]; 132 } 133 134 //set upload limit 135 BOOL checkUpload = [[fDefaults stringForKey: @"CheckUpload"] isEqualToString:@"YES"]; 136 int uploadLimit = [fDefaults integerForKey: @"UploadLimit"]; 137 138 [fUploadCheck setState: checkUpload ? NSOnState : NSOffState]; 139 [fUploadField setIntValue: uploadLimit]; 140 [fUploadField setEnabled: checkUpload]; 141 142 if (!checkUpload || uploadLimit == 0) 143 uploadLimit = -1; 144 tr_setUploadLimit( fHandle, uploadLimit ); 145 146 //set remove and quit prompts 147 [fQuitCheck setState:([[fDefaults stringForKey: @"CheckQuit"] 148 isEqualToString:@"YES"] ? NSOnState : NSOffState)]; 149 [fRemoveCheck setState:([[fDefaults stringForKey: @"CheckRemove"] 150 isEqualToString:@"YES"] ? NSOnState : NSOffState)]; 151 } 152 153 - (NSToolbarItem *) toolbar: (NSToolbar *) t itemForItemIdentifier: 154 (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag 155 { 156 NSToolbarItem * item; 157 item = [[NSToolbarItem alloc] initWithItemIdentifier: ident]; 158 159 if ([ident isEqualToString: TOOLBAR_GENERAL]) 160 { 161 [item setLabel: TOOLBAR_GENERAL]; 162 [item setImage: [NSImage imageNamed: @"Preferences.png"]]; 163 [item setTarget: self]; 164 [item setAction: @selector( showGeneralPref: )]; 165 } 166 else if ([ident isEqualToString: TOOLBAR_NETWORK]) 167 { 168 [item setLabel: TOOLBAR_NETWORK]; 169 [item setImage: [NSImage imageNamed: @"Network.png"]]; 170 [item setTarget: self]; 171 [item setAction: @selector( showNetworkPref: )]; 172 } 173 else 174 { 175 [item release]; 176 return nil; 177 } 178 179 return item; 180 } 181 182 - (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar 183 { 184 return [self toolbarDefaultItemIdentifiers: nil]; 185 } 186 187 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar 188 { 189 return [self toolbarAllowedItemIdentifiers: nil]; 190 } 191 192 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar 193 { 194 return [NSArray arrayWithObjects: 195 TOOLBAR_GENERAL, 196 TOOLBAR_NETWORK, 197 nil]; 198 } 199 200 - (void) setPort: (id) sender 201 { 202 int bindPort = [fPortField intValue]; 203 204 //if value entered is not an int or is not in range do not change 205 if (![[fPortField stringValue] isEqualToString: 206 [NSString stringWithFormat: @"%d", bindPort]] 207 || bindPort < MIN_PORT 208 || bindPort > MAX_PORT) 209 { 210 NSBeep(); 211 bindPort = [fDefaults integerForKey: @"BindPort"]; 175 212 [fPortField setIntValue: bindPort]; 176 return; 177 } 178 179 /* Upload limit */ 180 if( [fUploadCheck state] == NSOnState ) 181 { 182 uploadLimit = [fUploadField intValue]; 183 uploadLimit = MAX( 0, uploadLimit ); 184 185 if( ![[fUploadField stringValue] isEqualToString: 186 [NSString stringWithFormat: @"%d", uploadLimit]] ) 187 { 188 [fUploadField setIntValue: uploadLimit]; 189 return; 190 } 191 } 192 193 [self saveSettings]; 194 [self cancel: NULL]; 195 } 196 197 @end /* @implementation PrefsController */ 198 199 @implementation PrefsController (Private) 213 } 214 else 215 { 216 tr_setBindPort( fHandle, bindPort ); 217 [fDefaults setObject: [NSString stringWithFormat: @"%d", bindPort] 218 forKey: @"BindPort"]; 219 } 220 } 221 222 - (void) setLimitUploadCheck: (id) sender 223 { 224 BOOL checkUpload = [fUploadCheck state] == NSOnState; 225 226 [fDefaults setObject: checkUpload ? @"YES" : @"NO" 227 forKey: @"CheckUpload"]; 228 229 [self setUploadLimit: sender]; 230 [fUploadField setEnabled: checkUpload]; 231 } 232 233 - (void) setUploadLimit: (id) sender 234 { 235 int uploadLimit = [fUploadField intValue]; 236 237 //if value entered is not an int or is less than 0 do not change 238 if (![[fUploadField stringValue] isEqualToString: 239 [NSString stringWithFormat: @"%d", uploadLimit]] 240 || uploadLimit < 0) 241 { 242 NSBeep(); 243 uploadLimit = [fDefaults integerForKey: @"UploadLimit"]; 244 [fUploadField setIntValue: uploadLimit]; 245 } 246 else 247 { 248 [fDefaults setObject: [NSString stringWithFormat: @"%d", uploadLimit] 249 forKey: @"UploadLimit"]; 250 } 251 252 if ([fUploadCheck state] == NSOffState || uploadLimit == 0) 253 uploadLimit = -1; 254 tr_setUploadLimit( fHandle, uploadLimit ); 255 } 256 257 - (void) setQuitMessage: (id) sender 258 { 259 [fDefaults setObject: ([fQuitCheck state] == NSOnState ? @"YES" : @"NO") 260 forKey: @"CheckQuit"]; 261 } 262 263 - (void) setRemoveMessage: (id) sender 264 { 265 [fDefaults setObject: ([fRemoveCheck state] == NSOnState ? @"YES" : @"NO") 266 forKey: @"CheckRemove"]; 267 } 268 269 - (void) setDownloadLocation: (id) sender 270 { 271 //Download folder 272 switch( [fFolderMatrix selectedRow] ) 273 { 274 case DOWNLOAD_FOLDER: 275 [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"]; 276 break; 277 case DOWNLOAD_TORRENT: 278 [fDefaults setObject: @"Torrent" forKey: @"DownloadChoice"]; 279 break; 280 case DOWNLOAD_ASK: 281 [fDefaults setObject: @"Ask" forKey: @"DownloadChoice"]; 282 break; 283 } 284 [fFolderPopUp setEnabled: [fFolderMatrix selectedRow] == 0]; 285 } 200 286 201 287 - (void) folderSheetShow: (id) sender 202 288 { 203 NSOpenPanel * panel; 204 205 panel = [NSOpenPanel openPanel]; 289 NSOpenPanel * panel = [NSOpenPanel openPanel]; 206 290 207 291 [panel setPrompt: @"Select"]; … … 216 300 } 217 301 218 - (void) folderSheetClosed: (NSOpenPanel *) s returnCode: (int) code 302 @end // @implementation PrefsController 303 304 @implementation PrefsController (Private) 305 306 - (void) showGeneralPref: (id) sender 307 { 308 [self setPrefView: fGeneralView]; 309 } 310 311 - (void) showNetworkPref: (id) sender 312 { 313 [self setPrefView: fNetworkView]; 314 } 315 316 - (void) setPrefView: (NSView *) view 317 { 318 NSRect windowRect = [fPrefsWindow frame]; 319 int difference = [view frame].size.height - [[fPrefsWindow contentView] frame].size.height; 320 321 windowRect.origin.y -= difference; 322 windowRect.size.height += difference; 323 324 [fPrefsWindow setTitle: [fToolbar selectedItemIdentifier]]; 325 [fPrefsWindow setContentView: fBlankView]; 326 [fPrefsWindow setFrame:windowRect display: YES animate: YES]; 327 [fPrefsWindow setContentView: view]; 328 } 329 330 - (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code 219 331 contextInfo: (void *) info 220 332 { 221 333 [fFolderPopUp selectItemAtIndex: 0]; 222 334 223 if( code != NSOKButton ) 224 { 335 if (code != NSOKButton) 225 336 return; 226 }227 337 228 338 [fDownloadFolder release]; 229 fDownloadFolder = [[ sfilenames] objectAtIndex: 0];339 fDownloadFolder = [[openPanel filenames] objectAtIndex: 0]; 230 340 [fDownloadFolder retain]; 341 342 [fDefaults setObject: fDownloadFolder forKey: @"DownloadFolder"]; 231 343 232 344 [self updatePopUp]; 233 345 } 234 346 235 /***********************************************************************236 * loadSettings237 ***********************************************************************238 * Update the interface with the current settings239 **********************************************************************/240 - (void) loadSettings241 {242 NSUserDefaults * defaults;243 NSString * downloadChoice;244 int uploadLimit;245 246 /* Fill with current settings */247 defaults = [NSUserDefaults standardUserDefaults];248 249 /* Download folder selection */250 downloadChoice = [defaults stringForKey: @"DownloadChoice"];251 fDownloadFolder = [defaults stringForKey: @"DownloadFolder"];252 [fDownloadFolder retain];253 254 if( [downloadChoice isEqualToString: @"Constant"] )255 {256 [fFolderMatrix selectCellAtRow: 0 column: 0];257 }258 else if( [downloadChoice isEqualToString: @"Torrent"] )259 {260 [fFolderMatrix selectCellAtRow: 1 column: 0];261 }262 else263 {264 [fFolderMatrix selectCellAtRow: 2 column: 0];265 }266 [self ratio: NULL];267 [self updatePopUp];268 269 [fPortField setIntValue: [defaults integerForKey: @"BindPort"]];270 271 uploadLimit = [defaults integerForKey: @"UploadLimit"];272 if( uploadLimit < 0 )273 {274 [fUploadCheck setState: NSOffState];275 }276 else277 {278 [fUploadCheck setState: NSOnState];279 [fUploadField setIntValue: uploadLimit];280 }281 [self check: NULL];282 }283 284 /***********************************************************************285 * saveSettings286 ***********************************************************************287 *288 **********************************************************************/289 - (void) saveSettings290 {291 NSUserDefaults * defaults;292 int bindPort;293 int uploadLimit;294 295 defaults = [NSUserDefaults standardUserDefaults];296 297 /* Download folder */298 switch( [fFolderMatrix selectedRow] )299 {300 case 0:301 [defaults setObject: @"Constant" forKey: @"DownloadChoice"];302 break;303 case 1:304 [defaults setObject: @"Torrent" forKey: @"DownloadChoice"];305 break;306 case 2:307 [defaults setObject: @"Ask" forKey: @"DownloadChoice"];308 break;309 }310 [defaults setObject: fDownloadFolder forKey: @"DownloadFolder"];311 312 /* Bind port */313 bindPort = [fPortField intValue];314 tr_setBindPort( fHandle, bindPort );315 [defaults setObject: [NSString stringWithFormat: @"%d", bindPort]316 forKey: @"BindPort"];317 318 /* Upload limit */319 if( [fUploadCheck state] == NSOnState )320 {321 uploadLimit = [fUploadField intValue];322 }323 else324 {325 uploadLimit = -1;326 }327 tr_setUploadLimit( fHandle, uploadLimit );328 [defaults setObject: [NSString stringWithFormat: @"%d", uploadLimit]329 forKey: @"UploadLimit"];330 }331 332 /***********************************************************************333 * updatePopUp334 ***********************************************************************335 * Uses fDownloadFolder to update the displayed folder name and icon336 **********************************************************************/337 347 - (void) updatePopUp 338 348 { … … 340 350 NSImage * image32, * image16; 341 351 342 /* Set up the pop up */ 343 [fFolderPopUp removeAllItems]; 344 [fFolderPopUp addItemWithTitle: @""]; 345 [[fFolderPopUp menu] addItem: [NSMenuItem separatorItem]]; 346 [fFolderPopUp addItemWithTitle: @"Other..."]; 347 348 menuItem = (NSMenuItem *) [fFolderPopUp lastItem]; 349 [menuItem setTarget: self]; 350 [menuItem setAction: @selector( folderSheetShow: )]; 351 352 /* Get the icon for the folder */ 352 // Get the icon for the folder 353 353 image32 = [[NSWorkspace sharedWorkspace] iconForFile: 354 354 fDownloadFolder]; 355 355 image16 = [[NSImage alloc] initWithSize: NSMakeSize(16,16)]; 356 356 357 / * 32x32 -> 16x16 scaling */357 // 32x32 -> 16x16 scaling 358 358 [image16 lockFocus]; 359 359 [[NSGraphicsContext currentContext] … … 364 364 [image16 unlockFocus]; 365 365 366 / * Update the menu item */366 // Update the menu item 367 367 menuItem = (NSMenuItem *) [fFolderPopUp itemAtIndex: 0]; 368 368 [menuItem setTitle: [fDownloadFolder lastPathComponent]]; -
trunk/macosx/TorrentTableView.h
r3 r19 11 11 tr_stat_t * fStat; 12 12 NSPoint fClickPoint; 13 14 IBOutlet NSMenu * fContextRow; 15 IBOutlet NSMenu * fContextNoRow; 13 16 } 14 17 -
trunk/macosx/TorrentTableView.m
r7 r19 57 57 } 58 58 59 60 59 - (BOOL) pointInPauseRect: (NSPoint) point 61 60 { … … 115 114 point = [self convertPoint: [e locationInWindow] fromView: NULL]; 116 115 row = [self rowAtPoint: point]; 116 117 [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; 117 118 118 if( row < 0 ) 119 { 120 return NULL; 121 } 122 123 [self selectRowIndexes: [NSIndexSet indexSetWithIndex: row] 124 byExtendingSelection: NO]; 125 return [fController menuForIndex: row]; 119 return row >= 0 ? fContextRow : fContextNoRow; 126 120 } 127 121 -
trunk/macosx/Transmission.xcodeproj/project.pbxproj
r16 r19 19 19 4D752E930913C949008EAAD4 /* Preferences.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D752E920913C949008EAAD4 /* Preferences.png */; }; 20 20 4D813EB508AA43AC00191DB4 /* Progress.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D813EB408AA43AC00191DB4 /* Progress.png */; }; 21 4D8CEF91095870E00063BAEA /* Network.png in Resources */ = {isa = PBXBuildFile; fileRef = 4D8CEF90095870E00063BAEA /* Network.png */; }; 21 22 4DA6FDBA0911233800450CB1 /* PauseOn.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDB80911233800450CB1 /* PauseOn.png */; }; 22 23 4DA6FDBB0911233800450CB1 /* PauseOff.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DA6FDB90911233800450CB1 /* PauseOff.png */; }; … … 85 86 4D752E920913C949008EAAD4 /* Preferences.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Preferences.png; path = Images/Preferences.png; sourceTree = "<group>"; }; 86 87 4D813EB408AA43AC00191DB4 /* Progress.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Progress.png; path = Images/Progress.png; sourceTree = "<group>"; }; 88 4D8CEF90095870E00063BAEA /* Network.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Network.png; path = Images/Network.png; sourceTree = "<group>"; }; 87 89 4DA6FDB80911233800450CB1 /* PauseOn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseOn.png; path = Images/PauseOn.png; sourceTree = "<group>"; }; 88 90 4DA6FDB90911233800450CB1 /* PauseOff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseOff.png; path = Images/PauseOff.png; sourceTree = "<group>"; }; … … 195 197 4DA6FDC4091141AD00450CB1 /* ResumeOn.png */, 196 198 4D752E920913C949008EAAD4 /* Preferences.png */, 199 4D8CEF90095870E00063BAEA /* Network.png */, 197 200 8D1107310486CEB800E47090 /* Info.plist */, 198 201 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, … … 284 287 4DA6FDC6091141AD00450CB1 /* ResumeOn.png in Resources */, 285 288 4D752E930913C949008EAAD4 /* Preferences.png in Resources */, 289 4D8CEF91095870E00063BAEA /* Network.png in Resources */, 286 290 ); 287 291 runOnlyForDeploymentPostprocessing = 0; … … 332 336 i386, 333 337 ); 334 FRAMEWORK_SEARCH_PATHS = ( 335 "$(FRAMEWORK_SEARCH_PATHS)", 336 ); 338 FRAMEWORK_SEARCH_PATHS = "$(FRAMEWORK_SEARCH_PATHS)"; 337 339 GCC_GENERATE_DEBUGGING_SYMBOLS = YES; 338 340 GCC_OPTIMIZATION_LEVEL = 3;
Note: See TracChangeset
for help on using the changeset viewer.