diff --git a/ChangeLog b/ChangeLog index 4f0b3a3e1..7a10a3f2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,26 @@ 2009-12-01 Wolfgang Sourdeau + * UI/PreferencesUI/UIxPreferences.m (-categoryList): simplified + method by returning only the array of defined categories from the + user defaults or those defined in the Localizable.strings and sort + the resulting array. + (-categoryColor): new accessor that return the color associated + with the value in the "category" ivar, if not exists, we return + the default from SOGoCalendarDefaultCategoryColor. + (-setCategoriesValue): simplified method since we now receive a + dictionary. The dictionary is now transferred as a JSON object + rather than a property list. + + * SoObjects/SOGo/SOGoUserDefaults.m + (-setCalendarCategoriesColors:, -calendarCategoriesColors): + SOGoCalendarCategoriesColors is now a dictionary. The values are + migrated in _migrateCalendarCategories. + + * SoObjects/SOGo/SOGoDomainDefaults.m + (-calendarDefaultCategoryColor): new accessor for the domain + default SOGoCalendarDefaultCategoryColor. + * SoObjects/SOGo/SOGoDefaultsSource.m (-boolForKey:) (-floatForKey:, -integerForKey:, -dataForKey:, -stringForKey:) (-dictionaryForKey:, -arrayForKey:, -stringArrayForKey:): added diff --git a/SoObjects/SOGo/SOGoSystemDefaults.m b/SoObjects/SOGo/SOGoSystemDefaults.m index 833066e34..f53b41c93 100644 --- a/SoObjects/SOGo/SOGoSystemDefaults.m +++ b/SoObjects/SOGo/SOGoSystemDefaults.m @@ -33,7 +33,6 @@ #import "NSDictionary+Utilities.h" #import "SOGoStartupLogger.h" -#define NEEDS_DEFAULTS_SOURCE_INTERNAL 1 #import "SOGoSystemDefaults.h" @implementation SOGoSystemDefaults diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 45807ab49..f09b6fd80 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -125,8 +125,8 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (void) setCalendarCategories: (NSArray *) newValues; - (NSArray *) calendarCategories; -- (void) setCalendarCategoriesColors: (NSArray *) newValues; -- (NSArray *) calendarCategoriesColors; +- (void) setCalendarCategoriesColors: (NSDictionary *) newValues; +- (NSDictionary *) calendarCategoriesColors; - (void) setCalendarShouldDisplayWeekend: (BOOL) newValue; - (BOOL) calendarShouldDisplayWeekend; diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index 13d5812cb..d982ee910 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -26,7 +26,6 @@ #import #import "NSString+Utilities.h" -#define NEEDS_DEFAULTS_SOURCE_INTERNAL 1 #import "SOGoDomainDefaults.h" #import "SOGoSystemDefaults.h" #import "SOGoUserProfile.h" @@ -147,6 +146,33 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return rc; } +- (BOOL) _migrateCalendarCategories +{ + NSArray *categories, *colors; + NSDictionary *newColors; + BOOL rc; + + colors = [source objectForKey: @"SOGoCalendarCategoriesColors"]; + if ([colors isKindOfClass: [NSArray class]]) + { + categories = [source objectForKey: @"SOGoCalendarCategories"]; + if ([categories count] == [colors count]) + { + newColors = [NSDictionary dictionaryWithObjects: colors + forKeys: categories]; + [source setObject: newColors + forKey: @"SOGoCalendarCategoriesColors"]; + } + else + [source removeObjectForKey: @"SOGoCalendarCategoriesColors"]; + rc = YES; + } + else + rc = NO; + + return rc; +} + - (BOOL) migrate { static NSDictionary *migratedKeys = nil; @@ -185,6 +211,7 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; not be invoked in the case where rc = YES. */ return ([self _migrateLastModule] | [self _migrateSignature] + | [self _migrateCalendarCategories] | [self migrateOldDefaultsWithDictionary: migratedKeys] | [super migrate]); } @@ -490,14 +517,14 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return [self stringArrayForKey: @"SOGoCalendarCategories"]; } -- (void) setCalendarCategoriesColors: (NSArray *) newValues +- (void) setCalendarCategoriesColors: (NSDictionary *) newValues { [self setObject: newValues forKey: @"SOGoCalendarCategoriesColors"]; } -- (NSArray *) calendarCategoriesColors +- (NSDictionary *) calendarCategoriesColors { - return [self stringArrayForKey: @"SOGoCalendarCategoriesColors"]; + return [self dictionaryForKey: @"SOGoCalendarCategoriesColors"]; } - (void) setCalendarShouldDisplayWeekend: (BOOL) newValue diff --git a/UI/PreferencesUI/UIxPreferences.h b/UI/PreferencesUI/UIxPreferences.h index 3e3100521..326f02bb9 100644 --- a/UI/PreferencesUI/UIxPreferences.h +++ b/UI/PreferencesUI/UIxPreferences.h @@ -35,6 +35,10 @@ id item; SOGoUser *user; NSDictionary *locale; + NSArray *calendarCategories; + NSDictionary *calendarCategoriesColors; + NSString *category; + NSString *defaultCategoryColor; SOGoUserDefaults *userDefaults; NSCalendarDate *today; NSArray *daysOfWeek, *daysBetweenResponsesList; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 0fbabb36e..5cda8e49b 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -33,6 +33,7 @@ #import #import +#import #import #import #import @@ -70,6 +71,11 @@ //locale = [context valueForKey: @"locale"]; language = [userDefaults language]; + calendarCategories = nil; + calendarCategoriesColors = nil; + defaultCategoryColor = nil; + category = nil; + ASSIGN (locale, [[WOApplication application] localeForLanguageNamed: language]); ASSIGN (daysOfWeek, [locale objectForKey: NSWeekDayNameArray]); @@ -108,6 +114,10 @@ [user release]; [userDefaults release]; [vacationOptions release]; + [calendarCategories release]; + [calendarCategoriesColors release]; + [defaultCategoryColor release]; + [category release]; [forwardOptions release]; [daysOfWeek release]; [locale release]; @@ -941,44 +951,60 @@ return [self labelForKey: @"Color"]; } -- (NSArray *) categories +- (NSArray *) languageCategories { - NSDictionary *element; - NSArray *k, *v, *names, *colors; - NSMutableArray *categories, *newColors; - int i, count; + NSArray *categoryLabels; - names = [userDefaults calendarCategories]; - if (names) - colors = [userDefaults calendarCategoriesColors]; - else - { - names = [[self labelForKey: @"category_labels"] - componentsSeparatedByString: @","]; - count = [names count]; - newColors = [NSMutableArray arrayWithCapacity: count]; - for (i = 0; i < count; i++) - [newColors addObject: @"#F0F0F0"]; - colors = newColors; - } + categoryLabels = [[self labelForKey: @"category_labels"] + componentsSeparatedByString: @","]; - categories = [NSMutableArray array]; - k = [NSArray arrayWithObjects: @"name", @"color", nil]; - - count = [names count]; - for (i = 0; i < count; i++) - { - v = [NSArray arrayWithObjects: [names objectAtIndex: i], - [colors objectAtIndex: i], nil]; - - element = [NSDictionary dictionaryWithObjects: v - forKeys: k]; - [categories addObject: element]; - } - - return categories; + return [categoryLabels trimmedComponents]; } +- (NSArray *) categoryList +{ + if (!calendarCategories) + { + ASSIGN (calendarCategories, [userDefaults calendarCategories]); + if (!calendarCategories) + ASSIGN (calendarCategories, [self languageCategories]); + } + + return [calendarCategories + sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; +} + +- (void) setCategory: (NSString *) newCategory +{ + ASSIGN (category, newCategory); +} + +- (NSString *) category +{ + return category; +} + +- (NSString *) categoryColor +{ + SOGoDomainDefaults *dd; + NSString *categoryColor; + + if (!calendarCategoriesColors) + ASSIGN (calendarCategoriesColors, [userDefaults calendarCategoriesColors]); + + categoryColor = [calendarCategoriesColors objectForKey: category]; + if (!categoryColor) + { + if (!defaultCategoryColor) + { + dd = [[context activeUser] domainDefaults]; + ASSIGN (defaultCategoryColor, [dd calendarDefaultCategoryColor]); + } + categoryColor = defaultCategoryColor; + } + + return categoryColor; +} - (NSString *) categoriesValue { @@ -987,26 +1013,13 @@ - (void) setCategoriesValue: (NSString *) value { - NSData *data; - NSString *error; - NSPropertyListFormat format; - NSArray *plist; + NSDictionary *newColors; - data = [value dataUsingEncoding: NSUTF8StringEncoding]; - plist = [NSPropertyListSerialization propertyListFromData: data - mutabilityOption: NSPropertyListImmutable - format: &format - errorDescription: &error]; - if (!plist) + newColors = [NSMutableDictionary dictionaryWithJSONString: value]; + if (newColors) { - [self errorWithFormat: @"an error occured during deserialization" - @" of categories: %@", error]; - [error release]; - } - else - { - [userDefaults setCalendarCategories: [plist objectAtIndex: 0]]; - [userDefaults setCalendarCategoriesColors: [plist objectAtIndex: 1]]; + [userDefaults setCalendarCategories: [newColors allKeys]]; + [userDefaults setCalendarCategoriesColors: newColors]; } } diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index ec06a0111..bf57f571a 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -108,12 +108,12 @@ > - +
diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index cda63c42a..be35d56e1 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -245,21 +245,16 @@ function onCategoryDelete (e) { function serializeCategories (e) { var r = $$("TABLE#categoriesList tbody tr"); - var names = "("; - var colors = "("; + var values = []; for (var i = 0; i < r.length; i++) { var tds = r[i].childElements (); var name = $(tds.first ()).innerHTML; var color = $(tds.last ().childElements ().first ()).showColor; - - names += "\"" + name + "\", "; - colors += "\"" + color + "\", "; + values.push("\"" + name + "\": \"" + color + "\""); } - names = names.substr (0, names.length - 1) + ")"; - colors = colors.substr (0, colors.length - 1) + ")"; - $("categoriesValue").value = "(" + names + ", " + colors + ")"; + $("categoriesValue").value = "{ " + values.join(",\n") + "}"; } function resetCategoriesColors (e) {