/***************************************************************************
- * Copyright (C) 2005-2016 by the Quassel Project *
+ * Copyright (C) 2005-2018 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include <QHeaderView>
#include <QTableWidget>
-#include <QtWidgets/QHeaderView>
+#include "client.h"
#include "corehighlightsettingspage.h"
#include "qtui.h"
-#include "client.h"
CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent)
- : SettingsPage(tr("Interface"), tr("Core-Side Highlights"), parent)
+ : SettingsPage(tr("Interface"), tr("Remote Highlights"), parent)
{
ui.setupUi(this);
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()));
this,
SLOT(selectIgnoredRow(QTableWidgetItem * )));
+ // Update the "Case sensitive" checkbox
+ connect(ui.highlightNicksComboBox,
+ SIGNAL(currentIndexChanged(int)),
+ this,
+ SLOT(highlightNicksChanged(int)));
connect(ui.highlightNicksComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged()));
connect(ui.nicksCaseSensitive, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
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();
void CoreHighlightSettingsPage::defaults()
{
- int defaultIndex = ui.highlightNicksComboBox->findData(QVariant(HighlightRuleManager::HighlightNickType::CurrentNick));
+ int highlightNickType = HighlightRuleManager::HighlightNickType::CurrentNick;
+ int defaultIndex = ui.highlightNicksComboBox->findData(QVariant(highlightNickType));
ui.highlightNicksComboBox->setCurrentIndex(defaultIndex);
ui.nicksCaseSensitive->setChecked(false);
emptyHighlightTable();
}
}
+void CoreHighlightSettingsPage::highlightNicksChanged(const int index) {
+ // Only allow toggling "Case sensitive" when a nickname will be highlighted
+ auto highlightNickType = ui.highlightNicksComboBox->itemData(index).value<int>();
+ ui.nicksCaseSensitive->setEnabled(highlightNickType != HighlightRuleManager::NoNick);
+}
+
void CoreHighlightSettingsPage::selectHighlightRow(QTableWidgetItem *item)
{
int row = item->row();
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();
}
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();
}
switch (item->column()) {
case CoreHighlightSettingsPage::EnableColumn:
highlightRule.isEnabled = (item->checkState() == Qt::Checked);
+ break;
case CoreHighlightSettingsPage::NameColumn:
if (item->text() == "")
item->setText(tr("this shouldn't be empty"));
switch (item->column()) {
case CoreHighlightSettingsPage::EnableColumn:
ignoredRule.isEnabled = (item->checkState() == Qt::Checked);
+ break;
case CoreHighlightSettingsPage::NameColumn:
if (item->text() == "")
item->setText(tr("this shouldn't be empty"));
}
}
- ui.highlightNicksComboBox
- ->setCurrentIndex(ui.highlightNicksComboBox->findData(QVariant(ruleManager->highlightNick())));
+ int highlightNickType = ruleManager->highlightNick();
+ ui.highlightNicksComboBox->setCurrentIndex(ui.highlightNicksComboBox->findData(QVariant(highlightNickType)));
+ // Trigger the initial update of nicksCaseSensitive being enabled or not
+ highlightNicksChanged(ui.highlightNicksComboBox->currentIndex());
ui.nicksCaseSensitive->setChecked(ruleManager->nicksCaseSensitive());
setChangedState(false);
rule.sender, rule.chanName);
}
- auto highlightNickType = ui.highlightNicksComboBox->currentData().value<HighlightRuleManager::HighlightNickType>();
+ auto highlightNickType = ui.highlightNicksComboBox->itemData(ui.highlightNicksComboBox->currentIndex()).value<int>();
- clonedManager.setHighlightNick(highlightNickType);
+ clonedManager.setHighlightNick(HighlightRuleManager::HighlightNickType(highlightNickType));
clonedManager.setNicksCaseSensitive(ui.nicksCaseSensitive->isChecked());
ruleManager->requestUpdate(clonedManager.toVariantMap());
void CoreHighlightSettingsPage::widgetHasChanged()
{
setChangedState(true);
-}
\ No newline at end of file
+}
+
+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);
+}