Ignore:
Timestamp:
Jun 19, 2006, 11:07:28 PM (16 years ago)
Author:
livings124
Message:

A little cleanup, a slightly more straight-forward way of checking the Growl path, and the method to register Growl won't be called through Interface Builder.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r393 r394  
    6565        fInfoController = [[InfoWindowController alloc] initWithWindowNibName: @"InfoWindow"];
    6666        fPrefsController = [[PrefsController alloc] initWithWindowNibName: @"PrefsWindow"];
     67        fBadger = [[Badger alloc] init];
     68       
     69        //check and register Growl if it is installed for this user or all users
     70        NSFileManager * manager = [NSFileManager defaultManager];
     71        fHasGrowl = [manager fileExistsAtPath: GROWL_PATH]
     72            || [manager fileExistsAtPath: [NSHomeDirectory() stringByAppendingPathComponent: GROWL_PATH]];
     73        [self growlRegister];
    6774    }
    6875    return self;
     
    140147    }
    141148    else
    142         NSLog( @"Could not IORegisterForSystemPower" );
     149        NSLog(@"Could not IORegisterForSystemPower");
    143150
    144151    //load torrents from history
     
    168175        currentSortItem = fDateSortItem;
    169176    [currentSortItem setState: NSOnState];
    170 
    171     //check and register Growl if it is installed for this user or all users
    172     NSFileManager * manager = [NSFileManager defaultManager];
    173     fHasGrowl = [manager fileExistsAtPath: GROWL_PATH]
    174                 || [manager fileExistsAtPath: [[NSString stringWithFormat: @"~%@",
    175                 GROWL_PATH] stringByExpandingTildeInPath]];
    176     [self growlRegister: self];
    177 
    178     //initialize badging
    179     fBadger = [[Badger alloc] init];
    180177   
    181178    //set upload limit action button
     
    234231    [fWindow makeKeyAndOrderFront: nil];
    235232
    236     [fInfoController updateInfoForTorrents: [self torrentsAtIndexes:
    237                                     [fTableView selectedRowIndexes]]];
     233    [fInfoController updateInfoForTorrents: [self torrentsAtIndexes: [fTableView selectedRowIndexes]]];
    238234    if ([fDefaults boolForKey: @"InfoVisible"])
    239235        [self showInfo: nil];
     
    279275
    280276- (void) quitSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode
    281                         contextInfo: (void *) contextInfo
     277    contextInfo: (void *) contextInfo
    282278{
    283279    [NSApp stopModal];
     
    416412    int count = [fTorrents count];
    417413    [fTotalTorrentsField setStringValue: [NSString stringWithFormat:
    418                     @"%d Transfer%s", count, count == 1 ? "" : "s"]];
     414        @"%d Transfer%s", count, count == 1 ? "" : "s"]];
    419415}
    420416
     
    667663        NSSavePanel * panel = [NSSavePanel savePanel];
    668664        [panel setRequiredFileType: @"torrent"];
     665        [panel setCanSelectHiddenExtension: NO];
    669666        [panel setExtensionHidden: NO];
    670         [panel setCanSelectHiddenExtension: NO];
    671667       
    672668        [panel beginSheetForDirectory: nil file: [torrent name]
     
    872868{
    873869    [fPrefsController setLimitEnabled: (sender == fUploadLimitItem || sender == fDownloadLimitItem)
    874                         type: (sender == fUploadLimitItem || sender == fUploadNoLimitItem)
    875                             ? @"Upload" : @"Download"];
     870        type: (sender == fUploadLimitItem || sender == fUploadNoLimitItem) ? @"Upload" : @"Download"];
    876871}
    877872
     
    971966    if (![[pasteboard types] containsObject: NSFilenamesPboardType]
    972967            || [[[pasteboard propertyListForType: NSFilenamesPboardType]
    973                 pathsMatchingExtensions: [NSArray arrayWithObject: @"torrent"]]
    974                 count] == 0)
     968        pathsMatchingExtensions: [NSArray arrayWithObject: @"torrent"]] count] == 0)
    975969        return NSDragOperationNone;
    976970
     
    13461340}
    13471341
    1348 - (void) sleepCallBack: (natural_t) messageType argument:
    1349                           (void *) messageArgument
     1342- (void) sleepCallBack: (natural_t) messageType argument: (void *) messageArgument
    13501343{
    13511344    NSEnumerator * enumerator;
     
    14001393}
    14011394
    1402 - (NSRect) windowWillUseStandardFrame: (NSWindow *) w
    1403     defaultFrame: (NSRect) defaultFrame
     1395- (NSRect) windowWillUseStandardFrame: (NSWindow *) w defaultFrame: (NSRect) defaultFrame
    14041396{
    14051397    NSRect windowRect = [fWindow frame];
     
    14391431- (void) notifyGrowl: (NSString * ) file
    14401432{
    1441     NSString * growlScript;
    1442     NSAppleScript * appleScript;
    1443     NSDictionary * error;
    1444 
    1445     if( !fHasGrowl )
     1433    if (!fHasGrowl)
    14461434        return;
    14471435
    1448     growlScript = [NSString stringWithFormat:
     1436    NSString * growlScript = [NSString stringWithFormat:
    14491437        @"tell application \"System Events\"\n"
    14501438         "  if exists application process \"GrowlHelperApp\" then\n"
     
    14571445         "  end if\n"
    14581446         "end tell", file];
    1459     appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
    1460     if( ![appleScript executeAndReturnError: &error] )
    1461     {
    1462         NSLog( @"Growl notify failed" );
    1463     }
     1447   
     1448    NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
     1449    NSDictionary * error;
     1450    if (![appleScript executeAndReturnError: &error])
     1451        NSLog(@"Growl notify failed");
    14641452    [appleScript release];
    14651453}
    14661454
    1467 - (void) growlRegister: (id) sender
    1468 {
    1469     NSString * growlScript;
    1470     NSAppleScript * appleScript;
    1471     NSDictionary * error;
    1472 
    1473     if( !fHasGrowl )
     1455- (void) growlRegister
     1456{
     1457    if (!fHasGrowl)
    14741458        return;
    14751459
    1476     growlScript = [NSString stringWithFormat:
     1460    NSString * growlScript = [NSString stringWithFormat:
    14771461        @"tell application \"System Events\"\n"
    14781462         "  if exists application process \"GrowlHelperApp\" then\n"
     
    14861470         "end tell"];
    14871471
    1488     appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
    1489     if( ![appleScript executeAndReturnError: &error] )
    1490     {
    1491         NSLog( @"Growl registration failed" );
    1492     }
     1472    NSAppleScript * appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
     1473    NSDictionary * error;
     1474    if (![appleScript executeAndReturnError: &error])
     1475        NSLog(@"Growl registration failed");
    14931476    [appleScript release];
    14941477}
Note: See TracChangeset for help on using the changeset viewer.