Author: rmottola
Date: Wed Jun 1 01:19:39 2016
New Revision: 39825
URL: http://svn.gna.org/viewcvs/gnustep?rev=39825&view=rev
Log:
Partially revert, but fix and complete using a class instead of a separate
Task, Rename Resizer to ImageResizer to avid class name clash
Modified:
apps/gworkspace/trunk/ChangeLog
apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h
apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m
apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m
Modified: apps/gworkspace/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/ChangeLog?rev=39825&r1=39824&r2=39825&view=diff
==============================================================================
--- apps/gworkspace/trunk/ChangeLog (original)
+++ apps/gworkspace/trunk/ChangeLog Wed Jun 1 01:19:39 2016
@@ -1,3 +1,10 @@
+2016-06-01 Riccardo Mottola <[email protected]>
+
+ * Inspector/ContentViewers/ImageViewer/ImageViewer.h
+ * Inspector/ContentViewers/ImageViewer/ImageViewer.m
+ * Inspector/ContentViewers/ImageViewer/Resizer.m
+ Partially revert, but fix and complete using a class instead of a
separate Task, Rename Resizer to ImageResizer to avid class name clash.
+
2016-04-28 Riccardo Mottola <[email protected]>
* GWorkspace/GWorkspace.m
Modified:
apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h?rev=39825&r1=39824&r2=39825&view=diff
==============================================================================
--- apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h
(original)
+++ apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.h
Wed Jun 1 01:19:39 2016
@@ -44,8 +44,10 @@
@protocol ImageResizerProtocol
-- (void)readImageAtPath:(NSString *)path
+- (oneway void)readImageAtPath:(NSString *)path
setSize:(NSSize)imsize;
+
+- (oneway void)terminate;
@end
@@ -77,9 +79,16 @@
NSWorkspace *ws;
}
+- (void)checkResizer:(id)sender;
+
- (void)setResizer:(id)anObject;
-- (void)imageReady:(NSDictionary *)info;
+- (BOOL)connection:(NSConnection *)ancestor
+
shouldMakeNewConnection:(NSConnection *)newConn;
+
+- (void)connectionDidDie:(NSNotification *)notification;
+
+- (void)imageReady:(NSData *)data;
- (void)editFile:(id)sender;
Modified:
apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m?rev=39825&r1=39824&r2=39825&view=diff
==============================================================================
--- apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m
(original)
+++ apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/ImageViewer.m
Wed Jun 1 01:19:39 2016
@@ -1,6 +1,6 @@
/* ImageViewer.m
*
- * Copyright (C) 2004-2016 Free Software Foundation, Inc.
+ * Copyright (C) 2004-2013 Free Software Foundation, Inc.
*
* Author: Enrico Sersale <[email protected]>
* Date: January 2004
@@ -26,16 +26,7 @@
#import "ImageViewer.h"
#include <math.h>
-@interface Resizer : NSObject
-{
- id viewer;
- NSNotificationCenter *nc;
-}
-
-- (void)readImageAtPath:(NSString *)path
- setSize:(NSSize)imsize;
-
-@end
+#import "Resizer.h"
@implementation ImageViewer
@@ -43,11 +34,13 @@
{
[nc removeObserver: self];
- if (resizerConn != nil)
- {
- DESTROY (resizer);
- DESTROY (resizerConn);
- }
+ if (resizerConn != nil) {
+ if (resizer != nil) {
+ [resizer terminate];
+ }
+ DESTROY (resizer);
+ DESTROY (resizerConn);
+ }
RELEASE (imagePath);
RELEASE (image);
@@ -172,12 +165,33 @@
}
ASSIGN (imagePath, path);
+
+ if (conn == nil) {
+ NSString *cname = [NSString stringWithFormat: @"search_%lu", (unsigned
long)self];
+
+ conn = [[NSConnection alloc] initWithReceivePort: (NSPort *)[NSPort port]
+
sendPort: nil];
+ [conn setRootObject: self];
+ [conn registerName: cname];
+ [conn setDelegate: self];
+
+ [nc addObserver: self
+ selector: @selector(connectionDidDie:)
+ name: NSConnectionDidDieNotification
+ object: conn];
+ }
if ((resizer == nil) && (waitingResizer == NO)) {
+ NSString *cname = [NSString stringWithFormat: @"search_%lu", (unsigned
long)self];
waitingResizer = YES;
- resizer = [[Resizer alloc] init];
-
+
+ [NSTimer scheduledTimerWithTimeInterval: 5.0
+
target: self
+ selector: @selector(checkResizer:)
+
userInfo: nil
+ repeats: NO];
+ ImageResizer *resizer = [[ImageResizer alloc] initWithConnectionName:
cname];
} else {
NSSize imsize = [imview bounds].size;
@@ -201,6 +215,16 @@
}
}
+- (void)checkResizer:(id)sender
+{
+ if (waitingResizer && (resizer == nil)) {
+ NSRunAlertPanel(nil,
+ NSLocalizedString(@"unable to launch the resizer task.",
@""),
+ NSLocalizedString(@"Continue", @""),
+ nil,
+ nil);
+ }
+}
- (void)setResizer:(id)anObject
{
@@ -209,7 +233,9 @@
imsize.width -= 4;
imsize.height -= 4;
- resizer = [[Resizer alloc] init];
+ [anObject setProtocolForProxy: @protocol(ImageResizerProtocol)];
+ resizer = (id <ImageResizerProtocol>)anObject;
+ RETAIN (resizer);
waitingResizer = NO;
[self addSubview: progView];
[progView start];
@@ -217,14 +243,61 @@
}
}
-
-
-- (void)imageReady:(NSDictionary *)imginfo
-{
+- (BOOL)connection:(NSConnection *)ancestor
+
shouldMakeNewConnection:(NSConnection *)newConn
+{
+ if (ancestor == conn) {
+ ASSIGN (resizerConn, newConn);
+ [resizerConn setDelegate: self];
+
+ [nc addObserver: self
+ selector: @selector(connectionDidDie:)
+ name: NSConnectionDidDieNotification
+ object: resizerConn];
+ }
+
+ return YES;
+}
+
+- (void)connectionDidDie:(NSNotification *)notification
+{
+ id diedconn = [notification object];
+
+ [nc removeObserver: self
+ name: NSConnectionDidDieNotification
+ object: diedconn];
+
+ if ((diedconn == conn) || (resizerConn && (diedconn == resizerConn))) {
+ DESTROY (resizer);
+ DESTROY (resizerConn);
+ waitingResizer = NO;
+
+ if ([[self subviews] containsObject: progView]) {
+ [progView stop];
+ [progView removeFromSuperview];
+ }
+
+ if (diedconn == conn) {
+ DESTROY (conn);
+ }
+
+ DESTROY (imagePath);
+
+ NSRunAlertPanel(nil,
+ NSLocalizedString(@"resizer connection died.", @""),
+ NSLocalizedString(@"Continue", @""),
+ nil,
+ nil);
+ }
+}
+
+- (void)imageReady:(NSData *)data
+{
+ NSDictionary *imginfo = [NSUnarchiver unarchiveObjectWithData: data];
NSData *imgdata = [imginfo objectForKey: @"imgdata"];
BOOL imgok = YES;
NSString *lastPath;
- NSLog(@"ImageViewer - imageReady");
+
if ([self superview]) {
[inspector contentsReadyAt: imagePath];
}
Modified: apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m
URL:
http://svn.gna.org/viewcvs/gnustep/apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m?rev=39825&r1=39824&r2=39825&view=diff
==============================================================================
--- apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m
(original)
+++ apps/gworkspace/trunk/Inspector/ContentViewers/ImageViewer/Resizer.m
Wed Jun 1 01:19:39 2016
@@ -22,10 +22,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
*/
-#include <Foundation/Foundation.h>
-#include <AppKit/AppKit.h>
+#import <Foundation/Foundation.h>
+#import <AppKit/AppKit.h>
#include <math.h>
-#include "config.h"
+
+#import "Resizer.h"
#define GWDebugLog(format, args...) \
do { if (GW_DEBUG_LOG) \
@@ -33,27 +34,69 @@
@protocol ImageViewerProtocol
-- (void)setResizer:(id)anObject;
-
-- (void)imageReady:(NSDictionary *)info;
+- (oneway void)setResizer:(id)anObject;
+
+- (oneway void)imageReady:(NSData *)data;
@end
-@interface Resizer : NSObject
-{
- id viewer;
- NSNotificationCenter *nc;
-}
-
-- (void)readImageAtPath:(NSString *)path
- setSize:(NSSize)imsize;
-
-@end
-
-
-@implementation Resizer
-
+
+
+
+@implementation ImageResizer
+
+- (void)dealloc
+{
+ [nc removeObserver: self];
+ DESTROY (viewer);
+ [super dealloc];
+}
+
+- (id)initWithConnectionName:(NSString *)cname
+{
+ self = [super init];
+
+ if (self) {
+ NSConnection *conn;
+ id anObject;
+
+ nc = [NSNotificationCenter defaultCenter];
+
+ conn = [NSConnection connectionWithRegisteredName: cname host: nil];
+
+ if (conn == nil) {
+ NSLog(@"failed to contact the Image Viewer - bye.");
+ exit(1);
+ }
+
+ [nc addObserver: self
+ selector: @selector(connectionDidDie:)
+ name: NSConnectionDidDieNotification
+ object: conn];
+
+ anObject = [conn rootProxy];
+ [anObject setProtocolForProxy: @protocol(ImageViewerProtocol)];
+ viewer = (id <ImageViewerProtocol>)anObject;
+ RETAIN (viewer);
+
+ [viewer setResizer: self];
+ }
+
+ return self;
+}
+
+- (void)connectionDidDie:(NSNotification *)notification
+{
+ id conn = [notification object];
+
+ [nc removeObserver: self
+ name: NSConnectionDidDieNotification
+ object: conn];
+
+ NSLog(@"Image Viewer connection has been destroyed.");
+ exit(0);
+}
#define MIX_LIM 16
@@ -63,7 +106,7 @@
CREATE_AUTORELEASE_POOL(arp);
NSMutableDictionary *info = [NSMutableDictionary dictionary];
NSImage *srcImage = [[NSImage alloc] initWithContentsOfFile: path];
- NSLog(@"Resizer - readImage");
+
if (srcImage && [srcImage isValid])
{
NSData *srcData = [srcImage TIFFRepresentation];
@@ -172,10 +215,16 @@
RELEASE (srcImage);
}
- [viewer imageReady: info];
+ [viewer imageReady: [NSArchiver archivedDataWithRootObject: info]];
RELEASE (arp);
}
+- (void)terminate
+{
+ NSLog(@"Should terminate - doing nothing");
+}
@end
+
+
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs