Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gui/integration/fileactionsmodel.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/

Check warning on line 4 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Edit this comment to use the C++ format, i.e. "//".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUU_&open=AZ2C3ZsMO-njQfcvHUU_&pullRequest=9738

#include "fileactionsmodel.h"
#include "networkjobs.h"
Expand All @@ -16,12 +16,12 @@

Q_LOGGING_CATEGORY(lcFileActions, "nextcloud.gui.fileactions", QtInfoMsg)

FileActionsModel::FileActionsModel(QObject *parent)

Check warning on line 19 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "parent" of type "class QObject *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVB&open=AZ2C3ZsMO-njQfcvHUVB&pullRequest=9738
: QAbstractListModel(parent)
{
}

QVariant FileActionsModel::data(const QModelIndex &index, int role) const

Check warning on line 24 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "role" of type "int" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVC&open=AZ2C3ZsMO-njQfcvHUVC&pullRequest=9738
{
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid));
const auto row = index.row();
Expand Down Expand Up @@ -53,7 +53,7 @@
return 0;
}

return _fileActions.size();

Check warning on line 56 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion loses integer precision: 'qsizetype' (aka 'long long') to 'int'

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVA&open=AZ2C3ZsMO-njQfcvHUVA&pullRequest=9738
}

QHash<int, QByteArray> FileActionsModel::roleNames() const
Expand All @@ -75,7 +75,7 @@
return _accountState;
}

void FileActionsModel::setAccountState(AccountState *accountState)

