Semi-yearly copyright bump
[quassel.git] / src / client / networkmodel.cpp
index dc985bd..9d1f5b2 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2014 by the Quassel Project                        *
+ *   Copyright (C) 2005-2018 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -22,7 +22,9 @@
 
 #include <QAbstractItemView>
 #include <QMimeData>
+#if QT_VERSION < 0x050000
 #include <QTextDocument>        // for Qt::escape()
+#endif
 
 #include "buffermodel.h"
 #include "buffersettings.h"
@@ -209,8 +211,13 @@ QString NetworkItem::toolTip(int column) const
 {
     Q_UNUSED(column);
 
+#if QT_VERSION < 0x050000
     QStringList toolTip(QString("<b>%1</b>").arg(Qt::escape(networkName())));
     toolTip.append(tr("Server: %1").arg(Qt::escape(currentServer())));
+#else
+    QStringList toolTip(QString("<b>%1</b>").arg(networkName().toHtmlEscaped()));
+    toolTip.append(tr("Server: %1").arg(currentServer().toHtmlEscaped()));
+#endif
     toolTip.append(tr("Users: %1").arg(nickCount()));
 
     if (_network) {
@@ -456,6 +463,12 @@ bool QueryBufferItem::setData(int column, const QVariant &value, int role)
     case Qt::EditRole:
     {
         QString newName = value.toString();
+
+        // Sanity check - buffer names must not contain newlines!
+        int nlpos = newName.indexOf('\n');
+        if (nlpos >= 0)
+            newName = newName.left(nlpos);
+
         if (!newName.isEmpty()) {
             Client::renameBuffer(bufferId(), newName);
             return true;
@@ -541,8 +554,22 @@ void QueryBufferItem::setIrcUser(IrcUser *ircUser)
 
 void QueryBufferItem::removeIrcUser()
 {
-    _ircUser = 0;
-    emit dataChanged();
+    if (_ircUser) {
+        // Disconnect the active IrcUser before removing it, otherwise it will fire removeIrcUser()
+        // a second time when the object's destroyed due to QueryBufferItem::setIrcUser() connecting
+        // SIGNAL destroyed(QObject*) to SLOT removeIrcUser().
+        // This fixes removing an active IrcUser if the user had quit then rejoined in a nonstandard
+        // manner (e.g. updateNickFromHost calling newIrcUser, triggered by an away-notify message).
+        disconnect(_ircUser, 0, this, 0);
+
+        // Clear IrcUser (only set to 0 if not already 0)
+        _ircUser = 0;
+
+        // Only emit dataChanged() if data actually changed.  This might serve as a small
+        // optimization, but it can be moved outside the if statement if other behavior depends on
+        // it always being called.
+        emit dataChanged();
+    }
 }
 
 
@@ -553,6 +580,7 @@ ChannelBufferItem::ChannelBufferItem(const BufferInfo &bufferInfo, AbstractTreeI
     : BufferItem(bufferInfo, parent),
     _ircChannel(0)
 {
+    setFlags(flags() | Qt::ItemIsDropEnabled);
 }
 
 
@@ -572,7 +600,11 @@ QString ChannelBufferItem::toolTip(int column) const
     Q_UNUSED(column);
     QStringList toolTip;
 
+#if QT_VERSION < 0x050000
     toolTip.append(tr("<b>Channel %1</b>").arg(Qt::escape(bufferName())));
+#else
+    toolTip.append(tr("<b>Channel %1</b>").arg(bufferName().toHtmlEscaped()));
+#endif
     if (isActive()) {
         //TODO: add channel modes
         toolTip.append(tr("<b>Users:</b> %1").arg(nickCount()));
@@ -588,7 +620,11 @@ QString ChannelBufferItem::toolTip(int column) const
             QString _topic = topic();
             if (_topic != "") {
                 _topic = stripFormatCodes(_topic);
+#if QT_VERSION < 0x050000
                 _topic = Qt::escape(_topic);
+#else
+                _topic = _topic.toHtmlEscaped();
+#endif
                 toolTip.append(QString("<font size='-2'>&nbsp;</font>"));
                 toolTip.append(tr("<b>Topic:</b> %1").arg(_topic));
             }
@@ -708,7 +744,7 @@ void ChannelBufferItem::addUsersToCategory(const QList<IrcUser *> &ircUsers)
     QHash<UserCategoryItem *, QList<IrcUser *> >::const_iterator catIter = categories.constBegin();
     while (catIter != categories.constEnd()) {
         catIter.key()->addUsers(catIter.value());
-        catIter++;
+        ++catIter;
     }
 }
 
@@ -1102,7 +1138,7 @@ QList<QPair<NetworkId, BufferId> > NetworkModel::mimeDataToBufferList(const QMim
     if (!mimeContainsBufferList(mimeData))
         return bufferList;
 
-    QStringList rawBufferList = QString::fromAscii(mimeData->data("application/Quassel/BufferItemList")).split(",");
+    QStringList rawBufferList = QString::fromLatin1(mimeData->data("application/Quassel/BufferItemList")).split(",");
     NetworkId networkId;
     BufferId bufferUid;
     foreach(QString rawBuffer, rawBufferList) {
@@ -1130,7 +1166,7 @@ QMimeData *NetworkModel::mimeData(const QModelIndexList &indexes) const
             bufferlist << bufferid;
     }
 
-    mimeData->setData("application/Quassel/BufferItemList", bufferlist.join(",").toAscii());
+    mimeData->setData("application/Quassel/BufferItemList", bufferlist.join(",").toLatin1());
 
     return mimeData;
 }
@@ -1264,7 +1300,8 @@ void NetworkModel::updateBufferActivity(Message &msg)
         }
     }
     else {
-        updateBufferActivity(bufferItem(msg.bufferInfo()), msg);
+        if ((BufferSettings(msg.bufferId()).messageFilter() & msg.type()) != msg.type())
+            updateBufferActivity(bufferItem(msg.bufferInfo()), msg);
     }
 }