NSHost'ing fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@12079 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-01-10 16:33:39 +00:00
parent 65de9f1abd
commit 3aa806681b
3 changed files with 220 additions and 65 deletions

View file

@ -33,6 +33,7 @@
#include <AppKit/NSFileWrapper.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSData.h>
#include <Foundation/NSHost.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSConnection.h>
#include <Foundation/NSDistantObject.h>
@ -97,7 +98,7 @@ static NSMapTable *mimeMap = NULL;
removeObserver: self
name: NSConnectionDidDieNotification
object: [notification object]];
[obj release];
RELEASE(obj);
return self;
}
@ -105,17 +106,33 @@ static NSMapTable *mimeMap = NULL;
{
if (the_server == nil)
{
NSString* host;
NSString *host;
host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
if (host == nil)
{
host = [[NSProcessInfo processInfo] hostName];
host = @"";
}
else
{
NSHost *h;
/*
* If we have a host specified, but it is the current host,
* we do not need to ask for a host by name (nameserver lookup
* can be faster) and the empty host name can be used to
* indicate that we may start a pasteboard server locally.
*/
h = [NSHost hostWithName: host];
if ([h isEqual: [NSHost currentHost]] == YES)
{
host = @"";
}
}
the_server = (id<GSPasteboardSvr>)[NSConnection
rootProxyForConnectionWithRegisteredName: PBSNAME
host: host];
if ([(id)the_server retain])
if (RETAIN((id)the_server) != nil)
{
NSConnection* conn = [(id)the_server connectionForProxy];
@ -125,14 +142,14 @@ static NSMapTable *mimeMap = NULL;
name: NSConnectionDidDieNotification
object: conn];
}
else
else if ([host isEqual: @""] == YES)
{
static BOOL recursion = NO;
if (recursion)
{
NSLog(@"Unable to contact pasteboard server - "
@"please ensure that gpbs is running.\n");
@"please ensure that gpbs is running.");
return nil;
}
else
@ -162,6 +179,12 @@ static NSMapTable *mimeMap = NULL;
recursion = NO;
}
}
else
{
NSLog(@"Unable to contact pasteboard server on %@ - "
@"please ensure that gpbs is running.", host);
return nil;
}
}
return the_server;
}
@ -190,8 +213,8 @@ static NSMapTable *mimeMap = NULL;
*/
if (p->target != (id)aTarget)
{
[p->target autorelease];
p->target = [(id)aTarget retain];
AUTORELEASE(p->target);
p->target = RETAIN((id)aTarget);
}
}
else
@ -203,15 +226,15 @@ static NSMapTable *mimeMap = NULL;
p = [NSPasteboard alloc];
if (p)
{
p->target = [(id)aTarget retain];
p->name = [aName retain];
p->target = RETAIN((id)aTarget);
p->name = RETAIN(aName);
[pasteboards setObject: p forKey: aName];
[p autorelease];
AUTORELEASE(p);
}
/*
* The [-autorelease] message ensures that the NSPasteboard object we are
* The AUTORELEASE ensures that the NSPasteboard object we are
* returning will be released once our caller has finished with it.
* This is necessary so that our [-release] method will be called to
* This is necessary so that our RELEASE method will be called to
* remove the NSPasteboard from the 'pasteboards' array when it is not
* needed any more.
*/
@ -425,8 +448,8 @@ static NSMapTable *mimeMap = NULL;
- (void) dealloc
{
[target release];
[name release];
RELEASE(target);
RELEASE(name);
[super dealloc];
}
@ -502,12 +525,12 @@ static NSMapTable *mimeMap = NULL;
if ([self retainCount] == 2)
{
[dictionary_lock lock];
[super retain];
RETAIN(super);
[pasteboards removeObjectForKey: name];
[super release];
RELEASE(super);
[dictionary_lock unlock];
}
[super release];
RELEASE(super);
}
- (BOOL) setData: (NSData*)data
@ -937,7 +960,7 @@ NSGetFileTypes(NSArray *pboardTypes)
}
if ([a count] > 0)
{
return [[a copy] autorelease];
return AUTORELEASE([a copy]);
}
return nil;
}

View file

