/[gnustep]/gnustep/usr-apps/gworkspace/GWLib/GWLib.m
ViewVC logotype

Diff of /gnustep/usr-apps/gworkspace/GWLib/GWLib.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by esersale, Mon Sep 29 13:20:28 2003 UTC revision 1.5 by esersale, Mon Sep 29 18:13:47 2003 UTC
# Line 24  Line 24 
24    
25  #include <Foundation/Foundation.h>  #include <Foundation/Foundation.h>
26  #include <AppKit/AppKit.h>  #include <AppKit/AppKit.h>
27    #include <math.h>
28  #include "GWLib.h"  #include "GWLib.h"
29  #include "GWFunctions.h"  #include "GWFunctions.h"
30    #include "GWNotifications.h"
31  #include "FSWatcher.h"  #include "FSWatcher.h"
32  #include "GWProtocol.h"  #include "GWProtocol.h"
33  #include "GNUstep.h"  #include "GNUstep.h"
# Line 44  gwapp = (id <GWProtocol>)[[GWLib class] Line 46  gwapp = (id <GWProtocol>)[[GWLib class]
46  if (gwapp == nil) return x  if (gwapp == nil) return x
47    
48  #ifndef CACHED_MAX  #ifndef CACHED_MAX
49    #define CACHED_MAX 20;    #define CACHED_MAX 20
50  #endif  #endif
51    
52  #ifndef byname  #ifndef byname
# Line 61  static NSString *gwName = @"GWorkspace"; Line 63  static NSString *gwName = @"GWorkspace";
63    
64  @interface GWLib (PrivateMethods)  @interface GWLib (PrivateMethods)
65    
66  - (void)setCachedMax:(int)cmax;  + (GWLib *)instance;
67    
68    - (NSArray *)sortedDirectoryContentsAtPath:(NSString *)path;
69    
70    - (NSArray *)checkHiddenFiles:(NSArray *)files atPath:(NSString *)path;
71    
72  - (NSMutableDictionary *)cachedRepresentationForPath:(NSString *)path;  - (NSMutableDictionary *)cachedRepresentationForPath:(NSString *)path;
73    
# Line 74  static NSString *gwName = @"GWorkspace"; Line 80  static NSString *gwName = @"GWorkspace";
80    
81  - (void)clearCache;  - (void)clearCache;
82    
83  - (NSArray *)sortedDirectoryContentsAtPath:(NSString *)path;  - (void)setCachedMax:(int)cmax;
   
 - (BOOL)isLockedPath:(NSString *)path;  
