diff --git a/SoObjects/SOGo/SOGoDefaults.plist b/SoObjects/SOGo/SOGoDefaults.plist index 89c9f8374..f68ae9a40 100644 --- a/SoObjects/SOGo/SOGoDefaults.plist +++ b/SoObjects/SOGo/SOGoDefaults.plist @@ -99,28 +99,28 @@ SOGoCalendarCategories = ("Customer", "Calls", "Favorites", "Meeting", "Ideas", "Miscellaneous", "Birthday", "Anniversary", "Vacation", "Travel", "Projects", "Suppliers", "Gifts", "Clients", "Issues", "Business", "Holidays", "Personal", "Status", "Competition", "Follow up", "Public Holiday"); SOGoCalendarCategoriesColors = { - "Customer" = "#F0F0F0"; - "Calls" = "#F0F0F0"; - "Favorites" = "#F0F0F0"; - "Meeting" = "#F0F0F0"; - "Ideas" = "#F0F0F0"; - "Miscellaneous" = "#F0F0F0"; - "Birthday" = "#F0F0F0"; - "Anniversary" = "#F0F0F0"; - "Vacation" = "#F0F0F0"; - "Travel" = "#F0F0F0"; - "Projects" = "#F0F0F0"; - "Suppliers" = "#F0F0F0"; - "Gifts" = "#F0F0F0"; - "Clients" = "#F0F0F0"; - "Issues" = "#F0F0F0"; - "Business" = "#F0F0F0"; - "Holidays" = "#F0F0F0"; - "Personal" = "#F0F0F0"; - "Status" = "#F0F0F0"; - "Competition" = "#F0F0F0"; - "Follow up" = "#F0F0F0"; - "Public Holiday" = "#F0F0F0"; + "Customer" = "#CCCCCC"; + "Calls" = "#FFCC33"; + "Favorites" = "#CCCCCC"; + "Meeting" = "#CCCCCC"; + "Ideas" = "#CCCCCC"; + "Miscellaneous" = "#CCCCCC"; + "Birthday" = "#CCCCCC"; + "Anniversary" = "#CCCCCC"; + "Vacation" = "#CCCCCC"; + "Travel" = "#CCCCCC"; + "Projects" = "#CCCCCC"; + "Suppliers" = "#CCCCCC"; + "Gifts" = "#CCCCCC"; + "Clients" = "#CCCCCC"; + "Issues" = "#CCCCCC"; + "Business" = "#CCCCCC"; + "Holidays" = "#CCCCCC"; + "Personal" = "#CCCCCC"; + "Status" = "#CCCCCC"; + "Competition" = "#CCCCCC"; + "Follow up" = "#CCCCCC"; + "Public Holiday" = "#CCCCCC"; }; SOGoSubscriptionFolderFormat = "%{FolderName} (%{UserName} <%{Email}>)"; diff --git a/UI/PreferencesUI/UIxJSONPreferences.m b/UI/PreferencesUI/UIxJSONPreferences.m index cf8291dca..8d639ab88 100644 --- a/UI/PreferencesUI/UIxJSONPreferences.m +++ b/UI/PreferencesUI/UIxJSONPreferences.m @@ -1,6 +1,6 @@ /* UIxJSONPreferences.m - this file is part of SOGo * - * Copyright (C) 2007-2015 Inverse inc. + * Copyright (C) 2007-2016 Inverse inc. * * 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 @@ -24,6 +24,8 @@ #import #import +#import + #import #import #import @@ -41,12 +43,38 @@ static SoProduct *preferencesProduct = nil; @implementation UIxJSONPreferences +- (NSDictionary *) _localizedCategoryLabels +{ + NSArray *categoryLabels, *localizedCategoryLabels; + NSDictionary *labelsDictionary; + + labelsDictionary = nil; + localizedCategoryLabels = [[self labelForKey: @"calendar_category_labels" + withResourceManager: [preferencesProduct resourceManager]] + componentsSeparatedByString: @","]; + categoryLabels = [[[preferencesProduct resourceManager] + stringForKey: @"calendar_category_labels" + inTableNamed: nil + withDefaultValue: @"" + languages: [NSArray arrayWithObject: @"English"]] + componentsSeparatedByString: @","]; + + if ([localizedCategoryLabels count] == [categoryLabels count]) + labelsDictionary = [NSDictionary dictionaryWithObjects: localizedCategoryLabels + forKeys: categoryLabels]; + else + [self logWithFormat: @"ERROR: localizable strings calendar_category_labels is incorrect for language %@", + [[[context activeUser] userDefaults] language]]; + + return labelsDictionary; +} + - (WOResponse *) jsonDefaultsAction { NSMutableDictionary *values, *account; SOGoUserDefaults *defaults; NSMutableArray *accounts; - NSArray *categoryLabels; + NSDictionary *categoryLabels; NSDictionary *locale; if (!preferencesProduct) @@ -56,6 +84,7 @@ static SoProduct *preferencesProduct = nil; } defaults = [[context activeUser] userDefaults]; + categoryLabels = nil; // // Default General preferences @@ -112,28 +141,89 @@ static SoProduct *preferencesProduct = nil; [[defaults source] setObject: [defaults calendarDefaultReminder] forKey: @"SOGoCalendarDefaultReminder"]; // Populate default calendar categories, based on the user's preferred language - if (![defaults calendarCategories]) + if (![[defaults source] objectForKey: @"SOGoCalendarCategories"]) { - categoryLabels = [[[self labelForKey: @"calendar_category_labels" withResourceManager: [preferencesProduct resourceManager]] - componentsSeparatedByString: @","] - sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + NSArray *defaultCalendarCategories; - [defaults setCalendarCategories: categoryLabels]; + categoryLabels = [self _localizedCategoryLabels]; - // TODO: build categories colors dictionary with localized keys + if ((defaultCalendarCategories = [defaults calendarCategories])) + { + // Calendar categories are taken from SOGo's configuration or SOGoDefaults.plist + + NSMutableArray *filteredCalendarCategories; + NSString *label, *localizedLabel; + int count, max; + + max = [defaultCalendarCategories count]; + filteredCalendarCategories = [NSMutableArray arrayWithCapacity: max]; + + for (count = 0; count < max; count++) + { + label = [defaultCalendarCategories objectAtIndex: count]; + if ((localizedLabel = [categoryLabels objectForKey: label])) + { + [filteredCalendarCategories addObject: localizedLabel]; + } + } + + [defaults setCalendarCategories: filteredCalendarCategories]; + } + else + { + // Calendar categories are taken from localizable strings + + [defaults setCalendarCategories: [categoryLabels allValues]]; + } } - if (![defaults calendarCategoriesColors]) + if (![[defaults source] objectForKey: @"SOGoCalendarCategoriesColors"]) { - NSMutableDictionary *colors; - int i; + NSDictionary *defaultCalendarCategoriesColors; - categoryLabels = [defaults calendarCategories]; - colors = [NSMutableDictionary dictionaryWithCapacity: [categoryLabels count]]; + if (!categoryLabels) + categoryLabels = [self _localizedCategoryLabels]; - for (i = 0; i < [categoryLabels count]; i++) - [colors setObject: @"#aaa" forKey: [categoryLabels objectAtIndex: i]]; + if ((defaultCalendarCategoriesColors = [defaults calendarCategoriesColors])) + { + // Calendar categories colors are taken from SOGo's configuration or SOGoDefaults.plist - [defaults setCalendarCategoriesColors: colors]; + NSArray *defaultCalendarCategories; + NSMutableDictionary *filteredCalendarCategoriesColors; + NSString *label, *localizedLabel; + int count, max; + + defaultCalendarCategories = [defaultCalendarCategoriesColors allKeys]; + max = [defaultCalendarCategories count]; + filteredCalendarCategoriesColors = [NSMutableDictionary dictionaryWithCapacity: max]; + + for (count = 0; count < max; count++) + { + label = [defaultCalendarCategories objectAtIndex: count]; + if ((localizedLabel = [categoryLabels objectForKey: label])) + { + [filteredCalendarCategoriesColors setObject: [defaultCalendarCategoriesColors objectForKey: label] + forKey: localizedLabel]; + } + } + + [defaults setCalendarCategoriesColors: filteredCalendarCategoriesColors]; + } + else + { + // Calendar categories colors are set to #CCC + + NSArray *calendarCategories; + NSMutableDictionary *colors; + int i; + + calendarCategories = [categoryLabels allValues]; + colors = [NSMutableDictionary dictionaryWithCapacity: [calendarCategories count]]; + + for (i = 0; i < [calendarCategories count]; i++) + [colors setObject: @"#CCCCCCC" forKey: [calendarCategories objectAtIndex: i]]; + + [defaults setCalendarCategoriesColors: colors]; + } } // @@ -203,10 +293,6 @@ static SoProduct *preferencesProduct = nil; if ([[defaults source] dirty]) [defaults synchronize]; - // - // We inject our default mail account, something we don't want to do before we - // call -synchronize on our defaults. - // values = [[[[defaults source] values] mutableCopy] autorelease]; // Add locale code (used by CK Editor) @@ -219,6 +305,10 @@ static SoProduct *preferencesProduct = nil; [locale objectForKey: @"NSShortWeekDayNameArray"], @"shortDays", nil] forKey: @"locale"]; + // + // We inject our default mail account, something we don't want to do before we + // call -synchronize on our defaults. + // accounts = [NSMutableArray arrayWithArray: [values objectForKey: @"AuxiliaryMailAccounts"]]; account = [[[context activeUser] mailAccounts] objectAtIndex: 0]; if (![account objectForKey: @"receipts"])