X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fhighlightsettingspage.cpp;h=af0af1f28615f4990cd0578c7921df1251ba3f09;hp=7a000e9b742a7d3e1dc1fd9f8cfb153eb429f5e1;hb=ec747d2e6065e645e2cd768abc84923ef6a19705;hpb=95700544764698a7e2a417c3616d9a6ff30a2fd6 diff --git a/src/qtui/settingspages/highlightsettingspage.cpp b/src/qtui/settingspages/highlightsettingspage.cpp index 7a000e9b..af0af1f2 100644 --- a/src/qtui/settingspages/highlightsettingspage.cpp +++ b/src/qtui/settingspages/highlightsettingspage.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2018 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,157 +20,159 @@ #include "highlightsettingspage.h" -#include "client.h" -#include "qtui.h" -#include "uisettings.h" +#include #include #include -HighlightSettingsPage::HighlightSettingsPage(QWidget *parent) - : SettingsPage(tr("Interface"), tr("Local Highlights"), parent) +#include "client.h" +#include "icon.h" +#include "qtui.h" +#include "uisettings.h" + +HighlightSettingsPage::HighlightSettingsPage(QWidget* parent) + : SettingsPage(tr("Interface"), + // In Monolithic mode, local highlights are replaced by remote highlights + Quassel::runMode() == Quassel::Monolithic ? tr("Legacy Highlights") : tr("Local Highlights"), + parent) { ui.setupUi(this); ui.highlightTable->verticalHeader()->hide(); ui.highlightTable->setShowGrid(false); - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)->setToolTip( - tr("RegEx: This option determines if the highlight rule should be " - "interpreted as a regular expression or just as a keyword.")); - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)->setWhatsThis( - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)->toolTip()); - - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->setToolTip( - tr("CS: This option determines if the highlight rule should be interpreted " - "case sensitive.")); - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->setWhatsThis( - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->toolTip()); - - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)->setToolTip( - tr("

Channel: Semicolon separated list of channel names.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and on 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

")); - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)->setWhatsThis( - ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)->toolTip()); - -#if QT_VERSION < 0x050000 - ui.highlightTable->horizontalHeader()->setResizeMode(HighlightSettingsPage::NameColumn, QHeaderView::Stretch); - ui.highlightTable->horizontalHeader()->setResizeMode(HighlightSettingsPage::RegExColumn, QHeaderView::ResizeToContents); - ui.highlightTable->horizontalHeader()->setResizeMode(HighlightSettingsPage::CsColumn, QHeaderView::ResizeToContents); - ui.highlightTable->horizontalHeader()->setResizeMode(HighlightSettingsPage::EnableColumn, QHeaderView::ResizeToContents); - ui.highlightTable->horizontalHeader()->setResizeMode(HighlightSettingsPage::ChanColumn, QHeaderView::ResizeToContents); -#else + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::EnableColumn)->setToolTip(tr("Enable/disable this rule")); + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::EnableColumn) + ->setWhatsThis(ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::EnableColumn)->toolTip()); + + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::NameColumn)->setToolTip(tr("Phrase to match")); + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::NameColumn) + ->setWhatsThis(ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::NameColumn)->toolTip()); + + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn) + ->setToolTip(tr("RegEx: This option determines if the highlight rule and Channel " + "should be interpreted as regular expressions or just as keywords.")); + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn) + ->setWhatsThis(ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)->toolTip()); + + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn) + ->setToolTip(tr("CS: This option determines if the highlight rule and Channel " + "should be interpreted case sensitive.")); + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn) + ->setWhatsThis(ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->toolTip()); + + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn) + ->setToolTip(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

")); + ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn) + ->setWhatsThis(ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)->toolTip()); + ui.highlightTable->horizontalHeader()->setSectionResizeMode(HighlightSettingsPage::NameColumn, QHeaderView::Stretch); ui.highlightTable->horizontalHeader()->setSectionResizeMode(HighlightSettingsPage::RegExColumn, QHeaderView::ResizeToContents); ui.highlightTable->horizontalHeader()->setSectionResizeMode(HighlightSettingsPage::CsColumn, QHeaderView::ResizeToContents); ui.highlightTable->horizontalHeader()->setSectionResizeMode(HighlightSettingsPage::EnableColumn, QHeaderView::ResizeToContents); ui.highlightTable->horizontalHeader()->setSectionResizeMode(HighlightSettingsPage::ChanColumn, QHeaderView::ResizeToContents); -#endif // Information icon - ui.localHighlightsIcon->setPixmap(QIcon::fromTheme("dialog-information").pixmap(16)); + ui.localHighlightsIcon->setPixmap(icon::get("dialog-information").pixmap(16)); // Set up client/monolithic local highlights information if (Quassel::runMode() == Quassel::Monolithic) { // We're running in Monolithic mode, core/client version in total sync. Discourage the use - // of local highlights as it's identical to setting remote highlights. - ui.localHighlightsLabel->setText( - tr("Local Highlights are replaced by Remote Highlights")); - } else { + // of local (legacy) highlights as it's identical to setting remote highlights. + ui.localHighlightsLabel->setText(tr("Legacy Highlights are replaced by Highlights")); + } + else { // We're running in client/split mode, allow for splitting the details. ui.localHighlightsLabel->setText(tr("Local Highlights apply to this device only")); } - connect(ui.add, SIGNAL(clicked(bool)), this, SLOT(addNewRow())); - connect(ui.remove, SIGNAL(clicked(bool)), this, SLOT(removeSelectedRows())); - //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(selectRow(QTableWidgetItem *))); - - connect(ui.highlightAllNicks, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); - connect(ui.highlightCurrentNick, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); - connect(ui.highlightNoNick, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); - connect(ui.nicksCaseSensitive, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged())); - connect(ui.add, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); - connect(ui.remove, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); - connect(ui.highlightTable, SIGNAL(itemChanged(QTableWidgetItem *)), this, SLOT(tableChanged(QTableWidgetItem *))); + connect(ui.add, &QAbstractButton::clicked, this, [this]() { addNewRow(); }); + connect(ui.remove, &QAbstractButton::clicked, this, &HighlightSettingsPage::removeSelectedRows); + // TODO: search for a better signal (one that emits everytime a selection has been changed for one item) + connect(ui.highlightTable, &QTableWidget::itemClicked, this, &HighlightSettingsPage::selectRow); + + connect(ui.highlightAllNicks, &QAbstractButton::clicked, this, &HighlightSettingsPage::widgetHasChanged); + connect(ui.highlightCurrentNick, &QAbstractButton::clicked, this, &HighlightSettingsPage::widgetHasChanged); + connect(ui.highlightNoNick, &QAbstractButton::clicked, this, &HighlightSettingsPage::widgetHasChanged); + connect(ui.nicksCaseSensitive, &QAbstractButton::clicked, this, &HighlightSettingsPage::widgetHasChanged); + connect(ui.add, &QAbstractButton::clicked, this, &HighlightSettingsPage::widgetHasChanged); + connect(ui.remove, &QAbstractButton::clicked, this, &HighlightSettingsPage::widgetHasChanged); + connect(ui.highlightTable, &QTableWidget::itemChanged, this, &HighlightSettingsPage::tableChanged); } - bool HighlightSettingsPage::hasDefaults() const { return true; } - void HighlightSettingsPage::defaults() { - ui.highlightNoNick->setChecked(true); + ui.highlightCurrentNick->setChecked(true); ui.nicksCaseSensitive->setChecked(false); emptyTable(); widgetHasChanged(); } - void HighlightSettingsPage::addNewRow(QString name, bool regex, bool cs, bool enable, QString chanName, bool self) { - ui.highlightTable->setRowCount(ui.highlightTable->rowCount()+1); + ui.highlightTable->setRowCount(ui.highlightTable->rowCount() + 1); - QTableWidgetItem *enableItem = new QTableWidgetItem(""); + QTableWidgetItem* enableItem = new QTableWidgetItem(""); if (enable) enableItem->setCheckState(Qt::Checked); else enableItem->setCheckState(Qt::Unchecked); - enableItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable); + enableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - QTableWidgetItem *nameItem = new QTableWidgetItem(name); + auto* nameItem = new QTableWidgetItem(name); - QTableWidgetItem *regexItem = new QTableWidgetItem(""); + QTableWidgetItem* regexItem = new QTableWidgetItem(""); if (regex) regexItem->setCheckState(Qt::Checked); else regexItem->setCheckState(Qt::Unchecked); - regexItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable); + regexItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - QTableWidgetItem *csItem = new QTableWidgetItem(""); + QTableWidgetItem* csItem = new QTableWidgetItem(""); if (cs) csItem->setCheckState(Qt::Checked); else csItem->setCheckState(Qt::Unchecked); - csItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable); + csItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - QTableWidgetItem *chanNameItem = new QTableWidgetItem(chanName); + 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 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.")); - chanNameItem->setToolTip( - tr("

Channel: Semicolon separated list of channel names.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and on 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

")); - - int lastRow = ui.highlightTable->rowCount()-1; + regexItem->setToolTip(tr("RegEx: This option determines if the highlight rule and Channel " + "should be interpreted as regular expressions or just as keywords.")); + csItem->setToolTip(tr("CS: This option determines if the highlight rule and Channel " + "should be interpreted case sensitive.")); + chanNameItem->setToolTip(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

")); + + int lastRow = ui.highlightTable->rowCount() - 1; ui.highlightTable->setItem(lastRow, HighlightSettingsPage::EnableColumn, enableItem); ui.highlightTable->setItem(lastRow, HighlightSettingsPage::NameColumn, nameItem); ui.highlightTable->setItem(lastRow, HighlightSettingsPage::RegExColumn, regexItem); @@ -190,17 +192,16 @@ void HighlightSettingsPage::addNewRow(QString name, bool regex, bool cs, bool en highlightList.append(highlightRule); } - void HighlightSettingsPage::removeSelectedRows() { QList selectedRows; - QList selectedItemList = ui.highlightTable->selectedItems(); - foreach(QTableWidgetItem *selectedItem, selectedItemList) { + QList selectedItemList = ui.highlightTable->selectedItems(); + foreach (QTableWidgetItem* selectedItem, selectedItemList) { selectedRows.append(selectedItem->row()); } - qSort(selectedRows.begin(), selectedRows.end(), qGreater()); + std::sort(selectedRows.begin(), selectedRows.end(), std::greater<>()); int lastRow = -1; - foreach(int row, selectedRows) { + foreach (int row, selectedRows) { if (row != lastRow) { ui.highlightTable->removeRow(row); highlightList.removeAt(row); @@ -209,15 +210,13 @@ void HighlightSettingsPage::removeSelectedRows() } } - -void HighlightSettingsPage::selectRow(QTableWidgetItem *item) +void HighlightSettingsPage::selectRow(QTableWidgetItem* item) { int row = item->row(); bool selected = item->isSelected(); - ui.highlightTable->setRangeSelected(QTableWidgetSelectionRange(row, 0, row, HighlightSettingsPage::ColumnCount-1), selected); + ui.highlightTable->setRangeSelected(QTableWidgetSelectionRange(row, 0, row, HighlightSettingsPage::ColumnCount - 1), selected); } - void HighlightSettingsPage::emptyTable() { // ui.highlight and highlightList should have the same size, but just to make sure. @@ -232,16 +231,14 @@ void HighlightSettingsPage::emptyTable() } } - -void HighlightSettingsPage::tableChanged(QTableWidgetItem *item) +void HighlightSettingsPage::tableChanged(QTableWidgetItem* item) { - if (item->row()+1 > highlightList.size()) + if (item->row() + 1 > highlightList.size()) return; QVariantMap highlightRule = highlightList.value(item->row()).toMap(); - switch (item->column()) - { + switch (item->column()) { case HighlightSettingsPage::EnableColumn: highlightRule["Enable"] = (item->checkState() == Qt::Checked); break; @@ -266,49 +263,45 @@ void HighlightSettingsPage::tableChanged(QTableWidgetItem *item) emit widgetHasChanged(); } - void HighlightSettingsPage::on_localHighlightsDetails_clicked() { - // Re-use translations of "Remote Highlights" as this is a word-for-word reference, forcing all - // spaces to non-breaking - const QString remoteHighlightsName = tr("Remote Highlights").replace(" ", " "); - QString localHighlightsMsgText; - - // Set up client/monolithic local highlights information + // Show information specific to client/monolithic differences if (Quassel::runMode() == Quassel::Monolithic) { // We're running in Monolithic mode, core/client version in total sync. Discourage the use - // of local highlights as it's identical to setting remote highlights. - localHighlightsMsgText = - QString("

%1


%2


%3

" - ).arg(tr("Local Highlights are replaced by Remote Highlights"), - tr("These highlights will keep working for now, but you should move " - "to the improved highlight rules when you can."), - tr("Configure the new style of highlights in " - "%1.").arg(remoteHighlightsName)); - } else { + // of local (legacy) highlights as it's identical to setting remote highlights. + QMessageBox::information(this, + tr("Legacy Highlights vs. Highlights"), + QString("

%1


%2


%3

") + .arg(tr("Legacy Highlights are replaced by Highlights"), + tr("These highlights will keep working for now, but you should move to " + "the improved highlight rules when you can."), + tr("Configure the new style of highlights in " + "%1.") + .arg(tr("Highlights")))); + } + else { // We're running in client/split mode, allow for splitting the details. - localHighlightsMsgText = - QString("

%1


%2


%3

" - ).arg(tr("Local Highlights apply to this device only"), - tr("Highlights configured on this page only apply to your current " - "device."), - tr("Configure highlights for all of your devices in " - "%1.").arg(remoteHighlightsName)); + QMessageBox::information(this, + tr("Local Highlights vs. Remote Highlights"), + QString("

%1


%2


%3

") + .arg(tr("Local Highlights apply to this device only"), + tr("Highlights configured on this page only apply to your current " + "device."), + tr("Configure highlights for all of your devices in " + "%1.") + .arg(tr("Remote Highlights").replace(" ", " ")))); + // Re-use translations of "Remote Highlights" as this is a word-for-word reference, forcing + // all spaces to be non-breaking } - - QMessageBox::information(this, - tr("Local Highlights vs. Remote Highlights"), - localHighlightsMsgText); } - void HighlightSettingsPage::load() { NotificationSettings notificationSettings; emptyTable(); - foreach(QVariant highlight, notificationSettings.highlightList()) { + foreach (QVariant highlight, notificationSettings.highlightList()) { QVariantMap highlightRule = highlight.toMap(); QString name = highlightRule["Name"].toString(); bool regex = highlightRule["RegEx"].toBool(); @@ -319,8 +312,7 @@ void HighlightSettingsPage::load() addNewRow(name, regex, cs, enable, chanName, true); } - switch (notificationSettings.highlightNick()) - { + switch (notificationSettings.highlightNick()) { case NotificationSettings::NoNick: ui.highlightNoNick->setChecked(true); break; @@ -336,7 +328,6 @@ void HighlightSettingsPage::load() setChangedState(false); } - void HighlightSettingsPage::save() { NotificationSettings notificationSettings; @@ -355,14 +346,13 @@ void HighlightSettingsPage::save() setChangedState(false); } - void HighlightSettingsPage::widgetHasChanged() { bool changed = testHasChanged(); - if (changed != hasChanged()) setChangedState(changed); + if (changed != hasChanged()) + setChangedState(changed); } - bool HighlightSettingsPage::testHasChanged() { NotificationSettings notificationSettings;