X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fnetworkmodel.cpp;h=974f31a69eafab040d83d521089a144cb8f1de60;hp=aea48bf860ced751ac31f9d8d50ef54d7c4019ee;hb=61aac1868f15babb7086d8bc6bbcff530346f438;hpb=5b164bbc62960cea62a31287f679197b623ad7ac diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index aea48bf8..974f31a6 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -76,7 +76,7 @@ QVariant NetworkItem::data(int column, int role) const QString NetworkItem::escapeHTML(const QString &string, bool useNonbreakingSpaces) { - // QString.replace() doesn't guarentee the source string will remain constant. + // 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); @@ -224,7 +224,7 @@ QString NetworkItem::toolTip(int column) const Q_UNUSED(column); QString strTooltip; QTextStream tooltip( &strTooltip, QIODevice::WriteOnly ); - tooltip << ""; + tooltip << ""; // Function to add a row to the tooltip table auto addRow = [&](const QString& key, const QString& value, bool condition) { @@ -234,15 +234,18 @@ QString NetworkItem::toolTip(int column) const }; tooltip << "

" << NetworkItem::escapeHTML(networkName(), true) << "

"; - tooltip << ""; - addRow(tr("Server"), NetworkItem::escapeHTML(currentServer(), true), true); - - addRow(tr("Users"), QString::number(nickCount()), true); - - if (_network) - addRow(tr("Lag"), NetworkItem::escapeHTML(tr("%1 msecs").arg(_network->latency()), true), 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 << "
"; + tooltip << ""; + } else { + tooltip << "

" << tr("Not connected") << "

"; + } + tooltip << "
"; return strTooltip; } @@ -519,8 +522,7 @@ QString QueryBufferItem::toolTip(int column) const Q_UNUSED(column); QString strTooltip; QTextStream tooltip( &strTooltip, QIODevice::WriteOnly ); - tooltip << "" - << ""; + tooltip << ""; // Keep track of whether or not information has been added bool infoAdded = false; @@ -549,11 +551,13 @@ QString QueryBufferItem::toolTip(int column) const tooltip << ""; if (_ircUser->isAway()) { - QString awayMessage(tr("(unknown)")); - if(!_ircUser->awayMessage().isEmpty()) { - awayMessage = _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), NetworkItem::escapeHTML(awayMessage), true); + addRow(NetworkItem::escapeHTML(tr("Away message"), true), awayMessageHTML, true); } addRow(tr("Realname"), NetworkItem::escapeHTML(_ircUser->realName()), @@ -626,7 +630,7 @@ QString QueryBufferItem::toolTip(int column) const // If no further information found, offer an explanatory message if (!infoAdded) - tooltip << "

" << tr("No information available") << "

"; + tooltip << "

" << tr("No information available") << "

"; tooltip << ""; return strTooltip; @@ -656,8 +660,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(); + } } @@ -668,6 +686,7 @@ ChannelBufferItem::ChannelBufferItem(const BufferInfo &bufferInfo, AbstractTreeI : BufferItem(bufferInfo, parent), _ircChannel(0) { + setFlags(flags() | Qt::ItemIsDropEnabled); } @@ -687,8 +706,7 @@ QString ChannelBufferItem::toolTip(int column) const Q_UNUSED(column); QString strTooltip; QTextStream tooltip( &strTooltip, QIODevice::WriteOnly ); - tooltip << "" - << ""; + tooltip << ""; // Function to add a row to the tooltip table auto addRow = [&](const QString& key, const QString& value, bool condition) { @@ -723,7 +741,7 @@ QString ChannelBufferItem::toolTip(int column) const tooltip << "
"; } else { - tooltip << "

" << tr("Not active, double-click to join") << "

"; + tooltip << "

" << tr("Not active, double-click to join") << "

"; } tooltip << "
"; @@ -1073,8 +1091,7 @@ QString IrcUserItem::toolTip(int column) const Q_UNUSED(column); QString strTooltip; QTextStream tooltip( &strTooltip, QIODevice::WriteOnly ); - tooltip << "" - << ""; + tooltip << ""; // Keep track of whether or not information has been added bool infoAdded = false; @@ -1100,11 +1117,13 @@ QString IrcUserItem::toolTip(int column) const NetworkItem::escapeHTML(channelModes()), !channelModes().isEmpty()); if (_ircUser->isAway()) { - QString awayMessage(tr("(unknown)")); - if(!_ircUser->awayMessage().isEmpty()) { - awayMessage = _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), NetworkItem::escapeHTML(awayMessage), true); + addRow(NetworkItem::escapeHTML(tr("Away message"), true), awayMessageHTML, true); } addRow(tr("Realname"), NetworkItem::escapeHTML(_ircUser->realName()), @@ -1177,7 +1196,7 @@ QString IrcUserItem::toolTip(int column) const // If no further information found, offer an explanatory message if (!infoAdded) - tooltip << "

" << tr("No information available") << "

"; + tooltip << "

" << tr("No information available") << "

"; tooltip << "
"; return strTooltip;