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*) newWithApplication: (NSApplication*)app;
+ (GSServicesManager*) manager; + (GSServicesManager*) manager;
- (void) checkServices;
- (void) doService: (NSCell*)item; - (void) doService: (NSCell*)item;
- (BOOL) hasRegisteredTypes: (NSDictionary*)service; - (BOOL) hasRegisteredTypes: (NSDictionary*)service;
- (NSString*) item2title: (NSCell*)item; - (NSString*) item2title: (NSCell*)item;

View file

@ -44,6 +44,7 @@
#include <Foundation/NSUserDefaults.h> #include <Foundation/NSUserDefaults.h>
#include <Foundation/NSSerialization.h> #include <Foundation/NSSerialization.h>
#include <Foundation/NSPortNameServer.h> #include <Foundation/NSPortNameServer.h>
#include <Foundation/NSTask.h>
#include <base/fast.x> #include <base/fast.x>
@ -57,20 +58,16 @@
#include <AppKit/GSServicesManager.h> #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 * It is a proxy with some dangerous methods implemented in a
* harmless manner to reduce the chances of a malicious app * harmless manner to reduce the chances of a malicious app
* messing with us. This is responsible for forwarding service * messing with us. This is responsible for forwarding service
* requests and other communications with the outside world. * requests and other communications with the outside world.
*/ */
@interface GNUListener : NSObject @interface GSListener : NSObject
+ (id) connectionBecameInvalid: (NSNotification*)notification; + (id) connectionBecameInvalid: (NSNotification*)notification;
+ (GNUListener*) listener; + (GSListener*) listener;
+ (id) servicesProvider; + (id) servicesProvider;
+ (void) setServicesProvider: (id)anObject; + (void) setServicesProvider: (id)anObject;
- (Class) class; - (Class) class;
@ -78,10 +75,20 @@
- (void) release; - (void) release;
- (id) retain; - (id) retain;
- (id) self; - (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 @end
static NSConnection *listenerConnection = nil; static NSConnection *listenerConnection = nil;
static GNUListener *listener = nil; static GSListener *listener = nil;
static id servicesProvider = nil; static id servicesProvider = nil;
void void
@ -94,7 +101,7 @@ NSUnregisterServicesProvider(NSString *name)
* the given port name. * the given port name.
*/ */
[[NSPortNameServer defaultPortNameServer] removePortForName: name]; [[NSPortNameServer defaultPortNameServer] removePortForName: name];
[NSNotificationCenter removeObserver: [GNUListener class] [NSNotificationCenter removeObserver: [GSListener class]
name: NSConnectionDidDieNotification name: NSConnectionDidDieNotification
object: listenerConnection]; object: listenerConnection];
[listenerConnection release]; [listenerConnection release];
@ -113,7 +120,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
* the given port name. * the given port name.
*/ */
[[NSPortNameServer defaultPortNameServer] removePortForName: name]; [[NSPortNameServer defaultPortNameServer] removePortForName: name];
[NSNotificationCenter removeObserver: [GNUListener class] [NSNotificationCenter removeObserver: [GSListener class]
name: NSConnectionDidDieNotification name: NSConnectionDidDieNotification
object: listenerConnection]; object: listenerConnection];
[listenerConnection release]; [listenerConnection release];
@ -122,12 +129,12 @@ NSRegisterServicesProvider(id provider, NSString *name)
if (name && provider) if (name && provider)
{ {
listenerConnection = [NSConnection newRegisteringAtName: name listenerConnection = [NSConnection newRegisteringAtName: name
withRootObject: [GNUListener listener]]; withRootObject: [GSListener listener]];
if (listenerConnection) if (listenerConnection)
{ {
[listenerConnection retain]; [listenerConnection retain];
[NotificationDispatcher [NotificationDispatcher
addObserver: [GNUListener class] addObserver: [GSListener class]
selector: @selector(connectionBecameInvalid:) selector: @selector(connectionBecameInvalid:)
name: NSConnectionDidDieNotification name: NSConnectionDidDieNotification
object: listenerConnection]; 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 * service provider objects. It implements very few methods and
* those that it does implement are generally designed to defeat * those that it does implement are generally designed to defeat
* any attack by a malicious program. * any attack by a malicious program.
*/ */
@implementation GNUListener @implementation GSListener
+ (id) connectionBecameInvalid: (NSNotification*)notification + (id) connectionBecameInvalid: (NSNotification*)notification
{ {
@ -160,7 +167,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
return self; return self;
} }
+ (GNUListener*) listener + (GSListener*) listener
{ {
if (listener == nil) if (listener == nil)
{ {
@ -219,6 +226,63 @@ NSRegisterServicesProvider(id provider, NSString *name)
return nil; 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 - (void) release
{ {
} }
@ -232,7 +296,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
{ {
return self; return self;
} }
@end /* GNUListener */ @end /* GSListener */
@ -302,13 +366,6 @@ static NSString *disabledName = @".GNUstepDisabled";
return manager; return manager;
} }
- (void) checkServices
{
system(prog_path(GNUSTEP_INSTALL_PREFIX, "/make_services"));
[self loadServices];
}
- (void) dealloc - (void) dealloc
{ {
NSString *appName; NSString *appName;
@ -860,7 +917,7 @@ static NSString *disabledName = @".GNUstepDisabled";
- (id) servicesProvider - (id) servicesProvider
{ {
return [GNUListener servicesProvider]; return [GSListener servicesProvider];
} }
- (void) setServicesMenu: (NSMenu*)aMenu - (void) setServicesMenu: (NSMenu*)aMenu
@ -871,7 +928,7 @@ static NSString *disabledName = @".GNUstepDisabled";
- (void) setServicesProvider: (id)anObject - (void) setServicesProvider: (id)anObject
{ {
[GNUListener setServicesProvider: anObject]; [GSListener setServicesProvider: anObject];
} }
- (int) setShowsServicesMenuItem: (NSString*)item to: (BOOL)enable - (int) setShowsServicesMenuItem: (NSString*)item to: (BOOL)enable
@ -1195,7 +1252,12 @@ NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
msgImp = get_imp(fastClass(provider), msgSel); msgImp = get_imp(fastClass(provider), msgSel);
NS_DURING 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 NS_HANDLER
{ {

View file

@ -50,6 +50,34 @@
#include <AppKit/NSCursor.h> #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 + (void) removeFrameUsingName: (NSString *)name
{ // Saving and restoring { // Saving and restoring
} // the window's frame } // the window's frame
@ -208,13 +231,14 @@
{ {
NSView *wv; NSView *wv;
if (!aView) // contentview can't be nil // contentview can't be nil
if (!aView)
aView = [[[NSView alloc] initWithFrame: frame] autorelease]; 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)) if ((!content_view) || ([content_view superview] == nil))
{ {
wv = [NSWindow _windowViewWithFrame: frame]; wv = [[GSWindowView allocWithZone: [self zone]] initWithFrame: frame];
[wv viewWillMoveToWindow: self]; [wv viewWillMoveToWindow: self];
} }
else else

View file

@ -40,13 +40,18 @@
#include <Foundation/NSTask.h> #include <Foundation/NSTask.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSProcessInfo.h> #include <Foundation/NSProcessInfo.h>
#include <Foundation/NSFileManager.h>
#define stringify_it(X) #X #define stringify_it(X) #X
#define prog_path(X,Y) \ #define mkpath(X) stringify_it(X) "/Tools"
stringify_it(X) "/Tools/" GNUSTEP_TARGET_DIR "/" LIBRARY_COMBO
static NSDictionary *applications = nil; static NSDictionary *applications = nil;
@interface NSWorkspace (GNUstep)
- (NSTask*) launchProgram: (NSString *)prog
atPath: (NSString *)path;
@end
@implementation NSWorkspace @implementation NSWorkspace
@ -248,8 +253,6 @@ static NSString* library_combo =
NSDate *finish = [NSDate dateWithTimeIntervalSinceNow: 30.0]; NSDate *finish = [NSDate dateWithTimeIntervalSinceNow: 30.0];
id app; id app;
/* FIXME - should probably deactivate self here. */
/* /*
* Try to connect to the application - launches if necessary. * Try to connect to the application - launches if necessary.
*/ */
@ -280,10 +283,13 @@ static NSString* library_combo =
} }
NS_ENDHANDLER NS_ENDHANDLER
if (flag)
[[NSApplication sharedApplication] deactivate];
return YES; return YES;
} }
- (BOOL)openTempFile:(NSString *)fullPath - (BOOL) openTempFile: (NSString *)appName
{ {
return NO; return NO;
} }
@ -370,17 +376,27 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
} }
- (void) noteFileSystemChanged - (void) noteFileSystemChanged
{} {
}
// //
// Updating Registered Services and File Types // Updating Registered Services and File Types
// //
- (void) findApplications - (void) findApplications
{ {
static NSString *path = nil;
NSData *data; NSData *data;
NSDictionary *newApps; 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]; data = [NSData dataWithContentsOfFile: appListPath];
if (data) if (data)
@ -396,7 +412,8 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
// Launching and Manipulating Applications // Launching and Manipulating Applications
// //
- (void) hideOtherApplications - (void) hideOtherApplications
{} {
}
- (BOOL) launchApplication: (NSString *)appName - (BOOL) launchApplication: (NSString *)appName
{ {
@ -409,8 +426,6 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
showIcon: (BOOL)showIcon showIcon: (BOOL)showIcon
autolaunch: (BOOL)autolaunch autolaunch: (BOOL)autolaunch
{ {
NSArray *args;
NSTask *task;
NSString *path; NSString *path;
NSString *file; NSString *file;
NSDictionary *info; NSDictionary *info;
@ -437,21 +452,26 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
if (path == nil) if (path == nil)
return NO; 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"]; file = [path stringByAppendingPathComponent: @"Resources/Info-gnustep.plist"];
info = [NSDictionary dictionaryWithContentsOfFile: file]; info = [NSDictionary dictionaryWithContentsOfFile: file];
file = [info objectForKey: @"NSExecutable"]; 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; return YES;
} }
@ -467,7 +487,8 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
// Tracking Status Changes for Devices // Tracking Status Changes for Devices
// //
- (void) checkForRemovableMedia - (void) checkForRemovableMedia
{} {
}
- (NSArray *) mountNewRemovableMedia - (NSArray *) mountNewRemovableMedia
{ {
@ -508,7 +529,8 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
- (void) slideImage: (NSImage *)image - (void) slideImage: (NSImage *)image
from: (NSPoint)fromPoint from: (NSPoint)fromPoint
to: (NSPoint)toPoint to: (NSPoint)toPoint
{} {
}
// //
// Requesting Additional Time before Power Off or Logout // Requesting Additional Time before Power Off or Logout
@ -519,3 +541,48 @@ inFileViewerRootedAtPath:(NSString *)rootFullpath
} }
@end @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