Revision: 2912
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2912&view=rev
Author:   hofman
Date:     2007-09-12 12:23:19 -0700 (Wed, 12 Sep 2007)

Log Message:
-----------
Change hidden default for saving the password. Make it an int, so we can set it 
to Always=1, Never=0 or Ask=-1.

Modified Paths:
--------------
    trunk/InitialUserDefaults.plist
    trunk/SKPDFView.m
    trunk/SKStringConstants.h
    trunk/SKStringConstants.m

Modified: trunk/InitialUserDefaults.plist
===================================================================
--- trunk/InitialUserDefaults.plist     2007-09-12 19:05:23 UTC (rev 2911)
+++ trunk/InitialUserDefaults.plist     2007-09-12 19:23:19 UTC (rev 2912)
@@ -218,6 +218,8 @@
         <real>2.0</real>
         <key>SKReadMissingNotesFromSkimFileOption</key>
         <integer>-1</integer>
+        <key>SKSavePasswordOption</key>
+        <integer>-1</integer>
         <key>SKBlankAllScreensInFullScreen</key>
         <false/>
         <key>SKAutoCropBoxMarginHeight</key>
@@ -324,6 +326,7 @@
             <string>SKActivateFullScreenNavigationAtBottom</string>
             <string>SKActivatePresentationNavigationAtBottom</string>
             <string>SKReadMissingNotesFromSkimFileOption</string>
