Ignore:
Timestamp:
Jun 13, 2008, 6:47:38 PM (14 years ago)
Author:
livings124
Message:

put some of the keychain code into methods for future expandability

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/PrefsController.m

    r6171 r6176  
    5252#define TOOLBAR_REMOTE      @"TOOLBAR_REMOTE"
    5353
     54#define PROXY_KEYCHAIN_SERVICE  @"Transmission:Proxy"
     55#define PROXY_KEYCHAIN_NAME     @"Proxy"
     56
    5457@interface PrefsController (Private)
    5558
     
    5962- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    6063- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
     64
     65- (void) setKeychainPassword: (NSString *) password forService: (NSString *) service username: (NSString *) username;
    6166
    6267@end
     
    754759{
    755760    NSString * password = [[sender stringValue] retain];
    756    
    757     EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: @"Transmission:Proxy"
    758                                             withUsername: @"Proxy"];
    759     if (keychainItem)
    760     {
    761         if (![password isEqualToString: @""])
    762             [keychainItem setPassword: password];
    763         else
    764             [keychainItem removeFromKeychain];
    765     }
    766     else
    767     {
    768         if (![password isEqualToString: @""])
    769             [[EMKeychainProxy sharedProxy] addGenericKeychainItemForService: @"Transmission:Proxy" withUsername: @"Proxy"
    770                 password: password];
    771     }
     761    [self setKeychainPassword: password forService: PROXY_KEYCHAIN_SERVICE username: PROXY_KEYCHAIN_NAME];
    772762   
    773763    tr_sessionSetProxyPassword(fHandle, [password UTF8String]);
     
    778768{
    779769    NSString * password;
    780     EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: @"Transmission:Proxy"
    781                                             withUsername: @"Proxy"];
     770    EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: PROXY_KEYCHAIN_SERVICE
     771                                            withUsername: PROXY_KEYCHAIN_NAME];
    782772    if (!(password = [keychainItem password]))
    783773        password = @"";
     
    11321122}
    11331123
     1124- (void) setKeychainPassword: (NSString *) password forService: (NSString *) service username: (NSString *) username
     1125{
     1126    BOOL shouldAdd = ![password isEqualToString: @""];
     1127   
     1128    EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: service withUsername: username];
     1129    if (keychainItem)
     1130    {
     1131        if (shouldAdd)
     1132            [keychainItem setPassword: password];
     1133        else
     1134            [keychainItem removeFromKeychain];
     1135    }
     1136    else
     1137    {
     1138        if (shouldAdd)
     1139            [[EMKeychainProxy sharedProxy] addGenericKeychainItemForService: service withUsername: username password: password];
     1140    }
     1141}
     1142
    11341143@end
Note: See TracChangeset for help on using the changeset viewer.