1998-12-01 20:54:23 +00:00
|
|
|
|
/*
|
1998-12-10 21:14:52 +00:00
|
|
|
|
GSServicesManager.m
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
Copyright (C) 1998 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
|
|
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
Date: Novemeber 1998
|
|
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <gnustep/gui/config.h>
|
|
|
|
|
|
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
|
#include <Foundation/NSSet.h>
|
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
|
#include <Foundation/NSNotification.h>
|
|
|
|
|
#include <Foundation/NSRunLoop.h>
|
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
|
#include <Foundation/NSTimer.h>
|
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
|
|
|
|
#include <Foundation/NSFileManager.h>
|
|
|
|
|
#include <Foundation/NSConnection.h>
|
|
|
|
|
#include <Foundation/NSDistantObject.h>
|
|
|
|
|
#include <Foundation/NSMethodSignature.h>
|
1999-01-07 15:52:42 +00:00
|
|
|
|
#include <Foundation/NSPathUtilities.h>
|
1998-12-01 20:54:23 +00:00
|
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
|
#include <Foundation/NSSerialization.h>
|
|
|
|
|
#include <Foundation/NSPortNameServer.h>
|
1999-04-08 20:42:46 +00:00
|
|
|
|
#include <Foundation/NSTask.h>
|
2000-10-31 12:47:09 +00:00
|
|
|
|
#include <Foundation/NSObjCRuntime.h>
|
2002-04-11 23:17:42 +00:00
|
|
|
|
#include <Foundation/NSInvocation.h>
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
#include <AppKit/NSApplication.h>
|
|
|
|
|
#include <AppKit/NSPasteboard.h>
|
|
|
|
|
#include <AppKit/NSMenu.h>
|
1998-12-14 15:59:51 +00:00
|
|
|
|
#include <AppKit/NSPanel.h>
|
1998-12-01 20:54:23 +00:00
|
|
|
|
#include <AppKit/NSWindow.h>
|
|
|
|
|
#include <AppKit/NSCell.h>
|
|
|
|
|
#include <AppKit/NSWorkspace.h>
|
|
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
|
#include <AppKit/GSServicesManager.h>
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1999-04-08 20:42:46 +00:00
|
|
|
|
* The GSListener class is for talking to other applications.
|
1998-12-01 20:54:23 +00:00
|
|
|
|
* It is a proxy with some dangerous methods implemented in a
|
|
|
|
|
* harmless manner to reduce the chances of a malicious app
|
1999-01-07 14:28:58 +00:00
|
|
|
|
* messing with us. This is responsible for forwarding service
|
|
|
|
|
* requests and other communications with the outside world.
|
1998-12-01 20:54:23 +00:00
|
|
|
|
*/
|
1999-04-08 20:42:46 +00:00
|
|
|
|
@interface GSListener : NSObject
|
1998-12-01 20:54:23 +00:00
|
|
|
|
+ (id) connectionBecameInvalid: (NSNotification*)notification;
|
1999-04-08 20:42:46 +00:00
|
|
|
|
+ (GSListener*) listener;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
+ (id) servicesProvider;
|
|
|
|
|
+ (void) setServicesProvider: (id)anObject;
|
|
|
|
|
- (Class) class;
|
|
|
|
|
- (void) dealloc;
|
|
|
|
|
- (void) release;
|
|
|
|
|
- (id) retain;
|
|
|
|
|
- (id) self;
|
1999-04-08 20:42:46 +00:00
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
openFile: (NSString*)file;
|
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
openFileWithoutUI: (NSString*)file;
|
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
openTempFile: (NSString*)file;
|
1999-09-02 15:21:42 +00:00
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
printFile: (NSString*)file;
|
1999-04-08 20:42:46 +00:00
|
|
|
|
- (void) performService: (NSString*)name
|
|
|
|
|
withPasteboard: (NSPasteboard*)pb
|
|
|
|
|
userData: (NSString*)ud
|
|
|
|
|
error: (NSString**)e;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
static NSConnection *listenerConnection = nil;
|
1999-04-08 20:42:46 +00:00
|
|
|
|
static GSListener *listener = nil;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
static id servicesProvider = nil;
|
2001-04-18 09:25:39 +00:00
|
|
|
|
static NSString *providerName = nil;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NSUnregisterServicesProvider(NSString *name)
|
|
|
|
|
{
|
2001-04-18 09:25:39 +00:00
|
|
|
|
if (listenerConnection != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Ensure there is no previous listener and nothing else using
|
|
|
|
|
* the given port name.
|
|
|
|
|
*/
|
2000-07-04 09:52:17 +00:00
|
|
|
|
[[NSPortNameServer systemDefaultPortNameServer] removePortForName: name];
|
1999-06-15 20:02:58 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
removeObserver: [GSListener class]
|
|
|
|
|
name: NSConnectionDidDieNotification
|
|
|
|
|
object: listenerConnection];
|
2001-04-18 09:25:39 +00:00
|
|
|
|
DESTROY(listenerConnection);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
ASSIGN(servicesProvider, nil);
|
2001-04-18 09:25:39 +00:00
|
|
|
|
ASSIGN(providerName, nil);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NSRegisterServicesProvider(id provider, NSString *name)
|
|
|
|
|
{
|
2001-04-18 09:25:39 +00:00
|
|
|
|
if (listenerConnection != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Ensure there is no previous listener and nothing else using
|
|
|
|
|
* the given port name.
|
|
|
|
|
*/
|
2000-07-04 09:52:17 +00:00
|
|
|
|
[[NSPortNameServer systemDefaultPortNameServer] removePortForName: name];
|
1999-06-15 20:02:58 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
removeObserver: [GSListener class]
|
|
|
|
|
name: NSConnectionDidDieNotification
|
|
|
|
|
object: listenerConnection];
|
2001-04-18 09:25:39 +00:00
|
|
|
|
DESTROY(listenerConnection);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
2001-04-18 09:25:39 +00:00
|
|
|
|
if (name != nil && provider != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
listenerConnection = [NSConnection newRegisteringAtName: name
|
2001-04-18 09:25:39 +00:00
|
|
|
|
withRootObject: [GSListener listener]];
|
|
|
|
|
if (listenerConnection != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
2001-04-18 09:25:39 +00:00
|
|
|
|
RETAIN(listenerConnection);
|
1999-06-15 20:02:58 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
1999-04-08 20:42:46 +00:00
|
|
|
|
addObserver: [GSListener class]
|
1998-12-01 20:54:23 +00:00
|
|
|
|
selector: @selector(connectionBecameInvalid:)
|
|
|
|
|
name: NSConnectionDidDieNotification
|
|
|
|
|
object: listenerConnection];
|
|
|
|
|
}
|
1999-01-09 06:49:48 +00:00
|
|
|
|
else
|
2001-04-18 09:25:39 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"unable to register %@", name];
|
|
|
|
|
}
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
ASSIGN(servicesProvider, provider);
|
2001-04-18 09:25:39 +00:00
|
|
|
|
ASSIGN(providerName, name);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
1999-04-08 20:42:46 +00:00
|
|
|
|
* The GSListener class exists as a proxy to forward messages to
|
1998-12-01 20:54:23 +00:00
|
|
|
|
* 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.
|
|
|
|
|
*/
|
1999-04-08 20:42:46 +00:00
|
|
|
|
@implementation GSListener
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
+ (id) connectionBecameInvalid: (NSNotification*)notification
|
|
|
|
|
{
|
|
|
|
|
NSAssert(listenerConnection==[notification object],
|
|
|
|
|
NSInternalInconsistencyException);
|
|
|
|
|
|
1999-06-15 20:02:58 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
|
removeObserver: self
|
|
|
|
|
name: NSConnectionDidDieNotification
|
|
|
|
|
object: listenerConnection];
|
2001-04-18 09:25:39 +00:00
|
|
|
|
DESTROY(listenerConnection);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-08 20:42:46 +00:00
|
|
|
|
+ (GSListener*) listener
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (listener == nil)
|
|
|
|
|
{
|
|
|
|
|
listener = (id)NSAllocateObject(self, 0, NSDefaultMallocZone());
|
|
|
|
|
}
|
|
|
|
|
return listener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id) servicesProvider
|
|
|
|
|
{
|
|
|
|
|
return servicesProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) setServicesProvider: (id)anObject
|
|
|
|
|
{
|
|
|
|
|
NSString *appName;
|
|
|
|
|
|
|
|
|
|
if (servicesProvider != anObject)
|
|
|
|
|
{
|
1999-09-03 08:59:07 +00:00
|
|
|
|
appName = [[NSProcessInfo processInfo] processName];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NSRegisterServicesProvider(anObject, appName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (Class) class
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-29 08:22:33 +00:00
|
|
|
|
/*
|
|
|
|
|
* Obsolete ... prefer forwardInvocation now.
|
|
|
|
|
*/
|
1998-12-01 20:54:23 +00:00
|
|
|
|
- forward: (SEL)aSel :(arglist_t)frame
|
|
|
|
|
{
|
|
|
|
|
NSString *selName = NSStringFromSelector(aSel);
|
1999-01-07 14:28:58 +00:00
|
|
|
|
id delegate;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the selector matches the correct form for a services request,
|
|
|
|
|
* send the message to the services provider - otherwise raise an
|
|
|
|
|
* exception to say the method is not implemented.
|
|
|
|
|
*/
|
|
|
|
|
if ([selName hasSuffix: @":userData:error:"])
|
|
|
|
|
return [servicesProvider performv: aSel :frame];
|
|
|
|
|
|
1999-01-07 14:28:58 +00:00
|
|
|
|
/*
|
|
|
|
|
* If tha applications delegate can handle the message - forward to it.
|
|
|
|
|
*/
|
|
|
|
|
delegate = [[NSApplication sharedApplication] delegate];
|
|
|
|
|
if ([delegate respondsToSelector: aSel] == YES)
|
|
|
|
|
return [delegate performv: aSel :frame];
|
|
|
|
|
|
1998-12-01 20:54:23 +00:00
|
|
|
|
[NSException raise: NSGenericException
|
2001-12-29 08:22:33 +00:00
|
|
|
|
format: @"method %@ not implemented", selName];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-29 08:22:33 +00:00
|
|
|
|
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
|
|
|
|
{
|
|
|
|
|
SEL aSel = [anInvocation selector];
|
|
|
|
|
NSString *selName = NSStringFromSelector(aSel);
|
|
|
|
|
id delegate;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the selector matches the correct form for a services request,
|
|
|
|
|
* send the message to the services provider.
|
|
|
|
|
*/
|
|
|
|
|
if ([selName hasSuffix: @":userData:error:"])
|
|
|
|
|
{
|
|
|
|
|
[anInvocation invokeWithTarget: servicesProvider];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If tha applications delegate can handle the message - forward to it.
|
|
|
|
|
*/
|
|
|
|
|
delegate = [[NSApplication sharedApplication] delegate];
|
|
|
|
|
if ([delegate respondsToSelector: aSel] == YES)
|
|
|
|
|
{
|
|
|
|
|
[anInvocation invokeWithTarget: delegate];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"method %@ not implemented", selName];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-04-08 20:42:46 +00:00
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
openFile: (NSString*)file
|
|
|
|
|
{
|
1999-09-02 15:21:42 +00:00
|
|
|
|
id del = [NSApp delegate];
|
1999-04-08 20:42:46 +00:00
|
|
|
|
|
1999-09-02 15:21:42 +00:00
|
|
|
|
if ([del respondsToSelector: _cmd])
|
|
|
|
|
return [del application: theApp openFile: file];
|
|
|
|
|
return NO;
|
1999-04-08 20:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
openFileWithoutUI: (NSString*)file
|
|
|
|
|
{
|
1999-09-02 15:21:42 +00:00
|
|
|
|
id del = [NSApp delegate];
|
1999-04-08 20:42:46 +00:00
|
|
|
|
|
1999-09-02 15:21:42 +00:00
|
|
|
|
if ([del respondsToSelector: _cmd])
|
|
|
|
|
return [del application: theApp openFileWithoutUI: file];
|
|
|
|
|
return NO;
|
1999-04-08 20:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
openTempFile: (NSString*)file
|
|
|
|
|
{
|
1999-09-02 15:21:42 +00:00
|
|
|
|
id del = [NSApp delegate];
|
|
|
|
|
|
|
|
|
|
if ([del respondsToSelector: _cmd])
|
|
|
|
|
return [del application: theApp openTempFile: file];
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) application: (NSApplication*)theApp
|
|
|
|
|
printFile: (NSString*)file
|
|
|
|
|
{
|
|
|
|
|
id del = [NSApp delegate];
|
1999-04-08 20:42:46 +00:00
|
|
|
|
|
1999-09-02 15:21:42 +00:00
|
|
|
|
if ([del respondsToSelector: _cmd])
|
|
|
|
|
return [del application: theApp openFile: file];
|
|
|
|
|
return NO;
|
1999-04-08 20:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (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";
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-01 20:54:23 +00:00
|
|
|
|
- (void) release
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) retain
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) self
|
|
|
|
|
{
|
|
|
|
|
return self;
|
|
|
|
|
}
|
1999-04-08 20:42:46 +00:00
|
|
|
|
@end /* GSListener */
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
|
@implementation GSServicesManager
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
|
static GSServicesManager *manager = nil;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
static NSString *servicesName = @".GNUstepServices";
|
|
|
|
|
static NSString *disabledName = @".GNUstepDisabled";
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Create a new listener for this application.
|
|
|
|
|
* Uses NSRegisterServicesProvider() to register itsself as a service
|
|
|
|
|
* provider with the applications name so we can handle incoming
|
|
|
|
|
* service requests.
|
|
|
|
|
*/
|
1998-12-10 21:14:52 +00:00
|
|
|
|
+ (GSServicesManager*) newWithApplication: (NSApplication*)app
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSString *str;
|
|
|
|
|
NSString *path;
|
|
|
|
|
|
2001-04-18 09:25:39 +00:00
|
|
|
|
if (manager != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (manager->_application == nil)
|
2001-04-18 09:25:39 +00:00
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
manager->_application = app;
|
2001-04-18 09:25:39 +00:00
|
|
|
|
}
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return manager;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
|
manager = [GSServicesManager alloc];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
2001-01-28 12:26:36 +00:00
|
|
|
|
str = [NSSearchPathForDirectoriesInDomains(NSUserDirectory,
|
|
|
|
|
NSUserDomainMask, YES) objectAtIndex: 0];
|
1998-12-06 19:51:44 +00:00
|
|
|
|
str = [str stringByAppendingPathComponent: @"Services"];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
path = [str stringByAppendingPathComponent: servicesName];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
manager->_servicesPath = [path copy];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
path = [str stringByAppendingPathComponent: disabledName];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
manager->_disabledPath = [path copy];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
/*
|
2001-08-14 22:39:06 +00:00
|
|
|
|
* Don't retain application object - that would create a cycle.
|
1998-12-01 20:54:23 +00:00
|
|
|
|
*/
|
2002-01-06 13:26:27 +00:00
|
|
|
|
manager->_application = app;
|
|
|
|
|
manager->_returnInfo = [[NSMutableSet alloc] initWithCapacity: 16];
|
|
|
|
|
manager->_combinations = [[NSMutableDictionary alloc] initWithCapacity: 16];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
/*
|
|
|
|
|
* Check for changes to the services cache every thirty seconds.
|
|
|
|
|
*/
|
2002-01-06 13:26:27 +00:00
|
|
|
|
manager->_timer =
|
1998-12-01 20:54:23 +00:00
|
|
|
|
[NSTimer scheduledTimerWithTimeInterval: 30.0
|
|
|
|
|
target: manager
|
|
|
|
|
selector: @selector(loadServices)
|
|
|
|
|
userInfo: nil
|
|
|
|
|
repeats: YES];
|
|
|
|
|
|
|
|
|
|
[manager loadServices];
|
|
|
|
|
return manager;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
|
+ (GSServicesManager*) manager
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (manager == nil)
|
|
|
|
|
{
|
|
|
|
|
[self newWithApplication: nil];
|
|
|
|
|
}
|
|
|
|
|
return manager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
|
{
|
|
|
|
|
NSString *appName;
|
|
|
|
|
|
1999-09-03 08:59:07 +00:00
|
|
|
|
appName = [[NSProcessInfo processInfo] processName];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
[_timer invalidate];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NSUnregisterServicesProvider(appName);
|
2002-01-06 13:26:27 +00:00
|
|
|
|
RELEASE(_languages);
|
|
|
|
|
RELEASE(_returnInfo);
|
|
|
|
|
RELEASE(_combinations);
|
|
|
|
|
RELEASE(_title2info);
|
|
|
|
|
RELEASE(_menuTitles);
|
|
|
|
|
RELEASE(_servicesMenu);
|
|
|
|
|
RELEASE(_disabledPath);
|
|
|
|
|
RELEASE(_servicesPath);
|
|
|
|
|
RELEASE(_disabledStamp);
|
|
|
|
|
RELEASE(_servicesStamp);
|
|
|
|
|
RELEASE(_allDisabled);
|
|
|
|
|
RELEASE(_allServices);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
[super dealloc];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) doService: (NSCell*)item
|
|
|
|
|
{
|
|
|
|
|
NSString *title = [self item2title: item];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSDictionary *info = [_title2info objectForKey: title];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NSArray *sendTypes = [info objectForKey: @"NSSendTypes"];
|
|
|
|
|
NSArray *returnTypes = [info objectForKey: @"NSReturnTypes"];
|
|
|
|
|
unsigned i, j;
|
|
|
|
|
unsigned es = [sendTypes count];
|
|
|
|
|
unsigned er = [returnTypes count];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSWindow *resp = [[_application keyWindow] firstResponder];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
id obj = nil;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i <= es; i++)
|
|
|
|
|
{
|
|
|
|
|
NSString *sendType;
|
|
|
|
|
|
|
|
|
|
sendType = (i < es) ? [sendTypes objectAtIndex: i] : nil;
|
|
|
|
|
|
|
|
|
|
for (j = 0; j <= er; j++)
|
|
|
|
|
{
|
|
|
|
|
NSString *returnType;
|
|
|
|
|
|
|
|
|
|
returnType = (j < er) ? [returnTypes objectAtIndex: j] : nil;
|
|
|
|
|
|
|
|
|
|
obj = [resp validRequestorForSendType: sendType
|
|
|
|
|
returnType: returnType];
|
|
|
|
|
if (obj != nil)
|
|
|
|
|
{
|
|
|
|
|
NSPasteboard *pb;
|
|
|
|
|
|
|
|
|
|
pb = [NSPasteboard pasteboardWithUniqueName];
|
2002-06-08 18:11:17 +00:00
|
|
|
|
if (sendType
|
|
|
|
|
&& [obj writeSelectionToPasteboard: pb
|
|
|
|
|
types: sendTypes] == NO)
|
1998-12-14 15:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(nil,
|
|
|
|
|
@"object failed to write to pasteboard",
|
|
|
|
|
@"Continue", nil, nil);
|
|
|
|
|
}
|
|
|
|
|
else if (NSPerformService(title, pb) == YES)
|
|
|
|
|
{
|
2002-06-08 18:11:17 +00:00
|
|
|
|
if (returnType
|
|
|
|
|
&& [obj readSelectionFromPasteboard: pb] == NO)
|
1998-12-14 15:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(nil,
|
|
|
|
|
@"object failed to read from pasteboard",
|
|
|
|
|
@"Continue", nil, nil);
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL) hasRegisteredTypes: (NSDictionary*)service
|
|
|
|
|
{
|
|
|
|
|
NSArray *sendTypes = [service objectForKey: @"NSSendTypes"];
|
|
|
|
|
NSArray *returnTypes = [service objectForKey: @"NSReturnTypes"];
|
|
|
|
|
NSString *type;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We know that both sendTypes and returnTypes can't be nil since
|
|
|
|
|
* make_services has validated the service entry for us.
|
|
|
|
|
*/
|
|
|
|
|
if (sendTypes == nil || [sendTypes count] == 0)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < [returnTypes count]; i++)
|
|
|
|
|
{
|
|
|
|
|
type = [returnTypes objectAtIndex: i];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([_returnInfo member: type] != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (returnTypes == nil || [returnTypes count] == 0)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < [sendTypes count]; i++)
|
|
|
|
|
{
|
|
|
|
|
type = [sendTypes objectAtIndex: i];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([_combinations objectForKey: type] != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < [sendTypes count]; i++)
|
|
|
|
|
{
|
|
|
|
|
NSSet *rset;
|
|
|
|
|
|
|
|
|
|
type = [sendTypes objectAtIndex: i];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
rset = [_combinations objectForKey: type];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (rset != nil)
|
|
|
|
|
{
|
|
|
|
|
unsigned j;
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < [returnTypes count]; j++)
|
|
|
|
|
{
|
|
|
|
|
type = [returnTypes objectAtIndex: j];
|
|
|
|
|
if ([rset member: type] != nil)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Use tag in menu cell to identify slot in menu titles array that
|
|
|
|
|
* contains the full title of the service.
|
|
|
|
|
* Return nil if this is not one of our service menu cells.
|
|
|
|
|
*/
|
|
|
|
|
- (NSString*) item2title: (NSCell*)item
|
|
|
|
|
{
|
|
|
|
|
unsigned pos;
|
|
|
|
|
|
|
|
|
|
if ([item target] != self)
|
|
|
|
|
return nil;
|
|
|
|
|
pos = [item tag];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (pos > [_menuTitles count])
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return nil;
|
2002-01-06 13:26:27 +00:00
|
|
|
|
return [_menuTitles objectAtIndex: pos];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) loadServices
|
|
|
|
|
{
|
|
|
|
|
NSFileManager *mgr = [NSFileManager defaultManager];
|
|
|
|
|
NSDate *stamp = [NSDate date];
|
|
|
|
|
BOOL changed = NO;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([mgr fileExistsAtPath: _disabledPath])
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSDictionary *attr;
|
|
|
|
|
NSDate *mod;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
attr = [mgr fileAttributesAtPath: _disabledPath
|
1998-12-01 20:54:23 +00:00
|
|
|
|
traverseLink: YES];
|
|
|
|
|
mod = [attr objectForKey: NSFileModificationDate];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (_disabledStamp == nil || [_disabledStamp laterDate: mod] == mod)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSData *data;
|
|
|
|
|
id plist = nil;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
data = [NSData dataWithContentsOfFile: _disabledPath];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (data)
|
|
|
|
|
{
|
|
|
|
|
plist = [NSDeserializer deserializePropertyListFromData: data
|
|
|
|
|
mutableContainers: NO];
|
|
|
|
|
if (plist)
|
|
|
|
|
{
|
|
|
|
|
NSMutableSet *s;
|
|
|
|
|
stamp = mod;
|
|
|
|
|
changed = YES;
|
|
|
|
|
s = (NSMutableSet*)[NSMutableSet setWithArray: plist];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_allDisabled, s);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Track most recent version of file loaded or last time we checked */
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_disabledStamp, stamp);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
stamp = [NSDate date];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([mgr fileExistsAtPath: _servicesPath])
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSDictionary *attr;
|
|
|
|
|
NSDate *mod;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
attr = [mgr fileAttributesAtPath: _servicesPath
|
1998-12-01 20:54:23 +00:00
|
|
|
|
traverseLink: YES];
|
|
|
|
|
mod = [attr objectForKey: NSFileModificationDate];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (_servicesStamp == nil || [_servicesStamp laterDate: mod] == mod)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSData *data;
|
|
|
|
|
id plist = nil;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
data = [NSData dataWithContentsOfFile: _servicesPath];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (data)
|
|
|
|
|
{
|
|
|
|
|
plist = [NSDeserializer deserializePropertyListFromData: data
|
|
|
|
|
mutableContainers: YES];
|
|
|
|
|
if (plist)
|
|
|
|
|
{
|
|
|
|
|
stamp = mod;
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_allServices, plist);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
changed = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Track most recent version of file loaded or last time we checked */
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_servicesStamp, stamp);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (changed)
|
|
|
|
|
{
|
|
|
|
|
[self rebuildServices];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSDictionary*) menuServices
|
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (_allServices == nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
[self loadServices];
|
|
|
|
|
}
|
2002-01-06 13:26:27 +00:00
|
|
|
|
return _title2info;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) rebuildServices
|
|
|
|
|
{
|
|
|
|
|
NSDictionary *services;
|
|
|
|
|
NSMutableArray *newLang;
|
|
|
|
|
NSMutableSet *alreadyFound;
|
|
|
|
|
NSMutableDictionary *newServices;
|
|
|
|
|
unsigned pos;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (_allServices == nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2001-11-28 19:20:10 +00:00
|
|
|
|
newLang = AUTORELEASE([[NSUserDefaults userLanguages] mutableCopy]);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (newLang == nil)
|
|
|
|
|
{
|
|
|
|
|
newLang = [NSMutableArray arrayWithCapacity: 1];
|
|
|
|
|
}
|
|
|
|
|
if ([newLang containsObject: @"default"] == NO)
|
|
|
|
|
{
|
|
|
|
|
[newLang addObject: @"default"];
|
|
|
|
|
}
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_languages, newLang);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
services = [_allServices objectForKey: @"ByService"];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
newServices = [NSMutableDictionary dictionaryWithCapacity: 16];
|
|
|
|
|
alreadyFound = [NSMutableSet setWithCapacity: 16];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Build dictionary of services we can use.
|
|
|
|
|
* 1. make sure we make dictionary keyed on preferred menu item language
|
|
|
|
|
* 2. don't include entries for services already examined.
|
|
|
|
|
* 3. don't include entries for menu items specifically disabled.
|
|
|
|
|
* 4. don't include entries for which we have no registered types.
|
|
|
|
|
*/
|
2002-01-06 13:26:27 +00:00
|
|
|
|
for (pos = 0; pos < [_languages count]; pos++)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSDictionary *byLanguage;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
byLanguage = [services objectForKey: [_languages objectAtIndex: pos]];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (byLanguage != nil)
|
|
|
|
|
{
|
|
|
|
|
NSEnumerator *enumerator = [byLanguage keyEnumerator];
|
|
|
|
|
NSString *menuItem;
|
|
|
|
|
|
|
|
|
|
while ((menuItem = [enumerator nextObject]) != nil)
|
|
|
|
|
{
|
|
|
|
|
NSDictionary *service = [byLanguage objectForKey: menuItem];
|
|
|
|
|
|
|
|
|
|
if ([alreadyFound member: service] != nil)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
[alreadyFound addObject: service];
|
|
|
|
|
|
|
|
|
|
/* See if this service item is disabled. */
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([_allDisabled member: menuItem] != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if ([self hasRegisteredTypes: service])
|
|
|
|
|
[newServices setObject: service forKey: menuItem];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([newServices isEqual: _title2info] == NO)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSArray *titles;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_title2info, newServices);
|
|
|
|
|
titles = [_title2info allKeys];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
titles = [titles sortedArrayUsingSelector: @selector(compare:)];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_menuTitles, titles);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
[self rebuildServicesMenu];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) rebuildServicesMenu
|
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (_servicesMenu != nil)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSArray *itemArray;
|
|
|
|
|
NSMutableSet *keyEquivalents;
|
|
|
|
|
unsigned pos;
|
|
|
|
|
unsigned loc0;
|
1999-02-01 14:14:58 +00:00
|
|
|
|
unsigned loc1 = 0;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
SEL sel = @selector(doService:);
|
|
|
|
|
NSMenu *submenu = nil;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
itemArray = [[_servicesMenu itemArray] copy];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
pos = [itemArray count];
|
|
|
|
|
while (pos > 0)
|
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
[_servicesMenu removeItem: [itemArray objectAtIndex: --pos]];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
2001-04-18 09:25:39 +00:00
|
|
|
|
RELEASE(itemArray);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
keyEquivalents = [NSMutableSet setWithCapacity: 4];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
for (loc0 = pos = 0; pos < [_menuTitles count]; pos++)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSString *title = [_menuTitles objectAtIndex: pos];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NSString *equiv = @"";
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSDictionary *info = [_title2info objectForKey: title];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NSDictionary *titles;
|
|
|
|
|
NSDictionary *equivs;
|
|
|
|
|
NSRange r;
|
|
|
|
|
unsigned lang;
|
|
|
|
|
id<NSMenuItem> item;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find the key equivalent corresponding to this menu title
|
|
|
|
|
* in the service definition.
|
|
|
|
|
*/
|
|
|
|
|
titles = [info objectForKey: @"NSMenuItem"];
|
|
|
|
|
equivs = [info objectForKey: @"NSKeyEquivalent"];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
for (lang = 0; lang < [_languages count]; lang++)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSString *language = [_languages objectAtIndex: lang];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NSString *t = [titles objectForKey: language];
|
|
|
|
|
|
|
|
|
|
if ([t isEqual: title])
|
|
|
|
|
{
|
|
|
|
|
equiv = [equivs objectForKey: language];
|
2002-01-06 13:06:56 +00:00
|
|
|
|
if (equiv == nil)
|
|
|
|
|
{
|
|
|
|
|
equiv = [equivs objectForKey: @"default"];
|
|
|
|
|
}
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Make a note that we are using the key equivalent, or
|
|
|
|
|
* set to nil if we have already used it in this menu.
|
|
|
|
|
*/
|
|
|
|
|
if (equiv)
|
|
|
|
|
{
|
|
|
|
|
if ([keyEquivalents member: equiv] == nil)
|
|
|
|
|
{
|
|
|
|
|
[keyEquivalents addObject: equiv];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
equiv = @"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r = [title rangeOfString: @"/"];
|
|
|
|
|
if (r.length > 0)
|
|
|
|
|
{
|
|
|
|
|
NSString *subtitle = [title substringFromIndex: r.location+1];
|
|
|
|
|
NSString *parentTitle = [title substringToIndex: r.location];
|
|
|
|
|
NSMenu *menu;
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
item = [_servicesMenu itemWithTitle: parentTitle];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (item == nil)
|
|
|
|
|
{
|
|
|
|
|
loc1 = 0;
|
2002-01-06 13:26:27 +00:00
|
|
|
|
item = [_servicesMenu insertItemWithTitle: parentTitle
|
1998-12-01 20:54:23 +00:00
|
|
|
|
action: 0
|
|
|
|
|
keyEquivalent: @""
|
|
|
|
|
atIndex: loc0++];
|
|
|
|
|
menu = [[NSMenu alloc] initWithTitle: parentTitle];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
[_servicesMenu setSubmenu: menu
|
1998-12-01 20:54:23 +00:00
|
|
|
|
forItem: item];
|
2001-04-18 09:25:39 +00:00
|
|
|
|
RELEASE(menu);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
menu = (NSMenu*)[item target];
|
|
|
|
|
}
|
|
|
|
|
if (menu != submenu)
|
|
|
|
|
{
|
|
|
|
|
[submenu sizeToFit];
|
|
|
|
|
submenu = menu;
|
|
|
|
|
}
|
|
|
|
|
item = [submenu insertItemWithTitle: subtitle
|
|
|
|
|
action: sel
|
|
|
|
|
keyEquivalent: equiv
|
|
|
|
|
atIndex: loc1++];
|
|
|
|
|
[item setTarget: self];
|
|
|
|
|
[item setTag: pos];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
item = [_servicesMenu insertItemWithTitle: title
|
1998-12-01 20:54:23 +00:00
|
|
|
|
action: sel
|
|
|
|
|
keyEquivalent: equiv
|
|
|
|
|
atIndex: loc0++];
|
|
|
|
|
[item setTarget: self];
|
|
|
|
|
[item setTag: pos];
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-08-20 20:55:23 +00:00
|
|
|
|
[submenu update];
|
|
|
|
|
// [submenu sizeToFit];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
// [_servicesMenu sizeToFit];
|
|
|
|
|
[_servicesMenu update];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set up connection to listen for incoming service requests.
|
|
|
|
|
*/
|
|
|
|
|
- (void) registerAsServiceProvider
|
|
|
|
|
{
|
1999-01-09 06:49:48 +00:00
|
|
|
|
NSString *appName;
|
|
|
|
|
BOOL registered;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
1999-09-03 08:59:07 +00:00
|
|
|
|
appName = [[NSProcessInfo processInfo] processName];
|
1998-12-10 19:53:41 +00:00
|
|
|
|
NS_DURING
|
1999-01-09 06:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
NSRegisterServicesProvider(self, appName);
|
|
|
|
|
registered = YES;
|
|
|
|
|
}
|
1998-12-10 19:53:41 +00:00
|
|
|
|
NS_HANDLER
|
2001-04-18 09:25:39 +00:00
|
|
|
|
{
|
|
|
|
|
registered = NO;
|
|
|
|
|
}
|
1998-12-10 19:53:41 +00:00
|
|
|
|
NS_ENDHANDLER
|
1999-01-09 06:49:48 +00:00
|
|
|
|
|
|
|
|
|
if (registered == NO)
|
|
|
|
|
{
|
|
|
|
|
int result = NSRunAlertPanel(appName,
|
|
|
|
|
@"Application may already be running with this name",
|
|
|
|
|
@"Continue", @"Abort", @"Rename");
|
|
|
|
|
|
|
|
|
|
if (result == NSAlertDefaultReturn || result == NSAlertOtherReturn)
|
|
|
|
|
{
|
|
|
|
|
if (result == NSAlertOtherReturn)
|
1999-02-01 14:14:58 +00:00
|
|
|
|
appName = [[NSProcessInfo processInfo] globallyUniqueString];
|
|
|
|
|
|
2000-07-04 09:52:17 +00:00
|
|
|
|
[[NSPortNameServer systemDefaultPortNameServer]
|
|
|
|
|
removePortForName: appName];
|
1999-01-09 06:49:48 +00:00
|
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
|
{
|
|
|
|
|
NSRegisterServicesProvider(self, appName);
|
|
|
|
|
registered = YES;
|
|
|
|
|
}
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
{
|
|
|
|
|
registered = NO;
|
|
|
|
|
NSLog(@"Warning: Could not register application due to "
|
|
|
|
|
@"exception: %@\n", [localException reason]);
|
|
|
|
|
}
|
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Something is seriously wrong - we can't talk to the
|
|
|
|
|
* nameserver, so all interaction with the workspace manager
|
|
|
|
|
* and/or other applications will fail.
|
|
|
|
|
* Give the user a chance to keep on going anyway.
|
|
|
|
|
*/
|
|
|
|
|
if (registered == NO)
|
|
|
|
|
{
|
|
|
|
|
result = NSRunAlertPanel(appName,
|
|
|
|
|
@"Unable to register application with ANY name",
|
|
|
|
|
@"Abort", @"Continue", nil);
|
|
|
|
|
|
|
|
|
|
if (result == NSAlertDefaultReturn)
|
|
|
|
|
registered = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (registered == NO)
|
|
|
|
|
[[NSApplication sharedApplication] terminate: self];
|
|
|
|
|
}
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Register send and return types that an object can handle - we keep
|
|
|
|
|
* a note of all the possible combinations -
|
|
|
|
|
* 'returnInfo' is a set of all the return types that can be handled
|
|
|
|
|
* without a send.
|
|
|
|
|
* 'combinations' is a dictionary of all send types, with the assciated
|
|
|
|
|
* values being sets of possible return types.
|
|
|
|
|
*/
|
|
|
|
|
- (void) registerSendTypes: (NSArray *)sendTypes
|
|
|
|
|
returnTypes: (NSArray *)returnTypes
|
|
|
|
|
{
|
|
|
|
|
BOOL didChange = NO;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < [sendTypes count]; i++)
|
|
|
|
|
{
|
|
|
|
|
NSString *sendType = [sendTypes objectAtIndex: i];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSMutableSet *returnSet = [_combinations objectForKey: sendType];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
if (returnSet == nil)
|
|
|
|
|
{
|
|
|
|
|
returnSet = [NSMutableSet setWithCapacity: [returnTypes count]];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
[_combinations setObject: returnSet forKey: sendType];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
[returnSet addObjectsFromArray: returnTypes];
|
|
|
|
|
didChange = YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
unsigned count = [returnSet count];
|
|
|
|
|
|
|
|
|
|
[returnSet addObjectsFromArray: returnTypes];
|
|
|
|
|
if ([returnSet count] != count)
|
|
|
|
|
{
|
|
|
|
|
didChange = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
i = [_returnInfo count];
|
|
|
|
|
[_returnInfo addObjectsFromArray: returnTypes];
|
|
|
|
|
if ([_returnInfo count] != i)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
didChange = YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (didChange)
|
|
|
|
|
{
|
|
|
|
|
[self rebuildServices];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSMenu*) servicesMenu
|
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
return _servicesMenu;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id) servicesProvider
|
|
|
|
|
{
|
1999-04-08 20:42:46 +00:00
|
|
|
|
return [GSListener servicesProvider];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setServicesMenu: (NSMenu*)aMenu
|
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
ASSIGN(_servicesMenu, aMenu);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
[self rebuildServicesMenu];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) setServicesProvider: (id)anObject
|
|
|
|
|
{
|
1999-04-08 20:42:46 +00:00
|
|
|
|
[GSListener setServicesProvider: anObject];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (int) setShowsServicesMenuItem: (NSString*)item to: (BOOL)enable
|
|
|
|
|
{
|
|
|
|
|
NSData *d;
|
|
|
|
|
|
|
|
|
|
[self loadServices];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (_allDisabled == nil)
|
|
|
|
|
_allDisabled = [[NSMutableSet alloc] initWithCapacity: 1];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
if (enable)
|
2002-01-06 13:26:27 +00:00
|
|
|
|
[_allDisabled removeObject: item];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
else
|
2002-01-06 13:26:27 +00:00
|
|
|
|
[_allDisabled addObject: item];
|
|
|
|
|
d = [NSSerializer serializePropertyList: [_allDisabled allObjects]];
|
|
|
|
|
if ([d writeToFile: _disabledPath atomically: YES] == YES)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-04 10:44:02 +00:00
|
|
|
|
- (BOOL) showsServicesMenuItem: (NSString*)item
|
1998-12-03 13:27:08 +00:00
|
|
|
|
{
|
|
|
|
|
[self loadServices];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([_allDisabled member: item] == nil)
|
1998-12-03 13:27:08 +00:00
|
|
|
|
return YES;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-01 20:54:23 +00:00
|
|
|
|
- (BOOL) validateMenuItem: (NSCell*)item
|
|
|
|
|
{
|
|
|
|
|
NSString *title = [self item2title: item];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSDictionary *info = [_title2info objectForKey: title];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NSArray *sendTypes = [info objectForKey: @"NSSendTypes"];
|
|
|
|
|
NSArray *returnTypes = [info objectForKey: @"NSReturnTypes"];
|
|
|
|
|
unsigned i, j;
|
|
|
|
|
unsigned es = [sendTypes count];
|
|
|
|
|
unsigned er = [returnTypes count];
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSWindow *resp = [[_application keyWindow] firstResponder];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the menu item is not in our map, it must be the cell containing
|
|
|
|
|
* a sub-menu - so we see if any cell in the submenu is valid.
|
|
|
|
|
*/
|
|
|
|
|
if (title == nil)
|
|
|
|
|
{
|
|
|
|
|
NSMenu *sub = [item target];
|
|
|
|
|
|
|
|
|
|
if (sub && [sub isKindOfClass: [NSMenu class]])
|
|
|
|
|
{
|
|
|
|
|
NSArray *a = [sub itemArray];
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < [a count]; i++)
|
|
|
|
|
{
|
|
|
|
|
if ([self validateMenuItem: [a objectAtIndex: i]] == YES)
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The cell corresponds to one of our services - so we check to see if
|
|
|
|
|
* there is anything that can deal with it.
|
|
|
|
|
*/
|
|
|
|
|
if (es == 0)
|
|
|
|
|
{
|
|
|
|
|
if (er == 0)
|
|
|
|
|
{
|
|
|
|
|
if ([resp validRequestorForSendType: nil
|
|
|
|
|
returnType: nil] != nil)
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (j = 0; j < er; j++)
|
|
|
|
|
{
|
|
|
|
|
NSString *returnType;
|
|
|
|
|
|
|
|
|
|
returnType = [returnTypes objectAtIndex: j];
|
|
|
|
|
if ([resp validRequestorForSendType: nil
|
|
|
|
|
returnType: returnType] != nil)
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < es; i++)
|
|
|
|
|
{
|
|
|
|
|
NSString *sendType;
|
|
|
|
|
|
|
|
|
|
sendType = [sendTypes objectAtIndex: i];
|
|
|
|
|
|
|
|
|
|
if (er == 0)
|
|
|
|
|
{
|
|
|
|
|
if ([resp validRequestorForSendType: sendType
|
|
|
|
|
returnType: nil] != nil)
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (j = 0; j < er; j++)
|
|
|
|
|
{
|
|
|
|
|
NSString *returnType;
|
|
|
|
|
|
|
|
|
|
returnType = [returnTypes objectAtIndex: j];
|
|
|
|
|
if ([resp validRequestorForSendType: sendType
|
|
|
|
|
returnType: returnType] != nil)
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) updateServicesMenu
|
|
|
|
|
{
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if (_servicesMenu && [[_application mainMenu] autoenablesItems])
|
1998-12-01 20:54:23 +00:00
|
|
|
|
{
|
|
|
|
|
NSArray *a;
|
|
|
|
|
unsigned i;
|
2002-01-06 13:26:27 +00:00
|
|
|
|
NSMenu *mainMenu = [_application mainMenu];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
BOOL found = NO;
|
|
|
|
|
|
|
|
|
|
a = [mainMenu itemArray];
|
|
|
|
|
for (i = 0; i < [a count]; i++)
|
2002-01-06 13:26:27 +00:00
|
|
|
|
if ([[a objectAtIndex: i] submenu] == _servicesMenu)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
found = YES;
|
|
|
|
|
if (found == NO)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Services menu not in main menu!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-06 13:26:27 +00:00
|
|
|
|
a = [_servicesMenu itemArray];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < [a count]; i++)
|
|
|
|
|
{
|
|
|
|
|
NSCell *cell = [a objectAtIndex: i];
|
|
|
|
|
BOOL wasEnabled = [cell isEnabled];
|
1998-12-14 15:59:51 +00:00
|
|
|
|
BOOL shouldBeEnabled;
|
|
|
|
|
NSString *title = [self item2title: cell];
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If there is no title mapping, this cell must be a
|
1998-12-22 12:34:03 +00:00
|
|
|
|
* submenu - so we check the submenu cells.
|
1998-12-14 15:59:51 +00:00
|
|
|
|
*/
|
|
|
|
|
if (title == nil && [[cell target] isKindOfClass: [NSMenu class]])
|
|
|
|
|
{
|
1999-07-19 22:21:10 +00:00
|
|
|
|
NSArray *sub = [[cell target] itemArray];
|
1998-12-14 15:59:51 +00:00
|
|
|
|
int j;
|
|
|
|
|
|
|
|
|
|
shouldBeEnabled = NO;
|
|
|
|
|
for (j = 0; j < [sub count]; j++)
|
|
|
|
|
{
|
|
|
|
|
NSCell *subCell = [sub objectAtIndex: j];
|
|
|
|
|
BOOL subWasEnabled = [subCell isEnabled];
|
|
|
|
|
BOOL subShouldBeEnabled = NO;
|
|
|
|
|
|
|
|
|
|
if ([self validateMenuItem: subCell] == YES)
|
|
|
|
|
{
|
|
|
|
|
shouldBeEnabled = YES; /* Enabled menu */
|
|
|
|
|
subShouldBeEnabled = YES;
|
|
|
|
|
}
|
|
|
|
|
if (subWasEnabled != subShouldBeEnabled)
|
|
|
|
|
{
|
|
|
|
|
[subCell setEnabled: subShouldBeEnabled];
|
1999-07-19 22:21:10 +00:00
|
|
|
|
// [subMenuCells setNeedsDisplayInRect:
|
|
|
|
|
// [subMenuCells cellFrameAtRow: j]];
|
1998-12-14 15:59:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
shouldBeEnabled = [self validateMenuItem: cell];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
if (wasEnabled != shouldBeEnabled)
|
|
|
|
|
{
|
|
|
|
|
[cell setEnabled: shouldBeEnabled];
|
1999-07-19 22:21:10 +00:00
|
|
|
|
// [menuCells setNeedsDisplayInRect: [menuCells cellFrameAtRow: i]];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
|
@end /* GSServicesManager */
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
|
1999-01-07 15:52:42 +00:00
|
|
|
|
id
|
|
|
|
|
GSContactApplication(NSString *appName, NSString *port, NSDate *expire)
|
|
|
|
|
{
|
2001-05-04 04:11:53 +00:00
|
|
|
|
id app;
|
1999-01-07 15:52:42 +00:00
|
|
|
|
|
2001-04-18 09:25:39 +00:00
|
|
|
|
if (providerName != nil && [port isEqual: providerName] == YES)
|
1999-01-07 15:52:42 +00:00
|
|
|
|
{
|
2001-05-04 04:11:53 +00:00
|
|
|
|
app = [GSListener listener]; // Contect our own listener.
|
1999-01-07 15:52:42 +00:00
|
|
|
|
}
|
2001-04-18 09:25:39 +00:00
|
|
|
|
else
|
1999-01-07 15:52:42 +00:00
|
|
|
|
{
|
2001-04-18 09:25:39 +00:00
|
|
|
|
NS_DURING
|
|
|
|
|
{
|
|
|
|
|
app = [NSConnection rootProxyForConnectionWithRegisteredName: port
|
|
|
|
|
host: @""];
|
|
|
|
|
}
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
{
|
|
|
|
|
return nil; /* Fatal error in DO */
|
|
|
|
|
}
|
|
|
|
|
NS_ENDHANDLER
|
1999-01-07 15:52:42 +00:00
|
|
|
|
}
|
|
|
|
|
if (app == nil)
|
|
|
|
|
{
|
|
|
|
|
if ([[NSWorkspace sharedWorkspace] launchApplication: appName] == NO)
|
|
|
|
|
{
|
|
|
|
|
return nil; /* Unable to launch. */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
|
{
|
|
|
|
|
app = [NSConnection
|
|
|
|
|
rootProxyForConnectionWithRegisteredName: port
|
|
|
|
|
host: @""];
|
|
|
|
|
while (app == nil && [expire timeIntervalSinceNow] > 0.1)
|
|
|
|
|
{
|
|
|
|
|
NSRunLoop *loop = [NSRunLoop currentRunLoop];
|
|
|
|
|
NSDate *next;
|
|
|
|
|
|
|
|
|
|
[NSTimer scheduledTimerWithTimeInterval: 0.1
|
|
|
|
|
invocation: nil
|
|
|
|
|
repeats: NO];
|
|
|
|
|
next = [NSDate dateWithTimeIntervalSinceNow: 0.2];
|
|
|
|
|
[loop runUntilDate: next];
|
|
|
|
|
app = [NSConnection
|
|
|
|
|
rootProxyForConnectionWithRegisteredName: port
|
|
|
|
|
host: @""];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
{
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-01 20:54:23 +00:00
|
|
|
|
BOOL
|
|
|
|
|
NSPerformService(NSString *serviceItem, NSPasteboard *pboard)
|
|
|
|
|
{
|
|
|
|
|
NSDictionary *service;
|
|
|
|
|
NSString *port;
|
|
|
|
|
NSString *timeout;
|
|
|
|
|
double seconds;
|
|
|
|
|
NSDate *finishBy;
|
|
|
|
|
NSString *appPath;
|
|
|
|
|
id provider;
|
|
|
|
|
NSString *message;
|
|
|
|
|
NSString *selName;
|
|
|
|
|
NSString *userData;
|
|
|
|
|
NSString *error = nil;
|
|
|
|
|
|
|
|
|
|
service = [[manager menuServices] objectForKey: serviceItem];
|
|
|
|
|
if (service == nil)
|
1998-12-14 15:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(nil,
|
2002-06-08 18:11:17 +00:00
|
|
|
|
@"No service matching '%@'",
|
|
|
|
|
@"Continue", nil, nil,
|
|
|
|
|
serviceItem);
|
1998-12-14 15:59:51 +00:00
|
|
|
|
return NO; /* No matching service. */
|
|
|
|
|
}
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
|
|
|
|
port = [service objectForKey: @"NSPortName"];
|
|
|
|
|
timeout = [service objectForKey: @"NSTimeout"];
|
|
|
|
|
if (timeout && [timeout floatValue] > 100)
|
|
|
|
|
{
|
|
|
|
|
seconds = [timeout floatValue] / 1000.0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
seconds = 30.0;
|
|
|
|
|
}
|
|
|
|
|
finishBy = [NSDate dateWithTimeIntervalSinceNow: seconds];
|
|
|
|
|
appPath = [service objectForKey: @"ServicePath"];
|
|
|
|
|
userData = [service objectForKey: @"NSUserData"];
|
|
|
|
|
message = [service objectForKey: @"NSMessage"];
|
|
|
|
|
selName = [message stringByAppendingString: @":userData:error:"];
|
|
|
|
|
|
|
|
|
|
/*
|
2001-05-04 04:11:53 +00:00
|
|
|
|
* Locate the service provider ... this will be a proxy to the remote
|
|
|
|
|
* object, or a local object (if we provide the service ourself)
|
1998-12-01 20:54:23 +00:00
|
|
|
|
*/
|
1999-01-07 15:52:42 +00:00
|
|
|
|
provider = GSContactApplication(appPath, port, finishBy);
|
|
|
|
|
if (provider == nil)
|
1998-12-14 15:59:51 +00:00
|
|
|
|
{
|
|
|
|
|
NSRunAlertPanel(nil,
|
2002-06-08 18:11:17 +00:00
|
|
|
|
@"Failed to contact service provider for '%@'",
|
|
|
|
|
@"Continue", nil, nil,
|
|
|
|
|
serviceItem);
|
1998-12-14 15:59:51 +00:00
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-04 04:11:53 +00:00
|
|
|
|
/*
|
|
|
|
|
* If the service provider is a remote object, we can set timeouts on
|
|
|
|
|
* the NSConnection so we don't hang waiting for it to reply.
|
|
|
|
|
*/
|
|
|
|
|
if ([provider isProxy] == YES)
|
|
|
|
|
{
|
|
|
|
|
NSConnection *connection;
|
1998-12-01 20:54:23 +00:00
|
|
|
|
|
2001-05-04 04:11:53 +00:00
|
|
|
|
connection = [(NSDistantObject*)provider connectionForProxy];
|
|
|
|
|
seconds = [finishBy timeIntervalSinceNow];
|
|
|
|
|
[connection setRequestTimeout: seconds];
|
|
|
|
|
[connection setReplyTimeout: seconds];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* At last, we ask for the service to be performed.
|
|
|
|
|
*/
|
1998-12-01 20:54:23 +00:00
|
|
|
|
NS_DURING
|
|
|
|
|
{
|
1999-04-08 20:42:46 +00:00
|
|
|
|
[provider performService: selName
|
|
|
|
|
withPasteboard: pboard
|
|
|
|
|
userData: userData
|
|
|
|
|
error: &error];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
NS_HANDLER
|
|
|
|
|
{
|
1998-12-14 15:59:51 +00:00
|
|
|
|
error = [NSString stringWithFormat: @"%@", [localException reason]];
|
1998-12-01 20:54:23 +00:00
|
|
|
|
}
|
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
|
|
if (error != nil)
|
|
|
|
|
{
|
1998-12-14 15:59:51 +00:00
|
|
|
|
NSRunAlertPanel(nil,
|
2002-06-08 18:11:17 +00:00
|
|
|
|
@"Failed to contact service provider for '%@': %@",
|
|
|
|
|
@"Continue", nil, nil,
|
|
|
|
|
serviceItem, error);
|
1998-12-01 20:54:23 +00:00
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
NSSetShowsServicesMenuItem(NSString *name, BOOL enabled)
|
|
|
|
|
{
|
|
|
|
|
|
1998-12-10 21:14:52 +00:00
|
|
|
|
return [[GSServicesManager manager] setShowsServicesMenuItem: name
|
1998-12-01 20:54:23 +00:00
|
|
|
|
to: enabled];
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-03 13:27:08 +00:00
|
|
|
|
BOOL
|
1998-12-09 01:26:37 +00:00
|
|
|
|
NSShowsServicesMenuItem(NSString * name)
|
1998-12-03 13:27:08 +00:00
|
|
|
|
{
|
1998-12-10 21:14:52 +00:00
|
|
|
|
return [[GSServicesManager manager] showsServicesMenuItem: name];
|
1998-12-03 13:27:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-14 22:39:06 +00:00
|
|
|
|
void
|
|
|
|
|
NSUpdateDynamicServices(void)
|
|
|
|
|
{
|
|
|
|
|
[[GSServicesManager manager] loadServices];
|
|
|
|
|
}
|