diff --git a/SoObjects/Mailer/SOGoMailLabel.h b/SoObjects/Mailer/SOGoMailLabel.h index 5a64f908d..dec1d6839 100644 --- a/SoObjects/Mailer/SOGoMailLabel.h +++ b/SoObjects/Mailer/SOGoMailLabel.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Inverse inc. + Copyright (C) 2013-2015 Inverse inc. This file is part of SOGo. diff --git a/SoObjects/Mailer/SOGoMailLabel.m b/SoObjects/Mailer/SOGoMailLabel.m index 1d822e90b..bdbce74b8 100644 --- a/SoObjects/Mailer/SOGoMailLabel.m +++ b/SoObjects/Mailer/SOGoMailLabel.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2007-2013 Inverse inc. + Copyright (C) 2007-2015 Inverse inc. This file is part of SOGo. diff --git a/SoObjects/SOGo/SOGoSQLUserProfile.h b/SoObjects/SOGo/SOGoSQLUserProfile.h index 1a3b9d253..51ff1c9e8 100644 --- a/SoObjects/SOGo/SOGoSQLUserProfile.h +++ b/SoObjects/SOGo/SOGoSQLUserProfile.h @@ -1,8 +1,6 @@ /* SOGoSQLUserProfile.h - this file is part of SOGo * - * Copyright (C) 2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2009-2015 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 diff --git a/SoObjects/SOGo/SOGoSQLUserProfile.m b/SoObjects/SOGo/SOGoSQLUserProfile.m index 5172896a7..c3d126f46 100644 --- a/SoObjects/SOGo/SOGoSQLUserProfile.m +++ b/SoObjects/SOGo/SOGoSQLUserProfile.m @@ -1,8 +1,6 @@ /* SOGoSQLUserProfile.m - this file is part of SOGo * - * Copyright (C) 2009 Inverse inc. - * - * Author: Wolfgang Sourdeau + * Copyright (C) 2009-2015 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 diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 66dbcf5fb..465aca2f8 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -1,6 +1,6 @@ /* SOGoUserDefaults.h - this file is part of SOGo * - * Copyright (C) 2011-2014 Inverse inc. + * Copyright (C) 2011-2015 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 diff --git a/UI/PreferencesUI/UIxJSONPreferences.m b/UI/PreferencesUI/UIxJSONPreferences.m index edea3c0b8..099e44e04 100644 --- a/UI/PreferencesUI/UIxJSONPreferences.m +++ b/UI/PreferencesUI/UIxJSONPreferences.m @@ -27,6 +27,9 @@ #import #import #import +#import + +#import #import "UIxJSONPreferences.h" @@ -47,9 +50,51 @@ - (WOResponse *) jsonDefaultsAction { SOGoUserDefaults *defaults; + NSArray *categoryLabels; defaults = [[context activeUser] userDefaults]; + if (![[defaults source] objectForKey: @"SOGoLongDateFormat"]) + [[defaults source] setObject: @"default" forKey: @"SOGoLongDateFormat"]; + + // Populate default calendar categories, based on the user's preferred language + if (![defaults calendarCategories]) + { + categoryLabels = [[[self labelForKey: @"calendar_category_labels"] + componentsSeparatedByString: @","] + sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + + [defaults setCalendarCategories: categoryLabels]; + } + + // Populate default contact categories, based on the user's preferred language + if (![defaults contactsCategories]) + { + categoryLabels = [[[self labelForKey: @"contacts_category_labels"] + componentsSeparatedByString: @","] + sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + + if (!categoryLabels) + categoryLabels = [NSArray array]; + + [defaults setContactsCategories: categoryLabels]; + } + + // Populate default mail lablels, based on the user's preferred language + if (![[defaults source] objectForKey: @"SOGoMailLabelsColors"]) + { + NSDictionary *v; + + v = [defaults mailLabelsColors]; + + // TODO - translate + refactor to not pass self since it's not a component + //[defaults setMailLabelsColors: [SOGoMailLabel labelsFromDefaults: v component: self]]; + [defaults setMailLabelsColors: v]; + } + + + [defaults synchronize]; + return [self _makeResponse: [defaults source]]; } diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 486bd38e0..492830b97 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -52,7 +52,6 @@ #import #import #import -#import #import @@ -1539,167 +1538,177 @@ static NSArray *reminderValues = nil; // return [locale objectForKey: @"NSLocaleCode"]; // } -- (NSArray *) _languageCalendarCategories -{ - NSArray *categoryLabels; +// - (NSArray *) _languageCalendarCategories +// { +// NSArray *categoryLabels; - categoryLabels = [[self labelForKey: @"calendar_category_labels"] - componentsSeparatedByString: @","]; +// categoryLabels = [[self labelForKey: @"calendar_category_labels"] +// componentsSeparatedByString: @","]; - return [categoryLabels trimmedComponents]; -} +// return [categoryLabels trimmedComponents]; +// } -- (NSArray *) calendarCategoryList -{ - if (!calendarCategories) - { - ASSIGN (calendarCategories, [userDefaults calendarCategories]); - if (!calendarCategories) - ASSIGN (calendarCategories, [self _languageCalendarCategories]); - } +// - (NSArray *) calendarCategoryList +// { +// if (!calendarCategories) +// { +// ASSIGN (calendarCategories, [userDefaults calendarCategories]); +// if (!calendarCategories) +// ASSIGN (calendarCategories, [self _languageCalendarCategories]); +// } - return [calendarCategories - sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; -} +// return [calendarCategories +// sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; +// } -- (SOGoMailLabel *) label -{ - return label; -} +// - (SOGoMailLabel *) label +// { +// return label; +// } -- (void) setLabel: (SOGoMailLabel *) newLabel -{ - ASSIGN(label, newLabel); -} +// - (void) setLabel: (SOGoMailLabel *) newLabel +// { +// ASSIGN(label, newLabel); +// } -- (NSArray *) mailLabelList -{ - if (!mailLabels) - { - NSDictionary *v; +// - (NSArray *) mailLabelList +// { +// if (!mailLabels) +// { +// NSDictionary *v; - v = [[[context activeUser] userDefaults] mailLabelsColors]; - ASSIGN(mailLabels, [SOGoMailLabel labelsFromDefaults: v component: self]); - } +// v = [[[context activeUser] userDefaults] mailLabelsColors]; +// ASSIGN(mailLabels, [SOGoMailLabel labelsFromDefaults: v component: self]); +// } - return mailLabels; -} +// return mailLabels; +// } -- (NSString *) mailLabelsValue -{ - return @""; -} +// - (NSString *) mailLabelsValue +// { +// return @""; +// } -- (void) setMailLabelsValue: (NSString *) value -{ - NSMutableDictionary *sanitizedLabels; - NSDictionary *newLabels; - NSArray *allKeys; - NSString *name; - int i; +// - (void) setMailLabelsValue: (NSString *) value +// { +// NSMutableDictionary *sanitizedLabels; +// NSDictionary *newLabels; +// NSArray *allKeys; +// NSString *name; +// int i; - newLabels = [value objectFromJSONString]; - if (newLabels && [newLabels isKindOfClass: [NSDictionary class]]) - { - // We encode correctly our keys - sanitizedLabels = [NSMutableDictionary dictionary]; - allKeys = [newLabels allKeys]; +// newLabels = [value objectFromJSONString]; +// if (newLabels && [newLabels isKindOfClass: [NSDictionary class]]) +// { +// // We encode correctly our keys +// sanitizedLabels = [NSMutableDictionary dictionary]; +// allKeys = [newLabels allKeys]; - for (i = 0; i < [allKeys count]; i++) - { - name = [allKeys objectAtIndex: i]; +// for (i = 0; i < [allKeys count]; i++) +// { +// name = [allKeys objectAtIndex: i]; - if (![name is7bitSafe]) - name = [name stringByEncodingImap4FolderName]; +// if (![name is7bitSafe]) +// name = [name stringByEncodingImap4FolderName]; - name = [name lowercaseString]; +// name = [name lowercaseString]; - [sanitizedLabels setObject: [newLabels objectForKey: [allKeys objectAtIndex: i]] - forKey: name]; - } +// [sanitizedLabels setObject: [newLabels objectForKey: [allKeys objectAtIndex: i]] +// forKey: name]; +// } - [userDefaults setMailLabelsColors: sanitizedLabels]; - } -} +// [userDefaults setMailLabelsColors: sanitizedLabels]; +// } +// } -- (void) setCategory: (NSString *) newCategory -{ - ASSIGN (category, newCategory); -} +// - (void) setCategory: (NSString *) newCategory +// { +// ASSIGN (category, newCategory); +// } -- (NSString *) category -{ - return category; -} +// - (NSString *) category +// { +// return category; +// } -- (NSString *) categoryColor -{ - NSString *categoryColor; +// - (NSString *) categoryColor +// { +// SOGoDomainDefaults *dd; +// NSString *categoryColor; - if (!calendarCategoriesColors) - ASSIGN (calendarCategoriesColors, [userDefaults calendarCategoriesColors]); +// if (!calendarCategoriesColors) +// ASSIGN (calendarCategoriesColors, [userDefaults calendarCategoriesColors]); - categoryColor = [calendarCategoriesColors objectForKey: category]; +// categoryColor = [calendarCategoriesColors objectForKey: category]; +// if (!categoryColor) +// { +// if (!defaultCategoryColor) +// { +// dd = [[context activeUser] domainDefaults]; +// ASSIGN (defaultCategoryColor, [dd calendarDefaultCategoryColor]); +// } +// categoryColor = defaultCategoryColor; +// } - return categoryColor; -} +// return categoryColor; +// } -- (NSString *) calendarCategoriesValue -{ - return @""; -} +// - (NSString *) calendarCategoriesValue +// { +// return @""; +// } -- (void) setCalendarCategoriesValue: (NSString *) value -{ - NSDictionary *newColors; +// - (void) setCalendarCategoriesValue: (NSString *) value +// { +// NSDictionary *newColors; - newColors = [value objectFromJSONString]; - if (newColors && [newColors isKindOfClass: [NSDictionary class]]) - { - [userDefaults setCalendarCategories: [newColors allKeys]]; - [userDefaults setCalendarCategoriesColors: newColors]; - } -} +// newColors = [value objectFromJSONString]; +// if (newColors && [newColors isKindOfClass: [NSDictionary class]]) +// { +// [userDefaults setCalendarCategories: [newColors allKeys]]; +// [userDefaults setCalendarCategoriesColors: newColors]; +// } +// } -- (NSArray *) _languageContactsCategories -{ - NSArray *categoryLabels; +// - (NSArray *) _languageContactsCategories +// { +// NSArray *categoryLabels; - categoryLabels = [[self labelForKey: @"contacts_category_labels"] - componentsSeparatedByString: @","]; - if (!categoryLabels) - categoryLabels = [NSArray array]; +// categoryLabels = [[self labelForKey: @"contacts_category_labels"] +// componentsSeparatedByString: @","]; +// if (!categoryLabels) +// categoryLabels = [NSArray array]; - return [categoryLabels trimmedComponents]; -} +// return [categoryLabels trimmedComponents]; +// } -- (NSArray *) contactsCategoryList -{ - if (!contactsCategories) - { - ASSIGN (contactsCategories, [userDefaults contactsCategories]); - if (!contactsCategories) - ASSIGN (contactsCategories, [self _languageContactsCategories]); - } +// - (NSArray *) contactsCategoryList +// { +// if (!contactsCategories) +// { +// ASSIGN (contactsCategories, [userDefaults contactsCategories]); +// if (!contactsCategories) +// ASSIGN (contactsCategories, [self _languageContactsCategories]); +// } - return [contactsCategories - sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; -} +// return [contactsCategories +// sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; +// } -- (NSString *) contactsCategoriesValue -{ - return @""; -} +// - (NSString *) contactsCategoriesValue +// { +// return @""; +// } -- (void) setContactsCategoriesValue: (NSString *) value -{ - NSArray *newCategories; +// - (void) setContactsCategoriesValue: (NSString *) value +// { +// NSArray *newCategories; - newCategories = [value objectFromJSONString]; - if (newCategories && [newCategories isKindOfClass: [NSArray class]]) - [userDefaults setContactsCategories: newCategories]; -} +// newCategories = [value objectFromJSONString]; +// if (newCategories && [newCategories isKindOfClass: [NSArray class]]) +// [userDefaults setContactsCategories: newCategories]; +// } // // Used by wox template @@ -2020,14 +2029,45 @@ static NSArray *reminderValues = nil; - (id ) saveAction { - //SOGoUser *user; id o, v; o = [[[context request] contentAsString] objectFromJSONString]; - //user = [[self context] activeUser]; + // Proceed with data sanitization of the "defaults" if ((v = [o objectForKey: @"defaults"])) { + NSMutableDictionary *sanitizedLabels; + NSDictionary *newLabels; + NSArray *allKeys; + NSString *name; + int i; + + // We convert our object into a mutable one + v = [[v mutableCopy] autorelease]; + + newLabels = [v objectForKey: @"SOGoMailLabelsColors"]; + if (newLabels && [newLabels isKindOfClass: [NSDictionary class]]) + { + // We encode correctly our keys + sanitizedLabels = [NSMutableDictionary dictionary]; + allKeys = [newLabels allKeys]; + + for (i = 0; i < [allKeys count]; i++) + { + name = [allKeys objectAtIndex: i]; + + if (![name is7bitSafe]) + name = [name stringByEncodingImap4FolderName]; + + name = [name lowercaseString]; + + [sanitizedLabels setObject: [newLabels objectForKey: [allKeys objectAtIndex: i]] + forKey: name]; + } + + [v setObject: sanitizedLabels forKey: @"SOGoMailLabelsColors"]; + } + [[[user userDefaults] source] setValues: v]; [[user userDefaults] synchronize]; }