Changeset 141
- Timestamp:
- Mar 10, 2006, 9:10:17 PM (17 years ago)
- Location:
- branches/new_api
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/new_api/libtransmission/transmission.c
r140 r141 1 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining a … … 423 423 } 424 424 425 void tr_torrentAvailability( tr_torrent_t * tor, uint8_t * tab, int size )425 void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size ) 426 426 { 427 427 int i, j, piece; -
branches/new_api/libtransmission/transmission.h
r140 r141 177 177 * of connected peers who have the piece. 178 178 **********************************************************************/ 179 void tr_torrentAvailability( tr_torrent_t *, uint8_t * tab, int size );179 void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size ); 180 180 181 181 /*********************************************************************** … … 230 230 #define TR_STATUS_DOWNLOAD 0x002 /* Downloading */ 231 231 #define TR_STATUS_SEED 0x004 /* Seeding */ 232 #define TR_STATUS_ACTIVE 0x007 /* CHECK | DOWNLOAD | SEED */233 232 #define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */ 234 233 #define TR_STATUS_STOPPED 0x010 /* Sent 'stopped' but thread still 235 234 running (for internal use only) */ 236 235 #define TR_STATUS_PAUSE 0x020 /* Paused */ 237 #define TR_STATUS_INACTIVE 0x038 /* STOPPING | STOPPED | PAUSE */ 236 237 #define TR_STATUS_ACTIVE (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED) 238 #define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE) 238 239 int status; 239 240 -
branches/new_api/macosx/Controller.h
r107 r141 1 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining a … … 33 33 @interface Controller : NSObject 34 34 { 35 tr_handle_t * f Handle;35 tr_handle_t * fLib; 36 36 int fCount, fSeeding, fDownloading, fCompleted; 37 tr_stat_t * fStat; 38 int fResumeOnWake[TR_MAX_TORRENT_COUNT]; 37 NSMutableArray * fTorrents; 39 38 40 39 NSToolbar * fToolbar; -
branches/new_api/macosx/Controller.m
r126 r141 1 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining a … … 23 23 #import <IOKit/IOMessage.h> 24 24 25 #import "Controller.h" 26 #import "Torrent.h" 25 27 #import "NameCell.h" 26 28 #import "ProgressCell.h" … … 56 58 { 57 59 [fWindow setContentMinSize: NSMakeSize( 400, 120 )]; 58 59 f Handle= tr_init();60 61 [fPrefsController setPrefsWindow: f Handle];60 61 fLib = tr_init(); 62 63 [fPrefsController setPrefsWindow: fLib]; 62 64 fDefaults = [NSUserDefaults standardUserDefaults]; 63 65 64 66 [fInfoPanel setFrameAutosaveName:@"InfoPanel"]; 65 67 … … 67 69 [fAdvancedBarItem setState: [fDefaults 68 70 boolForKey:@"UseAdvancedBar"] ? NSOnState : NSOffState]; 69 71 70 72 fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Transmission Toolbar"]; 71 73 [fToolbar setDelegate: self]; … … 109 111 NSDictionary * dic; 110 112 113 Torrent * torrent; 111 114 NSEnumerator * enumerator = [[fDefaults arrayForKey: @"History"] objectEnumerator]; 112 115 while ((dic = [enumerator nextObject])) … … 115 118 downloadFolder = [dic objectForKey: @"DownloadFolder"]; 116 119 paused = [dic objectForKey: @"Paused"]; 117 120 118 121 if (!torrentPath || !downloadFolder || !paused) 119 122 continue; 120 123 121 if (tr_torrentInit(fHandle, [torrentPath UTF8String])) 124 torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib]; 125 if( !torrent ) 122 126 continue; 123 127 124 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 125 [downloadFolder UTF8String] ); 128 [fTorrents addObject: torrent]; 129 130 [torrent setFolder: downloadFolder]; 126 131 127 132 if ([paused isEqualToString: @"NO"]) 128 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );133 [torrent start]; 129 134 } 130 135 … … 138 143 //initialize badging 139 144 fBadger = [[Badger alloc] init]; 140 145 141 146 //update the interface every 500 ms 142 fCount = 0;143 147 fDownloading = 0; 144 148 fSeeding = 0; 145 149 fCompleted = 0; 146 fStat = nil;147 150 [self updateUI: nil]; 148 151 fTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self … … 200 203 nil, nil, message); 201 204 return NSTerminateLater; 202 } 203 205 } 206 204 207 return NSTerminateNow; 205 208 } … … 215 218 - (void) applicationWillTerminate: (NSNotification *) notification 216 219 { 217 int i; 218 220 NSEnumerator * enumerator; 221 Torrent * torrent; 222 219 223 // Stop updating the interface 220 224 [fTimer invalidate]; … … 223 227 //clear badge 224 228 [fBadger clearBadge]; 225 [fBadger release]; 229 [fBadger release]; 226 230 227 231 // Save history 228 232 [self updateTorrentHistory]; 229 233 230 234 // Stop running torrents 231 for( i = 0; i < fCount; i++ ) 232 if( fStat[i].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | 233 TR_STATUS_SEED ) ) 234 tr_torrentStop( fHandle, i ); 235 enumerator = [fTorrents objectEnumerator]; 236 while( ( torrent = [enumerator nextObject] ) ) 237 { 238 [torrent stop]; 239 } 235 240 236 241 // Wait for torrents to stop (5 seconds timeout) 237 242 NSDate * start = [NSDate date]; 238 while( fCount > 0 ) 239 { 243 while( [fTorrents count] ) 244 { 245 torrent = [fTorrents objectAtIndex: 0]; 240 246 while( [[NSDate date] timeIntervalSinceDate: start] < 5 && 241 ! ( fStat[0].status & TR_STATUS_PAUSE ))247 ![torrent isPaused] ) 242 248 { 243 249 usleep( 100000 ); 244 tr_torrentStat( fHandle, &fStat ); 245 } 246 tr_torrentClose( fHandle, 0 ); 247 fCount = tr_torrentStat( fHandle, &fStat ); 248 } 249 250 tr_close( fHandle ); 250 [torrent update]; 251 } 252 [fTorrents removeObject: torrent]; 253 [torrent release]; 254 } 255 [fTorrents release]; 256 257 tr_close( fLib ); 251 258 } 252 259 … … 258 265 [fPrefsWindow center]; 259 266 } 260 267 261 268 [fPrefsWindow makeKeyAndOrderFront:NULL]; 262 269 } … … 265 272 contextInfo: (void *) info 266 273 { 274 Torrent * torrent = [fTorrents lastObject]; 267 275 if (code == NSOKButton) 268 276 { 269 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 270 [[[s filenames] objectAtIndex: 0] UTF8String] ); 271 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); 277 [torrent setFolder: [[s filenames] objectAtIndex: 0]]; 278 [torrent start]; 272 279 } 273 280 else 274 281 { 275 tr_torrentClose( fHandle, tr_torrentCount( fHandle ) - 1 );282 [torrent release]; 276 283 } 277 284 [NSApp stopModal]; … … 282 289 { 283 290 NSString * downloadChoice, * downloadFolder, * torrentPath; 291 Torrent * torrent; 284 292 285 293 downloadChoice = [fDefaults stringForKey: @"DownloadChoice"]; … … 289 297 while ((torrentPath = [enumerator nextObject])) 290 298 { 291 if( tr_torrentInit( fHandle, [torrentPath UTF8String] ) ) 299 torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib]; 300 if( !torrent ) 292 301 continue; 302 [fTorrents addObject: torrent]; 293 303 294 304 /* Add it to the "File > Open Recent" menu */ … … 298 308 if( [downloadChoice isEqualToString: @"Constant"] ) 299 309 { 300 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 301 [[downloadFolder stringByExpandingTildeInPath] UTF8String] ); 302 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); 310 [torrent setFolder: [downloadFolder stringByExpandingTildeInPath]]; 311 [torrent start]; 303 312 } 304 313 else if( [downloadChoice isEqualToString: @"Torrent"] ) 305 314 { 306 tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1, 307 [[torrentPath stringByDeletingLastPathComponent] UTF8String] ); 308 tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 ); 315 [torrent setFolder: [torrentPath stringByDeletingLastPathComponent]]; 316 [torrent start]; 309 317 } 310 318 else 311 319 { 312 320 NSOpenPanel * panel = [NSOpenPanel openPanel]; 313 321 314 322 [panel setPrompt: @"Select Download Folder"]; 315 323 [panel setMessage: [NSString stringWithFormat: … … 356 364 panel = [NSOpenPanel openPanel]; 357 365 fileTypes = [NSArray arrayWithObject: @"torrent"]; 358 366 359 367 [panel setAllowsMultipleSelection: YES]; 360 368 [panel setCanChooseFiles: YES]; … … 394 402 - (void) resumeAllTorrents: (id) sender 395 403 { 396 int i; 397 for ( i = 0; i < fCount; i++) 398 { 399 if ( fStat[i].status & ( TR_STATUS_STOPPING 400 | TR_STATUS_PAUSE | TR_STATUS_STOPPED ) ) 401 { 402 [self resumeTorrentWithIndex: i]; 403 } 404 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 405 Torrent * torrent; 406 while( ( torrent = [enumerator nextObject] ) ) 407 { 408 [torrent stop]; 404 409 } 405 410 } … … 407 412 - (void) resumeTorrentWithIndex: (int) idx 408 413 { 409 tr_torrentStart( fHandle, idx );410 [self updateUI: NULL];414 [[fTorrents objectAtIndex: idx] start]; 415 [self updateUI: nil]; 411 416 [self updateTorrentHistory]; 412 417 } … … 419 424 - (void) stopAllTorrents: (id) sender 420 425 { 421 int i; 422 for ( i = 0; i < fCount; i++) 423 { 424 if ( fStat[i].status & ( TR_STATUS_CHECK 425 | TR_STATUS_DOWNLOAD | TR_STATUS_SEED) ) 426 { 427 [self stopTorrentWithIndex: i]; 428 } 426 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 427 Torrent * torrent; 428 while( ( torrent = [enumerator nextObject] ) ) 429 { 430 [torrent start]; 429 431 } 430 432 } … … 432 434 - (void) stopTorrentWithIndex: (int) idx 433 435 { 434 tr_torrentStop( fHandle, idx ); 435 [self updateUI: NULL]; 436 Torrent * torrent = [fTorrents objectAtIndex: idx]; 437 [torrent stop]; 438 [self updateUI: nil]; 436 439 [self updateTorrentHistory]; 437 440 } … … 441 444 deleteData: (BOOL) deleteData 442 445 { 443 if ( fStat[idx].status & ( TR_STATUS_CHECK 444 | TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) ) 446 Torrent * torrent = [fTorrents objectAtIndex: idx]; 447 448 if( [torrent isActive] ) 445 449 { 446 450 if ([fDefaults boolForKey: @"CheckRemove"]) … … 452 456 nil]; 453 457 [dict retain]; 454 458 455 459 NSBeginAlertSheet(@"Confirm Remove", 456 460 @"Remove", @"Cancel", nil, … … 464 468 [self stopTorrentWithIndex:idx]; 465 469 } 466 470 467 471 [self confirmRemoveTorrentWithIndex: idx 468 472 deleteTorrent: deleteTorrent … … 479 483 return; 480 484 } 481 485 482 486 int idx = [[dict objectForKey:@"Index"] intValue]; 483 487 484 488 [self stopTorrentWithIndex:idx]; 485 489 … … 489 493 [dict release]; 490 494 } 491 495 492 496 - (void) confirmRemoveTorrentWithIndex: (int) idx 493 497 deleteTorrent: (BOOL) deleteTorrent 494 498 deleteData: (BOOL) deleteData 495 499 { 500 #if 0 496 501 if( deleteData ) 497 502 { … … 505 510 fStat[idx].info.torrent]]; 506 511 } 507 512 508 513 tr_torrentClose( fHandle, idx ); 509 514 [self updateUI: NULL]; 510 515 [self updateTorrentHistory]; 516 #endif 511 517 } 512 518 … … 546 552 { 547 553 float dl, ul; 548 int row, i; 549 550 //Update the NSTableView 551 if (fStat) 552 free(fStat); 553 554 fCount = tr_torrentStat( fHandle, &fStat ); 555 fDownloading = 0; 556 fSeeding = 0; 557 [fTableView updateUI: fStat]; 554 NSEnumerator * enumerator; 555 Torrent * torrent; 556 557 /* Update the TableView */ 558 enumerator = [fTorrents objectEnumerator]; 559 while( ( torrent = [enumerator nextObject] ) ) 560 { 561 [torrent update]; 562 563 if( [torrent justFinished] ) 564 { 565 /* Notifications */ 566 [self notifyGrowl: [torrent name]]; 567 if( ![fWindow isKeyWindow] ) 568 { 569 fCompleted++; 570 } 571 } 572 } 573 [fTableView reloadData]; 558 574 559 575 //Update the global DL/UL rates 560 tr_torrentRates( f Handle, &dl, &ul );576 tr_torrentRates( fLib, &dl, &ul ); 561 577 NSString * downloadRate = [NSString stringForSpeed: dl]; 562 578 NSString * uploadRate = [NSString stringForSpeed: ul]; … … 564 580 [fTotalULField setStringValue: uploadRate]; 565 581 582 #if 0 566 583 //Update DL/UL totals in the Info panel 567 584 row = [fTableView selectedRow]; … … 573 590 [NSString stringForFileSize: fStat[row].uploaded]]; 574 591 } 575 576 //check if torrents have recently ended. 577 for (i = 0; i < fCount; i++) 578 { 579 if (fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD)) 580 fDownloading++; 581 else if (fStat[i].status & TR_STATUS_SEED) 582 fSeeding++; 583 584 if( !tr_getFinished( fHandle, i ) ) 585 continue; 586 587 if( ![fWindow isKeyWindow] ) 588 fCompleted++; 589 [self notifyGrowl: [NSString stringWithUTF8String: 590 fStat[i].info.name]]; 591 tr_setFinished( fHandle, i, 0 ); 592 } 592 #endif 593 593 594 594 //badge dock … … 602 602 - (void) updateTorrentHistory 603 603 { 604 if( !fStat)604 if( [fTorrents count] < 1 ) 605 605 return; 606 606 607 NSMutableArray * history = [NSMutableArray arrayWithCapacity: fCount]; 608 609 int i; 610 for (i = 0; i < fCount; i++) 607 NSMutableArray * history = [NSMutableArray 608 arrayWithCapacity: [fTorrents count]]; 609 610 NSEnumerator * enumerator = [fTorrents objectEnumerator]; 611 Torrent * torrent; 612 while( ( torrent = [enumerator nextObject] ) ) 613 { 611 614 [history addObject: [NSDictionary dictionaryWithObjectsAndKeys: 612 [NSString stringWithUTF8String: fStat[i].info.torrent], 613 @"TorrentPath", 614 [NSString stringWithUTF8String: tr_torrentGetFolder( fHandle, i )], 615 @"DownloadFolder", 616 fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD | 617 TR_STATUS_SEED) ? @"NO" : @"YES", 618 @"Paused", 615 [torrent path], @"TorrentPath", 616 [torrent getFolder], @"DownloadFolder", 617 [torrent isActive] ? @"NO" : @"YES", @"Paused", 619 618 nil]]; 619 } 620 620 621 621 [fDefaults setObject: history forKey: @"History"]; … … 624 624 - (int) numberOfRowsInTableView: (NSTableView *) t 625 625 { 626 return fCount;626 return [fTorrents count]; 627 627 } 628 628 … … 630 630 (NSTableColumn *) tableColumn row: (int) rowIndex 631 631 { 632 return NULL; 633 } 634 635 - (void) tableView: (NSTableView *) t willDisplayCell: (id) cell 636 forTableColumn: (NSTableColumn *) tableColumn row: (int) rowIndex 637 { 638 BOOL w; 639 640 w = [fWindow isKeyWindow] && rowIndex == [fTableView selectedRow]; 641 if( [[tableColumn identifier] isEqualToString: @"Name"] ) 642 { 643 [(NameCell *) cell setStat: &fStat[rowIndex] whiteText: w]; 644 } 645 else if( [[tableColumn identifier] isEqualToString: @"Progress"] ) 646 { 647 [(ProgressCell *) cell setStat: &fStat[rowIndex] whiteText: w]; 648 } 632 return [fTorrents objectAtIndex: rowIndex]; 649 633 } 650 634 … … 671 655 return NSDragOperationNone; 672 656 673 [fTableView setDropRow: fCount dropOperation: NSTableViewDropAbove]; 657 [fTableView setDropRow: [fTorrents count] 658 dropOperation: NSTableViewDropAbove]; 674 659 return NSDragOperationGeneric; 675 660 } … … 695 680 } 696 681 682 #if 0 697 683 /* Update info window */ 698 684 [fInfoTitle setStringValue: [NSString stringWithUTF8String: … … 710 696 [fInfoFolder setStringValue: [[NSString stringWithUTF8String: 711 697 tr_torrentGetFolder( fHandle, row )] lastPathComponent]]; 712 698 713 699 if ( fStat[row].seeders == -1 ) { 714 700 [fInfoSeeders setStringValue: [NSString stringWithUTF8String: "?"]]; … … 723 709 fStat[row].leechers]]; 724 710 } 711 #endif 725 712 } 726 713 … … 825 812 if (action == @selector(removeTorrent:)) 826 813 return [fTableView selectedRow] >= 0; 827 814 828 815 829 816 //enable resume all item … … 833 820 //enable pause all item 834 821 if (action == @selector(stopAllTorrents:)) 835 return fDownloading > 0 || fSeeding > 0; 836 822 return fDownloading > 0 || fSeeding > 0; 823 837 824 return YES; 838 825 } … … 840 827 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem 841 828 { 829 #if 0 842 830 SEL action = [menuItem action]; 843 831 … … 845 833 if ([fToolbar customizationPaletteIsRunning]) 846 834 return NO; 847 835 848 836 //enable customize toolbar item 849 837 if (action == @selector(showHideToolbar:)) … … 852 840 return YES; 853 841 } 854 842 855 843 //enable show info 856 844 if (action == @selector(showInfo:)) … … 866 854 //enable pause all item 867 855 if (action == @selector(stopAllTorrents:)) 868 return fDownloading > 0 || fSeeding > 0; 869 856 return fDownloading > 0 || fSeeding > 0; 857 870 858 int row = [fTableView selectedRow]; 871 859 872 860 //enable remove items 873 861 if (action == @selector(removeTorrent:) … … 890 878 return row >= 0; 891 879 } 892 880 893 881 //enable reveal in finder item 894 882 if (action == @selector(revealFromMenu:)) 895 883 return row >= 0; 896 884 897 885 //enable and change pause / remove item 898 886 if (action == @selector(resumeTorrent:) || action == @selector(stopTorrent:)) … … 910 898 return row >= 0; 911 899 } 912 900 #endif 913 901 return YES; 914 902 } … … 917 905 (void *) messageArgument 918 906 { 919 int i; 907 NSEnumerator * enumerator;; 908 Torrent * torrent; 920 909 921 910 switch( messageType ) … … 924 913 /* Close all connections before going to sleep and remember 925 914 we should resume when we wake up */ 926 for( i = 0; i < fCount; i++ ) 915 enumerator = [fTorrents objectEnumerator]; 916 while( ( torrent = [enumerator nextObject] ) ) 927 917 { 928 if( fStat[i].status & ( TR_STATUS_CHECK | 929 TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) ) 918 [torrent sleep]; 919 } 920 921 /* Wait for torrents to stop (5 seconds timeout) */ 922 NSDate * start = [NSDate date]; 923 enumerator = [fTorrents objectEnumerator]; 924 while( ( torrent = [enumerator nextObject] ) ) 925 { 926 while( [[NSDate date] timeIntervalSinceDate: start] < 5 && 927 ![torrent isPaused] ) 930 928 { 931 tr_torrentStop( fHandle, i ); 932 fResumeOnWake[i] = 1; 933 } 934 else 935 { 936 fResumeOnWake[i] = 0; 929 usleep( 100000 ); 930 [torrent update]; 937 931 } 938 932 } 939 933 940 /* TODO: wait a few seconds to let the torrents941 stop properly */942 943 934 IOAllowPowerChange( fRootPort, (long) messageArgument ); 944 935 break; … … 954 945 case kIOMessageSystemHasPoweredOn: 955 946 /* Resume download after we wake up */ 956 for( i = 0; i < fCount; i++ ) 947 enumerator = [fTorrents objectEnumerator]; 948 while( ( torrent = [enumerator nextObject] ) ) 957 949 { 958 if( fResumeOnWake[i] ) 959 { 960 tr_torrentStart( fHandle, i ); 961 } 950 [torrent wakeUp]; 962 951 } 963 952 break; … … 973 962 rectWin = [fWindow frame]; 974 963 rectView = [fScrollView frame]; 975 foo = 25.0 + MAX( 1, fCount ) * ( [fTableView rowHeight] + 976 [fTableView intercellSpacing].height ) - 977 rectView.size.height; 964 foo = 25.0 - rectView.size.height + MAX( 1U, [fTorrents count] ) * 965 ( [fTableView rowHeight] + [fTableView intercellSpacing].height ); 978 966 979 967 rectWin.size.height += foo; … … 1008 996 if( !fHasGrowl ) 1009 997 return; 1010 998 1011 999 growlScript = [NSString stringWithFormat: 1012 1000 @"tell application \"System Events\"\n" … … 1029 1017 1030 1018 - (void) growlRegister: (id) sender 1031 { 1019 { 1032 1020 NSString * growlScript; 1033 1021 NSAppleScript * appleScript; … … 1036 1024 if( !fHasGrowl ) 1037 1025 return; 1038 1026 1039 1027 growlScript = [NSString stringWithFormat: 1040 1028 @"tell application \"System Events\"\n" … … 1048 1036 " end if\n" 1049 1037 "end tell"]; 1050 1038 1051 1039 appleScript = [[NSAppleScript alloc] initWithSource: growlScript]; 1052 1040 if( ![appleScript executeAndReturnError: &error] ) … … 1059 1047 - (void) revealFromMenu: (id) sender 1060 1048 { 1049 #if 0 1061 1050 int row = [fTableView selectedRow]; 1062 1051 if (row >= 0) … … 1066 1055 [NSString stringWithUTF8String: fStat[row].info.name]]]; 1067 1056 } 1057 #endif 1068 1058 } 1069 1059 … … 1073 1063 NSAppleScript * appleScript; 1074 1064 NSDictionary * error; 1075 1065 1076 1066 string = [NSString stringWithFormat: 1077 1067 @"tell application \"Finder\"\n" … … 1142 1132 [fDefaults setObject: [NSDate date] forKey: @"VersionCheckLast"]; 1143 1133 } 1144 1134 1145 1135 - (void) checkForUpdateAuto: (BOOL) automatic 1146 1136 { … … 1151 1141 1152 1142 - (void) URLResourceDidFinishLoading: (NSURL *) sender 1153 { 1143 { 1154 1144 NSDictionary * dict = [NSPropertyListSerialization 1155 1145 propertyListFromData: [sender resourceDataUsingCache: NO] -
branches/new_api/macosx/NameCell.h
r119 r141 1 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining a … … 25 25 26 26 #import <Cocoa/Cocoa.h> 27 #import <transmission.h>28 #import "Controller.h"29 27 30 28 @interface NameCell : NSCell 31 29 { 32 BOOL fWhiteText;33 34 NSString * fNameString;35 NSString * fSizeString;36 NSString * fTimeString;37 NSString * fPeersString;38 39 NSMutableDictionary * fIcons;40 NSImage * fCurrentIcon;41 30 } 42 - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w;43 31 @end 44 32 -
branches/new_api/macosx/NameCell.m
r119 r141 1 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining a … … 22 22 23 23 #import "NameCell.h" 24 #import "Torrent.h" 24 25 #import "StringAdditions.h" 25 26 #import "Utils.h" … … 27 28 @implementation NameCell 28 29 29 - (id) init30 {31 if ((self = [super init]))32 fIcons = [[NSMutableDictionary alloc] initWithCapacity: 10];33 34 return self;35 }36 37 - (void) dealloc38 {39 [fIcons release];40 [super dealloc];41 }42 43 - (NSImage *) iconForFileType: (NSString *) type44 {45 NSImage * icon;46 if (!(icon = [fIcons objectForKey: type]))47 {48 /* Unknown file type, get its icon and cache it */49 icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];50 [icon setFlipped: YES];51 52 [fIcons setObject: icon forKey: type];53 }54 55 return icon;56 }57 58 - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w59 {60 fWhiteText = w;61 62 fNameString = [NSString stringWithUTF8String: stat->info.name];63 fSizeString = [NSString stringWithFormat: @" (%@)",64 [NSString stringForFileSize: stat->info.totalSize]];65 66 fCurrentIcon = [self iconForFileType: stat->info.fileCount > 1 ?67 NSFileTypeForHFSTypeCode('fldr') : [fNameString pathExtension]];68 69 fTimeString = @"";70 fPeersString = @"";71 72 if( stat->status & TR_STATUS_PAUSE )73 {74 fTimeString = [NSString stringWithFormat:75 @"Paused (%.2f %%)", 100 * stat->progress];76 }77 else if( stat->status & TR_STATUS_CHECK )78 {79 fTimeString = [NSString stringWithFormat:80 @"Checking existing files (%.2f %%)", 100 * stat->progress];81 }82 else if( stat->status & TR_STATUS_DOWNLOAD )83 {84 if( stat->eta < 0 )85 {86 fTimeString = [NSString stringWithFormat:87 @"Finishing in --:--:-- (%.2f %%)", 100 * stat->progress];88 }89 else90 {91 fTimeString = [NSString stringWithFormat:92 @"Finishing in %02d:%02d:%02d (%.2f %%)",93 stat->eta / 3600, ( stat->eta / 60 ) % 60,94 stat->eta % 60, 100 * stat->progress];95 }96 fPeersString = [NSString stringWithFormat:97 @"Downloading from %d of %d peer%s",98 stat->peersUploading, stat->peersTotal,99 ( stat->peersTotal == 1 ) ? "" : "s"];100 }101 else if( stat->status & TR_STATUS_SEED )102 {103 fTimeString = [NSString stringWithFormat:104 @"Seeding, uploading to %d of %d peer%s",105 stat->peersDownloading, stat->peersTotal,106 ( stat->peersTotal == 1 ) ? "" : "s"];107 }108 else if( stat->status & TR_STATUS_STOPPING )109 {110 fTimeString = @"Stopping...";111 }112 113 if( ( stat->status & ( TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) ) &&114 ( stat->status & TR_TRACKER_ERROR ) )115 {116 fPeersString = [NSString stringWithFormat: @"%@%@",117 @"Error: ", [NSString stringWithUTF8String: stat->error]];118 }119 }120 121 30 - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view 122 31 { 32 Torrent * torrent = [self objectValue]; 33 123 34 NSString * string; 124 35 NSPoint pen; … … 133 44 float cellWidth = cellFrame.size.width; 134 45 135 pen.x += 5; 136 pen.y += 5;137 [ fCurrentIcon drawAtPoint: pen fromRect:138 NSMakeRect( 0,0,[fCurrentIcon size].width,[fCurrentIcon size].height)46 pen.x += 5; pen.y += 5; 47 NSImage * icon = [torrent icon]; 48 [icon drawAtPoint: pen fromRect: 49 NSMakeRect( 0, 0, [icon size].width, [icon size].height ) 139 50 operation: NSCompositeSourceOver fraction: 1.0]; 140 51 141 52 attributes = [NSMutableDictionary dictionaryWithCapacity: 2]; 142 [attributes setObject: fWhiteText? [NSColor whiteColor] :53 [attributes setObject: /*fWhiteText*/0 ? [NSColor whiteColor] : 143 54 [NSColor blackColor] forKey: NSForegroundColorAttributeName]; 144 55 … … 147 58 148 59 pen.x += 37; 149 string = [[fNameString stringFittingInWidth: cellWidth - 150 72 - [fSizeString sizeWithAttributes: attributes].width 151 withAttributes: attributes] stringByAppendingString: fSizeString]; 60 NSString * sizeString = [NSString stringWithFormat: @" (%@)", 61 [NSString stringForFileSize: [torrent size]]]; 62 string = [[[torrent name] stringFittingInWidth: cellWidth - 63 72 - [sizeString sizeWithAttributes: attributes].width 64 withAttributes: attributes] stringByAppendingString: sizeString]; 152 65 [string drawAtPoint: pen withAttributes: attributes]; 153 66 … … 156 69 157 70 pen.x += 5; pen.y += 20; 158 [ fTimeStringdrawAtPoint: pen withAttributes: attributes];71 [[torrent statusString] drawAtPoint: pen withAttributes: attributes]; 159 72 160 73 pen.x += 0; pen.y += 15; 161 string = [ fPeersString stringFittingInWidth: cellFrame.size.width -162 77withAttributes: attributes];74 string = [[torrent infoString] stringFittingInWidth: 75 ( cellFrame.size.width - 77 ) withAttributes: attributes]; 163 76 [string drawAtPoint: pen withAttributes: attributes]; 164 77 -
branches/new_api/macosx/ProgressCell.h
r34 r141 1 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining a … … 25 25 26 26 #import <Cocoa/Cocoa.h> 27 #import <transmission.h>28 27 29 28 @interface ProgressCell : NSCell 30 29 { 31 tr_stat_t * fStat;32 BOOL fWhiteText;33 34 NSString * fDlString;35 NSString * fUlString;36 37 NSBitmapImageRep * fBackgroundBmp;38 NSBitmapImageRep * fProgressBmp;39 30 } 40 - (id) init;41 - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w;42 - (void) buildSimpleBar;43 - (void) buildAdvancedBar;44 - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view;45 31 @end 46 32 -
branches/new_api/macosx/ProgressCell.m
r94 r141 1 1 /****************************************************************************** 2 * Copyright (c) 2005 Eric Petit2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 3 * 4 4 * Permission is hereby granted, free of charge, to any person obtaining a … … 81 81 0x00ED00FF, 0x00F200FF, 0x00F400FF, 0x00B500FF }; 82 82 83 #if 0 83 84 /*********************************************************************** 84 85 * init … … 259 260 } 260 261 } 262 #endif 261 263 262 264 /*********************************************************************** … … 268 270 - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view 269 271 { 272 #if 0 270 273 NSImage * img; 271 274 NSMutableDictionary * attributes; … … 308 311 309 312 [view unlockFocus]; 313 #endif 310 314 } 311 315 -
branches/new_api/macosx/TorrentTableView.m
r34 r141 1 /****************************************************************************** 2 * Copyright (c) 2005-2006 Transmission authors and contributors 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 *****************************************************************************/ 22 1 23 #import "TorrentTableView.h" 2 24 #import "Controller.h" … … 88 110 else if( [self pointInRevealRect: point] ) 89 111 { 112 #if 0 90 113 [fController finderReveal: [NSString stringWithFormat: 91 114 @"%@/%@", [NSString stringWithUTF8String: fStat[row].folder], 92 115 [NSString stringWithUTF8String: fStat[row].info.name]]]; 93 116 [self display]; 117 #endif 94 118 } 95 119 else if( row >= 0 && col == [self columnWithIdentifier: @"Progress"] 96 120 && ( [e modifierFlags] & NSAlternateKeyMask ) ) 97 121 { 98 [fController advancedChanged: NULL];122 [fController advancedChanged: nil]; 99 123 } 100 124 else -
branches/new_api/macosx/Transmission.xcodeproj/project.pbxproj
r103 r141 37 37 4DF7500D08A103AD007B0D70 /* Info.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DF7500808A103AD007B0D70 /* Info.png */; }; 38 38 4DF7500E08A103AD007B0D70 /* Remove.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DF7500908A103AD007B0D70 /* Remove.png */; }; 39 4DFBC2DF09C0970D00D5C571 /* Torrent.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DFBC2DE09C0970D00D5C571 /* Torrent.m */; }; 39 40 8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; }; 40 41 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; … … 115 116 4DF7500808A103AD007B0D70 /* Info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Info.png; path = Images/Info.png; sourceTree = "<group>"; }; 116 117 4DF7500908A103AD007B0D70 /* Remove.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Remove.png; path = Images/Remove.png; sourceTree = "<group>"; }; 118 4DFBC2DD09C0970D00D5C571 /* Torrent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Torrent.h; sourceTree = "<group>"; }; 119 4DFBC2DE09C0970D00D5C571 /* Torrent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Torrent.m; sourceTree = "<group>"; }; 117 120 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; }; 118 121 8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; }; … … 150 153 4DE5CCA50980735700BE280E /* Badger.h */, 151 154 4DE5CCA60980735700BE280E /* Badger.m */, 155 4DFBC2DD09C0970D00D5C571 /* Torrent.h */, 156 4DFBC2DE09C0970D00D5C571 /* Torrent.m */, 152 157 ); 153 158 name = Classes; … … 340 345 4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */, 341 346 4DE5CCA70980735700BE280E /* Badger.m in Sources */, 347 4DFBC2DF09C0970D00D5C571 /* Torrent.m in Sources */, 342 348 ); 343 349 runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset
for help on using the changeset viewer.