X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fnetworkmodel.cpp;h=dd5b84862d79b403e0fb8e4d5f05667aa85b9d07;hb=6ee26fd6d0a163314002616d277e5444f11b7720;hp=51a6af6fc4f2003b5feb0b6afb5f68dd151fc1c9;hpb=5b686746c880e5cda6d5de3e08180ea4332ff222;p=quassel.git
diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp
index 51a6af6f..dd5b8486 100644
--- a/src/client/networkmodel.cpp
+++ b/src/client/networkmodel.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2005-2012 by the Quassel Project *
+ * Copyright (C) 2005-2016 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
#include
+#if QT_VERSION < 0x050000
#include // for Qt::escape()
+#endif
#include "buffermodel.h"
#include "buffersettings.h"
@@ -72,6 +74,18 @@ QVariant NetworkItem::data(int column, int role) const
}
}
+QString NetworkItem::escapeHTML(const QString &string, bool useNonbreakingSpaces)
+{
+ // QString.replace() doesn't guarantee the source string will remain constant.
+ // Use a local variable to avoid compiler errors.
+#if QT_VERSION < 0x050000
+ QString formattedString = Qt::escape(string);
+#else
+ QString formattedString = string.toHtmlEscaped();
+#endif
+ return (useNonbreakingSpaces ? formattedString.replace(" ", " ") : formattedString);
+}
+
// FIXME shouldn't we check the bufferItemCache here?
BufferItem *NetworkItem::findBufferItem(BufferId bufferId)
@@ -153,7 +167,7 @@ void NetworkItem::attachNetwork(Network *network)
connect(network, SIGNAL(connectedSet(bool)),
this, SIGNAL(networkDataChanged()));
connect(network, SIGNAL(destroyed()),
- this, SIGNAL(networkDataChanged()));
+ this, SLOT(onNetworkDestroyed()));
emit networkDataChanged();
}
@@ -208,16 +222,31 @@ void NetworkItem::setCurrentServer(const QString &serverName)
QString NetworkItem::toolTip(int column) const
{
Q_UNUSED(column);
+ QString strTooltip;
+ QTextStream tooltip( &strTooltip, QIODevice::WriteOnly );
+ tooltip << "";
+
+ // Function to add a row to the tooltip table
+ auto addRow = [&](const QString& key, const QString& value, bool condition) {
+ if (condition) {
+ tooltip << "" << key << " | " << value << " |
";
+ }
+ };
- QStringList toolTip(QString("%1").arg(Qt::escape(networkName())));
- toolTip.append(tr("Server: %1").arg(Qt::escape(currentServer())));
- toolTip.append(tr("Users: %1").arg(nickCount()));
-
- if (_network) {
- toolTip.append(tr("Lag: %1 msecs").arg(_network->latency()));
+ tooltip << "" << NetworkItem::escapeHTML(networkName(), true) << "
";
+ if (isActive()) {
+ tooltip << "";
+ addRow(tr("Server"), NetworkItem::escapeHTML(currentServer(), true), !currentServer().isEmpty());
+ addRow(tr("Users"), QString::number(nickCount()), true);
+ if (_network)
+ addRow(tr("Lag"), NetworkItem::escapeHTML(tr("%1 msecs").arg(_network->latency()), true), true);
+
+ tooltip << "
";
+ } else {
+ tooltip << "" << tr("Not connected") << "
";
}
-
- return QString(" %1
").arg(toolTip.join("
"));
+ tooltip << "";
+ return strTooltip;
}
@@ -233,6 +262,14 @@ void NetworkItem::onBeginRemoveChilds(int start, int end)
}
+void NetworkItem::onNetworkDestroyed()
+{
+ _network = 0;
+ emit networkDataChanged();
+ removeAllChilds();
+}
+
+
/*****************************************
* Fancy Buffer Items
*****************************************/
@@ -448,6 +485,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;
@@ -477,36 +520,120 @@ QString QueryBufferItem::toolTip(int column) const
{
// pretty much code duplication of IrcUserItem::toolTip() but inheritance won't solve this...
Q_UNUSED(column);
- QStringList toolTip;
+ QString strTooltip;
+ QTextStream tooltip( &strTooltip, QIODevice::WriteOnly );
+ tooltip << "";
+
+ // Keep track of whether or not information has been added
+ bool infoAdded = false;
+
+ // Use bufferName() for QueryBufferItem, nickName() for IrcUserItem
+ tooltip << "";
+ tooltip << tr("Query with %1").arg(NetworkItem::escapeHTML(bufferName(), true));
+ if (!_ircUser) {
+ // User seems to be offline, let the no information message be added below
+ tooltip << "
";
+ } else {
+ // Function to add a row to the tooltip table
+ auto addRow = [&](const QString& key, const QString& value, bool condition) {
+ if (condition) {
+ tooltip << "" << key << " | " << value << " |
";
+ infoAdded = true;
+ }
+ };
- toolTip.append(tr("Query with %1").arg(bufferName()));
+ // User information is available
+ if (_ircUser->userModes() != "") {
+ //TODO Translate user Modes and add them to the table below and in IrcUserItem::toolTip
+ tooltip << " (" << _ircUser->userModes() << ")";
+ }
+ tooltip << "
";
- if (_ircUser) {
- if (_ircUser->userModes() != "") toolTip[0].append(QString(" (+%1)").arg(_ircUser->userModes()));
+ tooltip << "";
if (_ircUser->isAway()) {
- toolTip[0].append(QString(" (away%1)").arg(!_ircUser->awayMessage().isEmpty() ? (QString(" ") + _ircUser->awayMessage()) : QString()));
+ QString awayMessageHTML = QString("%1
").arg(tr("Unknown"));
+
+ // If away message is known, replace with the escaped message.
+ if (!_ircUser->awayMessage().isEmpty()) {
+ awayMessageHTML = NetworkItem::escapeHTML(_ircUser->awayMessage());
+ }
+ addRow(NetworkItem::escapeHTML(tr("Away message"), true), awayMessageHTML, true);
+ }
+ addRow(tr("Realname"),
+ NetworkItem::escapeHTML(_ircUser->realName()),
+ !_ircUser->realName().isEmpty());
+ // suserHost may return " is available for help", which should be translated.
+ // See https://www.alien.net.au/irc/irc2numerics.html
+ if(_ircUser->suserHost().endsWith("available for help")) {
+ addRow(NetworkItem::escapeHTML(tr("Help status"), true),
+ NetworkItem::escapeHTML(tr("Available for help")),
+ true);
+ } else {
+ addRow(NetworkItem::escapeHTML(tr("Service status"), true),
+ NetworkItem::escapeHTML(_ircUser->suserHost()),
+ !_ircUser->suserHost().isEmpty());
}
- if (!_ircUser->realName().isEmpty()) toolTip.append(_ircUser->realName());
- if (!_ircUser->ircOperator().isEmpty()) toolTip.append(QString("%1 %2").arg(_ircUser->nick()).arg(_ircUser->ircOperator()));
- if (!_ircUser->suserHost().isEmpty()) toolTip.append(_ircUser->suserHost());
- if (!_ircUser->whoisServiceReply().isEmpty()) toolTip.append(_ircUser->whoisServiceReply());
- toolTip.append(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!")+1));
+ // Keep track of whether or not the account information's been added. Don't show it twice.
+ bool accountAdded = false;
+ if(!_ircUser->account().isEmpty()) {
+ // IRCv3 account-notify is supported by the core and IRC server.
+ // Assume logged out (seems to be more common)
+ QString accountHTML = QString("%1
").arg(tr("Not logged in"));
+
+ // If account is logged in, replace with the escaped account name.
+ if (_ircUser->account() != "*") {
+ accountHTML = NetworkItem::escapeHTML(_ircUser->account());
+ }
+ addRow(NetworkItem::escapeHTML(tr("Account"), true),
+ accountHTML,
+ true);
+ // Mark the row as added
+ accountAdded = true;
+ }
+ // whoisServiceReply may return " is identified for this nick", which should be translated.
+ // See https://www.alien.net.au/irc/irc2numerics.html
+ if(_ircUser->whoisServiceReply().endsWith("identified for this nick")) {
+ addRow(NetworkItem::escapeHTML(tr("Account"), true),
+ NetworkItem::escapeHTML(tr("Identified for this nick")),
+ !accountAdded);
+ // Don't add the account row again if information's already added via account-notify
+ // Mark the row as added
+ accountAdded = true;
+ } else {
+ addRow(NetworkItem::escapeHTML(tr("Service Reply"), true),
+ NetworkItem::escapeHTML(_ircUser->whoisServiceReply()),
+ !_ircUser->whoisServiceReply().isEmpty());
+ }
+ addRow(tr("Hostmask"),
+ NetworkItem::escapeHTML(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!") + 1)),
+ !(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!") + 1) == "@"));
+ // ircOperator may contain "is an" or "is a", which should be removed.
+ addRow(tr("Operator"),
+ NetworkItem::escapeHTML(_ircUser->ircOperator().replace("is an ", "").replace("is a ", "")),
+ !_ircUser->ircOperator().isEmpty());
if (_ircUser->idleTime().isValid()) {
QDateTime now = QDateTime::currentDateTime();
QDateTime idle = _ircUser->idleTime();
int idleTime = idle.secsTo(now);
- toolTip.append(tr("idling since %1").arg(secondsToString(idleTime)));
+ addRow(NetworkItem::escapeHTML(tr("Idling since"), true), secondsToString(idleTime), true);
}
+
if (_ircUser->loginTime().isValid()) {
- toolTip.append(tr("login time: %1").arg(_ircUser->loginTime().toString()));
+ addRow(NetworkItem::escapeHTML(tr("Login time"), true), _ircUser->loginTime().toString(), true);
}
- if (!_ircUser->server().isEmpty()) toolTip.append(tr("server: %1").arg(_ircUser->server()));
+ addRow(tr("Server"), NetworkItem::escapeHTML(_ircUser->server()), !_ircUser->server().isEmpty());
+ tooltip << "
";
}
- return QString(" %1
").arg(toolTip.join("
"));
+ // If no further information found, offer an explanatory message
+ if (!infoAdded)
+ tooltip << "" << tr("No information available") << "
";
+
+ tooltip << "";
+ return strTooltip;
}
@@ -520,8 +647,10 @@ void QueryBufferItem::setIrcUser(IrcUser *ircUser)
}
if (ircUser) {
+ connect(ircUser, SIGNAL(destroyed(QObject*)), SLOT(removeIrcUser()));
connect(ircUser, SIGNAL(quited()), this, SLOT(removeIrcUser()));
connect(ircUser, SIGNAL(awaySet(bool)), this, SIGNAL(dataChanged()));
+ connect(ircUser, SIGNAL(encryptedSet(bool)), this, SLOT(setEncrypted(bool)));
}
_ircUser = ircUser;
@@ -543,6 +672,7 @@ ChannelBufferItem::ChannelBufferItem(const BufferInfo &bufferInfo, AbstractTreeI
: BufferItem(bufferInfo, parent),
_ircChannel(0)
{
+ setFlags(flags() | Qt::ItemIsDropEnabled);
}
@@ -560,16 +690,28 @@ QVariant ChannelBufferItem::data(int column, int role) const
QString ChannelBufferItem::toolTip(int column) const
{
Q_UNUSED(column);
- QStringList toolTip;
+ QString strTooltip;
+ QTextStream tooltip( &strTooltip, QIODevice::WriteOnly );
+ tooltip << "";
+
+ // Function to add a row to the tooltip table
+ auto addRow = [&](const QString& key, const QString& value, bool condition) {
+ if (condition) {
+ tooltip << "" << key << " | " << value << " |
";
+ }
+ };
+
+ tooltip << "";
+ tooltip << NetworkItem::escapeHTML(tr("Channel %1").arg(bufferName()), true) << "
";
- toolTip.append(tr("Channel %1").arg(Qt::escape(bufferName())));
if (isActive()) {
- //TODO: add channel modes
- toolTip.append(tr("Users: %1").arg(nickCount()));
+ tooltip << "";
+ addRow(tr("Users"), QString::number(nickCount()), true);
+
if (_ircChannel) {
QString channelMode = _ircChannel->channelModeString(); // channelModeString is compiled on the fly -> thus cache the result
if (!channelMode.isEmpty())
- toolTip.append(tr("Mode: %1").arg(channelMode));
+ addRow(tr("Mode"), channelMode, true);
}
ItemViewSettings s;
@@ -578,28 +720,36 @@ QString ChannelBufferItem::toolTip(int column) const
QString _topic = topic();
if (_topic != "") {
_topic = stripFormatCodes(_topic);
- _topic = Qt::escape(_topic);
- toolTip.append(QString(" "));
- toolTip.append(tr("Topic: %1").arg(_topic));
+ _topic = NetworkItem::escapeHTML(_topic);
+ addRow(tr("Topic"), _topic, true);
}
}
- }
- else {
- toolTip.append(tr("Not active
Double-click to join"));
+
+ tooltip << "
";
+ } else {
+ tooltip << "" << tr("Not active, double-click to join") << "
";
}
- return tr(" %1
").arg(toolTip.join("
"));
+ tooltip << "";
+ return strTooltip;
}
void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel)
{
- Q_ASSERT(!_ircChannel && ircChannel);
+ if (_ircChannel) {
+ qWarning() << Q_FUNC_INFO << "IrcChannel already set; cleanup failed!?";
+ disconnect(_ircChannel, 0, this, 0);
+ }
_ircChannel = ircChannel;
+ connect(ircChannel, SIGNAL(destroyed(QObject*)),
+ this, SLOT(ircChannelDestroyed()));
connect(ircChannel, SIGNAL(topicSet(QString)),
this, SLOT(setTopic(QString)));
+ connect(ircChannel, SIGNAL(encryptedSet(bool)),
+ this, SLOT(setEncrypted(bool)));
connect(ircChannel, SIGNAL(ircUsersJoined(QList )),
this, SLOT(join(QList )));
connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
@@ -619,6 +769,16 @@ void ChannelBufferItem::attachIrcChannel(IrcChannel *ircChannel)
emit dataChanged();
}
+QString ChannelBufferItem::nickChannelModes(const QString &nick) const
+{
+ if (!_ircChannel) {
+ qDebug() << Q_FUNC_INFO << "IrcChannel not set, can't get user modes";
+ return QString();
+ }
+
+ return _ircChannel->userModes(nick);
+}
+
void ChannelBufferItem::ircChannelParted()
{
@@ -630,6 +790,16 @@ void ChannelBufferItem::ircChannelParted()
}
+void ChannelBufferItem::ircChannelDestroyed()
+{
+ if (_ircChannel) {
+ _ircChannel = 0;
+ emit dataChanged();
+ removeAllChilds();
+ }
+}
+
+
void ChannelBufferItem::join(const QList &ircUsers)
{
addUsersToCategory(ircUsers);
@@ -681,7 +851,7 @@ void ChannelBufferItem::addUsersToCategory(const QList &ircUsers)
QHash >::const_iterator catIter = categories.constBegin();
while (catIter != categories.constEnd()) {
catIter.key()->addUsers(catIter.value());
- catIter++;
+ ++catIter;
}
}
@@ -905,33 +1075,132 @@ QVariant IrcUserItem::data(int column, int role) const
QString IrcUserItem::toolTip(int column) const
{
Q_UNUSED(column);
- QStringList toolTip(QString("%1").arg(nickName()));
- if (_ircUser->userModes() != "") toolTip[0].append(QString(" (%1)").arg(_ircUser->userModes()));
+ QString strTooltip;
+ QTextStream tooltip( &strTooltip, QIODevice::WriteOnly );
+ tooltip << "";
+
+ // Keep track of whether or not information has been added
+ bool infoAdded = false;
+
+ // Use bufferName() for QueryBufferItem, nickName() for IrcUserItem
+ tooltip << "" << NetworkItem::escapeHTML(nickName(), true);
+ if (_ircUser->userModes() != "") {
+ //TODO: Translate user Modes and add them to the table below and in QueryBufferItem::toolTip
+ tooltip << " (" << _ircUser->userModes() << ")";
+ }
+ tooltip << "
";
+
+ auto addRow = [&](const QString& key, const QString& value, bool condition) {
+ if (condition)
+ {
+ tooltip << "" << key << " | " << value << " |
";
+ infoAdded = true;
+ }
+ };
+
+ tooltip << "";
+ addRow(tr("Modes"),
+ NetworkItem::escapeHTML(channelModes()),
+ !channelModes().isEmpty());
if (_ircUser->isAway()) {
- toolTip[0].append(tr(" is away"));
- if (!_ircUser->awayMessage().isEmpty())
- toolTip[0].append(QString(" (%1)").arg(_ircUser->awayMessage()));
+ QString awayMessageHTML = QString("%1
").arg(tr("Unknown"));
+
+ // If away message is known, replace with the escaped message.
+ if (!_ircUser->awayMessage().isEmpty()) {
+ awayMessageHTML = NetworkItem::escapeHTML(_ircUser->awayMessage());
+ }
+ addRow(NetworkItem::escapeHTML(tr("Away message"), true), awayMessageHTML, true);
+ }
+ addRow(tr("Realname"),
+ NetworkItem::escapeHTML(_ircUser->realName()),
+ !_ircUser->realName().isEmpty());
+
+ // suserHost may return " is available for help", which should be translated.
+ // See https://www.alien.net.au/irc/irc2numerics.html
+ if(_ircUser->suserHost().endsWith("available for help")) {
+ addRow(NetworkItem::escapeHTML(tr("Help status"), true),
+ NetworkItem::escapeHTML(tr("Available for help")),
+ true);
+ } else {
+ addRow(NetworkItem::escapeHTML(tr("Service status"), true),
+ NetworkItem::escapeHTML(_ircUser->suserHost()),
+ !_ircUser->suserHost().isEmpty());
}
- if (!_ircUser->realName().isEmpty()) toolTip.append(_ircUser->realName());
- if (!_ircUser->ircOperator().isEmpty()) toolTip.append(QString("%1 %2").arg(nickName()).arg(_ircUser->ircOperator()));
- if (!_ircUser->suserHost().isEmpty()) toolTip.append(_ircUser->suserHost());
- if (!_ircUser->whoisServiceReply().isEmpty()) toolTip.append(_ircUser->whoisServiceReply());
- toolTip.append(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!")+1));
+ // Keep track of whether or not the account information's been added. Don't show it twice.
+ bool accountAdded = false;
+ if(!_ircUser->account().isEmpty()) {
+ // IRCv3 account-notify is supported by the core and IRC server.
+ // Assume logged out (seems to be more common)
+ QString accountHTML = QString("%1
").arg(tr("Not logged in"));
+
+ // If account is logged in, replace with the escaped account name.
+ if (_ircUser->account() != "*") {
+ accountHTML = NetworkItem::escapeHTML(_ircUser->account());
+ }
+ addRow(NetworkItem::escapeHTML(tr("Account"), true),
+ accountHTML,
+ true);
+ // Mark the row as added
+ accountAdded = true;
+ }
+ // whoisServiceReply may return " is identified for this nick", which should be translated.
+ // See https://www.alien.net.au/irc/irc2numerics.html
+ if(_ircUser->whoisServiceReply().endsWith("identified for this nick")) {
+ addRow(NetworkItem::escapeHTML(tr("Account"), true),
+ NetworkItem::escapeHTML(tr("Identified for this nick")),
+ !accountAdded);
+ // Don't add the account row again if information's already added via account-notify
+ // Mark the row as added
+ accountAdded = true;
+ } else {
+ addRow(NetworkItem::escapeHTML(tr("Service Reply"), true),
+ NetworkItem::escapeHTML(_ircUser->whoisServiceReply()),
+ !_ircUser->whoisServiceReply().isEmpty());
+ }
+ addRow(tr("Hostmask"),
+ NetworkItem::escapeHTML(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!") + 1)),
+ !(_ircUser->hostmask().remove(0, _ircUser->hostmask().indexOf("!") + 1) == "@"));
+ // ircOperator may contain "is an" or "is a", which should be removed.
+ addRow(tr("Operator"),
+ NetworkItem::escapeHTML(_ircUser->ircOperator().replace("is an ", "").replace("is a ", "")),
+ !_ircUser->ircOperator().isEmpty());
if (_ircUser->idleTime().isValid()) {
QDateTime now = QDateTime::currentDateTime();
QDateTime idle = _ircUser->idleTime();
int idleTime = idle.secsTo(now);
- toolTip.append(tr("idling since %1").arg(secondsToString(idleTime)));
+ addRow(NetworkItem::escapeHTML(tr("Idling since"), true), secondsToString(idleTime), true);
}
+
if (_ircUser->loginTime().isValid()) {
- toolTip.append(tr("login time: %1").arg(_ircUser->loginTime().toString()));
+ addRow(NetworkItem::escapeHTML(tr("Login time"), true), _ircUser->loginTime().toString(), true);
}
- if (!_ircUser->server().isEmpty()) toolTip.append(tr("server: %1").arg(_ircUser->server()));
+ addRow(tr("Server"), NetworkItem::escapeHTML(_ircUser->server()), !_ircUser->server().isEmpty());
+ tooltip << "
";
+
+ // If no further information found, offer an explanatory message
+ if (!infoAdded)
+ tooltip << "" << tr("No information available") << "
";
- return QString(" %1
").arg(toolTip.join("
"));
+ tooltip << "";
+ return strTooltip;
+}
+
+QString IrcUserItem::channelModes() const
+{
+ // IrcUserItems are parented to UserCategoryItem, which are parented to ChannelBufferItem.
+ // We want the channel buffer item in order to get the channel-specific user modes.
+ UserCategoryItem *category = qobject_cast(parent());
+ if (!category)
+ return QString();
+
+ ChannelBufferItem *channel = qobject_cast(category->parent());
+ if (!channel)
+ return QString();
+
+ return channel->nickChannelModes(nickName());
}
@@ -1075,7 +1344,7 @@ QList > 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) {
@@ -1103,7 +1372,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;
}
@@ -1237,7 +1506,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);
}
}