bool AwayLogFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent) QModelIndex source_index = sourceModel()->index(sourceRow, 0); Message::Flags flags = (Message::Flags)sourceModel()->data(source_index, MessageModel::FlagsRole).toInt(); // Only show highlights from the backlog if (!(flags & Message::Backlog && flags & Message::Highlight)) { return false; } // do not use invalid buffers BufferId bufferId = sourceModel()->data(source_index, MessageModel::BufferIdRole).value<BufferId>(); if (!bufferId.isValid()) { return false; } // only show messages that were sent after the user detached if (Client::networkModel()->lastSeenMsgId(bufferId) >= sourceModel()->data(source_index, MessageModel::MsgIdRole).value<MsgId>()) { return false; } // ignorelist handling // only match if message is not flagged as server msg if (!(flags & Message::ServerMsg) && Client::ignoreListManager() && Client::ignoreListManager()->match(source_index.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufferId))) { return false; } return true; }
void Bb10Ui::onChannelListTriggered(const QVariantList index) { // Headers are not clickable if (index.length() < 2) return; QModelIndex modelIndex = qobject_cast<DataModelAdapter*>(m_channelListView->dataModel())->getQModelIndex(index); BufferInfo bufferInfo = modelIndex.data(NetworkModel::BufferInfoRole).value<BufferInfo>(); BufferId id = bufferInfo.bufferId(); if (!id.isValid()) return; QString bufferName = bufferInfo.bufferName(); qDebug() << "xxxxx Bb10Ui::onChannelListTriggered bufferInfo = " << bufferInfo << " index = " << index << " modelIndex = " << modelIndex; ChatView *view = qobject_cast<ChatView *>(m_chatViews.value(id)); if (!view) { view = new ChatView(id, bufferName); m_chatViews[id] = view; } m_currentBufferId = id; Client::bufferModel()->switchToBuffer(id); Client::networkModel()->clearBufferActivity(id); Client::setBufferLastSeenMsg(id, view->getLastMsgId()); Client::backlogManager()->checkForBacklog(id); navPanePush(view->getPage()); // ask channelListView to update the appearance qobject_cast<DataModelAdapter*>(m_channelListView->dataModel())->handleBufferModelDataChanged(modelIndex, modelIndex); }
void TopicWidget::setTopic(const QModelIndex &index) { QString newtopic; bool readonly = true; BufferId id = index.data(NetworkModel::BufferIdRole).value<BufferId>(); if(id.isValid()) { QModelIndex index0 = index.sibling(index.row(), 0); const Network *network = Client::network(Client::networkModel()->networkId(id)); switch(Client::networkModel()->bufferType(id)) { case BufferInfo::StatusBuffer: if(network) { newtopic = QString("%1 (%2) | %3 | %4") .arg(Qt::escape(network->networkName())) .arg(Qt::escape(network->currentServer())) .arg(tr("Users: %1").arg(network->ircUsers().count())) .arg(tr("Lag: %1 msecs").arg(network->latency())); } else { newtopic = index0.data(Qt::DisplayRole).toString(); } break; case BufferInfo::ChannelBuffer: newtopic = index.sibling(index.row(), 1).data().toString(); readonly = false; break; case BufferInfo::QueryBuffer: { QString nickname = index0.data(Qt::DisplayRole).toString(); if(network) { const IrcUser *user = network->ircUser(nickname); if(user) { newtopic = QString("%1%2%3 | %4@%5").arg(nickname) .arg(user->userModes().isEmpty() ? QString() : QString(" (+%1)").arg(user->userModes())) .arg(user->realName().isEmpty() ? QString() : QString(" | %1").arg(user->realName())) .arg(user->user()) .arg(user->host()); } else { // no such user newtopic = nickname; } } else { // no valid Network-Obj. newtopic = nickname; } break; } default: newtopic = index0.data(Qt::DisplayRole).toString(); } } _topic = newtopic; _readonly = readonly; ui.topicEditButton->setVisible(!_readonly); ui.topicLabel->setText(newtopic); ui.topicLineEdit->setPlainText(newtopic); switchPlain(); }
void TitleSetter::changeWindowTitle(const QModelIndex &index) { BufferId id = index.data(NetworkModel::BufferIdRole).value<BufferId>(); if (!id.isValid()) return; QString title; if (Client::networkModel()->bufferType(id) == BufferInfo::StatusBuffer) title = index.data().toString(); else title = QString("%1 (%2)").arg(index.data().toString(), Client::networkModel()->networkName(id)); QString newTitle = QString("%1 - %2").arg("Quassel IRC").arg(title); _mainWin->setWindowTitle(newTitle); _mainWin->setWindowIconText(newTitle); }
void MainWin::saveStateToSettings(UiSettings &s) { s.setValue("MainWinSize", _normalSize); s.setValue("MainWinPos", _normalPos); s.setValue("MainWinState", saveState()); s.setValue("MainWinGeometry", saveGeometry()); s.setValue("MainWinMinimized", isMinimized()); s.setValue("MainWinMaximized", isMaximized()); s.setValue("MainWinHidden", !isVisible()); BufferId lastBufId = Client::bufferModel()->currentBuffer(); if(lastBufId.isValid()) s.setValue("LastUsedBufferId", lastBufId.toInt()); #ifdef HAVE_KDE saveAutoSaveSettings(); #endif }
bool BufferViewOverlayFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { if (!_overlay) return false; QModelIndex source_bufferIndex = sourceModel()->index(source_row, 0, source_parent); if (!source_bufferIndex.isValid()) { qWarning() << "filterAcceptsRow has been called with an invalid Child"; return false; } NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_bufferIndex, NetworkModel::ItemTypeRole).toInt(); NetworkId networkId = sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value<NetworkId>(); if (!_overlay->networkIds().contains(networkId) && !_overlay->allNetworks()) { return false; } else if (itemType == NetworkModel::NetworkItemType) { // network items don't need further checks. return true; } int activityLevel = sourceModel()->data(source_bufferIndex, NetworkModel::BufferActivityRole).toInt(); if (_overlay->minimumActivity() > activityLevel) return false; int bufferType = sourceModel()->data(source_bufferIndex, NetworkModel::BufferTypeRole).toInt(); if (!(_overlay->allowedBufferTypes() & bufferType)) return false; BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value<BufferId>(); Q_ASSERT(bufferId.isValid()); if (_overlay->bufferIds().contains(bufferId)) return true; if (_overlay->tempRemovedBufferIds().contains(bufferId)) return activityLevel > BufferInfo::OtherActivity; if (_overlay->removedBufferIds().contains(bufferId)) return false; // the buffer is not known to us qDebug() << "BufferViewOverlayFilter::filterAcceptsRow()" << bufferId << "is unknown!"; return false; }
void QtUi::notificationActivated(uint notificationId) { if(notificationId != 0) { QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin(); while(i != _notifications.end()) { if(i->notificationId == notificationId) { BufferId bufId = i->bufferId; if(bufId.isValid()) Client::bufferModel()->switchToBuffer(bufId); break; } ++i; } } closeNotification(notificationId); activateMainWidget(); }
void BufferWidget::showChatView(BufferId id) { if(!id.isValid()) { ui.stackedWidget->setCurrentWidget(ui.page); } else { ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id)); Q_ASSERT(view); ui.stackedWidget->setCurrentWidget(view); _chatViewSearchController->setScene(view->scene()); } }
bool AwayLogFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent) QModelIndex source_index = sourceModel()->index(sourceRow, 0); Message::Flags flags = (Message::Flags)sourceModel()->data(source_index, MessageModel::FlagsRole).toInt(); if(!(flags & Message::Backlog && flags & Message::Highlight)) return false; BufferId bufferId = sourceModel()->data(source_index, MessageModel::BufferIdRole).value<BufferId>(); if(!bufferId.isValid()) { return false; } if(Client::networkModel()->lastSeenMsgId(bufferId) >= sourceModel()->data(source_index, MessageModel::MsgIdRole).value<MsgId>()) return false; return true; }
void QtUi::closeNotifications(BufferId bufferId) { QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin(); while(i != _notifications.end()) { if(!bufferId.isValid() || i->bufferId == bufferId) { foreach(AbstractNotificationBackend *backend, _notificationBackends) backend->close(i->notificationId); i = _notifications.erase(i); } else ++i; } }
void BufferWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { ChatView *prevView = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget()); AbstractBufferContainer::currentChanged(current, previous); // switch first to avoid a redraw // we need to hide the marker line if it's already/still at the bottom of the view (and not scrolled up) ChatView *curView = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget()); if(curView) { BufferId curBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>(); if(curBufferId.isValid()) { MsgId markerMsgId = Client::networkModel()->markerLineMsgId(curBufferId); if(markerMsgId == curView->lastMsgId() && markerMsgId == curView->lastVisibleMsgId()) curView->setMarkerLineVisible(false); else curView->setMarkerLineVisible(true); } } if(prevView && autoMarkerLine()) setMarkerLine(prevView, false); }
void ClientUserInputHandler::switchBuffer(const NetworkId &networkId, const QString &bufferName) { BufferId newBufId = Client::networkModel()->bufferId(networkId, bufferName); if (!newBufId.isValid()) { Client::bufferModel()->switchToBufferAfterCreation(networkId, bufferName); } else { Client::bufferModel()->switchToBuffer(newBufId); // unhide the buffer ClientBufferViewManager *clientBufferViewManager = Client::bufferViewManager(); QList<ClientBufferViewConfig *> bufferViewConfigList = clientBufferViewManager->clientBufferViewConfigs(); foreach(ClientBufferViewConfig *bufferViewConfig, bufferViewConfigList) { if (bufferViewConfig->temporarilyRemovedBuffers().contains(newBufId)) { bufferViewConfig->requestAddBuffer(newBufId, bufferViewConfig->bufferList().length()); //if (bufferViewConfig->sortAlphabetically()) { // TODO we need to trigger a sort here, but can't reach the model required // to get a bufferviewfilter, as the bufferviewmanager only managers configs //BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model()); //} } } } }
bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { Q_UNUSED(sourceParent); QModelIndex sourceIdx = sourceModel()->index(sourceRow, 2); Message::Type messageType = (Message::Type)sourceIdx.data(MessageModel::TypeRole).toInt(); // apply message type filter if (_messageTypeFilter & messageType) return false; if (_validBuffers.isEmpty()) return true; BufferId bufferId = sourceIdx.data(MessageModel::BufferIdRole).value<BufferId>(); if (!bufferId.isValid()) { return true; } // MsgId msgId = sourceIdx.data(MessageModel::MsgIdRole).value<MsgId>(); Message::Flags flags = (Message::Flags)sourceIdx.data(MessageModel::FlagsRole).toInt(); NetworkId myNetworkId = networkId(); NetworkId msgNetworkId = Client::networkModel()->networkId(bufferId); if (myNetworkId != msgNetworkId) return false; // ignorelist handling // only match if message is not flagged as server msg if (!(flags & Message::ServerMsg) && Client::ignoreListManager() && Client::ignoreListManager()->match(sourceIdx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufferId))) return false; if (flags & Message::Redirected) { int redirectionTarget = 0; switch (messageType) { case Message::Notice: if (Client::networkModel()->bufferType(bufferId) != BufferInfo::ChannelBuffer) { if (flags & Message::ServerMsg) { // server notice redirectionTarget = _serverNoticesTarget; } else { redirectionTarget = _userNoticesTarget; } } break; case Message::Error: redirectionTarget = _errorMsgsTarget; break; default: break; } if (redirectionTarget & BufferSettings::DefaultBuffer && _validBuffers.contains(bufferId)) return true; if (redirectionTarget & BufferSettings::CurrentBuffer && !(flags & Message::Backlog)) { BufferId redirectedTo = sourceModel()->data(sourceIdx, MessageModel::RedirectedToRole).value<BufferId>(); if (!redirectedTo.isValid()) { BufferId redirectedTo = Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>(); if (redirectedTo.isValid()) sourceModel()->setData(sourceIdx, QVariant::fromValue<BufferId>(redirectedTo), MessageModel::RedirectedToRole); } if (_validBuffers.contains(redirectedTo)) return true; } if (redirectionTarget & BufferSettings::StatusBuffer) { QSet<BufferId>::const_iterator idIter = _validBuffers.constBegin(); while (idIter != _validBuffers.constEnd()) { if (Client::networkModel()->bufferType(*idIter) == BufferInfo::StatusBuffer) return true; ++idIter; } } return false; } if (_validBuffers.contains(bufferId)) { return true; } else { // show Quit messages in Query buffers: if (bufferType() != BufferInfo::QueryBuffer) return false; if (!(messageType & Message::Quit)) return false; if (myNetworkId != msgNetworkId) return false; // Extract timestamp and nickname from the new quit message qint64 messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole).value<QDateTime>().toMSecsSinceEpoch(); QString quiter = nickFromMask(sourceModel()->data(sourceIdx, MessageModel::MessageRole).value<Message>().sender()).toLower(); // Check that nickname matches query name if (quiter != bufferName().toLower()) return false; // Check if a quit message was already forwarded within +/- 1000 ms static constexpr qint64 MAX_QUIT_DELTA_MS = 1 * 1000; // No need to check if it's the appropriate buffer, each query has a unique message filter if (std::binary_search(_filteredQuitMsgTime.begin(), _filteredQuitMsgTime.end(), messageTimestamp, [](qint64 a, qint64 b) { return ((a + MAX_QUIT_DELTA_MS) < b); })) { // New element is less than if at least 1000 ms older/newer // Match found, no need to forward another quit message return false; } // Mark query as having a quit message inserted auto* that = const_cast<MessageFilter*>(this); that->_filteredQuitMsgTime.insert(messageTimestamp); return true; } }
void QtUi::bufferMarkedAsRead(BufferId bufferId) { if(bufferId.isValid()) { closeNotifications(bufferId); } }
// add a list of actions sensible for the current item(s) void ContextMenuActionProvider::addActions(QMenu *menu, const QList<QModelIndex> &indexList_, MessageFilter *filter_, const QString &contextItem_, QObject *receiver_, const char *method_, bool isCustomBufferView) { if (!indexList_.count()) return; setIndexList(indexList_); setMessageFilter(filter_); setContextItem(contextItem_); setSlot(receiver_, method_); if (!messageFilter()) { // this means we are in a BufferView (or NickView) rather than a ChatView // first index in list determines the menu type (just in case we have both buffers and networks selected, for example) QModelIndex index = indexList().at(0); NetworkModel::ItemType itemType = static_cast<NetworkModel::ItemType>(index.data(NetworkModel::ItemTypeRole).toInt()); switch (itemType) { case NetworkModel::NetworkItemType: addNetworkItemActions(menu, index); break; case NetworkModel::BufferItemType: addBufferItemActions(menu, index, isCustomBufferView); break; case NetworkModel::IrcUserItemType: addIrcUserActions(menu, index); break; default: return; } } else { // ChatView actions if (contextItem().isEmpty()) { // a) query buffer: handle like ircuser // b) general chatview: handle like channel iff it displays a single buffer // NOTE stuff breaks probably with merged buffers, need to rework a lot around here then if (messageFilter()->containedBuffers().count() == 1) { // we can handle this like a single bufferItem QModelIndex index = Client::networkModel()->bufferIndex(messageFilter()->containedBuffers().values().at(0)); setIndexList(index); addBufferItemActions(menu, index); return; } else { // TODO: actions for merged buffers... _indexList contains the index of the message we clicked on } } else { // context item = chan or nick, _indexList = buf where the msg clicked on originated if (isChannelName(contextItem())) { QModelIndex msgIdx = indexList().at(0); if (!msgIdx.isValid()) return; NetworkId networkId = msgIdx.data(NetworkModel::NetworkIdRole).value<NetworkId>(); BufferId bufId = Client::networkModel()->bufferId(networkId, contextItem()); if (bufId.isValid()) { QModelIndex targetIdx = Client::networkModel()->bufferIndex(bufId); setIndexList(targetIdx); addAction(BufferJoin, menu, targetIdx, InactiveState); addAction(BufferSwitchTo, menu, targetIdx, ActiveState); } else addAction(JoinChannel, menu); } else { // TODO: actions for a nick } } } }
void ContextMenuActionProvider::addActions(QMenu *menu, BufferId bufId, QObject *receiver, const char *method) { if (!bufId.isValid()) return; addActions(menu, Client::networkModel()->bufferIndex(bufId), receiver, method); }
bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); QModelIndex sourceIdx = sourceModel()->index(sourceRow, 2); Message::Type messageType = (Message::Type)sourceIdx.data(MessageModel::TypeRole).toInt(); // apply message type filter if(_messageTypeFilter & messageType) return false; if(_validBuffers.isEmpty()) return true; BufferId bufferId = sourceIdx.data(MessageModel::BufferIdRole).value<BufferId>(); if(!bufferId.isValid()) { return true; } MsgId msgId = sourceIdx.data(MessageModel::MsgIdRole).value<MsgId>(); Message::Flags flags = (Message::Flags)sourceIdx.data(MessageModel::FlagsRole).toInt(); NetworkId myNetworkId = networkId(); NetworkId msgNetworkId = Client::networkModel()->networkId(bufferId); if(myNetworkId != msgNetworkId) return false; // ignorelist handling // only match if message is not flagged as server msg if(!(flags & Message::ServerMsg) && Client::ignoreListManager() && Client::ignoreListManager()->match(sourceIdx.data(MessageModel::MessageRole).value<Message>(), Client::networkModel()->networkName(bufferId))) return false; if(flags & Message::Redirected) { int redirectionTarget = 0; switch(messageType) { case Message::Notice: if(Client::networkModel()->bufferType(bufferId) != BufferInfo::ChannelBuffer) { if(flags & Message::ServerMsg) { // server notice redirectionTarget = _serverNoticesTarget; } else { redirectionTarget = _userNoticesTarget; } } break; case Message::Error: redirectionTarget = _errorMsgsTarget; break; default: break; } if(redirectionTarget & BufferSettings::DefaultBuffer && _validBuffers.contains(bufferId)) return true; if(redirectionTarget & BufferSettings::CurrentBuffer && !(flags & Message::Backlog)) { BufferId redirectedTo = sourceModel()->data(sourceIdx, MessageModel::RedirectedToRole).value<BufferId>(); if(!redirectedTo.isValid()) { BufferId redirectedTo = Client::bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>(); if(redirectedTo.isValid()) sourceModel()->setData(sourceIdx, QVariant::fromValue<BufferId>(redirectedTo), MessageModel::RedirectedToRole); } if(_validBuffers.contains(redirectedTo)) return true; } if(redirectionTarget & BufferSettings::StatusBuffer) { QSet<BufferId>::const_iterator idIter = _validBuffers.constBegin(); while(idIter != _validBuffers.constEnd()) { if(Client::networkModel()->bufferType(*idIter) == BufferInfo::StatusBuffer) return true; idIter++; } } return false; } if(_validBuffers.contains(bufferId)) { return true; } else { // show Quit messages in Query buffers: if(bufferType() != BufferInfo::QueryBuffer) return false; if(!(messageType & Message::Quit)) return false; if(myNetworkId != msgNetworkId) return false; uint messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole).value<QDateTime>().toTime_t(); QString quiter = sourceModel()->data(sourceIdx, Qt::DisplayRole).toString().section(' ', 0, 0, QString::SectionSkipEmpty).toLower(); if(quiter != bufferName().toLower()) return false; if(_filteredQuitMsgs.contains(quiter, messageTimestamp)) return false; MessageFilter *that = const_cast<MessageFilter *>(this); that->_filteredQuitMsgs.insert(quiter, messageTimestamp); return true; } }