mirror of
https://github.com/gnustep/libs-ec.git
synced 2025-02-15 16:11:01 +00:00
Make the alerter class to load configurable in AlertConfig.plist;
rearrange and expose a few methods in EcAlerter for easier subclassing. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36383 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8d65d2eb37
commit
6854d8e7d9
4 changed files with 91 additions and 8 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2013-03-18: Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
* EcAlerter.h
|
||||||
|
* EcAlerter.m:
|
||||||
|
Rearrange and expose a few methods so that subclasses can
|
||||||
|
easily inject alert rules.
|
||||||
|
* EcControl.m:
|
||||||
|
Allow dynamically loading the alerter class based on the
|
||||||
|
AlerterBundle key in AlertConfig.plist
|
||||||
|
|
||||||
2013-03-18 Richard Frith-Macdonald <rfm@gnu.org>
|
2013-03-18 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* EcProcess.h:
|
* EcProcess.h:
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
GSMimeSMTPClient *smtp;
|
GSMimeSMTPClient *smtp;
|
||||||
}
|
}
|
||||||
- (BOOL) configure: (NSNotification*)n;
|
- (BOOL) configure: (NSNotification*)n;
|
||||||
|
- (BOOL) configureWithDefaults: (NSDictionary*)c;
|
||||||
- (void) handleInfo: (NSString*)str;
|
- (void) handleInfo: (NSString*)str;
|
||||||
- (void) flushEmail;
|
- (void) flushEmail;
|
||||||
- (void) flushSms;
|
- (void) flushSms;
|
||||||
|
@ -56,5 +57,6 @@
|
||||||
- (void) mail: (NSMutableDictionary*)m to: (NSArray*)destinations;
|
- (void) mail: (NSMutableDictionary*)m to: (NSArray*)destinations;
|
||||||
- (void) sms: (NSMutableDictionary*)m to: (NSArray*)destinations;
|
- (void) sms: (NSMutableDictionary*)m to: (NSArray*)destinations;
|
||||||
- (void) timeout: (NSTimer*)t;
|
- (void) timeout: (NSTimer*)t;
|
||||||
|
- (BOOL) setRules: (NSArray*)ra;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
21
EcAlerter.m
21
EcAlerter.m
|
@ -252,21 +252,28 @@ replaceFields(NSDictionary *fields)
|
||||||
{
|
{
|
||||||
NSUserDefaults *d;
|
NSUserDefaults *d;
|
||||||
NSDictionary *c;
|
NSDictionary *c;
|
||||||
NSMutableArray *r;
|
|
||||||
unsigned int i;
|
|
||||||
|
|
||||||
d = [EcProc cmdDefaults];
|
d = [EcProc cmdDefaults];
|
||||||
c = [d dictionaryForKey: @"Alerter"];
|
c = [d dictionaryForKey: @"Alerter"];
|
||||||
|
return [self configureWithDefaults: c];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) configureWithDefaults: (NSDictionary*)c
|
||||||
|
{
|
||||||
ASSIGNCOPY(eHost, [c objectForKey: @"EmailHost"]);
|
ASSIGNCOPY(eHost, [c objectForKey: @"EmailHost"]);
|
||||||
ASSIGNCOPY(eFrom, [c objectForKey: @"EmailFrom"]);
|
ASSIGNCOPY(eFrom, [c objectForKey: @"EmailFrom"]);
|
||||||
ASSIGNCOPY(ePort, [c objectForKey: @"EmailPort"]);
|
ASSIGNCOPY(ePort, [c objectForKey: @"EmailPort"]);
|
||||||
|
return [self setRules: [c objectForKey: @"Rules"]];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cache a copy of the Rules with modifications to store information
|
* Cache a copy of the Rules with modifications to store information
|
||||||
* so we don't need to regenerate it every time we check a message.
|
* so we don't need to regenerate it every time we check a message.
|
||||||
*/
|
*/
|
||||||
r = [[[c objectForKey: @"Rules"] mutableCopy] autorelease];
|
- (BOOL)setRules: (NSArray*)ra
|
||||||
|
{
|
||||||
|
NSUInteger i = 0;
|
||||||
|
NSMutableArray *r = AUTORELEASE([ra mutableCopy]);
|
||||||
for (i = 0; i < [r count]; i++)
|
for (i = 0; i < [r count]; i++)
|
||||||
{
|
{
|
||||||
NSMutableDictionary *md;
|
NSMutableDictionary *md;
|
||||||
|
|
67
EcControl.m
67
EcControl.m
|
@ -2345,6 +2345,40 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
|
||||||
from: nil];
|
from: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (Class)_loadClassFromBundle: (NSString*)bundleName
|
||||||
|
{
|
||||||
|
NSString *path = nil;
|
||||||
|
Class c = Nil;
|
||||||
|
NSBundle *bundle = nil;
|
||||||
|
path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
|
||||||
|
NSLocalDomainMask, YES) lastObject];
|
||||||
|
path = [path stringByAppendingPathComponent: @"Bundles"];
|
||||||
|
path = [path stringByAppendingPathComponent: bundleName];
|
||||||
|
path = [path stringByAppendingPathExtension: @"bundle"];
|
||||||
|
bundle = [NSBundle bundleWithPath: path];
|
||||||
|
|
||||||
|
if (nil == bundle)
|
||||||
|
{
|
||||||
|
[[self cmdLogFile: logname] printf:
|
||||||
|
@"Couldn't load bundle '%@'", bundleName];
|
||||||
|
}
|
||||||
|
else if (Nil == (c = [bundle principalClass]))
|
||||||
|
{
|
||||||
|
[[self cmdLogFile: logname] printf:
|
||||||
|
@"Couldn't load principal class from %@"
|
||||||
|
@" at %@.", bundleName, path];
|
||||||
|
}
|
||||||
|
else if (NO == [c isSubclassOfClass: [EcAlerter class]])
|
||||||
|
{
|
||||||
|
[[self cmdLogFile: logname] printf:
|
||||||
|
@"%@ is not a subclass of EcAlerter",
|
||||||
|
NSStringFromClass(c)];
|
||||||
|
c = Nil;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL) update
|
- (BOOL) update
|
||||||
{
|
{
|
||||||
NSMutableDictionary *dict;
|
NSMutableDictionary *dict;
|
||||||
|
@ -2358,6 +2392,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
|
||||||
unsigned count;
|
unsigned count;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
BOOL changed = NO;
|
BOOL changed = NO;
|
||||||
|
Class alerterClass = Nil;
|
||||||
|
|
||||||
host = [NSHost currentHost];
|
host = [NSHost currentHost];
|
||||||
str = [NSHost controlWellKnownName];
|
str = [NSHost controlWellKnownName];
|
||||||
|
@ -2393,10 +2428,40 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
|
||||||
d, @"Alerter", nil];
|
d, @"Alerter", nil];
|
||||||
[[self cmdDefaults] setConfiguration: d];
|
[[self cmdDefaults] setConfiguration: d];
|
||||||
changed = YES;
|
changed = YES;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
NSString *alerterDef = [[d objectForKey: @"Alerter"]
|
||||||
|
objectForKey: @"AlerterBundle"];
|
||||||
|
if (nil == alerterDef)
|
||||||
|
{
|
||||||
|
alerterClass = [EcAlerter class];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// First, let's try whether this corresponds to
|
||||||
|
// a class we already loaded.
|
||||||
|
alerterClass = NSClassFromString(alerterDef);
|
||||||
|
if (Nil == alerterClass)
|
||||||
|
{
|
||||||
|
// We didn't link the class. Try to load it
|
||||||
|
// from a bundle.
|
||||||
|
alerterClass =
|
||||||
|
[self _loadClassFromBundle: alerterDef];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (Nil == alerterClass)
|
||||||
|
{
|
||||||
|
NSLog(@"Could not load alerter class '%@'", alerterDef);
|
||||||
|
}
|
||||||
|
else if ([alerter class] != alerterClass)
|
||||||
|
{
|
||||||
|
DESTROY(alerter);
|
||||||
|
}
|
||||||
|
|
||||||
if (nil == alerter)
|
if (nil == alerter)
|
||||||
{
|
{
|
||||||
alerter = [EcAlerter new];
|
alerter = [alerterClass new];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue