From 77397f5e999830077fee13187c6a1ee044d92545 Mon Sep 17 00:00:00 2001 From: Sebastian Goth Date: Mon, 1 Dec 2008 13:11:28 +0100 Subject: [PATCH] ChatMonitorSettingspage ported to 0.3.x ChatMonitorSettingspage ported to 0.3.x --- src/qtui/chatmonitorfilter.cpp | 36 +++ src/qtui/chatmonitorfilter.h | 6 + src/qtui/chatviewsettings.h | 11 +- src/qtui/mainwin.cpp | 2 + .../settingspages/chatmonitorsettingspage.cpp | 238 ++++++++++++++++++ .../settingspages/chatmonitorsettingspage.h | 60 +++++ .../settingspages/chatmonitorsettingspage.ui | 209 +++++++++++++++ src/qtui/settingspages/settingspages.inc | 2 +- 8 files changed, 562 insertions(+), 2 deletions(-) create mode 100644 src/qtui/settingspages/chatmonitorsettingspage.cpp create mode 100644 src/qtui/settingspages/chatmonitorsettingspage.h create mode 100644 src/qtui/settingspages/chatmonitorsettingspage.ui diff --git a/src/qtui/chatmonitorfilter.cpp b/src/qtui/chatmonitorfilter.cpp index 547ea27f..e51b2cd9 100644 --- a/src/qtui/chatmonitorfilter.cpp +++ b/src/qtui/chatmonitorfilter.cpp @@ -33,6 +33,21 @@ ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent) _showOwnMessages = viewSettings.value("showOwnMsgs", true).toBool(); viewSettings.notify("showFields", this, SLOT(showFieldsSettingsChanged(const QVariant &))); viewSettings.notify("showOwnMsgs", this, SLOT(showOwnMessagesSettingChanged(const QVariant &))); + + // ChatMonitorSettingsPage + QString highlightAlwaysSettingsId = "HighlightAlways"; + QString operationModeSettingsId = "OperationMode"; + QString buffersSettingsId = "Buffers"; + + _highlightAlways = viewSettings.value(highlightAlwaysSettingsId, false).toBool(); + _operationMode = viewSettings.value(operationModeSettingsId, 0).toInt(); + // read configured list of buffers to monitor/ignore + foreach(QVariant v, viewSettings.value(buffersSettingsId, QVariant()).toList()) + _bufferIds << v.value(); + + viewSettings.notify(highlightAlwaysSettingsId, this, SLOT(highlightAlwaysSettingsChanged(const QVariant &))); + viewSettings.notify(operationModeSettingsId, this, SLOT(operationModeSettingsChanged(const QVariant &))); + viewSettings.notify(buffersSettingsId, this, SLOT(buffersSettingsChanged(const QVariant &))); } bool ChatMonitorFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { @@ -46,6 +61,12 @@ bool ChatMonitorFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourc if(!(type & (Message::Plain | Message::Notice | Message::Action))) return false; + // ChatMonitorSettingsPage + if (_operationMode == ChatViewSettings::OptOut && !(_highlightAlways && flags & Message::Highlight) && _bufferIds.contains(sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value())) + return false; + if (_operationMode == ChatViewSettings::OptIn && !(_highlightAlways && flags & Message::Highlight) && !_bufferIds.contains(sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value())) + return false; + return true; } @@ -116,3 +137,18 @@ void ChatMonitorFilter::showFieldsSettingsChanged(const QVariant &newValue) { void ChatMonitorFilter::showOwnMessagesSettingChanged(const QVariant &newValue) { _showOwnMessages = newValue.toBool(); } + +void ChatMonitorFilter::highlightAlwaysSettingsChanged(const QVariant &newValue) { + _highlightAlways = newValue.toBool(); +} + +void ChatMonitorFilter::operationModeSettingsChanged(const QVariant &newValue) { + _operationMode = newValue.toInt(); +} + +void ChatMonitorFilter::buffersSettingsChanged(const QVariant &newValue) { + _bufferIds.clear(); + foreach (QVariant v, newValue.toList()) { + _bufferIds << v.value(); + } +} diff --git a/src/qtui/chatmonitorfilter.h b/src/qtui/chatmonitorfilter.h index 5c1cfe9b..75016636 100644 --- a/src/qtui/chatmonitorfilter.h +++ b/src/qtui/chatmonitorfilter.h @@ -54,10 +54,16 @@ public slots: private slots: void showFieldsSettingsChanged(const QVariant &newValue); void showOwnMessagesSettingChanged(const QVariant &newValue); + void highlightAlwaysSettingsChanged(const QVariant &newValue); + void operationModeSettingsChanged(const QVariant &newValue); + void buffersSettingsChanged(const QVariant &newValue); private: int _showFields; bool _showOwnMessages; + QList _bufferIds; + bool _highlightAlways; + int _operationMode; }; #endif diff --git a/src/qtui/chatviewsettings.h b/src/qtui/chatviewsettings.h index 17904938..2398f77b 100644 --- a/src/qtui/chatviewsettings.h +++ b/src/qtui/chatviewsettings.h @@ -28,6 +28,15 @@ class ChatView; class ChatViewSettings : public QtUiSettings { public: + Q_ENUMS(OperationMode); + public: + enum OperationMode { + InvalidMode = 0, + OptIn = 1, + OptOut = 2 + }; + Q_DECLARE_FLAGS(operationModes, OperationMode); + ChatViewSettings(const QString &id = "__default__"); ChatViewSettings(ChatScene *scene); ChatViewSettings(ChatView *view); @@ -35,5 +44,5 @@ public: inline bool showWebPreview() { return localValue("ShowWebPreview", true).toBool(); } inline void enableWebPreview(bool enabled) { setLocalValue("ShowWebPreview", enabled); } }; - +Q_DECLARE_METATYPE(ChatViewSettings::OperationMode); #endif //CHATVIEWSETTINGS_H diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 32b98346..1541a567 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -67,6 +67,7 @@ #include "settingspages/backlogsettingspage.h" #include "settingspages/bufferviewsettingspage.h" #include "settingspages/colorsettingspage.h" +#include "settingspages/chatmonitorsettingspage.h" #include "settingspages/fontssettingspage.h" #include "settingspages/generalsettingspage.h" #include "settingspages/highlightsettingspage.h" @@ -594,6 +595,7 @@ void MainWin::showSettingsDlg() { dlg->registerSettingsPage(new HighlightSettingsPage(dlg)); dlg->registerSettingsPage(new AliasesSettingsPage(dlg)); dlg->registerSettingsPage(new NotificationsSettingsPage(dlg)); + dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg)); //Category: General dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg)); dlg->registerSettingsPage(new NetworksSettingsPage(dlg)); diff --git a/src/qtui/settingspages/chatmonitorsettingspage.cpp b/src/qtui/settingspages/chatmonitorsettingspage.cpp new file mode 100644 index 00000000..c5049697 --- /dev/null +++ b/src/qtui/settingspages/chatmonitorsettingspage.cpp @@ -0,0 +1,238 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * 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 * + * 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. * + * * + * 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. * + ***************************************************************************/ + +#include "chatmonitorsettingspage.h" + + +#include "client.h" +#include "networkmodel.h" +#include "bufferviewconfig.h" +#include "buffermodel.h" +#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) { + ui.setupUi(this); + + ui.activateBuffer->setIcon(SmallIcon("go-next")); + ui.deactivateBuffer->setIcon(SmallIcon("go-previous")); + // initialize pointers + configAvailable = 0; + configActive = 0; + + // fill combobox with operation modes + ui.operationMode->addItem("Opt-In", ChatViewSettings::OptIn); + ui.operationMode->addItem("Opt-Out", ChatViewSettings::OptOut); + + // connect slots + connect(ui.operationMode, SIGNAL(currentIndexChanged(int)), this, SLOT(switchOperationMode(int))); +} + +bool ChatMonitorSettingsPage::hasDefaults() const { + return true; +} + +void ChatMonitorSettingsPage::defaults() { + settings["OperationMode"] = ChatViewSettings::OptOut; + settings["HighlightAlways"] = false; + settings["Buffers"] = QVariant(); + settings["Default"] = true; + load(); + widgetHasChanged(); +} + +void ChatMonitorSettingsPage::load() { + delete configAvailable; + delete configActive; + + if (settings.contains("Default")) + settings.remove("Default"); + else + loadSettings(); + + ui.operationMode->setCurrentIndex(settings["OperationMode"].toInt() - 1); + ui.highlightAlways->setChecked(settings["HighlightAlways"].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 + QList allBufferIds = Client::networkModel()->allBufferIds(); + + if(!settings["Buffers"].toList().isEmpty()) { + QList bufferIdsFromConfig; + // remove all active buffers from the available config + foreach(QVariant v, settings["Buffers"].toList()) { + bufferIdsFromConfig << v.value(); + allBufferIds.removeOne(v.value()); + } + configActive->initSetBufferList(bufferIdsFromConfig); + } + ui.activeBuffers->setFilteredModel(Client::bufferModel(), configActive); + + configAvailable->initSetBufferList(allBufferIds); + ui.availableBuffers->setFilteredModel(Client::bufferModel(), configAvailable); + + setChangedState(false); +} + +void ChatMonitorSettingsPage::loadSettings() { + ChatViewSettings chatViewSettings; + settings["OperationMode"] = static_cast(chatViewSettings.value("OperationMode", QVariant()).toInt()); + // Load default behavior if no or invalid settings found + if (settings["OperationMode"] == ChatViewSettings::InvalidMode) { + switchOperationMode(ui.operationMode->findData(ChatViewSettings::OptOut)); + settings["OperationMode"] == ChatViewSettings::OptOut; + } + settings["HighlightAlways"] = chatViewSettings.value("HighlightAlways", false); + settings["Buffers"] = chatViewSettings.value("Buffers", QVariantList()); +} + +void ChatMonitorSettingsPage::save() { + ChatViewSettings chatViewSettings; + // save operation mode + chatViewSettings.setValue("OperationMode", settings["OperationMode"]); + chatViewSettings.setValue("HighlightAlways", settings["HighlightAlways"]); + + // save list of active buffers + QVariantList saveableBufferIdList; + foreach(BufferId id, configActive->bufferList()) { + saveableBufferIdList << QVariant::fromValue(id); + } + + chatViewSettings.setValue("Buffers", saveableBufferIdList); + load(); + setChangedState(false); +} + +void ChatMonitorSettingsPage::widgetHasChanged() { + bool changed = testHasChanged(); + if(changed != hasChanged()) setChangedState(changed); +} + +bool ChatMonitorSettingsPage::testHasChanged() { + if (configAvailable != configActive) return true; + return false; +} + +//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) { + + // Fill QMap with selected items ordered by selection row + QMap > selectedBuffers; + foreach (QModelIndex index, inView.selectionModel()->selectedIndexes()) { + BufferId inBufferId = index.data(NetworkModel::BufferIdRole).value(); + if(index.data(NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType) { + // 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) { + selectedBuffers[index.parent().row()] << inBufferId; + } + } + + // clear selection to be able to remove the bufferIds without errors + inView.selectionModel()->clearSelection(); + + /* + Invalidate the BufferViewFilters' configs to get constant add/remove times + even for huge lists. + 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); + + // actually move the ids + foreach (QList list, selectedBuffers) { + foreach (BufferId buffer, list) { + outCfg.addBuffer(buffer,0); + inCfg.removeBuffer(buffer); + } + } + + 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); + widgetHasChanged(); + } +} + +void ChatMonitorSettingsPage::on_deactivateBuffer_clicked() { + if (ui.activeBuffers->currentIndex().isValid() && ui.activeBuffers->selectionModel()->hasSelection()) { + toggleBuffers(*ui.activeBuffers, *configActive, *ui.availableBuffers, *configAvailable); + widgetHasChanged(); + } +} + +void ChatMonitorSettingsPage::on_highlightAlways_toggled(bool state) +{ + settings["HighlightAlways"] = state; + widgetHasChanged(); +} + +/* + switchOperationMode gets called on combobox signal currentIndexChanged. + modeIndex is the row id in combobox itemlist +*/ +void ChatMonitorSettingsPage::switchOperationMode(int modeIndex) { + ChatViewSettings::OperationMode newMode = static_cast(ui.operationMode->itemData(modeIndex).toInt()); + + if(newMode == ChatViewSettings::OptIn) { + ui.labelActiveBuffers->setText(tr("Show:")); + } + else if(newMode == ChatViewSettings::OptOut) { + ui.labelActiveBuffers->setText(tr("Ignore:")); + } + + if(settings["OperationMode"] != newMode) { + setChangedState(true); + } + settings["OperationMode"] = newMode; +} diff --git a/src/qtui/settingspages/chatmonitorsettingspage.h b/src/qtui/settingspages/chatmonitorsettingspage.h new file mode 100644 index 00000000..6a7ca978 --- /dev/null +++ b/src/qtui/settingspages/chatmonitorsettingspage.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel IRC Team * + * 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 * + * 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. * + * * + * 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. * + ***************************************************************************/ + +#ifndef _CHATMONITORSETTINGSPAGE_H_ +#define _CHATMONITORSETTINGSPAGE_H_ + +#include "settingspage.h" +#include "ui_chatmonitorsettingspage.h" + +// replace with forward declaration +#include "bufferviewconfig.h" + +#include + +class ChatMonitorSettingsPage : public SettingsPage { + Q_OBJECT + + public: + ChatMonitorSettingsPage(QWidget *parent = 0); + bool hasDefaults() const; + + public slots: + void save(); + void load(); + void loadSettings(); + void defaults(); + + private slots: + void widgetHasChanged(); + void on_activateBuffer_clicked(); + void on_deactivateBuffer_clicked(); + void on_highlightAlways_toggled(bool state); + void switchOperationMode(int modeIndex); + + private: + Ui::ChatMonitorSettingsPage ui; + QHash settings; + bool testHasChanged(); + void toggleBuffers(BufferView &inView, BufferViewConfig &inCfg, BufferView &outView, BufferViewConfig &outCfg); + BufferViewConfig *configAvailable; + BufferViewConfig *configActive; +}; +#endif diff --git a/src/qtui/settingspages/chatmonitorsettingspage.ui b/src/qtui/settingspages/chatmonitorsettingspage.ui new file mode 100644 index 00000000..999ed2e9 --- /dev/null +++ b/src/qtui/settingspages/chatmonitorsettingspage.ui @@ -0,0 +1,209 @@ + + ChatMonitorSettingsPage + + + + 0 + 0 + 672 + 529 + + + + Form + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Operation Mode: + + + + + + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Operation modes:</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"><span style=" font-weight:400; text-decoration: underline;">Opt-In:</span> <span style=" font-weight:400;">Only buffers on the right side are shown in chatmonitor</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Opt-Out:</span> Buffers on the right side will be ignored in chatmonitor</p></body></html> + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Show highlights in chatmonitor even if the originating buffer is ignored + + + Highlights always + + + + + + + Qt::Vertical + + + + 20 + 338 + + + + + + + + + + + + Available Buffers: + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Move selected buffers to the left + + + + + + + :/16x16/actions/oxygen/16x16/actions/go-previous.png:/16x16/actions/oxygen/16x16/actions/go-previous.png + + + + + + + + Move selected buffers to the right + + + + + + + :/16x16/actions/oxygen/16x16/actions/go-next.png:/16x16/actions/oxygen/16x16/actions/go-next.png + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + Show: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + BufferView + QTreeView +
bufferview.h
+
+
+ + +
diff --git a/src/qtui/settingspages/settingspages.inc b/src/qtui/settingspages/settingspages.inc index c1014d0f..fd9819f7 100644 --- a/src/qtui/settingspages/settingspages.inc +++ b/src/qtui/settingspages/settingspages.inc @@ -1,7 +1,7 @@ # Putting $FOO in SETTINGSPAGES automatically includes # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui -set(SETTINGSPAGES aliases appearance backlog bufferview color fonts general highlight identities networks) +set(SETTINGSPAGES aliases appearance backlog bufferview color chatmonitor fonts general highlight identities networks) # Specify additional files (e.g. for subdialogs) here! set(SP_SOURCES aliasesmodel.cpp notificationssettingspage.cpp) -- 2.20.1