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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
|
|
|
#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>
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
#import "UIxJSONPreferences.h"
|
|
|
|
|
|
|
|
@implementation UIxJSONPreferences
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (WOResponse *) _makeResponse: (SOGoUserProfile *) profile
|
2007-06-22 21:59:54 +02:00
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [context response];
|
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
2009-11-29 05:19:32 +01:00
|
|
|
[response appendContentString: [profile jsonRepresentation]];
|
2007-06-22 21:59:54 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-06-19 19:58:21 +02:00
|
|
|
- (WOResponse *) jsonDefaultsAction
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *defaults;
|
2015-03-24 15:44:50 +01:00
|
|
|
NSArray *categoryLabels;
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
defaults = [[context activeUser] userDefaults];
|
|
|
|
|
2015-03-24 15:44:50 +01:00
|
|
|
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];
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
return [self _makeResponse: [defaults source]];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) jsonSettingsAction
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserSettings *settings;
|
2007-06-19 19:58:21 +02:00
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
return [self _makeResponse: [settings source]];
|
2007-06-19 19:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|