Monotone-Parent: 1a0f96fd588d7f7edaa7a85a352ab39c2acbca70

Monotone-Revision: b0d54fb9b69827b08042c1be219b87648b1a9df2

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2009-12-01T16:53:15
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2009-12-01 16:53:15 +00:00
parent ee001b16ab
commit b9a5c1e750
8 changed files with 127 additions and 69 deletions

View File

@@ -5,6 +5,26 @@
2009-12-01 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* UI/PreferencesUI/UIxPreferences.m (-categoryList): simplified
method by returning only the array of defined categories from the
user defaults or those defined in the Localizable.strings and sort
the resulting array.
(-categoryColor): new accessor that return the color associated
with the value in the "category" ivar, if not exists, we return
the default from SOGoCalendarDefaultCategoryColor.
(-setCategoriesValue): simplified method since we now receive a
dictionary. The dictionary is now transferred as a JSON object
rather than a property list.
* SoObjects/SOGo/SOGoUserDefaults.m
(-setCalendarCategoriesColors:, -calendarCategoriesColors):
SOGoCalendarCategoriesColors is now a dictionary. The values are
migrated in _migrateCalendarCategories.
* SoObjects/SOGo/SOGoDomainDefaults.m
(-calendarDefaultCategoryColor): new accessor for the domain
default SOGoCalendarDefaultCategoryColor.
* SoObjects/SOGo/SOGoDefaultsSource.m (-boolForKey:)
(-floatForKey:, -integerForKey:, -dataForKey:, -stringForKey:)
(-dictionaryForKey:, -arrayForKey:, -stringArrayForKey:): added

View File

@@ -33,7 +33,6 @@
#import "NSDictionary+Utilities.h"
#import "SOGoStartupLogger.h"
#define NEEDS_DEFAULTS_SOURCE_INTERNAL 1
#import "SOGoSystemDefaults.h"
@implementation SOGoSystemDefaults

View File

@@ -125,8 +125,8 @@ extern NSString *SOGoWeekStartFirstFullWeek;
- (void) setCalendarCategories: (NSArray *) newValues;
- (NSArray *) calendarCategories;
- (void) setCalendarCategoriesColors: (NSArray *) newValues;
- (NSArray *) calendarCategoriesColors;
- (void) setCalendarCategoriesColors: (NSDictionary *) newValues;
- (NSDictionary *) calendarCategoriesColors;
- (void) setCalendarShouldDisplayWeekend: (BOOL) newValue;
- (BOOL) calendarShouldDisplayWeekend;

View File

@@ -26,7 +26,6 @@
#import <Foundation/NSTimeZone.h>
#import "NSString+Utilities.h"
#define NEEDS_DEFAULTS_SOURCE_INTERNAL 1
#import "SOGoDomainDefaults.h"
#import "SOGoSystemDefaults.h"
#import "SOGoUserProfile.h"
@@ -147,6 +146,33 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
return rc;
}
- (BOOL) _migrateCalendarCategories
{
NSArray *categories, *colors;
NSDictionary *newColors;
BOOL rc;
colors = [source objectForKey: @"SOGoCalendarCategoriesColors"];
if ([colors isKindOfClass: [NSArray class]])
{
categories = [source objectForKey: @"SOGoCalendarCategories"];
if ([categories count] == [colors count])
{
newColors = [NSDictionary dictionaryWithObjects: colors
forKeys: categories];
[source setObject: newColors
forKey: @"SOGoCalendarCategoriesColors"];
}
else
[source removeObjectForKey: @"SOGoCalendarCategoriesColors"];
rc = YES;
}
else
rc = NO;
return rc;
}
- (BOOL) migrate
{
static NSDictionary *migratedKeys = nil;
@@ -185,6 +211,7 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
not be invoked in the case where rc = YES. */
return ([self _migrateLastModule]
| [self _migrateSignature]
| [self _migrateCalendarCategories]
| [self migrateOldDefaultsWithDictionary: migratedKeys]
| [super migrate]);
}
@@ -490,14 +517,14 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
return [self stringArrayForKey: @"SOGoCalendarCategories"];
}
- (void) setCalendarCategoriesColors: (NSArray *) newValues
- (void) setCalendarCategoriesColors: (NSDictionary *) newValues
{
[self setObject: newValues forKey: @"SOGoCalendarCategoriesColors"];
}
- (NSArray *) calendarCategoriesColors
- (NSDictionary *) calendarCategoriesColors
{
return [self stringArrayForKey: @"SOGoCalendarCategoriesColors"];
return [self dictionaryForKey: @"SOGoCalendarCategoriesColors"];
}
- (void) setCalendarShouldDisplayWeekend: (BOOL) newValue

View File

@@ -35,6 +35,10 @@
id item;
SOGoUser *user;
NSDictionary *locale;
NSArray *calendarCategories;
NSDictionary *calendarCategoriesColors;
NSString *category;
NSString *defaultCategoryColor;
SOGoUserDefaults *userDefaults;
NSCalendarDate *today;
NSArray *daysOfWeek, *daysBetweenResponsesList;

View File

