_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<BufferId>();
+
+ 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 {
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<BufferId>()))
+ return false;
+ if (_operationMode == ChatViewSettings::OptIn && !(_highlightAlways && flags & Message::Highlight) && !_bufferIds.contains(sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value<BufferId>()))
+ return false;
+
return true;
}
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<BufferId>();
+ }
+}
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<BufferId> _bufferIds;
+ bool _highlightAlways;
+ int _operationMode;
};
#endif
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);
inline bool showWebPreview() { return localValue("ShowWebPreview", true).toBool(); }
inline void enableWebPreview(bool enabled) { setLocalValue("ShowWebPreview", enabled); }
};
-
+Q_DECLARE_METATYPE(ChatViewSettings::OperationMode);
#endif //CHATVIEWSETTINGS_H
#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"
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));
--- /dev/null
+/***************************************************************************
+ * 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 <QVariant>
+
+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<BufferId> allBufferIds = Client::networkModel()->allBufferIds();
+
+ if(!settings["Buffers"].toList().isEmpty()) {
+ QList<BufferId> bufferIdsFromConfig;
+ // remove all active buffers from the available config
+ foreach(QVariant v, settings["Buffers"].toList()) {
+ bufferIdsFromConfig << v.value<BufferId>();
+ allBufferIds.removeOne(v.value<BufferId>());
+ }
+ 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::OperationMode>(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<BufferId>(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<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:
+ // 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<BufferViewFilter *>(outView.model())->setConfig(0);
+ qobject_cast<BufferViewFilter *>(inView.model())->setConfig(0);
+
+ // actually move the ids
+ foreach (QList<BufferId> 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<ChatViewSettings::OperationMode>(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;
+}
--- /dev/null
+/***************************************************************************
+ * 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 <QHash>
+
+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<QString, QVariant> settings;
+ bool testHasChanged();
+ void toggleBuffers(BufferView &inView, BufferViewConfig &inCfg, BufferView &outView, BufferViewConfig &outCfg);
+ BufferViewConfig *configAvailable;
+ BufferViewConfig *configActive;
+};
+#endif
--- /dev/null
+<ui version="4.0" >
+ <class>ChatMonitorSettingsPage</class>
+ <widget class="QWidget" name="ChatMonitorSettingsPage" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>672</width>
+ <height>529</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_3" >
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_3" >
+ <item>
+ <spacer name="verticalSpacer_4" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>Operation Mode:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <widget class="QComboBox" name="operationMode" >
+ <property name="toolTip" >
+ <string><!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></string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="highlightAlways" >
+ <property name="toolTip" >
+ <string>Show highlights in chatmonitor even if the originating buffer is ignored</string>
+ </property>
+ <property name="text" >
+ <string>Highlights always</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_3" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>338</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" >
+ <item>
+ <widget class="QLabel" name="labelAvailableBuffers" >
+ <property name="text" >
+ <string>Available Buffers:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="BufferView" name="availableBuffers" />
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <spacer name="verticalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="deactivateBuffer" >
+ <property name="toolTip" >
+ <string>Move selected buffers to the left</string>
+ </property>
+ <property name="text" >
+ <string/>
+ </property>
+ <property name="icon" >
+ <iconset>
+ <normaloff>:/16x16/actions/oxygen/16x16/actions/go-previous.png</normaloff>:/16x16/actions/oxygen/16x16/actions/go-previous.png
+ </iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="activateBuffer" >
+ <property name="toolTip" >
+ <string>Move selected buffers to the right</string>
+ </property>
+ <property name="text" >
+ <string/>
+ </property>
+ <property name="icon" >
+ <iconset>
+ <normaloff>:/16x16/actions/oxygen/16x16/actions/go-next.png</normaloff>:/16x16/actions/oxygen/16x16/actions/go-next.png
+ </iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_2" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QLabel" name="labelActiveBuffers" >
+ <property name="text" >
+ <string>Show:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="BufferView" name="activeBuffers" />
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>BufferView</class>
+ <extends>QTreeView</extends>
+ <header>bufferview.h</header>
+ </customwidget>
+ </customwidgets>
+<resources/>
+ <connections/>
+</ui>
# 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)