X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fchatmonitorsettingspage.cpp;h=16a4ca950b3af1e7b5f7387c7e7585f12bd0c586;hp=0c3819f1264789d280ab76f94aa9d792d599548a;hb=9188f1a4880dc7f4c26612a265c1d874f6df5a8c;hpb=695758015a80eb8c158a9ac4c0f1c0b547e70df3 diff --git a/src/qtui/settingspages/chatmonitorsettingspage.cpp b/src/qtui/settingspages/chatmonitorsettingspage.cpp index 0c3819f1..16a4ca95 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.cpp +++ b/src/qtui/settingspages/chatmonitorsettingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,25 +20,24 @@ #include "chatmonitorsettingspage.h" -#include +#include -#include "client.h" -#include "networkmodel.h" -#include "bufferviewconfig.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 - -ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget *parent) +ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget* parent) : SettingsPage(tr("Interface"), tr("Chat Monitor"), parent) { ui.setupUi(this); - ui.activateBuffer->setIcon(QIcon::fromTheme("go-next")); - ui.deactivateBuffer->setIcon(QIcon::fromTheme("go-previous")); + ui.activateBuffer->setIcon(icon::get("go-next")); + ui.deactivateBuffer->setIcon(icon::get("go-previous")); // setup available buffers config (for the bufferview on the left) _configAvailable = new BufferViewConfig(-667, this); @@ -61,25 +60,28 @@ ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget *parent) ui.operationMode->addItem(tr("Opt Out"), ChatViewSettings::OptOut); // connect slots - connect(ui.operationMode, SIGNAL(currentIndexChanged(int)), SLOT(switchOperationMode(int))); - connect(ui.showHighlights, SIGNAL(toggled(bool)), SLOT(widgetHasChanged())); - connect(ui.showOwnMessages, SIGNAL(toggled(bool)), SLOT(widgetHasChanged())); - connect(ui.showBacklog, SIGNAL(toggled(bool)), SLOT(widgetHasChanged())); - connect(ui.includeRead, SIGNAL(toggled(bool)), SLOT(widgetHasChanged())); + connect(ui.operationMode, selectOverload(&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); } - bool ChatMonitorSettingsPage::hasDefaults() const { return true; } - void ChatMonitorSettingsPage::defaults() { + // NOTE: Whenever changing defaults here, also update ChatMonitorFilter::ChatMonitorFilter() + // and ChatMonitorSettingsPage::loadSettings() to match + settings["OperationMode"] = ChatViewSettings::OptOut; settings["ShowHighlights"] = false; - settings["ShowOwnMsgs"] = false; + settings["ShowOwnMsgs"] = true; + settings["AlwaysOwn"] = false; settings["Buffers"] = QVariant(); settings["Default"] = true; settings["ShowBacklog"] = true; @@ -88,7 +90,6 @@ void ChatMonitorSettingsPage::defaults() widgetHasChanged(); } - void ChatMonitorSettingsPage::load() { if (settings.contains("Default")) @@ -100,6 +101,7 @@ void ChatMonitorSettingsPage::load() ui.operationMode->setCurrentIndex(settings["OperationMode"].toInt() - 1); ui.showHighlights->setChecked(settings["ShowHighlights"].toBool()); ui.showOwnMessages->setChecked(settings["ShowOwnMsgs"].toBool()); + ui.alwaysOwn->setChecked(settings["AlwaysOwn"].toBool()); ui.showBacklog->setChecked(settings["ShowBacklog"].toBool()); ui.includeRead->setChecked(settings["IncludeRead"].toBool()); @@ -109,36 +111,37 @@ void ChatMonitorSettingsPage::load() if (!settings["Buffers"].toList().isEmpty()) { QList bufferIdsFromConfig; // remove all active buffers from the available config - foreach(QVariant v, settings["Buffers"].toList()) { + foreach (QVariant v, settings["Buffers"].toList()) { bufferIdsFromConfig << v.value(); allBufferIds.removeAll(v.value()); } 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", false); + settings["ShowOwnMsgs"] = chatViewSettings.value("ShowOwnMsgs", true); + settings["AlwaysOwn"] = chatViewSettings.value("AlwaysOwn", false); settings["Buffers"] = chatViewSettings.value("Buffers", QVariantList()); settings["ShowBacklog"] = chatViewSettings.value("ShowBacklog", true); - settings["IncludeRead"] = chatViewSettings.value("IncludeRead", true); + settings["IncludeRead"] = chatViewSettings.value("IncludeRead", false); } - void ChatMonitorSettingsPage::save() { ChatViewSettings chatViewSettings("ChatMonitor"); @@ -146,12 +149,13 @@ void ChatMonitorSettingsPage::save() chatViewSettings.setValue("OperationMode", ui.operationMode->currentIndex() + 1); chatViewSettings.setValue("ShowHighlights", ui.showHighlights->isChecked()); chatViewSettings.setValue("ShowOwnMsgs", ui.showOwnMessages->isChecked()); + chatViewSettings.setValue("AlwaysOwn", ui.alwaysOwn->isChecked()); chatViewSettings.setValue("ShowBacklog", ui.showBacklog->isChecked()); chatViewSettings.setValue("IncludeRead", ui.includeRead->isChecked()); // save list of active buffers QVariantList saveableBufferIdList; - foreach(BufferId id, _configActive->bufferList()) { + foreach (BufferId id, _configActive->bufferList()) { saveableBufferIdList << QVariant::fromValue(id); } @@ -160,14 +164,13 @@ void ChatMonitorSettingsPage::save() 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) @@ -176,6 +179,8 @@ bool ChatMonitorSettingsPage::testHasChanged() return true; if (settings["ShowOwnMsgs"].toBool() != ui.showOwnMessages->isChecked()) return true; + if (settings["AlwaysOwn"].toBool() != ui.alwaysOwn->isChecked()) + return true; if (settings["ShowBacklog"].toBool() != ui.showBacklog->isChecked()) return true; if (settings["IncludeRead"].toBool() != ui.includeRead->isChecked()) @@ -186,27 +191,26 @@ bool ChatMonitorSettingsPage::testHasChanged() QSet uiBufs = _configActive->bufferList().toSet(); QSet settingsBufs; - foreach(QVariant v, settings["Buffers"].toList()) - settingsBufs << v.value(); + foreach (QVariant v, settings["Buffers"].toList()) + settingsBufs << v.value(); 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 > selectedBuffers; - foreach(QModelIndex index, inView->selectionModel()->selectedIndexes()) { + QMap> selectedBuffers; + foreach (QModelIndex index, inView->selectionModel()->selectedIndexes()) { BufferId inBufferId = index.data(NetworkModel::BufferIdRole).value(); if (index.data(NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType) { // TODO: @@ -226,12 +230,12 @@ void ChatMonitorSettingsPage::toggleBuffers(BufferView *inView, BufferViewConfig This can probably be removed whenever BufferViewConfig::bulkAdd or something like that is available. */ - qobject_cast(outView->model())->setConfig(0); - qobject_cast(inView->model())->setConfig(0); + qobject_cast(outView->model())->setConfig(nullptr); + qobject_cast(inView->model())->setConfig(nullptr); // actually move the ids - foreach(QList list, selectedBuffers) { - foreach(BufferId buffer, list) { + foreach (QList list, selectedBuffers) { + foreach (BufferId buffer, list) { outCfg->addBuffer(buffer, 0); inCfg->removeBuffer(buffer); } @@ -243,7 +247,6 @@ void ChatMonitorSettingsPage::toggleBuffers(BufferView *inView, BufferViewConfig widgetHasChanged(); } - void ChatMonitorSettingsPage::on_activateBuffer_clicked() { if (ui.availableBuffers->currentIndex().isValid() && ui.availableBuffers->selectionModel()->hasSelection()) { @@ -252,7 +255,6 @@ void ChatMonitorSettingsPage::on_activateBuffer_clicked() } } - void ChatMonitorSettingsPage::on_deactivateBuffer_clicked() { if (ui.activeBuffers->currentIndex().isValid() && ui.activeBuffers->selectionModel()->hasSelection()) { @@ -261,14 +263,13 @@ void ChatMonitorSettingsPage::on_deactivateBuffer_clicked() } } - /* switchOperationMode gets called on combobox signal currentIndexChanged. modeIndex is the row id in combobox itemlist */ void ChatMonitorSettingsPage::switchOperationMode(int idx) { - ChatViewSettings::OperationMode mode = (ChatViewSettings::OperationMode)(idx + 1); + auto mode = (ChatViewSettings::OperationMode)(idx + 1); if (mode == ChatViewSettings::OptIn) { ui.labelActiveBuffers->setText(tr("Show:")); }