modernize: Reformat ALL the source... again!
[quassel.git] / src / qtui / settingspages / highlightsettingspage.cpp
index f881645..1d7a20f 100644 (file)
 #include "qtui.h"
 #include "uisettings.h"
 
-
-HighlightSettingsPage::HighlightSettingsPage(QWidget *parent)
+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"),
+                   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::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("<b>RegEx</b>: This option determines if the highlight rule and <i>Channel</i> "
-                   "should be interpreted as <b>regular expressions</b> or just as keywords."));
-    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)->setWhatsThis(
-                ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)->toolTip());
-
-    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->setToolTip(
-                tr("<b>CS</b>: This option determines if the highlight rule and <i>Channel</i> "
-                   "should be interpreted <b>case sensitive</b>."));
-    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->setWhatsThis(
-                ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->toolTip());
-
-    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)->setToolTip(
-                tr("<p><b>Channel</b>: Semicolon separated list of channel/query names, leave "
-                   "blank to match any name.</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
-                   "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> "
-                   "except for <i>#quasseldroid</i><br />"
-                   "<p>If only inverted names are specified, it will match anything except for "
-                   "what's specified (implicit wildcard).</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>!#quassel*; !#foobar</i><br />"
-                   "would match anything except for <i>#foobar</i> or any channel starting with "
-                   "<i>#quassel</i></p>"));
-    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)->setWhatsThis(
-                ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)->toolTip());
+    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("<b>RegEx</b>: This option determines if the highlight rule and <i>Channel</i> "
+                        "should be interpreted as <b>regular expressions</b> or just as keywords."));
+    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)
+        ->setWhatsThis(ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::RegExColumn)->toolTip());
+
+    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)
+        ->setToolTip(tr("<b>CS</b>: This option determines if the highlight rule and <i>Channel</i> "
+                        "should be interpreted <b>case sensitive</b>."));
+    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)
+        ->setWhatsThis(ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::CsColumn)->toolTip());
+
+    ui.highlightTable->horizontalHeaderItem(HighlightSettingsPage::ChanColumn)
+        ->setToolTip(tr("<p><b>Channel</b>: Semicolon separated list of channel/query names, leave "
+                        "blank to match any name.</p>"
+                        "<p><i>Example:</i><br />"
+                        "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
+                        "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> "
+                        "except for <i>#quasseldroid</i><br />"
+                        "<p>If only inverted names are specified, it will match anything except for "
+                        "what's specified (implicit wildcard).</p>"
+                        "<p><i>Example:</i><br />"
+                        "<i>!#quassel*; !#foobar</i><br />"
+                        "would match anything except for <i>#foobar</i> or any channel starting with "
+                        "<i>#quassel</i></p>"));
+    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);
@@ -92,16 +87,16 @@ HighlightSettingsPage::HighlightSettingsPage(QWidget *parent)
     if (Quassel::runMode() == Quassel::Monolithic) {
         // We're running in Monolithic mode, core/client version in total sync.  Discourage the use
         // of local (legacy) highlights as it's identical to setting remote highlights.
-        ui.localHighlightsLabel->setText(
-                    tr("Legacy Highlights are replaced by Highlights"));
-    else {
+        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, &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)
+    // 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);
@@ -113,13 +108,11 @@ HighlightSettingsPage::HighlightSettingsPage(QWidget *parent)
     connect(ui.highlightTable, &QTableWidget::itemChanged, this, &HighlightSettingsPage::tableChanged);
 }
 
-
 bool HighlightSettingsPage::hasDefaults() const
 {
     return true;
 }
 
-
 void HighlightSettingsPage::defaults()
 {
     ui.highlightCurrentNick->setChecked(true);
@@ -129,59 +122,55 @@ void HighlightSettingsPage::defaults()
     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("");
+    QTableWidgetItemenableItem = 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);
 
-    auto *nameItem = new QTableWidgetItem(name);
+    autonameItem = new QTableWidgetItem(name);
 
-    QTableWidgetItem *regexItem = new QTableWidgetItem("");
+    QTableWidgetItemregexItem = 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("");
+    QTableWidgetItemcsItem = 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);
 
-    auto *chanNameItem = new QTableWidgetItem(chanName);
+    autochanNameItem = new QTableWidgetItem(chanName);
 
     enableItem->setToolTip(tr("Enable/disable this rule"));
     nameItem->setToolTip(tr("Phrase to match"));