@ -32,6 +32,7 @@
#include <gnustep/gui/config.h>
#include <Foundation/NSBundle.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSHost.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSPathUtilities.h>
#include <Foundation/NSUserDefaults.h>
@ -78,17 +79,26 @@ static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification";
{
remote = RETAIN([NSDistributedNotificationCenter defaultCenter]);
NS_DURING
[remote addObserver: self
selector: @selector(_handleRemoteNotification:)
name: nil
object: GSWorkspaceNotification];
{
[remote addObserver: self
selector: @selector(_handleRemoteNotification:)
name: nil
object: GSWorkspaceNotification];
}
NS_HANDLER
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
if ([defs boolForKey: @"GSLogWorkspaceTimeout"])
NSLog(@"NSWorkspace caught exception %@: %@",
{
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
if ([defs boolForKey: @"GSLogWorkspaceTimeout"])
{
NSLog(@"NSWorkspace caught exception %@: %@",
[localException name], [localException reason]);
else
[localException raise];
}
else
{
[localException raise];
}
}
NS_ENDHANDLER
}
return self;
@ -107,14 +117,23 @@ static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification";
object: GSWorkspaceNotification
userInfo: [aNotification userInfo]];
NS_DURING
[remote postNotification: rem];
{
[remote postNotification: rem];
}
NS_HANDLER
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
if ([defs boolForKey: @"GSLogWorkspaceTimeout"])
NSLog(@"NSWorkspace caught exception %@: %@",
{
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
if ([defs boolForKey: @"GSLogWorkspaceTimeout"])
{
NSLog(@"NSWorkspace caught exception %@: %@",
[localException name], [localException reason]);
else
[localException raise];
}
else
{
[localException raise];
}
}
NS_ENDHANDLER
}
@ -374,10 +393,10 @@ static NSString *_rootPath = @"/";
}
NS_ENDHANDLER
}
if (flag)
[NSApp deactivate];
{
[NSApp deactivate];
}
return YES;
}
@ -1498,38 +1517,108 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
}
}
/**
* Launch an application ... if there is a workspace application, ask it
* to perform the launch for us. Otherwise we try to launch the app
* ourself as long as it is on the same host as we are.
*/
- (BOOL) _launchApplication: (NSString *)appName
arguments: (NSArray *)args
{
NSString *path;
NSDictionary *userinfo;
id app = nil;
path = [self locateApplicationBinary: appName];
if (path == nil)
return NO;
// app = [self _workspaceApplication];
if (app != nil)
{
return [app _launchApplication: appName arguments: args];
}
else
{
NSString *path;
NSDictionary *userinfo;
NSString *host;
// App being launched, send NSWorkspaceWillLaunchApplicationNotification
userinfo = [NSDictionary dictionaryWithObject:
[[appName lastPathComponent] stringByDeletingPathExtension]
forKey: @"NSApplicationName"];
[_workspaceCenter
postNotificationName: NSWorkspaceWillLaunchApplicationNotification
object: self
userInfo: userinfo];
path = [self locateApplicationBinary: appName];
if (path == nil)
{
return NO;
}
if ([NSTask launchedTaskWithLaunchPath: path arguments: args] == nil)
return NO;
/*
* Try to ensure that apps we launch display in this workspace
* ie they have the same -NSHost specification.
*/
host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
if (host != nil)
{
NSHost *h;
// The NSWorkspaceDidLaunchApplicationNotification will be send by the
// started application itself.
return YES;
h = [NSHost hostWithName: host];
if ([h isEqual: [NSHost currentHost]] == NO)
{
if ([args containsObject: @"-NSHost"] == NO)
{
NSMutableArray *a;
if (args == nil)
{
a = [NSMutableArray arrayWithCapacity: 2];
}
else
{
a = AUTORELEASE([args mutableCopy]);
}
[a insertObject: @"-NSHost" atIndex: 0];
[a insertObject: host atIndex: 1];
args = a;
}
}
}
/*
* App being launched, send
* NSWorkspaceWillLaunchApplicationNotification
*/
userinfo = [NSDictionary dictionaryWithObject:
[[appName lastPathComponent] stringByDeletingPathExtension]
forKey: @"NSApplicationName"];
[_workspaceCenter
postNotificationName: NSWorkspaceWillLaunchApplicationNotification
object: self
userInfo: userinfo];
if ([NSTask launchedTaskWithLaunchPath: path arguments: args] == nil)
{
return NO;
}
/*
* The NSWorkspaceDidLaunchApplicationNotification will be
* sent by the started application itself.
*/
return YES;
}
}
- (id) _connectApplication: (NSString *)appName
{
NSString *port;
id app = nil;
NSString *host;
NSString *port;
id app = nil;
host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
if (host == nil)
{
host = @"";
}
else
{
NSHost *h;
h = [NSHost hostWithName: host];
if ([h isEqual: [NSHost currentHost]] == YES)
{
host = @"";
}
}
port = [appName stringByDeletingPathExtension];
/*
* Try to contact a running application.
@ -1537,7 +1626,7 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
NS_DURING
{
app = [NSConnection rootProxyForConnectionWithRegisteredName: port
host: @""];
host: host];
}
NS_HANDLER
{
@ -1551,21 +1640,53 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
- (id) _workspaceApplication
{
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSString *appName;
id app;
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSString *appName;
id app;
/* What Workspace application? */
appName = [defs stringForKey: @"GSWorkspaceApplication"];
if (appName == nil)
appName = @"GSWorkspace";
{
appName = @"GSWorkspace";
}
app = [self _connectApplication: appName];
if (app == nil)
{
if (![self _launchApplication: appName arguments: nil])
return nil;
app = [self _connectApplication: appName];
NSString *host;
/**
* We don't use -_launchApplication:arguents: here as that method
* calls -_workspaceApplication, and would cause recursion.
*/
host = [[NSUserDefaults standardUserDefaults] stringForKey: @"NSHost"];
if (host == nil)
{
host = @"";
}
else
{
NSHost *h;
h = [NSHost hostWithName: host];
if ([h isEqual: [NSHost currentHost]] == YES)
{
host = @"";
}
}
/**
* We can only launch a workspace app if we are displaying to the
* local host (since if we are displaying on another host we want
* to to talk to the workspace app on that host too).
*/
if ([host isEqual: @""] == YES)
{
if ([self _launchApplication: appName arguments: nil] == YES)
{
app = [self _connectApplication: appName];
}
}
}
return app;