84    
85  - (void)addWatcherForPath:(NSString *)path;  - (void)addWatcherForPath:(NSString *)path;
86    
# Line 90  static NSString *gwName = @"GWorkspace"; Line 94  static NSString *gwName = @"GWorkspace";
94    
95  - (NSTimer *)timerForPath:(NSString *)path;  - (NSTimer *)timerForPath:(NSString *)path;
96    
97  - (int)sortTypeForDirectoryAtPath:(NSString *)aPath;  - (void)watcherNotification:(NSNotification *)notification;
98    
99    - (void)lockFiles:(NSArray *)files inDirectoryAtPath:(NSString *)path;
100    
101    - (void)unLockFiles:(NSArray *)files inDirectoryAtPath:(NSString *)path;
102    
103    - (BOOL)isLockedPath:(NSString *)path;
104    
105    - (BOOL)existsAndIsDirectoryFileAtPath:(NSString *)path;
106    
107    - (NSString *)typeOfFileAt:(NSString *)path;  
108    
109    - (BOOL)isWritableFileAtPath:(NSString *)path;
110    
111    - (BOOL)isPakageAtPath:(NSString *)path;
112    
113    - (int)sortTypeForDirectoryAtPath:(NSString *)path;
114    
115    - (void)setSortType:(int)type forDirectoryAtPath:(NSString *)path;
116    
117  - (void)setDefSortType:(int)type;  - (void)setDefSortType:(int)type;
118    
119    - (int)defSortType;
120    
121    - (void)setHideSysFiles:(BOOL)value;
122    
123    - (BOOL)hideSysFiles;
124    
125    - (void)setHideDotFiles:(NSNotification *)notif;
126    
127    - (NSImage *)iconForFile:(NSString *)fullPath ofType:(NSString *)type;
128    
129    - (NSImage *)smallIconForFile:(NSString*)aPath;
130    
131    - (NSImage *)smallIconForFiles:(NSArray*)pathArray;
132    
133    - (NSImage *)smallHighlightIcon;
134    
135    - (NSImage *)thumbnailForPath:(NSString *)path;
136    
137    - (void)prepareThumbnailsCache;
138    
139    - (void)thumbnailsDidChange:(NSNotification *)notif;
140    
141    - (void)setUseThumbnails:(BOOL)value;
142    
143    - (NSArray *)imageExtensions;
144    
145  @end  @end
146    
147  @implementation GWLib (PrivateMethods)  @implementation GWLib (PrivateMethods)
148    
149  - (void)setCachedMax:(int)cmax  + (GWLib *)instance
150  {  {
151    cachedMax = cmax;          if (instance == nil) {
152                    instance = [[GWLib alloc] init];
153            }      
154      return instance;
155    }
156    
157    - (void)dealloc
158    {
159      [[NSDistributedNotificationCenter defaultCenter] removeObserver: self];
160      [nc removeObserver: self];
161    
162      RELEASE (cachedContents);
163            RELEASE (watchers);
164            RELEASE (watchTimers);
165      RELEASE (watchedPaths);
166            RELEASE (lockedPaths);
167      RELEASE (tumbsCache);
168      RELEASE (thumbnailDir);
169    
170            [super dealloc];
171    }
172    
173    - (id)init
174    {
175      self = [super init];
176    
177      if (self) {
178        BOOL isdir;
179        
180        fm = [NSFileManager defaultManager];
181        ws = [NSWorkspace sharedWorkspace];
182        nc = [NSNotificationCenter defaultCenter];
183      
184        cachedContents = [NSMutableDictionary new];
185        cachedMax = CACHED_MAX;
186        defSortType = byname;
187        hideSysFiles = NO;
188        
189        watchers = [NSMutableArray new];    
190              watchTimers = [NSMutableArray new];  
191        watchedPaths = [NSMutableArray new];
192    
193              lockedPaths = [NSMutableArray new];  
194    
195        tumbsCache = [NSMutableDictionary new];
196        thumbnailDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
197        thumbnailDir = [thumbnailDir stringByAppendingPathComponent: @"Thumbnails"];
198        RETAIN (thumbnailDir);
199        if (([fm fileExistsAtPath: thumbnailDir isDirectory: &isdir] && isdir) == NO) {
200          [fm createDirectoryAtPath: thumbnailDir attributes: nil];
201        }
202        usesThumbnails = NO;
203        
204        [nc addObserver: self
205               selector: @selector(watcherNotification:)
206                   name: GWFileWatcherFileDidChangeNotification
207                 object: nil];
208    
209        [[NSDistributedNotificationCenter defaultCenter] addObserver: self
210                              selector: @selector(setHideDotFiles:)
211                                                                name: GSHideDotFilesDidChangeNotification
212                                                              object: nil];
213    
214        [[NSDistributedNotificationCenter defaultCenter] addObserver: self
215                            selector: @selector(thumbnailsDidChange:)
216                                                              name: GWThumbnailsDidChangeNotification
217                              object: nil];
218      }
219      
220      return self;
221    }
222    
223    - (NSArray *)sortedDirectoryContentsAtPath:(NSString *)path
224    {
225      NSMutableDictionary *contentsDict = [self cachedRepresentationForPath: path];
226      
227      if (contentsDict) {
228        return [contentsDict objectForKey: @"files"];
229        
230      } else {
231        NSArray *files = [fm directoryContentsAtPath: path];
232        int stype = [self sortTypeForDirectoryAtPath: path];
233        int count = [files count];
234        NSMutableArray *paths = [NSMutableArray arrayWithCapacity: count];
235        NSMutableArray *sortfiles = [NSMutableArray arrayWithCapacity: count];
236        NSArray *sortPaths = nil;
237        NSDictionary *attributes = nil;
238        NSDate *date = nil;
239        SEL appendPathCompSel = @selector(stringByAppendingPathComponent:);
240        IMP appendPathComp = [[NSString class] instanceMethodForSelector: appendPathCompSel];
241        SEL lastPathCompSel = @selector(lastPathComponent);
242        IMP lastPathComp = [[NSString class] instanceMethodForSelector: lastPathCompSel];  
243        int i;
244    
245        for (i = 0; i < count; i++) {
246          NSString *s = (*appendPathComp)(path, appendPathCompSel, [files objectAtIndex: i]);
247          [paths addObject: s];
248        }
249    
250        sortPaths = [paths sortedArrayUsingFunction: (int (*)(id, id, void*))comparePaths
251                                            context: (void *)stype];
252    
253        for (i = 0; i < count; i++) {
254          NSString *s = (*lastPathComp)([sortPaths objectAtIndex: i], lastPathCompSel);
255          [sortfiles addObject: s];
256        }
257    
258        contentsDict = [NSMutableDictionary dictionary];
259        [contentsDict setObject: [NSDate date] forKey: @"datestamp"];
260        attributes = [fm fileAttributesAtPath: path traverseLink: YES];
261        date = [attributes fileModificationDate];
262        [contentsDict setObject: date forKey: @"moddate"];
263        [contentsDict setObject: sortfiles forKey: @"files"];
264        
265        if ([cachedContents count] >= cachedMax) {
266          [self removeOlderCache];
267        }
268        
269        [self addCachedRepresentation: contentsDict ofDirectory: path];
270      
271        return sortfiles;
272      }
273      
274      return nil;
275    }
276    
277    - (NSArray *)checkHiddenFiles:(NSArray *)files atPath:(NSString *)path
278    {
279      NSArray *checkedFiles;
280      NSArray *hiddenFiles;
281      NSString *h;
282                            
283            h = [path stringByAppendingPathComponent: @".hidden"];
284      if ([fm fileExistsAtPath: h]) {
285              h = [NSString stringWithContentsOfFile: h];
286              hiddenFiles = [h componentsSeparatedByString: @"\n"];
287            } else {
288        hiddenFiles = nil;
289      }
290            
291            if (hiddenFiles != nil  ||  hideSysFiles) {    
292                    NSMutableArray *mutableFiles = AUTORELEASE ([files mutableCopy]);
293            
294                    if (hiddenFiles != nil) {
295                [mutableFiles removeObjectsInArray: hiddenFiles];
296              }
297            
298                    if (hideSysFiles) {
299                int j = [mutableFiles count] - 1;
300                
301                while (j >= 0) {
302                                    NSString *file = (NSString *)[mutableFiles objectAtIndex: j];
303    
304                                    if ([file hasPrefix: @"."]) {
305                            [mutableFiles removeObjectAtIndex: j];
306                            }
307                                    j--;
308                            }
309              }            
310        
311                    checkedFiles = mutableFiles;
312        
313            } else {
314        checkedFiles = files;
315      }
316    
317      return checkedFiles;
318  }  }
319    
320  - (NSMutableDictionary *)cachedRepresentationForPath:(NSString *)path  - (NSMutableDictionary *)cachedRepresentationForPath:(NSString *)path
# Line 189  static NSString *gwName = @"GWorkspace"; Line 403  static NSString *gwName = @"GWorkspace";
403    cachedContents = [NSMutableDictionary new];    cachedContents = [NSMutableDictionary new];
404  }  }
405    
406  - (NSArray *)sortedDirectoryContentsAtPath:(NSString *)path  - (void)setCachedMax:(int)cmax
 {  
   NSMutableDictionary *contentsDict = [self cachedRepresentationForPath: path];  
     
   if (contentsDict) {  
     return [contentsDict objectForKey: @"files"];  
       
   } else {  
     NSArray *files = [fm directoryContentsAtPath: path];  
     int stype = [self sortTypeForDirectoryAtPath: path];  
     int count = [files count];  
     NSMutableArray *paths = [NSMutableArray arrayWithCapacity: count];  
     NSMutableArray *sortfiles = [NSMutableArray arrayWithCapacity: count];  
     NSArray *sortPaths = nil;  
     NSDictionary *attributes = nil;  
     NSDate *date = nil;  
     SEL appendPathCompSel = @selector(stringByAppendingPathComponent:);  
     IMP appendPathComp = [[NSString class] instanceMethodForSelector: appendPathCompSel];  
     SEL lastPathCompSel = @selector(lastPathComponent);  
     IMP lastPathComp = [[NSString class] instanceMethodForSelector: lastPathCompSel];    
     int i;  
   
     for (i = 0; i < count; i++) {  
       NSString *s = (*appendPathComp)(path, appendPathCompSel, [files objectAtIndex: i]);  
       [paths addObject: s];  
     }  
   
     sortPaths = [paths sortedArrayUsingFunction: (int (*)(id, id, void*))comparePaths  
                                         context: (void *)stype];  
   
     for (i = 0; i < count; i++) {  
       NSString *s = (*lastPathComp)([sortPaths objectAtIndex: i], lastPathCompSel);  
       [sortfiles addObject: s];  
     }  
   
     contentsDict = [NSMutableDictionary dictionary];  
     [contentsDict setObject: [NSDate date] forKey: @"datestamp"];  
     attributes = [fm fileAttributesAtPath: path traverseLink: YES];  
     date = [attributes fileModificationDate];  
     [contentsDict setObject: date forKey: @"moddate"];  
     [contentsDict setObject: sortfiles forKey: @"files"];  
       
     if ([cachedContents count] >= cachedMax) {  
       [self removeOlderCache];  
     }  
       
     [self addCachedRepresentation: contentsDict ofDirectory: path];  
     
     return sortfiles;  
   }  
     
   return nil;  
 }  
   
 - (BOOL)isLockedPath:(NSString *)path  
