From 725878ebdbec019b874b5a761614bcf190177d67 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 6 Oct 2009 18:12:07 +0000 Subject: [PATCH] Proper system defaults fallback for preferences (Bug #145) Monotone-Parent: 86d5fda1266a9ae6071c1b0c48daa229594679fb Monotone-Revision: 33a4befb91778f46b962f6c895f7697b0d1df722 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2009-10-06T18:12:07 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 30 +++++++++++++ SoObjects/Mailer/SOGoMailObject+Draft.m | 4 +- SoObjects/SOGo/SOGoUser.h | 2 + SoObjects/SOGo/SOGoUser.m | 60 ++++++++++++++++++++++--- UI/PreferencesUI/UIxPreferences.m | 28 ++++-------- UI/Scheduler/UIxCalDayTable.h | 2 +- UI/Scheduler/UIxCalDayTable.m | 7 +-- UI/WebServerResources/UIxPreferences.js | 2 +- 8 files changed, 99 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index ffa451500..202df5592 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2009-10-06 Francis Lachapelle + + * SoObjects/SOGo/SOGoUser.m (_timeValue): improved parsing to + support single integers (not only the XY:00 form). + (-timeFormat): returns the user's time format or system + (SOGoTimeFormat) default if not defined. + (-replyPlacement): honor the system defaults (SOGoMailReplyPlacement). + (-signaturePlacement): honor the system defaults + (SOGoMailSignaturePlacement). + (-messageForwarding): honor the system defaults (SOGoMailMessageForwarding). + + * SoObjects/Mailer/SOGoMailObject+Draft.m (-contentForReply): + reply and signature placement properly honors system defaults + (SOGoMailReplyPlacement and SOGoMailSignaturePlacement). + + * UI/PreferencesUI/UIxPreferences.m (-userTimeFormat): honor the + system defaults through the SOGoUser class. + (-userDayStartTime): idem. + (-userDayEndTime): idem. + (-userMessageForwarding): idem. + (-repyPlacement): idem. + (-signaturePlacement): idem. + + * UI/Scheduler/UIxCalDayTable.m (-hoursToDisplay): honor the + system defaults through the SOGoUser class. + + * UI/WebServerResources/UIxPreferences.js (-initPreferences): fix + to properly set the initial status of the signature placement + select field. + 2009-10-05 Wolfgang Sourdeau * Tests/test-maildav.py (DAVMailCollectionTest._testFilter): fixed diff --git a/SoObjects/Mailer/SOGoMailObject+Draft.m b/SoObjects/Mailer/SOGoMailObject+Draft.m index f81f58734..c6e7983ba 100644 --- a/SoObjects/Mailer/SOGoMailObject+Draft.m +++ b/SoObjects/Mailer/SOGoMailObject+Draft.m @@ -175,8 +175,8 @@ inContext: context]; [page setSourceMail: self]; [page setOutlookMode: [self useOutlookStyleReplies]]; - [page setReplyPlacement: [[currentUser userDefaults] stringForKey: @"ReplyPlacement"]]; - [page setSignaturePlacement: [[currentUser userDefaults] stringForKey: @"SignaturePlacement"]]; + [page setReplyPlacement: [currentUser replyPlacement]]; + [page setSignaturePlacement: [currentUser signaturePlacement]]; return [[page generateResponse] contentAsString]; } diff --git a/SoObjects/SOGo/SOGoUser.h b/SoObjects/SOGo/SOGoUser.h index fb53377ac..80da3c315 100644 --- a/SoObjects/SOGo/SOGoUser.h +++ b/SoObjects/SOGo/SOGoUser.h @@ -117,6 +117,8 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (unsigned int) dayStartHour; - (unsigned int) dayEndHour; +- (NSString *) timeFormat; + - (NSCalendarDate *) firstWeekOfYearForDate: (NSCalendarDate *) date; - (unsigned int) weekNumberForDate: (NSCalendarDate *) date; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 6ceb75d83..fad71c6e5 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -58,6 +58,7 @@ static NSString *defaultReplyPlacement = nil; static NSString *defaultSignaturePlacement = nil; static NSString *defaultMessageForwarding = nil; static NSString *defaultMessageCheck = nil; +static NSString *defaultTimeFormat = nil; static NSArray *superUsernames = nil; static NSURL *SOGoProfileURL = nil; // static BOOL acceptAnyUser = NO; @@ -89,13 +90,19 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; static int _timeValue (NSString *key) { - int time; + int i, time; - if (key && [key length] > 1) - time = [[key substringToIndex: 2] intValue]; + if (key && [key length] > 0) + { + i = [key rangeOfString: @":"].location; + if (i != NSNotFound) + time = [[key substringToIndex: i] intValue]; + else + time = [key intValue]; + } else time = -1; - + return time; } @@ -191,6 +198,12 @@ _timeValue (NSString *key) if (!defaultMessageCheck) ASSIGN (defaultMessageCheck, @"manually"); } + if (!defaultTimeFormat) + { + ASSIGN (defaultTimeFormat, [ud stringForKey: @"SOGoTimeFormat"]); + if (!defaultTimeFormat) + ASSIGN (defaultTimeFormat, @"%H:00"); + } if (!superUsernames) ASSIGN (superUsernames, [ud arrayForKey: @"SOGoSuperUsernames"]); @@ -662,6 +675,17 @@ _timeValue (NSString *key) return limit; } +- (NSString *) timeFormat +{ + NSString *timeFormat; + + timeFormat = [[self userDefaults] stringForKey: @"TimeFormat"]; + if (!timeFormat) + timeFormat = defaultTimeFormat; + + return timeFormat; +} + - (NSCalendarDate *) firstWeekOfYearForDate: (NSCalendarDate *) date { NSString *firstWeekRule; @@ -891,17 +915,39 @@ _timeValue (NSString *key) - (NSString *) replyPlacement { - return [[self userDefaults] stringForKey: @"ReplyPlacement"]; + NSString *replyPlacement = [[self userDefaults] stringForKey: @"ReplyPlacement"]; + + if (!replyPlacement) + replyPlacement = defaultReplyPlacement; + + return replyPlacement; } - (NSString *) signaturePlacement { - return [[self userDefaults] stringForKey: @"SignaturePlacement"]; + NSString *signaturePlacement; + + if ([[self replyPlacement] isEqualToString: @"below"]) + // When replying to an email, if the reply is below the quoted text, + // the signature must also be below the quoted text. + signaturePlacement = @"below"; + else + { + signaturePlacement = [[self userDefaults] stringForKey: @"SignaturePlacement"]; + if (!signaturePlacement) + signaturePlacement = defaultSignaturePlacement; + } + + return signaturePlacement; } - (NSString *) messageForwarding { - return [[self userDefaults] stringForKey: @"MessageForwarding"]; + NSString *messageForwarding = [[self userDefaults] stringForKey: @"MessageForwarding"]; + if (!messageForwarding) + messageForwarding = defaultMessageForwarding; + + return messageForwarding; } /* folders */ diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 7c8685870..a6b33c156 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -290,7 +290,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSString *) userTimeFormat { - return [userDefaults objectForKey: @"TimeFormat"]; + return [user timeFormat]; } - (void) setUserTimeFormat: (NSString *) newFormat @@ -318,7 +318,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSString *) userWeekStartDay { - return [NSString stringWithFormat: @"%d", [user firstDayOfWeek]];; + return [NSString stringWithFormat: @"%d", [user firstDayOfWeek]]; } - (void) setUserWeekStartDay: (NSString *) newDay @@ -343,13 +343,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSString *) userDayStartTime { - NSString *time; - - time = [userDefaults objectForKey: @"DayStartTime"]; - if (!time) - time = @"08:00"; - - return time; + return [NSString stringWithFormat: @"%02d:00", [user dayStartHour]]; } - (void) setUserDayStartTime: (NSString *) newTime @@ -359,13 +353,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSString *) userDayEndTime { - NSString *time; - - time = [userDefaults objectForKey: @"DayEndTime"]; - if (!time) - time = @"18:00"; - - return time; + return [NSString stringWithFormat: @"%02d:00", [user dayEndHour]]; } - (void) setUserDayEndTime: (NSString *) newTime @@ -375,7 +363,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSArray *) firstWeekList { - return [NSArray arrayWithObjects: + return [NSArray arrayWithObjects: SOGoWeekStartJanuary1, SOGoWeekStartFirst4DayWeek, SOGoWeekStartFirstFullWeek, @@ -541,7 +529,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSString *) userMessageForwarding { - return [userDefaults stringForKey: @"MessageForwarding"]; + return [user messageForwarding]; } - (void) setUserMessageForwarding: (NSString *) newMessageForwarding @@ -591,7 +579,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSString *) userReplyPlacement { - return [userDefaults stringForKey: @"ReplyPlacement"]; + return [user replyPlacement]; } - (void) setUserReplyPlacement: (NSString *) newReplyPlacement @@ -612,7 +600,7 @@ static BOOL defaultShowSubscribedFoldersOnly = NO; - (NSString *) userSignaturePlacement { - return [userDefaults stringForKey: @"SignaturePlacement"]; + return [user signaturePlacement]; } - (NSArray *) composeMessagesType diff --git a/UI/Scheduler/UIxCalDayTable.h b/UI/Scheduler/UIxCalDayTable.h index e60d7a495..1ef5abcfd 100644 --- a/UI/Scheduler/UIxCalDayTable.h +++ b/UI/Scheduler/UIxCalDayTable.h @@ -44,7 +44,7 @@ NSArray *weekDays; SOGoDateFormatter *dateFormatter; NSUserDefaults *ud; - NSMutableString *timeFormat; + NSString *timeFormat; } - (void) setNumberOfDays: (NSNumber *) aNumber; diff --git a/UI/Scheduler/UIxCalDayTable.m b/UI/Scheduler/UIxCalDayTable.m index 6c4690a29..3945af985 100644 --- a/UI/Scheduler/UIxCalDayTable.m +++ b/UI/Scheduler/UIxCalDayTable.m @@ -120,11 +120,8 @@ { unsigned int currentHour, lastHour; - // For later - ud = [[context activeUser] userDefaults]; - timeFormat = [NSMutableString stringWithString: [ud stringForKey: @"TimeFormat"]]; - if (!timeFormat || [timeFormat length] == 0) - timeFormat = [NSMutableString stringWithString: @"%H:00"]; + // For later in method currentTableHour + timeFormat = [[context activeUser] timeFormat]; if (!hoursToDisplay) { diff --git a/UI/WebServerResources/UIxPreferences.js b/UI/WebServerResources/UIxPreferences.js index 77e5bf9f7..cec0349ff 100644 --- a/UI/WebServerResources/UIxPreferences.js +++ b/UI/WebServerResources/UIxPreferences.js @@ -81,8 +81,8 @@ function initPreferences() { if ($("composeMessagesType").value == 1) { $("replyPlacementList").selectedIndex = 0; $("replyPlacementList").disabled = 1; - onReplyPlacementListChange (); } + onReplyPlacementListChange (); } }