X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fchatmonitorsettingspage.cpp;h=1b12c885e340165d49f508b427ce98271da2b5a4;hp=2a434c2c515a3dd9c9555a8b404d0eefbd832a8f;hb=694f9bfbf7f1af19108461c7e00d133e55082bce;hpb=3f354bcce2cecfe88a46de90cbf94ffd1bc7c506 diff --git a/src/qtui/settingspages/chatmonitorsettingspage.cpp b/src/qtui/settingspages/chatmonitorsettingspage.cpp index 2a434c2c..1b12c885 100644 --- a/src/qtui/settingspages/chatmonitorsettingspage.cpp +++ b/src/qtui/settingspages/chatmonitorsettingspage.cpp @@ -32,138 +32,154 @@ #include ChatMonitorSettingsPage::ChatMonitorSettingsPage(QWidget *parent) - : SettingsPage(tr("Interface"), tr("Chat Monitor"), parent) { - ui.setupUi(this); - - ui.activateBuffer->setIcon(SmallIcon("go-next")); - ui.deactivateBuffer->setIcon(SmallIcon("go-previous")); - - // 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(tr("Opt In"), ChatViewSettings::OptIn); - 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())); + : SettingsPage(tr("Interface"), tr("Chat Monitor"), parent) +{ + ui.setupUi(this); + + ui.activateBuffer->setIcon(SmallIcon("go-next")); + ui.deactivateBuffer->setIcon(SmallIcon("go-previous")); + + // 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(tr("Opt In"), ChatViewSettings::OptIn); + 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())); } -bool ChatMonitorSettingsPage::hasDefaults() const { - return true; + +bool ChatMonitorSettingsPage::hasDefaults() const +{ + return true; } -void ChatMonitorSettingsPage::defaults() { - settings["OperationMode"] = ChatViewSettings::OptOut; - settings["ShowHighlights"] = false; - settings["ShowOwnMsgs"] = false; - settings["Buffers"] = QVariant(); - settings["Default"] = true; - load(); - widgetHasChanged(); + +void ChatMonitorSettingsPage::defaults() +{ + settings["OperationMode"] = ChatViewSettings::OptOut; + settings["ShowHighlights"] = false; + settings["ShowOwnMsgs"] = false; + settings["Buffers"] = QVariant(); + settings["Default"] = true; + load(); + widgetHasChanged(); } -void ChatMonitorSettingsPage::load() { - if(settings.contains("Default")) - settings.remove("Default"); - else - loadSettings(); - - switchOperationMode(settings["OperationMode"].toInt() - 1); - ui.operationMode->setCurrentIndex(settings["OperationMode"].toInt() - 1); - ui.showHighlights->setChecked(settings["ShowHighlights"].toBool()); - ui.showOwnMessages->setChecked(settings["ShowOwnMsgs"].toBool()); - - // 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.removeAll(v.value()); + +void ChatMonitorSettingsPage::load() +{ + if (settings.contains("Default")) + settings.remove("Default"); + else + loadSettings(); + + switchOperationMode(settings["OperationMode"].toInt() - 1); + ui.operationMode->setCurrentIndex(settings["OperationMode"].toInt() - 1); + ui.showHighlights->setChecked(settings["ShowHighlights"].toBool()); + ui.showOwnMessages->setChecked(settings["ShowOwnMsgs"].toBool()); + + // 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.removeAll(v.value()); + } + Client::networkModel()->sortBufferIds(bufferIdsFromConfig); + _configActive->initSetBufferList(bufferIdsFromConfig); } - Client::networkModel()->sortBufferIds(bufferIdsFromConfig); - _configActive->initSetBufferList(bufferIdsFromConfig); - } - ui.activeBuffers->setFilteredModel(Client::bufferModel(), _configActive); + ui.activeBuffers->setFilteredModel(Client::bufferModel(), _configActive); - Client::networkModel()->sortBufferIds(allBufferIds); - _configAvailable->initSetBufferList(allBufferIds); - ui.availableBuffers->setFilteredModel(Client::bufferModel(), _configAvailable); + Client::networkModel()->sortBufferIds(allBufferIds); + _configAvailable->initSetBufferList(allBufferIds); + ui.availableBuffers->setFilteredModel(Client::bufferModel(), _configAvailable); - setChangedState(false); + setChangedState(false); } -void ChatMonitorSettingsPage::loadSettings() { - ChatViewSettings chatViewSettings("ChatMonitor"); - settings["OperationMode"] = (ChatViewSettings::OperationMode)chatViewSettings.value("OperationMode", ChatViewSettings::OptOut).toInt(); - settings["ShowHighlights"] = chatViewSettings.value("ShowHighlights", false); - settings["ShowOwnMsgs"] = chatViewSettings.value("ShowOwnMsgs", false); - settings["Buffers"] = chatViewSettings.value("Buffers", QVariantList()); +void ChatMonitorSettingsPage::loadSettings() +{ + ChatViewSettings chatViewSettings("ChatMonitor"); + settings["OperationMode"] = (ChatViewSettings::OperationMode)chatViewSettings.value("OperationMode", ChatViewSettings::OptOut).toInt(); + + settings["ShowHighlights"] = chatViewSettings.value("ShowHighlights", false); + settings["ShowOwnMsgs"] = chatViewSettings.value("ShowOwnMsgs", false); + settings["Buffers"] = chatViewSettings.value("Buffers", QVariantList()); } -void ChatMonitorSettingsPage::save() { - ChatViewSettings chatViewSettings("ChatMonitor"); - // save operation mode - chatViewSettings.setValue("OperationMode", ui.operationMode->currentIndex() + 1); - chatViewSettings.setValue("ShowHighlights", ui.showHighlights->isChecked()); - chatViewSettings.setValue("ShowOwnMsgs", ui.showOwnMessages->isChecked()); - - // 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::save() +{ + ChatViewSettings chatViewSettings("ChatMonitor"); + // save operation mode + chatViewSettings.setValue("OperationMode", ui.operationMode->currentIndex() + 1); + chatViewSettings.setValue("ShowHighlights", ui.showHighlights->isChecked()); + chatViewSettings.setValue("ShowOwnMsgs", ui.showOwnMessages->isChecked()); + + // 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); + +void ChatMonitorSettingsPage::widgetHasChanged() +{ + bool changed = testHasChanged(); + if (changed != hasChanged()) setChangedState(changed); } -bool ChatMonitorSettingsPage::testHasChanged() { - if(settings["OperationMode"].toInt() != ui.operationMode->currentIndex() + 1) - return true; - if(settings["ShowHighlights"].toBool() != ui.showHighlights->isChecked()) - return true; - if(settings["ShowOwnMsgs"].toBool() != ui.showOwnMessages->isChecked()) - return true; - if(_configActive->bufferList().count() != settings["Buffers"].toList().count()) - return true; +bool ChatMonitorSettingsPage::testHasChanged() +{ + if (settings["OperationMode"].toInt() != ui.operationMode->currentIndex() + 1) + return true; + if (settings["ShowHighlights"].toBool() != ui.showHighlights->isChecked()) + return true; + if (settings["ShowOwnMsgs"].toBool() != ui.showOwnMessages->isChecked()) + return true; + + if (_configActive->bufferList().count() != settings["Buffers"].toList().count()) + return true; - QSet uiBufs = _configActive->bufferList().toSet(); - QSet settingsBufs; - foreach(QVariant v, settings["Buffers"].toList()) + QSet uiBufs = _configActive->bufferList().toSet(); + QSet settingsBufs; + foreach(QVariant v, settings["Buffers"].toList()) settingsBufs << v.value(); - if(uiBufs != settingsBufs) - return true; + if (uiBufs != settingsBufs) + return true; - return false; + return false; } + //TODO: - support drag 'n drop // - adding of complete networks(?) @@ -171,72 +187,78 @@ 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) { - - // 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 +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; + } } - 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); + + // 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); + outView->setFilteredModel(Client::bufferModel(), outCfg); + inView->setFilteredModel(Client::bufferModel(), inCfg); - widgetHasChanged(); + 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_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_deactivateBuffer_clicked() +{ + if (ui.activeBuffers->currentIndex().isValid() && ui.activeBuffers->selectionModel()->hasSelection()) { + toggleBuffers(ui.activeBuffers, _configActive, ui.availableBuffers, _configAvailable); + widgetHasChanged(); + } } + /* 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); - if(mode == ChatViewSettings::OptIn) { - ui.labelActiveBuffers->setText(tr("Show:")); - } - else if(mode == ChatViewSettings::OptOut) { - ui.labelActiveBuffers->setText(tr("Ignore:")); - } - widgetHasChanged(); +void ChatMonitorSettingsPage::switchOperationMode(int idx) +{ + ChatViewSettings::OperationMode mode = (ChatViewSettings::OperationMode)(idx + 1); + if (mode == ChatViewSettings::OptIn) { + ui.labelActiveBuffers->setText(tr("Show:")); + } + else if (mode == ChatViewSettings::OptOut) { + ui.labelActiveBuffers->setText(tr("Ignore:")); + } + widgetHasChanged(); }