+// this determines the sort order
+bool TabCompleter::CompletionKey::operator<(const CompletionKey &other) const {
+ switch(_completionType) {
+ case UserTab:
+ {
+ IrcUser *thisUser = _currentNetwork->ircUser(this->contents);
+ if(thisUser && _currentNetwork->isMe(thisUser))
+ return false;
+
+ IrcUser *thatUser = _currentNetwork->ircUser(other.contents);
+ if(thatUser && _currentNetwork->isMe(thatUser))
+ return true;
+
+ if(!thisUser || !thatUser)
+ return QString::localeAwareCompare(this->contents, other.contents) < 0;
+
+ QDateTime thisSpokenTo = thisUser->lastSpokenTo(_currentBufferId);
+ QDateTime thatSpokenTo = thatUser->lastSpokenTo(_currentBufferId);
+
+ if(thisSpokenTo.isValid() || thatSpokenTo.isValid())
+ return thisSpokenTo > thatSpokenTo;
+
+ QDateTime thisTime = thisUser->lastChannelActivity(_currentBufferId);
+ QDateTime thatTime = thatUser->lastChannelActivity(_currentBufferId);
+
+ if(thisTime.isValid() || thatTime.isValid())
+ return thisTime > thatTime;
+ }
+ break;
+ case ChannelTab:
+ if(QString::compare(_currentBufferName, this->contents, Qt::CaseInsensitive) == 0)
+ return true;
+
+ if(QString::compare(_currentBufferName, other.contents, Qt::CaseInsensitive) == 0)
+ return false;
+ break;
+ default:
+ break;
+ }
+
+ return QString::localeAwareCompare(this->contents, other.contents) < 0;
+}