X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fcorehighlightsettingspage.cpp;h=24c78c1c4d930e7812abdbb12b3beaf342e2bcb1;hp=7e50229661df4edcd18926a196ef3f351e5229d4;hb=824852f39114a70b69f71ac154650b71a9394f3c;hpb=17c39210b1bce04795046657642de66292518fe6
diff --git a/src/qtui/settingspages/corehighlightsettingspage.cpp b/src/qtui/settingspages/corehighlightsettingspage.cpp
index 7e502296..24c78c1c 100644
--- a/src/qtui/settingspages/corehighlightsettingspage.cpp
+++ b/src/qtui/settingspages/corehighlightsettingspage.cpp
@@ -111,6 +111,7 @@ CoreHighlightSettingsPage::CoreHighlightSettingsPage(QWidget *parent)
}
}
+
void CoreHighlightSettingsPage::coreConnectionStateChanged(bool state)
{
updateCoreSupportStatus(state);
@@ -122,81 +123,171 @@ void CoreHighlightSettingsPage::coreConnectionStateChanged(bool state)
}
}
+
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());
+ 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));
#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::SenderColumn, QHeaderView::ResizeToContents);
table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::ChanColumn, QHeaderView::ResizeToContents);
#else
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 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)
{
// Assume connected state as enforced by the settings page UI
@@ -212,11 +303,13 @@ void CoreHighlightSettingsPage::updateCoreSupportStatus(bool state)
}
}
+
void CoreHighlightSettingsPage::clientConnected()
{
connect(Client::highlightRuleManager(), SIGNAL(updated()), SLOT(revert()));
}
+
void CoreHighlightSettingsPage::revert()
{
if (!hasChanged())
@@ -226,11 +319,13 @@ void CoreHighlightSettingsPage::revert()
load();
}
+
bool CoreHighlightSettingsPage::hasDefaults() const
{
return true;
}
+
void CoreHighlightSettingsPage::defaults()
{
int highlightNickType = HighlightRuleManager::HighlightNickType::CurrentNick;
@@ -243,6 +338,7 @@ 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)
{
@@ -279,41 +375,7 @@ void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QS
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
"));
+ setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem);
int lastRow = ui.highlightTable->rowCount() - 1;
ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem);
@@ -329,6 +391,7 @@ 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)
{
@@ -365,29 +428,7 @@ void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QStr
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
"));
+ setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem);
int lastRow = ui.ignoredTable->rowCount() - 1;
ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem);
@@ -403,6 +444,7 @@ 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;
@@ -421,6 +463,7 @@ void CoreHighlightSettingsPage::removeSelectedHighlightRows()
}
}
+
void CoreHighlightSettingsPage::removeSelectedIgnoredRows()
{
QList selectedRows;
@@ -439,12 +482,15 @@ void CoreHighlightSettingsPage::removeSelectedIgnoredRows()
}
}
-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();
ui.nicksCaseSensitive->setEnabled(highlightNickType != HighlightRuleManager::NoNick);
}
+
void CoreHighlightSettingsPage::selectHighlightRow(QTableWidgetItem *item)
{
int row = item->row();
@@ -454,6 +500,7 @@ void CoreHighlightSettingsPage::selectHighlightRow(QTableWidgetItem *item)
selected);
}
+
void CoreHighlightSettingsPage::selectIgnoredRow(QTableWidgetItem *item)
{
int row = item->row();
@@ -463,6 +510,7 @@ void CoreHighlightSettingsPage::selectIgnoredRow(QTableWidgetItem *item)
selected);
}
+
void CoreHighlightSettingsPage::emptyHighlightTable()
{
// ui.highlight and highlightList should have the same size, but just to make sure.
@@ -475,6 +523,7 @@ void CoreHighlightSettingsPage::emptyHighlightTable()
highlightList.clear();
}
+
void CoreHighlightSettingsPage::emptyIgnoredTable()
{
// ui.highlight and highlightList should have the same size, but just to make sure.
@@ -487,6 +536,7 @@ void CoreHighlightSettingsPage::emptyIgnoredTable()
ignoredList.clear();
}
+
void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item)
{
if (item->row() + 1 > highlightList.size())
@@ -500,8 +550,6 @@ void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item)
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:
@@ -525,6 +573,7 @@ void CoreHighlightSettingsPage::highlightTableChanged(QTableWidgetItem *item)
emit widgetHasChanged();
}
+
void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item)
{
if (item->row() + 1 > ignoredList.size())
@@ -538,8 +587,6 @@ void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item)
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:
@@ -563,6 +610,7 @@ void CoreHighlightSettingsPage::ignoredTableChanged(QTableWidgetItem *item)
emit widgetHasChanged();
}
+
void CoreHighlightSettingsPage::load()
{
emptyHighlightTable();
@@ -599,6 +647,7 @@ void CoreHighlightSettingsPage::load()
}
}
+
void CoreHighlightSettingsPage::save()
{
if (!hasChanged())
@@ -635,7 +684,9 @@ void CoreHighlightSettingsPage::save()
load();
}
-int CoreHighlightSettingsPage::nextId() {
+
+int CoreHighlightSettingsPage::nextId()
+{
int max = 0;
for (int i = 0; i < highlightList.count(); i++) {
int id = highlightList[i].id;
@@ -649,14 +700,16 @@ int CoreHighlightSettingsPage::nextId() {
max = id;
}
}
- return max+1;
+ 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
@@ -676,7 +729,9 @@ void CoreHighlightSettingsPage::on_coreUnsupportedDetails_clicked()
remoteHighlightsMsgText);
}
-void CoreHighlightSettingsPage::importRules() {
+
+void CoreHighlightSettingsPage::importRules()
+{
NotificationSettings notificationSettings;
const auto localHighlightList = notificationSettings.highlightList();
@@ -711,6 +766,11 @@ void CoreHighlightSettingsPage::importRules() {
return;
}
+ if (hasChanged()) {
+ // Save existing changes first to avoid overwriting them
+ save();
+ }
+
auto clonedManager = HighlightRuleManager();
clonedManager.fromVariantMap(Client::highlightRuleManager()->toVariantMap());
@@ -740,7 +800,9 @@ void CoreHighlightSettingsPage::importRules() {
).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.