#include "client.h"
#include "corehighlightsettingspage.h"
+#include "icon.h"
#include "qtui.h"
CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent)
connect(Client::instance(), SIGNAL(connected()), this, SLOT(clientConnected()));
// Warning icon
- ui.coreUnsupportedIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(16));
+ ui.coreUnsupportedIcon->setPixmap(icon::get("dialog-warning").pixmap(16));
// Set up client/monolithic remote highlights information
if (Quassel::runMode() == Quassel::Monolithic) {
}
}
+
void CoreHighlightSettingsPage::coreConnectionStateChanged(bool state)
{
updateCoreSupportStatus(state);
}
}
+
void CoreHighlightSettingsPage::setupRuleTable(QTableWidget *table) const
{
table->verticalHeader()->hide();
#endif
}
+
void CoreHighlightSettingsPage::updateCoreSupportStatus(bool state)
{
// Assume connected state as enforced by the settings page UI
}
}
+
void CoreHighlightSettingsPage::clientConnected()
{
connect(Client::highlightRuleManager(), SIGNAL(updated()), SLOT(revert()));
}
+
void CoreHighlightSettingsPage::revert()
{
if (!hasChanged())
load();
}
+
bool CoreHighlightSettingsPage::hasDefaults() const
{
return true;
}
+
void CoreHighlightSettingsPage::defaults()
{
int highlightNickType = HighlightRuleManager::HighlightNickType::CurrentNick;
widgetHasChanged();
}
-void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, const QString &name, bool regex, bool cs,
+
+void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QString &name, bool regex, bool cs,
const QString &sender, const QString &chanName, bool self)
{
ui.highlightTable->setRowCount(ui.highlightTable->rowCount() + 1);
+ if (id < 0) {
+ id = nextId();
+ }
+
auto *nameItem = new QTableWidgetItem(name);
auto *regexItem = new QTableWidgetItem("");
if (!self)
ui.highlightTable->setCurrentItem(nameItem);
- highlightList << HighlightRuleManager::HighlightRule(name, regex, cs, enable, false, sender, chanName);
+ highlightList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, false, sender, chanName);
}
-void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, const QString &name, bool regex, bool cs,
+
+void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QString &name, bool regex, bool cs,
const QString &sender, const QString &chanName, bool self)
{
ui.ignoredTable->setRowCount(ui.ignoredTable->rowCount() + 1);
+ if (id < 0) {
+ id = nextId();
+ }
+
auto *nameItem = new QTableWidgetItem(name);
auto *regexItem = new QTableWidgetItem("");
if (!self)
ui.ignoredTable->setCurrentItem(nameItem);
- ignoredList << HighlightRuleManager::HighlightRule(name, regex, cs, enable, true, sender, chanName);
+ ignoredList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, true, sender, chanName);
}
+
void CoreHighlightSettingsPage::removeSelectedHighlightRows()
{
QList<int> selectedRows;
}
}
+
void CoreHighlightSettingsPage::removeSelectedIgnoredRows()
{
QList<int> selectedRows;
}
}
-void CoreHighlightSettingsPage::highlightNicksChanged(const int index) {
+
+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();
selected);
}
+
void CoreHighlightSettingsPage::selectIgnoredRow(QTableWidgetItem *item)
{
int row = item->row();
selected);
}
+
void CoreHighlightSettingsPage::emptyHighlightTable()
{
// ui.highlight and highlightList should have the same size, but just to make sure.
highlightList.clear();
}
+
void CoreHighlightSettingsPage::emptyIgnoredTable()
{
// ui.highlight and highlightList should have the same size, but just to make sure.
ignoredList.clear();
}
+
void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item)
{
if (item->row() + 1 > highlightList.size())
emit widgetHasChanged();
}
+
void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item)
{
if (item->row() + 1 > ignoredList.size())
emit widgetHasChanged();
}
+
void CoreHighlightSettingsPage::load()
{
emptyHighlightTable();
for (auto &rule : ruleManager->highlightRuleList()) {
if (rule.isInverse) {
addNewIgnoredRow(rule.isEnabled,
+ rule.id,
rule.name,
rule.isRegEx,
rule.isCaseSensitive,
rule.chanName);
}
else {
- addNewHighlightRow(rule.isEnabled, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.sender,
+ addNewHighlightRow(rule.isEnabled, rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.sender,
rule.chanName);
}
}
}
}
+
void CoreHighlightSettingsPage::save()
{
if (!hasChanged())
clonedManager.clear();
for (auto &rule : highlightList) {
- clonedManager.addHighlightRule(rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, false,
+ clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, false,
rule.sender, rule.chanName);
}
for (auto &rule : ignoredList) {
- clonedManager.addHighlightRule(rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, true,
+ clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, true,
rule.sender, rule.chanName);
}
load();
}
+
+int CoreHighlightSettingsPage::nextId()
+{
+ int max = 0;
+ for (int i = 0; i < highlightList.count(); i++) {
+ int id = highlightList[i].id;
+ if (id > max) {
+ max = id;
+ }
+ }
+ for (int i = 0; i < ignoredList.count(); i++) {
+ int id = ignoredList[i].id;
+ if (id > max) {
+ max = id;
+ }
+ }
+ return max + 1;
+}
+
+
void CoreHighlightSettingsPage::widgetHasChanged()
{
setChangedState(true);
}
+
void CoreHighlightSettingsPage::on_coreUnsupportedDetails_clicked()
{
// Re-use translations of "Local Highlights" as this is a word-for-word reference, forcing all
remoteHighlightsMsgText);
}
-void CoreHighlightSettingsPage::importRules() {
+
+void CoreHighlightSettingsPage::importRules()
+{
NotificationSettings notificationSettings;
const auto localHighlightList = notificationSettings.highlightList();
return;
}
+ if (hasChanged()) {
+ // Save existing changes first to avoid overwriting them
+ save();
+ }
+
auto clonedManager = HighlightRuleManager();
clonedManager.fromVariantMap(Client::highlightRuleManager()->toVariantMap());
auto highlightRule = variant.toMap();
clonedManager.addHighlightRule(
+ clonedManager.nextId(),
highlightRule["Name"].toString(),
highlightRule["RegEx"].toBool(),
highlightRule["CS"].toBool(),
).arg(QString::number(localHighlightList.count())));
}
-bool CoreHighlightSettingsPage::isSelectable() const {
+
+bool CoreHighlightSettingsPage::isSelectable() const
+{
return Client::isConnected();
// We check for Quassel::Feature::CoreSideHighlights when loading this page, allowing us to show
// a friendly error message.