Skip to content

Commit

Permalink
fix(contacts): Custom contacts categories in sogo.conf wasn't working
Browse files Browse the repository at this point in the history
  • Loading branch information
QHivert committed Dec 14, 2023
1 parent 0d471ef commit 26c7462
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 23 deletions.
82 changes: 66 additions & 16 deletions UI/PreferencesUI/UIxJSONPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ - (NSDictionary *) _localizedCategoryLabels
return labelsDictionary;
}

- (NSDictionary *) _localizedContactsLabels
{
NSArray *categoryLabels, *localizedCategoryLabels;
NSDictionary *labelsDictionary;

labelsDictionary = nil;
localizedCategoryLabels = [[self labelForKey: @"contacts_category_labels"
withResourceManager: [preferencesProduct resourceManager]]
componentsSeparatedByString: @","];
categoryLabels = [[[preferencesProduct resourceManager]
stringForKey: @"contacts_category_labels"
inTableNamed: nil
withDefaultValue: @""
languages: [NSArray arrayWithObject: @"English"]]
componentsSeparatedByString: @","];

if ([localizedCategoryLabels count] == [categoryLabels count])
labelsDictionary = [NSDictionary dictionaryWithObjects: localizedCategoryLabels
forKeys: categoryLabels];
else
[self logWithFormat: @"ERROR: localizable strings contacts_category_labels is incorrect for language %@",
[[[context activeUser] userDefaults] language]];

return labelsDictionary;
}

