modernize: Reformat ALL the source... again!
[quassel.git] / src / client / messagefilter.cpp
index 18aedd2..64ea2a4 100644 (file)
 
 #include <algorithm>
 
+#include "buffermodel.h"
 #include "buffersettings.h"
 #include "client.h"
-#include "buffermodel.h"
+#include "clientignorelistmanager.h"
 #include "messagemodel.h"
 #include "networkmodel.h"
-#include "clientignorelistmanager.h"
 
-MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent)
-    : QSortFilterProxyModel(parent),
-    _messageTypeFilter(0)
+MessageFilter::MessageFilter(QAbstractItemModel* source, QObject* parent)
+    : QSortFilterProxyModel(parent)
+    _messageTypeFilter(0)
 {
     init();
     setSourceModel(source);
 }
 
-
-MessageFilter::MessageFilter(MessageModel *source, const QList<BufferId> &buffers, QObject *parent)
-    : QSortFilterProxyModel(parent),
-    _validBuffers(buffers.toSet()),
-    _messageTypeFilter(0)
+MessageFilter::MessageFilter(MessageModel* source, const QList<BufferId>& buffers, QObject* parent)
+    : QSortFilterProxyModel(parent)
+    , _validBuffers(buffers.toSet())
+    , _messageTypeFilter(0)
 {
     init();
     setSourceModel(source);
 }
 
-
 void MessageFilter::init()
 {
     setDynamicSortFilter(true);
@@ -70,7 +68,6 @@ void MessageFilter::init()
     mySettings.notify("hasMessageTypeFilter", this, &MessageFilter::messageTypeFilterChanged);
 }
 
-
 void MessageFilter::messageTypeFilterChanged()
 {
     int newFilter;
@@ -88,7 +85,6 @@ void MessageFilter::messageTypeFilterChanged()
     }
 }
 
-
 void MessageFilter::messageRedirectionChanged()
 {
     BufferSettings bufferSettings;
@@ -113,7 +109,6 @@ void MessageFilter::messageRedirectionChanged()
         invalidateFilter();
 }
 
-
 QString MessageFilter::idString() const
 {
     if (_validBuffers.isEmpty())
@@ -123,14 +118,13 @@ QString MessageFilter::idString() const
     qSort(bufferIds);
 
     QStringList bufferIdStrings;
-    foreach(BufferId id, bufferIds)
-    bufferIdStrings << QString::number(id.toInt());
+    foreach (BufferId id, bufferIds)
+        bufferIdStrings << QString::number(id.toInt());
 
     return bufferIdStrings.join("|");
 }
 
-
-bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
+bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
 {
     Q_UNUSED(sourceParent);
     QModelIndex sourceIdx = sourceModel()->index(sourceRow, 2);
@@ -159,7 +153,8 @@ bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePar
     // ignorelist handling
     // only match if message is not flagged as server msg
     if (!(flags & Message::ServerMsg) && Client::ignoreListManager()
-        && Client::ignoreListManager()->match(sourceIdx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufferId)))
+        && Client::ignoreListManager()->match(sourceIdx.data(MessageModel::MessageRole).value<Message>(),
+                                              Client::networkModel()->networkName(bufferId)))
         return false;
 
     if (flags & Message::Redirected) {
@@ -224,10 +219,8 @@ bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePar
             return false;
 
         // Extract timestamp and nickname from the new quit message
-        qint64 messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole)
-                .value<QDateTime>().toMSecsSinceEpoch();
-        QString quiter = nickFromMask(sourceModel()->data(sourceIdx, MessageModel::MessageRole)
-                                      .value<Message>().sender()).toLower();
+        qint64 messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole).value<QDateTime>().toMSecsSinceEpoch();
+        QString quiter = nickFromMask(sourceModel()->data(sourceIdx, MessageModel::MessageRole).value<Message>().sender()).toLower();
 
         // Check that nickname matches query name
         if (quiter != bufferName().toLower())
@@ -236,22 +229,21 @@ bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePar
         // Check if a quit message was already forwarded within +/- 1000 ms
         static constexpr qint64 MAX_QUIT_DELTA_MS = 1 * 1000;
         // No need to check if it's the appropriate buffer, each query has a unique message filter
-        if (std::binary_search(_filteredQuitMsgTime.begin(), _filteredQuitMsgTime.end(),
-                               messageTimestamp,
-                               [](qint64 a, qint64 b) { return ((a + MAX_QUIT_DELTA_MS) < b); } )) {
+        if (std::binary_search(_filteredQuitMsgTime.begin(), _filteredQuitMsgTime.end(), messageTimestamp, [](qint64 a, qint64 b) {
+                return ((a + MAX_QUIT_DELTA_MS) < b);
+            })) {
             // New element is less than if at least 1000 ms older/newer
             // Match found, no need to forward another quit message
             return false;
         }
 
         // Mark query as having a quit message inserted
-        auto *that = const_cast<MessageFilter *>(this);
+        auto* that = const_cast<MessageFilter*>(this);
         that->_filteredQuitMsgTime.insert(messageTimestamp);
         return true;
     }
 }
 
-
 void MessageFilter::requestBacklog()
 {
     QSet<BufferId>::const_iterator bufferIdIter = _validBuffers.constBegin();