From 738fb6d3d40a10426dbf955ddd8d2cc1b8ad1ff6 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 7 Nov 2007 23:35:56 +0000 Subject: [PATCH] Monotone-Parent: 21e396c8605b155acfec0b2ce58b23eb13319cf3 Monotone-Revision: 2ef2c3374f2dd549c494c4faf0429f5fe6e13f6d Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-11-07T23:35:56 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 ++ SoObjects/SOGo/SOGoFolder.h | 3 ++ SoObjects/SOGo/SOGoFolder.m | 72 ++++++++++++++++++++++++++++++++++ SoObjects/SOGo/SOGoGCSFolder.h | 3 -- SoObjects/SOGo/SOGoGCSFolder.m | 71 --------------------------------- 5 files changed, 78 insertions(+), 74 deletions(-) diff --git a/ChangeLog b/ChangeLog index 754a4edf4..392b9c753 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2007-11-07 Wolfgang Sourdeau + * SoObjects/SOGo/SOGoGCSFolder.m ([-compare:otherFolder]): method + moved into the SOGoFolder class. + * SoObjects/Appointments/SOGoAppointmentObject.m ([SOGoAppointmentObject -saveContentString:_iCalinUIDs:_uids]): simplified method by directly building a similar appointment diff --git a/SoObjects/SOGo/SOGoFolder.h b/SoObjects/SOGo/SOGoFolder.h index ee5de48e4..1292b96e3 100644 --- a/SoObjects/SOGo/SOGoFolder.h +++ b/SoObjects/SOGo/SOGoFolder.h @@ -35,6 +35,9 @@ - (NSString *) folderType; +/* sorting */ +- (NSComparisonResult) compare: (id) otherFolder; + /* dav */ - (NSArray *) davNamespaces; diff --git a/SoObjects/SOGo/SOGoFolder.m b/SoObjects/SOGo/SOGoFolder.m index af83275ea..3f49d254f 100644 --- a/SoObjects/SOGo/SOGoFolder.m +++ b/SoObjects/SOGo/SOGoFolder.m @@ -113,6 +113,78 @@ return [[self davURL] absoluteString]; } +/* sorting */ +- (NSComparisonResult) _compareByOrigin: (SOGoFolder *) otherFolder +{ + NSArray *thisElements, *otherElements; + unsigned thisCount, otherCount; + NSComparisonResult comparison; + + thisElements = [nameInContainer componentsSeparatedByString: @"_"]; + otherElements = [[otherFolder nameInContainer] + componentsSeparatedByString: @"_"]; + thisCount = [thisElements count]; + otherCount = [otherElements count]; + if (thisCount == otherCount) + { + if (thisCount == 1) + comparison = NSOrderedSame; + else + comparison = [[thisElements objectAtIndex: 0] + compare: [otherElements objectAtIndex: 0]]; + } + else + { + if (thisCount > otherCount) + comparison = NSOrderedDescending; + else + comparison = NSOrderedAscending; + } + + return comparison; +} + +- (NSComparisonResult) _compareByNameInContainer: (SOGoFolder *) otherFolder +{ + NSString *otherName; + NSComparisonResult comparison; + + otherName = [otherFolder nameInContainer]; + if ([nameInContainer hasSuffix: @"personal"]) + { + if ([otherName hasSuffix: @"personal"]) + comparison = [nameInContainer compare: otherName]; + else + comparison = NSOrderedAscending; + } + else + { + if ([otherName hasSuffix: @"personal"]) + comparison = NSOrderedDescending; + else + comparison = NSOrderedSame; + } + + return comparison; +} + +- (NSComparisonResult) compare: (id) otherFolder +{ + NSComparisonResult comparison; + + comparison = [self _compareByOrigin: otherFolder]; + if (comparison == NSOrderedSame) + { + comparison = [self _compareByNameInContainer: otherFolder]; + if (comparison == NSOrderedSame) + comparison + = [[self displayName] + localizedCaseInsensitiveCompare: [otherFolder displayName]]; + } + + return comparison; +} + /* WebDAV */ - (NSArray *) davNamespaces diff --git a/SoObjects/SOGo/SOGoGCSFolder.h b/SoObjects/SOGo/SOGoGCSFolder.h index 9e331452e..21fb8934a 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.h +++ b/SoObjects/SOGo/SOGoGCSFolder.h @@ -71,9 +71,6 @@ - (BOOL) folderIsMandatory; -/* sorting */ -- (NSComparisonResult) compare: (SOGoGCSFolder *) otherFolder; - - (BOOL) create; - (NSException *) delete; - (void) renameTo: (NSString *) newName; diff --git a/SoObjects/SOGo/SOGoGCSFolder.m b/SoObjects/SOGo/SOGoGCSFolder.m index 2caaa6878..42c5974a7 100644 --- a/SoObjects/SOGo/SOGoGCSFolder.m +++ b/SoObjects/SOGo/SOGoGCSFolder.m @@ -635,77 +635,6 @@ static NSString *defaultUserID = @""; return defaultUserID; } -- (NSComparisonResult) _compareByOrigin: (SOGoFolder *) otherFolder -{ - NSArray *thisElements, *otherElements; - unsigned thisCount, otherCount; - NSComparisonResult comparison; - - thisElements = [nameInContainer componentsSeparatedByString: @"_"]; - otherElements = [[otherFolder nameInContainer] - componentsSeparatedByString: @"_"]; - thisCount = [thisElements count]; - otherCount = [otherElements count]; - if (thisCount == otherCount) - { - if (thisCount == 1) - comparison = NSOrderedSame; - else - comparison = [[thisElements objectAtIndex: 0] - compare: [otherElements objectAtIndex: 0]]; - } - else - { - if (thisCount > otherCount) - comparison = NSOrderedDescending; - else - comparison = NSOrderedAscending; - } - - return comparison; -} - -- (NSComparisonResult) _compareByNameInContainer: (SOGoFolder *) otherFolder -{ - NSString *otherName; - NSComparisonResult comparison; - - otherName = [otherFolder nameInContainer]; - if ([nameInContainer hasSuffix: @"personal"]) - { - if ([otherName hasSuffix: @"personal"]) - comparison = [nameInContainer compare: otherName]; - else - comparison = NSOrderedAscending; - } - else - { - if ([otherName hasSuffix: @"personal"]) - comparison = NSOrderedDescending; - else - comparison = NSOrderedSame; - } - - return comparison; -} - -- (NSComparisonResult) compare: (SOGoGCSFolder *) otherFolder -{ - NSComparisonResult comparison; - - comparison = [self _compareByOrigin: otherFolder]; - if (comparison == NSOrderedSame) - { - comparison = [self _compareByNameInContainer: otherFolder]; - if (comparison == NSOrderedSame) - comparison - = [[self displayName] - localizedCaseInsensitiveCompare: [otherFolder displayName]]; - } - - return comparison; -} - /* description */ - (void) appendAttributesToDescription: (NSMutableString *) _ms