mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-03-23 07:12:42 +00:00
More cleanups, defaults values for mail/contact/calendar labels and data validation
This commit is contained in:
committed by
Francis Lachapelle
parent
818af41ea6
commit
0f2e3df164
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2013 Inverse inc.
|
||||
Copyright (C) 2013-2015 Inverse inc.
|
||||
|
||||
This file is part of SOGo.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2007-2013 Inverse inc.
|
||||
Copyright (C) 2007-2015 Inverse inc.
|
||||
|
||||
This file is part of SOGo.
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/* SOGoSQLUserProfile.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
* 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
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
/* SOGoSQLUserProfile.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||||
* 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
#import <SOGo/SOGoUserDefaults.h>
|
||||
#import <SOGo/SOGoUserSettings.h>
|
||||
#import <SOGo/SOGoUserProfile.h>
|
||||
#import <Mailer/SOGoMailLabel.h>
|
||||
|
||||
#import <SOGoUI/UIxComponent.h>
|
||||
|
||||
#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]];
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#import <SOGo/SOGoBuild.h>
|
||||
#import <Mailer/SOGoMailAccount.h>
|
||||
#import <Mailer/SOGoMailAccounts.h>
|
||||
#import <Mailer/SOGoMailLabel.h>
|
||||
|
||||
#import <Contacts/SOGoContactGCSFolder.h>
|
||||
|
||||
@@ -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 <WOActionResults>) 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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user