source: trunk/macosx/PrefsController.m @ 6529

Last change on this file since 6529 was 6529, checked in by livings124, 13 years ago

initial Sparkle 1.5 b5 commit

  • Property svn:keywords set to Date Rev Author Id
File size: 40.4 KB
Line 
1/******************************************************************************
2 * $Id: PrefsController.m 6529 2008-08-15 01:44:46Z livings124 $
3 *
4 * Copyright (c) 2005-2008 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "PrefsController.h"
26#import "BlocklistDownloader.h"
27#import "NSApplicationAdditions.h"
28#import "NSStringAdditions.h"
29#import "UKKQueue.h"
30
31#define DOWNLOAD_FOLDER     0
32#define DOWNLOAD_TORRENT    2
33
34#define PROXY_HTTP      0
35#define PROXY_SOCKS4    1
36#define PROXY_SOCKS5    2
37
38#define RPC_ACCESS_ALLOW    0
39#define RPC_ACCESS_DENY     1
40
41#define RPC_IP_ADD_TAG      0
42#define RPC_IP_REMOVE_TAG   1
43
44#define TOOLBAR_GENERAL     @"TOOLBAR_GENERAL"
45#define TOOLBAR_TRANSFERS   @"TOOLBAR_TRANSFERS"
46#define TOOLBAR_BANDWIDTH   @"TOOLBAR_BANDWIDTH"
47#define TOOLBAR_PEERS       @"TOOLBAR_PEERS"
48#define TOOLBAR_NETWORK     @"TOOLBAR_NETWORK"
49#define TOOLBAR_REMOTE      @"TOOLBAR_REMOTE"
50
51#define PROXY_KEYCHAIN_SERVICE  "Transmission:Proxy"
52#define PROXY_KEYCHAIN_NAME     "Proxy"
53
54#define RPC_KEYCHAIN_SERVICE    "Transmission:Remote"
55#define RPC_KEYCHAIN_NAME       "Remote"
56
57#define WEBUI_URL   @"http://localhost:%d/transmission/web/"
58
59@interface PrefsController (Private)
60
61- (void) setPrefView: (id) sender;
62
63- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
64- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
65- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
66
67- (void) setKeychainPassword: (const char *) password forService: (const char *) service username: (const char *) username;
68
69@end
70
71@implementation PrefsController
72
73- (id) initWithHandle: (tr_handle *) handle
74{
75    if ((self = [super initWithWindowNibName: @"PrefsWindow"]))
76    {
77        fDefaults = [NSUserDefaults standardUserDefaults];
78        fHandle = handle;
79       
80        //checks for old version speeds of -1
81        if ([fDefaults integerForKey: @"UploadLimit"] < 0)
82        {
83            [fDefaults setInteger: 20 forKey: @"UploadLimit"];
84            [fDefaults setBool: NO forKey: @"CheckUpload"];
85        }
86        if ([fDefaults integerForKey: @"DownloadLimit"] < 0)
87        {
88            [fDefaults setInteger: 20 forKey: @"DownloadLimit"];
89            [fDefaults setBool: NO forKey: @"CheckDownload"];
90        }
91       
92        //check for old version download location (before 1.1)
93        NSString * choice;
94        if ((choice = [fDefaults stringForKey: @"DownloadChoice"]))
95        {
96            [fDefaults setBool: [choice isEqualToString: @"Constant"] forKey: @"DownloadLocationConstant"];
97            [fDefaults setBool: YES forKey: @"DownloadAsk"];
98           
99            [fDefaults removeObjectForKey: @"DownloadChoice"];
100        }
101       
102        //set auto import
103        NSString * autoPath;
104        if ([fDefaults boolForKey: @"AutoImport"] && (autoPath = [fDefaults stringForKey: @"AutoImportDirectory"]))
105            [[UKKQueue sharedFileWatcher] addPath: [autoPath stringByExpandingTildeInPath]];
106       
107        //set encryption
108        [self setEncryptionMode: nil];
109       
110        //actually set bandwidth limits
111        [self applySpeedSettings: nil];
112       
113        //set proxy type
114        [self updateProxyType];
115        [self updateProxyPassword];
116       
117        //update rpc access list
118        [self updateRPCPassword];
119       
120        fRPCAccessArray = [[fDefaults arrayForKey: @"RPCAccessList"] mutableCopy];
121        if (!fRPCAccessArray)
122            fRPCAccessArray = [[NSMutableArray arrayWithObject: [NSDictionary dictionaryWithObjectsAndKeys: @"127.0.0.1", @"IP",
123                                [NSNumber numberWithBool: YES], @"Allow", nil]] retain];
124        [self updateRPCAccessList];
125    }
126   
127    return self;
128}
129
130- (tr_handle *) handle
131{
132    return fHandle;
133}
134
135- (void) dealloc
136{
137    [fPortStatusTimer invalidate];
138    if (fPortChecker)
139    {
140        [fPortChecker cancelProbe];
141        [fPortChecker release];
142    }
143   
144    [fRPCAccessArray release];
145   
146    [super dealloc];
147}
148
149- (void) awakeFromNib
150{
151    fHasLoaded = YES;
152   
153    NSToolbar * toolbar = [[NSToolbar alloc] initWithIdentifier: @"Preferences Toolbar"];
154    [toolbar setDelegate: self];
155    [toolbar setAllowsUserCustomization: NO];
156    [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
157    [toolbar setSizeMode: NSToolbarSizeModeRegular];
158    [toolbar setSelectedItemIdentifier: TOOLBAR_GENERAL];
159    [[self window] setToolbar: toolbar];
160    [toolbar release];
161   
162    [self setPrefView: nil];
163   
164    if (![NSApp isOnLeopardOrBetter])
165    {
166        [fRPCAddRemoveControl sizeToFit];
167        [fRPCAddRemoveControl setLabel: @"+" forSegment: RPC_IP_ADD_TAG];
168        [fRPCAddRemoveControl setLabel: @"-" forSegment: RPC_IP_REMOVE_TAG];
169    }
170   
171    //set download folder
172    [fFolderPopUp selectItemAtIndex: [fDefaults boolForKey: @"DownloadLocationConstant"] ? DOWNLOAD_FOLDER : DOWNLOAD_TORRENT];
173   
174    //set stop ratio
175    [self updateRatioStopField];
176   
177    //set limits
178    [self updateLimitFields];
179   
180    //set speed limit
181    [fSpeedLimitUploadField setIntValue: [fDefaults integerForKey: @"SpeedLimitUploadLimit"]];
182    [fSpeedLimitDownloadField setIntValue: [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]];
183   
184    //set port
185    [fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]];
186    fNatStatus = -1;
187   
188    [self updatePortStatus];
189    fPortStatusTimer = [NSTimer scheduledTimerWithTimeInterval: 5.0 target: self
190                        selector: @selector(updatePortStatus) userInfo: nil repeats: YES];
191   
192    //set peer connections
193    [fPeersGlobalField setIntValue: [fDefaults integerForKey: @"PeersTotal"]];
194    [fPeersTorrentField setIntValue: [fDefaults integerForKey: @"PeersTorrent"]];
195   
196    //set queue values
197    [fQueueDownloadField setIntValue: [fDefaults integerForKey: @"QueueDownloadNumber"]];
198    [fQueueSeedField setIntValue: [fDefaults integerForKey: @"QueueSeedNumber"]];
199    [fStalledField setIntValue: [fDefaults integerForKey: @"StalledMinutes"]];
200   
201    //set proxy type
202    [fProxyAddressField setStringValue: [fDefaults stringForKey: @"ProxyAddress"]];
203    int proxyType;
204    switch(tr_sessionGetProxyType(fHandle))
205    {
206        case TR_PROXY_SOCKS4:
207            proxyType = PROXY_SOCKS4;
208            break;
209        case TR_PROXY_SOCKS5:
210            proxyType = PROXY_SOCKS5;
211            break;
212        case TR_PROXY_HTTP:
213            proxyType = PROXY_HTTP;
214    }
215    [fProxyTypePopUp selectItemAtIndex: proxyType];
216   
217    //set proxy password - does NOT need to be released
218    [fProxyPasswordField setStringValue: [NSString stringWithUTF8String: tr_sessionGetProxyPassword(fHandle)]];
219   
220    //set proxy port
221    [fProxyPortField setIntValue: [fDefaults integerForKey: @"ProxyPort"]];
222   
223    //set blocklist
224    [self updateBlocklistFields];
225   
226    //set rpc port
227    [fRPCPortField setIntValue: [fDefaults integerForKey: @"RPCPort"]];
228   
229    //set rpc password - has to be released
230    const char * rpcPassword = tr_sessionGetRPCPassword(fHandle);
231    [fRPCPasswordField setStringValue: [NSString stringWithUTF8String: rpcPassword]];
232    tr_free(rpcPassword);
233}
234
235- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag
236{
237    NSToolbarItem * item = [[NSToolbarItem alloc] initWithItemIdentifier: ident];
238
239    if ([ident isEqualToString: TOOLBAR_GENERAL])
240    {
241        [item setLabel: NSLocalizedString(@"General", "Preferences -> toolbar item title")];
242        [item setImage: [NSImage imageNamed: [NSApp isOnLeopardOrBetter] ? NSImageNamePreferencesGeneral : @"Preferences.png"]];
243        [item setTarget: self];
244        [item setAction: @selector(setPrefView:)];
245        [item setAutovalidates: NO];
246    }
247    else if ([ident isEqualToString: TOOLBAR_TRANSFERS])
248    {
249        [item setLabel: NSLocalizedString(@"Transfers", "Preferences -> toolbar item title")];
250        [item setImage: [NSImage imageNamed: @"Transfers.png"]];
251        [item setTarget: self];
252        [item setAction: @selector(setPrefView:)];
253        [item setAutovalidates: NO];
254    }
255    else if ([ident isEqualToString: TOOLBAR_BANDWIDTH])
256    {
257        [item setLabel: NSLocalizedString(@"Bandwidth", "Preferences -> toolbar item title")];
258        [item setImage: [NSImage imageNamed: @"Bandwidth.png"]];
259        [item setTarget: self];
260        [item setAction: @selector(setPrefView:)];
261        [item setAutovalidates: NO];
262    }
263    else if ([ident isEqualToString: TOOLBAR_PEERS])
264    {
265        [item setLabel: NSLocalizedString(@"Peers", "Preferences -> toolbar item title")];
266        [item setImage: [NSImage imageNamed: [NSApp isOnLeopardOrBetter] ? NSImageNameUserGroup : @"Peers.png"]];
267        [item setTarget: self];
268        [item setAction: @selector(setPrefView:)];
269        [item setAutovalidates: NO];
270    }
271    else if ([ident isEqualToString: TOOLBAR_NETWORK])
272    {
273        [item setLabel: NSLocalizedString(@"Network", "Preferences -> toolbar item title")];
274        [item setImage: [NSImage imageNamed: [NSApp isOnLeopardOrBetter] ? NSImageNameNetwork : @"Network.png"]];
275        [item setTarget: self];
276        [item setAction: @selector(setPrefView:)];
277        [item setAutovalidates: NO];
278    }
279    else if ([ident isEqualToString: TOOLBAR_REMOTE])
280    {
281        [item setLabel: NSLocalizedString(@"Remote", "Preferences -> toolbar item title")];
282        [item setImage: [NSImage imageNamed: @"Remote.png"]];
283        [item setTarget: self];
284        [item setAction: @selector(setPrefView:)];
285        [item setAutovalidates: NO];
286    }
287    else
288    {
289        [item release];
290        return nil;
291    }
292
293    return [item autorelease];
294}
295
296- (NSArray *) toolbarSelectableItemIdentifiers: (NSToolbar *) toolbar
297{
298    return [self toolbarDefaultItemIdentifiers: toolbar];
299}
300
301- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
302{
303    return [self toolbarAllowedItemIdentifiers: toolbar];
304}
305
306- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
307{
308    return [NSArray arrayWithObjects: TOOLBAR_GENERAL, TOOLBAR_TRANSFERS, TOOLBAR_BANDWIDTH,
309                                        TOOLBAR_PEERS, TOOLBAR_NETWORK, TOOLBAR_REMOTE, nil];
310}
311
312//used by ipc
313- (void) updatePortField
314{
315    [fPortField setIntValue: [fDefaults integerForKey: @"BindPort"]];
316}
317
318- (void) setPort: (id) sender
319{
320    int port = [sender intValue];
321    [fDefaults setInteger: port forKey: @"BindPort"];
322    tr_sessionSetPeerPort(fHandle, port);
323   
324    fPeerPort = -1;
325    [self updatePortStatus];
326}
327
328- (void) setNat: (id) sender
329{
330    tr_sessionSetPortForwardingEnabled(fHandle, [fDefaults boolForKey: @"NatTraversal"]);
331   
332    fNatStatus = -1;
333    [self updatePortStatus];
334}
335
336- (void) updatePortStatus
337{
338    const tr_port_forwarding fwd = tr_sessionGetPortForwarding(fHandle);
339    const int port = tr_sessionGetPeerPort(fHandle);
340
341    if (fNatStatus != fwd || fPeerPort != port )
342    {
343        fNatStatus = fwd;
344        fPeerPort = port;
345       
346        [fPortStatusField setStringValue: @""];
347        [fPortStatusImage setImage: nil];
348        [fPortStatusProgress startAnimation: self];
349       
350        if (fPortChecker)
351        {
352            [fPortChecker cancelProbe];
353            [fPortChecker release];
354        }
355        fPortChecker = [[PortChecker alloc] initForPort: fPeerPort withDelegate: self];
356    }
357}
358
359- (void) portCheckerDidFinishProbing: (PortChecker *) portChecker
360{
361    [fPortStatusProgress stopAnimation: self];
362    switch ([fPortChecker status])
363    {
364        case PORT_STATUS_OPEN:
365            [fPortStatusField setStringValue: NSLocalizedString(@"Port is open", "Preferences -> Network -> port status")];
366            [fPortStatusImage setImage: [NSImage imageNamed: @"GreenDot.png"]];
367            break;
368        case PORT_STATUS_CLOSED:
369            [fPortStatusField setStringValue: NSLocalizedString(@"Port is closed", "Preferences -> Network -> port status")];
370            [fPortStatusImage setImage: [NSImage imageNamed: @"RedDot.png"]];
371            break;
372        case PORT_STATUS_ERROR:
373            [fPortStatusField setStringValue: NSLocalizedString(@"Port check website is down", "Preferences -> Network -> port status")];
374            [fPortStatusImage setImage: [NSImage imageNamed: @"YellowDot.png"]];
375            break;
376    }
377    [fPortChecker release];
378    fPortChecker = nil;
379}
380
381- (NSArray *) sounds
382{
383    NSMutableArray * sounds = [NSMutableArray array];
384   
385    NSMutableArray * directories = [NSMutableArray arrayWithObjects: @"/System/Library/Sounds", @"/Library/Sounds", nil];
386    if ([NSApp isOnLeopardOrBetter])
387        [directories addObject: [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Sounds"]];
388   
389    BOOL isDirectory;
390    NSString * directory;
391    NSEnumerator * enumerator = [directories objectEnumerator];
392    while ((directory = [enumerator nextObject]))
393        if ([[NSFileManager defaultManager] fileExistsAtPath: directory isDirectory: &isDirectory] && isDirectory)
394        {
395            NSString * sound;
396            NSEnumerator * soundEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath: directory] objectEnumerator];
397            while ((sound = [soundEnumerator nextObject]))
398            {
399                sound = [sound stringByDeletingPathExtension];
400                if ([NSSound soundNamed: sound])
401                    [sounds addObject: sound];
402            }
403        }
404   
405    return sounds;
406}
407
408- (void) setSound: (id) sender
409{
410    //play sound when selecting
411    NSSound * sound;
412    if ((sound = [NSSound soundNamed: [sender titleOfSelectedItem]]))
413        [sound play];
414}
415
416- (void) setPeersGlobal: (id) sender
417{
418    int count = [sender intValue];
419    [fDefaults setInteger: count forKey: @"PeersTotal"];
420    tr_sessionSetPeerLimit(fHandle, count);
421}
422
423- (void) setPeersTorrent: (id) sender
424{
425    int count = [sender intValue];
426    [fDefaults setInteger: count forKey: @"PeersTorrent"];
427}
428
429- (void) setPEX: (id) sender
430{
431    tr_sessionSetPexEnabled(fHandle, [fDefaults boolForKey: @"PEXGlobal"]);
432}
433
434- (void) setEncryptionMode: (id) sender
435{
436    tr_sessionSetEncryption(fHandle, [fDefaults boolForKey: @"EncryptionPrefer"] ?
437        ([fDefaults boolForKey: @"EncryptionRequire"] ? TR_ENCRYPTION_REQUIRED : TR_ENCRYPTION_PREFERRED) : TR_CLEAR_PREFERRED);
438}
439
440- (void) setBlocklistEnabled: (id) sender
441{
442    BOOL enable = [sender state] == NSOnState;
443    [fDefaults setBool: enable forKey: @"Blocklist"];
444    tr_blocklistSetEnabled(fHandle, enable);
445}
446
447- (void) updateBlocklist: (id) sender
448{
449    [BlocklistDownloader downloadWithPrefsController: self];
450}
451
452- (void) updateBlocklistFields
453{
454    BOOL exists = tr_blocklistExists(fHandle);
455   
456    if (exists)
457    {
458        NSNumberFormatter * numberFormatter = [[NSNumberFormatter alloc] init];
459        [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle];
460        [numberFormatter setMaximumFractionDigits: 0];
461        NSString * countString = [numberFormatter stringFromNumber: [NSNumber numberWithInt: tr_blocklistGetRuleCount(fHandle)]];
462        [numberFormatter release];
463       
464        [fBlocklistMessageField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ IP address rules in list",
465            "Prefs -> blocklist -> message"), countString]];
466    }
467    else
468        [fBlocklistMessageField setStringValue: NSLocalizedString(@"A blocklist must first be downloaded",
469            "Prefs -> blocklist -> message")];
470   
471    [fBlocklistEnableCheck setEnabled: exists];
472    [fBlocklistEnableCheck setState: exists && [fDefaults boolForKey: @"Blocklist"]];
473}
474
475- (void) applySpeedSettings: (id) sender
476{
477    if ([fDefaults boolForKey: @"SpeedLimit"])
478    {
479        tr_sessionSetSpeedLimitEnabled(fHandle, TR_UP, 1);
480        tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"SpeedLimitUploadLimit"]);
481       
482        tr_sessionSetSpeedLimitEnabled(fHandle, TR_DOWN, 1);
483        tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"SpeedLimitDownloadLimit"]);
484    }
485    else
486    {
487        tr_sessionSetSpeedLimitEnabled(fHandle, TR_UP, [fDefaults boolForKey: @"CheckUpload"]);
488        tr_sessionSetSpeedLimit(fHandle, TR_UP, [fDefaults integerForKey: @"UploadLimit"]);
489       
490        tr_sessionSetSpeedLimitEnabled(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
491        tr_sessionSetSpeedLimit(fHandle, TR_DOWN, [fDefaults integerForKey: @"DownloadLimit"]);
492    }
493}
494
495- (void) applyRatioSetting: (id) sender
496{
497    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
498}
499
500- (void) updateRatioStopField
501{
502    if (!fHasLoaded)
503        return;
504   
505    [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
506   
507    [self applyRatioSetting: nil];
508}
509
510- (void) setRatioStop: (id) sender
511{
512    [fDefaults setFloat: [sender floatValue] forKey: @"RatioLimit"];
513    [self applyRatioSetting: nil];
514}
515
516- (void) updateLimitFields
517{
518    if (!fHasLoaded)
519        return;
520   
521    [fUploadField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
522    [fDownloadField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
523}
524
525- (void) setGlobalLimit: (id) sender
526{
527    [fDefaults setInteger: [sender intValue] forKey: sender == fUploadField ? @"UploadLimit" : @"DownloadLimit"];
528    [self applySpeedSettings: self];
529}
530
531- (void) setSpeedLimit: (id) sender
532{
533    [fDefaults setInteger: [sender intValue] forKey: sender == fSpeedLimitUploadField
534                                                        ? @"SpeedLimitUploadLimit" : @"SpeedLimitDownloadLimit"];
535    [self applySpeedSettings: self];
536}
537
538- (void) setAutoSpeedLimit: (id) sender
539{
540    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSpeedLimitChange" object: self];
541}
542
543- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
544{
545    [fInitialString release];
546    fInitialString = [[control stringValue] retain];
547   
548    return YES;
549}
550
551- (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error
552{
553    NSBeep();
554    if (fInitialString)
555    {
556        [control setStringValue: fInitialString];
557        [fInitialString release];
558        fInitialString = nil;
559    }
560    return NO;
561}
562
563- (void) setBadge: (id) sender
564{
565    [[NSNotificationCenter defaultCenter] postNotificationName: @"DockBadgeChange" object: self];
566}
567
568- (void) resetWarnings: (id) sender
569{
570    [fDefaults removeObjectForKey: @"WarningDuplicate"];
571    [fDefaults removeObjectForKey: @"WarningRemainingSpace"];
572    [fDefaults removeObjectForKey: @"WarningFolderDataSameName"];
573    [fDefaults removeObjectForKey: @"WarningResetStats"];
574    [fDefaults removeObjectForKey: @"WarningCreatorBlankAddress"];
575    [fDefaults removeObjectForKey: @"WarningRemoveBuiltInTracker"];
576    [fDefaults removeObjectForKey: @"WarningInvalidOpen"];
577}
578
579- (void) setQueue: (id) sender
580{
581    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
582}
583
584- (void) setQueueNumber: (id) sender
585{
586    [fDefaults setInteger: [sender intValue] forKey: sender == fQueueDownloadField ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
587    [self setQueue: nil];
588}
589
590- (void) setStalled: (id) sender
591{
592    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
593}
594
595- (void) setStalledMinutes: (id) sender
596{
597    [fDefaults setInteger: [sender intValue] forKey: @"StalledMinutes"];
598    [self setStalled: nil];
599}
600
601- (void) setDownloadLocation: (id) sender
602{
603    [fDefaults setBool: [fFolderPopUp indexOfSelectedItem] == DOWNLOAD_FOLDER forKey: @"DownloadLocationConstant"];
604}
605
606- (void) folderSheetShow: (id) sender
607{
608    NSOpenPanel * panel = [NSOpenPanel openPanel];
609
610    [panel setPrompt: NSLocalizedString(@"Select", "Preferences -> Open panel prompt")];
611    [panel setAllowsMultipleSelection: NO];
612    [panel setCanChooseFiles: NO];
613    [panel setCanChooseDirectories: YES];
614    [panel setCanCreateDirectories: YES];
615
616    [panel beginSheetForDirectory: nil file: nil types: nil
617        modalForWindow: [self window] modalDelegate: self didEndSelector:
618        @selector(folderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
619}
620
621- (void) incompleteFolderSheetShow: (id) sender
622{
623    NSOpenPanel * panel = [NSOpenPanel openPanel];
624
625    [panel setPrompt: NSLocalizedString(@"Select", "Preferences -> Open panel prompt")];
626    [panel setAllowsMultipleSelection: NO];
627    [panel setCanChooseFiles: NO];
628    [panel setCanChooseDirectories: YES];
629    [panel setCanCreateDirectories: YES];
630
631    [panel beginSheetForDirectory: nil file: nil types: nil
632        modalForWindow: [self window] modalDelegate: self didEndSelector:
633        @selector(incompleteFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
634}
635
636- (void) setAutoImport: (id) sender
637{
638    NSString * path;
639    if ((path = [fDefaults stringForKey: @"AutoImportDirectory"]))
640    {
641        path = [path stringByExpandingTildeInPath];
642        if ([fDefaults boolForKey: @"AutoImport"])
643            [[UKKQueue sharedFileWatcher] addPath: path];
644        else
645            [[UKKQueue sharedFileWatcher] removePathFromQueue: path];
646       
647        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
648    }
649    else
650        [self importFolderSheetShow: nil];
651}
652
653- (void) importFolderSheetShow: (id) sender
654{
655    NSOpenPanel * panel = [NSOpenPanel openPanel];
656
657    [panel setPrompt: NSLocalizedString(@"Select", "Preferences -> Open panel prompt")];
658    [panel setAllowsMultipleSelection: NO];
659    [panel setCanChooseFiles: NO];
660    [panel setCanChooseDirectories: YES];
661    [panel setCanCreateDirectories: YES];
662
663    [panel beginSheetForDirectory: nil file: nil types: nil
664        modalForWindow: [self window] modalDelegate: self didEndSelector:
665        @selector(importFolderSheetClosed:returnCode:contextInfo:) contextInfo: nil];
666}
667
668- (void) setAutoSize: (id) sender
669{
670    [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoSizeSettingChange" object: self];
671}
672
673- (void) setProxyEnabled: (id) sender
674{
675    tr_sessionSetProxyEnabled(fHandle, [fDefaults boolForKey: @"Proxy"]);
676}
677
678- (void) setProxyAddress: (id) sender
679{
680    NSString * address = [sender stringValue];
681    BOOL blank = [address isEqualToString: @""];
682   
683    if (!blank && [address rangeOfString: @"://"].location == NSNotFound)
684        address = [@"http://" stringByAppendingString: address];
685   
686    if (blank || tr_httpIsValidURL([address UTF8String]))
687    {
688        tr_sessionSetProxy(fHandle, [address UTF8String]);
689        [sender setStringValue: address];
690        [fDefaults setObject: address forKey: @"ProxyAddress"];
691    }
692    else
693    {
694        NSBeep();
695        [sender setStringValue: [fDefaults stringForKey: @"ProxyAddress"]];
696    }
697}
698
699- (void) setProxyPort: (id) sender
700{
701    int port = [sender intValue];
702    [fDefaults setInteger: port forKey: @"ProxyPort"];
703    tr_sessionSetProxyPort(fHandle, port);
704}
705
706- (void) setProxyType: (id) sender
707{
708    NSString * type;
709    switch ([sender indexOfSelectedItem])
710    {
711        case PROXY_HTTP:
712            type = @"HTTP";
713            break;
714        case PROXY_SOCKS4:
715            type = @"SOCKS4";
716            break;
717        case PROXY_SOCKS5:
718            type = @"SOCKS5";
719    }
720   
721    [fDefaults setObject: type forKey: @"ProxyType"];
722    [self updateProxyType];
723}
724
725- (void) updateProxyType
726{
727    NSString * typeString = [fDefaults stringForKey: @"ProxyType"];
728    tr_proxy_type type;
729    if ([typeString isEqualToString: @"SOCKS4"])
730        type = TR_PROXY_SOCKS4;
731    else if ([typeString isEqualToString: @"SOCKS5"])
732        type = TR_PROXY_SOCKS5;
733    else
734    {
735        //safety
736        if (![typeString isEqualToString: @"HTTP"])
737        {
738            typeString = @"HTTP";
739            [fDefaults setObject: typeString forKey: @"ProxyType"];
740        }
741        type = TR_PROXY_HTTP;
742    }
743   
744    tr_sessionSetProxyType(fHandle, type);
745}
746
747- (void) setProxyAuthorize: (id) sender
748{
749    BOOL enable = [fDefaults boolForKey: @"ProxyAuthorize"];
750    tr_sessionSetProxyAuthEnabled(fHandle, enable);
751}
752
753- (void) setProxyUsername: (id) sender
754{
755    tr_sessionSetProxyUsername(fHandle, [[fDefaults stringForKey: @"ProxyUsername"] UTF8String]);
756}
757
758- (void) setProxyPassword: (id) sender
759{
760    const char * password = [[sender stringValue] UTF8String];
761    [self setKeychainPassword: password forService: PROXY_KEYCHAIN_SERVICE username: PROXY_KEYCHAIN_NAME];
762   
763    tr_sessionSetProxyPassword(fHandle, password);
764}
765
766- (void) updateProxyPassword
767{
768    UInt32 passwordLength;
769    const char * password = nil;
770    SecKeychainFindGenericPassword(NULL, strlen(PROXY_KEYCHAIN_SERVICE), PROXY_KEYCHAIN_SERVICE,
771        strlen(PROXY_KEYCHAIN_NAME), PROXY_KEYCHAIN_NAME, &passwordLength, (void **)&password, NULL);
772   
773    if (password != NULL)
774    {
775        char fullPassword[passwordLength+1];
776        strncpy(fullPassword, password, passwordLength);
777        fullPassword[passwordLength] = '\0';
778        SecKeychainItemFreeContent(NULL, (void *)password);
779       
780        tr_sessionSetProxyPassword(fHandle, fullPassword);
781        [fProxyPasswordField setStringValue: [NSString stringWithUTF8String: fullPassword]];
782    }
783}
784
785- (void) setRPCEnabled: (id) sender
786{
787    tr_sessionSetRPCEnabled(fHandle, [fDefaults boolForKey: @"RPC"]);
788}
789
790- (void) linkWebUI: (id) sender
791{
792    NSString * urlString = [NSString stringWithFormat: WEBUI_URL, [fDefaults integerForKey: @"RPCPort"]];
793    [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: urlString]];
794}
795
796- (void) setRPCAuthorize: (id) sender
797{
798    tr_sessionSetRPCPasswordEnabled(fHandle, [fDefaults boolForKey: @"RPCAuthorize"]);
799}
800
801- (void) setRPCUsername: (id) sender
802{
803    tr_sessionSetRPCUsername(fHandle, [[fDefaults stringForKey: @"RPCUsername"] UTF8String]);
804}
805
806- (void) setRPCPassword: (id) sender
807{
808    const char * password = [[sender stringValue] UTF8String];
809    [self setKeychainPassword: password forService: RPC_KEYCHAIN_SERVICE username: RPC_KEYCHAIN_NAME];
810   
811    tr_sessionSetRPCPassword(fHandle, password);
812}
813
814- (void) updateRPCPassword
815{
816    UInt32 passwordLength;
817    const char * password = nil;
818    SecKeychainFindGenericPassword(NULL, strlen(RPC_KEYCHAIN_SERVICE), RPC_KEYCHAIN_SERVICE,
819        strlen(RPC_KEYCHAIN_NAME), RPC_KEYCHAIN_NAME, &passwordLength, (void **)&password, NULL);
820   
821    if (password != NULL)
822    {
823        char fullPassword[passwordLength+1];
824        strncpy(fullPassword, password, passwordLength);
825        fullPassword[passwordLength] = '\0';
826        SecKeychainItemFreeContent(NULL, (void *)password);
827       
828        tr_sessionSetRPCPassword(fHandle, fullPassword);
829        [fRPCPasswordField setStringValue: [NSString stringWithUTF8String: fullPassword]];
830    }
831}
832
833- (void) setRPCPort: (id) sender
834{
835    int port = [sender intValue];
836    [fDefaults setInteger: port forKey: @"RPCPort"];
837    tr_sessionSetRPCPort(fHandle, port);
838}
839
840- (void) updateRPCAccessList
841{
842    NSMutableArray * components = [NSMutableArray arrayWithCapacity: [fRPCAccessArray count]];
843   
844    NSEnumerator * enumerator = [fRPCAccessArray objectEnumerator];
845    NSDictionary * dict;
846    while ((dict = [enumerator nextObject]))
847        [components addObject: [NSString stringWithFormat: @"%c%@", [[dict objectForKey: @"Allow"] boolValue] ? '+' : '-',
848                                [dict objectForKey: @"IP"]]];
849   
850    NSString * string = [components componentsJoinedByString: @","];
851   
852    char * error = NULL;
853    if (tr_sessionSetRPCACL(fHandle, [string UTF8String], &error))
854    {
855        NSLog([NSString stringWithUTF8String: error]);
856        tr_free(error);
857    }
858}
859
860- (void) addRemoveRPCIP: (id) sender
861{
862    //don't allow add/remove when currently adding - it leads to weird results
863    if ([fRPCAccessTable editedRow] != -1)
864        return;
865   
866    if ([[sender cell] tagForSegment: [sender selectedSegment]] == RPC_IP_REMOVE_TAG)
867    {
868        [fRPCAccessArray removeObjectsAtIndexes: [fRPCAccessTable selectedRowIndexes]];
869        [fRPCAccessTable deselectAll: self];
870        [fRPCAccessTable reloadData];
871       
872        [fDefaults setObject: fRPCAccessArray forKey: @"RPCAccessList"];
873        [self updateRPCAccessList];
874    }
875    else
876    {
877        [fRPCAccessArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: @"", @"IP",
878                                        [NSNumber numberWithBool: YES], @"Allow", nil]];
879        [fRPCAccessTable reloadData];
880       
881        int row = [fRPCAccessArray count] - 1;
882        [fRPCAccessTable selectRow: row byExtendingSelection: NO];
883        [fRPCAccessTable editColumn: 0 row: row withEvent: nil select: YES];
884    }
885}
886
887- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView
888{
889    return [fRPCAccessArray count];
890}
891
892- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
893{
894    NSDictionary * dict = [fRPCAccessArray objectAtIndex: row];
895   
896    NSString * ident = [tableColumn identifier];
897    if ([ident isEqualToString: @"Permission"])
898    {
899        int allow = [[dict objectForKey: @"Allow"] boolValue] ? RPC_ACCESS_ALLOW : RPC_ACCESS_DENY;
900        return [NSNumber numberWithInt: allow];
901    }
902    else
903        return [dict objectForKey: @"IP"];
904}
905
906- (void) tableView: (NSTableView *) tableView setObjectValue: (id) object forTableColumn: (NSTableColumn *) tableColumn
907    row: (NSInteger) row
908{
909    NSDictionary * oldDict = [fRPCAccessArray objectAtIndex: row];
910   
911    NSString * ident = [tableColumn identifier];
912    if ([ident isEqualToString: @"Permission"])
913    {
914        NSNumber * allow = [NSNumber numberWithBool: [object intValue] == RPC_ACCESS_ALLOW];
915        NSDictionary * newDict = [NSDictionary dictionaryWithObjectsAndKeys: [oldDict objectForKey: @"IP"], @"IP", allow, @"Allow", nil];
916        [fRPCAccessArray replaceObjectAtIndex: row withObject: newDict];
917    }
918    else
919    {
920        NSArray * components = [object componentsSeparatedByString: @"."];
921        NSMutableArray * newComponents = [NSMutableArray arrayWithCapacity: 4];
922       
923        //create better-formatted ip string
924        if ([components count] == 4)
925        {
926            NSEnumerator * enumerator = [components objectEnumerator];
927            NSString * component;
928            while ((component = [enumerator nextObject]))
929            {
930                if ([component isEqualToString: @"*"])
931                    [newComponents addObject: component];
932                else
933                    [newComponents addObject: [[NSNumber numberWithInt: [component intValue]] stringValue]];
934            }
935        }
936       
937        NSString * newIP = [newComponents componentsJoinedByString: @"."];
938       
939        //verify ip string
940        if (!tr_sessionTestRPCACL(fHandle, [[@"+" stringByAppendingString: newIP] UTF8String], NULL))
941        {
942            NSDictionary * newDict = [NSDictionary dictionaryWithObjectsAndKeys: newIP, @"IP",
943                                        [oldDict objectForKey: @"Allow"], @"Allow", nil];
944            [fRPCAccessArray replaceObjectAtIndex: row withObject: newDict];
945           
946            NSSortDescriptor * descriptor = [[[NSSortDescriptor alloc] initWithKey: @"IP" ascending: YES
947                                                selector: @selector(compareNumeric:)] autorelease];
948            [fRPCAccessArray sortUsingDescriptors: [NSArray arrayWithObject: descriptor]];
949        }
950        else
951        {
952            NSBeep();
953           
954            if ([[oldDict objectForKey: @"IP"] isEqualToString: @""])
955                [fRPCAccessArray removeObjectAtIndex: row];
956        }
957       
958        [fRPCAccessTable deselectAll: self];
959        [fRPCAccessTable reloadData];
960    }
961   
962    [fDefaults setObject: fRPCAccessArray forKey: @"RPCAccessList"];
963    [self updateRPCAccessList];
964}
965
966- (void) tableViewSelectionDidChange: (NSNotification *) notification
967{
968    [fRPCAddRemoveControl setEnabled: [fRPCAccessTable numberOfSelectedRows] > 0 forSegment: RPC_IP_REMOVE_TAG];
969}
970
971- (void) helpForPeers: (id) sender
972{
973    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PeersPrefs"
974        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
975}
976
977- (void) helpForNetwork: (id) sender
978{
979    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"NetworkPrefs"
980        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
981}
982
983- (void) helpForRemote: (id) sender
984{
985    [[NSHelpManager sharedHelpManager] openHelpAnchor: @"RemotePrefs"
986        inBook: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookName"]];
987}
988
989- (void) rpcUpdatePrefs
990{
991    //encryption
992    tr_encryption_mode encryptionMode = tr_sessionGetEncryption(fHandle);
993    [fDefaults setBool: encryptionMode != TR_CLEAR_PREFERRED forKey: @"EncryptionPrefer"];
994    [fDefaults setBool: encryptionMode == TR_ENCRYPTION_REQUIRED forKey: @"EncryptionRequire"];
995   
996    //download directory
997    NSString * downloadLocation = [[NSString stringWithUTF8String: tr_sessionGetDownloadDir(fHandle)] stringByStandardizingPath];
998    [fDefaults setObject: downloadLocation forKey: @"DownloadFolder"];
999   
1000    //peers
1001    uint16_t peersTotal = tr_sessionGetPeerLimit(fHandle);
1002    [fDefaults setInteger: peersTotal forKey: @"PeersTotal"];
1003   
1004    //pex
1005    BOOL pex = tr_sessionIsPexEnabled(fHandle);
1006    [fDefaults setBool: pex forKey: @"PEXGlobal"];
1007   
1008    //port
1009    int port = tr_sessionGetPeerPort(fHandle);
1010    [fDefaults setInteger: port forKey: @"BindPort"];
1011   
1012    BOOL nat = tr_sessionIsPortForwardingEnabled(fHandle);
1013    [fDefaults setBool: nat forKey: @"NatTraversal"];
1014   
1015    fPeerPort = -1;
1016    fNatStatus = -1;
1017    [self updatePortStatus];
1018   
1019    //speed limit - down
1020    BOOL downLimitEnabled = tr_sessionIsSpeedLimitEnabled(fHandle, TR_DOWN);
1021    [fDefaults setBool: downLimitEnabled forKey: @"CheckDownload"];
1022   
1023    int downLimit = tr_sessionGetSpeedLimit(fHandle, TR_DOWN);
1024    [fDefaults setInteger: downLimit forKey: @"DownloadLimit"];
1025   
1026    //speed limit - up
1027    BOOL upLimitEnabled = tr_sessionIsSpeedLimitEnabled(fHandle, TR_UP);
1028    [fDefaults setBool: upLimitEnabled forKey: @"CheckUpload"];
1029   
1030    int upLimit = tr_sessionGetSpeedLimit(fHandle, TR_UP);
1031    [fDefaults setInteger: upLimit forKey: @"UploadLimit"];
1032   
1033    //update gui if loaded
1034    if (fHasLoaded)
1035    {
1036        //encryption handled by bindings
1037       
1038        //download directory handled by bindings
1039       
1040        [fPeersGlobalField setIntValue: peersTotal];
1041       
1042        //pex handled by bindings
1043       
1044        [fPortField setIntValue: port];
1045        //port forwarding (nat) handled by bindings
1046       
1047        //limit check handled by bindings
1048        [fDownloadField setIntValue: downLimit];
1049       
1050        //limit check handled by bindings
1051        [fUploadField setIntValue: upLimit];
1052    }
1053}
1054
1055@end
1056
1057@implementation PrefsController (Private)
1058
1059- (void) setPrefView: (id) sender
1060{
1061    NSView * view = fGeneralView;
1062    if (sender)
1063    {
1064        NSString * identifier = [sender itemIdentifier];
1065        if ([identifier isEqualToString: TOOLBAR_TRANSFERS])
1066            view = fTransfersView;
1067        else if ([identifier isEqualToString: TOOLBAR_BANDWIDTH])
1068            view = fBandwidthView;
1069        else if ([identifier isEqualToString: TOOLBAR_PEERS])
1070            view = fPeersView;
1071        else if ([identifier isEqualToString: TOOLBAR_NETWORK])
1072            view = fNetworkView;
1073        else if ([identifier isEqualToString: TOOLBAR_REMOTE])
1074            view = fRemoteView;
1075        else; //general view already selected
1076    }
1077   
1078    NSWindow * window = [self window];
1079    if ([window contentView] == view)
1080        return;
1081   
1082    NSRect windowRect = [window frame];
1083    float difference = ([view frame].size.height - [[window contentView] frame].size.height) * [window userSpaceScaleFactor];
1084    windowRect.origin.y -= difference;
1085    windowRect.size.height += difference;
1086   
1087    [view setHidden: YES];
1088    [window setContentView: view];
1089    [window setFrame: windowRect display: YES animate: YES];
1090    [view setHidden: NO];
1091   
1092    //set title label
1093    if (sender)
1094        [window setTitle: [sender label]];
1095    else
1096    {
1097        NSToolbar * toolbar = [window toolbar];
1098        NSString * itemIdentifier = [toolbar selectedItemIdentifier];
1099        NSEnumerator * enumerator = [[toolbar items] objectEnumerator];
1100        NSToolbarItem * item;
1101        while ((item = [enumerator nextObject]))
1102            if ([[item itemIdentifier] isEqualToString: itemIdentifier])
1103            {
1104                [window setTitle: [item label]];
1105                break;
1106            }
1107    }
1108   
1109    //for network view make sure progress indicator hides itself (get around a Tiger bug)
1110    if (![NSApp isOnLeopardOrBetter] && view == fNetworkView && [fPortStatusImage image])
1111        [fPortStatusProgress setDisplayedWhenStopped: NO];
1112}
1113
1114- (void) folderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
1115{
1116    if (code == NSOKButton)
1117    {
1118        [fFolderPopUp selectItemAtIndex: DOWNLOAD_FOLDER];
1119        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"DownloadFolder"];
1120        [fDefaults setObject: @"Constant" forKey: @"DownloadChoice"];
1121    }
1122    else
1123    {
1124        //reset if cancelled
1125        [fFolderPopUp selectItemAtIndex: [fDefaults boolForKey: @"DownloadLocationConstant"] ? DOWNLOAD_FOLDER : DOWNLOAD_TORRENT];
1126    }
1127}
1128
1129- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
1130{
1131    if (code == NSOKButton)
1132        [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
1133    [fIncompleteFolderPopUp selectItemAtIndex: 0];
1134}
1135
1136- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
1137{
1138    NSString * path = [fDefaults stringForKey: @"AutoImportDirectory"];
1139    if (code == NSOKButton)
1140    {
1141        UKKQueue * sharedQueue = [UKKQueue sharedFileWatcher];
1142        if (path)
1143            [sharedQueue removePathFromQueue: [path stringByExpandingTildeInPath]];
1144       
1145        path = [[openPanel filenames] objectAtIndex: 0];
1146        [fDefaults setObject: path forKey: @"AutoImportDirectory"];
1147        [sharedQueue addPath: [path stringByExpandingTildeInPath]];
1148       
1149        [[NSNotificationCenter defaultCenter] postNotificationName: @"AutoImportSettingChange" object: self];
1150    }
1151    else if (!path)
1152        [fDefaults setBool: NO forKey: @"AutoImport"];
1153   
1154    [fImportFolderPopUp selectItemAtIndex: 0];
1155}
1156
1157- (void) setKeychainPassword: (const char *) password forService: (const char *) service username: (const char *) username
1158{
1159    SecKeychainItemRef item = NULL;
1160    NSUInteger passwordLength = strlen(password);
1161   
1162    OSStatus result = SecKeychainFindGenericPassword(NULL, strlen(service), service, strlen(username), username, NULL, NULL, &item);
1163    if (result == noErr && item)
1164    {
1165        if (passwordLength > 0) //found, so update
1166        {
1167            result = SecKeychainItemModifyAttributesAndData(item, NULL, passwordLength, (const void *)password);
1168            if (result != noErr)
1169                NSLog(@"Problem updating Keychain item: %s", GetMacOSStatusErrorString(result));
1170        }
1171        else //remove the item
1172        {
1173            result = SecKeychainItemDelete(item);
1174            if (result != noErr)
1175                NSLog(@"Problem removing Keychain item: %s", GetMacOSStatusErrorString(result));
1176        }
1177    }
1178    else if (result == errSecItemNotFound) //not found, so add
1179    {
1180        if (passwordLength > 0)
1181        {
1182            result = SecKeychainAddGenericPassword(NULL, strlen(service), service, strlen(username), username,
1183                        passwordLength, (const void *)password, NULL);
1184            if (result != noErr)
1185                NSLog(@"Problem adding Keychain item: %s", GetMacOSStatusErrorString(result));
1186        }
1187    }
1188    else
1189        NSLog(@"Problem accessing Keychain: %s", GetMacOSStatusErrorString(result));
1190}
1191
1192@end
Note: See TracBrowser for help on using the repository browser.