Fix an issue where empty elements were shown in the highlight list
[quassel.git] / src / qtui / settingspages / corehighlightsettingspage.cpp
index d4be7cf..242c318 100644 (file)
@@ -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);
 
@@ -42,6 +42,7 @@ CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent)
 
     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()));
@@ -307,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();
 }
 
@@ -317,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();
 }
 
@@ -470,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);
+}