X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fcorehighlightsettingspage.cpp;h=242c3181d8ad370499aeb14124131c72563b83c6;hp=fba21eb24333f082d032e9cfb8448ddf41af3b18;hb=106526817f753cdd680c783fc58968d5111d16eb;hpb=71d3d0d705a853fa8fea3729e13dbddf52363417 diff --git a/src/qtui/settingspages/corehighlightsettingspage.cpp b/src/qtui/settingspages/corehighlightsettingspage.cpp index fba21eb2..242c3181 100644 --- a/src/qtui/settingspages/corehighlightsettingspage.cpp +++ b/src/qtui/settingspages/corehighlightsettingspage.cpp @@ -26,7 +26,7 @@ #include "qtui.h" CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent) - : SettingsPage(tr("Interface"), tr("Core-Side Highlights"), parent) + : SettingsPage(tr("Interface"), tr("Remote Highlights"), parent) { ui.setupUi(this); @@ -37,8 +37,12 @@ CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent) ui.highlightNicksComboBox->addItem(tr("Current Nick"), QVariant(HighlightRuleManager::CurrentNick)); ui.highlightNicksComboBox->addItem(tr("None"), QVariant(HighlightRuleManager::NoNick)); + coreConnectionStateChanged(Client::isConnected()); // need a core connection! + connect(Client::instance(), SIGNAL(coreConnectionStateChanged(bool)), this, SLOT(coreConnectionStateChanged(bool))); + connect(ui.highlightAdd, SIGNAL(clicked(bool)), this, SLOT(addNewHighlightRow())); connect(ui.highlightRemove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedHighlightRows())); + connect(ui.highlightImport, SIGNAL(clicked(bool)), this, SLOT(importRules())); connect(ui.ignoredAdd, SIGNAL(clicked(bool)), this, SLOT(addNewIgnoredRow())); connect(ui.ignoredRemove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedIgnoredRows())); @@ -76,6 +80,16 @@ CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent) connect(Client::instance(), SIGNAL(connected()), this, SLOT(clientConnected())); } +void CoreHighlightSettingsPage::coreConnectionStateChanged(bool state) +{ + setEnabled(state); + if (state) { + load(); + } else { + revert(); + } +} + void CoreHighlightSettingsPage::setupRuleTable(QTableWidget *table) const { table->verticalHeader()->hide(); @@ -294,7 +308,9 @@ void CoreHighlightSettingsPage::emptyHighlightTable() if (ui.highlightTable->rowCount() != highlightList.size()) { qDebug() << "something is wrong: ui.highlight and highlightList don't have the same size!"; } - ui.highlightTable->clearContents(); + while (ui.highlightTable->rowCount()) { + ui.highlightTable->removeRow(0); + } highlightList.clear(); } @@ -304,7 +320,9 @@ void CoreHighlightSettingsPage::emptyIgnoredTable() if (ui.ignoredTable->rowCount() != ignoredList.size()) { qDebug() << "something is wrong: ui.highlight and highlightList don't have the same size!"; } - ui.ignoredTable->clearContents(); + while (ui.ignoredTable->rowCount()) { + ui.ignoredTable->removeRow(0); + } ignoredList.clear(); } @@ -457,3 +475,32 @@ void CoreHighlightSettingsPage::widgetHasChanged() { setChangedState(true); } + +void CoreHighlightSettingsPage::importRules() { + NotificationSettings notificationSettings; + + auto clonedManager = HighlightRuleManager(); + clonedManager.fromVariantMap(Client::highlightRuleManager()->toVariantMap()); + + for (const auto &variant : notificationSettings.highlightList()) { + auto highlightRule = variant.toMap(); + + clonedManager.addHighlightRule( + highlightRule["Name"].toString(), + highlightRule["RegEx"].toBool(), + highlightRule["CS"].toBool(), + highlightRule["Enable"].toBool(), + false, + "", + highlightRule["Channel"].toString() + ); + } + + Client::highlightRuleManager()->requestUpdate(clonedManager.toVariantMap()); + setChangedState(false); + load(); +} + +bool CoreHighlightSettingsPage::isSelectable() const { + return Client::isConnected() && Client::isCoreFeatureEnabled(Quassel::Feature::CoreSideHighlights); +}