X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fnetworkmodel.cpp;h=a1bb73fd9b006072ac438634fad9177416307a72;hp=bba21756519b71e276349dc60af1fa3560d39311;hb=729e90cd941776ea76192a6c3bf110d2c572b0cd;hpb=73f9fcde56bcf4d55b73eb88a8d6cf8dc9f9f814 diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index bba21756..a1bb73fd 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); @@ -293,7 +293,12 @@ void BufferItem::setActivityLevel(BufferInfo::ActivityLevel level) void BufferItem::clearActivityLevel() { - _activity = BufferInfo::NoActivity; + if (Client::coreFeatures().testFlag(Quassel::Feature::BufferActivitySync)) { + // If the core handles activity sync, clear only the highlight flag + _activity &= ~BufferInfo::Highlight; + } else { + _activity = BufferInfo::NoActivity; + } _firstUnreadMsgId = MsgId(); // FIXME remove with core proto v11 @@ -307,6 +312,11 @@ void BufferItem::clearActivityLevel() void BufferItem::updateActivityLevel(const Message &msg) { + // If the core handles activity, and this message is not a highlight, ignore this + if (Client::coreFeatures().testFlag(Quassel::Feature::BufferActivitySync) && !msg.flags().testFlag(Message::Highlight)) { + return; + } + if (isCurrentBuffer()) { return; } @@ -327,19 +337,43 @@ void BufferItem::updateActivityLevel(const Message &msg) _firstUnreadMsgId = msg.msgId(); } + Message::Types type; + // If the core handles activities, ignore types + if (!Client::coreFeatures().testFlag(Quassel::Feature::BufferActivitySync)) { + type = Message::Types(); + } else { + type = msg.type(); + } + + if (addActivity(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::Highlight; + 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; } @@ -522,8 +556,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; @@ -552,11 +585,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()), @@ -629,7 +664,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; @@ -659,8 +694,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(); + } } @@ -671,6 +720,7 @@ ChannelBufferItem::ChannelBufferItem(const BufferInfo &bufferInfo, AbstractTreeI : BufferItem(bufferInfo, parent), _ircChannel(0) { + setFlags(flags() | Qt::ItemIsDropEnabled); } @@ -690,8 +740,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) { @@ -726,7 +775,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 << "
"; @@ -1076,8 +1125,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; @@ -1103,11 +1151,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()), @@ -1180,7 +1230,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; @@ -1690,3 +1740,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::bufferActivityChanged(): buffer is unknown:" << bufferId; + return; + } + auto hiddenTypes = BufferSettings(bufferId).messageFilter(); + auto visibleTypes = ~hiddenTypes; + auto activityVisibleTypesIntersection = activity & visibleTypes; + _bufferItem->setActivity(activityVisibleTypesIntersection, false); +}