qa: Replace deprecated qVariantFromValue() by QVariant::fromValue()
[quassel.git] / src / core / coreirclisthelper.cpp
index aefcec9..cadb5e3 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2015 by the Quassel Project                        *
+ *   Copyright (C) 2005-2019 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -23,8 +23,9 @@
 #include "corenetwork.h"
 #include "coreuserinputhandler.h"
 
-INIT_SYNCABLE_OBJECT(CoreIrcListHelper)
-QVariantList CoreIrcListHelper::requestChannelList(const NetworkId &netId, const QStringList &channelFilters)
+constexpr auto kTimeoutMs = 5000;
+
+QVariantList CoreIrcListHelper::requestChannelList(const NetworkId& netId, const QStringList& channelFilters)
 {
     if (_finishedChannelLists.contains(netId))
         return _finishedChannelLists.take(netId);
@@ -38,24 +39,30 @@ QVariantList CoreIrcListHelper::requestChannelList(const NetworkId &netId, const
     return QVariantList();
 }
 
-
-bool CoreIrcListHelper::addChannel(const NetworkId &netId, const QString &channelName, quint32 userCount, const QString &topic)
+bool CoreIrcListHelper::addChannel(const NetworkId& netId, const QString& channelName, quint32 userCount, const QString& topic)
 {
     if (!_channelLists.contains(netId))
         return false;
 
     _channelLists[netId] << ChannelDescription(channelName, userCount, topic);
+    if (_queryTimeoutByNetId.contains(netId))
+        _queryTimeoutByNetId[netId]->start(kTimeoutMs, this);
+
     return true;
 }
 
-
-bool CoreIrcListHelper::dispatchQuery(const NetworkId &netId, const QString &query)
+bool CoreIrcListHelper::dispatchQuery(const NetworkId& netId, const QString& query)
 {
-    CoreNetwork *network = coreSession()->network(netId);
+    CoreNetworknetwork = coreSession()->network(netId);
     if (network) {
         _channelLists[netId] = QList<ChannelDescription>();
         network->userInputHandler()->handleList(BufferInfo(), query);
-        _queryTimeout[startTimer(10000)] = netId;
+
+        auto timer = std::make_shared<QBasicTimer>();
+        timer->start(kTimeoutMs, this);
+        _queryTimeoutByNetId[netId] = timer;
+        _queryTimeoutByTimerId[timer->timerId()] = netId;
+
         return true;
     }
     else {
@@ -63,21 +70,24 @@ bool CoreIrcListHelper::dispatchQuery(const NetworkId &netId, const QString &que
     }
 }
 
-
-bool CoreIrcListHelper::endOfChannelList(const NetworkId &netId)
+bool CoreIrcListHelper::endOfChannelList(const NetworkId& netId)
 {
+    if (_queryTimeoutByNetId.contains(netId)) {
+        // If we recieved an actual RPL_LISTEND, remove the timer
+        int timerId = _queryTimeoutByNetId.take(netId)->timerId();
+        _queryTimeoutByTimerId.remove(timerId);
+    }
+
     if (_queuedQuery.contains(netId)) {
         // we're no longer interessted in the current data. drop it and issue a new request.
         return dispatchQuery(netId, _queuedQuery.take(netId));
     }
     else if (_channelLists.contains(netId)) {
         QVariantList channelList;
-        foreach(ChannelDescription channel, _channelLists[netId]) {
+        foreach (ChannelDescription channel, _channelLists[netId]) {
             QVariantList channelVariant;
-            channelVariant << channel.channelName
-                           << channel.userCount
-                           << channel.topic;
-            channelList << qVariantFromValue<QVariant>(channelVariant);
+            channelVariant << channel.channelName << channel.userCount << channel.topic;
+            channelList << QVariant::fromValue<QVariant>(channelVariant);
         }
         _finishedChannelLists[netId] = channelList;
         _channelLists.remove(netId);
@@ -89,11 +99,16 @@ bool CoreIrcListHelper::endOfChannelList(const NetworkId &netId)
     }
 }
 
-
-void CoreIrcListHelper::timerEvent(QTimerEvent *event)
+void CoreIrcListHelper::timerEvent(QTimerEvent* event)
 {
-    int timerId = event->timerId();
-    killTimer(timerId);
-    NetworkId netId = _queryTimeout.take(timerId);
+    if (!_queryTimeoutByTimerId.contains(event->timerId())) {
+        IrcListHelper::timerEvent(event);
+        return;
+    }
+
+    NetworkId netId = _queryTimeoutByTimerId.take(event->timerId());
+    _queryTimeoutByNetId.remove(netId);
+
+    event->accept();
     endOfChannelList(netId);
 }