Changeset 236

Show
Ignore:
Timestamp:
01/05/07 14:33:17 (2 years ago)
Author:
gbooker
Message:

Added installation detection and update the text field and button strings appropriately.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CPFPerianPrefPaneController.h

    r233 r236  
    33#import <Cocoa/Cocoa.h> 
    44#import <PreferencePanes/NSPreferencePane.h> 
     5 
     6typedef enum 
     7{ 
     8        InstallStatusNotInstalled, 
     9        InstallStatusOutdated, 
     10        InstallStatusInstalled 
     11} InstallStatus; 
     12 
     13typedef enum 
     14{ 
     15        ComponentTypeQuickTime, 
     16        ComponentTypeCoreAudio 
     17} ComponentType; 
    518 
    619@interface CPFPerianPrefPaneController : NSPreferencePane 
     
    2538        IBOutlet NSButton                                       *button_donate; 
    2639        IBOutlet NSButton                                       *button_forum; 
     40         
     41        InstallStatus                                           installStatus; //This is only marked as installed if everything is installed 
    2742         
    2843        NSURL                                                           *perianForumURL; 
  • trunk/CPFPerianPrefPaneController.m

    r233 r236  
    11#import "CPFPerianPrefPaneController.h" 
     2 
     3#define ComponentInfoDictionaryKey      @"Components" 
     4#define BundleVersionKey @"CFBundleVersion" 
     5#define ComponentNameKey @"Name" 
     6#define ComponentTypeKey @"Type" 
    27 
    38#define AC3DynamicRangeKey CFSTR("dynamicRange") 
     
    510 
    611@implementation CPFPerianPrefPaneController 
     12 
     13#pragma mark Private Functions 
     14 
     15- (void)setButton:(NSButton *)button fromKey:(CFStringRef)key forAppID:(CFStringRef)appID withDefault:(BOOL)defaultValue 
     16{ 
     17        CFPropertyListRef value;         
     18        value = CFPreferencesCopyAppValue(key, appID); 
     19        if(value && CFGetTypeID(value) == CFBooleanGetTypeID()) 
     20                [button setState:CFBooleanGetValue(value)]; 
     21        else 
     22                [button setState:defaultValue]; 
     23         
     24        if(value) 
     25                CFRelease(value); 
     26} 
     27 
     28- (void)setKey:(CFStringRef)key forAppID:(CFStringRef)appID fromButton:(NSButton *)button 
     29{ 
     30        if([button state]) 
     31                CFPreferencesSetAppValue(key, kCFBooleanTrue, appID); 
     32        else 
     33                CFPreferencesSetAppValue(key, kCFBooleanFalse, appID); 
     34} 
     35 
     36- (NSString *)quickTimeComponentDir 
     37{ 
     38        NSString *myPath = [[self bundle] bundlePath]; 
     39        NSString *basePath = nil; 
     40         
     41        if([myPath hasPrefix:NSHomeDirectory()]) 
     42                basePath = NSHomeDirectory(); 
     43        else 
     44                basePath = [NSString stringWithString:@"/"]; 
     45         
     46        return [basePath stringByAppendingPathComponent:@"Library/QuickTime"]; 
     47} 
     48 
     49- (NSString *)coreAudioComponentDir 
     50{ 
     51        NSString *myPath = [[self bundle] bundlePath]; 
     52        NSString *basePath = nil; 
     53         
     54        if([myPath hasPrefix:NSHomeDirectory()]) 
     55                basePath = NSHomeDirectory(); 
     56        else 
     57                basePath = [NSString stringWithString:@"/"]; 
     58         
     59        return [basePath stringByAppendingPathComponent:@"Library/Audio/Plug-Ins/Components"]; 
     60} 
     61 
     62- (InstallStatus)installStatusForComponent:(NSString *)component type:(ComponentType)type withMyVersion:(NSString *)myVersion 
     63{ 
     64        NSString *path = nil; 
     65         
     66        switch(type) 
     67        { 
     68                case ComponentTypeCoreAudio: 
     69                        path = [self coreAudioComponentDir]; 
     70                        break; 
     71                case ComponentTypeQuickTime: 
     72                        path = [self quickTimeComponentDir]; 
     73                        break; 
     74        } 
     75        path = [path stringByAppendingPathComponent:component]; 
     76         
     77        NSBundle *bundle = [NSBundle bundleWithPath:path]; 
     78        if(bundle == nil) 
     79                return InstallStatusNotInstalled; 
     80         
     81        NSString *currentVersion = [[bundle infoDictionary] objectForKey:BundleVersionKey]; 
     82        if([currentVersion compare:myVersion] == NSOrderedAscending) 
     83                return InstallStatusOutdated; 
     84         
     85        return InstallStatusInstalled; 
     86} 
     87 
     88#pragma mark Preference Pane Support 
    789 
    890- (id)initWithBundle:(NSBundle *)bundle 
     
    20102} 
    21103 
    22 - (void)setButton:(NSButton *)button fromKey:(CFStringRef)key forAppID:(CFStringRef)appID withDefault:(BOOL)defaultValue 
    23 { 
    24         CFPropertyListRef value;         
    25         value = CFPreferencesCopyAppValue(key, appID); 
    26         if(value && CFGetTypeID(value) == CFBooleanGetTypeID()) 
    27                 [button setState:CFBooleanGetValue(value)]; 
    28         else 
    29                 [button setState:defaultValue]; 
    30          
    31         if(value) 
    32                 CFRelease(value); 
    33 } 
    34  
    35 - (void)setKey:(CFStringRef)key forAppID:(CFStringRef)appID fromButton:(NSButton *)button 
    36 { 
    37         if([button state]) 
    38                 CFPreferencesSetAppValue(key, kCFBooleanTrue, appID); 
    39         else 
    40                 CFPreferencesSetAppValue(key, kCFBooleanFalse, appID); 
    41 } 
    42  
    43104- (void)mainViewDidLoad 
    44105{ 
     106        /* General */ 
     107        NSDictionary *infoDict = [[self bundle] infoDictionary]; 
     108        installStatus = [self installStatusForComponent:@"Perian.component" type:ComponentTypeQuickTime withMyVersion:[infoDict objectForKey:BundleVersionKey]]; 
     109        if(installStatus == InstallStatusNotInstalled) 
     110        { 
     111                [textField_installStatus setStringValue:NSLocalizedString(@"Perian is not Installed", @"")]; 
     112                [button_install setStringValue:NSLocalizedString(@"Install", @"")]; 
     113        } 
     114        else if(installStatus == InstallStatusOutdated) 
     115        { 
     116                [textField_installStatus setStringValue:NSLocalizedString(@"Perian is Installed, but Outdated", @"")]; 
     117                [button_install setStringValue:NSLocalizedString(@"Update", @"")]; 
     118        } 
     119        else 
     120        { 
     121                //Perian is fine, but check components 
     122                NSDictionary *myComponentsInfo = [infoDict objectForKey:ComponentInfoDictionaryKey]; 
     123                if(myComponentsInfo != nil) 
     124                { 
     125                        NSEnumerator *componentEnum = [myComponentsInfo objectEnumerator]; 
     126                        NSDictionary *componentInfo = nil; 
     127                        while((componentInfo = [componentEnum nextObject]) != nil) 
     128                        { 
     129                                InstallStatus tstatus = [self installStatusForComponent:[componentInfo objectForKey:ComponentNameKey] type:[[componentInfo objectForKey:ComponentTypeKey] intValue] withMyVersion:[componentInfo objectForKey:BundleVersionKey]]; 
     130                                if(tstatus < installStatus) 
     131                                        installStatus = tstatus; 
     132                        } 
     133                        switch(installStatus) 
     134                        { 
     135                                case InstallStatusNotInstalled: 
     136                                        [textField_installStatus setStringValue:NSLocalizedString(@"Perian is Installed, but parts are Not Installed", @"")]; 
     137                                        [button_install setStringValue:NSLocalizedString(@"Install", @"")]; 
     138                                        break; 
     139                                case InstallStatusOutdated: 
     140                                        [textField_installStatus setStringValue:NSLocalizedString(@"Perian is Installed, but parts are Outdated", @"")]; 
     141                                        [button_install setStringValue:NSLocalizedString(@"Update", @"")]; 
     142                                        break; 
     143                                case InstallStatusInstalled: 
     144                                        [textField_installStatus setStringValue:NSLocalizedString(@"Perian is Installed", @"")]; 
     145                                        [button_install setStringValue:NSLocalizedString(@"Uninstall", @"")]; 
     146                                        break; 
     147                        } 
     148                } 
     149                else 
     150                { 
     151                        [textField_installStatus setStringValue:NSLocalizedString(@"Perian is Installed", @"")]; 
     152                        [button_install setStringValue:NSLocalizedString(@"Uninstall", @"")]; 
     153                } 
     154                 
     155        } 
     156         
    45157        /* A52 Prefs */ 
    46158        [self setButton:button_ac3DynamicRange fromKey:AC3DynamicRangeKey forAppID:a52AppID withDefault:NO];