Check warning on line 78 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "accountState" of type "class OCC::AccountState *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVD&open=AZ2C3ZsMO-njQfcvHUVD&pullRequest=9738
{
if (accountState == nullptr) {
return;
Expand Down Expand Up @@ -176,7 +176,7 @@
_filePath = _localPath;

const auto folderForPath = FolderMan::instance()->folderForPath(_localPath);
if (folderForPath) {

Check warning on line 179 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "folderForPath" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVE&open=AZ2C3ZsMO-njQfcvHUVE&pullRequest=9738
qCDebug(lcFileActions) << "Found synchronization folder for" << _localPath;

_filePath = _localPath.mid(folderForPath->cleanPath().length() + 1);
Expand All @@ -197,7 +197,7 @@
}
}

QMimeDatabase mimeDb;

Check warning on line 200 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "mimeDb" of type "class QMimeDatabase" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVF&open=AZ2C3ZsMO-njQfcvHUVF&pullRequest=9738
const auto mimeType = mimeDb.mimeTypeForFile(_localPath, mimeMatchMode);
_mimeType = mimeType;
_fileIcon = _accountUrl + Activity::relativeServerFileTypeIconPath(_mimeType);
Expand Down Expand Up @@ -297,8 +297,8 @@
for (const auto &contextMenu : contextMenuList) {
QueryList queryList;
const auto paramsMap = contextMenu.value("params").toMap();
for (auto param = paramsMap.cbegin(), end = paramsMap.cend(); param != end; ++param) {

Check warning on line 300 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "end" of type "class QMap<class QString, class QVariant>::const_iterator" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVG&open=AZ2C3ZsMO-njQfcvHUVG&pullRequest=9738
const auto paramName = param.key();

Check warning on line 301 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid this unnecessary copy by using a "const" reference.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVH&open=AZ2C3ZsMO-njQfcvHUVH&pullRequest=9738
QByteArray paramValue;
if (paramName == fileIdC) {
paramValue = _fileId;
Expand All @@ -320,6 +320,7 @@
}

resetActions(actions);
setResponse({});
qCDebug(lcFileActions) << "File" << _localPath << "has"
<< actions.size()
<< "actions available.";
Expand Down Expand Up @@ -349,7 +350,7 @@
return;
}

auto job = new JsonApiJob(_accountState->account(),

Check failure on line 353 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVJ&open=AZ2C3ZsMO-njQfcvHUVJ&pullRequest=9738
_fileActions.at(row).url,
this);

Check warning on line 355 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "job" of type "class OCC::JsonApiJob *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVI&open=AZ2C3ZsMO-njQfcvHUVI&pullRequest=9738
connect(job, &JsonApiJob::jsonReceived,
Expand All @@ -365,7 +366,7 @@
job->start();
}

void FileActionsModel::processRequest(const QJsonDocument &json, int statusCode)

Check warning on line 369 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "statusCode" of type "int" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVL&open=AZ2C3ZsMO-njQfcvHUVL&pullRequest=9738
{
const auto row = sender()->property(rowC).toInt();
const auto fileAction = _fileActions.at(row).name;
Expand Down Expand Up @@ -436,7 +437,7 @@
};

for (const auto &rowValue : rows) {
const auto row = rowValue.toObject();

Check warning on line 440 in src/gui/integration/fileactionsmodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Declaration shadows a local variable "row" in the outer scope.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2C3ZsMO-njQfcvHUVK&open=AZ2C3ZsMO-njQfcvHUVK&pullRequest=9738
const auto children = row.value(QStringLiteral("children")).toArray();
for (const auto &childValue : children) {
if (const auto parsedResponse = parseChildResponse(childValue.toObject());
Expand Down
40 changes: 40 additions & 0 deletions test/testfileactionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <QTest>

Check failure on line 6 in test/testfileactionsmodel.cpp

View workflow job for this annotation

GitHub Actions / build

test/testfileactionsmodel.cpp:6:10 [clang-diagnostic-error]

'QTest' file not found
#include <QSignalSpy>
#include <QTemporaryFile>

Expand Down Expand Up @@ -308,6 +308,46 @@
}
}
}

#ifdef BUILD_FILE_PROVIDER_MODULE
void testEmptyFileId()
{
_model.setAccountState(&_fakeFolder->accountState());
const auto unsyncedFile = QStringLiteral("unsynced.odt");
_model.setLocalPath(_fakeFolder->localPath() + unsyncedFile);
QVERIFY(_model.fileId().isEmpty());
QCOMPARE(_model.rowCount(), 0);
_model.parseEndpoints();
QVERIFY(_model.responseLabel().contains(QStringLiteral("The file ID is empty")));

_fakeFolder->localModifier().insert(_fakeFolder->localPath() + unsyncedFile);
QVERIFY(_fakeFolder->syncOnce());
const auto fileInfo = _fakeFolder->remoteModifier().find(unsyncedFile);
QVERIFY(fileInfo);
QVERIFY(!fileInfo->fileId.isEmpty());
_model.setFileId(fileInfo->fileId);
QCOMPARE(_model.fileId(), fileInfo->fileId);
_model.parseEndpoints();
QVERIFY(_model.responseLabel().isEmpty());
QCOMPARE(_model.rowCount(), 6);

FileActionsModel fileProviderModel;
QSignalSpy fileActionModelChangedSpy(&fileProviderModel, &FileActionsModel::fileActionModelChanged);
fileProviderModel.setAccountState(&_fakeFolder->accountState());
fileProviderModel.setLocalPath(QDir::tempPath() + QStringLiteral("/fileprovider.odt"));
QVERIFY(fileProviderModel.fileId().isEmpty());
QCOMPARE(fileProviderModel.rowCount(), 0);

fileProviderModel.parseEndpoints();
QVERIFY(fileProviderModel.responseLabel().contains(QStringLiteral("The file ID is empty")));

fileProviderModel.setFileId("test-file-provider-id");
QCOMPARE(fileProviderModel.fileId(), QByteArray("test-file-provider-id"));
QVERIFY(fileActionModelChangedSpy.count() > 0);
QVERIFY(fileProviderModel.rowCount() > 0);
QVERIFY(fileProviderModel.responseLabel().isEmpty());
}
#endif
};

QTEST_MAIN(TestFileActionsModel)
Expand Down
Loading