+            <string>SKSavePasswordOption</string>
             <string>SKEnableAppleRemote</string>
         </array>
     </dict>

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2007-09-12 19:05:23 UTC (rev 2911)
+++ trunk/SKPDFView.m   2007-09-12 19:23:19 UTC (rev 2912)
@@ -453,7 +453,7 @@
 #pragma mark Accessors
 
 - (void)setDocument:(PDFDocument *)document {
-    if ([document isLocked] && [[NSUserDefaults standardUserDefaults] 
boolForKey:@"SKDisableSavingPassword"] == NO)
+    if ([document isLocked])
         [self tryToUnlockDocument:document];
     [readingBar release];
     readingBar = nil;
@@ -3685,21 +3685,24 @@
 }
 
 - (void)tryToUnlockDocument:(PDFDocument *)document {
-    NSArray *fileIDStrings = [(SKDocument *)[[[self window] windowController] 
document] fileIDStrings];
-    NSString *fileIDString = [fileIDStrings count] ? [fileIDStrings 
objectAtIndex:0] : nil;
-    if (fileIDString) {
-        const char *serviceName = [[NSString stringWithFormat:@"Skim - %@", 
fileIDString] UTF8String];
-        const char *userName = [NSUserName() UTF8String];
-        void *passwordData = NULL;
-        UInt32 passwordLength = 0;
-        NSData *data = nil;
-        NSString *password = nil;
-        OSErr err = SecKeychainFindGenericPassword(NULL, strlen(serviceName), 
serviceName, strlen(userName), userName, &passwordLength, &passwordData, NULL);
-        if (err == noErr) {
-            data = [NSData dataWithBytes:passwordData length:passwordLength];
-            SecKeychainItemFreeContent(NULL, passwordData);
-            password = [[[NSString alloc] initWithData:data 
encoding:NSUTF8StringEncoding] autorelease];
-            [document unlockWithPassword:password];
+    int saveOption = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKSavePasswordOptionKey];
+    if (saveOption != NSAlertAlternateReturn) {
+        NSArray *fileIDStrings = [(SKDocument *)[[[self window] 
windowController] document] fileIDStrings];
+        NSString *fileIDString = [fileIDStrings count] ? [fileIDStrings 
objectAtIndex:0] : nil;
+        if (fileIDString) {
+            const char *serviceName = [[NSString stringWithFormat:@"Skim - 
%@", fileIDString] UTF8String];
+            const char *userName = [NSUserName() UTF8String];
+            void *passwordData = NULL;
+            UInt32 passwordLength = 0;
+            NSData *data = nil;
+            NSString *password = nil;
+            OSErr err = SecKeychainFindGenericPassword(NULL, 
strlen(serviceName), serviceName, strlen(userName), userName, &passwordLength, 
&passwordData, NULL);
+            if (err == noErr) {
+                data = [NSData dataWithBytes:passwordData 
length:passwordLength];
+                SecKeychainItemFreeContent(NULL, passwordData);
+                password = [[[NSString alloc] initWithData:data 
encoding:NSUTF8StringEncoding] autorelease];
+                [document unlockWithPassword:password];
+            }
         }
     }
 }
@@ -3808,53 +3811,56 @@
 
 - (void)replacementPasswordEntered:(id)sender {
     originalPasswordEntered(self, _cmd, sender);
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:@"SKDisableSavingPassword"] == NO) {
-        SKDocument *document = [[[self window] windowController] document];
-        if ([document isKindOfClass:[SKDocument class]] && [[document 
pdfDocument] isLocked] == NO)
-            [self savePasswordInKeychain:[sender stringValue]];
-    }
+    [self savePasswordInKeychain:[sender stringValue]];
 }
 
 - (void)savePasswordInKeychain:(NSString *)password {
     SKDocument *document = [[[self window] windowController] document];
-    NSArray *fileIDStrings = [document fileIDStrings];
-    NSString *fileIDString = [fileIDStrings count] ? [fileIDStrings 
objectAtIndex:0] : nil;
-    if (fileIDString) {
-        NSAlert *alert = [NSAlert alertWithMessageText:[NSString 
stringWithFormat:NSLocalizedString(@"Remember Password?", @"Message in alert 
dialog")]
-                                         
defaultButton:NSLocalizedString(@"Yes", @"Button title")
-                                       
alternateButton:NSLocalizedString(@"No", @"Button title")
-                                           otherButton:nil
-                             informativeTextWithFormat:NSLocalizedString(@"Do 
you want to save this password in your Keychain?", @"Informative text in alert 
dialog")];
-        if ([alert runModal] == NSAlertDefaultReturn) {
-            const char *userNameCString = [NSUserName() UTF8String];
-            const char *nameCString = [[NSString stringWithFormat:@"Skim - 
%@", fileIDString] UTF8String];
-            
-            OSStatus err;
-            SecKeychainItemRef itemRef = NULL;    
-            const void *passwordData = NULL;
-            UInt32 passwordLength = 0;
-            
-            // first see if the password exists in the keychain
-            err = SecKeychainFindGenericPassword(NULL, strlen(nameCString), 
nameCString, strlen(userNameCString), userNameCString, &passwordLength, (void 
**)&passwordData, &itemRef);
-            
-            if(err == noErr){
-                // password was on keychain, so flush the buffer and then 
modify the keychain
-                SecKeychainItemFreeContent(NULL, (void *)passwordData);
-                passwordData = NULL;
+    int saveOption = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKSavePasswordOptionKey];
+    if ([document isKindOfClass:[SKDocument class]] && [[document pdfDocument] 
isLocked] == NO && saveOption != NSAlertAlternateReturn) {
+        SKDocument *document = [[[self window] windowController] document];
+        NSArray *fileIDStrings = [document fileIDStrings];
+        NSString *fileIDString = [fileIDStrings count] ? [fileIDStrings 
objectAtIndex:0] : nil;
+        if (fileIDString) {
+            if (saveOption == NSAlertOtherReturn) {
+                NSAlert *alert = [NSAlert alertWithMessageText:[NSString 
stringWithFormat:NSLocalizedString(@"Remember Password?", @"Message in alert 
dialog")]
+                                                 
defaultButton:NSLocalizedString(@"Yes", @"Button title")
+                                               
alternateButton:NSLocalizedString(@"No", @"Button title")
+                                                   otherButton:nil
+                                     
informativeTextWithFormat:NSLocalizedString(@"Do you want to save this password 
in your Keychain?", @"Informative text in alert dialog")];
+                saveOption = [alert runModal];
+            }
+            if (saveOption == NSAlertDefaultReturn) {
+                const char *userNameCString = [NSUserName() UTF8String];
+                const char *nameCString = [[NSString stringWithFormat:@"Skim - 
%@", fileIDString] UTF8String];
                 
-                passwordData = [password UTF8String];
-                SecKeychainAttribute attrs[] = {
-                    { kSecAccountItemAttr, strlen(userNameCString), (char 
*)userNameCString },
-                    { kSecServiceItemAttr, strlen(nameCString), (char 
*)nameCString } };
-                const SecKeychainAttributeList attributes = { sizeof(attrs) / 
sizeof(attrs[0]), attrs };
+                OSStatus err;
+                SecKeychainItemRef itemRef = NULL;    
+                const void *passwordData = NULL;
+                UInt32 passwordLength = 0;
                 
-                err = SecKeychainItemModifyAttributesAndData(itemRef, 
&attributes, strlen(passwordData), passwordData);
-            } else if(err == errSecItemNotFound){
-                // password not on keychain, so add it
-                passwordData = [password UTF8String];
-                err = SecKeychainAddGenericPassword(NULL, strlen(nameCString), 
nameCString, strlen(userNameCString), userNameCString, strlen(passwordData), 
passwordData, &itemRef);    
-            } else 
-                NSLog(@"Error %d occurred setting password", err);
+                // first see if the password exists in the keychain
+                err = SecKeychainFindGenericPassword(NULL, 
strlen(nameCString), nameCString, strlen(userNameCString), userNameCString, 
&passwordLength, (void **)&passwordData, &itemRef);
+                
+                if(err == noErr){
+                    // password was on keychain, so flush the buffer and then 
modify the keychain
+                    SecKeychainItemFreeContent(NULL, (void *)passwordData);
+                    passwordData = NULL;
+                    
+                    passwordData = [password UTF8String];
+                    SecKeychainAttribute attrs[] = {
+                        { kSecAccountItemAttr, strlen(userNameCString), (char 
*)userNameCString },
+                        { kSecServiceItemAttr, strlen(nameCString), (char 
*)nameCString } };
+                    const SecKeychainAttributeList attributes = { 
sizeof(attrs) / sizeof(attrs[0]), attrs };
+                    
+                    err = SecKeychainItemModifyAttributesAndData(itemRef, 
&attributes, strlen(passwordData), passwordData);
+                } else if(err == errSecItemNotFound){
+                    // password not on keychain, so add it
+                    passwordData = [password UTF8String];
+                    err = SecKeychainAddGenericPassword(NULL, 
strlen(nameCString), nameCString, strlen(userNameCString), userNameCString, 
strlen(passwordData), passwordData, &itemRef);    
+                } else 
+                    NSLog(@"Error %d occurred setting password", err);
+            }
         }
     }
 }

Modified: trunk/SKStringConstants.h
===================================================================
--- trunk/SKStringConstants.h   2007-09-12 19:05:23 UTC (rev 2911)
+++ trunk/SKStringConstants.h   2007-09-12 19:23:19 UTC (rev 2912)
@@ -100,6 +100,7 @@
 extern NSString *SKEnableAppleRemoteKey;
 extern NSString *SKAppleRemoteSwitchIndicationTimeoutKey;
 extern NSString *SKReadMissingNotesFromSkimFileOptionKey;
+extern NSString *SKSavePasswordOptionKey;
 extern NSString *SKBlankAllScreensInFullScreenKey;
 extern NSString *SKActivateFullScreenNavigationAtBottomKey;
 extern NSString *SKActivatePresentationNavigationAtBottomKey;

Modified: trunk/SKStringConstants.m
===================================================================
--- trunk/SKStringConstants.m   2007-09-12 19:05:23 UTC (rev 2911)
+++ trunk/SKStringConstants.m   2007-09-12 19:23:19 UTC (rev 2912)
@@ -101,6 +101,7 @@
 NSString *SKEnableAppleRemoteKey = @"SKEnableAppleRemote";
 NSString *SKAppleRemoteSwitchIndicationTimeoutKey = 
@"SKAppleRemoteSwitchIndicationTimeout";
 NSString *SKReadMissingNotesFromSkimFileOptionKey = 
@"SKReadMissingNotesFromSkimFileOption";
+NSString *SKSavePasswordOptionKey = @"SKSavePasswordOption";
 NSString *SKBlankAllScreensInFullScreenKey = @"SKBlankAllScreensInFullScreen";
 NSString *SKActivateFullScreenNavigationAtBottomKey = 
@"SKActivateFullScreenNavigationAtBottom";
 NSString *SKActivatePresentationNavigationAtBottomKey = 
@"SKActivatePresentationNavigationAtBottom";


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to