2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import <Adium/AIContactControllerProtocol.h>
18 #import <Adium/AIPreferenceControllerProtocol.h>
19 #import "ESStatusSort.h"
20 #import <AIUtilities/AIDictionaryAdditions.h>
21 #import <Adium/AIListObject.h>
22 #import <Adium/AILocalizationTextField.h>
24 #define STATUS_SORT_DEFAULT_PREFS @"StatusSortDefaults"
26 #define KEY_GROUP_AVAILABLE @"Status:Group Available"
27 #define KEY_GROUP_MOBILE @"Status:Group Mobile"
28 #define KEY_GROUP_UNAVAILABLE @"Status:Group Unavailable"
29 #define KEY_GROUP_AWAY @"Status:Group Away"
30 #define KEY_GROUP_IDLE @"Status:Group Idle"
31 #define KEY_GROUP_IDLE_AND_AWAY @"Status:Group Idle+Away"
32 #define KEY_SORT_IDLE_TIME @"Status:Sort by Idle Time"
33 #define KEY_RESOLVE_ALPHABETICALLY @"Status:Resolve Alphabetically"
34 #define KEY_SORT_ORDER @"Status:Sort Order"
35 #define KEY_RESOLVE_BY_LAST_NAME @"Status:Resolve Alphabetically By Last Name"
37 #define AVAILABLE AILocalizedString(@"Available",nil)
38 #define AWAY AILocalizedString(@"Away",nil)
39 #define IDLE AILocalizedString(@"Idle",nil)
40 #define AWAY_AND_IDLE AILocalizedString(@"Away and Idle",nil)
41 #define UNAVAILABLE AILocalizedString(@"Unavailable",nil)
42 #define OTHER_UNAVAILABLE AILocalizedString(@"Other Unavailable",nil)
43 #define ONLINE AILocalizedString(@"Online",nil)
44 #define MOBILE AILocalizedString(@"Mobile",nil)
46 #define STATUS_DRAG_TYPE @"Status Sort"
56 MAX_SORT_ORDER_DIMENSION
59 static BOOL groupAvailable;
60 static BOOL groupMobile;
61 static BOOL groupUnavailable;
62 static BOOL groupAway;
63 static BOOL groupIdle;
64 static BOOL groupIdleAndAway;
65 static BOOL sortIdleTime;
67 static BOOL resolveAlphabetically;
68 static BOOL resolveAlphabeticallyByLastName;
70 static int sortOrder[MAX_SORT_ORDER_DIMENSION];
71 static int sizeOfSortOrder;
73 @interface ESStatusSort (PRIVATE)
74 - (void)configureControlDimming;
75 - (void)pruneAndSetSortOrderFromArray:(NSArray *)sortOrderArray;
80 * @brief AISortController to sort by contacts and groups
82 * Extensive configuration is allowed.
84 @implementation ESStatusSort
87 * @brief Did become active first time
89 * Called only once; gives the sort controller an opportunity to set defaults and load preferences lazily.
91 - (void)didBecomeActiveFirstTime
93 //Register our default preferences
94 [[adium preferenceController] registerDefaults:[NSDictionary dictionaryNamed:STATUS_SORT_DEFAULT_PREFS
95 forClass:[self class]]
96 forGroup:PREF_GROUP_CONTACT_SORTING];
98 //Load our preferences
99 NSDictionary *prefDict = [[adium preferenceController] preferencesForGroup:PREF_GROUP_CONTACT_SORTING];
101 groupAvailable = [[prefDict objectForKey:KEY_GROUP_AVAILABLE] boolValue];
102 groupMobile = [[prefDict objectForKey:KEY_GROUP_MOBILE] boolValue];
103 groupUnavailable = [[prefDict objectForKey:KEY_GROUP_UNAVAILABLE] boolValue];
105 groupAway = [[prefDict objectForKey:KEY_GROUP_AWAY] boolValue];
106 groupIdle = [[prefDict objectForKey:KEY_GROUP_IDLE] boolValue];
107 groupIdleAndAway = [[prefDict objectForKey:KEY_GROUP_IDLE_AND_AWAY] boolValue];
109 sortIdleTime = [[prefDict objectForKey:KEY_SORT_IDLE_TIME] boolValue];
110 resolveAlphabetically = [[prefDict objectForKey:KEY_RESOLVE_ALPHABETICALLY] boolValue];
111 resolveAlphabeticallyByLastName = [[prefDict objectForKey:KEY_RESOLVE_BY_LAST_NAME] boolValue];
113 [self pruneAndSetSortOrderFromArray:[prefDict objectForKey:KEY_SORT_ORDER]];
117 * @brief Determines how the statusSort() method will operate.
119 * The sortOrder array, when it is done, contains, in order, the statuses which will be sorted upon.
121 * @param sortOrderArray An <tt>NSArray</tt> of <tt>NSNumber</tt>s whose values are Status_Sort_Type
123 - (void)pruneAndSetSortOrderFromArray:(NSArray *)sortOrderArray
125 NSEnumerator *enumerator;
126 NSNumber *sortTypeNumber;
129 for (i = 0; i < MAX_SORT_ORDER_DIMENSION; i++) {
135 //Enumerate the ordering array. For all sort types which are valid given the active sorting types,
136 //add to sortOrder[]. Finalize sortOrder with -1.
138 BOOL groupIdleOrIdleTime = (groupIdle || sortIdleTime);
140 enumerator = [sortOrderArray objectEnumerator];
141 while ((sortTypeNumber = [enumerator nextObject])) {
142 switch ([sortTypeNumber intValue]) {
144 /* Group available if:
146 Group all unavailable, or
147 Group separetely the idle and the away (such that the remaining alternative is Available)
149 if (groupAvailable ||
151 (/*!groupUnavailable &&*/ groupAway && groupIdleOrIdleTime)) sortOrder[i++] = Available;
155 if (!groupUnavailable && groupAway) sortOrder[i++] = Away;
159 if ((!groupUnavailable && groupIdle) || sortIdleTime) sortOrder[i++] = Idle;
163 if (!groupUnavailable && groupIdleAndAway) sortOrder[i++] = Away_And_Idle;
167 //If one of groupAway or groupIdle is off, or we need a generic unavailable sort
168 if (groupUnavailable ||
169 ((groupAvailable && (!groupAway || !groupIdleOrIdleTime)))) {
170 sortOrder[i++] = Unavailable;
175 /* Show Online category if:
176 We aren't grouping all the available ones (this would imply grouping unavailable)
177 We aren't grouping all the unavailable ones (this would imply grouping available)
178 We aren't grouping both the away and the idle ones (this would imply grouping available)
180 if (!groupAvailable && !groupUnavailable && !(groupAway && (groupIdleOrIdleTime))) {
181 sortOrder[i++] = Online;
186 if (groupAvailable && groupMobile) {
187 sortOrder[i++] = Mobile;
197 [tableView_sortOrder reloadData];
201 * @brief Non-localized identifier
203 - (NSString *)identifier{
208 * @brief Localized display name
210 - (NSString *)displayName{
211 return AILocalizedString(@"Sort Contacts by Status",nil);
215 * @brief Status keys which, when changed, should trigger a resort
217 - (NSSet *)statusKeysRequiringResort{
218 return [NSSet setWithObjects:@"Online",@"Idle",@"StatusType",@"IsMobile",nil];
222 * @brief Attribute keys which, when changed, should trigger a resort
224 - (NSSet *)attributeKeysRequiringResort{
225 return [NSSet setWithObject:@"Display Name"];
229 * @brief Can the user manually reorder when this sort controller is active?
231 * The status sort can sort within status groupings either manually or alphabetically. Only the former should allow user reordering.
233 - (BOOL)canSortManually {
234 return !resolveAlphabetically;
238 #pragma mark Configuration
240 * @brief Window title when configuring the sort
242 * Subclasses should provide a title for configuring the sort only if configuration is possible.
243 * @result Localized title. If nil, the menu item will be disabled.
245 - (NSString *)configureSortWindowTitle{
246 return AILocalizedString(@"Configure Status Sort",nil);
250 * @brief Nib name for configuration
252 - (NSString *)configureNibName{
253 return @"StatusSortConfiguration";
257 * @brief View did load
261 [checkBox_groupAvailable setState:groupAvailable];
262 [checkBox_groupMobileSeparately setState:groupMobile];
263 [checkBox_groupAway setState:groupAway];
264 [checkBox_groupIdle setState:groupIdle];
265 [checkBox_groupIdleAndAway setState:groupIdleAndAway];
266 [checkBox_sortIdleTime setState:sortIdleTime];
267 [checkBox_alphabeticallyByLastName setState:resolveAlphabeticallyByLastName];
269 [buttonCell_alphabetically setState:(resolveAlphabetically ? NSOnState : NSOffState)];
270 [buttonCell_manually setState:(resolveAlphabetically ? NSOffState : NSOnState)];
272 [buttonCell_allUnavailable setState:(groupUnavailable ? NSOnState : NSOffState)];
273 [buttonCell_separateUnavailable setState:(groupUnavailable ? NSOffState : NSOnState)];
275 [self configureControlDimming];
277 [tableView_sortOrder setDataSource:self];
278 [tableView_sortOrder setDelegate:self];
279 [tableView_sortOrder registerForDraggedTypes:[NSArray arrayWithObject:STATUS_DRAG_TYPE]];
283 * @brief Preference changed
285 * Sort controllers should live update as preferences change.
287 - (IBAction)changePreference:(id)sender
289 NSArray *sortOrderArray = [[adium preferenceController] preferenceForKey:KEY_SORT_ORDER
290 group:PREF_GROUP_CONTACT_SORTING];
291 if (sender == checkBox_groupAvailable) {
292 groupAvailable = [sender state];
293 [[adium preferenceController] setPreference:[NSNumber numberWithBool:groupAvailable]
294 forKey:KEY_GROUP_AVAILABLE
295 group:PREF_GROUP_CONTACT_SORTING];
297 [self configureControlDimming];
299 } else if (sender == checkBox_groupMobileSeparately) {
300 groupMobile = [sender state];
301 [[adium preferenceController] setPreference:[NSNumber numberWithBool:groupMobile]
302 forKey:KEY_GROUP_MOBILE
303 group:PREF_GROUP_CONTACT_SORTING];
305 //Ensure the mobile item is in our sort order array, as the old defaults didn't include it
306 if ([sortOrderArray indexOfObject:[NSNumber numberWithInt:Mobile]] == NSNotFound) {
307 NSMutableArray *newSortOrderArray = [[sortOrderArray mutableCopy] autorelease];
308 [newSortOrderArray addObject:[NSNumber numberWithInt:Mobile]];
310 [[adium preferenceController] setPreference:newSortOrderArray
311 forKey:KEY_SORT_ORDER
312 group:PREF_GROUP_CONTACT_SORTING];
314 sortOrderArray = newSortOrderArray;
317 } else if (sender == checkBox_groupAway) {
318 groupAway = [sender state];
319 [[adium preferenceController] setPreference:[NSNumber numberWithBool:groupAway]
320 forKey:KEY_GROUP_AWAY
321 group:PREF_GROUP_CONTACT_SORTING];
322 } else if (sender == checkBox_groupIdle) {
323 groupIdle = [sender state];
324 [[adium preferenceController] setPreference:[NSNumber numberWithBool:groupIdle]
325 forKey:KEY_GROUP_IDLE
326 group:PREF_GROUP_CONTACT_SORTING];
328 } else if (sender == checkBox_groupIdleAndAway) {
329 groupIdleAndAway = [sender state];
330 [[adium preferenceController] setPreference:[NSNumber numberWithBool:groupIdleAndAway]
331 forKey:KEY_GROUP_IDLE_AND_AWAY
332 group:PREF_GROUP_CONTACT_SORTING];
334 } else if (sender == checkBox_sortIdleTime) {
335 sortIdleTime = [sender state];
336 [[adium preferenceController] setPreference:[NSNumber numberWithBool:sortIdleTime]
337 forKey:KEY_SORT_IDLE_TIME
338 group:PREF_GROUP_CONTACT_SORTING];
339 } else if (sender == matrix_resolution) {
340 id selectedCell = [sender selectedCell];
342 resolveAlphabetically = (selectedCell == buttonCell_alphabetically);
343 [[adium preferenceController] setPreference:[NSNumber numberWithBool:resolveAlphabetically]
344 forKey:KEY_RESOLVE_ALPHABETICALLY
345 group:PREF_GROUP_CONTACT_SORTING];
347 [self configureControlDimming];
349 } else if (sender == matrix_unavailableGrouping) {
350 id selectedCell = [sender selectedCell];
352 groupUnavailable = (selectedCell == buttonCell_allUnavailable);
353 [[adium preferenceController] setPreference:[NSNumber numberWithBool:groupUnavailable]
354 forKey:KEY_GROUP_UNAVAILABLE
355 group:PREF_GROUP_CONTACT_SORTING];
357 [self configureControlDimming];
359 } else if (sender == checkBox_alphabeticallyByLastName) {
360 resolveAlphabeticallyByLastName = [sender state];
361 [[adium preferenceController] setPreference:[NSNumber numberWithBool:resolveAlphabeticallyByLastName]
362 forKey:KEY_RESOLVE_BY_LAST_NAME
363 group:PREF_GROUP_CONTACT_SORTING];
366 [self pruneAndSetSortOrderFromArray:sortOrderArray];
368 [[adium contactController] sortContactList];
372 * @brief Configure control dimming
374 - (void)configureControlDimming
376 [checkBox_alphabeticallyByLastName setEnabled:resolveAlphabetically];
377 [checkBox_groupAway setEnabled:!groupUnavailable];
378 [checkBox_groupIdle setEnabled:!groupUnavailable];
379 [checkBox_groupIdleAndAway setEnabled:!groupUnavailable];
381 [checkBox_groupMobileSeparately setEnabled:groupAvailable];
384 #pragma mark Sort Order Tableview datasource
386 * @brief Table view number of rows
388 - (int)numberOfRowsInTableView:(NSTableView *)tableView
390 return sizeOfSortOrder;
394 * @brief Table view object value
396 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
398 switch (sortOrder[rowIndex]) {
412 return AWAY_AND_IDLE;
416 //Unavailable is always the same sort, but to the user it can be either "Unavailable" or "Other Unavailable"
417 //depending upon what other options are active. The test here is purely cosmetic.
418 return ((!sortIdleTime && (groupUnavailable || !(groupAway || groupIdle || groupIdleAndAway))) ?
436 * @brief The NSNumber Status_Sort_Type which corresponds to a string
438 * @param string A string such as AVAILABLE or AWAY (localized)
439 * @result The NSNumber Status_Sort_Type which corresponds to the string
441 - (NSNumber *)numberForString:(NSString *)string
445 if ([string isEqualToString:AVAILABLE]) {
446 equivalent = Available;
447 } else if ([string isEqualToString:AWAY]) {
449 } else if ([string isEqualToString:IDLE]) {
451 } else if ([string isEqualToString:AWAY_AND_IDLE]) {
452 equivalent = Away_And_Idle;
453 } else if ([string isEqualToString:UNAVAILABLE] || ([string isEqualToString:OTHER_UNAVAILABLE])) {
454 equivalent = Unavailable;
455 } else if ([string isEqualToString:ONLINE]) {
457 } else if ([string isEqualToString:MOBILE]) {
461 return [NSNumber numberWithInt:equivalent];
465 * @brief Table view write rows
467 - (BOOL)tableView:(NSTableView *)tableView writeRows:(NSArray *)rows toPasteboard:(NSPasteboard *)pboard
469 [pboard declareTypes:[NSArray arrayWithObject:STATUS_DRAG_TYPE] owner:self];
471 //Build a list of all the highlighted aways
472 NSString *dragItem = [self tableView:tableView
473 objectValueForTableColumn:nil
474 row:[[rows objectAtIndex:0] intValue]];
476 //put it on the pasteboard
477 [pboard setString:dragItem forType:STATUS_DRAG_TYPE];
483 * @brief Table view validate drop
485 - (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)operation
487 NSString *avaliableType = [[info draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObject:STATUS_DRAG_TYPE]];
489 if ([avaliableType isEqualToString:STATUS_DRAG_TYPE]) {
490 if (operation == NSTableViewDropAbove && row != -1) {
491 return NSDragOperationMove;
493 return NSDragOperationNone;
497 return NSDragOperationNone;
501 * @brief Table view accept drop
503 - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info row:(int)row dropOperation:(NSTableViewDropOperation)operation
505 NSString *availableType = [[info draggingPasteboard] availableTypeFromArray:[NSArray arrayWithObject:STATUS_DRAG_TYPE]];
507 if ([availableType isEqualToString:STATUS_DRAG_TYPE]) {
508 NSString *item = [[info draggingPasteboard] stringForType:STATUS_DRAG_TYPE];
510 //Remember, sortOrderPref contains all possible sorting types, not just the ones presently visible in the table!
511 NSMutableArray *sortOrderPref = [[[adium preferenceController] preferenceForKey:KEY_SORT_ORDER
512 group:PREF_GROUP_CONTACT_SORTING] mutableCopy];
513 NSNumber *sortNumber = [self numberForString:item];
515 //Remove it from our array
516 [sortOrderPref removeObject:sortNumber];
518 if (row == [tableView numberOfRows]) {
519 //Dropped at the bottom
520 [sortOrderPref addObject:sortNumber];
522 //Find the object which will end up just below it
523 int targetIndex = [sortOrderPref indexOfObject:[self numberForString:[self tableView:tableView
524 objectValueForTableColumn:nil
526 if (targetIndex != NSNotFound) {
528 [sortOrderPref insertObject:sortNumber atIndex:targetIndex];
530 //Dropped at the bottom
531 [sortOrderPref addObject:sortNumber];
535 [[adium preferenceController] setPreference:sortOrderPref
536 forKey:KEY_SORT_ORDER
537 group:PREF_GROUP_CONTACT_SORTING];
539 [self pruneAndSetSortOrderFromArray:sortOrderPref];
541 //Select and scroll to the dragged object
542 [tableView reloadData];
544 [[adium contactController] sortContactList];
546 [sortOrderPref release];
557 * @brief The status sort method itself
559 * It's magic... but it's efficient magic!
561 int statusSort(id objectA, id objectB, BOOL groups)
564 //Keep groups in manual order
565 if ([objectA orderIndex] > [objectB orderIndex]) {
566 return NSOrderedDescending;
568 return NSOrderedAscending;
572 AIStatusSummary statusSummaryA = [objectA statusSummary];
573 AIStatusSummary statusSummaryB = [objectB statusSummary];
575 //Always sort offline contacts to the bottom
576 BOOL onlineA = (statusSummaryA != AIOfflineStatus);
577 BOOL onlineB = (statusSummaryB != AIOfflineStatus);
578 if (!onlineB && onlineA) {
579 return NSOrderedAscending;
580 } else if (!onlineA && onlineB) {
581 return NSOrderedDescending;
584 //We only need to start looking at status for sorting if both are online;
585 //otherwise, skip to resolving alphabetically or manually
586 if (onlineA && onlineB) {
590 BOOL definitelyFinishedIfSuccessful, onlyIfWeAintGotNothinBetter, status;
595 //Get the away state and idle times now rather than potentially doing each twice below
596 away[0] = ((statusSummaryA == AIAwayStatus) || (statusSummaryA == AIAwayAndIdleStatus));
597 away[1] = ((statusSummaryB == AIAwayStatus) || (statusSummaryB == AIAwayAndIdleStatus));
599 idle[0] = (((statusSummaryA == AIIdleStatus) || (statusSummaryA == AIAwayAndIdleStatus)) ?
600 [objectA integerStatusObjectForKey:@"Idle" fromAnyContainedObject:NO] :
602 idle[1] = (((statusSummaryB == AIIdleStatus) || (statusSummaryB == AIAwayAndIdleStatus)) ?
603 [objectB integerStatusObjectForKey:@"Idle" fromAnyContainedObject:NO] :
607 mobile[0] = [objectA isMobile];
608 mobile[1] = [objectB isMobile];
611 for (objectCounter = 0; objectCounter < 2; objectCounter++) {
612 sortIndex[objectCounter] = 999;
614 for (i = 0; i < sizeOfSortOrder ; i++) {
615 //Reset the internal bookkeeping
616 onlyIfWeAintGotNothinBetter = NO;
617 definitelyFinishedIfSuccessful = NO;
619 //Determine the state for the status this level of sorting cares about
620 switch (sortOrder[i]) {
622 status = (!away[objectCounter] && !idle[objectCounter]); // TRUE if A is available
626 status = mobile[objectCounter];
627 definitelyFinishedIfSuccessful = YES;
631 status = away[objectCounter];
635 status = (idle[objectCounter] != 0);
639 status = away[objectCounter] && (idle[objectCounter] != 0);
640 definitelyFinishedIfSuccessful = YES;
644 status = away[objectCounter] || (idle[objectCounter] != 0);
645 onlyIfWeAintGotNothinBetter = YES;
649 status = YES; //we can only get here if the person is online, anyways
650 onlyIfWeAintGotNothinBetter = YES;
657 //If the object has the desired status and we want to use it, store the new index it should go to
659 (!onlyIfWeAintGotNothinBetter || (sortIndex[objectCounter] == 999))) {
660 sortIndex[objectCounter] = i;
662 //If definitelyFinishedIfSuccessful is YES, we're done sorting as soon as something fits
664 if (definitelyFinishedIfSuccessful) break;
667 } //End for object loop
669 if (sortIndex[0] > sortIndex[1]) {
670 return NSOrderedDescending;
671 } else if (sortIndex[1] > sortIndex[0]) {
672 return NSOrderedAscending;
675 //If one idle time is greater than the other and we want to sort on that basis, we have an ordering
677 //Ordering is determined if either has a idle time and their idle times are not identical
678 if (((idle[0] != 0) || (idle[1] != 0)) && (idle[0] != idle[1])) {
679 if (idle[0] > idle[1]) {
680 return NSOrderedDescending;
682 return NSOrderedAscending;
688 if (!resolveAlphabetically) {
689 //If we don't want to resolve alphabetically, we do want to resolve by manual ordering if possible
690 float orderIndexA = [objectA orderIndex];
691 float orderIndexB = [objectB orderIndex];
693 if (orderIndexA > orderIndexB) {
694 return NSOrderedDescending;
695 } else if (orderIndexA < orderIndexB) {
696 return NSOrderedAscending;
700 //If we made it here, resolve the ordering alphabetically, which is guaranteed to be consistent.
701 //Note that this sort should -never- return NSOrderedSame, so as a last resort we use the internalObjectID.
702 NSComparisonResult returnValue;
704 if (resolveAlphabeticallyByLastName) {
705 //Split the displayname into parts by spacing and use the last part, the "last name," for comparison
706 NSString *space = @" ";
707 NSString *displayNameA = [objectA displayName];
708 NSString *displayNameB = [objectB displayName];
709 NSArray *componentsA = [displayNameA componentsSeparatedByString:space];
710 NSArray *componentsB = [displayNameB componentsSeparatedByString:space];
712 returnValue = [[componentsA lastObject] caseInsensitiveCompare:[componentsB lastObject]];
713 //If the last names are the same, compare the whole object, which will amount to sorting these objects
715 if (returnValue == NSOrderedSame) {
716 returnValue = [displayNameA caseInsensitiveCompare:displayNameB];
717 if (returnValue == NSOrderedSame) {
718 returnValue = [[objectA internalObjectID] caseInsensitiveCompare:[objectB internalObjectID]];
722 returnValue = [[objectA longDisplayName] caseInsensitiveCompare:[objectB longDisplayName]];
723 if (returnValue == NSOrderedSame) {
724 returnValue = [[objectA internalObjectID] caseInsensitiveCompare:[objectB internalObjectID]];
728 return (returnValue);
733 * @brief Sort function
735 - (sortfunc)sortFunction{