+bool TabCompleter::eventFilter(QObject *obj, QEvent *event) {
+ if(obj != inputLine || event->type() != QEvent::KeyPress)
+ return QObject::eventFilter(obj, event);
+
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+
+ if(keyEvent->key() == Qt::Key_Tab) {
+ complete();
+ return true;
+ } else {
+ reset();
+ return false;
+ }
+}
+
+// this determines the sort order
+bool TabCompleter::CompletionKey::operator<(const CompletionKey &other) const {
+ IrcUser *thisUser = _currentNetwork->ircUser(this->nick);
+ if(thisUser && _currentNetwork->isMe(thisUser))
+ return false;
+
+ IrcUser *thatUser = _currentNetwork->ircUser(other.nick);
+ if(thatUser && _currentNetwork->isMe(thatUser))
+ return true;
+
+ if(!thisUser || !thatUser)
+ return QString::localeAwareCompare(this->nick, other.nick) < 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;
+
+ return QString::localeAwareCompare(this->nick, other.nick) < 0;
+}