X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fcorehighlightsettingspage.cpp;h=e07c87d90d476904afa18cf6b443d09498564d9e;hp=9d2f155bcf867543cffccdc63be080536a433d1f;hb=HEAD;hpb=cefad53d40b08c4271a2150533b747c3ca64b735 diff --git a/src/qtui/settingspages/corehighlightsettingspage.cpp b/src/qtui/settingspages/corehighlightsettingspage.cpp index 9d2f155b..cb134899 100644 --- a/src/qtui/settingspages/corehighlightsettingspage.cpp +++ b/src/qtui/settingspages/corehighlightsettingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2022 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,20 +18,21 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "corehighlightsettingspage.h" + +#include + #include #include #include #include "client.h" -#include "corehighlightsettingspage.h" #include "icon.h" #include "qtui.h" +#include "util.h" -CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent) - : SettingsPage(tr("Interface"), - // In Monolithic mode, local highlights are replaced by remote highlights - Quassel::runMode() == Quassel::Monolithic ? - tr("Highlights") : tr("Remote Highlights"), +CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget* parent) + : SettingsPage(tr("Interface"), tr("Highlights"), parent) { ui.setupUi(this); @@ -43,162 +44,213 @@ 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))); + coreConnectionStateChanged(Client::isConnected()); // need a core connection! + connect(Client::instance(), &Client::coreConnectionStateChanged, this, &CoreHighlightSettingsPage::coreConnectionStateChanged); - 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.highlightAdd, &QAbstractButton::clicked, this, [this]() { addNewHighlightRow(); }); + connect(ui.highlightRemove, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::removeSelectedHighlightRows); + connect(ui.highlightImport, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::importRules); - connect(ui.ignoredAdd, SIGNAL(clicked(bool)), this, SLOT(addNewIgnoredRow())); - connect(ui.ignoredRemove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedIgnoredRows())); + connect(ui.ignoredAdd, &QAbstractButton::clicked, this, [this]() { addNewIgnoredRow(); }); + connect(ui.ignoredRemove, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::removeSelectedIgnoredRows); - // TODO: search for a better signal (one that emits everytime a selection has been changed for one item) - connect(ui.highlightTable, - SIGNAL(itemClicked(QTableWidgetItem * )), - this, - SLOT(selectHighlightRow(QTableWidgetItem * ))); - connect(ui.ignoredTable, - SIGNAL(itemClicked(QTableWidgetItem * )), - this, - SLOT(selectIgnoredRow(QTableWidgetItem * ))); + // TODO: search for a better signal (one that emits every time a selection has been changed for one item) + connect(ui.highlightTable, &QTableWidget::itemClicked, this, &CoreHighlightSettingsPage::selectHighlightRow); + connect(ui.ignoredTable, &QTableWidget::itemClicked, this, &CoreHighlightSettingsPage::selectIgnoredRow); // Update the "Case sensitive" checkbox connect(ui.highlightNicksComboBox, - SIGNAL(currentIndexChanged(int)), + selectOverload(&QComboBox::currentIndexChanged), this, - SLOT(highlightNicksChanged(int))); - - connect(ui.highlightNicksComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(widgetHasChanged())); - connect(ui.nicksCaseSensitive, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); + &CoreHighlightSettingsPage::highlightNicksChanged); + connect(ui.highlightNicksComboBox, selectOverload(&QComboBox::currentIndexChanged), this, &CoreHighlightSettingsPage::widgetHasChanged); + connect(ui.nicksCaseSensitive, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::widgetHasChanged); - connect(ui.highlightAdd, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); - connect(ui.highlightRemove, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); + connect(ui.highlightAdd, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::widgetHasChanged); + connect(ui.highlightRemove, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::widgetHasChanged); - connect(ui.ignoredAdd, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); - connect(ui.ignoredRemove, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); + connect(ui.ignoredAdd, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::widgetHasChanged); + connect(ui.ignoredRemove, &QAbstractButton::clicked, this, &CoreHighlightSettingsPage::widgetHasChanged); - connect(ui.highlightTable, - SIGNAL(itemChanged(QTableWidgetItem * )), - this, - SLOT(highlightTableChanged(QTableWidgetItem * ))); + connect(ui.highlightTable, &QTableWidget::itemChanged, this, &CoreHighlightSettingsPage::highlightTableChanged); - connect(ui.ignoredTable, - SIGNAL(itemChanged(QTableWidgetItem * )), - this, - SLOT(ignoredTableChanged(QTableWidgetItem * ))); + connect(ui.ignoredTable, &QTableWidget::itemChanged, this, &CoreHighlightSettingsPage::ignoredTableChanged); - connect(Client::instance(), SIGNAL(connected()), this, SLOT(clientConnected())); + connect(Client::instance(), &Client::connected, this, &CoreHighlightSettingsPage::clientConnected); // Warning icon - ui.coreUnsupportedIcon->setPixmap(icon::get("dialog-warning").pixmap(16)); + ui.coreUnsupportedIcon->setPixmap(icon::get({"emblem-unavailable", "dialog-warning"}).pixmap(16)); // Set up client/monolithic remote highlights information - if (Quassel::runMode() == Quassel::Monolithic) { - // We're running in Monolithic mode, local highlights are considered legacy - ui.highlightImport->setText(tr("Import Legacy")); - ui.highlightImport->setToolTip(tr("Import highlight rules configured in %1.") - .arg(tr("Legacy Highlights").replace(" ", " "))); - // Re-use translations of "Legacy Highlights" as this is a word-for-word reference, forcing - // all spaces to be non-breaking - } else { - // We're running in client/split mode, local highlights are distinguished from remote - ui.highlightImport->setText(tr("Import Local")); - ui.highlightImport->setToolTip(tr("Import highlight rules configured in %1.") - .arg(tr("Local Highlights").replace(" ", " "))); - // Re-use translations of "Local Highlights" as this is a word-for-word reference, forcing - // all spaces to be non-breaking - } + // Local highlights are considered legacy + ui.highlightImport->setText(tr("Import Legacy")); + ui.highlightImport->setToolTip( + tr("Import highlight rules configured in %1.").arg(tr("Legacy Highlights").replace(" ", " "))); + // Re-use translations of "Legacy Highlights" as this is a word-for-word reference, forcing + // all spaces to be non-breaking } - void CoreHighlightSettingsPage::coreConnectionStateChanged(bool state) { updateCoreSupportStatus(state); setEnabled(state); if (state) { load(); - } else { + } + else { revert(); } } - -void CoreHighlightSettingsPage::setupRuleTable(QTableWidget *table) const +void CoreHighlightSettingsPage::setupRuleTable(QTableWidget* table) const { table->verticalHeader()->hide(); table->setShowGrid(false); - table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->setToolTip( - tr("Enable/disable this rule")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->setToolTip( - tr("Phrase to match")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->setToolTip( - tr("RegEx: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted as regular expressions or just as " - "keywords.")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->setToolTip( - tr("CS: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted case sensitive.")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->setToolTip( - tr("

