Ignore:
Timestamp:
Jun 6, 2006, 6:05:57 PM (15 years ago)
Author:
livings124
Message:

First commit on my own 8-)

Sorting by progress, sorting no longer causes crashes.
New look for the table.
Info is now inspector: can set individual and multiple ratio limits, shows listing of files, more info in general, resizes when changing tabs, can change tabs with cmd-left and cmd-right.
Menu items moved to "Transfers" menu.
Sliding status bar in its own view.
Prefs moved into their own nib.
Toolbar items for pause and resume selected (many wanted this, but it needs better icons)
New icons for Transfers and General.
A lot of tweaking of main window to fix alignment etc.
Sparkle used for updated (still needs to be added to website to work).

And a lot more tweaking and changes that I'm too lazy to list.

...now let's hope I commit this right

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PrefsController.m

    r261 r272  
    2727#import "Utils.h"
    2828
     29#define MIN_PORT            1
     30#define MAX_PORT            65535
     31
    2932#define DOWNLOAD_FOLDER     0
    3033#define DOWNLOAD_TORRENT    2
     
    3639
    3740#define TOOLBAR_GENERAL     @"General"
    38 #define TOOLBAR_TRANSFERS    @"Transfers"
     41#define TOOLBAR_TRANSFERS   @"Transfers"
    3942#define TOOLBAR_NETWORK     @"Network"
    4043
     
    7477    [fToolbar setDelegate: self];
    7578    [fToolbar setAllowsUserCustomization: NO];
    76     [fPrefsWindow setToolbar: fToolbar];
     79    [[self window] setToolbar: fToolbar];
    7780    [fToolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
    7881    [fToolbar setSizeMode: NSToolbarSizeModeRegular];
     
    8992    [fDownloadFolder retain];
    9093
    91     if( [downloadChoice isEqualToString: @"Constant"] )
    92     {
     94    if ([downloadChoice isEqualToString: @"Constant"])
    9395        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
    94     }
    95     else if( [downloadChoice isEqualToString: @"Torrent"] )
    96     {
     96    else if ([downloadChoice isEqualToString: @"Torrent"])
    9797        [fFolderPopUp selectItemAtIndex: DOWNLOAD_TORRENT];
    98     }
    99     else
    100     {
     98    else
    10199        [fFolderPopUp selectItemAtIndex: DOWNLOAD_ASK];
    102     }
    103100    [self updatePopUp];
    104101
     
    124121    [fUploadField setEnabled: checkUpload];
    125122   
    126     [fUploadLimitItem setTitle:
    127                 [NSString stringWithFormat: @"Limit (%d KB/s)", uploadLimit]];
    128     if (checkUpload)
    129         [fUploadLimitItem setState: NSOnState];
    130     else
    131         [fUploadNoLimitItem setState: NSOnState];
    132    
    133123    tr_setUploadLimit( fHandle, checkUpload ? uploadLimit : -1 );
    134124
     
    141131    [fDownloadField setEnabled: checkDownload];
    142132   
    143     [fDownloadLimitItem setTitle:
    144                 [NSString stringWithFormat: @"Limit (%d KB/s)", downloadLimit]];
    145     if (checkDownload)
    146         [fDownloadLimitItem setState: NSOnState];
    147     else
    148         [fDownloadNoLimitItem setState: NSOnState];
    149    
    150133    tr_setDownloadLimit( fHandle, checkDownload ? downloadLimit : -1 );
    151134   
    152135    //set ratio limit
    153136    BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"];
    154     float ratioLimit = [fDefaults floatForKey: @"RatioLimit"];
    155 
    156137    [fRatioCheck setState: ratioCheck ? NSOnState : NSOffState];
    157138    [fRatioField setEnabled: ratioCheck];
    158     [fRatioField setFloatValue: ratioLimit];
    159    
    160     [fRatioSetItem setTitle: [NSString stringWithFormat: @"Stop at Ratio (%.1f)", ratioLimit]];
    161     if (ratioCheck)
    162         [fRatioSetItem setState: NSOnState];
    163     else
    164         [fRatioNotSetItem setState: NSOnState];
     139    [fRatioField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
    165140   
    166141    //set remove and quit prompts
     
    177152    [fAutoStartCheck setState: [fDefaults boolForKey: @"AutoStartDownload"]];
    178153
    179     /* Check for update */
    180     NSString * versionCheck  = [fDefaults stringForKey: @"VersionCheck"];
    181     if( [versionCheck isEqualToString: @"Daily"] )
     154    //set update check
     155    NSString * updateCheck = [fDefaults stringForKey: @"UpdateCheck"];
     156    if ([updateCheck isEqualToString: @"Weekly"])
     157        [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
     158    else if ([updateCheck isEqualToString: @"Never"])
     159        [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
     160    else
    182161        [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
    183     else if( [versionCheck isEqualToString: @"Weekly"] )
    184         [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
    185     else if( [versionCheck isEqualToString: @"Never"] )
    186         [fUpdatePopUp selectItemAtIndex: UPDATE_NEVER];
    187     else
    188     {
    189         [fDefaults setObject: @"Weekly" forKey: @"VersionCheck"];
    190         [fUpdatePopUp selectItemAtIndex: UPDATE_WEEKLY];
    191     }
    192162}
    193163
     
    247217- (void) setPort: (id) sender
    248218{
    249     int bindPort = [fPortField intValue];
    250    
    251     tr_setBindPort( fHandle, bindPort );
    252     [fDefaults setInteger: bindPort forKey: @"BindPort"];
     219    int bindPort = [sender intValue];
     220    if (![[NSString stringWithInt: bindPort] isEqualToString: [sender stringValue]]
     221            || bindPort < MIN_PORT || bindPort > MAX_PORT)
     222    {
     223        NSBeep();
     224        bindPort = [fDefaults integerForKey: @"BindPort"];
     225        [sender setIntValue: bindPort];
     226    }
     227    else
     228    {
     229        tr_setBindPort( fHandle, bindPort );
     230        [fDefaults setInteger: bindPort forKey: @"BindPort"];
     231    }
    253232}
    254233
     
    256235{
    257236    NSString * key;
    258     NSMenuItem * menuItem;
     237    NSButton * check;
     238    NSString * type;
    259239    if (sender == fUploadField)
    260240    {
    261241        key = @"UploadLimit";
    262         menuItem = fUploadLimitItem;
     242        check = fUploadCheck;
     243        type = @"Upload";
    263244    }
    264245    else
    265246    {
    266247        key = @"DownloadLimit";
    267         menuItem = fDownloadLimitItem;
     248        check = fDownloadCheck;
     249        type = @"Download";
    268250    }
    269251
    270252    int limit = [sender intValue];
    271     [fDefaults setInteger: limit forKey: key];
    272    
    273     [menuItem setTitle: [NSString stringWithFormat: @"Limit (%d KB/s)", limit]];
    274 
    275     if( sender == fUploadField )
    276         tr_setUploadLimit( fHandle,
    277             ( [fUploadCheck state] == NSOffState ) ? -1 : limit );
    278     else
    279         tr_setDownloadLimit( fHandle,
    280             ( [fDownloadCheck state] == NSOffState ) ? -1 : limit );
     253    if (![[sender stringValue] isEqualToString:
     254            [NSString stringWithFormat: @"%d", limit]]
     255            || limit < 0)
     256    {
     257        NSBeep();
     258        limit = [fDefaults integerForKey: key];
     259        [sender setIntValue: limit];
     260    }
     261    else
     262    {
     263        if( sender == fUploadField )
     264            tr_setUploadLimit( fHandle,
     265                ( [fUploadCheck state] == NSOffState ) ? -1 : limit );
     266        else
     267            tr_setDownloadLimit( fHandle,
     268                ( [fDownloadCheck state] == NSOffState ) ? -1 : limit );
     269       
     270        [fDefaults setInteger: limit forKey: key];
     271    }
     272   
     273    NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
     274                                    [NSNumber numberWithBool: [check state]], @"Enable",
     275                                    [NSNumber numberWithInt: limit], @"Limit",
     276                                    type, @"Type", nil];
     277    [[NSNotificationCenter defaultCenter] postNotificationName:
     278                            @"LimitGlobalChange" object: dict];
    281279}
    282280
     
    285283    NSString * key;
    286284    NSTextField * field;
    287     NSMenuItem * limitItem, * noLimitItem;
    288     if( sender == fUploadCheck )
     285    if (sender == fUploadCheck)
    289286    {
    290287        key = @"CheckUpload";
    291288        field = fUploadField;
    292         limitItem = fUploadLimitItem;
    293         noLimitItem = fUploadNoLimitItem;
    294289    }
    295290    else
     
    297292        key = @"CheckDownload";
    298293        field = fDownloadField;
    299         limitItem = fDownloadLimitItem;
    300         noLimitItem = fDownloadNoLimitItem;
    301     }
    302 
     294    }
     295   
    303296    BOOL check = [sender state] == NSOnState;
    304     [limitItem setState: check ? NSOnState : NSOffState];
    305     [noLimitItem setState: !check ? NSOnState : NSOffState];
     297    [self setLimit: field];
     298    [field setEnabled: check];
    306299   
    307300    [fDefaults setBool: check forKey: key];
    308    
    309     [field setIntValue: [field intValue]]; //set to valid value
    310     [self setLimit: field];
    311    
    312     [field setEnabled: check];
    313 }
    314 
    315 - (void) setLimitMenu: (id) sender
    316 {
    317     NSButton * check = (sender == fUploadLimitItem || sender == fUploadNoLimitItem)
     301}
     302
     303- (void) setLimitEnabled: (BOOL) enable type: (NSString *) type
     304{
     305    NSButton * check = [type isEqualToString: @"Upload"]
    318306                        ? fUploadCheck : fDownloadCheck;
    319     int state = (sender == fUploadLimitItem || sender == fDownloadLimitItem)
    320                     ? NSOnState : NSOffState;
    321                
    322     [check setState: state];
     307    [check setState: enable ? NSOnState : NSOffState];
    323308    [self setLimitCheck: check];
    324309}
    325310
    326 - (void) setQuickSpeed: (id) sender
    327 {
    328     NSString * title = [sender title];
    329     int limit = [[title substringToIndex: [title length] - [@" KB/s" length]] intValue];
    330    
    331     if ([sender menu] == fUploadMenu)
     311- (void) setQuickLimit: (int) limit type: (NSString *) type
     312{
     313    NSButton * check;
     314    if ([type isEqualToString: @"Upload"])
    332315    {
    333316        [fUploadField setIntValue: limit];
    334         [self setLimitMenu: fUploadLimitItem];
     317        check = fUploadCheck;
    335318    }
    336319    else
    337320    {
    338321        [fDownloadField setIntValue: limit];
    339         [self setLimitMenu: fDownloadLimitItem];
    340     }
     322        check = fDownloadCheck;
     323    }
     324    [check setState: NSOnState];
     325    [self setLimitCheck: check];
    341326}
    342327
    343328- (void) setRatio: (id) sender
    344329{
    345     float ratio = [sender floatValue];
    346     [fDefaults setFloat: ratio forKey: @"RatioLimit"];
    347    
    348     [fRatioSetItem setTitle: [NSString stringWithFormat: @"Stop at Ratio (%.1f)", ratio]];
     330    float ratioLimit = [sender floatValue];
     331    if (![[sender stringValue] isEqualToString:
     332            [NSString stringWithFormat: @"%.2f", ratioLimit]]
     333            || ratioLimit < 0)
     334    {
     335        NSBeep();
     336        ratioLimit = [fDefaults floatForKey: @"RatioLimit"];
     337        [sender setFloatValue: ratioLimit];
     338    }
     339    else
     340        [fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
     341   
     342    NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
     343                                    [NSNumber numberWithBool: [fRatioCheck state]], @"Enable",
     344                                    [NSNumber numberWithFloat: ratioLimit], @"Ratio", nil];
     345    [[NSNotificationCenter defaultCenter] postNotificationName:
     346                                @"RatioGlobalChange" object: dict];
    349347}
    350348
     
    352350{
    353351    BOOL check = [sender state] == NSOnState;
     352    [self setRatio: fRatioField];
     353    [fRatioField setEnabled: check];
    354354   
    355355    [fDefaults setBool: check forKey: @"RatioCheck"];
    356    
    357     [fRatioField setFloatValue: [fRatioField floatValue]]; //set to valid value
    358     [self setRatio: fRatioField];
    359    
    360     [fRatioField setEnabled: check];
    361    
    362     [fRatioSetItem setState: check ? NSOnState : NSOffState];
    363     [fRatioNotSetItem setState: !check ? NSOnState : NSOffState];
    364 }
    365 
    366 - (void) setRatioMenu: (id) sender
    367 {
    368     int state = sender == fRatioSetItem ? NSOnState : NSOffState;
    369                
     356}
     357
     358- (void) setRatioEnabled: (BOOL) enable
     359{
     360    int state = enable ? NSOnState : NSOffState;
     361   
    370362    [fRatioCheck setState: state];
    371363    [self setRatioCheck: fRatioCheck];
    372364}
    373365
    374 - (void) setQuickRatio: (id) sender
    375 {
    376     float limit = [[sender title] floatValue];
    377 
    378     [fRatioField setFloatValue: limit];
    379     [self setRatioMenu: fRatioSetItem];
     366- (void) setQuickRatio: (float) ratioLimit
     367{
     368    [fRatioField setFloatValue: ratioLimit];
     369   
     370    [fRatioCheck setState: NSOnState];
     371    [self setRatioCheck: fRatioCheck];
    380372}
    381373
     
    400392- (void) setUpdate: (id) sender
    401393{
    402     switch( [fUpdatePopUp indexOfSelectedItem] )
    403     {
    404         case UPDATE_DAILY:
    405             [fDefaults setObject: @"Daily" forKey: @"VersionCheck"];
    406             break;
    407         case UPDATE_WEEKLY:
    408             [fDefaults setObject: @"Weekly" forKey: @"VersionCheck"];
    409             break;
    410         case UPDATE_NEVER:
    411             [fDefaults setObject: @"Never" forKey: @"VersionCheck"];
    412             break;
    413     }
     394    NSString * schedule;
     395    int index = [fUpdatePopUp indexOfSelectedItem];
     396    NSTimeInterval seconds;
     397    if (index == UPDATE_DAILY)
     398    {
     399        [fDefaults setObject: @"Daily" forKey: @"UpdateCheck"];
     400        seconds = 86400;
     401    }
     402    else if (index == UPDATE_WEEKLY)
     403    {
     404        [fDefaults setObject: @"Weekly" forKey: @"UpdateCheck"];
     405        seconds = 604800;
     406    }
     407    else
     408    {
     409        [fDefaults setObject: @"Never" forKey: @"UpdateCheck"];
     410        seconds = 0;
     411    }
     412
     413    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
     414    [fUpdater scheduleCheckWithInterval: seconds];
    414415}
    415416
     
    436437}
    437438
     439- (void) checkUpdate
     440{
     441    [fUpdater checkForUpdates: nil];
     442}
     443
    438444- (void) folderSheetShow: (id) sender
    439445{
     
    446452
    447453    [panel beginSheetForDirectory: NULL file: NULL types: NULL
    448         modalForWindow: fPrefsWindow modalDelegate: self didEndSelector:
     454        modalForWindow: [self window] modalDelegate: self didEndSelector:
    449455        @selector( folderSheetClosed:returnCode:contextInfo: )
    450456        contextInfo: NULL];
    451457}
    452458
    453 @end // @implementation PrefsController
     459@end
    454460
    455461@implementation PrefsController (Private)
     
    472478- (void) setPrefView: (NSView *) view
    473479{
    474     NSRect windowRect = [fPrefsWindow frame];
    475     int difference = [view frame].size.height - [[fPrefsWindow contentView] frame].size.height;
    476 
     480    NSWindow * window = [self window];
     481   
     482    NSRect windowRect = [window frame];
     483    int difference = [view frame].size.height - [[window contentView] frame].size.height;
    477484    windowRect.origin.y -= difference;
    478485    windowRect.size.height += difference;
    479    
    480     [fPrefsWindow setTitle: [fToolbar selectedItemIdentifier]];
    481     [fPrefsWindow setContentView: fBlankView];
    482     [fPrefsWindow setFrame: windowRect display: YES animate: YES];
    483     [fPrefsWindow setContentView: view];
     486
     487    [window setTitle: [fToolbar selectedItemIdentifier]];
     488   
     489    [window setContentView: view];
     490    [view setHidden: YES];
     491    [window setFrame: windowRect display: YES animate: YES];
     492    [view setHidden: NO];
    484493}
    485494
     
    520529- (void) updatePopUp
    521530{
    522     NSMenuItem     * menuItem;
    523     NSImage        * image32, * image16;
    524 
    525531    // Get the icon for the folder
    526     image32 = [[NSWorkspace sharedWorkspace] iconForFile:
     532    NSImage * image32 = [[NSWorkspace sharedWorkspace] iconForFile:
    527533                fDownloadFolder];
    528     image16 = [[NSImage alloc] initWithSize: NSMakeSize(16,16)];
     534    NSImage * image16 = [[NSImage alloc] initWithSize: NSMakeSize(16,16)];
    529535
    530536    // 32x32 -> 16x16 scaling
     
    538544
    539545    // Update the menu item
    540     menuItem = (NSMenuItem *) [fFolderPopUp itemAtIndex: 0];
     546    NSMenuItem * menuItem = (NSMenuItem *) [fFolderPopUp itemAtIndex: 0];
    541547    [menuItem setTitle: [fDownloadFolder lastPathComponent]];
    542548    [menuItem setImage: image16];
     
    545551}
    546552
    547 @end /* @implementation PrefsController (Private) */
     553@end
Note: See TracChangeset for help on using the changeset viewer.