X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fchatmonitorsettingspage.cpp;h=cbfa26ebfc2cc86c221b9ccf09b5c3df0e067491;hp=c504969714bbdb8bbaaf858e6c824ee8ae4fca14;hb=731ec69d4608ba95e3ae4f154b8ca1852e1db2e5;hpb=77397f5e999830077fee13187c6a1ee044d92545;ds=sidebyside diff --git a/src/qtui/settingspages/chatmonitorsettingspage.cpp b/src/qtui/settingspages/chatmonitorsettingspage.cpp index c5049697..cbfa26eb 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.cpp +++ b/src/qtui/settingspages/chatmonitorsettingspage.cpp @@ -3,16 +3,16 @@ * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Blank Public License as published by * + * it under the terms of the GNU Blank Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Blank Public License for more details. * + * GNU Blank Public License for more details. * * * - * You should have received a copy of the GNU Blank Public License * + * You should have received a copy of the GNU Blank Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * @@ -20,7 +20,6 @@ #include "chatmonitorsettingspage.h" - #include "client.h" #include "networkmodel.h" #include "bufferviewconfig.h" @@ -28,24 +27,36 @@ #include "bufferview.h" #include "bufferviewfilter.h" #include "iconloader.h" -//#include "chatmonitorsettings.h" #include "chatviewsettings.h" #include ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget *parent) - : SettingsPage(tr("Behaviour"), tr("ChatMonitor"), parent) { + : SettingsPage(tr("General"), tr("Chat Monitor"), parent) { ui.setupUi(this); ui.activateBuffer->setIcon(SmallIcon("go-next")); ui.deactivateBuffer->setIcon(SmallIcon("go-previous")); - // initialize pointers - configAvailable = 0; - configActive = 0; + + // setup available buffers config (for the bufferview on the left) + _configAvailable = new BufferViewConfig(-667, this); + _configAvailable->setBufferViewName("tmpChatMonitorAvailableBuffers"); + _configAvailable->setSortAlphabetically(true); + _configAvailable->setDisableDecoration(true); + _configAvailable->setNetworkId(NetworkId()); + _configAvailable->setInitialized(); + + // setup active buffers config (for the bufferview on the right) + _configActive = new BufferViewConfig(-666, this); + _configActive->setBufferViewName("tmpChatMonitorActiveBuffers"); + _configActive->setSortAlphabetically(true); + _configActive->setDisableDecoration(true); + _configActive->setNetworkId(NetworkId()); + _configActive->setInitialized(); // fill combobox with operation modes - ui.operationMode->addItem("Opt-In", ChatViewSettings::OptIn); - ui.operationMode->addItem("Opt-Out", ChatViewSettings::OptOut); + ui.operationMode->addItem(tr("Opt In"), ChatViewSettings::OptIn); + ui.operationMode->addItem(tr("Opt Out"), ChatViewSettings::OptOut); // connect slots connect(ui.operationMode, SIGNAL(currentIndexChanged(int)), this, SLOT(switchOperationMode(int))); @@ -57,7 +68,7 @@ bool ChatMonitorSettingsPage::hasDefaults() const { void ChatMonitorSettingsPage::defaults() { settings["OperationMode"] = ChatViewSettings::OptOut; - settings["HighlightAlways"] = false; + settings["ShowHighlights"] = false; settings["Buffers"] = QVariant(); settings["Default"] = true; load(); @@ -65,32 +76,15 @@ void ChatMonitorSettingsPage::defaults() { } void ChatMonitorSettingsPage::load() { - delete configAvailable; - delete configActive; - - if (settings.contains("Default")) + if(settings.contains("Default")) settings.remove("Default"); else loadSettings(); ui.operationMode->setCurrentIndex(settings["OperationMode"].toInt() - 1); - ui.highlightAlways->setChecked(settings["HighlightAlways"].toBool()); + ui.showHighlights->setChecked(settings["ShowHighlights"].toBool()); - // setup available buffers config (for the bufferview on the left) - configAvailable = new BufferViewConfig(-667); - configAvailable->setBufferViewName("tmpChatMonitorAvailableBuffers"); - configAvailable->sortAlphabetically(); - configAvailable->setNetworkId(NetworkId()); - configAvailable->setInitialized(); - - // setup active buffers config (for the bufferview on the right) - configActive = new BufferViewConfig(-666); - configActive->setBufferViewName("tmpChatMonitorActiveBuffers"); - configActive->setSortAlphabetically(true); - configActive->setNetworkId(NetworkId()); - configActive->setInitialized(); - - // get all available buffer Ids + // get all available buffer Ids QList allBufferIds = Client::networkModel()->allBufferIds(); if(!settings["Buffers"].toList().isEmpty()) { @@ -98,39 +92,42 @@ void ChatMonitorSettingsPage::load() { // remove all active buffers from the available config foreach(QVariant v, settings["Buffers"].toList()) { bufferIdsFromConfig << v.value(); - allBufferIds.removeOne(v.value()); + allBufferIds.removeAll(v.value()); } - configActive->initSetBufferList(bufferIdsFromConfig); + qSort(bufferIdsFromConfig.begin(), bufferIdsFromConfig.end(), bufferIdLessThan); + _configActive->initSetBufferList(bufferIdsFromConfig); } - ui.activeBuffers->setFilteredModel(Client::bufferModel(), configActive); + ui.activeBuffers->setFilteredModel(Client::bufferModel(), _configActive); - configAvailable->initSetBufferList(allBufferIds); - ui.availableBuffers->setFilteredModel(Client::bufferModel(), configAvailable); + qSort(allBufferIds.begin(), allBufferIds.end(), bufferIdLessThan); + _configAvailable->initSetBufferList(allBufferIds); + ui.availableBuffers->setFilteredModel(Client::bufferModel(), _configAvailable); setChangedState(false); } void ChatMonitorSettingsPage::loadSettings() { - ChatViewSettings chatViewSettings; + ChatViewSettings chatViewSettings("ChatMonitor"); settings["OperationMode"] = static_cast(chatViewSettings.value("OperationMode", QVariant()).toInt()); + // Load default behavior if no or invalid settings found - if (settings["OperationMode"] == ChatViewSettings::InvalidMode) { + if(settings["OperationMode"] == ChatViewSettings::InvalidMode) { switchOperationMode(ui.operationMode->findData(ChatViewSettings::OptOut)); settings["OperationMode"] == ChatViewSettings::OptOut; } - settings["HighlightAlways"] = chatViewSettings.value("HighlightAlways", false); + settings["ShowHighlights"] = chatViewSettings.value("ShowHighlights", false); settings["Buffers"] = chatViewSettings.value("Buffers", QVariantList()); } void ChatMonitorSettingsPage::save() { - ChatViewSettings chatViewSettings; + ChatViewSettings chatViewSettings("ChatMonitor"); // save operation mode chatViewSettings.setValue("OperationMode", settings["OperationMode"]); - chatViewSettings.setValue("HighlightAlways", settings["HighlightAlways"]); + chatViewSettings.setValue("ShowHighlights", settings["ShowHighlights"]); // save list of active buffers - QVariantList saveableBufferIdList; - foreach(BufferId id, configActive->bufferList()) { + QVariantList saveableBufferIdList; + foreach(BufferId id, _configActive->bufferList()) { saveableBufferIdList << QVariant::fromValue(id); } @@ -145,7 +142,7 @@ void ChatMonitorSettingsPage::widgetHasChanged() { } bool ChatMonitorSettingsPage::testHasChanged() { - if (configAvailable != configActive) return true; + if (_configAvailable != _configActive) return true; return false; } @@ -156,23 +153,23 @@ bool ChatMonitorSettingsPage::testHasChanged() { 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()) { + foreach(QModelIndex index, inView->selectionModel()->selectedIndexes()) { BufferId inBufferId = index.data(NetworkModel::BufferIdRole).value(); if(index.data(NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType) { - // TODO: + // TODO: // If item is a network: move over all children and skip other selected items of this node } - else if (index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType) { + else if(index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType) { selectedBuffers[index.parent().row()] << inBufferId; } } // clear selection to be able to remove the bufferIds without errors - inView.selectionModel()->clearSelection(); + inView->selectionModel()->clearSelection(); /* Invalidate the BufferViewFilters' configs to get constant add/remove times @@ -180,40 +177,40 @@ 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(0); + qobject_cast(inView->model())->setConfig(0); // actually move the ids foreach (QList list, selectedBuffers) { foreach (BufferId buffer, list) { - outCfg.addBuffer(buffer,0); - inCfg.removeBuffer(buffer); + outCfg->addBuffer(buffer,0); + inCfg->removeBuffer(buffer); } } - outView.setFilteredModel(Client::bufferModel(), &outCfg); - inView.setFilteredModel(Client::bufferModel(), &inCfg); + outView->setFilteredModel(Client::bufferModel(), outCfg); + inView->setFilteredModel(Client::bufferModel(), inCfg); widgetHasChanged(); } void ChatMonitorSettingsPage::on_activateBuffer_clicked() { if (ui.availableBuffers->currentIndex().isValid() && ui.availableBuffers->selectionModel()->hasSelection()) { - toggleBuffers(*ui.availableBuffers, *configAvailable, *ui.activeBuffers, *configActive); + toggleBuffers(ui.availableBuffers, _configAvailable, ui.activeBuffers, _configActive); widgetHasChanged(); } } void ChatMonitorSettingsPage::on_deactivateBuffer_clicked() { if (ui.activeBuffers->currentIndex().isValid() && ui.activeBuffers->selectionModel()->hasSelection()) { - toggleBuffers(*ui.activeBuffers, *configActive, *ui.availableBuffers, *configAvailable); + toggleBuffers(ui.activeBuffers, _configActive, ui.availableBuffers, _configAvailable); widgetHasChanged(); } } -void ChatMonitorSettingsPage::on_highlightAlways_toggled(bool state) +void ChatMonitorSettingsPage::on_showHighlights_toggled(bool state) { - settings["HighlightAlways"] = state; + settings["ShowHighlights"] = state; widgetHasChanged(); } @@ -226,7 +223,7 @@ void ChatMonitorSettingsPage::switchOperationMode(int modeIndex) { if(newMode == ChatViewSettings::OptIn) { ui.labelActiveBuffers->setText(tr("Show:")); - } + } else if(newMode == ChatViewSettings::OptOut) { ui.labelActiveBuffers->setText(tr("Ignore:")); }