- if(_ircChannel) {
- QString channelMode = _ircChannel->channelModeString(); // channelModeString is compiled on the fly -> thus cache the result
- if(!channelMode.isEmpty())
- toolTip.append(tr("<b>Mode:</b> %1").arg(channelMode));
- }
- } else {
- toolTip.append(tr("Not active <br /> Double-click to join"));
- }
- break;
- case BufferInfo::QueryBuffer:
- toolTip.append(tr("<b>Query with %1</b>").arg(bufferName()));
- if(topic() != "") toolTip.append(tr("Away Message: %1").arg(topic()));
- break;
- default: //this should not happen
- toolTip.append(tr("%1 - %2").arg(bufferInfo().bufferId().toInt()).arg(bufferName()));
- break;
- }
-
- return tr("<p> %1 </p>").arg(toolTip.join("<br />"));
-}
-
-/*
-void BufferItem::setLastMsgInsert(QDateTime msgDate) {
- if(msgDate.isValid() && msgDate > _lastMsgInsert)
- _lastMsgInsert = msgDate;
-}
-*/
-/*
-// FIXME emit dataChanged()
-bool BufferItem::setLastSeen() {
- if(_lastSeen > _lastMsgInsert)
- return false;
-
- _lastSeen = _lastMsgInsert;
- BufferSettings(bufferInfo().bufferId()).setLastSeen(_lastSeen);
- return true;
-}
-
-QDateTime BufferItem::lastSeen() {
- return _lastSeen;
-}
-*/
-/*****************************************
-* Network Items
-*****************************************/
-NetworkItem::NetworkItem(const NetworkId &netid, AbstractTreeItem *parent)
- : PropertyMapItem(QList<QString>() << "networkName" << "currentServer" << "nickCount", parent),
- _networkId(netid)
+ else {
+ return false;
+ }
+ } break;
+ default:
+ return BufferItem::setData(column, value, role);
+ }
+}
+
+void QueryBufferItem::setBufferName(const QString& name)
+{
+ BufferItem::setBufferName(name);
+ NetworkId netId = data(0, NetworkModel::NetworkIdRole).value<NetworkId>();
+ const Network* net = Client::network(netId);
+ if (net)
+ setIrcUser(net->ircUser(name));
+}
+
+QString QueryBufferItem::toolTip(int column) const
+{
+ // pretty much code duplication of IrcUserItem::toolTip() but inheritance won't solve this...
+ Q_UNUSED(column);
+ QString strTooltip;
+ QTextStream tooltip(&strTooltip, QIODevice::WriteOnly);
+ tooltip << "<qt><style>.bold { font-weight: bold; } .italic { font-style: italic; }</style>";
+
+ // Keep track of whether or not information has been added
+ bool infoAdded = false;
+
+ // Use bufferName() for QueryBufferItem, nickName() for IrcUserItem
+ tooltip << "<p class='bold' align='center'>";
+ 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 << "</p>";
+ }
+ else {
+ // Function to add a row to the tooltip table
+ auto addRow = [&](const QString& key, const QString& value, bool condition) {
+ if (condition) {
+ tooltip << "<tr><td class='bold' align='right'>" << key << "</td><td>" << value << "</td></tr>";
+ infoAdded = true;
+ }
+ };
+
+ // 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 << "</p>";
+
+ tooltip << "<table cellspacing='5' cellpadding='0'>";
+ if (_ircUser->isAway()) {
+ QString awayMessageHTML = QString("<p class='italic'>%1</p>").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 "<nick> 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());
+ }
+
+ // 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("<p class='italic'>%1</p>").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 "<nick> 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
+ // Not used further down...
+ // 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);
+ addRow(NetworkItem::escapeHTML(tr("Idling since"), true), secondsToString(idleTime), true);
+ }
+
+ if (_ircUser->loginTime().isValid()) {
+ addRow(NetworkItem::escapeHTML(tr("Login time"), true), _ircUser->loginTime().toString(), true);
+ }
+
+ addRow(tr("Server"), NetworkItem::escapeHTML(_ircUser->server()), !_ircUser->server().isEmpty());
+ tooltip << "</table>";
+ }
+
+ // If no further information found, offer an explanatory message
+ if (!infoAdded)
+ tooltip << "<p class='italic' align='center'>" << tr("No information available") << "</p>";
+
+ tooltip << "</qt>";
+ return strTooltip;
+}
+
+void QueryBufferItem::setIrcUser(IrcUser* ircUser)
+{
+ if (_ircUser == ircUser)
+ return;
+
+ if (_ircUser) {
+ disconnect(_ircUser, nullptr, this, nullptr);
+ }
+
+ if (ircUser) {
+ connect(ircUser, &IrcUser::destroyed, this, &QueryBufferItem::removeIrcUser);
+ connect(ircUser, &IrcUser::quited, this, &QueryBufferItem::removeIrcUser);
+ connect(ircUser, &IrcUser::awaySet, this, [this]() { emit dataChanged(); });
+ connect(ircUser, &IrcUser::encryptedSet, this, &BufferItem::setEncrypted);
+ }
+
+ _ircUser = ircUser;
+ emit dataChanged();
+}
+
+void QueryBufferItem::removeIrcUser()