Sender: Semicolon separated list of nick!ident@host names, " - "leave blank to match any nickname.

" - "

Example:
" - "Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*
" - "would match on Alice, Bob with hostmask example.com, and " - "any nickname starting with Carol except for Caroline
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!Announce*!*; !Wheatley!aperture@*
" - "would match anything except for Wheatley with ident aperture or " - "any nickname starting with Announce

")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->setToolTip( - tr("

Channel: Semicolon separated list of channel names, leave blank to " - "match any name.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and any channel starting with #quassel " - "except for #quasseldroid
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!#quassel*; !#foobar
" - "would match anything except for #foobar or any channel starting with " - "#quassel

")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->toolTip()); - -#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) - table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::EnableColumn, QHeaderView::ResizeToContents); - table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::NameColumn, QHeaderView::Stretch); - table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::RegExColumn, QHeaderView::ResizeToContents); - table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::CsColumn, QHeaderView::ResizeToContents); - table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::ChanColumn, QHeaderView::ResizeToContents); -#else + setupTableTooltips(table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)); + table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::EnableColumn, QHeaderView::ResizeToContents); table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::NameColumn, QHeaderView::Stretch); table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::RegExColumn, QHeaderView::ResizeToContents); table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::CsColumn, QHeaderView::ResizeToContents); + table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::SenderColumn, QHeaderView::ResizeToContents); table->horizontalHeader()->setSectionResizeMode(CoreHighlightSettingsPage::ChanColumn, QHeaderView::ResizeToContents); -#endif } +QString CoreHighlightSettingsPage::getTableTooltip(column tableColumn) const +{ + switch (tableColumn) { + case CoreHighlightSettingsPage::EnableColumn: + return tr("Enable/disable this rule"); + + case CoreHighlightSettingsPage::NameColumn: + return tr("Phrase to match, leave blank to match any message"); + + case CoreHighlightSettingsPage::RegExColumn: + return tr("RegEx: This option determines if the highlight rule, Sender, and " + "Channel should be interpreted as regular expressions or just as " + "keywords."); + + case CoreHighlightSettingsPage::CsColumn: + return tr("CS: This option determines if the highlight rule, Sender, and " + "Channel should be interpreted case sensitive."); + + case CoreHighlightSettingsPage::SenderColumn: + return tr("

