Revision: 5163
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5163&view=rev
Author:   hofman
Date:     2009-01-25 18:15:35 +0000 (Sun, 25 Jan 2009)

Log Message:
-----------
Add some initial support for Open Meta tags and rating. Currently it's all 
hidden and they're not saved, only read. 

Modified Paths:
--------------
    trunk/SKMainWindowController.h
    trunk/SKMainWindowController.m
    trunk/SKPDFDocument.h
    trunk/SKPDFDocument.m
    trunk/Skim.sdef

Modified: trunk/SKMainWindowController.h
===================================================================
--- trunk/SKMainWindowController.h      2009-01-25 16:27:03 UTC (rev 5162)
+++ trunk/SKMainWindowController.h      2009-01-25 18:15:35 UTC (rev 5163)
@@ -171,6 +171,9 @@
     NSTimer                     *snapshotTimer;
     float                       roundedSnapshotThumbnailSize;
     
+    NSMutableArray              *tags;
+    double                      rating;
+    
     NSWindow                    *mainWindow;
     SKFullScreenWindow          *fullScreenWindow;
     SKSideWindow                *leftSideWindow;
@@ -385,6 +388,12 @@
 - (void)insertObject:(SKGroupedSearchResult *)groupedSearchResult 
inGroupedSearchResultsAtIndex:(unsigned int)theIndex;
 - (void)removeObjectFromGroupedSearchResultsAtIndex:(unsigned int)theIndex;
 
+- (NSArray *)tags;
+- (void)setTags:(NSArray *)newTags;
+
+- (double)rating;
+- (void)setRating:(double)newRating;
+
 - (NSArray *)selectedNotes;
 
 - (unsigned int)pageNumber;
@@ -449,6 +458,9 @@
 - (void)addAnnotationsFromDictionaries:(NSArray *)noteDicts 
undoable:(BOOL)undoable;
 - (void)setAnnotationsFromDictionaries:(NSArray *)noteDicts 
undoable:(BOOL)undoable;
 
+- (void)setOpenMetaTags:(NSArray *)tags;
+- (void)setOpenMetaRating:(double)rating;
+
 - (void)setInitialSetup:(NSDictionary *)setup;
 - (NSDictionary *)currentSetup;
 - (void)applyPDFSettings:(NSDictionary *)setup;

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2009-01-25 16:27:03 UTC (rev 5162)
+++ trunk/SKMainWindowController.m      2009-01-25 18:15:35 UTC (rev 5163)
@@ -231,6 +231,8 @@
         groupedSearchResults = [[NSMutableArray alloc] init];
         thumbnails = [[NSMutableArray alloc] init];
         notes = [[NSMutableArray alloc] init];
+        tags = [[NSArray alloc] init];
+        rating = 0.0;
         snapshots = [[NSMutableArray alloc] init];
         dirtySnapshots = [[NSMutableArray alloc] init];
         pageLabels = [[NSMutableArray alloc] init];
@@ -270,6 +272,7 @@
        [thumbnails release];
        [notes release];
        [snapshots release];
+       [tags release];
     [pageLabels release];
     [pageLabel release];
        CFRelease(rowHeights);
@@ -842,6 +845,18 @@
     [self addAnnotationsFromDictionaries:noteDicts undoable:undoable];
 }
 
+
+- (void)setOpenMetaTags:(NSArray *)newTags {
+    if (tags != newTags) {
+        [tags release];
+        tags = [newTags retain] ?: [[NSArray alloc] init];
+    }
+}
+
+- (void)setOpenMetaRating:(double)newRating {
+    rating = newRating;
+}
+
 - (SKPDFView *)pdfView {
     return pdfView;
 }
@@ -1183,6 +1198,34 @@
     [groupedSearchResults removeObjectAtIndex:theIndex];
 }
 