- (WOResponse *) activeExternalSieveScriptsAction
{
NGSieveClient *client;
Expand Down Expand Up @@ -121,7 +147,7 @@ - (NSString *) jsonDefaults
SOGoUserDefaults *defaults;
SOGoDomainDefaults *domainDefaults;
NSMutableArray *accounts;
NSDictionary *categoryLabels, *vacationOptions;
NSDictionary *calendarCategoryLabels, *contactsCategoriesLabels, *vacationOptions;

if (!preferencesProduct)
{
Expand All @@ -131,7 +157,8 @@ - (NSString *) jsonDefaults

defaults = [[context activeUser] userDefaults];
domainDefaults = [[context activeUser] domainDefaults];
categoryLabels = nil;
calendarCategoryLabels = nil;
contactsCategoriesLabels = nil;

//
// Default General preferences
Expand Down Expand Up @@ -223,7 +250,7 @@ - (NSString *) jsonDefaults
{
NSArray *defaultCalendarCategories;

categoryLabels = [self _localizedCategoryLabels];
calendarCategoryLabels = [self _localizedCategoryLabels];

if ((defaultCalendarCategories = [defaults calendarCategories]))
{
Expand All @@ -239,7 +266,7 @@ - (NSString *) jsonDefaults
for (count = 0; count < max; count++)
{
label = [defaultCalendarCategories objectAtIndex: count];
if (!(localizedLabel = [categoryLabels objectForKey: label]))
if (!(localizedLabel = [calendarCategoryLabels objectForKey: label]))
{
localizedLabel = label;
}
Expand All @@ -252,15 +279,15 @@ - (NSString *) jsonDefaults
{
// Calendar categories are taken from localizable strings

[defaults setCalendarCategories: [categoryLabels allValues]];
[defaults setCalendarCategories: [calendarCategoryLabels allValues]];
}
}
if (![[defaults source] objectForKey: @"SOGoCalendarCategoriesColors"])
{
NSDictionary *defaultCalendarCategoriesColors;

if (!categoryLabels)
categoryLabels = [self _localizedCategoryLabels];
if (!calendarCategoryLabels)
calendarCategoryLabels = [self _localizedCategoryLabels];

if ((defaultCalendarCategoriesColors = [defaults calendarCategoriesColors]))
{
Expand All @@ -278,7 +305,7 @@ - (NSString *) jsonDefaults
for (count = 0; count < max; count++)
{
label = [defaultCalendarCategories objectAtIndex: count];
if (!(localizedLabel = [categoryLabels objectForKey: label]))
if (!(localizedLabel = [calendarCategoryLabels objectForKey: label]))
{
localizedLabel = label;
}
Expand All @@ -296,7 +323,7 @@ - (NSString *) jsonDefaults
NSMutableDictionary *colors;
int i;

calendarCategories = [categoryLabels allValues];
calendarCategories = [calendarCategoryLabels allValues];
colors = [NSMutableDictionary dictionaryWithCapacity: [calendarCategories count]];

for (i = 0; i < [calendarCategories count]; i++)
Expand All @@ -311,18 +338,41 @@ - (NSString *) jsonDefaults
//
// Populate default contact categories, based on the user's preferred language
//
if (![defaults contactsCategories])
if (![[defaults source] objectForKey: @"SOGoContactsCategories"])
{
NSArray *contactsCategories;

contactsCategories = [[[[self labelForKey: @"contacts_category_labels" withResourceManager: [preferencesProduct resourceManager]]
componentsSeparatedByString: @","] trimmedComponents]
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
contactsCategoriesLabels = [self _localizedContactsLabels];

if((contactsCategories = [defaults contactsCategories]))
{
// Contact categories are taken from SOGo's configuration or SOGoDefaults.plist

NSMutableArray *filteredContactsCategories;
NSString *label, *localizedLabel;
int count, max;

if (!contactsCategories)
contactsCategories = [NSArray array];
max = [contactsCategories count];
filteredContactsCategories = [NSMutableArray arrayWithCapacity: max];

for (count = 0; count < max; count++)
{
label = [contactsCategories objectAtIndex: count];
if (!(localizedLabel = [contactsCategoriesLabels objectForKey: label]))
{
localizedLabel = label;
}
[filteredContactsCategories addObject: localizedLabel];
}

[defaults setContactsCategories: filteredContactsCategories];
}
else
{
// Contact categories are taken from localizable strings

[defaults setContactsCategories: contactsCategories];
[defaults setContactsCategories: [contactsCategoriesLabels allValues]];
}
}

if (![[defaults source] objectForKey: @"SOGoMailAddOutgoingAddresses"])
Expand Down
59 changes: 52 additions & 7 deletions UI/PreferencesUI/UIxPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -909,18 +909,63 @@ - (NSString *) defaultCalendarCategoriesColors
//
// Used by templates
//
- (NSDictionary *) _localizedContactsLabels
{
NSArray *categoryLabels, *localizedCategoryLabels;
NSDictionary *labelsDictionary;

labelsDictionary = nil;
localizedCategoryLabels = [[self labelForKey: @"contacts_category_labels"
withResourceManager: [self resourceManager]]
componentsSeparatedByString: @","];
categoryLabels = [[[self resourceManager]
stringForKey: @"contacts_category_labels"
inTableNamed: nil
withDefaultValue: @""
languages: [NSArray arrayWithObject: @"English"]]
componentsSeparatedByString: @","];

if ([localizedCategoryLabels count] == [categoryLabels count])
labelsDictionary = [NSDictionary dictionaryWithObjects: localizedCategoryLabels
forKeys: categoryLabels];
else
[self logWithFormat: @"ERROR: localizable strings contacts_category_labels is incorrect for language %@",
[[[context activeUser] userDefaults] language]];

return labelsDictionary;
}

- (NSString *) defaultContactsCategories
{
NSArray *contactsCategories;
NSArray *labels;
NSDictionary *localizedLabels;
NSMutableArray *defaultCategoriesLabels;
NSString *label, *localizedLabel;
unsigned int i;

localizedLabels = [self _localizedContactsLabels];
labels = [[SOGoSystemDefaults sharedSystemDefaults] contactsCategories];
defaultCategoriesLabels = [NSMutableArray array];

contactsCategories = [[[[self labelForKey: @"contacts_category_labels" withResourceManager: [self resourceManager]]
componentsSeparatedByString: @","] trimmedComponents]
sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)];
if(labels)
{
for (i = 0; i < [labels count]; i++)
{
label = [labels objectAtIndex: i];
if (!(localizedLabel = [localizedLabels objectForKey: label]))
{
localizedLabel = label;
}
[defaultCategoriesLabels addObject: localizedLabel];
}
}
else
{
defaultCategoriesLabels = [localizedLabels allValues];
}

if (!contactsCategories)
contactsCategories = [NSArray array];

return [contactsCategories jsonRepresentation];
return [defaultCategoriesLabels jsonRepresentation];
}

//
Expand Down

0 comments on commit 26c7462

Please sign in to comment.