-    regexItem->setToolTip(
-                tr("<b>RegEx</b>: This option determines if the highlight rule and <i>Channel</i> "
-                   "should be interpreted as <b>regular expressions</b> or just as keywords."));
-    csItem->setToolTip(
-                tr("<b>CS</b>: This option determines if the highlight rule and <i>Channel</i> "
-                   "should be interpreted <b>case sensitive</b>."));
-    chanNameItem->setToolTip(
-                tr("<p><b>Channel</b>: Semicolon separated list of channel/query names, leave "
-                   "blank to match any name.</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
-                   "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> "
-                   "except for <i>#quasseldroid</i><br />"
-                   "<p>If only inverted names are specified, it will match anything except for "
-                   "what's specified (implicit wildcard).</p>"
-                   "<p><i>Example:</i><br />"
-                   "<i>!#quassel*; !#foobar</i><br />"
-                   "would match anything except for <i>#foobar</i> or any channel starting with "
-                   "<i>#quassel</i></p>"));
-
-    int lastRow = ui.highlightTable->rowCount()-1;
+    regexItem->setToolTip(tr("<b>RegEx</b>: This option determines if the highlight rule and <i>Channel</i> "
+                             "should be interpreted as <b>regular expressions</b> or just as keywords."));
+    csItem->setToolTip(tr("<b>CS</b>: This option determines if the highlight rule and <i>Channel</i> "
+                          "should be interpreted <b>case sensitive</b>."));
+    chanNameItem->setToolTip(tr("<p><b>Channel</b>: Semicolon separated list of channel/query names, leave "
+                                "blank to match any name.</p>"
+                                "<p><i>Example:</i><br />"
+                                "<i>#quassel*; #foobar; !#quasseldroid</i><br />"
+                                "would match on <i>#foobar</i> and any channel starting with <i>#quassel</i> "
+                                "except for <i>#quasseldroid</i><br />"
+                                "<p>If only inverted names are specified, it will match anything except for "
+                                "what's specified (implicit wildcard).</p>"
+                                "<p><i>Example:</i><br />"
+                                "<i>!#quassel*; !#foobar</i><br />"
+                                "would match anything except for <i>#foobar</i> or any channel starting with "
+                                "<i>#quassel</i></p>"));
+
+    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);
@@ -201,17 +190,16 @@ void HighlightSettingsPage::addNewRow(QString name, bool regex, bool cs, bool en
     highlightList.append(highlightRule);
 }
 
-
 void HighlightSettingsPage::removeSelectedRows()
 {
     QList<int> selectedRows;
-    QList<QTableWidgetItem *> selectedItemList = ui.highlightTable->selectedItems();
-    foreach(QTableWidgetItem *selectedItem, selectedItemList) {
+    QList<QTableWidgetItem*> selectedItemList = ui.highlightTable->selectedItems();
+    foreach (QTableWidgetItem* selectedItem, selectedItemList) {
         selectedRows.append(selectedItem->row());
     }
     qSort(selectedRows.begin(), selectedRows.end(), qGreater<int>());
     int lastRow = -1;
-    foreach(int row, selectedRows) {
+    foreach (int row, selectedRows) {
         if (row != lastRow) {
             ui.highlightTable->removeRow(row);
             highlightList.removeAt(row);
@@ -220,15 +208,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.
@@ -243,16 +229,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;
@@ -277,46 +261,45 @@ void HighlightSettingsPage::tableChanged(QTableWidgetItem *item)
     emit widgetHasChanged();
 }
 
-
 void HighlightSettingsPage::on_localHighlightsDetails_clicked()
 {
     // 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 (legacy) highlights as it's identical to setting remote highlights.
-        QMessageBox::information(
-                    this,
-                    tr("Legacy Highlights vs. Highlights"),
-                    QString("<p><b>%1</b></p></br><p>%2</p></br><p>%3</p>")
-                    .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 "
-                            "<i>%1</i>.").arg(tr("Highlights"))));
-    } else {
+        QMessageBox::information(this,
+                                 tr("Legacy Highlights vs. Highlights"),
+                                 QString("<p><b>%1</b></p></br><p>%2</p></br><p>%3</p>")
+                                     .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 "
+                                             "<i>%1</i>.")
+                                              .arg(tr("Highlights"))));
+    }
+    else {
         // We're running in client/split mode, allow for splitting the details.
-        QMessageBox::information(
-                    this,
-                    tr("Local Highlights vs. Remote Highlights"),
-                    QString("<p><b>%1</b></p></br><p>%2</p></br><p>%3</p>")
-                    .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 "
-                            "<i>%1</i>.").arg(tr("Remote Highlights").replace(" ", "&nbsp;"))));
+        QMessageBox::information(this,
+                                 tr("Local Highlights vs. Remote Highlights"),
+                                 QString("<p><b>%1</b></p></br><p>%2</p></br><p>%3</p>")
+                                     .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 "
+                                             "<i>%1</i>.")
+                                              .arg(tr("Remote Highlights").replace(" ", "&nbsp;"))));
         // Re-use translations of "Remote Highlights" as this is a word-for-word reference, forcing
         // all spaces to be non-breaking
     }
 }
 
-
 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();
@@ -327,8 +310,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;
@@ -344,7 +326,6 @@ void HighlightSettingsPage::load()
     setChangedState(false);
 }
 
-
 void HighlightSettingsPage::save()
 {
     NotificationSettings notificationSettings;
@@ -363,14 +344,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;