Sender: Semicolon separated list of nick!ident@host names, " + "leave blank to match any nickname.

" + "

Example:
" + "Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*
" + "would match on Alice, Bob with hostmask example.com, and " + "any nickname starting with Carol except for Caroline
" + "

If only inverted names are specified, it will match anything except for " + "what's specified (implicit wildcard).

" + "

Example:
" + "!Announce*!*; !Wheatley!aperture@*
" + "would match anything except for Wheatley with ident aperture or " + "any nickname starting with Announce

"); + + case CoreHighlightSettingsPage::ChanColumn: + return tr("

Channel: Semicolon separated list of channel/query names, leave blank " + "to match any name.

" + "

Example:
" + "#quassel*; #foobar; !#quasseldroid
" + "would match on #foobar and any channel starting with #quassel " + "except for #quasseldroid
" + "

If only inverted names are specified, it will match anything except for " + "what's specified (implicit wildcard).

" + "

Example:
" + "!#quassel*; !#foobar
" + "would match anything except for #foobar or any channel starting with " + "#quassel

"); + + default: + // This shouldn't happen + return "Invalid column type in CoreHighlightSettingsPage::getTableTooltip()"; + } +} + +void CoreHighlightSettingsPage::setupTableTooltips( + QWidget* enableWidget, QWidget* nameWidget, QWidget* regExWidget, QWidget* csWidget, QWidget* senderWidget, QWidget* chanWidget) const +{ + // Make sure everything's valid + Q_ASSERT(enableWidget); + Q_ASSERT(nameWidget); + Q_ASSERT(regExWidget); + Q_ASSERT(csWidget); + Q_ASSERT(senderWidget); + Q_ASSERT(chanWidget); + + // Set tooltips and "What's this?" prompts + // Enabled + enableWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::EnableColumn)); + enableWidget->setWhatsThis(enableWidget->toolTip()); + + // Name + nameWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::NameColumn)); + nameWidget->setWhatsThis(nameWidget->toolTip()); + + // RegEx enabled + regExWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::RegExColumn)); + regExWidget->setWhatsThis(regExWidget->toolTip()); + + // Case-sensitivity + csWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::CsColumn)); + csWidget->setWhatsThis(csWidget->toolTip()); + + // Sender + senderWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::SenderColumn)); + senderWidget->setWhatsThis(senderWidget->toolTip()); + + // Channel/buffer name + chanWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::ChanColumn)); + chanWidget->setWhatsThis(chanWidget->toolTip()); +} + +void CoreHighlightSettingsPage::setupTableTooltips(QTableWidgetItem* enableWidget, + QTableWidgetItem* nameWidget, + QTableWidgetItem* regExWidget, + QTableWidgetItem* csWidget, + QTableWidgetItem* senderWidget, + QTableWidgetItem* chanWidget) const +{ + // Make sure everything's valid + Q_ASSERT(enableWidget); + Q_ASSERT(nameWidget); + Q_ASSERT(regExWidget); + Q_ASSERT(csWidget); + Q_ASSERT(senderWidget); + Q_ASSERT(chanWidget); + + // Set tooltips and "What's this?" prompts + // Enabled + enableWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::EnableColumn)); + enableWidget->setWhatsThis(enableWidget->toolTip()); + + // Name + nameWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::NameColumn)); + nameWidget->setWhatsThis(nameWidget->toolTip()); + + // RegEx enabled + regExWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::RegExColumn)); + regExWidget->setWhatsThis(regExWidget->toolTip()); + + // Case-sensitivity + csWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::CsColumn)); + csWidget->setWhatsThis(csWidget->toolTip()); + + // Sender + senderWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::SenderColumn)); + senderWidget->setWhatsThis(senderWidget->toolTip()); + + // Channel/buffer name + chanWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::ChanColumn)); + chanWidget->setWhatsThis(chanWidget->toolTip()); +} void CoreHighlightSettingsPage::updateCoreSupportStatus(bool state) { @@ -208,20 +260,19 @@ void CoreHighlightSettingsPage::updateCoreSupportStatus(bool state) // warning. Don't show the warning needlessly when disconnected. ui.highlightsConfigWidget->setEnabled(true); ui.coreUnsupportedWidget->setVisible(false); - } else { + } + else { // Core does not support highlights, show warning and disable highlight configuration ui.highlightsConfigWidget->setEnabled(false); ui.coreUnsupportedWidget->setVisible(true); } } - void CoreHighlightSettingsPage::clientConnected() { - connect(Client::highlightRuleManager(), SIGNAL(updated()), SLOT(revert())); + connect(Client::highlightRuleManager(), &SyncableObject::updated, this, &CoreHighlightSettingsPage::revert); } - void CoreHighlightSettingsPage::revert() { if (!hasChanged()) @@ -231,13 +282,11 @@ void CoreHighlightSettingsPage::revert() load(); } - bool CoreHighlightSettingsPage::hasDefaults() const { return true; } - void CoreHighlightSettingsPage::defaults() { int highlightNickType = HighlightRuleManager::HighlightNickType::CurrentNick; @@ -250,9 +299,8 @@ void CoreHighlightSettingsPage::defaults() widgetHasChanged(); } - -void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QString &name, bool regex, bool cs, - const QString &sender, const QString &chanName, bool self) +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); @@ -260,68 +308,34 @@ void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QS id = nextId(); } - auto *nameItem = new QTableWidgetItem(name); + auto* nameItem = new QTableWidgetItem(name); - auto *regexItem = new QTableWidgetItem(""); + auto* regexItem = new QTableWidgetItem(""); if (regex) regexItem->setCheckState(Qt::Checked); else regexItem->setCheckState(Qt::Unchecked); regexItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - auto *csItem = new QTableWidgetItem(""); + auto* csItem = new QTableWidgetItem(""); if (cs) csItem->setCheckState(Qt::Checked); else csItem->setCheckState(Qt::Unchecked); csItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - auto *enableItem = new QTableWidgetItem(""); + auto* enableItem = new QTableWidgetItem(""); if (enable) enableItem->setCheckState(Qt::Checked); else enableItem->setCheckState(Qt::Unchecked); enableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - auto *senderItem = new QTableWidgetItem(sender); - - auto *chanNameItem = new QTableWidgetItem(chanName); - - enableItem->setToolTip(tr("Enable/disable this rule")); - nameItem->setToolTip(tr("Phrase to match")); - regexItem->setToolTip( - tr("RegEx: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted as regular expressions or just as " - "keywords.")); - csItem->setToolTip( - tr("CS: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted case sensitive.")); - senderItem->setToolTip( - tr("