@@ -33,6 +33,7 @@
#import <NGExtensions/NSObject+Logs.h>
#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSDictionary+BSJSONAdditions.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoUser.h>
@@ -70,6 +71,11 @@
//locale = [context valueForKey: @"locale"];
language = [userDefaults language];
calendarCategories = nil;
calendarCategoriesColors = nil;
defaultCategoryColor = nil;
category = nil;
ASSIGN (locale,
[[WOApplication application] localeForLanguageNamed: language]);
ASSIGN (daysOfWeek, [locale objectForKey: NSWeekDayNameArray]);
@@ -108,6 +114,10 @@
[user release];
[userDefaults release];
[vacationOptions release];
[calendarCategories release];
[calendarCategoriesColors release];
[defaultCategoryColor release];
[category release];
[forwardOptions release];
[daysOfWeek release];
[locale release];
@@ -941,44 +951,60 @@
return [self labelForKey: @"Color"];
}
- (NSArray *) categories
- (NSArray *) languageCategories
{
NSDictionary *element;
NSArray *k, *v, *names, *colors;
NSMutableArray *categories, *newColors;
int i, count;
NSArray *categoryLabels;
names = [userDefaults calendarCategories];
if (names)
colors = [userDefaults calendarCategoriesColors];
else
{
names = [[self labelForKey: @"category_labels"]
componentsSeparatedByString: @","];
count = [names count];
newColors = [NSMutableArray arrayWithCapacity: count];
for (i = 0; i < count; i++)
[newColors addObject: @"#F0F0F0"];
colors = newColors;
}
categoryLabels = [[self labelForKey: @"category_labels"]
componentsSeparatedByString: @","];
categories = [NSMutableArray array];
k = [NSArray arrayWithObjects: @"name", @"color", nil];
count = [names count];
for (i = 0; i < count; i++)
{
v = [NSArray arrayWithObjects: [names objectAtIndex: i],
[colors objectAtIndex: i], nil];
element = [NSDictionary dictionaryWithObjects: v
forKeys: k];
[categories addObject: element];
}
return categories;
return [categoryLabels trimmedComponents];
}
- (NSArray *) categoryList
{
if (!calendarCategories)
{
ASSIGN (calendarCategories, [userDefaults calendarCategories]);
if (!calendarCategories)
ASSIGN (calendarCategories, [self languageCategories]);
}
return [calendarCategories
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
}
- (void) setCategory: (NSString *) newCategory
{
ASSIGN (category, newCategory);
}
- (NSString *) category
{
return category;
}
- (NSString *) categoryColor
{
SOGoDomainDefaults *dd;
NSString *categoryColor;
if (!calendarCategoriesColors)
ASSIGN (calendarCategoriesColors, [userDefaults calendarCategoriesColors]);
categoryColor = [calendarCategoriesColors objectForKey: category];
if (!categoryColor)
{
if (!defaultCategoryColor)
{
dd = [[context activeUser] domainDefaults];
ASSIGN (defaultCategoryColor, [dd calendarDefaultCategoryColor]);
}
categoryColor = defaultCategoryColor;
}
return categoryColor;
}
- (NSString *) categoriesValue
{
@@ -987,26 +1013,13 @@
- (void) setCategoriesValue: (NSString *) value
{
NSData *data;
NSString *error;
NSPropertyListFormat format;
NSArray *plist;
NSDictionary *newColors;
data = [value dataUsingEncoding: NSUTF8StringEncoding];
plist = [NSPropertyListSerialization propertyListFromData: data
mutabilityOption: NSPropertyListImmutable
format: &format
errorDescription: &error];
if (!plist)
newColors = [NSMutableDictionary dictionaryWithJSONString: value];
if (newColors)
{
[self errorWithFormat: @"an error occured during deserialization"
@" of categories: %@", error];
[error release];
}
else
{
[userDefaults setCalendarCategories: [plist objectAtIndex: 0]];
[userDefaults setCalendarCategoriesColors: [plist objectAtIndex: 1]];
[userDefaults setCalendarCategories: [newColors allKeys]];
[userDefaults setCalendarCategoriesColors: newColors];
}
}

View File

@@ -108,12 +108,12 @@
></tr
></thead>
<tbody>
<var:foreach list="categories" item="category">
<var:foreach list="categoryList" item="category">
<tr const:class="categoryListRow"
><td const:class="categoryListCell"
><var:string var:value="category.name"/></td
><var:string var:value="category"/></td
><td const:class="categoryListCell"
><div const:class="colorBox"><var:string var:value="category.color"
><div const:class="colorBox"><var:string var:value="categoryColor"
/></div></td
></tr>
</var:foreach>

View File

@@ -245,21 +245,16 @@ function onCategoryDelete (e) {
function serializeCategories (e) {
var r = $$("TABLE#categoriesList tbody tr");
var names = "(";
var colors = "(";
var values = [];
for (var i = 0; i < r.length; i++) {
var tds = r[i].childElements ();
var name = $(tds.first ()).innerHTML;
var color = $(tds.last ().childElements ().first ()).showColor;
names += "\"" + name + "\", ";
colors += "\"" + color + "\", ";
values.push("\"" + name + "\": \"" + color + "\"");
}
names = names.substr (0, names.length - 1) + ")";
colors = colors.substr (0, colors.length - 1) + ")";
$("categoriesValue").value = "(" + names + ", " + colors + ")";
$("categoriesValue").value = "{ " + values.join(",\n") + "}";
}
function resetCategoriesColors (e) {