diff --git a/ChangeLog b/ChangeLog index 558a959d5..d622b464a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-09-16 Wolfgang Sourdeau + * SoObjects/SOGo/SOGoFolder.m ([SOGoFolder -compare:otherFolder]): + new method for sorting folders. The folders are compared based on + their ownership, whether they are a main folder and finally + depending on their display name. + * SoObjects/SOGo/SOGoObject.m ([SOGoObject -pathArrayToSOGoObject]): do not reorder the paths if the third element is an instance of NSNull. diff --git a/SoObjects/SOGo/SOGoFolder.m b/SoObjects/SOGo/SOGoFolder.m index e0845f826..9341e8488 100644 --- a/SoObjects/SOGo/SOGoFolder.m +++ b/SoObjects/SOGo/SOGoFolder.m @@ -685,6 +685,77 @@ static NSString *defaultUserID = @""; return obj; } +- (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: (SOGoFolder *) 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