Sender: Semicolon separated list of nick!ident@host names, " - "leave blank to match any nickname.

" - "

Example:
" - "Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*
" - "would match on Alice, Bob with hostmask example.com, and " - "any nickname starting with Carol except for Caroline
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!Announce*!*; !Wheatley!aperture@*
" - "would match anything except for Wheatley with ident aperture or " - "any nickname starting with Announce

")); - chanNameItem->setToolTip( - tr("

Channel: Semicolon separated list of channel names, leave blank to " - "match any name.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and any channel starting with #quassel " - "except for #quasseldroid
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!#quassel*; !#foobar
" - "would match anything except for #foobar or any channel starting with " - "#quassel

")); + auto* senderItem = new QTableWidgetItem(sender); + + auto* chanNameItem = new QTableWidgetItem(chanName); + + setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem); int lastRow = ui.highlightTable->rowCount() - 1; ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem); @@ -337,9 +351,8 @@ void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QS highlightList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, false, sender, chanName); } - -void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QString &name, bool regex, bool cs, - const QString &sender, const QString &chanName, bool self) +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); @@ -347,56 +360,34 @@ void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QStr id = nextId(); } - auto *nameItem = new QTableWidgetItem(name); + auto* nameItem = new QTableWidgetItem(name); - auto *regexItem = new QTableWidgetItem(""); + auto* regexItem = new QTableWidgetItem(""); if (regex) regexItem->setCheckState(Qt::Checked); else regexItem->setCheckState(Qt::Unchecked); regexItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - auto *csItem = new QTableWidgetItem(""); + auto* csItem = new QTableWidgetItem(""); if (cs) csItem->setCheckState(Qt::Checked); else csItem->setCheckState(Qt::Unchecked); csItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - auto *enableItem = new QTableWidgetItem(""); + auto* enableItem = new QTableWidgetItem(""); if (enable) enableItem->setCheckState(Qt::Checked); else enableItem->setCheckState(Qt::Unchecked); enableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - auto *chanNameItem = new QTableWidgetItem(chanName); - - auto *senderItem = new QTableWidgetItem(sender); - - enableItem->setToolTip(tr("Enable/disable this rule")); - nameItem->setToolTip(tr("Phrase to match")); - regexItem->setToolTip( - tr("RegEx: This option determines if the highlight rule should be " - "interpreted as a regular expression or just as a keyword.")); - csItem->setToolTip( - tr("CS: This option determines if the highlight rule should be interpreted " - "case sensitive.")); - senderItem->setToolTip( - tr("Sender: This option specifies which sender nicknames match. Leave " - "blank to match any nickname.")); - chanNameItem->setToolTip( - tr("

