Revision: 3134
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3134&view=rev
Author:   hofman
Date:     2007-11-02 12:24:48 -0700 (Fri, 02 Nov 2007)

Log Message:
-----------
Unlock pdfdocument when removing converted notes if needed and if we have the 
password. Cache the password for this purpose. Disable convert notes menu item 
when the document is locked.

Modified Paths:
--------------
    trunk/SKDocument.h
    trunk/SKDocument.m

Modified: trunk/SKDocument.h
===================================================================
--- trunk/SKDocument.h  2007-11-02 18:38:53 UTC (rev 3133)
+++ trunk/SKDocument.h  2007-11-02 19:24:48 UTC (rev 3134)
@@ -67,6 +67,7 @@
     
     // variables to be saved:
     NSData *pdfData;
+    NSString *password;
     
     // temporary variables:
     PDFDocument *pdfDocument;

Modified: trunk/SKDocument.m
===================================================================
--- trunk/SKDocument.m  2007-11-02 18:38:53 UTC (rev 3133)
+++ trunk/SKDocument.m  2007-11-02 19:24:48 UTC (rev 3134)
@@ -89,6 +89,7 @@
 - (void)setPDFData:(NSData *)data;
 - (void)setPDFDoc:(PDFDocument *)doc;
 - (void)setNoteDicts:(NSArray *)array;
+- (void)setPassword:(NSString *)newPassword;
 
 - (void)tryToUnlockDocument:(PDFDocument *)document;
 
@@ -115,6 +116,7 @@
     [synchronizer release];
     [watchedFile release];
     [pdfData release];
+    [password release];
     [noteDicts release];
     [readNotesAccessoryView release];
     [lastModifiedDate release];
@@ -152,7 +154,6 @@
     }
     
     [mainController setPdfDocument:pdfDocument];
-    [self setPDFDoc:nil];
     
     [mainController setAnnotationsFromDictionaries:noteDicts undoable:NO];
     [self setNoteDicts:nil];
@@ -508,6 +509,13 @@
     }
 }
 
+- (void)setPassword:(NSString *)newPassword {
+    if (password != newPassword) {
+        [password release];
+        password = [newPassword retain];
+    }
+}
+
 - (BOOL)readFromData:(NSData *)data ofType:(NSString *)docType error:(NSError 
**)outError;
 {
     BOOL didRead = NO;
@@ -780,6 +788,8 @@
     
     if (didConvert) {
         pdfDoc = [[PDFDocument alloc] initWithData:pdfData];
+        if ([pdfDoc isLocked] && password)
+            [pdfDoc unlockWithPassword:password];
         count = [pdfDoc pageCount];
         for (i = 0; i < count; i++) {
             PDFPage *page = [pdfDoc pageAtIndex:i];
@@ -985,6 +995,8 @@
         return [self isDocumentEdited] || fileChangedOnDisk;
     } else if ([anItem action] == @selector(printDocument:)) {
         return [[self pdfDocument] allowsPrinting];
+    } else if ([anItem action] == @selector(convertNotes:)) {
+        return [[self pdfDocument] isLocked] == NO;
     }
     return [super validateUserInterfaceItem:anItem];
 }
@@ -1530,8 +1542,13 @@
 #pragma mark Passwords
 
 - (void)savePasswordInKeychain:(NSString *)password {
+    if ([[self pdfDocument] isLocked])
+        return;
+    
+    [self setPassword:password];
+    
     int saveOption = [[NSUserDefaults standardUserDefaults] 
integerForKey:SKSavePasswordOptionKey];
-    if ([[self pdfDocument] isLocked] == NO && saveOption != 
NSAlertAlternateReturn) {
+    if (saveOption != NSAlertAlternateReturn) {
         NSArray *fileIDStrings = [self fileIDStrings];
         NSString *fileIDString = [fileIDStrings count] ? [fileIDStrings 
objectAtIndex:0] : nil;
         if (fileIDString) {
@@ -1595,7 +1612,8 @@
                 data = [NSData dataWithBytes:passwordData 
length:passwordLength];
                 SecKeychainItemFreeContent(NULL, passwordData);
                 password = [[[NSString alloc] initWithData:data 
encoding:NSUTF8StringEncoding] autorelease];
-                [document unlockWithPassword:password];
+                if ([document unlockWithPassword:password])
+                    [self setPassword:password];
             }
         }
     }


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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to