407  {  {
408          int i;      cachedMax = cmax;
     
         if ([lockedPaths containsObject: path]) {  
                 return YES;  
         }  
           
         for (i = 0; i < [lockedPaths count]; i++) {  
                 NSString *lpath = [lockedPaths objectAtIndex: i];  
           
     if (subPathOfPath(lpath, path)) {  
                         return YES;  
                 }  
         }  
           
         return NO;  
409  }  }
410    
411  - (void)addWatcherForPath:(NSString *)path  - (void)addWatcherForPath:(NSString *)path
# Line 353  static NSString *gwName = @"GWorkspace"; Line 499  static NSString *gwName = @"GWorkspace";
499          return nil;          return nil;
500  }  }
501    
502  - (int)sortTypeForDirectoryAtPath:(NSString *)aPath  - (void)watcherNotification:(NSNotification *)notification
503  {  {
504    if ([fm isWritableFileAtPath: aPath]) {    NSDictionary *notifdict = (NSDictionary *)[notification object];
505      NSString *dictPath = [aPath stringByAppendingPathComponent: @".gwsort"];    NSString *path = [notifdict objectForKey: @"path"];
506    
507      if ([self cachedRepresentationForPath: path]) {
508        [self removeCachedRepresentationForPath: path];
509      }
510    }
511    
512    - (void)lockFiles:(NSArray *)files inDirectoryAtPath:(NSString *)path
513    {
514            int i;
515              
516            for (i = 0; i < [files count]; i++) {
517                    NSString *file = [files objectAtIndex: i];
518                    NSString *fpath = [path stringByAppendingPathComponent: file];    
519        
520                    if ([lockedPaths containsObject: fpath] == NO) {
521                            [lockedPaths addObject: fpath];
522                    }
523            }
524    }
525    
526    - (void)unLockFiles:(NSArray *)files inDirectoryAtPath:(NSString *)path
527    {
528            int i;
529              
530            for (i = 0; i < [files count]; i++) {
531                    NSString *file = [files objectAtIndex: i];
532                    NSString *fpath = [path stringByAppendingPathComponent: file];
533            
534                    if ([lockedPaths containsObject: fpath]) {
535                            [lockedPaths removeObject: fpath];
536                    }
537            }
538    }
539    
540    - (BOOL)isLockedPath:(NSString *)path
541    {
542            int i;  
543      
544            if ([lockedPaths containsObject: path]) {
545                    return YES;
546            }
547            
548            for (i = 0; i < [lockedPaths count]; i++) {
549                    NSString *lpath = [lockedPaths objectAtIndex: i];
550            
551        if (subPathOfPath(lpath, path)) {
552                            return YES;
553                    }
554            }
555            
556            return NO;
557    }
558    
559    - (BOOL)existsAndIsDirectoryFileAtPath:(NSString *)path            
560    {
561      BOOL isDir;
562      return ([fm fileExistsAtPath: path isDirectory: &isDir] && isDir);
563    }
564    
565    - (NSString *)typeOfFileAt:(NSString *)path
566    {
567      NSString *defApp, *type;
568      [ws getInfoForFile: path application: &defApp type: &type];
569      return type;
570    }
571    
572    - (BOOL)isWritableFileAtPath:(NSString *)path
573    {
574      return [fm isWritableFileAtPath: path];
575    }
576    
577    - (BOOL)isPakageAtPath:(NSString *)path
578    {
579            NSString *defApp, *type;
580            BOOL isdir;
581                    
582            [ws getInfoForFile: path application: &defApp type: &type];  
583            
584            if (type == NSApplicationFileType) {
585                    return YES;
586            } else if (type == NSPlainFileType) {
587              if ((([fm fileExistsAtPath: path isDirectory: &isdir]) && isdir)) {
588                      return YES;
589              }  
590      }
591            
592      return NO;
593    }
594    
595    - (int)sortTypeForDirectoryAtPath:(NSString *)path
596    {
597      if ([fm isWritableFileAtPath: path]) {
598        NSString *dictPath = [path stringByAppendingPathComponent: @".gwsort"];
599            
600      if ([fm fileExistsAtPath: dictPath]) {      if ([fm fileExistsAtPath: dictPath]) {
601        NSDictionary *sortDict = [NSDictionary dictionaryWithContentsOfFile: dictPath];        NSDictionary *sortDict = [NSDictionary dictionaryWithContentsOfFile: dictPath];
# Line 370  static NSString *gwName = @"GWorkspace"; Line 609  static NSString *gwName = @"GWorkspace";
609          return defSortType;          return defSortType;
610  }  }
611    
612    - (void)setSortType:(int)type forDirectoryAtPath:(NSString *)path
613    {
614      if ([fm isWritableFileAtPath: path]) {
615        NSString *sortstr = [NSString stringWithFormat: @"%i", type];
616        NSDictionary *dict = [NSDictionary dictionaryWithObject: sortstr
617                                                         forKey: @"sort"];
618        [dict writeToFile: [path stringByAppendingPathComponent: @".gwsort"]
619               atomically: YES];
620      }
621      
622      [self removeCachedRepresentationForPath: path];
623      
624            [[NSNotificationCenter defaultCenter]
625                                     postNotificationName: GWSortTypeDidChangeNotification
626                                                                                 object: (id)path];  
627    }
628    
629  - (void)setDefSortType:(int)type  - (void)setDefSortType:(int)type
630  {  {
631    defSortType = type;          if (defSortType == type) {
632                    return;
633            } else {
634                    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
635                    defSortType = type;
636                    [defaults setObject: [NSString stringWithFormat: @"%i", defSortType]
637                                                               forKey: @"defaultsorttype"];
638                    [defaults synchronize];
639                
640                    [[NSNotificationCenter defaultCenter]
641                                             postNotificationName: GWSortTypeDidChangeNotification
642                                                                                         object: nil];  
643            }
644  }  }
645    
646  @end  - (int)defSortType
647    {
648      return defSortType;
649    }
650    
651    - (void)setHideSysFiles:(BOOL)value
652    {
653      if (hideSysFiles != value) {
654        [self clearCache];
655    
656  @implementation GWLib      hideSysFiles = value;
657      }
658    }
659    
660  + (GWLib *)instance  - (BOOL)hideSysFiles
661  {  {
662          if (instance == nil) {    return hideSysFiles;
                 instance = [[GWLib alloc] init];  
         }        
   return instance;  
663  }  }
664    
665  - (void)dealloc  - (void)setHideDotFiles:(NSNotification *)notif
666  {  {
667    [nc removeObserver: self];    NSString *hideStr = (NSString *)[notif object];
668      BOOL hideDot = (BOOL)[hideStr intValue];
669      
670      if (hideSysFiles != hideDot) {
671        [self clearCache];
672    
673    RELEASE (cachedContents);      hideSysFiles = hideDot;
         RELEASE (watchers);  
         RELEASE (watchTimers);  
   RELEASE (watchedPaths);  
         RELEASE (lockedPaths);  
   RELEASE (tumbsCache);  
   RELEASE (thumbnailDir);  
674    
675          [super dealloc];      [[NSNotificationCenter defaultCenter]
676                             postNotificationName: GWSortTypeDidChangeNotification
677                                                                                     object: nil];  
678      }
679  }  }
680    
681  - (id)init  - (NSImage *)iconForFile:(NSString *)fullPath ofType:(NSString *)type
682  {  {
683    self = [super init];    NSImage *icon;
684            NSSize size;
685      
686      if (usesThumbnails) {
687        icon = [self thumbnailForPath: fullPath];
688        
689        if (icon) {
690          return icon;
691        }    
692      }
693    
694    if (self) {    icon = [ws iconForFile: fullPath];
695      cachedContents = [NSMutableDictionary new];    size = [icon size];
696      cachedMax = CACHED_MAX;    
697      defSortType = byname;    if ((size.width > ICNMAX) || (size.height > ICNMAX)) {
698        NSSize newsize;
699      
700        if (size.width >= size.height) {
701          newsize.width = ICNMAX;
702          newsize.height = floor(ICNMAX * size.height / size.width + 0.5);
703        } else {
704          newsize.height = ICNMAX;
705          newsize.width  = floor(ICNMAX * size.width / size.height + 0.5);
706        }
707            
708      watchers = [NSMutableArray new];                [icon setScalesWhenResized: YES];
709            watchTimers = [NSMutableArray new];              [icon setSize: newsize];  
710      watchedPaths = [NSMutableArray new];    }
711      
712      return icon;
713    }
714    
715            lockedPaths = [NSMutableArray new];    - (NSImage *)smallIconForFile:(NSString*)aPath
716    {
717            NSImage *icon = [[self iconForFile: aPath ofType: nil] copy];
718      NSSize size = [icon size];
719      [icon setScalesWhenResized: YES];
720      [icon setSize: NSMakeSize(size.width / 2, size.height / 2)];
721    
722      tumbsCache = [NSMutableDictionary new];    return AUTORELEASE (icon);
723      thumbnailDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];  }
724      thumbnailDir = [thumbnailDir stringByAppendingPathComponent: @"Thumbnails"];  
725      RETAIN (thumbnailDir);  - (NSImage *)smallIconForFiles:(NSArray*)pathArray
726      usesThumbnails = NO;  {
727            NSImage *icon = [NSImage imageNamed: @"MultipleSelection.tiff"];
728      NSSize size = [icon size];
729      [icon setScalesWhenResized: YES];
730      [icon setSize: NSMakeSize(size.width / 2, size.height / 2)];
731            
732            return icon;
733    }
734    
735    - (NSImage *)smallHighlightIcon
736    {
737      return [NSImage imageNamed: @"SmallCellHighlightSmall.tiff"];
738    }
739    
740    - (NSImage *)thumbnailForPath:(NSString *)path
741    {
742      if (usesThumbnails == NO) {
743        return nil;
744      } else {
745        return [tumbsCache objectForKey: path];
746      }
747    
748      return nil;
749    }
750    
751    - (void)prepareThumbnailsCache
752    {
753      NSString *dictName = @"thumbnails.plist";
754      NSString *dictPath = [thumbnailDir stringByAppendingPathComponent: dictName];
755      NSDictionary *tdict;
756      
757      TEST_RELEASE (tumbsCache);
758      tumbsCache = [NSMutableDictionary new];
759      
760      tdict = [NSDictionary dictionaryWithContentsOfFile: dictPath];
761            
762      fm = [NSFileManager defaultManager];    if (tdict) {
763      ws = [NSWorkspace sharedWorkspace];      NSArray *keys = [tdict allKeys];
764      nc = [NSNotificationCenter defaultCenter];      int i;
765    
766        for (i = 0; i < [keys count]; i++) {
767          NSString *key = [keys objectAtIndex: i];
768          NSString *tumbname = [tdict objectForKey: key];
769          NSString *tumbpath = [thumbnailDir stringByAppendingPathComponent: tumbname];
770    
771          if ([fm fileExistsAtPath: tumbpath]) {
772            NSImage *tumb = [[NSImage alloc] initWithContentsOfFile: tumbpath];
773            
774            if (tumb) {
775              [tumbsCache setObject: tumb forKey: key];
776              RELEASE (tumb);
777            }
778          }
779        }
780      }
781    }
782    
783    - (void)thumbnailsDidChange:(NSNotification *)notif
784    {
785      NSDictionary *info = [notif userInfo];
786      NSArray *deleted = [info objectForKey: @"deleted"];  
787      NSArray *created = [info objectForKey: @"created"];  
788      int i;
789    
790      if (usesThumbnails == NO) {
791        return;
792    }    }
793        
794    return self;    if ([deleted count]) {
795        for (i = 0; i < [deleted count]; i++) {
796          NSString *path = [deleted objectAtIndex: i];
797          
798          [tumbsCache removeObjectForKey: path];
799        }
800      }
801      
802      if ([created count]) {
803        NSString *dictName = @"thumbnails.plist";
804        NSString *dictPath = [thumbnailDir stringByAppendingPathComponent: dictName];
805        NSDictionary *tdict = [NSDictionary dictionaryWithContentsOfFile: dictPath];
806      
807        for (i = 0; i < [created count]; i++) {
808          NSString *key = [created objectAtIndex: i];
809          NSString *tumbname = [tdict objectForKey: key];
810          NSString *tumbpath = [thumbnailDir stringByAppendingPathComponent: tumbname];
811    
812          if ([fm fileExistsAtPath: tumbpath]) {
813            NSImage *tumb = [[NSImage alloc] initWithContentsOfFile: tumbpath];
814            
815            if (tumb) {
816              [tumbsCache setObject: tumb forKey: key];
817              RELEASE (tumb);
818            }
819          }
820        }
821      }
822    }
823    
824    - (void)setUseThumbnails:(BOOL)value
825    {
826      if (usesThumbnails == value) {
827        return;
828      }
829        
830      usesThumbnails = value;
831      if (usesThumbnails) {
832        [self prepareThumbnailsCache];
833      }
834    }
835    
836    - (NSArray *)imageExtensions
837    {
838      return [NSArray arrayWithObjects: @"tiff", @"tif", @"TIFF", @"TIF",
839                                        @"png", @"PNG", @"jpeg", @"jpg",
840                                        @"JPEG", @"JPG", @"gif", @"GIF",
841                                        @"xpm", nil];
842    }
843    
844    @end
845    
846    
847    @implementation GWLib
848    
849    + (NSArray *)sortedDirectoryContentsAtPath:(NSString *)path
850    {
851      return [[self instance] sortedDirectoryContentsAtPath: path];
852    }
853    
854    + (NSArray *)checkHiddenFiles:(NSArray *)files atPath:(NSString *)path
855    {
856      return [[self instance] checkHiddenFiles: files atPath: path];
857  }  }
858    
859  + (void)setCachedMax:(int)cmax  + (void)setCachedMax:(int)cmax
# Line 437  static NSString *gwName = @"GWorkspace"; Line 861  static NSString *gwName = @"GWorkspace";
861    [[self instance] setCachedMax: cmax];    [[self instance] setCachedMax: cmax];
862  }  }
863    
864  + (void)setDefSortType:(int)type  + (void)addWatcherForPath:(NSString *)path
865  {  {
866    [[self instance] setDefSortType: type];    [[self instance] addWatcherForPath: path];
867    }
868    
869    + (void)removeWatcherForPath:(NSString *)path
870    {
871      [[self instance] removeWatcherForPath: path];
872    }
873    
874    + (void)lockFiles:(NSArray *)files inDirectoryAtPath:(NSString *)path
875    {
876      [[self instance] lockFiles: files inDirectoryAtPath: path];
877    }
878    
879    + (void)unLockFiles:(NSArray *)files inDirectoryAtPath:(NSString *)path
880    {
881      [[self instance] unLockFiles: files inDirectoryAtPath: path];
882  }  }
883    
884  + (BOOL)isLockedPath:(NSString *)path  + (BOOL)isLockedPath:(NSString *)path
# Line 447  static NSString *gwName = @"GWorkspace"; Line 886  static NSString *gwName = @"GWorkspace";
886    return [[self instance] isLockedPath: path];    return [[self instance] isLockedPath: path];
887  }  }
888    
889    + (BOOL)existsAndIsDirectoryFileAtPath:(NSString *)path
890    {
891      return [[self instance] existsAndIsDirectoryFileAtPath: path];
892    }
893    
894    + (NSString *)typeOfFileAt:(NSString *)path
895    {
896      return [[self instance] typeOfFileAt: path];
897    }
898    
899    + (BOOL)isPakageAtPath:(NSString *)path
900    {
901      return [[self instance] isPakageAtPath: path];
902    }
903    
904    + (int)sortTypeForDirectoryAtPath:(NSString *)path
905    {
906      return [[self instance] sortTypeForDirectoryAtPath: path];
907    }
908    
909    + (void)setSortType:(int)type forDirectoryAtPath:(NSString *)path
910    {
911      [[self instance] setSortType: type forDirectoryAtPath: path];
912    }
913    
914    + (void)setDefSortType:(int)type
915    {
916      [[self instance] setDefSortType: type];
917    }
918    
919    + (int)defSortType
920    {
921      return [[self instance] defSortType];
922    }
923    
924    + (void)setHideSysFiles:(BOOL)value
925    {
926      [[self instance] setHideSysFiles: value];
927    }
928    
929    + (BOOL)hideSysFiles
930    {
931      return [[self instance] hideSysFiles];
932    }
933    
934    + (NSImage *)iconForFile:(NSString *)fullPath ofType:(NSString *)type
935    {
936      return [[self instance] iconForFile: fullPath ofType: type];
937    }
938    
939    + (NSImage *)smallIconForFile:(NSString*)aPath
940    {
941      return [[self instance] smallIconForFile: aPath];
942    }
943    
944    + (NSImage *)smallIconForFiles:(NSArray*)pathArray
945    {
946      return [[self instance] smallIconForFiles: pathArray];
947    }
948    
949    + (NSImage *)smallHighlightIcon
950    {
951      return [[self instance] smallHighlightIcon];
952    }
953    
954    + (void)setUseThumbnails:(BOOL)value
955    {
956      [[self instance] setUseThumbnails: value];
957    }
958    
959    + (NSArray *)imageExtensions
960    {
961      return [[self instance] imageExtensions];
962    }
963    
964    
965    
966    
967    
968    
969    
970    
971    
972    
973    
974    
975    
976    
977    
978  + (id)gworkspaceApplication  + (id)gworkspaceApplication
979  {  {
# Line 543  static NSString *gwName = @"GWorkspace"; Line 1070  static NSString *gwName = @"GWorkspace";
1070    [gwapp openSelectedPaths: paths];    [gwapp openSelectedPaths: paths];
1071  }  }
1072    
 + (oneway void)addWatcherForPath:(NSString *)path  
 {  
   CHECKGW;  
   [gwapp addWatcherForPath: path];  
 }  
   
 + (oneway void)removeWatcherForPath:(NSString *)path  
 {  
   CHECKGW;  
   [gwapp removeWatcherForPath: path];  
 }  
   
 + (BOOL)isPakageAtPath:(NSString *)path  
 {  
   CHECKGW_RET(NO);  
   return [gwapp isPakageAtPath: path];  
   return NO;  
 }  
   
1073  + (oneway void)performFileOperationWithDictionary:(NSDictionary *)dict  + (oneway void)performFileOperationWithDictionary:(NSDictionary *)dict
1074  {  {
1075    CHECKGW;    CHECKGW;

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26