Author: rmottola
Date: Wed Dec 2 12:09:08 2015
New Revision: 39209
URL: http://svn.gna.org/viewcvs/gnustep?rev=39209&view=rev
Log:
Make the thumbnailer a (releasable) singleton and instantiate it through
sharedThumbnailer. It may be released, but if it exists, it is a singleton.
Modified:
apps/gworkspace/trunk/ChangeLog
apps/gworkspace/trunk/GWorkspace/FileViewer/GWViewer.m
apps/gworkspace/trunk/GWorkspace/GWorkspaceInfo.plist
apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.h
apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.m
Modified: apps/gworkspace/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/ChangeLog?rev=39209&r1=39208&r2=39209&view=diff
==============================================================================
--- apps/gworkspace/trunk/ChangeLog (original)
+++ apps/gworkspace/trunk/ChangeLog Wed Dec 2 12:09:08 2015
@@ -1,3 +1,10 @@
+2015-12-02 Riccardo Mottola <[email protected]>
+
+ * GWorkspace/Thumbnailer/GWThumbnailer.h
+ * GWorkspace/Thumbnailer/GWThumbnailer.m
+ * GWorkspace/FileViewer/GWViewer.m
+ Make the thumbnailer a (releasable) singleton and instantiate it
through sharedThumbnailer. It may be released, but if it exists, it is a
singleton.
+
2015-11-19 Riccardo Mottola <[email protected]>
* FSNode/FSNodeRep.m
Modified: apps/gworkspace/trunk/GWorkspace/FileViewer/GWViewer.m
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/GWorkspace/FileViewer/GWViewer.m?rev=39209&r1=39208&r2=39209&view=diff
==============================================================================
--- apps/gworkspace/trunk/GWorkspace/FileViewer/GWViewer.m (original)
+++ apps/gworkspace/trunk/GWorkspace/FileViewer/GWViewer.m Wed Dec 2
12:09:08 2015
@@ -1564,12 +1564,11 @@
NSString *path;
path = [[nodeView shownNode] path];
- NSLog(@"make thumbnails in path: %@", path);
if (path)
{
Thumbnailer *t;
- t = [[Thumbnailer alloc] init];
+ t = [Thumbnailer sharedThumbnailer];
[t makeThumbnails:path];
[t release];
}
@@ -1580,12 +1579,11 @@
NSString *path;
path = [[nodeView shownNode] path];
- NSLog(@"remove thumbnails in: %@", path);
if (path)
{
Thumbnailer *t;
- t = [[Thumbnailer alloc] init];
+ t = [Thumbnailer sharedThumbnailer];
[t removeThumbnails:path];
[t release];
}
Modified: apps/gworkspace/trunk/GWorkspace/GWorkspaceInfo.plist
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/GWorkspace/GWorkspaceInfo.plist?rev=39209&r1=39208&r2=39209&view=diff
==============================================================================
--- apps/gworkspace/trunk/GWorkspace/GWorkspaceInfo.plist (original)
+++ apps/gworkspace/trunk/GWorkspace/GWorkspaceInfo.plist Wed Dec 2
12:09:08 2015
@@ -4,7 +4,7 @@
ApplicationIcon = "FileManager.tiff";
ApplicationRelease = "0.9.3";
NSBuildVersion = "05 2015";
- CFBundleIdentifier = "org.gnustep.GWorkspace"
+ CFBundleIdentifier = "org.gnustep.GWorkspace";
Authors = (
"Riccardo Mottola",
"Enrico Sersale",
Modified: apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.h
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.h?rev=39209&r1=39208&r2=39209&view=diff
==============================================================================
--- apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.h
(original)
+++ apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.h Wed Dec
2 12:09:08 2015
@@ -53,6 +53,8 @@
NSFileManager *fm;
}
++ (Thumbnailer *)sharedThumbnailer;
+
- (void)loadThumbnailers;
- (BOOL)addThumbnailer:(id)tmb;
Modified: apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.m
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.m?rev=39209&r1=39208&r2=39209&view=diff
==============================================================================
--- apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.m
(original)
+++ apps/gworkspace/trunk/GWorkspace/Thumbnailer/GWThumbnailer.m Wed Dec
2 12:09:08 2015
@@ -30,6 +30,8 @@
#import <AppKit/AppKit.h>
#import "GWThumbnailer.h"
+static Thumbnailer *sharedThumbnailerInstance = nil;
+static NSInteger countInstances = 0;
static NSString *GWThumbnailsDidChangeNotification =
@"GWThumbnailsDidChangeNotification";
@@ -37,21 +39,50 @@
@implementation Thumbnailer
+/* A singleton that can be released. However, once one existance exists,
+ all instances will be the same object.
+
+ This way we can insure that only one Thumbnail dictionary exists in memory
+*/
+
++ (Thumbnailer *)sharedThumbnailer
+{
+ if (nil == sharedThumbnailerInstance)
+ {
+ sharedThumbnailerInstance = [[Thumbnailer allocWithZone:NULL] init];
+ countInstances = 1;
+ }
+ else
+ {
+ countInstances++;
+ NSLog(@"returning existing instance, %lu", (long)countInstances);
+ }
+ return sharedThumbnailerInstance;
+}
+
- (void)dealloc
{
- [[NSNotificationCenter defaultCenter] removeObserver: self];
-
- if (timer && [timer isValid]) {
- [timer invalidate];
- }
-
- RELEASE (thumbnailers);
- RELEASE (extProviders);
- RELEASE (thumbnailDir);
- RELEASE (dictPath);
- RELEASE (thumbsDict);
- DESTROY (conn);
- [super dealloc];
+ countInstances--;
+
+ if (countInstances < 0)
+ NSLog(@"Something went wrong!");
+ if (countInstances == 0)
+ {
+ NSLog(@"Last thumbnailer instance, dealloc'ing");
+ [[NSNotificationCenter defaultCenter] removeObserver: self];
+
+ if (timer && [timer isValid])
+ [timer invalidate];
+
+ RELEASE (thumbnailers);
+ RELEASE (extProviders);
+ RELEASE (thumbnailDir);
+ RELEASE (dictPath);
+ RELEASE (thumbsDict);
+ DESTROY (conn);
+ sharedThumbnailerInstance = nil;
+ [super dealloc];
+ }
}
- (id)init
@@ -111,6 +142,7 @@
return self;
}
+
- (void)loadThumbnailers
{
@@ -232,19 +264,20 @@
RELEASE (paths);
- if ([deleted count]) {
- NSMutableDictionary *info = [NSMutableDictionary dictionary];
-
- [info setObject: deleted forKey: @"deleted"];
- [info setObject: [NSArray array] forKey: @"created"];
-
- [thumbsDict writeToFile: dictPath atomically: YES];
-
- [[NSDistributedNotificationCenter defaultCenter]
+ if ([deleted count])
+ {
+ NSMutableDictionary *info = [NSMutableDictionary dictionary];
+
+ [info setObject: deleted forKey: @"deleted"];
+ [info setObject: [NSArray array] forKey: @"created"];
+
+ [thumbsDict writeToFile: dictPath atomically: YES];
+
+ [[NSDistributedNotificationCenter defaultCenter]
postNotificationName: GWThumbnailsDidChangeNotification
-
object: nil
+ object: nil
userInfo: info];
- }
+ }
}
}
@@ -345,19 +378,20 @@
}
}
- if ([deleted count]) {
+ if ([deleted count])
+ {
NSMutableDictionary *info = [NSMutableDictionary dictionary];
-
- [info setObject: deleted forKey: @"deleted"];
+
+ [info setObject: deleted forKey: @"deleted"];
[info setObject: [NSArray array] forKey: @"created"];
[thumbsDict writeToFile: dictPath atomically: YES];
- [[NSDistributedNotificationCenter defaultCenter]
+ [[NSDistributedNotificationCenter defaultCenter]
postNotificationName: GWThumbnailsDidChangeNotification
-
object: nil
+ object: nil
userInfo: info];
- }
+ }
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs