X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fclient%2Fnetworkmodel.cpp;h=f3896e58d0ccefde356a7159d26a94e09974b9c1;hb=54ead1bace1c9306ccfd5ebd7fb7bbd0c9843db7;hp=64349690630d9a555f117c38c035fa758cc36cc1;hpb=2261829376bf9f404f2b27e77050202e9bb3b1ca;p=quassel.git diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 64349690..f3896e58 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; } @@ -304,6 +307,10 @@ void BufferItem::clearActivityLevel() void BufferItem::updateActivityLevel(const Message &msg) { + if (Client::coreFeatures().testFlag(Quassel::Feature::BufferActivitySync)) { + return; + } + if (isCurrentBuffer()) { return; } @@ -324,19 +331,35 @@ void BufferItem::updateActivityLevel(const Message &msg) _firstUnreadMsgId = msg.msgId(); } + if (addActivity(Message::Types(msg.type()), msg.flags().testFlag(Message::Highlight)) || stateChanged) { + emit dataChanged(); + } +} + +void BufferItem::setActivity(Message::Types type, bool highlight) { BufferInfo::ActivityLevel oldLevel = activityLevel(); - _activity |= BufferInfo::OtherActivity; - if (msg.type() & (Message::Plain | Message::Notice | Message::Action)) + _activity = BufferInfo::Activity(); + addActivity(type, highlight); + + if (_activity != oldLevel) { + emit dataChanged(); + } +} + +bool BufferItem::addActivity(Message::Types type, bool highlight) { + auto oldActivity = activityLevel(); + + if (type != 0) + _activity |= BufferInfo::OtherActivity; + + if (type.testFlag(Message::Plain) || type.testFlag(Message::Notice) || type.testFlag(Message::Action)) _activity |= BufferInfo::NewMessage; - if (msg.flags() & Message::Highlight) + if (highlight) _activity |= BufferInfo::Highlight; - stateChanged |= (oldLevel != _activity); - - if (stateChanged) - emit dataChanged(); + return oldActivity != _activity; } @@ -519,8 +542,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 +571,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()), @@ -569,12 +593,33 @@ QString QueryBufferItem::toolTip(int column) const NetworkItem::escapeHTML(_ircUser->suserHost()), !_ircUser->suserHost().isEmpty()); } + + // 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")), - true); + !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()), @@ -605,7 +650,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; @@ -635,8 +680,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(); + } } @@ -647,6 +706,7 @@ ChannelBufferItem::ChannelBufferItem(const BufferInfo &bufferInfo, AbstractTreeI : BufferItem(bufferInfo, parent), _ircChannel(0) { + setFlags(flags() | Qt::ItemIsDropEnabled); } @@ -666,8 +726,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) { @@ -702,7 +761,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 << "
"; @@ -1052,8 +1111,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; @@ -1079,11 +1137,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()), @@ -1100,12 +1160,33 @@ QString IrcUserItem::toolTip(int column) const NetworkItem::escapeHTML(_ircUser->suserHost()), !_ircUser->suserHost().isEmpty()); } + + // 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")), - true); + !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()), @@ -1135,7 +1216,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; @@ -1645,3 +1726,15 @@ void NetworkModel::messageRedirectionSettingsChanged() _serverNoticesTarget = bufferSettings.serverNoticesTarget(); _errorMsgsTarget = bufferSettings.errorMsgsTarget(); } + +void NetworkModel::bufferActivityChanged(BufferId bufferId, const Message::Types activity) { + auto bufferItem = findBufferItem(bufferId); + if (!bufferItem) { + qDebug() << "NetworkModel::clearBufferActivity(): buffer is unknown:" << bufferId; + return; + } + auto hiddenTypes = BufferSettings(bufferId).messageFilter(); + auto visibleTypes = ~hiddenTypes; + auto activityVisibleTypesIntersection = activity & visibleTypes; + bufferItem->setActivity(activityVisibleTypesIntersection, false); +}