Repository: nextcloud/desktop
Pull request #5681: Modernise ignorelisttablewidget code
Author: login: claucambra
Created: 2023-05-11T13:02:56Z | Merged: 2025-03-14T15:39:39Z

<!-- 
Thanks for opening a pull request on the Nextcloud desktop client.

Instead of a Contributor License Agreement (CLA) we use a Developer Certificate of Origin (DCO).
https://en.wikipedia.org/wiki/Developer_Certificate_of_Origin

To accept that DCO, please make sure that you add a line like
Signed-off-by: Random Developer <random@developer.example.org>
at the end of each commit message.

This Signed-off-by trailer can be added automatically by git if you pass --signoff or -s to git commit.
See also:
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---no-signoff
-->



Diff:
diff --git a/src/gui/ignorelisttablewidget.cpp b/src/gui/ignorelisttablewidget.cpp
index 1d4f2422599af..193d41585a906 100644
--- a/src/gui/ignorelisttablewidget.cpp
+++ b/src/gui/ignorelisttablewidget.cpp
@@ -27,11 +27,11 @@ IgnoreListTableWidget::IgnoreListTableWidget(QWidget *parent)
                                      "This is useful for meta data."));
 
     ui->removePushButton->setEnabled(false);
-    connect(ui->tableWidget,         &QTableWidget::itemSelectionChanged,
+    connect(ui->tableWidget, &QTableWidget::itemSelectionChanged,
             this, &IgnoreListTableWidget::slotItemSelectionChanged);
-    connect(ui->removePushButton,    &QAbstractButton::clicked,
+    connect(ui->removePushButton, &QAbstractButton::clicked,
             this, &IgnoreListTableWidget::slotRemoveCurrentItem);
-    connect(ui->addPushButton,       &QAbstractButton::clicked,
+    connect(ui->addPushButton, &QAbstractButton::clicked,
             this, &IgnoreListTableWidget::slotAddPattern);
     connect(ui->removeAllPushButton, &QAbstractButton::clicked,
             this, &IgnoreListTableWidget::slotRemoveAllItems);
@@ -48,13 +48,13 @@ IgnoreListTableWidget::~IgnoreListTableWidget()
 
 void IgnoreListTableWidget::slotItemSelectionChanged()
 {
-    QTableWidgetItem *item = ui->tableWidget->currentItem();
+    const auto item = ui->tableWidget->currentItem();
     if (!item) {
         ui->removePushButton->setEnabled(false);
         return;
     }
 
-    bool enable = item->flags() & Qt::ItemIsEnabled;
+    const auto enable = item->flags() & Qt::ItemIsEnabled;
     ui->removePushButton->setEnabled(enable);
 }
 
@@ -70,15 +70,18 @@ void IgnoreListTableWidget::slotRemoveAllItems()
     ui->tableWidget->setRowCount(0);
 }
 
-void IgnoreListTableWidget::slotWriteIgnoreFile(const QString & file)
+void IgnoreListTableWidget::slotWriteIgnoreFile(const QString &file)
 {
     QFile ignores(file);
+
     if (ignores.open(QIODevice::WriteOnly)) {
         // rewrites the whole file since now the user can also remove system patterns
         QFile::resize(file, 0);
-        for (int row = 0; row < ui->tableWidget->rowCount(); ++row) {
-            QTableWidgetItem *patternItem = ui->tableWidget->item(row, patternCol);
-            QTableWidgetItem *deletableItem = ui->tableWidget->item(row, deletableCol);
+
+        for (auto row = 0; row < ui->tableWidget->rowCount(); ++row) {
+            const auto patternItem = ui->tableWidget->item(row, patternCol);
+            const auto deletableItem = ui->tableWidget->item(row, deletableCol);
+
             if (patternItem->flags() & Qt::ItemIsEnabled) {
                 QByteArray prepend;
                 if (deletableItem->checkState() == Qt::Checked) {
@@ -90,12 +93,13 @@ void IgnoreListTableWidget::slotWriteIgnoreFile(const QString & file)
             }
         }
     } else {
-        QMessageBox::warning(this, tr("Could not open file"),
-            tr("Cannot write changes to \"%1\".").arg(file));
+        QMessageBox::warning(this,
+                             tr("Could not open file"),
+                             tr("Cannot write changes to \"%1\".").arg(file));
     }
     ignores.close(); //close the file before reloading stuff.
 
-    FolderMan *folderMan = FolderMan::instance();
+    const auto folderMan = FolderMan::instance();
 
     // We need to force a remote discovery after a change of the ignore list.
     // Otherwise we would not download the files/directories that are no longer
@@ -108,10 +112,13 @@ void IgnoreListTableWidget::slotWriteIgnoreFile(const QString & file)
 
 void IgnoreListTableWidget::slotAddPattern()
 {
-    bool okClicked = false;
-    QString pattern = QInputDialog::getText(this, tr("Add Ignore Pattern"),
-        tr("Add a new ignore pattern:"),
-        QLineEdit::Normal, QString(), &okClicked);
+    auto okClicked = false;
+    const auto pattern = QInputDialog::getText(this,
+                                               tr("Add Ignore Pattern"),
+                                               tr("Add a new ignore pattern:"),
+                                               QLineEdit::Normal,
+                                               {},
+                                               &okClicked);
 
     if (!okClicked || pattern.isEmpty())
         return;
@@ -120,18 +127,20 @@ void IgnoreListTableWidget::slotAddPattern()
     ui->tableWidget->scrollToBottom();
 }
 
-void IgnoreListTableWidget::readIgnoreFile(const QString &file, bool readOnly)
+void IgnoreListTableWidget::readIgnoreFile(const QString &file, const bool readOnly)
 {
     QFile ignores(file);
+
     if (ignores.open(QIODevice::ReadOnly)) {
         while (!ignores.atEnd()) {
-            QString line = QString::fromUtf8(ignores.readLine());
+            auto line = QString::fromUtf8(ignores.readLine());
             line.chop(1);
             if (line == QStringLiteral("\\#*#")) {
                 continue;
             }
+
             if (!line.isEmpty() && !line.startsWith("#")) {
-                bool deletable = false;
+                auto deletable = false;
                 if (line.startsWith(']')) {
                     deletable = true;
                     line = line.mid(1);
@@ -142,16 +151,16 @@ void IgnoreListTableWidget::readIgnoreFile(const QString &file, bool readOnly)
     }
 }
 
-int IgnoreListTableWidget::addPattern(const QString &pattern, bool deletable, bool readOnly)
+int IgnoreListTableWidget::addPattern(const QString &pattern, const bool deletable, const bool readOnly)
 {
-    int newRow = ui->tableWidget->rowCount();
+    const auto newRow = ui->tableWidget->rowCount();
     ui->tableWidget->setRowCount(newRow + 1);
 
-    auto *patternItem = new QTableWidgetItem;
+    const auto patternItem = new QTableWidgetItem;
     patternItem->setText(pattern);
     ui->tableWidget->setItem(newRow, patternCol, patternItem);
 
-    auto *deletableItem = new QTableWidgetItem;
+    const auto deletableItem = new QTableWidgetItem;
     deletableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
     deletableItem->setCheckState(deletable ? Qt::Checked : Qt::Unchecked);
     ui->tableWidget->setItem(newRow, deletableCol, deletableItem);
diff --git a/src/gui/ignorelisttablewidget.h b/src/gui/ignorelisttablewidget.h
index 39d43fde98247..d958cbc4dbaa1 100644
--- a/src/gui/ignorelisttablewidget.h
+++ b/src/gui/ignorelisttablewidget.h
@@ -23,7 +23,7 @@ class IgnoreListTableWidget : public QWidget
 
 public slots:
     void slotRemoveAllItems();
-    void slotWriteIgnoreFile(const QString & file);
+    void slotWriteIgnoreFile(const QString &file);
 
 private slots:
     void slotItemSelectionChanged();


Reviews:
user: login: mgallien
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-03-12T13:42:01Z
user: login: claucambra
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-13T03:13:39Z
user: login: mgallien
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-14T14:01:32Z

Review comments:
diff_hunk: @@ -18,12 +18,12 @@ class IgnoreListTableWidget : public QWidget
     IgnoreListTableWidget(QWidget *parent = nullptr);
     ~IgnoreListTableWidget() override;
 
-    void readIgnoreFile(const QString &file, bool readOnly = false);
-    int addPattern(const QString &pattern, bool deletable, bool readOnly);
+    void readIgnoreFile(const QString &file, const bool readOnly = false);
+    int addPattern(const QString &pattern, const bool deletable, const bool readOnly);
path: src/gui/ignorelisttablewidget.h
user: login: mgallien
body: please remove the `const` qualifier for POD data types as they must not be in the declaration interface for the methods, only the implementation

they do not change the signature for a caller (the generated symbol in the shared library does not include them)
they are an implementation detail
created_at: 2025-03-12T13:41:58Z
author_association: COLLABORATOR
diff_hunk: @@ -18,12 +18,12 @@ class IgnoreListTableWidget : public QWidget
     IgnoreListTableWidget(QWidget *parent = nullptr);
     ~IgnoreListTableWidget() override;
 
-    void readIgnoreFile(const QString &file, bool readOnly = false);
-    int addPattern(const QString &pattern, bool deletable, bool readOnly);
+    void readIgnoreFile(const QString &file, const bool readOnly = false);
+    int addPattern(const QString &pattern, const bool deletable, const bool readOnly);
path: src/gui/ignorelisttablewidget.h
user: login: claucambra
body: Thanks, fixed
created_at: 2025-03-13T03:13:39Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2023-05-11T14:36:42Z
body: SonarCloud Quality Gate failed.&nbsp; &nbsp; [![Quality Gate failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/failed-16px.png 'Quality Gate failed')](https://sonarcloud.io/dashboard?id=nextcloud_desktop&pullRequest=5681)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=CODE_SMELL) [2 Code Smells](https://sonarcloud.io/project/issues?id=nextcloud_desktop&pullRequest=5681&resolved=false&types=CODE_SMELL)

[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/0-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=nextcloud_desktop&pullRequest=5681&metric=new_coverage&view=list) [0.0% Coverage](https://sonarcloud.io/component_measures?id=nextcloud_desktop&pullRequest=5681&metric=new_coverage&view=list)  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=nextcloud_desktop&pullRequest=5681&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=nextcloud_desktop&pullRequest=5681&metric=new_duplicated_lines_density&view=list)


author_association: NONE
user: login: github-actions[bot]
created_at: 2025-03-14T14:07:38Z
body: 
  <!-- automated comment for an appimage build -->

  Artifact containing the AppImage: [nextcloud-appimage-pr-5681.zip](https://github.com/nextcloud/desktop/actions/runs/13858231418/artifacts/2753100529)

  SHA256 checksum: `880b940b18afdc9a15aff7a589b4c4789d2efad1837a4e686438dd5d971c8d57`

  To test this change/fix you can download the above artifact file, unzip it, and run it.

  Please make sure to quit your existing Nextcloud app and backup your data.

author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-03-14T14:38:09Z
body: ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=nextcloud_desktop&pullRequest=5681) **Quality Gate failed**  
Failed conditions  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=nextcloud_desktop&pullRequest=5681&metric=new_coverage&view=list) (required ≥ 80%)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [2 New Code Smells](https://sonarcloud.io/dashboard?id=nextcloud_desktop&pullRequest=5681) (required ≤ 0)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=nextcloud_desktop&pullRequest=5681)

##   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/light_bulb-16px.png '') Catch issues before they fail your Quality Gate with our IDE extension ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/sonarlint-16px.png '') [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)


author_association: NONE