2007-06-19 19:58:21 +02:00
|
|
|
/* UIxJSONPreferences.m - this file is part of SOGo
|
|
|
|
*
|
2015-02-25 23:21:07 +01:00
|
|
|
* Copyright (C) 2007-2015 Inverse inc.
|
2007-06-19 19:58:21 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2015-05-01 19:56:43 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2015-04-03 23:37:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
#import <NGObjWeb/SoObjects.h>
|
2007-06-19 19:58:21 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGObjWeb/WODirectAction.h>
|
2007-06-22 21:59:54 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2007-06-19 19:58:21 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
2015-04-08 20:19:31 +02:00
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
|
|
|
#import <SOGo/SOGoUserProfile.h>
|
2015-03-24 15:44:50 +01:00
|
|
|
#import <Mailer/SOGoMailLabel.h>
|
|
|
|
|
|
|
|
#import <SOGoUI/UIxComponent.h>
|
2015-04-03 23:37:46 +02:00
|
|
|
#import <UI/Common/WODirectAction+SOGo.h>
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
#import "UIxJSONPreferences.h"
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
static SoProduct *preferencesProduct = nil;
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
@implementation UIxJSONPreferences
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
- (WOResponse *) _makeResponse: (NSDictionary *) values
|
2007-06-22 21:59:54 +02:00
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [context response];
|
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
2015-03-26 18:37:44 +01:00
|
|
|
[response appendContentString: [values jsonRepresentation]];
|
2007-06-22 21:59:54 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
- (WOResponse *) jsonDefaultsAction
|
|
|
|
{
|
2015-04-30 17:19:30 +02:00
|
|
|
NSMutableDictionary *values, *account;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *defaults;
|
2015-04-10 15:44:30 +02:00
|
|
|
NSMutableArray *accounts;
|
2015-03-24 15:44:50 +01:00
|
|
|
NSArray *categoryLabels;
|
2015-08-06 22:07:46 +02:00
|
|
|
NSDictionary *locale;
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (!preferencesProduct)
|
|
|
|
{
|
|
|
|
preferencesProduct = [[SoProduct alloc] initWithBundle:
|
|
|
|
[NSBundle bundleForClass: NSClassFromString(@"PreferencesUIProduct")]];
|
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
defaults = [[context activeUser] userDefaults];
|
2015-04-06 16:55:42 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
|
|
|
// Default General preferences
|
|
|
|
//
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoLanguage"])
|
|
|
|
[[defaults source] setObject: [defaults language] forKey: @"SOGoLanguage"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoTimeZone"])
|
|
|
|
[[defaults source] setObject: [defaults timeZoneName] forKey: @"SOGoTimeZone"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-06 16:55:42 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoShortDateFormat"])
|
2015-04-10 15:44:30 +02:00
|
|
|
[[defaults source] setObject: [defaults shortDateFormat] forKey: @"SOGoShortDateFormat"];
|
2015-04-06 16:55:42 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoLongDateFormat"])
|
2015-04-10 15:44:30 +02:00
|
|
|
[[defaults source] setObject: [defaults longDateFormat] forKey: @"SOGoLongDateFormat"];
|
2015-03-24 15:44:50 +01:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoTimeFormat"])
|
|
|
|
[[defaults source] setObject: [defaults timeFormat] forKey: @"SOGoTimeFormat"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoLoginModule"])
|
|
|
|
[[defaults source] setObject: [defaults loginModule] forKey: @"SOGoLoginModule"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoRefreshViewCheck"])
|
|
|
|
[[defaults source] setObject: [defaults refreshViewCheck] forKey: @"SOGoRefreshViewCheck"];
|
|
|
|
|
|
|
|
//
|
|
|
|
// Default Calendar preferences
|
|
|
|
//
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoFirstDayOfWeek"])
|
|
|
|
[[defaults source] setObject: [NSNumber numberWithInt: [defaults firstDayOfWeek]] forKey: @"SOGoFirstDayOfWeek"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoDayStartTime"])
|
|
|
|
[[defaults source] setObject: [NSString stringWithFormat: @"%02d:00", [defaults dayStartHour]] forKey: @"SOGoDayStartTime"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoDayEndTime"])
|
|
|
|
[[defaults source] setObject: [NSString stringWithFormat: @"%02d:00", [defaults dayEndHour]] forKey: @"SOGoDayEndTime"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-07 22:32:51 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoFirstWeekOfYear"])
|
|
|
|
[[defaults source] setObject: [defaults firstWeekOfYear] forKey: @"SOGoFirstWeekOfYear"];
|
2015-04-10 15:44:30 +02:00
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoDefaultCalendar"])
|
|
|
|
[[defaults source] setObject: [defaults defaultCalendar] forKey: @"SOGoDefaultCalendar"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarEventsDefaultClassification"])
|
|
|
|
[[defaults source] setObject: [defaults calendarEventsDefaultClassification] forKey: @"SOGoCalendarEventsDefaultClassification"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarTasksDefaultClassification"])
|
|
|
|
[[defaults source] setObject: [defaults calendarTasksDefaultClassification] forKey: @"SOGoCalendarTasksDefaultClassification"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoCalendarDefaultReminder"])
|
|
|
|
[[defaults source] setObject: [defaults calendarDefaultReminder] forKey: @"SOGoCalendarDefaultReminder"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
// Populate default calendar categories, based on the user's preferred language
|
|
|
|
if (![defaults calendarCategories])
|
|
|
|
{
|
2015-04-10 15:44:30 +02:00
|
|
|
categoryLabels = [[[self labelForKey: @"calendar_category_labels" withResourceManager: [preferencesProduct resourceManager]]
|
2015-03-24 15:44:50 +01:00
|
|
|
componentsSeparatedByString: @","]
|
|
|
|
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
[defaults setCalendarCategories: categoryLabels];
|
|
|
|
}
|
2015-04-28 21:15:42 +02:00
|
|
|
if (![defaults calendarCategoriesColors])
|
|
|
|
{
|
|
|
|
NSMutableDictionary *colors;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
categoryLabels = [defaults calendarCategories];
|
|
|
|
colors = [NSMutableDictionary dictionaryWithCapacity: [categoryLabels count]];
|
|
|
|
|
|
|
|
for (i = 0; i < [categoryLabels count]; i++)
|
|
|
|
[colors setObject: @"#aaa" forKey: [categoryLabels objectAtIndex: i]];
|
|
|
|
|
|
|
|
[defaults setCalendarCategoriesColors: colors];
|
|
|
|
}
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
|
|
|
// Default Contacts preferences
|
|
|
|
//
|
2015-03-24 15:44:50 +01:00
|
|
|
// Populate default contact categories, based on the user's preferred language
|
2015-04-10 15:44:30 +02:00
|
|
|
//
|
2015-03-24 15:44:50 +01:00
|
|
|
if (![defaults contactsCategories])
|
|
|
|
{
|
2015-04-10 15:44:30 +02:00
|
|
|
categoryLabels = [[[self labelForKey: @"contacts_category_labels" withResourceManager: [preferencesProduct resourceManager]]
|
2015-04-03 23:37:46 +02:00
|
|
|
componentsSeparatedByString: @","]
|
2015-03-24 15:44:50 +01:00
|
|
|
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
if (!categoryLabels)
|
|
|
|
categoryLabels = [NSArray array];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
[defaults setContactsCategories: categoryLabels];
|
|
|
|
}
|
2015-04-10 15:44:30 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Default Mail preferences
|
|
|
|
//
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoSelectedAddressBook"])
|
|
|
|
[[defaults source] setObject: [defaults selectedAddressBook] forKey: @"SOGoSelectedAddressBook"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailMessageForwarding"])
|
|
|
|
[[defaults source] setObject: [defaults mailMessageForwarding] forKey: @"SOGoMailMessageForwarding"];
|
|
|
|
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailReplyPlacement"])
|
|
|
|
[[defaults source] setObject: [defaults mailReplyPlacement] forKey: @"SOGoMailReplyPlacement"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailSignaturePlacement"])
|
|
|
|
[[defaults source] setObject: [defaults mailSignaturePlacement] forKey: @"SOGoMailSignaturePlacement"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailComposeMessageType"])
|
|
|
|
[[defaults source] setObject: [defaults mailComposeMessageType] forKey: @"SOGoMailComposeMessageType"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailDisplayRemoteInlineImages"])
|
|
|
|
[[defaults source] setObject: [defaults mailDisplayRemoteInlineImages] forKey: @"SOGoMailDisplayRemoteInlineImages"];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
// Populate default mail lablels, based on the user's preferred language
|
|
|
|
if (![[defaults source] objectForKey: @"SOGoMailLabelsColors"])
|
|
|
|
{
|
2015-04-03 23:37:46 +02:00
|
|
|
SOGoMailLabel *label;
|
|
|
|
NSArray *labels;
|
|
|
|
id v;
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
int i;
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
v = [defaults mailLabelsColors];
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
labels = [SOGoMailLabel labelsFromDefaults: v component: self];
|
|
|
|
v = [NSMutableDictionary dictionary];
|
|
|
|
for (i = 0; i < [labels count]; i++)
|
|
|
|
{
|
|
|
|
label = [labels objectAtIndex: i];
|
|
|
|
[v setObject: [NSArray arrayWithObjects: [label label], [label color], nil]
|
|
|
|
forKey: [label name]];
|
|
|
|
}
|
2015-08-06 22:07:46 +02:00
|
|
|
|
2015-04-03 23:37:46 +02:00
|
|
|
[defaults setMailLabelsColors: v];
|
2015-03-24 15:44:50 +01:00
|
|
|
}
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
if ([[defaults source] dirty])
|
2015-03-26 18:37:44 +01:00
|
|
|
[defaults synchronize];
|
|
|
|
|
2015-04-30 17:19:30 +02:00
|
|
|
//
|
2015-03-26 18:37:44 +01:00
|
|
|
// We inject our default mail account, something we don't want to do before we
|
|
|
|
// call -synchronize on our defaults.
|
2015-04-30 17:19:30 +02:00
|
|
|
//
|
2015-03-26 18:37:44 +01:00
|
|
|
values = [[[[defaults source] values] mutableCopy] autorelease];
|
2015-04-10 15:44:30 +02:00
|
|
|
|
2015-08-06 22:07:46 +02:00
|
|
|
// Add locale code (used by CK Editor)
|
|
|
|
locale = [[preferencesProduct resourceManager] localeForLanguageNamed: [defaults language]];
|
|
|
|
[values setObject: [locale objectForKey: @"NSLocaleCode"] forKey: @"LocaleCode"];
|
|
|
|
|
2015-04-10 15:44:30 +02:00
|
|
|
accounts = [NSMutableArray arrayWithArray: [values objectForKey: @"AuxiliaryMailAccounts"]];
|
2015-04-30 17:19:30 +02:00
|
|
|
account = [[[context activeUser] mailAccounts] objectAtIndex: 0];
|
|
|
|
if (![account objectForKey: @"receipts"])
|
|
|
|
{
|
|
|
|
[account setObject: [NSDictionary dictionaryWithObjectsAndKeys: @"ignore", @"receiptAction",
|
|
|
|
@"ignore", @"receiptNonRecipientAction",
|
|
|
|
@"ignore", @"receiptOutsideDomainAction",
|
|
|
|
@"ignore", @"receiptAnyAction", nil]
|
|
|
|
forKey: @"receipts"];
|
|
|
|
}
|
|
|
|
|
|
|
|
[accounts insertObject: account atIndex: 0];
|
2015-04-10 15:44:30 +02:00
|
|
|
[values setObject: accounts forKey: @"AuxiliaryMailAccounts"];
|
2015-04-30 17:19:30 +02:00
|
|
|
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
return [self _makeResponse: values];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) jsonSettingsAction
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserSettings *settings;
|
2015-04-08 20:19:31 +02:00
|
|
|
id v;
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
|
2015-04-08 20:19:31 +02:00
|
|
|
// We sanitize PreventInvitationsWhitelist if we need to, this is due to the fact
|
|
|
|
// that SOGo <= 2.2.17 used to store it as a JSON *string* within the JSON-blob -
|
|
|
|
// sorry about this engineering brain fart!
|
|
|
|
v = [[settings objectForKey: @"Calendar"] objectForKey: @"PreventInvitationsWhitelist"];
|
|
|
|
|
|
|
|
if (v && [v isKindOfClass: [NSString class]])
|
|
|
|
{
|
|
|
|
[[settings objectForKey: @"Calendar"] setObject: [v objectFromJSONString]
|
|
|
|
forKey: @"PreventInvitationsWhitelist"];
|
|
|
|
}
|
|
|
|
|
2015-08-17 15:55:14 +02:00
|
|
|
// Initialize some default values
|
|
|
|
if (![settings objectForKey: @"Calendar"])
|
|
|
|
[settings setObject: [NSMutableDictionary dictionary] forKey: @"Calendar"];
|
|
|
|
|
|
|
|
if (![settings objectForKey: @"Contact"])
|
|
|
|
[settings setObject: [NSMutableDictionary dictionary] forKey: @"Contact"];
|
|
|
|
|
|
|
|
if (![settings objectForKey: @"Mail"])
|
|
|
|
[settings setObject: [NSMutableDictionary dictionary] forKey: @"Mail"];
|
|
|
|
|
2015-03-26 18:37:44 +01:00
|
|
|
return [self _makeResponse: [[settings source] values]];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|