Channel: Semicolon separated list of channel names.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and any channel starting with #quassel except " - "for #quasseldroid
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!#quassel*; !#foobar
" - "would match anything except for #foobar or any channel starting with " - "#quassel

")); + auto* chanNameItem = new QTableWidgetItem(chanName); + + auto* senderItem = new QTableWidgetItem(sender); + + setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem); int lastRow = ui.ignoredTable->rowCount() - 1; ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem); @@ -412,15 +403,14 @@ void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QStr ignoredList << HighlightRuleManager::HighlightRule(id, name, regex, cs, enable, true, sender, chanName); } - void CoreHighlightSettingsPage::removeSelectedHighlightRows() { QList selectedRows; - QList selectedItemList = ui.highlightTable->selectedItems(); + QList selectedItemList = ui.highlightTable->selectedItems(); for (auto selectedItem : selectedItemList) { selectedRows.append(selectedItem->row()); } - qSort(selectedRows.begin(), selectedRows.end(), qGreater()); + std::sort(selectedRows.begin(), selectedRows.end(), std::greater<>()); int lastRow = -1; for (auto row : selectedRows) { if (row != lastRow) { @@ -431,15 +421,14 @@ void CoreHighlightSettingsPage::removeSelectedHighlightRows() } } - void CoreHighlightSettingsPage::removeSelectedIgnoredRows() { QList selectedRows; - QList selectedItemList = ui.ignoredTable->selectedItems(); + QList selectedItemList = ui.ignoredTable->selectedItems(); for (auto selectedItem : selectedItemList) { selectedRows.append(selectedItem->row()); } - qSort(selectedRows.begin(), selectedRows.end(), qGreater()); + std::sort(selectedRows.begin(), selectedRows.end(), std::greater<>()); int lastRow = -1; for (auto row : selectedRows) { if (row != lastRow) { @@ -450,7 +439,6 @@ void CoreHighlightSettingsPage::removeSelectedIgnoredRows() } } - void CoreHighlightSettingsPage::highlightNicksChanged(const int index) { // Only allow toggling "Case sensitive" when a nickname will be highlighted @@ -458,27 +446,20 @@ void CoreHighlightSettingsPage::highlightNicksChanged(const int index) ui.nicksCaseSensitive->setEnabled(highlightNickType != HighlightRuleManager::NoNick); } - -void CoreHighlightSettingsPage::selectHighlightRow(QTableWidgetItem *item) +void CoreHighlightSettingsPage::selectHighlightRow(QTableWidgetItem* item) { int row = item->row(); bool selected = item->isSelected(); - ui.highlightTable - ->setRangeSelected(QTableWidgetSelectionRange(row, 0, row, CoreHighlightSettingsPage::ColumnCount - 1), - selected); + ui.highlightTable->setRangeSelected(QTableWidgetSelectionRange(row, 0, row, CoreHighlightSettingsPage::ColumnCount - 1), selected); } - -void CoreHighlightSettingsPage::selectIgnoredRow(QTableWidgetItem *item) +void CoreHighlightSettingsPage::selectIgnoredRow(QTableWidgetItem* item) { int row = item->row(); bool selected = item->isSelected(); - ui.ignoredTable - ->setRangeSelected(QTableWidgetSelectionRange(row, 0, row, CoreHighlightSettingsPage::ColumnCount - 1), - selected); + ui.ignoredTable->setRangeSelected(QTableWidgetSelectionRange(row, 0, row, CoreHighlightSettingsPage::ColumnCount - 1), selected); } - void CoreHighlightSettingsPage::emptyHighlightTable() { // ui.highlight and highlightList should have the same size, but just to make sure. @@ -491,7 +472,6 @@ void CoreHighlightSettingsPage::emptyHighlightTable() highlightList.clear(); } - void CoreHighlightSettingsPage::emptyIgnoredTable() { // ui.highlight and highlightList should have the same size, but just to make sure. @@ -504,85 +484,76 @@ void CoreHighlightSettingsPage::emptyIgnoredTable() ignoredList.clear(); } - -void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item) +void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem* item) { if (item->row() + 1 > highlightList.size()) return; auto highlightRule = highlightList.value(item->row()); - 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")); - highlightRule.name = item->text(); - break; - case CoreHighlightSettingsPage::RegExColumn: - highlightRule.isRegEx = (item->checkState() == Qt::Checked); - break; - case CoreHighlightSettingsPage::CsColumn: - highlightRule.isCaseSensitive = (item->checkState() == Qt::Checked); - break; - case CoreHighlightSettingsPage::SenderColumn: - if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) - item->setText(""); - highlightRule.sender = item->text(); - break; - case CoreHighlightSettingsPage::ChanColumn: - if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) - item->setText(""); - highlightRule.chanName = item->text(); - break; + case CoreHighlightSettingsPage::EnableColumn: + highlightRule.setIsEnabled(item->checkState() == Qt::Checked); + break; + case CoreHighlightSettingsPage::NameColumn: + highlightRule.setContents(item->text()); + break; + case CoreHighlightSettingsPage::RegExColumn: + highlightRule.setIsRegEx(item->checkState() == Qt::Checked); + break; + case CoreHighlightSettingsPage::CsColumn: + highlightRule.setIsCaseSensitive(item->checkState() == Qt::Checked); + break; + case CoreHighlightSettingsPage::SenderColumn: + if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) + item->setText(""); + highlightRule.setSender(item->text()); + break; + case CoreHighlightSettingsPage::ChanColumn: + if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) + item->setText(""); + highlightRule.setChanName(item->text()); + break; } highlightList[item->row()] = highlightRule; emit widgetHasChanged(); } - -void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item) +void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem* item) { if (item->row() + 1 > ignoredList.size()) return; auto ignoredRule = ignoredList.value(item->row()); - 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")); - ignoredRule.name = item->text(); - break; - case CoreHighlightSettingsPage::RegExColumn: - ignoredRule.isRegEx = (item->checkState() == Qt::Checked); - break; - case CoreHighlightSettingsPage::CsColumn: - ignoredRule.isCaseSensitive = (item->checkState() == Qt::Checked); - break; - case CoreHighlightSettingsPage::SenderColumn: - if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) - item->setText(""); - ignoredRule.sender = item->text(); - break; - case CoreHighlightSettingsPage::ChanColumn: - if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) - item->setText(""); - ignoredRule.chanName = item->text(); - break; + case CoreHighlightSettingsPage::EnableColumn: + ignoredRule.setIsEnabled(item->checkState() == Qt::Checked); + break; + case CoreHighlightSettingsPage::NameColumn: + ignoredRule.setContents(item->text()); + break; + case CoreHighlightSettingsPage::RegExColumn: + ignoredRule.setIsRegEx(item->checkState() == Qt::Checked); + break; + case CoreHighlightSettingsPage::CsColumn: + ignoredRule.setIsCaseSensitive(item->checkState() == Qt::Checked); + break; + case CoreHighlightSettingsPage::SenderColumn: + if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) + item->setText(""); + ignoredRule.setSender(item->text()); + break; + case CoreHighlightSettingsPage::ChanColumn: + if (!item->text().isEmpty() && item->text().trimmed().isEmpty()) + item->setText(""); + ignoredRule.setChanName(item->text()); + break; } ignoredList[item->row()] = ignoredRule; emit widgetHasChanged(); } - void CoreHighlightSettingsPage::load() { emptyHighlightTable(); @@ -590,19 +561,24 @@ void CoreHighlightSettingsPage::load() auto ruleManager = Client::highlightRuleManager(); if (ruleManager) { - for (auto &rule : ruleManager->highlightRuleList()) { - if (rule.isInverse) { - addNewIgnoredRow(rule.isEnabled, - rule.id, - rule.name, - rule.isRegEx, - rule.isCaseSensitive, - rule.sender, - rule.chanName); + for (auto& rule : ruleManager->highlightRuleList()) { + if (rule.isInverse()) { + addNewIgnoredRow(rule.isEnabled(), + rule.id(), + rule.contents(), + rule.isRegEx(), + rule.isCaseSensitive(), + rule.sender(), + rule.chanName()); } else { - addNewHighlightRow(rule.isEnabled, rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.sender, - rule.chanName); + addNewHighlightRow(rule.isEnabled(), + rule.id(), + rule.contents(), + rule.isRegEx(), + rule.isCaseSensitive(), + rule.sender(), + rule.chanName()); } } @@ -614,12 +590,12 @@ void CoreHighlightSettingsPage::load() setChangedState(false); _initialized = true; - } else { + } + else { defaults(); } } - void CoreHighlightSettingsPage::save() { if (!hasChanged()) @@ -632,18 +608,30 @@ void CoreHighlightSettingsPage::save() if (ruleManager == nullptr) return; - auto clonedManager = HighlightRuleManager(); + HighlightRuleManager clonedManager; clonedManager.fromVariantMap(ruleManager->toVariantMap()); clonedManager.clear(); - for (auto &rule : highlightList) { - clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, false, - rule.sender, rule.chanName); + for (auto& rule : highlightList) { + clonedManager.addHighlightRule(rule.id(), + rule.contents(), + rule.isRegEx(), + rule.isCaseSensitive(), + rule.isEnabled(), + false, + rule.sender(), + rule.chanName()); } - for (auto &rule : ignoredList) { - clonedManager.addHighlightRule(rule.id, rule.name, rule.isRegEx, rule.isCaseSensitive, rule.isEnabled, true, - rule.sender, rule.chanName); + for (auto& rule : ignoredList) { + clonedManager.addHighlightRule(rule.id(), + rule.contents(), + rule.isRegEx(), + rule.isCaseSensitive(), + rule.isEnabled(), + true, + rule.sender(), + rule.chanName()); } auto highlightNickType = ui.highlightNicksComboBox->itemData(ui.highlightNicksComboBox->currentIndex()).value(); @@ -656,18 +644,17 @@ void CoreHighlightSettingsPage::save() load(); } - int CoreHighlightSettingsPage::nextId() { int max = 0; for (int i = 0; i < highlightList.count(); i++) { - int id = highlightList[i].id; + int id = highlightList[i].id(); if (id > max) { max = id; } } for (int i = 0; i < ignoredList.count(); i++) { - int id = ignoredList[i].id; + int id = ignoredList[i].id(); if (id > max) { max = id; } @@ -675,32 +662,27 @@ int CoreHighlightSettingsPage::nextId() 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 + // Re-use translations of "Legacy Highlights" as this is a word-for-word reference, forcing all // spaces to non-breaking - const QString localHighlightsName = tr("Local Highlights").replace(" ", " "); - - const QString remoteHighlightsMsgText = - QString("

%1


%2


%3

" - ).arg(tr("Your Quassel core is too old to support remote highlights"), - tr("You need a Quassel core v0.13.0 or newer to configure remote " - "highlights."), - tr("You can still configure highlights for this device only in " - "%1.").arg(localHighlightsName)); - - QMessageBox::warning(this, - tr("Remote Highlights unsupported"), - remoteHighlightsMsgText); -} + const QString localHighlightsName = tr("Legacy Highlights").replace(" ", " "); + const QString remoteHighlightsMsgText = QString("

%1


%2


%3

") + .arg(tr("Your Quassel core is too old to support remote highlights"), + tr("You need a Quassel core v0.13.0 or newer to configure remote " + "highlights."), + tr("You can still configure highlights for this device only in " + "%1.") + .arg(localHighlightsName)); + + QMessageBox::warning(this, tr("Remote Highlights unsupported"), remoteHighlightsMsgText); +} void CoreHighlightSettingsPage::importRules() { @@ -710,27 +692,19 @@ void CoreHighlightSettingsPage::importRules() // Re-use translations of "Legacy/Local Highlights" as this is a word-for-word reference, // forcing all spaces to non-breaking - QString localHighlightsName; - if (Quassel::runMode() == Quassel::Monolithic) { - localHighlightsName = tr("Legacy Highlights").replace(" ", " "); - } else { - localHighlightsName = tr("Local Highlights").replace(" ", " "); - } + // "Local Highlights" has been removed; it's always called "Legacy" now. + QString localHighlightsName = tr("Legacy Highlights").replace(" ", " "); if (localHighlightList.count() == 0) { // No highlight rules exist to import, do nothing - QMessageBox::information(this, - tr("No highlights to import"), - tr("No highlight rules in %1." - ).arg(localHighlightsName)); + QMessageBox::information(this, tr("No highlights to import"), tr("No highlight rules in %1.").arg(localHighlightsName)); return; } int ret = QMessageBox::question(this, tr("Import highlights?"), - tr("Import all highlight rules from %1?" - ).arg(localHighlightsName), - QMessageBox::Yes|QMessageBox::No, + tr("Import all highlight rules from %1?").arg(localHighlightsName), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); if (ret != QMessageBox::Yes) { @@ -743,35 +717,65 @@ void CoreHighlightSettingsPage::importRules() save(); } - auto clonedManager = HighlightRuleManager(); + HighlightRuleManager clonedManager; clonedManager.fromVariantMap(Client::highlightRuleManager()->toVariantMap()); - for (const auto &variant : notificationSettings.highlightList()) { + for (const auto& variant : notificationSettings.highlightList()) { auto highlightRule = variant.toMap(); - clonedManager.addHighlightRule( - clonedManager.nextId(), - highlightRule["Name"].toString(), - highlightRule["RegEx"].toBool(), - highlightRule["CS"].toBool(), - highlightRule["Enable"].toBool(), - false, - "", - highlightRule["Channel"].toString() - ); + clonedManager.addHighlightRule(clonedManager.nextId(), + highlightRule["Name"].toString(), + highlightRule["RegEx"].toBool(), + highlightRule["CS"].toBool(), + highlightRule["Enable"].toBool(), + false, + "", + highlightRule["Channel"].toString()); + } + + // Copy nickname highlighting settings + clonedManager.setNicksCaseSensitive(notificationSettings.nicksCaseSensitive()); + if (notificationSettings.highlightNick() == NotificationSettings::HighlightNickType::AllNicks) { + clonedManager.setHighlightNick(HighlightRuleManager::HighlightNickType::AllNicks); + } + else if (notificationSettings.highlightNick() == NotificationSettings::HighlightNickType::CurrentNick) { + clonedManager.setHighlightNick(HighlightRuleManager::HighlightNickType::CurrentNick); } + // else - Don't copy "NoNick", "NoNick" is now default and should be ignored Client::highlightRuleManager()->requestUpdate(clonedManager.toVariantMap()); setChangedState(false); load(); - // Give a heads-up that all succeeded - QMessageBox::information(this, - tr("Imported highlights"), - tr("%1 highlight rules successfully imported." - ).arg(QString::number(localHighlightList.count()))); -} + // Give a heads-up that all succeeded, ask about removing old rules + // + // Hypothetically, someone might use a common set of highlight rules across multiple cores. + // This won't matter once client highlights are disabled entirely on newer cores. + // + // Remove this once client-side highlights are disabled for newer cores. + ret = QMessageBox::question(this, tr("Imported highlights"), + QString("

%1


%2

").arg( + tr("%1 highlight rules successfully imported.").arg(QString::number(localHighlightList.count())), + tr("Clean up old, duplicate highlight rules?")), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes); + + if (ret != QMessageBox::Yes) { + // Only two options, Yes or No, return if not Yes + return; + } + // Remove all local highlight rules + notificationSettings.setHighlightList({}); + // Disable local nickname highlighting + notificationSettings.setHighlightNick(NotificationSettings::HighlightNickType::NoNick); + // Disable nickname sensitivity + // This isn't needed to disable local highlights, but it's part of appearing reset-to-default + notificationSettings.setNicksCaseSensitive(false); + + // Refresh HighlightSettingsPage in case it was already loaded + emit localHighlightsChanged(); +} bool CoreHighlightSettingsPage::isSelectable() const {