/***************************************************************************
- * Copyright (C) 2005-2018 by the Quassel Project *
+ * Copyright (C) 2005-2022 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
#include "chatmonitorsettingspage.h"
-#include "client.h"
-#include "icon.h"
-#include "networkmodel.h"
-#include "bufferviewconfig.h"
+#include <QMessageBox>
+#include <QVariant>
+
+#include "backlogrequester.h"
+#include "backlogsettings.h"
#include "buffermodel.h"
#include "bufferview.h"
+#include "bufferviewconfig.h"
#include "bufferviewfilter.h"
#include "chatviewsettings.h"
+#include "client.h"
+#include "icon.h"
+#include "networkmodel.h"
+#include "util.h"
-#include <QVariant>
-
-ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget *parent)
+ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget* parent)
: SettingsPage(tr("Interface"), tr("Chat Monitor"), parent)
{
ui.setupUi(this);
ui.operationMode->addItem(tr("Opt Out"), ChatViewSettings::OptOut);
// connect slots
- connect(ui.operationMode, SIGNAL(currentIndexChanged(int)), SLOT(switchOperationMode(int)));
+ connect(ui.operationMode, selectOverload<int>(&QComboBox::currentIndexChanged), this, &ChatMonitorSettingsPage::switchOperationMode);
connect(ui.showHighlights, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged);
connect(ui.showOwnMessages, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged);
connect(ui.alwaysOwn, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged);
connect(ui.showBacklog, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged);
connect(ui.includeRead, &QAbstractButton::toggled, this, &ChatMonitorSettingsPage::widgetHasChanged);
-}
+ // AsNeededBacklogRequester conflicts with showing backlog in Chat Monitor
+ BacklogSettings backlogSettings;
+ backlogSettings.initAndNotify("RequesterType", this, &ChatMonitorSettingsPage::setRequesterType, BacklogRequester::AsNeeded);
+}
bool ChatMonitorSettingsPage::hasDefaults() const
{
return true;
}
-
void ChatMonitorSettingsPage::defaults()
{
// NOTE: Whenever changing defaults here, also update ChatMonitorFilter::ChatMonitorFilter()
widgetHasChanged();
}
-
void ChatMonitorSettingsPage::load()
{
if (settings.contains("Default"))
if (!settings["Buffers"].toList().isEmpty()) {
QList<BufferId> bufferIdsFromConfig;
// remove all active buffers from the available config
- foreach(QVariant v, settings["Buffers"].toList()) {
+ foreach (QVariant v, settings["Buffers"].toList()) {
bufferIdsFromConfig << v.value<BufferId>();
allBufferIds.removeAll(v.value<BufferId>());
}
Client::networkModel()->sortBufferIds(bufferIdsFromConfig);
- _configActive->initSetBufferList(bufferIdsFromConfig);
+ _configActive->setBufferList(bufferIdsFromConfig);
}
ui.activeBuffers->setFilteredModel(Client::bufferModel(), _configActive);
Client::networkModel()->sortBufferIds(allBufferIds);
- _configAvailable->initSetBufferList(allBufferIds);
+ _configAvailable->setBufferList(allBufferIds);
ui.availableBuffers->setFilteredModel(Client::bufferModel(), _configAvailable);
setChangedState(false);
}
-
void ChatMonitorSettingsPage::loadSettings()
{
// NOTE: Whenever changing defaults here, also update ChatMonitorFilter::ChatMonitorFilter()
// and ChatMonitorSettingsPage::defaults() to match
ChatViewSettings chatViewSettings("ChatMonitor");
- settings["OperationMode"] = (ChatViewSettings::OperationMode)
- chatViewSettings.value("OperationMode", ChatViewSettings::OptOut).toInt();
+ settings["OperationMode"] = (ChatViewSettings::OperationMode)chatViewSettings.value("OperationMode", ChatViewSettings::OptOut).toInt();
settings["ShowHighlights"] = chatViewSettings.value("ShowHighlights", false);
settings["ShowOwnMsgs"] = chatViewSettings.value("ShowOwnMsgs", true);
settings["AlwaysOwn"] = chatViewSettings.value("AlwaysOwn", false);
settings["IncludeRead"] = chatViewSettings.value("IncludeRead", false);
}
-
void ChatMonitorSettingsPage::save()
{
ChatViewSettings chatViewSettings("ChatMonitor");
// save list of active buffers
QVariantList saveableBufferIdList;
- foreach(BufferId id, _configActive->bufferList()) {
- saveableBufferIdList << QVariant::fromValue<BufferId>(id);
+ foreach (BufferId id, _configActive->bufferList()) {
+ saveableBufferIdList << QVariant::fromValue(id);
}
chatViewSettings.setValue("Buffers", saveableBufferIdList);
setChangedState(false);
}
-
void ChatMonitorSettingsPage::widgetHasChanged()
{
bool changed = testHasChanged();
- if (changed != hasChanged()) setChangedState(changed);
+ if (changed != hasChanged())
+ setChangedState(changed);
}
-
bool ChatMonitorSettingsPage::testHasChanged()
{
if (settings["OperationMode"].toInt() != ui.operationMode->currentIndex() + 1)
if (_configActive->bufferList().count() != settings["Buffers"].toList().count())
return true;
- QSet<BufferId> uiBufs = _configActive->bufferList().toSet();
+ QSet<BufferId> uiBufs = toQSet(_configActive->bufferList());
QSet<BufferId> settingsBufs;
- foreach(QVariant v, settings["Buffers"].toList())
- settingsBufs << v.value<BufferId>();
+ foreach (QVariant v, settings["Buffers"].toList())
+ settingsBufs << v.value<BufferId>();
if (uiBufs != settingsBufs)
return true;
return false;
}
-
-//TODO: - support drag 'n drop
+// TODO: - support drag 'n drop
// - adding of complete networks(?)
/*
toggleBuffers takes each a bufferView and its config for "input" and "output".
Any selected item will be moved over from the input to the output bufferview.
*/
-void ChatMonitorSettingsPage::toggleBuffers(BufferView *inView, BufferViewConfig *inCfg, BufferView *outView, BufferViewConfig *outCfg)
+void ChatMonitorSettingsPage::toggleBuffers(BufferView* inView, BufferViewConfig* inCfg, BufferView* outView, BufferViewConfig* outCfg)
{
// Fill QMap with selected items ordered by selection row
- QMap<int, QList<BufferId> > selectedBuffers;
- foreach(QModelIndex index, inView->selectionModel()->selectedIndexes()) {
+ QMap<int, QList<BufferId>> selectedBuffers;
+ foreach (QModelIndex index, inView->selectionModel()->selectedIndexes()) {
BufferId inBufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
if (index.data(NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType) {
// TODO:
This can probably be removed whenever BufferViewConfig::bulkAdd or something
like that is available.
*/
- qobject_cast<BufferViewFilter *>(outView->model())->setConfig(nullptr);
- qobject_cast<BufferViewFilter *>(inView->model())->setConfig(nullptr);
+ qobject_cast<BufferViewFilter*>(outView->model())->setConfig(nullptr);
+ qobject_cast<BufferViewFilter*>(inView->model())->setConfig(nullptr);
// actually move the ids
- foreach(QList<BufferId> list, selectedBuffers) {
- foreach(BufferId buffer, list) {
+ foreach (QList<BufferId> list, selectedBuffers) {
+ foreach (BufferId buffer, list) {
outCfg->addBuffer(buffer, 0);
inCfg->removeBuffer(buffer);
}
widgetHasChanged();
}
-
void ChatMonitorSettingsPage::on_activateBuffer_clicked()
{
if (ui.availableBuffers->currentIndex().isValid() && ui.availableBuffers->selectionModel()->hasSelection()) {
}
}
-
void ChatMonitorSettingsPage::on_deactivateBuffer_clicked()
{
if (ui.activeBuffers->currentIndex().isValid() && ui.activeBuffers->selectionModel()->hasSelection()) {
}
}
-
/*
switchOperationMode gets called on combobox signal currentIndexChanged.
modeIndex is the row id in combobox itemlist
}
widgetHasChanged();
}
+
+void ChatMonitorSettingsPage::setRequesterType(const QVariant& v)
+{
+ bool usingAsNeededRequester = (v.toInt() == BacklogRequester::AsNeeded);
+ ui.showBacklogUnavailableDetails->setVisible(usingAsNeededRequester);
+ if (usingAsNeededRequester) {
+ ui.showBacklog->setText(tr("Show messages from backlog (not available)"));
+ }
+ else {
+ ui.showBacklog->setText(tr("Show messages from backlog"));
+ }
+}
+
+void ChatMonitorSettingsPage::on_showBacklogUnavailableDetails_clicked()
+{
+ // Explain that backlog fetching is disabled, so backlog messages won't show up
+ //
+ // Technically, backlog messages *will* show up once fetched, e.g. after clicking on a buffer.
+ // This might be too trivial of a detail to warrant explaining, though.
+ QMessageBox::information(this,
+ tr("Messages from backlog are not fetched"),
+ QString("<p>%1</p><p>%2</p>")
+ .arg(tr("No initial backlog will be fetched when using the backlog request method of <i>%1</i>.")
+ .arg(tr("Only fetch when needed").replace(" ", " ")),
+ tr("Configure this in the <i>%1</i> settings page.")
+ .arg(tr("Backlog Fetching").replace(" ", " "))
+ )
+ );
+ // Re-use translations of "Only fetch when needed" and "Backlog Fetching" as this is a
+ // word-for-word reference, forcing all spaces to be non-breaking
+}