Changeset 1030 for trunk/macosx


Ignore:
Timestamp:
Oct 25, 2006, 2:57:00 AM (15 years ago)
Author:
livings124
Message:

load prefs when first used as opposed to at launch

Location:
trunk/macosx
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r1013 r1030  
    9191    NSTimer                         * fTimer;
    9292   
     93    IBOutlet SUUpdater              * fUpdater;
    9394    BOOL                            fUpdateInProgress;
     95   
    9496    Badger                          * fBadger;
    9597   
     
    201203- (void) linkForums:        (id) sender;
    202204
    203 - (void) checkUpdate:       (id) sender;
    204205- (void) prepareForUpdate:  (NSNotification *) notification;
    205206
  • trunk/macosx/Controller.m

    r1027 r1030  
    206206    [fSpeedLimitButton setToolTip: NSLocalizedString(@"Speed Limit overrides the total bandwidth limits with its own limits.",
    207207                                "Main window -> 2nd bottom left button (turtle) tooltip")];
    208 
     208   
     209    [fPrefsController setUpdater: fUpdater];
     210   
    209211    [fTableView setTorrents: fDisplayedTorrents];
    210212    [[fTableView tableColumnWithIdentifier: @"Torrent"] setDataCell: [[TorrentCell alloc] init]];
     
    13631365- (void) setLimitGlobalEnabled: (id) sender
    13641366{
    1365     [fPrefsController setLimitEnabled: (sender == fUploadLimitItem || sender == fDownloadLimitItem)
     1367    [fPrefsController setQuickLimitEnabled: (sender == fUploadLimitItem || sender == fDownloadLimitItem)
    13661368        type: (sender == fUploadLimitItem || sender == fUploadNoLimitItem) ? @"Upload" : @"Download"];
    13671369}
     
    13751377- (void) limitGlobalChange: (NSNotification *) notification
    13761378{
    1377     NSDictionary * dict = [notification object];
    1378    
    13791379    NSMenuItem * limitItem, * noLimitItem;
    1380     if ([[dict objectForKey: @"Type"] isEqualToString: @"Upload"])
     1380    BOOL enable;
     1381    int limit;
     1382    if ([[notification object] boolValue])
    13811383    {
    13821384        limitItem = fUploadLimitItem;
    13831385        noLimitItem = fUploadNoLimitItem;
     1386       
     1387        enable = [fDefaults boolForKey: @"CheckUpload"];
     1388        limit = [fDefaults integerForKey: @"UploadLimit"];
    13841389    }
    13851390    else
     
    13871392        limitItem = fDownloadLimitItem;
    13881393        noLimitItem = fDownloadNoLimitItem;
    1389     }
    1390    
    1391     BOOL enable = [[dict objectForKey: @"Enable"] boolValue];
     1394       
     1395        enable = [fDefaults boolForKey: @"CheckDownload"];
     1396        limit = [fDefaults integerForKey: @"DownloadLimit"];
     1397    }
     1398   
    13921399    [limitItem setState: enable ? NSOnState : NSOffState];
    13931400    [noLimitItem setState: !enable ? NSOnState : NSOffState];
    13941401   
    13951402    [limitItem setTitle: [NSString stringWithFormat: NSLocalizedString(@"Limit (%d KB/s)",
    1396                             "Action context menu -> upload/download limit"), [[dict objectForKey: @"Limit"] intValue]]];
    1397 
    1398     [dict release];
     1403                            "Action context menu -> upload/download limit"), limit]];
     1404   
     1405    [[notification object] release];
    13991406}
    14001407
    14011408- (void) setRatioGlobalEnabled: (id) sender
    14021409{
    1403     [fPrefsController setRatioEnabled: sender == fRatioSetItem];
     1410    [fPrefsController setQuickRatioEnabled: sender == fRatioSetItem];
    14041411}
    14051412
     
    14111418- (void) ratioGlobalChange: (NSNotification *) notification
    14121419{
    1413     NSDictionary * dict = [notification object];
    1414    
    1415     BOOL enable = [[dict objectForKey: @"Enable"] boolValue];
     1420    BOOL enable = [fDefaults boolForKey: @"RatioCheck"];
    14161421    [fRatioSetItem setState: enable ? NSOnState : NSOffState];
    14171422    [fRatioNotSetItem setState: !enable ? NSOnState : NSOffState];
    14181423   
    14191424    [fRatioSetItem setTitle: [NSString stringWithFormat: NSLocalizedString(@"Stop at Ratio (%.2f)",
    1420                                 "Action context menu -> ratio stop"), [[dict objectForKey: @"Ratio"] floatValue]]];
    1421 
    1422     [dict release];
     1425                                "Action context menu -> ratio stop"), [fDefaults floatForKey: @"RatioLimit"]]];
    14231426}
    14241427
     
    24492452}
    24502453
    2451 - (void) checkUpdate: (id) sender
    2452 {
    2453     [fPrefsController checkUpdate];
    2454 }
    2455 
    24562454- (void) prepareForUpdate: (NSNotification *) notification
    24572455{
  • trunk/macosx/English.lproj/MainMenu.nib/classes.nib

    r923 r1030  
    55            ACTIONS = {
    66                applyFilter = id;
    7                 checkUpdate = id;
    87                copyTorrentFile = id;
    98                linkForums = id;
     
    8079                fTotalTorrentsField = NSTextField;
    8180                fTotalULField = NSTextField;
     81                fUpdater = SUUpdater;
    8282                fUploadLimitItem = NSMenuItem;
    8383                fUploadMenu = NSMenu;
  • trunk/macosx/English.lproj/MainMenu.nib/info.nib

    r1025 r1030  
    1414                <string>337 545 477 67 0 0 1152 842 </string>
    1515                <key>29</key>
    16                 <string>229 615 451 44 0 0 1024 746 </string>
     16                <string>280 699 451 44 0 0 1152 842 </string>
    1717                <key>456</key>
    1818                <string>340 316 240 225 0 0 1024 746 </string>
     
    3030        <key>IBOpenObjects</key>
    3131        <array>
     32                <integer>29</integer>
    3233                <integer>21</integer>
    33                 <integer>29</integer>
    3434        </array>
    3535        <key>IBSystem Version</key>
  • trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib

    r956 r1030  
    7474                fTransfersView = NSView;
    7575                fUpdatePopUp = NSPopUpButton;
    76                 fUpdater = SUUpdater;
    7776                fUploadCheck = NSButton;
    7877                fUploadField = NSTextField;
  • trunk/macosx/English.lproj/PrefsWindow.nib/info.nib

    r974 r1030  
    1414                <string>213 415 563 317 0 0 1152 842 </string>
    1515                <key>66</key>
    16                 <string>162 503 563 144 0 0 1152 842 </string>
     16                <string>294 507 563 144 0 0 1152 842 </string>
    1717        </dict>
    1818        <key>IBFramework Version</key>
     
    2222                <integer>253</integer>
    2323        </array>
    24         <key>IBOpenObjects</key>
    25         <array>
    26                 <integer>66</integer>
    27         </array>
    2824        <key>IBSystem Version</key>
    2925        <string>8L127</string>
  • trunk/macosx/PrefsController.h

    r957 r1030  
    4343                            * fCopyTorrentCheck, * fDeleteOriginalTorrentCheck,
    4444                            * fAutoImportCheck, * fAutoSizeCheck;
    45                            
     45   
     46    SUUpdater               * fUpdater;
    4647    IBOutlet NSPopUpButton  * fUpdatePopUp;
    4748
     
    6465    IBOutlet NSButton       * fQueueCheck, * fStartAtOpenCheck;
    6566    IBOutlet NSTextField    * fQueueNumberField;
    66    
    67     IBOutlet SUUpdater      * fUpdater;
    6867
    6968    NSString                * fDownloadFolder, * fImportFolder;
     
    7271
    7372- (id) initWithWindowNibName: (NSString *) name handle: (tr_handle_t *) handle;
     73- (void) setUpdater: (SUUpdater *) updater;
    7474
    7575- (void) setShowMessage:    (id) sender;
     
    7878- (void) setSound:          (id) sender;
    7979- (void) setUpdate:         (id) sender;
    80 - (void) checkUpdate;
    8180
    8281- (void) setStartAtOpen:    (id) sender;
     
    102101- (void) setLimit:          (id) sender;
    103102- (void) setLimitCheck:     (id) sender;
    104 - (void) setLimitEnabled:   (BOOL) enable type: (NSString *) type;
     103- (void) setQuickLimitEnabled:   (BOOL) enable type: (NSString *) type;
    105104- (void) setQuickLimit:     (int) limit type: (NSString *) type;
    106105
     
    114113- (void) setRatio:          (id) sender;
    115114- (void) setRatioCheck:     (id) sender;
    116 - (void) setRatioEnabled:   (BOOL) enable;
     115- (void) setQuickRatioEnabled:   (BOOL) enable;
    117116- (void) setQuickRatio: (float) ratioLimit;
    118117
  • trunk/macosx/PrefsController.m

    r1029 r1030  
    7171        }
    7272       
    73         [[self window] update]; //make sure nib is loaded right away
     73        //set download folder and import folder
     74        fDownloadFolder = [[[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath] retain];
     75        fImportFolder = [[[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath] retain];
     76       
     77        //set auto import
     78        if ([fDefaults boolForKey: @"AutoImport"])
     79            [[UKKQueue sharedFileWatcher] addPath: fImportFolder];
     80       
     81        //set bind port
     82        int bindPort = [fDefaults integerForKey: @"BindPort"];
     83        tr_setBindPort(fHandle, bindPort);
     84       
     85        //set NAT
     86        if ([fDefaults boolForKey: @"NatTraversal"])
     87            tr_natTraversalEnable(fHandle);
     88       
     89        //actually set bandwidth limits
     90        if ([fDefaults boolForKey: @"SpeedLimit"])
     91        {
     92            tr_setUploadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
     93            tr_setDownloadLimit(fHandle, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
     94        }
     95        else
     96        {
     97            tr_setUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
     98                                            ? [fDefaults integerForKey: @"UploadLimit"] : -1);
     99            tr_setDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
     100                                            ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
     101        }
    74102    }
    75103    return self;
     
    78106- (void) dealloc
    79107{
    80     [fNatStatusTimer invalidate];
     108    if (fNatStatusTimer)
     109        [fNatStatusTimer invalidate];
    81110
    82111    [fDownloadFolder release];
     
    99128    //set download folder
    100129    NSString * downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
    101     fDownloadFolder = [[[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath] retain];
    102130    if ([downloadChoice isEqualToString: @"Constant"])
    103131        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
     
    109137   
    110138    //set auto import
    111     fImportFolder = [[[fDefaults stringForKey: @"AutoImportDirectory"] stringByExpandingTildeInPath] retain];
    112139    [self updateImportPopUp];
    113140 
     
    116143    [fImportFolderPopUp setEnabled: autoImport];
    117144   
    118     if (autoImport)
    119         [[UKKQueue sharedFileWatcher] addPath: fImportFolder];
    120    
    121145    //set auto size
    122146    [fAutoSizeCheck setState: [fDefaults boolForKey: @"AutoSize"]];
     
    125149    int bindPort = [fDefaults integerForKey: @"BindPort"];
    126150    [fPortField setIntValue: bindPort];
    127     tr_setBindPort(fHandle, bindPort);
    128    
    129151    [self updatePortStatus];
    130152   
    131153    //set NAT
    132     BOOL natShouldEnable = [fDefaults boolForKey: @"NatTraversal"];
    133     if (natShouldEnable)
    134         tr_natTraversalEnable(fHandle);
    135     [fNatCheck setState: natShouldEnable];
     154    [fNatCheck setState: [fDefaults boolForKey: @"NatTraversal"]];
    136155   
    137156    fNatStatus = -1;
     
    142161    //set upload limit
    143162    BOOL checkUpload = [fDefaults boolForKey: @"CheckUpload"];
    144     int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
    145    
    146163    [fUploadCheck setState: checkUpload];
    147     [fUploadField setIntValue: uploadLimit];
     164    [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
    148165    [fUploadField setEnabled: checkUpload];
    149166
    150167        //set download limit
    151168    BOOL checkDownload = [fDefaults boolForKey: @"CheckDownload"];
    152     int downloadLimit = [fDefaults integerForKey: @"DownloadLimit"];
    153    
    154169    [fDownloadCheck setState: checkDownload];
    155     [fDownloadField setIntValue: downloadLimit];
     170    [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
    156171    [fDownloadField setEnabled: checkDownload];
    157172   
    158173    //set speed limit
    159     int speedLimitUploadLimit = [fDefaults integerForKey: @"SpeedLimitUploadLimit"];
    160     [fSpeedLimitUploadField setIntValue: speedLimitUploadLimit];
    161    
    162     int speedLimitDownloadLimit = [fDefaults integerForKey: @"SpeedLimitDownloadLimit"];
    163     [fSpeedLimitDownloadField setIntValue: speedLimitDownloadLimit];
    164    
    165     //actually set bandwidth limits
    166     if ([fDefaults boolForKey: @"SpeedLimit"])
    167     {
    168         tr_setUploadLimit(fHandle, speedLimitUploadLimit);
    169         tr_setDownloadLimit(fHandle, speedLimitDownloadLimit);
    170     }
    171     else
    172     {
    173         tr_setUploadLimit(fHandle, checkUpload ? uploadLimit : -1);
    174         tr_setDownloadLimit(fHandle, checkDownload ? downloadLimit : -1);
    175     }
     174    [fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]];
     175    [fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]];
    176176   
    177177    //set auto speed limit
     
    279279    else
    280280        [fUpdatePopUp selectItemAtIndex: UPDATE_DAILY];
     281}
     282
     283- (void) setUpdater: (SUUpdater *) updater
     284{
     285    fUpdater = updater;
    281286}
    282287
     
    482487    }
    483488   
    484     NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
    485                                     [NSNumber numberWithBool: [check state]], @"Enable",
    486                                     [NSNumber numberWithInt: limit], @"Limit",
    487                                     type, @"Type", nil];
    488     [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange" object: dict];
     489    [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange"
     490                                            object: [[NSNumber alloc] initWithBool: sender == fUploadField]];
    489491}
    490492
     
    511513}
    512514
    513 - (void) setLimitEnabled: (BOOL) enable type: (NSString *) type
    514 {
    515     NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck;
    516     [check setState: enable ? NSOnState : NSOffState];
    517     [self setLimitCheck: check];
     515- (void) setQuickLimitEnabled: (BOOL) enable type: (NSString *) type
     516{
     517    //if interface is loaded, perform change as if user performed it
     518    #warning better way?
     519    if (fToolbar)
     520    {
     521        NSButton * check = [type isEqualToString: @"Upload"] ? fUploadCheck : fDownloadCheck;
     522        [check setState: enable ? NSOnState : NSOffState];
     523        [self setLimitCheck: check];
     524    }
     525    else
     526    {
     527        BOOL upload = [type isEqualToString: @"Upload"];
     528        [fDefaults setBool: enable forKey: upload ? @"CheckUpload" : @"CheckDownload"];
     529       
     530        [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange"
     531                                                object: [[NSNumber alloc] initWithBool: upload]];
     532    }
    518533}
    519534
    520535- (void) setQuickLimit: (int) limit type: (NSString *) type
    521536{
    522     NSButton * check;
    523     if ([type isEqualToString: @"Upload"])
    524     {
    525         [fUploadField setIntValue: limit];
    526         check = fUploadCheck;
    527     }
    528     else
    529     {
    530         [fDownloadField setIntValue: limit];
    531         check = fDownloadCheck;
    532     }
    533     [check setState: NSOnState];
    534     [self setLimitCheck: check];
     537    //if interface is loaded, perform change as if user performed it
     538    #warning better way?
     539    if (fToolbar)
     540    {
     541        NSButton * check;
     542        if ([type isEqualToString: @"Upload"])
     543        {
     544            [fUploadField setIntValue: limit];
     545            check = fUploadCheck;
     546        }
     547        else
     548        {
     549            [fDownloadField setIntValue: limit];
     550            check = fDownloadCheck;
     551        }
     552        [check setState: NSOnState];
     553        [self setLimitCheck: check];
     554    }
     555    else
     556    {
     557        BOOL upload = [type isEqualToString: @"Upload"];
     558        [fDefaults setBool: YES forKey: upload ? @"CheckUpload" : @"CheckDownload"];
     559        [fDefaults setInteger: limit forKey: upload ? @"UploadLimit" : @"DownloadLimit"];
     560       
     561        [[NSNotificationCenter defaultCenter] postNotificationName: @"LimitGlobalChange"
     562                                                object: [[NSNumber alloc] initWithBool: upload]];
     563    }
    535564}
    536565
     
    548577        else
    549578        {
    550             tr_setUploadLimit(fHandle, [fUploadCheck state] ? [fDefaults integerForKey: @"UploadLimit"] : -1);
    551             tr_setDownloadLimit(fHandle, [fDownloadCheck state] ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
     579            tr_setUploadLimit(fHandle, [fDefaults boolForKey: @"CheckUpload"]
     580                                        ? [fDefaults integerForKey: @"UploadLimit"] : -1);
     581            tr_setDownloadLimit(fHandle, [fDefaults boolForKey: @"CheckDownload"]
     582                                            ? [fDefaults integerForKey: @"DownloadLimit"] : -1);
    552583        }
    553584    }
     
    628659        [fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
    629660   
    630     NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
    631                                 [NSNumber numberWithBool: [fRatioCheck state]], @"Enable",
    632                                 [NSNumber numberWithFloat: ratioLimit], @"Ratio", nil];
    633     [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: dict];
     661    [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: nil];
    634662}
    635663
     
    643671}
    644672
    645 - (void) setRatioEnabled: (BOOL) enable
    646 {
    647     int state = enable ? NSOnState : NSOffState;
    648    
    649     [fRatioCheck setState: state];
    650     [self setRatioCheck: fRatioCheck];
     673- (void) setQuickRatioEnabled: (BOOL) enable
     674{
     675    //if interface is loaded, perform change as if user performed it
     676    #warning better way?
     677    if (fToolbar)
     678    {
     679        int state = enable ? NSOnState : NSOffState;
     680       
     681        [fRatioCheck setState: state];
     682        [self setRatioCheck: fRatioCheck];
     683    }
     684    else
     685    {
     686        [fDefaults setBool: enable forKey: @"RatioCheck"];
     687       
     688        [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: nil];
     689    }
    651690}
    652691
    653692- (void) setQuickRatio: (float) ratioLimit
    654693{
    655     [fRatioField setFloatValue: ratioLimit];
    656    
    657     [fRatioCheck setState: NSOnState];
    658     [self setRatioCheck: fRatioCheck];
     694    //if interface is loaded, perform change as if user performed it
     695    #warning better way?
     696    if (fToolbar)
     697    {
     698        [fRatioField setFloatValue: ratioLimit];
     699       
     700        [fRatioCheck setState: NSOnState];
     701        [self setRatioCheck: fRatioCheck];
     702    }
     703    else
     704    {
     705        [fDefaults setBool: YES forKey: @"RatioCheck"];
     706        [fDefaults setFloat: ratioLimit forKey: @"RatioLimit"];
     707       
     708        [[NSNotificationCenter defaultCenter] postNotificationName: @"RatioGlobalChange" object: nil];
     709    }
    659710}
    660711
     
    744795
    745796    [fDefaults setInteger: seconds forKey: @"SUScheduledCheckInterval"];
    746     [fUpdater scheduleCheckWithInterval: seconds];
     797   
     798    if (fUpdater)
     799        [fUpdater scheduleCheckWithInterval: seconds];
    747800}
    748801
     
    811864}
    812865
    813 - (void) checkUpdate
    814 {
    815     [fUpdater checkForUpdates: nil];
    816 }
    817 
    818866- (void) folderSheetShow: (id) sender
    819867{
Note: See TracChangeset for help on using the changeset viewer.