+- (NSArray *)tags {
+    return tags;
+}
+
+- (void)setTags:(NSArray *)newTags {
+    if (newTags == nil) newTags = [NSArray array];
+    if (tags != newTags) {
+        NSUndoManager *undoManager = [[self document] undoManager];
+        [[undoManager prepareWithInvocationTarget:self] setTags:tags];
+        [undoManager setActionName:NSLocalizedString(@"Edit Tags", @"Undo 
action name")];
+        [tags release];
+        tags = [newTags retain];
+    }
+}
+
+- (double)rating {
+    return rating;
+}
+
+- (void)setRating:(double)newRating {
+    if (fabs(rating - newRating) > 0.0) {
+        NSUndoManager *undoManager = [[self document] undoManager];
+        [[undoManager prepareWithInvocationTarget:self] setRating:rating];
+        [undoManager setActionName:NSLocalizedString(@"Edit Rating", @"Undo 
action name")];
+        rating = newRating;
+    }
+}
+
 #pragma mark Actions
 
 - (IBAction)changeColor:(id)sender{

Modified: trunk/SKPDFDocument.h
===================================================================
--- trunk/SKPDFDocument.h       2009-01-25 16:27:03 UTC (rev 5162)
+++ trunk/SKPDFDocument.h       2009-01-25 18:15:35 UTC (rev 5163)
@@ -76,6 +76,8 @@
     // temporary variables:
     PDFDocument *pdfDocument;
     NSMutableArray *noteDicts;
+    NSArray *openMetaTags;
+    double openMetaRating;
     
     SKProgressController *progressController;
     
@@ -136,6 +138,10 @@
 - (void)insertInNotes:(PDFAnnotation *)newNote;
 - (void)insertObject:(PDFAnnotation *)newNote inNotesAtIndex:(unsigned 
int)anIndex;
 - (void)removeObjectFromNotesAtIndex:(unsigned int)anIndex;
+- (NSArray *)tags;
+- (void)setTags:(NSArray *)newTags;
+- (double)rating;
+- (void)setRating:(double)newRating;
 - (PDFPage *)currentPage;
 - (void)setCurrentPage:(PDFPage *)page;
 - (id)activeNote;

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2009-01-25 16:27:03 UTC (rev 5162)
+++ trunk/SKPDFDocument.m       2009-01-25 18:15:35 UTC (rev 5163)
@@ -77,6 +77,8 @@
 #import "SKRuntime.h"
 
 #define BUNDLE_DATA_FILENAME @"data"
+#define OPEN_META_TAGS_KEY @"com.apple.metadata:kOMUserTags"
+#define OPEN_META_RATING_KEY @"com.apple.metadata:kOMStarRating"
 
 NSString *SKPDFDocumentWillSaveNotification = 
@"SKPDFDocumentWillSaveNotification";
 NSString *SKSkimFileDidSaveNotification = @"SKSkimFileDidSaveNotification";
@@ -93,6 +95,8 @@
 - (void)setPDFData:(NSData *)data;
 - (void)setPDFDoc:(PDFDocument *)doc;
 - (void)setNoteDicts:(NSArray *)array;
+- (void)setOpenMetaTags:(NSArray *)array;
+- (void)setOpenMetaRating:(double)rating;
 - (void)setPassword:(NSString *)newPassword;
 
 - (void)tryToUnlockDocument:(PDFDocument *)document;
@@ -126,6 +130,7 @@
     [pdfDocument release];
     [password release];
     [noteDicts release];
+    [openMetaTags release];
     [readNotesAccessoryView release];
     [lastModifiedDate release];
     [progressController release];
@@ -166,6 +171,12 @@
     [mainController setAnnotationsFromDictionaries:noteDicts undoable:NO];
     [self setNoteDicts:nil];
     
+    [mainController setOpenMetaTags:openMetaTags];
+    [self setOpenMetaTags:nil];
+    
+    [mainController setOpenMetaRating:openMetaRating];
+    [self setOpenMetaRating:0.0];
+    
     [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self 
forKey:SKAutoCheckFileUpdateKey 
context:SKPDFDocumentDefaultsObservationContext];
        [[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(handleWindowWillCloseNotification:) 
                                                  
name:NSWindowWillCloseNotification object:[mainController window]];
@@ -350,7 +361,19 @@
                                      informativeTextWithFormat:[NSString 
stringWithFormat:message, [[absoluteURL path] lastPathComponent]]];
                 [alert runModal];
             }
+            /*
+            SKNExtendedAttributeManager *eam = [SKNExtendedAttributeManager 
sharedNoSplitManager];
             
+            if ([[self tags] count])
+                [eam setExtendedAttributeNamed:OPEN_META_TAGS_KEY 
toPropertyListValue:[self tags] atPath:[absoluteURL path] 
options:kSKNXattrNoCompress error:NULL];
+            else
+                [eam removeExtendedAttribute:OPEN_META_TAGS_KEY 
atPath:[absoluteURL path] traverseLink:YES error:NULL];
+            
+            if ([self rating] > 0.0)
+                [eam setExtendedAttributeNamed:OPEN_META_RATING_KEY 
toPropertyListValue:[NSNumber numberWithDouble:[self rating]] 
atPath:[absoluteURL path] options:kSKNXattrNoCompress error:NULL];
+            else
+                [eam removeExtendedAttribute:OPEN_META_RATING_KEY 
atPath:[absoluteURL path] traverseLink:YES error:NULL];
+            */
             if (success)
                 [[NSDistributedNotificationCenter defaultCenter]
                     postNotificationName:SKSkimFileDidSaveNotification 
object:[absoluteURL path]];
@@ -519,10 +542,16 @@
             [self tryToUnlockDocument:pdfDocument];
         [[self mainWindowController] setPdfDocument:pdfDocument];
         [self setPDFDoc:nil];
-        if (noteDicts) {
-            [[self mainWindowController] 
setAnnotationsFromDictionaries:noteDicts undoable:NO];
-            [self setNoteDicts:nil];
-        }
+        
+        [[self mainWindowController] setAnnotationsFromDictionaries:noteDicts 
undoable:NO];
+        [self setNoteDicts:nil];
+        
+        [[self mainWindowController] setOpenMetaTags:openMetaTags];
+        [self setOpenMetaTags:nil];
+        
+        [[self mainWindowController] setOpenMetaRating:openMetaRating];
+        [self setOpenMetaRating:0.0];
+        
         [[self undoManager] removeAllActions];
         // file watching could have been disabled if the file was deleted
         if (watchedFile == nil && fileUpdateTimer == nil)
@@ -585,6 +614,17 @@
     }
 }
 
+- (void)setOpenMetaTags:(NSArray *)array {
+    if (openMetaTags != array) {
+        [openMetaTags autorelease];
+        openMetaTags = [array retain];
+    }
+}
+
+- (void)setOpenMetaRating:(double)rating {
+    openMetaRating = rating;
+}
+
 - (void)setPassword:(NSString *)newPassword {
     if (password != newPassword) {
         [password release];
@@ -639,6 +679,8 @@
     [self setPDFData:nil];
     [self setPDFDoc:nil];
     [self setNoteDicts:nil];
+    [self setOpenMetaTags:nil];
+    [self setOpenMetaRating:0.0];
     
     if (SKIsPDFDocumentType(docType)) {
         if ((data = [[NSData alloc] initWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) &&
@@ -683,6 +725,14 @@
                     }
                 }
             }
+            if (pdfDoc) {
+                array = [[SKNExtendedAttributeManager sharedNoSplitManager] 
propertyListFromExtendedAttributeNamed:OPEN_META_TAGS_KEY atPath:[absoluteURL 
path] traverseLink:YES error:NULL];
+                if ([array count])
+                    [self setOpenMetaTags:array];
+                NSNumber *number = [[SKNExtendedAttributeManager 
sharedNoSplitManager] 
propertyListFromExtendedAttributeNamed:OPEN_META_RATING_KEY atPath:[absoluteURL 
path] traverseLink:YES error:NULL];
+                if (number && [number doubleValue] > 0.0)
+                    [self setOpenMetaRating:[number doubleValue]];
+            }
         }
     } else if (SKIsPDFBundleDocumentType(docType)) {
         NSString *path = [absoluteURL path];
@@ -1803,6 +1853,22 @@
     [[self undoManager] setActionName:NSLocalizedString(@"Remove Note", @"Undo 
action name")];
 }
 
+- (NSArray *)tags {
+    return [[self mainWindowController] tags];
+}
+
+- (void)setTags:(NSArray *)newTags {
+    [[self mainWindowController] setTags:newTags];
+}
+
+- (double)rating {
+    return [[self mainWindowController] rating];
+}
+
+- (void)setRating:(double)newRating {
+    [[self mainWindowController] setRating:newRating];
+}
+
 - (PDFPage *)currentPage {
     return [[self pdfView] currentPage];
 }

Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef     2009-01-25 16:27:03 UTC (rev 5162)
+++ trunk/Skim.sdef     2009-01-25 18:15:35 UTC (rev 5163)
@@ -153,6 +153,15 @@
                 description="The attributes of the PDF document.">
                 <cocoa key="documentAttributes"/>
             </property>
+            <property name="tags" code="Tags" hidden="yes"
+                description="The tags of the PDF document.">
+                <type type="text" list="yes"/>
+                <cocoa key="tags"/>
+            </property>
+            <property name="rating" type="real" code="Rate" hidden="yes"
+                description="The rating of the PDF document.">
+                <cocoa key="rating"/>
+            </property>
             <responds-to name="close">
                 <cocoa method="handleCloseScriptCommand:"/>
             </responds-to>


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:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to