diff --git a/ChangeLog b/ChangeLog index 4a9d1b46d..62509d775 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-03-23 Francis Lachapelle + + * UI/PreferencesUI/UIxPreferences.m (-timeZonesList): we make use + of the new method [iCalTimeZone knownTimeZoneNames] instead of + [NSTimeZone knownTimeZoneNames] to avoid listing tons of useless timezones. + 2011-03-22 Wolfgang Sourdeau * OpenChange/MAPIStoreCalendarMessage.m (-init): new method to diff --git a/SOPE/NGCards/ChangeLog b/SOPE/NGCards/ChangeLog index 97549f4ab..156882b82 100644 --- a/SOPE/NGCards/ChangeLog +++ b/SOPE/NGCards/ChangeLog @@ -1,9 +1,15 @@ +2011-03-23 francis + 2011-03-23 Francis Lachapelle * iCalRepeatableEntityObject.m (-removeAllExceptionDates): don't use the method "exceptionDates" since it returns an array of strings and not CardElement instances. + * iCalTimeZone.m (+knownTimeZoneNames): new class method to + retrieve the timezone names. Used in replacement of the same + method in NSTimeZone. + 2011-03-22 Wolfgang Sourdeau * iCalEvent.m (-firstRecurrenceStartDate): new method that makes diff --git a/SOPE/NGCards/iCalTimeZone.h b/SOPE/NGCards/iCalTimeZone.h index a44bddbee..150377e87 100644 --- a/SOPE/NGCards/iCalTimeZone.h +++ b/SOPE/NGCards/iCalTimeZone.h @@ -33,6 +33,7 @@ @interface iCalTimeZone : CardGroup + (iCalTimeZone *) timeZoneForName: (NSString *) theName; ++ (NSArray *) knownTimeZoneNames; - (NSString *) tzId; - (iCalTimeZonePeriod *) periodForDate: (NSCalendarDate *) date; - (NSCalendarDate *) computedDateForDate: (NSCalendarDate *) theDate; diff --git a/SOPE/NGCards/iCalTimeZone.m b/SOPE/NGCards/iCalTimeZone.m index 156110f63..310983c94 100644 --- a/SOPE/NGCards/iCalTimeZone.m +++ b/SOPE/NGCards/iCalTimeZone.m @@ -41,6 +41,7 @@ #import "iCalTimeZone.h" static NSMutableDictionary *cache; +static NSArray *knownTimeZones; @implementation iCalTimeZone @@ -106,6 +107,62 @@ static NSMutableDictionary *cache; return o; } +/** + * Fetch the names of the available timezones for which we have a + * vTimeZone definition (.ics). + * @return an array of timezones names. + * @see [NSTimeZone knownTimeZoneNames] + */ ++ (NSArray *) knownTimeZoneNames +{ + NSFileManager *fm; + NSEnumerator *e; + NSDirectoryEnumerator *zones; + NSArray *paths; + NSMutableArray *timeZoneNames; + NSString *path, *zone, *zonePath; + NSRange ext; + BOOL b; + + timeZoneNames = knownTimeZones; + + if (!timeZoneNames) + { + timeZoneNames = [NSMutableArray new]; + + paths = NSSearchPathForDirectoriesInDomains(NSAllLibrariesDirectory, + NSAllDomainsMask, + YES); + fm = [NSFileManager defaultManager]; + + if ([paths count] > 0) + { + e = [paths objectEnumerator]; + while ((path = [e nextObject])) + { + path = [NSString stringWithFormat: @"%@/Libraries/Resources/NGCards/TimeZones", path]; + if ([fm fileExistsAtPath: path isDirectory: &b] && b) + { + zones = [fm enumeratorAtPath: path]; + while ((zone = [zones nextObject])) { + zonePath = [NSString stringWithFormat: @"%@/%@", path, zone]; + if ([fm fileExistsAtPath: zonePath isDirectory: &b] && !b) + { + ext = [zone rangeOfString: @".ics"]; + zone = [zone substringToIndex: ext.location]; + [timeZoneNames addObject: zone]; + } + } + } + } + } + knownTimeZones = [timeZoneNames sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + [knownTimeZones retain]; + } + + return timeZoneNames; +} + - (Class) classForTag: (NSString *) classTag { Class tagClass; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index dadf9792e..685c44785 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -32,6 +32,8 @@ #import +#import + #import #import #import @@ -149,8 +151,7 @@ - (NSArray *) timeZonesList { - return [[NSTimeZone knownTimeZoneNames] - sortedArrayUsingSelector: @selector (localizedCaseInsensitiveCompare:)]; + return [iCalTimeZone knownTimeZoneNames]; } - (NSString *) userTimeZone