From: helge Date: Thu, 4 Aug 2005 17:25:43 +0000 (+0000) Subject: added EOKeyValueArchiving, some improvs X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac12d09009cd3b9e039c5846a82a233bbc8c7b07;p=sope added EOKeyValueArchiving, some improvs git-svn-id: http://svn.opengroupware.org/SOPE/trunk@971 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/NGExtensions/ChangeLog b/sope-core/NGExtensions/ChangeLog index 6b0ead9b..a769ff03 100644 --- a/sope-core/NGExtensions/ChangeLog +++ b/sope-core/NGExtensions/ChangeLog @@ -1,3 +1,9 @@ +2005-08-04 Helge Hess + + * NGRuleEngine.subproj/NGRuleModel.m: added EOKeyValueArchiving, added + method to load from such an archive, added -addRules: to add a set + of rules (v4.5.170) + 2005-08-04 Helge Hess * NGRuleEngine.subproj/NGRuleContext.m: added new method diff --git a/sope-core/NGExtensions/NGExtensions/NGRuleModel.h b/sope-core/NGExtensions/NGExtensions/NGRuleModel.h index 6ab65ad9..cefd1ce8 100644 --- a/sope-core/NGExtensions/NGExtensions/NGRuleModel.h +++ b/sope-core/NGExtensions/NGExtensions/NGRuleModel.h @@ -23,6 +23,7 @@ #define __NGRuleEngine_NGRuleModel_H__ #import +#include /* NGRuleModel @@ -33,10 +34,10 @@ // TODO: need some method to join two models (two allow one model being // configured as a default but still have fallback rules in another) -@class NSArray, NSMutableArray; +@class NSArray, NSMutableArray, NSURL; @class NGRule; -@interface NGRuleModel : NSObject +@interface NGRuleModel : NSObject < EOKeyValueArchiving > { NSMutableArray *rules; } @@ -49,6 +50,7 @@ - (id)initWithPropertyList:(id)_plist; - (id)initWithContentsOfFile:(NSString *)_path; - (id)initWithContentsOfUserDefault:(NSString *)_defaultName; +- (id)initWithKeyValueArchiveAtURL:(NSURL *)_url; /* accessors */ @@ -56,6 +58,7 @@ - (NSArray *)rules; - (void)addRule:(NGRule *)_rule; - (void)removeRule:(NGRule *)_rule; +- (void)addRules:(NSArray *)_rules; /* operations */ diff --git a/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleModel.m b/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleModel.m index bdb35e89..39e4e3ff 100644 --- a/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleModel.m +++ b/sope-core/NGExtensions/NGRuleEngine.subproj/NGRuleModel.m @@ -23,6 +23,7 @@ #include "NGRule.h" #include "NGRuleParser.h" #include "EOTrueQualifier.h" +#include #include #include "common.h" @@ -83,6 +84,23 @@ return [[[self class] ruleModelWithContentsOfUserDefault:_defName] retain]; } +- (id)initWithKeyValueArchiveAtURL:(NSURL *)_url { + EOKeyValueUnarchiver *unarchiver; + NSDictionary *plist; + + if ((plist = [NSDictionary dictionaryWithContentsOfURL:_url]) == nil) { + [self errorWithFormat:@"Could not read plist at URL: %@", _url]; + [self release]; + return nil; + } + + unarchiver = [[EOKeyValueUnarchiver alloc] initWithDictionary:plist]; + self = [self initWithKeyValueUnarchiver:unarchiver]; + [unarchiver release]; unarchiver = nil; + + return self; +} + - (void)dealloc { [self->rules release]; [super dealloc]; @@ -92,19 +110,25 @@ - (void)setRules:(NSArray *)_rules { [self->rules removeAllObjects]; - [self->rules addObjectsFromArray:_rules]; + if (_rules != nil) [self->rules addObjectsFromArray:_rules]; } - (NSArray *)rules { return [[self->rules shallowCopy] autorelease]; } - (void)addRule:(NGRule *)_rule { + if (_rule == nil) return; [self->rules addObject:_rule]; } - (void)removeRule:(NGRule *)_rule { + if (_rule == nil) return; [self->rules removeObject:_rule]; } +- (void)addRules:(NSArray *)_rules { + if (_rules != nil) [self->rules addObjectsFromArray:_rules]; +} + /* operations */ static int candidateSort(NGRule *rule1, NGRule *rule2, NGRuleModel *model) { @@ -162,4 +186,13 @@ static int candidateSort(NGRule *rule1, NGRule *rule2, NGRuleModel *model) { /* representations */ +/* key/value archiving */ + +- (id)initWithKeyValueUnarchiver:(EOKeyValueUnarchiver *)_unarchiver { + return [self initWithRules:[_unarchiver decodeObjectForKey:@"rules"]]; +} +- (void)encodeWithKeyValueArchiver:(EOKeyValueArchiver *)_archiver { + [_archiver encodeObject:[self rules] forKey:@"rules"]; +} + @end /* NGRuleModel */ diff --git a/sope-core/NGExtensions/Version b/sope-core/NGExtensions/Version index 5eee82ff..336b5832 100644 --- a/sope-core/NGExtensions/Version +++ b/sope-core/NGExtensions/Version @@ -1,6 +1,6 @@ # version -SUBMINOR_VERSION:=169 +SUBMINOR_VERSION:=170 # v4.3.115 requires libFoundation v1.0.59 # v4.2.72 requires libEOControl v4.2.39