From bb2373ebe69b9c6ee095a27ed08fa7e6c38c3301 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 3 Feb 2011 16:12:22 +0000 Subject: [PATCH] Monotone-Parent: 659def76b8868bdc540986987d61b39410737054 Monotone-Revision: 6eed7e248c203a0103250e46033fc47b929ee536 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-02-03T16:12:22 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 6 ++ Main/SOGo.h | 2 - Main/SOGo.m | 83 +------------------ SoObjects/SOGo/GNUmakefile | 4 +- SoObjects/SOGo/SOGoUser.m | 7 +- SoObjects/SOGo/WOResourceManager+SOGo.h | 34 ++++++++ SoObjects/SOGo/WOResourceManager+SOGo.m | 106 ++++++++++++++++++++++++ UI/MailerUI/UIxMailEditor.m | 21 +++-- UI/PreferencesUI/UIxPreferences.m | 4 +- UI/Scheduler/UIxCalDayTable.m | 5 +- UI/Scheduler/UIxCalMonthView.m | 9 +- UI/Scheduler/UIxComponentEditor.m | 3 +- 12 files changed, 176 insertions(+), 108 deletions(-) create mode 100644 SoObjects/SOGo/WOResourceManager+SOGo.h create mode 100644 SoObjects/SOGo/WOResourceManager+SOGo.m diff --git a/ChangeLog b/ChangeLog index f593410b1..7b5146e07 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-02-03 Wolfgang Sourdeau + + * SoObjects/SOGo/WOResourceManager+SOGo.m: new category module + defining methods useful to the vanilla and OpenChange frontends. + (-localeForLanguageNamed:): method moved from SOGo.m. + 2011-02-01 Ludovic Marcotte * SoObjects/SOGo/NSString+Utilities.h,m: Fixed diff --git a/Main/SOGo.h b/Main/SOGo.h index c6ed757d8..02bce3c4c 100644 --- a/Main/SOGo.h +++ b/Main/SOGo.h @@ -33,12 +33,10 @@ @interface SOGo : SoApplication { - NSMutableDictionary *localeLUT; SOGoCache *cache; } - (NSDictionary *) currentLocaleConsideringLanguages:(NSArray *)_langs; -- (NSDictionary *) localeForLanguageNamed:(NSString *)_name; - (NSString *) davURLAsString; @end diff --git a/Main/SOGo.m b/Main/SOGo.m index 04f16b262..3aa0b18d8 100644 --- a/Main/SOGo.m +++ b/Main/SOGo.m @@ -60,6 +60,7 @@ #import #import #import +#import #import #import "NSException+Stacktrace.h" @@ -125,9 +126,6 @@ static BOOL debugLeaks; [$(@"SOGoContentObject") soClass]; [$(@"SOGoFolder") soClass]; - /* setup locale cache */ - localeLUT = [[NSMutableDictionary alloc] initWithCapacity:2]; - /* load products */ [[SOGoProductLoader productLoader] loadAllProducts]; @@ -140,12 +138,6 @@ static BOOL debugLeaks; return self; } -- (void) dealloc -{ - [localeLUT release]; - [super dealloc]; -} - #warning the following methods should be replaced with helpers in GCSSpecialQueries - (NSString *) _sqlScriptForTable: (NSString *) tableName withType: (NSString *) tableType @@ -497,86 +489,17 @@ static BOOL debugLeaks; lname = [enumerator nextObject]; while (lname && !locale) { - locale = [self localeForLanguageNamed: lname]; + locale = [[self resourceManager] localeForLanguageNamed: lname]; lname = [enumerator nextObject]; } if (!locale) - locale = [self localeForLanguageNamed: @"English"]; + locale = [[self resourceManager] localeForLanguageNamed: @"English"]; /* no appropriate language, fallback to default */ return locale; } -- (NSString *) pathToLocaleForLanguageNamed: (NSString *) _name -{ - static Class MainProduct = Nil; - NSString *lpath; - - lpath = [[self resourceManager] pathForResourceNamed: @"Locale" - inFramework: nil - languages: [NSArray arrayWithObject:_name]]; - if (![lpath length]) - { - if (!MainProduct) - { - MainProduct = $(@"MainUIProduct"); - if (!MainProduct) - [self errorWithFormat: @"did not find MainUIProduct class!"]; - } - - lpath = [(id) MainProduct pathToLocaleForLanguageNamed: _name]; - if (![lpath length]) - lpath = nil; - } - - return lpath; -} - -- (NSDictionary *) localeForLanguageNamed: (NSString *) _name -{ - NSString *lpath; - id data; - NSDictionary *locale; - - locale = nil; - if ([_name length] > 0) - { - locale = [localeLUT objectForKey: _name]; - if (!locale) - { - lpath = [self pathToLocaleForLanguageNamed:_name]; - if (lpath) - { - data = [NSData dataWithContentsOfFile: lpath]; - if (data) - { - data = [[[NSString alloc] initWithData: data - encoding: NSUTF8StringEncoding] autorelease]; - locale = [data propertyList]; - if (locale) - [localeLUT setObject: locale forKey: _name]; - else - [self logWithFormat:@"%s couldn't load locale with name:%@", - __PRETTY_FUNCTION__, - _name]; - } - else - [self logWithFormat:@"%s didn't find locale with name: %@", - __PRETTY_FUNCTION__, - _name]; - } - else - [self errorWithFormat:@"did not find locale for language: %@", _name]; - } - } - else - [self errorWithFormat:@"%s: name parameter must not be nil!", - __PRETTY_FUNCTION__]; - - return locale; -} - - (NSURL *) _urlPreferringParticle: (NSString *) expected overThisOne: (NSString *) possible { diff --git a/SoObjects/SOGo/GNUmakefile b/SoObjects/SOGo/GNUmakefile index dee5233a6..c76b79c47 100644 --- a/SoObjects/SOGo/GNUmakefile +++ b/SoObjects/SOGo/GNUmakefile @@ -46,7 +46,7 @@ SOGo_HEADER_FILES = \ NSURL+DAV.h \ \ SOGoAuthenticator.h \ - SOGoSession.h \ + SOGoSession.h \ SOGoCASSession.h \ SOGoDAVAuthenticator.h \ SOGoProxyAuthenticator.h \ @@ -60,6 +60,7 @@ SOGo_HEADER_FILES = \ DOMNode+SOGo.h \ \ WORequest+SOGo.h \ + WOResourceManager+SOGo.h \ WOResponse+SOGo.h \ WOContext+SOGo.h @@ -123,6 +124,7 @@ SOGo_OBJC_FILES = \ DOMNode+SOGo.m \ \ WORequest+SOGo.m \ + WOResourceManager+SOGo.m \ WOResponse+SOGo.m \ WOContext+SOGo.m diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 965749b52..26097fc62 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -50,8 +50,7 @@ #import "SOGoUserManager.h" #import "SOGoUserProfile.h" #import "SOGoUserSettings.h" - -#import "../../Main/SOGo.h" +#import "WOResourceManager+SOGo.h" #import "SOGoUser.h" @@ -283,12 +282,14 @@ NSString *format; SOGoUserDefaults *ud; NSDictionary *locale; + WOResourceManager *resMgr; dateFormatter = [SOGoDateFormatter new]; [dateFormatter autorelease]; ud = [self userDefaults]; - locale = [[WOApplication application] localeForLanguageNamed: [ud language]]; + resMgr = [[WOApplication application] resourceManager]; + locale = [resMgr localeForLanguageNamed: [ud language]]; [dateFormatter setLocale: locale]; format = [ud shortDateFormat]; if (format) diff --git a/SoObjects/SOGo/WOResourceManager+SOGo.h b/SoObjects/SOGo/WOResourceManager+SOGo.h new file mode 100644 index 000000000..c0c4bef34 --- /dev/null +++ b/SoObjects/SOGo/WOResourceManager+SOGo.h @@ -0,0 +1,34 @@ +/* WOResourceManager+SOGo.h - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef WORESOURCEMANAGER_SOGO_H +#define WORESOURCEMANAGER_SOGO_H + +#import + +@interface WOResourceManager (SOGoExtensions) + +- (NSDictionary *) localeForLanguageNamed: (NSString *) _name; + +@end + +#endif /* WORESOURCEMANAGER_SOGO_H */ diff --git a/SoObjects/SOGo/WOResourceManager+SOGo.m b/SoObjects/SOGo/WOResourceManager+SOGo.m new file mode 100644 index 000000000..79a112785 --- /dev/null +++ b/SoObjects/SOGo/WOResourceManager+SOGo.m @@ -0,0 +1,106 @@ +/* WOResourceManager+SOGo.m - this file is part of SOGo + * + * Copyright (C) 2011 Inverse inc + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import + +#import "WOResourceManager+SOGo.h" + +@implementation WOResourceManager (SOGoExtensions) + +- (NSString *) pathToLocaleForLanguageNamed: (NSString *) _name +{ + static Class MainProduct = Nil; + NSString *lpath; + + lpath = [self pathForResourceNamed: @"Locale" + inFramework: nil + languages: [NSArray arrayWithObject:_name]]; + if (![lpath length]) + { + if (!MainProduct) + { + MainProduct = NSClassFromString (@"MainUIProduct"); + if (!MainProduct) + [self errorWithFormat: @"did not find MainUIProduct class!"]; + } + + lpath = [(id) MainProduct performSelector: NSSelectorFromString (@"pathToLocaleForLanguageNamed:") + withObject: _name]; + if (![lpath length]) + lpath = nil; + } + + return lpath; +} + +- (NSDictionary *) localeForLanguageNamed: (NSString *) _name +{ + NSString *lpath; + id data; + NSDictionary *locale; + static NSMutableDictionary *localeLUT = nil; + + locale = nil; + if ([_name length] > 0) + { + if (!localeLUT) + localeLUT = [NSMutableDictionary new]; + + locale = [localeLUT objectForKey: _name]; + if (!locale) + { + lpath = [self pathToLocaleForLanguageNamed:_name]; + if (lpath) + { + data = [NSData dataWithContentsOfFile: lpath]; + if (data) + { + data = [[[NSString alloc] initWithData: data + encoding: NSUTF8StringEncoding] autorelease]; + locale = [data propertyList]; + if (locale) + [localeLUT setObject: locale forKey: _name]; + else + [self logWithFormat:@"%s couldn't load locale with name:%@", + __PRETTY_FUNCTION__, + _name]; + } + else + [self logWithFormat:@"%s didn't find locale with name: %@", + __PRETTY_FUNCTION__, + _name]; + } + else + [self errorWithFormat:@"did not find locale for language: %@", _name]; + } + } + else + [self errorWithFormat:@"%s: name parameter must not be nil!", + __PRETTY_FUNCTION__]; + + return locale; +} + +@end diff --git a/UI/MailerUI/UIxMailEditor.m b/UI/MailerUI/UIxMailEditor.m index f1a25153b..66c8dd0fa 100644 --- a/UI/MailerUI/UIxMailEditor.m +++ b/UI/MailerUI/UIxMailEditor.m @@ -47,17 +47,16 @@ #import #import -#import -#import -#import -#import -#import -#import -#import +#import +#import +#import +#import +#import +#import +#import +#import #import -#import "../../Main/SOGo.h" - /* UIxMailEditor @@ -210,8 +209,8 @@ static NSArray *infoKeys = nil; NSDictionary *locale; ud = [[context activeUser] userDefaults]; - locale = [[WOApplication application] - localeForLanguageNamed: [ud language]]; + locale = [[self resourceManager] + localeForLanguageNamed: [ud language]]; // WARNING : NSLocaleCode is not defined in return [locale objectForKey: @"NSLocaleCode"]; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 555b9228d..dadf9792e 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -40,8 +40,8 @@ #import #import #import +#import #import -#import "../../Main/SOGo.h" #import "UIxPreferences.h" @@ -77,7 +77,7 @@ category = nil; ASSIGN (locale, - [[WOApplication application] localeForLanguageNamed: language]); + [[self resourceManager] localeForLanguageNamed: language]); ASSIGN (daysOfWeek, [locale objectForKey: NSWeekDayNameArray]); dd = [user domainDefaults]; diff --git a/UI/Scheduler/UIxCalDayTable.m b/UI/Scheduler/UIxCalDayTable.m index 2082984b0..9030bfcc5 100644 --- a/UI/Scheduler/UIxCalDayTable.m +++ b/UI/Scheduler/UIxCalDayTable.m @@ -35,8 +35,7 @@ #import #import #import - -#import "../../Main/SOGo.h" +#import #import "UIxCalDayTable.h" @@ -57,7 +56,7 @@ ud = [user userDefaults]; ASSIGN (timeFormat, [ud timeFormat]); language = [ud language]; - locale = [[WOApplication application] localeForLanguageNamed: language]; + locale = [[self resourceManager] localeForLanguageNamed: language]; daysToDisplay = nil; hoursToDisplay = nil; diff --git a/UI/Scheduler/UIxCalMonthView.m b/UI/Scheduler/UIxCalMonthView.m index 310295f4f..97cbbeee0 100644 --- a/UI/Scheduler/UIxCalMonthView.m +++ b/UI/Scheduler/UIxCalMonthView.m @@ -30,10 +30,9 @@ #import #import -#import -#import - -#import "../../Main/SOGo.h" +#import +#import +#import #import "UIxCalMonthView.h" @@ -52,7 +51,7 @@ // dateFormatter = [[SOGoDateFormatter alloc] // initWithLocale: [self locale]]; ud = [[context activeUser] userDefaults]; - locale = [[WOApplication application] localeForLanguageNamed: [ud language]]; + locale = [[self resourceManager] localeForLanguageNamed: [ud language]]; dayNames = [locale objectForKey: NSWeekDayNameArray]; [dayNames retain]; monthNames = [locale objectForKey: NSMonthNameArray]; diff --git a/UI/Scheduler/UIxComponentEditor.m b/UI/Scheduler/UIxComponentEditor.m index 3dac37db6..37930abd1 100644 --- a/UI/Scheduler/UIxComponentEditor.m +++ b/UI/Scheduler/UIxComponentEditor.m @@ -63,6 +63,7 @@ #import #import #import +#import #import "../../Main/SOGo.h" @@ -1869,7 +1870,7 @@ RANGE(2); NSDictionary *locale; ud = [[context activeUser] userDefaults]; - locale = [[WOApplication application] + locale = [[self resourceManager] localeForLanguageNamed: [ud language]]; date = [NSCalendarDate dateWithString: [self range2] calendarFormat: dateFormat