Skip to content
Merged
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
111 changes: 39 additions & 72 deletions src/gui/integration/FileActionsWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,42 @@ ApplicationWindow {
spacing: Style.trayHorizontalMargin
Layout.fillWidth: true
Layout.fillHeight: true
delegate: fileActionsDelegate
delegate: ItemDelegate {
id: fileActionsDelegate

required property string name
required property int index
required property string actionIcon

Layout.fillWidth: true
height: implicitHeight
width: parent.width
implicitHeight: Style.activityListButtonHeight
padding: Style.standardSpacing

text: name
font.pixelSize: Style.defaultFontPtSize
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
icon {
source: actionIcon
color: palette.windowText
width: Style.minimumActivityItemHeight
height: Style.minimumActivityItemHeight
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
}

background: Rectangle {
color: "transparent"
radius: root.windowRadius
border.width: fileActionsDelegate.hovered ? Style.trayWindowBorderWidth : 0
border.color: palette.dark
anchors.margins: Style.standardSpacing
height: parent.height
width: parent.width
}

onClicked: fileActionModel.createRequest(index)
}
}

Button {
Expand Down Expand Up @@ -186,79 +221,11 @@ ApplicationWindow {
id: responseArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: Qt.openUrlExternally(fileActionModel.responseUrl)
}
}
}
}

Component {
id: fileActionsDelegate

RowLayout {
id: fileAction
Layout.fillWidth: true
height: implicitHeight
width: parent.width

required property string name
required property int index
required property string icon

Button {
id: fileActionButton
flat: true
Layout.fillWidth: true
implicitHeight: Style.activityListButtonHeight

padding: Style.standardSpacing

contentItem: Row {
id: fileActionsContent
anchors.fill: parent
anchors.topMargin: Style.standardSpacing
anchors.rightMargin: Style.standardSpacing
anchors.bottomMargin: Style.standardSpacing
anchors.leftMargin: Style.extraSmallSpacing
spacing: Style.standardSpacing
Layout.fillWidth: true

Image {
source: fileAction.icon + palette.windowText
width: Style.minimumActivityItemHeight
height: Style.minimumActivityItemHeight
fillMode: Image.PreserveAspectFit
Layout.preferredWidth: Style.minimumActivityItemHeight
Layout.preferredHeight: Style.minimumActivityItemHeight
anchors.verticalCenter: parent.verticalCenter
}

EnforcedPlainTextLabel {
text: fileAction.name
color: palette.text
font.pixelSize: Style.defaultFontPtSize
verticalAlignment: Text.AlignVCenter
anchors.verticalCenter: parent.verticalCenter
onClicked: {
Qt.openUrlExternally(fileActionModel.responseUrl)
root.close()
}
}

background: Rectangle {
color: "transparent"
radius: root.windowRadius
border.width: fileActionButton.hovered ? Style.trayWindowBorderWidth : 0
border.color: palette.dark
anchors.margins: Style.standardSpacing
height: parent.height
width: parent.width
}

MouseArea {
id: fileActionMouseArea
anchors.fill: parent
anchors.margins: Style.standardSpacing
cursorShape: Qt.PointingHandCursor
onClicked: fileActionModel.createRequest(fileAction.index)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 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=AZzitiS8Sd2Wf1VcF2D-&open=AZzitiS8Sd2Wf1VcF2D-&pullRequest=9617

#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=AZzitiS8Sd2Wf1VcF2EA&open=AZzitiS8Sd2Wf1VcF2EA&pullRequest=9617
: 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=AZzitiS8Sd2Wf1VcF2EB&open=AZzitiS8Sd2Wf1VcF2EB&pullRequest=9617
{
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid));
const auto row = index.row();
Expand Down Expand Up @@ -53,13 +53,13 @@
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=AZzitiS8Sd2Wf1VcF2D_&open=AZzitiS8Sd2Wf1VcF2D_&pullRequest=9617
}

QHash<int, QByteArray> FileActionsModel::roleNames() const
{
auto roles = QAbstractListModel::roleNames();
roles[FileActionIconRole] = "icon";
roles[FileActionIconRole] = "actionIcon";
roles[FileActionNameRole] = "name";
roles[FileActionUrlRole] = "url";
roles[FileActionMethodRole] = "method";
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=AZzitiS8Sd2Wf1VcF2EC&open=AZzitiS8Sd2Wf1VcF2EC&pullRequest=9617
{
if (accountState == nullptr) {
return;
Expand Down Expand Up @@ -163,7 +163,7 @@
_filePath = _localPath;

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

Check warning on line 166 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=AZzitiS8Sd2Wf1VcF2ED&open=AZzitiS8Sd2Wf1VcF2ED&pullRequest=9617
qCDebug(lcFileActions) << "Found synchronization folder for" << _localPath;

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

QMimeDatabase mimeDb;

Check warning on line 187 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=AZzitiS8Sd2Wf1VcF2EE&open=AZzitiS8Sd2Wf1VcF2EE&pullRequest=9617
const auto mimeType = mimeDb.mimeTypeForFile(_localPath, mimeMatchMode);
_mimeType = mimeType;
_fileIcon = _accountUrl + Activity::relativeServerFileTypeIconPath(_mimeType);
Expand Down Expand Up @@ -284,8 +284,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 287 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=AZzitiS8Sd2Wf1VcF2EF&open=AZzitiS8Sd2Wf1VcF2EF&pullRequest=9617
const auto paramName = param.key();

Check warning on line 288 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=AZzitiS8Sd2Wf1VcF2EG&open=AZzitiS8Sd2Wf1VcF2EG&pullRequest=9617
QByteArray paramValue;
if (paramName == fileIdC) {
paramValue = _fileId;
Expand Down Expand Up @@ -325,7 +325,7 @@
return QStringLiteral("image://svgimage-custom-color/convert_to_text.svg/");
}

return _accountUrl + icon;
return QStringLiteral("image://tray-image-provider/") + _accountUrl + icon;
}

void FileActionsModel::createRequest(const int row)
Expand All @@ -336,7 +336,7 @@
return;
}

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

Check failure on line 339 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=AZzitiS8Sd2Wf1VcF2EI&open=AZzitiS8Sd2Wf1VcF2EI&pullRequest=9617
_fileActions.at(row).url,
this);

Check warning on line 341 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=AZzitiS8Sd2Wf1VcF2EH&open=AZzitiS8Sd2Wf1VcF2EH&pullRequest=9617
connect(job, &JsonApiJob::jsonReceived,
Expand All @@ -352,7 +352,7 @@
job->start();
}

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

Check warning on line 355 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=AZzitiS8Sd2Wf1VcF2EK&open=AZzitiS8Sd2Wf1VcF2EK&pullRequest=9617
{
const auto row = sender()->property(rowC).toInt();
const auto fileAction = _fileActions.at(row).name;
Expand Down Expand Up @@ -423,7 +423,7 @@
};

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

Check warning on line 426 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=AZzitiS8Sd2Wf1VcF2EJ&open=AZzitiS8Sd2Wf1VcF2EJ&pullRequest=9617
const auto children = row.value(QStringLiteral("children")).toArray();
for (const auto &childValue : children) {
if (const auto parsedResponse = parseChildResponse(childValue.toObject());
Expand Down
Loading