From beac7e7aeab0c37a8844e6853a2e3edf98d64700 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 14 Sep 2007 21:59:00 +0000 Subject: [PATCH] Monotone-Parent: 17441bc6502df80d7fa89d2f1beee98ac6e2c5d9 Monotone-Revision: c4c95e670daa9c22e838239469a51f3d23b84ab0 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-09-14T21:59:00 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 11 +++++ SoObjects/SOGo/SOGoObject.h | 9 +++- SoObjects/SOGo/SOGoObject.m | 92 ++++++++++++++++++++++++++++++++++++- 3 files changed, 109 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3556ea464..8ce905a88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-09-14 Wolfgang Sourdeau + + * SoObjects/SOGo/SOGoObject.m ([SOGoObject -labelForKey:key]): new + method that returns translated strings for controller bundles + (same as what UIxComponent does for view bundles). + ([SOGoObject -pathArrayToSOGoObject]): new method that returns + the real path to a subscribed folder (if subscribed). + ([SOGoObject +globallyUniqueObjectId]): move method from SOGoFolder. + ([SOGoObject -globallyUniqueObjectId]): new instance method + calling its class equivalent. + 2007-09-12 Wolfgang Sourdeau * UI/MainUI/SOGoRootPage.m ([SOGoRootPage -defaultAction]): test diff --git a/SoObjects/SOGo/SOGoObject.h b/SoObjects/SOGo/SOGoObject.h index 67142bfef..5404508a0 100644 --- a/SoObjects/SOGo/SOGoObject.h +++ b/SoObjects/SOGo/SOGoObject.h @@ -61,6 +61,9 @@ id container; } ++ (NSString *) globallyUniqueObjectId; +- (NSString *) globallyUniqueObjectId; + + (id) objectWithName: (NSString *)_name inContainer:(id)_container; - (id) initWithName: (NSString *) _name inContainer:(id)_container; @@ -70,11 +73,15 @@ - (NSString *) nameInContainer; - (id) container; +- (NSArray *) pathArrayToSOGoObject; + - (NSURL *) davURL; - (NSURL *) soURL; - (NSURL *) soURLToBaseContainerForUser: (NSString *) uid; - (NSURL *) soURLToBaseContainerForCurrentUser; +- (NSString *) labelForKey: (NSString *) key; + /* ownership */ - (void) setOwner: (NSString *) newOwner; @@ -100,7 +107,7 @@ /* etag support */ -- (NSException *)matchesRequestConditionInContext:(id)_ctx; +- (NSException *) matchesRequestConditionInContext:(id)_ctx; /* acls */ diff --git a/SoObjects/SOGo/SOGoObject.m b/SoObjects/SOGo/SOGoObject.m index 280211e53..31a6b6ce6 100644 --- a/SoObjects/SOGo/SOGoObject.m +++ b/SoObjects/SOGo/SOGoObject.m @@ -24,6 +24,9 @@ Please use gnustep-base instead. #endif +#import + +#import #import #import #import @@ -35,6 +38,7 @@ #import #import #import +#import #import #import #import @@ -52,6 +56,7 @@ #import "SOGoDAVRendererTypes.h" #import "NSArray+Utilities.h" +#import "NSDictionary+Utilities.h" #import "NSString+Utilities.h" #import "SOGoObject.h" @@ -179,6 +184,35 @@ static BOOL kontactGroupDAV = YES; // asDefaultForPermission: SoPerm_WebDAVAccess]; } ++ (NSString *) globallyUniqueObjectId +{ + /* + 4C08AE1A-A808-11D8-AC5A-000393BBAFF6 + SOGo-Web-28273-18283-288182 + printf( "%x", *(int *) &f); + */ + static int pid = 0; + static int sequence = 0; + static float rndm = 0; + float f; + + if (pid == 0) + { /* break if we fork ;-) */ + pid = getpid(); + rndm = random(); + } + sequence++; + f = [[NSDate date] timeIntervalSince1970]; + + return [NSString stringWithFormat:@"%0X-%0X-%0X-%0X", + pid, (int) f, sequence++, random]; +} + +- (NSString *) globallyUniqueObjectId +{ + return [[self class] globallyUniqueObjectId]; +} + + (void) _fillDictionary: (NSMutableDictionary *) dictionary withDAVMethods: (NSString *) firstMethod, ... { @@ -447,6 +481,30 @@ static BOOL kontactGroupDAV = YES; return container; } +- (NSArray *) pathArrayToSOGoObject +{ + NSMutableArray *realPathArray; + NSString *objectName; + NSArray *objectDescription; + + realPathArray + = [NSMutableArray arrayWithArray: [self pathArrayToSoObject]]; + if ([realPathArray count] > 2) + { + objectName = [realPathArray objectAtIndex: 2]; + objectDescription = [objectName componentsSeparatedByString: @"_"]; + if ([objectDescription count] > 1) + { + [realPathArray replaceObjectAtIndex: 0 + withObject: [objectDescription objectAtIndex: 0]]; + [realPathArray replaceObjectAtIndex: 2 + withObject: [objectDescription objectAtIndex: 1]]; + } + } + + return realPathArray; +} + /* ownership */ - (void) setOwner: (NSString *) newOwner @@ -493,14 +551,16 @@ static BOOL kontactGroupDAV = YES; /* looking up shared objects */ -- (SOGoUserFolder *)lookupUserFolder { +- (SOGoUserFolder *) lookupUserFolder +{ if (![container respondsToSelector:_cmd]) return nil; return [container lookupUserFolder]; } -- (SOGoGroupsFolder *)lookupGroupsFolder { +- (SOGoGroupsFolder *) lookupGroupsFolder +{ return [[self lookupUserFolder] lookupGroupsFolder]; } @@ -905,6 +965,34 @@ static BOOL kontactGroupDAV = YES; return nil; } +- (NSString *) labelForKey: (NSString *) key +{ + NSString *userLanguage, *label; + NSArray *paths; + NSBundle *bundle; + NSDictionary *strings; + + bundle = [NSBundle bundleForClass: [self class]]; + if (!bundle) + bundle = [NSBundle mainBundle]; + + userLanguage = [[context activeUser] language]; + paths = [bundle pathsForResourcesOfType: @"strings" + inDirectory: [NSString stringWithFormat: @"%@.lproj", userLanguage] + forLocalization: userLanguage]; + if ([paths count] > 0) + { + strings = [NSDictionary dictionaryFromStringsFile: [paths objectAtIndex: 0]]; + label = [strings objectForKey: key]; + if (!label) + label = key; + } + else + label = key; + + return label; +} + /* description */ - (void)appendAttributesToDescription:(NSMutableString *)_ms {