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