Tidied launching

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4049 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-04-08 20:42:46 +00:00
parent a332c8f19c
commit c07241993d
4 changed files with 268 additions and 116 deletions

View file

@ -57,7 +57,6 @@
}
+ (GSServicesManager*) newWithApplication: (NSApplication*)app;
+ (GSServicesManager*) manager;
- (void) checkServices;
- (void) doService: (NSCell*)item;
- (BOOL) hasRegisteredTypes: (NSDictionary*)service;
- (NSString*) item2title: (NSCell*)item;

View file

@ -44,6 +44,7 @@
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSSerialization.h>
#include <Foundation/NSPortNameServer.h>
#include <Foundation/NSTask.h>
#include <base/fast.x>
@ -57,20 +58,16 @@
#include <AppKit/GSServicesManager.h>
#define stringify_it(X) #X
#define prog_path(X,Y) \
stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/" LIBRARY_COMBO
/*
* The GNUListener class is for talking to other applications.
* The GSListener class is for talking to other applications.
* It is a proxy with some dangerous methods implemented in a
* harmless manner to reduce the chances of a malicious app
* messing with us. This is responsible for forwarding service
* requests and other communications with the outside world.
*/
@interface GNUListener : NSObject
@interface GSListener : NSObject
+ (id) connectionBecameInvalid: (NSNotification*)notification;
+ (GNUListener*) listener;
+ (GSListener*) listener;
+ (id) servicesProvider;
+ (void) setServicesProvider: (id)anObject;
- (Class) class;
@ -78,10 +75,20 @@
- (void) release;
- (id) retain;
- (id) self;
- (BOOL) application: (NSApplication*)theApp
openFile: (NSString*)file;
- (BOOL) application: (NSApplication*)theApp
openFileWithoutUI: (NSString*)file;
- (BOOL) application: (NSApplication*)theApp
openTempFile: (NSString*)file;
- (void) performService: (NSString*)name
withPasteboard: (NSPasteboard*)pb
userData: (NSString*)ud
error: (NSString**)e;
@end
static NSConnection *listenerConnection = nil;
static GNUListener *listener = nil;
static GSListener *listener = nil;
static id servicesProvider = nil;
void
@ -94,7 +101,7 @@ NSUnregisterServicesProvider(NSString *name)
* the given port name.
*/
[[NSPortNameServer defaultPortNameServer] removePortForName: name];
[NSNotificationCenter removeObserver: [GNUListener class]
[NSNotificationCenter removeObserver: [GSListener class]
name: NSConnectionDidDieNotification
object: listenerConnection];
[listenerConnection release];
@ -113,7 +120,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
* the given port name.
*/
[[NSPortNameServer defaultPortNameServer] removePortForName: name];
[NSNotificationCenter removeObserver: [GNUListener class]
[NSNotificationCenter removeObserver: [GSListener class]
name: NSConnectionDidDieNotification
object: listenerConnection];
[listenerConnection release];
@ -122,12 +129,12 @@ NSRegisterServicesProvider(id provider, NSString *name)
if (name && provider)
{
listenerConnection = [NSConnection newRegisteringAtName: name
withRootObject: [GNUListener listener]];
withRootObject: [GSListener listener]];
if (listenerConnection)
{
[listenerConnection retain];
[NotificationDispatcher
addObserver: [GNUListener class]
addObserver: [GSListener class]
selector: @selector(connectionBecameInvalid:)
name: NSConnectionDidDieNotification
object: listenerConnection];
@ -140,12 +147,12 @@ NSRegisterServicesProvider(id provider, NSString *name)
}
/*
* The GNUListener class exists as a proxy to forward messages to
* The GSListener class exists as a proxy to forward messages to
* service provider objects. It implements very few methods and
* those that it does implement are generally designed to defeat
* any attack by a malicious program.
*/
@implementation GNUListener
@implementation GSListener
+ (id) connectionBecameInvalid: (NSNotification*)notification
{
@ -160,7 +167,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
return self;
}
+ (GNUListener*) listener
+ (GSListener*) listener
{
if (listener == nil)
{
@ -219,6 +226,63 @@ NSRegisterServicesProvider(id provider, NSString *name)
return nil;
}
- (BOOL) application: (NSApplication*)theApp
openFile: (NSString*)file
{
NSApplication *app = [NSApplication sharedApplication];
return [app application: theApp openFile: file];
}
- (BOOL) application: (NSApplication*)theApp
openFileWithoutUI: (NSString*)file
{
NSApplication *app = [NSApplication sharedApplication];
return [app application: theApp openFileWithoutUI: file];
}
- (BOOL) application: (NSApplication*)theApp
openTempFile: (NSString*)file
{
NSApplication *app = [NSApplication sharedApplication];
return [app application: theApp openTempFile: file];
}
- (void) performService: (NSString*)name
withPasteboard: (NSPasteboard*)pb
userData: (NSString*)ud
error: (NSString**)e
{
id obj = servicesProvider;
SEL msgSel = NSSelectorFromString(name);
IMP msgImp;
if (obj != nil && [obj respondsToSelector: msgSel])
{
msgImp = [obj methodForSelector: msgSel];
if (msgImp != 0)
{
(*msgImp)(obj, msgSel, pb, ud, e);
return;
}
}
obj = [[NSApplication sharedApplication] delegate];
if (obj != nil && [obj respondsToSelector: msgSel])
{
msgImp = [obj methodForSelector: msgSel];
if (msgImp != 0)
{
(*msgImp)(obj, msgSel, pb, ud, e);
return;
}
}
*e = @"No object available to provide service";
}
- (void) release
{
}
@ -232,7 +296,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
{
return self;
}
@end /* GNUListener */
@end /* GSListener */
@ -302,13 +366,6 @@ static NSString *disabledName = @".GNUstepDisabled";
return manager;
}
- (void) checkServices
{
system(prog_path(GNUSTEP_INSTALL_PREFIX, "/make_services"));
[self loadServices];
}
- (void) dealloc
{
NSString *appName;
@ -860,7 +917,7 @@ static NSString *disabledName = @".GNUstepDisabled";
- (id) servicesProvider
{
return [GNUListener servicesProvider];
return [GSListener servicesProvider];
}
- (void) setServicesMenu: (NSMenu*)aMenu
@ -871,7 +928,7 @@ static NSString *disabledName = @".GNUstepDisabled";
- (void) setServicesProvider: (id)anObject
{
[GNUListener setServicesProvider: anObject];
[GSListener setServicesProvider: anObject];
}
- (int) setShowsServicesMenuItem: (NSString*)item to: (BOOL)enable
@ -1195,7 +1252,12 @@ NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
msgImp = get_imp(fastClass(provider), msgSel);
NS_DURING
{
(*msgImp)(provider, msgSel, pboard, userData, &error);
[provider performService: selName
withPasteboard: pboard
userData: userData
error: &error];
// (*msgImp)(provider, msgSel, pboard, userData, &error);
}
NS_HANDLER
{

View file

@ -50,6 +50,34 @@
#include <AppKit/NSCursor.h>
@interface GSWindowView : NSView
{
}
@end
@implementation GSWindowView
- (BOOL) isOpaque
{
return YES;
}
- (void) drawRect: (NSRect)rect
{
NSColor *c = [[self window] backgroundColor];
[c set];
NSRectFill(rect);
}
- (Class) classForCoder: (NSCoder*)aCoder
{
if ([self class] == [GSWindowView class])
return [super class];
return [self class];
}
@end
//*****************************************************************************
//
@ -71,11 +99,6 @@
}
}
+ (NSView *) _windowViewWithFrame: (NSRect)frameRect // create the view at
{ // the root of window's
return nil; // view heirarchy.
} // (backend)
+ (void) removeFrameUsingName: (NSString *)name
{ // Saving and restoring
} // the window's frame
@ -208,13 +231,14 @@
{
NSView *wv;
if (!aView) // contentview can't be nil
// contentview can't be nil
if (!aView)
aView = [[[NSView alloc] initWithFrame: frame] autorelease];
// If window view has not
// been created, create it
// If window view has not been created, create it
if ((!content_view) || ([content_view superview] == nil))
{
wv = [NSWindow _windowViewWithFrame: frame];
wv = [[GSWindowView allocWithZone: [self zone]] initWithFrame: frame];
[wv viewWillMoveToWindow: self];
}
else

View file

@ -40,13 +40,18 @@
#include <Foundation/NSTask.h>
#include <Foundation/NSException.h>
#include <Foundation/NSProcessInfo.h>
#include <Foundation/NSFileManager.h>
#define stringify_it(X) #X
#define prog_path(X,Y) \
stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/" LIBRARY_COMBO
#define mkpath(X) stringify_it(X) "/Tools"
static NSDictionary *applications = nil;
@interface NSWorkspace (GNUstep)
- (NSTask*) launchProgram: (NSString *)prog
atPath: (NSString *)path;
@end
@implementation NSWorkspace
@ -248,8 +253,6 @@ static NSString* library_combo =
NSDate *finish = [NSDate dateWithTimeIntervalSinceNow: 30.0];
id app;
/* FIXME - should probably deactivate self here. */
/*
* Try to connect to the application - launches if necessary.
*/
@ -280,10 +283,13 @@ static NSString* library_combo =
}
NS_ENDHANDLER
if (flag)
[[NSApplication sharedApplication] deactivate];
return YES;
}
- (BOOL)openTempFile:(NSString *)fullPath
- (BOOL) openTempFile: (NSString *)appName
{
return NO;
}
@ -370,17 +376,27 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
}
- (void) noteFileSystemChanged
{}
{
}
//
// Updating Registered Services and File Types
//
- (void) findApplications
{
static NSString *path = nil;
NSData *data;
NSDictionary *newApps;
NSTask *task;
system(prog_path(GNUSTEP_INSTALL_PREFIX, "/make_services"));
/*
* Try to locate and run an executable copy of 'make_services'
*/
if (path == nil)
path = [[NSString alloc] initWithCString: mkpath(GNUSTEP_INSTALL_PREFIX)];
task = [self launchProgram: @"make_services" atPath: path];
if (task != nil)
[task waitUntilExit];
data = [NSData dataWithContentsOfFile: appListPath];
if (data)
@ -396,7 +412,8 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
// Launching and Manipulating Applications
//
- (void) hideOtherApplications
{}
{
}
- (BOOL) launchApplication: (NSString *)appName
{
@ -409,8 +426,6 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
showIcon: (BOOL)showIcon
autolaunch: (BOOL)autolaunch
{
NSArray *args;
NSTask *task;
NSString *path;
NSString *file;
NSDictionary *info;
@ -437,21 +452,26 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
if (path == nil)
return NO;
/*
* See if the 'Info-gnustep.plist' specifies the location of the
* executable - if it does, replace our app name with the specified
* value. If the executable name is an absolute path name, we also
* replace the path with that specified.
*/
file = [path stringByAppendingPathComponent: @"Resources/Info-gnustep.plist"];
info = [NSDictionary dictionaryWithContentsOfFile: file];
file = [info objectForKey: @"NSExecutable"];
if (file == nil)
if (file != nil)
{
file = appName;
appName = [file lastPathComponent];
if ([file isAbsolutePath] == YES)
{
path = [file stringByDeletingLastPathComponent];
}
}
path = [path stringByAppendingPathComponent: gnustep_target_dir];
path = [path stringByAppendingPathComponent: library_combo];
path = [path stringByAppendingPathComponent: appName];
args = [NSArray arrayWithObjects: nil];
task = [NSTask launchedTaskWithLaunchPath: path
arguments: args];
if ([self launchProgram: appName atPath: path] == nil)
return NO;
return YES;
}
@ -467,7 +487,8 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
// Tracking Status Changes for Devices
//
- (void) checkForRemovableMedia
{}
{
}
- (NSArray *) mountNewRemovableMedia
{
@ -508,7 +529,8 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
- (void) slideImage: (NSImage *)image
from: (NSPoint)fromPoint
to: (NSPoint)toPoint
{}
{
}
//
// Requesting Additional Time before Power Off or Logout
@ -519,3 +541,48 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
}
@end
@implementation NSWorkspace (GNUstep)
/*
* Attempt to start a program. First look in machine/os/libs directory,
* then in machine/os directory, then at top level.
*/
- (NSTask*) launchProgram: (NSString *)prog
atPath: (NSString *)path
{
NSArray *args;
NSTask *task;
NSString *path0;
NSString *path1;
NSString *path2;
NSFileManager *mgr;
/*
* Try to locate the actual executable file and start it running.
*/
path2 = [path stringByAppendingPathComponent: prog];
path = [path stringByAppendingPathComponent: gnustep_target_dir];
path1 = [path stringByAppendingPathComponent: prog];
path = [path stringByAppendingPathComponent: library_combo];
path0 = [path stringByAppendingPathComponent: prog];
mgr = [NSFileManager defaultManager];
if ([mgr isExecutableFileAtPath: path0])
path = path0;
else if ([mgr isExecutableFileAtPath: path1])
path = path1;
else if ([mgr isExecutableFileAtPath: path2])
path = path2;
else
return nil;
args = [NSArray arrayWithObjects: nil];
task = [NSTask launchedTaskWithLaunchPath: path
arguments: args];
return task;
}
@end