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
6 changes: 6 additions & 0 deletions src/gui/macOS/fileproviderdomainmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include <QObject>

Check failure on line 8 in src/gui/macOS/fileproviderdomainmanager.h

View workflow job for this annotation

GitHub Actions / build

src/gui/macOS/fileproviderdomainmanager.h:8:10 [clang-diagnostic-error]

'QObject' file not found
#include <QList>

#include "accountstate.h"
Expand Down Expand Up @@ -73,6 +73,12 @@
*/
[[nodiscard]] QString userVisibleUrlForDomainIdentifier(const QString &domainIdentifier) const;

/**
* @brief Open the system file viewer at the root container of a file provider domain.
* @param domainIdentifier The identifier of the file provider domain.
*/
void openFileViewerForDomainIdentifier(const QString &domainIdentifier) const;

public slots:
/**
* @brief Handle file ID changes from push notifications
Expand Down
12 changes: 12 additions & 0 deletions src/gui/macOS/fileproviderdomainmanager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "configfile.h"

#import <AppKit/AppKit.h>
#import <FileProvider/FileProvider.h>

#include <QDir>
Expand Down Expand Up @@ -540,6 +541,17 @@ void removeFileProviderDomainData(NSString * const domainIdentifier)
return {};
}

void FileProviderDomainManager::openFileViewerForDomainIdentifier(const QString &domainIdentifier) const
{
const auto url = userVisibleUrlForDomainIdentifier(domainIdentifier);

if (url.isEmpty()) {
return;
}

[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:@[[NSURL fileURLWithPath:url.toNSString()]]];
}

void FileProviderDomainManager::slotHandleFileIdsChanged(const OCC::Account * const account, const QList<qint64> &fileIds)
{
// NOTE: The fileIds argument is ignored for now but retained in the signature for future use.
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/TrayFoldersMenuButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HeaderButton {
}
}

visible: currentUser.hasLocalFolder
visible: currentUser.hasLocalFolder || (Qt.platform.os === "osx" && currentUser.hasFileProvider)
display: AbstractButton.IconOnly
flat: true

Expand Down
22 changes: 19 additions & 3 deletions src/gui/tray/TrayWindowHeader.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,33 @@ Rectangle {
Layout.preferredWidth: Style.trayWindowHeaderHeight
Layout.fillHeight: true

visible: currentUser.hasLocalFolder
visible: currentUser.hasLocalFolder || (Qt.platform.os === "osx" && currentUser.hasFileProvider)
currentUser: UserModel.currentUser
parentBackgroundColor: root.color

onClicked: openLocalFolderButton.userHasGroupFolders ? openLocalFolderButton.toggleMenuOpen() : UserModel.openCurrentAccountLocalFolder()
onClicked: {
if (openLocalFolderButton.userHasGroupFolders) {
openLocalFolderButton.toggleMenuOpen()
} else if (currentUser.hasLocalFolder) {
UserModel.openCurrentAccountLocalFolder()
} else if (Qt.platform.os === "osx") {
UserModel.openCurrentAccountFileProviderDomain()
}
}

onFolderEntryTriggered: isGroupFolder ? UserModel.openCurrentAccountFolderFromTrayInfo(fullFolderPath) : UserModel.openCurrentAccountLocalFolder()

Accessible.role: Accessible.Graphic
Accessible.name: qsTr("Open local or group folders")
Accessible.onPressAction: openLocalFolderButton.userHasGroupFolders ? openLocalFolderButton.toggleMenuOpen() : UserModel.openCurrentAccountLocalFolder()
Accessible.onPressAction: {
if (openLocalFolderButton.userHasGroupFolders) {
openLocalFolderButton.toggleMenuOpen()
} else if (currentUser.hasLocalFolder) {
UserModel.openCurrentAccountLocalFolder()
} else if (Qt.platform.os === "osx") {
UserModel.openCurrentAccountFileProviderDomain()
}
}
}

HeaderButton {
Expand Down
32 changes: 32 additions & 0 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/

Check warning on line 4 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s358&open=AZ2a2VRpqEJ0bSB3s358&pullRequest=9857

#include "notificationhandler.h"
#include "usermodel.h"
Expand Down Expand Up @@ -117,7 +117,7 @@
if (nestedOutput.isObject()) {
const auto nestedObject = nestedOutput.toObject();
const auto textValue = nestedObject.value("text"_L1);
if (textValue.isString()) {

Check warning on line 120 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36F&open=AZ2a2VRpqEJ0bSB3s36F&pullRequest=9857
return textValue.toString();
}
const auto answerValue = nestedObject.value("answer"_L1);
Expand All @@ -127,7 +127,7 @@
}

const auto textValue = outputObject.value("text"_L1);
if (textValue.isString()) {

Check warning on line 130 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36E&open=AZ2a2VRpqEJ0bSB3s36E&pullRequest=9857
return textValue.toString();
}
const auto answerValue = outputObject.value("answer"_L1);
Expand Down Expand Up @@ -176,7 +176,7 @@

const auto state = determineSyncStatus(folder->syncResult());

switch (state) {

Check failure on line 179 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a "default" case to this switch statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36G&open=AZ2a2VRpqEJ0bSB3s36G&pullRequest=9857
case OCC::SyncResult::Error:
case OCC::SyncResult::SetupError:
hasError = true;
Expand Down Expand Up @@ -217,7 +217,7 @@

bool isSyncStatusError(const OCC::SyncResult::Status status)
{
switch (status) {

Check failure on line 220 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a "default" case to this switch statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36H&open=AZ2a2VRpqEJ0bSB3s36H&pullRequest=9857
case OCC::SyncResult::Error:
case OCC::SyncResult::SetupError:
case OCC::SyncResult::Problem:
Expand Down Expand Up @@ -274,7 +274,7 @@
this, &User::slotCheckExpiredActivities);

connect(_account.data(), &AccountState::stateChanged,
[=, this]() { if (isConnected()) {slotRefreshImmediately();} });

Check failure on line 277 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture the required scope variables.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36I&open=AZ2a2VRpqEJ0bSB3s36I&pullRequest=9857
connect(_account.data(), &AccountState::stateChanged, this, &User::accountStateChanged);
connect(_account.data(), &AccountState::hasFetchedNavigationApps,
this, &User::slotRebuildNavigationAppList);
Expand Down Expand Up @@ -322,7 +322,7 @@
connect(&_assistantPollTimer, &QTimer::timeout, this, &User::slotAssistantPoll);

const auto folderMan = FolderMan::instance();
connect(folderMan, &FolderMan::folderSyncStateChange, this, [this](const Folder *folder) {

Check warning on line 325 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "folder" of type "const class OCC::Folder *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36J&open=AZ2a2VRpqEJ0bSB3s36J&pullRequest=9857
if (!folder || folder->accountState() == _account.data()) {
updateSyncStatus();
}
Expand Down Expand Up @@ -384,7 +384,7 @@

void User::showDesktopNotification(const ActivityList &activityList)
{
const auto subject = tr("%n notification(s)", nullptr, activityList.count());

Check warning on line 387 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s359&open=AZ2a2VRpqEJ0bSB3s359&pullRequest=9857
const auto notificationId = -static_cast<int>(qHash(subject));

if (!canShowNotification(notificationId)) {
Expand Down Expand Up @@ -439,7 +439,7 @@

_activityModel->removeOutdatedNotifications(list);

std::copy_if(list.constBegin(), list.constEnd(), std::back_inserter(toNotifyList), [&](const Activity &activity) -> bool {

Check warning on line 442 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the redundant return type of this lambda.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36K&open=AZ2a2VRpqEJ0bSB3s36K&pullRequest=9857
if (!activity._shouldNotify) {
qCDebug(lcActivity).nospace() << "No notification should be sent for activity with id=" << activity._id << " objectType=" << activity._objectType;
return false;
Expand Down Expand Up @@ -537,7 +537,7 @@
setNotificationRefreshInterval(ConfigFile().notificationRefreshInterval());
}

void User::slotReceivedPushFilesChanges(Account *account)

Check warning on line 540 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "account" is "class OCC::Account *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36L&open=AZ2a2VRpqEJ0bSB3s36L&pullRequest=9857

Check warning on line 540 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "account" of type "class OCC::Account *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36M&open=AZ2a2VRpqEJ0bSB3s36M&pullRequest=9857
{
if (account->id() != _account->account()->id()) {
return;
Expand All @@ -555,7 +555,7 @@
#endif
}

void User::slotReceivedPushFileIdsChanges(Account *account, const QList<qint64> &fileIds)

Check warning on line 558 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "account" is "class OCC::Account *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36N&open=AZ2a2VRpqEJ0bSB3s36N&pullRequest=9857

Check warning on line 558 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "account" of type "class OCC::Account *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRpqEJ0bSB3s36O&open=AZ2a2VRpqEJ0bSB3s36O&pullRequest=9857
{
if (account->id() != _account->account()->id()) {
return;
Expand Down Expand Up @@ -1074,7 +1074,7 @@
if(activity._fileAction != "file_deleted" && !item->isEmpty()) {
const auto localFiles = FolderMan::instance()->findFileInLocalFolders(folder->remotePathTrailingSlash() + item->_file, account());
if (!localFiles.isEmpty()) {
const auto firstFilePath = localFiles.constFirst();

Check warning on line 1077 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s36P&open=AZ2a2VRpqEJ0bSB3s36P&pullRequest=9857
const auto itemJournalRecord = item->toSyncJournalFileRecordWithInode(firstFilePath);

if(!itemJournalRecord.isVirtualFile()) {
Expand Down Expand Up @@ -1199,6 +1199,21 @@
}
}

#ifdef BUILD_FILE_PROVIDER_MODULE
void User::openFileProviderDomain() const
{
const auto domainIdentifier = _account->account()->fileProviderDomainIdentifier();
if (domainIdentifier.isEmpty()) {
return;
}
const auto domainManager = Mac::FileProvider::instance()->domainManager();
if (!domainManager) {
return;
}
domainManager->openFileViewerForDomainIdentifier(domainIdentifier);
}
#endif

void User::openFolderLocallyOrInBrowser(const QString &fullRemotePath)
{
const auto folder = getFolder();
Expand Down Expand Up @@ -1337,6 +1352,13 @@
return getFolder() != nullptr;
}

#ifdef BUILD_FILE_PROVIDER_MODULE
bool User::hasFileProvider() const
{
return !_account->account()->fileProviderDomainIdentifier().isEmpty();
}
#endif

bool User::serverHasTalk() const
{
return talkApp() != nullptr;
Expand Down Expand Up @@ -1587,7 +1609,7 @@
_assistantConnector->fetchTasks(_assistantTaskType);
}

void User::slotAssistantTaskTypesFetched(const QJsonDocument &json, int statusCode)

Check warning on line 1612 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s36R&open=AZ2a2VRpqEJ0bSB3s36R&pullRequest=9857
{
if (statusCode < assistantSuccessMinStatusCode || statusCode >= assistantSuccessMaxStatusCode) {
slotAssistantRequestError(QStringLiteral("taskTypes"), statusCode);
Expand Down Expand Up @@ -1622,7 +1644,7 @@
_assistantConnector->scheduleTask(_assistantQuestion, _assistantTaskType, history);
}

void User::slotAssistantTasksFetched(const QJsonDocument &json, int statusCode)

Check warning on line 1647 in src/gui/tray/usermodel.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=AZ2a2VRqqEJ0bSB3s36S&open=AZ2a2VRqqEJ0bSB3s36S&pullRequest=9857
{
if (statusCode < assistantSuccessMinStatusCode || statusCode >= assistantSuccessMaxStatusCode) {
slotAssistantRequestError(QStringLiteral("tasks"), statusCode);
Expand Down Expand Up @@ -1670,7 +1692,7 @@
}
}

void User::slotAssistantTaskScheduled(const QJsonDocument &json, int statusCode)

Check warning on line 1695 in src/gui/tray/usermodel.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=AZ2a2VRqqEJ0bSB3s36T&open=AZ2a2VRqqEJ0bSB3s36T&pullRequest=9857
{
if (statusCode < assistantSuccessMinStatusCode || statusCode >= assistantSuccessMaxStatusCode) {
slotAssistantRequestError(QStringLiteral("schedule"), statusCode);
Expand All @@ -1687,7 +1709,7 @@
}
}

void User::slotAssistantTaskDeleted(int statusCode)

Check warning on line 1712 in src/gui/tray/usermodel.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=AZ2a2VRqqEJ0bSB3s36U&open=AZ2a2VRqqEJ0bSB3s36U&pullRequest=9857
{
if (statusCode >= assistantSuccessMinStatusCode && statusCode < assistantSuccessMaxStatusCode) {
return;
Expand All @@ -1695,7 +1717,7 @@
slotAssistantRequestError(QStringLiteral("deleteTask"), statusCode);
}

void User::slotAssistantRequestError(const QString &context, int statusCode)

Check warning on line 1720 in src/gui/tray/usermodel.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=AZ2a2VRqqEJ0bSB3s36V&open=AZ2a2VRqqEJ0bSB3s36V&pullRequest=9857
{
_assistantPollTimer.stop();
_assistantRequestInProgress = false;
Expand Down Expand Up @@ -1747,7 +1769,7 @@
return;
}

int64_t total = usedBytes + availableBytes;

Check warning on line 1772 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "total" of type "long" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36W&open=AZ2a2VRqqEJ0bSB3s36W&pullRequest=9857
if (total <= 0 || !ConfigFile().showQuotaWarningNotifications()) {
return;
}
Expand Down Expand Up @@ -1823,11 +1845,11 @@
const auto mountPoint = groupFolderInfo.value(QStringLiteral("mount_point"), {}).toString();
parseNewGroupFolderPath(mountPoint);
}
std::sort(std::begin(_trayFolderInfos), std::end(_trayFolderInfos), [](const auto &leftVariant, const auto &rightVariant) {
const auto folderInfoA = leftVariant.template value<TrayFolderInfo>();
const auto folderInfoB = rightVariant.template value<TrayFolderInfo>();
return folderInfoA._fullPath < folderInfoB._fullPath;
});

Check warning on line 1852 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::sort" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36X&open=AZ2a2VRqqEJ0bSB3s36X&pullRequest=9857

if (!_trayFolderInfos.isEmpty()) {
if (hasLocalFolder()) {
Expand Down Expand Up @@ -1865,7 +1887,7 @@
: QAbstractListModel(parent)
{
if (AccountManager::instance()->accounts().size() > 0) {
setInitialUser();

Check failure on line 1890 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This call leads to the invocation of "UserModel::rowCount" that doesn't consider overrides in subclasses. Ensure the code unambiguously uses the desired function.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36Y&open=AZ2a2VRqqEJ0bSB3s36Y&pullRequest=9857
}

const auto folderMan = FolderMan::instance();
Expand Down Expand Up @@ -1907,7 +1929,7 @@
buildUserList();

if(!_users.isEmpty()) {
ConfigFile cfg;

Check warning on line 1932 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "cfg" of type "class OCC::ConfigFile" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36Z&open=AZ2a2VRqqEJ0bSB3s36Z&pullRequest=9857
const uint lastSelectedAccountId = cfg.lastSelectedAccount();

for (int i = 0; i < _users.size(); i++) {
Expand All @@ -1926,7 +1948,7 @@

int UserModel::numUsers()
{
return _users.size();

Check warning on line 1951 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s35-&open=AZ2a2VRpqEJ0bSB3s35-&pullRequest=9857
}

int UserModel::currentUserId() const
Expand All @@ -1949,7 +1971,7 @@

int UserModel::syncErrorUserCount() const
{
return _syncErrorUserIds.size();

Check warning on line 1974 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s35_&open=AZ2a2VRpqEJ0bSB3s35_&pullRequest=9857
}

int UserModel::firstSyncErrorUserId() const
Expand All @@ -1969,9 +1991,9 @@

QImage UserModel::avatarById(const int id) const
{
const auto foundUserByIdIter = std::find_if(std::cbegin(_users), std::cend(_users), [&id](const OCC::User* const user) {
return user->account()->id() == QString::number(id);
});

Check warning on line 1996 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::find_if" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36a&open=AZ2a2VRqqEJ0bSB3s36a&pullRequest=9857

if (foundUserByIdIter == std::cend(_users)) {
return {};
Expand Down Expand Up @@ -2031,7 +2053,7 @@

_users << u;
if (isCurrent || (_currentUserId < 0 && !_init)) {
setCurrentUserId(_users.size() - 1);

Check warning on line 2056 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s36A&open=AZ2a2VRpqEJ0bSB3s36A&pullRequest=9857
}

endInsertRows();
Expand All @@ -2056,6 +2078,16 @@
_users[_currentUserId]->openLocalFolder();
}

#ifdef BUILD_FILE_PROVIDER_MODULE
void UserModel::openCurrentAccountFileProviderDomain()
{
if (_currentUserId < 0 || _currentUserId >= _users.size())
return;

_users[_currentUserId]->openFileProviderDomain();
}
#endif

void UserModel::openCurrentAccountServer()
{
if (_currentUserId < 0 || _currentUserId >= _users.size())
Expand All @@ -2078,7 +2110,7 @@
_users[_currentUserId]->openFolderLocallyOrInBrowser(fullRemotePath);
}

void UserModel::openCurrentAccountFeaturedApp()

Check warning on line 2113 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function should be declared "const".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36b&open=AZ2a2VRqqEJ0bSB3s36b&pullRequest=9857
{
if (!currentUser()) {
return;
Expand Down Expand Up @@ -2174,7 +2206,7 @@
endRemoveRows();

if (_users.size() <= 1) {
setCurrentUserId(_users.size() - 1);

Check warning on line 2209 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s36B&open=AZ2a2VRpqEJ0bSB3s36B&pullRequest=9857
} else if (currentUserId() > id) {
// an account was removed from the in-between 0 and the current one, the index of the current one needs a decrement
setCurrentUserId(currentUserId() - 1);
Expand All @@ -2197,13 +2229,13 @@
int UserModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return _users.count();

Check warning on line 2232 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s36C&open=AZ2a2VRpqEJ0bSB3s36C&pullRequest=9857
}

QVariant UserModel::data(const QModelIndex &index, int role) const
{
auto result = QVariant{};
switch (static_cast<UserRoles>(role))

Check failure on line 2238 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a "default" case to this switch statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36c&open=AZ2a2VRqqEJ0bSB3s36c&pullRequest=9857
{
case NameRole:
result = _users[index.row()]->name();
Expand Down Expand Up @@ -2316,9 +2348,9 @@
{
Q_ASSERT(account);

const auto it = std::find_if(_users.cbegin(), _users.cend(), [account](const User *user) {
return user->account()->id() == account->account()->id();
});

Check warning on line 2353 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::find_if" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36d&open=AZ2a2VRqqEJ0bSB3s36d&pullRequest=9857

if (it == _users.cend()) {
return nullptr;
Expand All @@ -2329,9 +2361,9 @@

int UserModel::findUserIdForAccount(AccountState *account) const
{
const auto it = std::find_if(std::cbegin(_users), std::cend(_users), [=](const User *user) {
return user->account()->id() == account->account()->id();
});

Check warning on line 2366 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::find_if" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36e&open=AZ2a2VRqqEJ0bSB3s36e&pullRequest=9857

if (it == std::cend(_users)) {
return -1;
Expand All @@ -2341,7 +2373,7 @@
return id;
}

bool UserModel::userHasSyncErrors(const User *user) const

Check warning on line 2376 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "user" of type "const class OCC::User *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36f&open=AZ2a2VRqqEJ0bSB3s36f&pullRequest=9857
{
if (!user) {
return false;
Expand All @@ -2352,7 +2384,7 @@
return false;
}

for (const auto folder : FolderMan::instance()->map().values()) {

Check warning on line 2387 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this range for-loop by "std::ranges::any_of".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36g&open=AZ2a2VRqqEJ0bSB3s36g&pullRequest=9857
if (folder->accountState() != accountState.data()) {
continue;
}
Expand Down Expand Up @@ -2394,7 +2426,7 @@
class ImageResponse : public QQuickImageResponse
{
public:
ImageResponse(const QString &id, const QSize &requestedSize, QThreadPool *pool)

Check warning on line 2429 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "pool" is "class QThreadPool *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36h&open=AZ2a2VRqqEJ0bSB3s36h&pullRequest=9857

Check warning on line 2429 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "pool" of type "class QThreadPool *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36i&open=AZ2a2VRqqEJ0bSB3s36i&pullRequest=9857
{
Q_UNUSED(pool)

Expand All @@ -2419,8 +2451,8 @@
// Format is "image://avatars/user-id=avatar-requested-user/local-user-id:0"
const auto userIdsString = id.split('=');
const auto userIds = userIdsString.last().split("/local-account:");
const auto avatarUserId = userIds.first();

Check warning on line 2454 in src/gui/tray/usermodel.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=AZ2a2VRqqEJ0bSB3s36j&open=AZ2a2VRqqEJ0bSB3s36j&pullRequest=9857
const auto accountString = userIds.last();

Check warning on line 2455 in src/gui/tray/usermodel.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=AZ2a2VRqqEJ0bSB3s36k&open=AZ2a2VRqqEJ0bSB3s36k&pullRequest=9857
const auto accountState = AccountManager::instance()->account(accountString);
Q_ASSERT(accountState);
Q_ASSERT(accountState->account());
Expand All @@ -2434,8 +2466,8 @@

QMetaObject::invokeMethod(qnam, [this, requestedSize, avatarUserId, account]() {
const auto avatarSize = requestedSize.width() > 0 ? requestedSize.width() : 64;
const auto avatarJob = new AvatarJob(account, avatarUserId, avatarSize);

Check failure on line 2469 in src/gui/tray/usermodel.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=AZ2a2VRqqEJ0bSB3s36l&open=AZ2a2VRqqEJ0bSB3s36l&pullRequest=9857
connect(avatarJob, &AvatarJob::avatarPixmap, this, [&](const QImage &avatarImg) {

Check failure on line 2470 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture the required scope variables.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36m&open=AZ2a2VRqqEJ0bSB3s36m&pullRequest=9857

Check failure on line 2470 in src/gui/tray/usermodel.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Explicitly capture all local variables required in this lambda.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VRqqEJ0bSB3s36n&open=AZ2a2VRqqEJ0bSB3s36n&pullRequest=9857
QMetaObject::invokeMethod(this, [this, avatarImg] {
handleDone(AvatarJob::makeCircularAvatar(avatarImg));
});
Expand Down Expand Up @@ -2518,7 +2550,7 @@
int UserAppsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return _apps.count();

Check warning on line 2553 in src/gui/tray/usermodel.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=AZ2a2VRpqEJ0bSB3s36D&open=AZ2a2VRpqEJ0bSB3s36D&pullRequest=9857
}

QVariant UserAppsModel::data(const QModelIndex &index, int role) const
Expand Down
12 changes: 12 additions & 0 deletions src/gui/tray/usermodel.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
*/

Check warning on line 4 in src/gui/tray/usermodel.h

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=AZ2a2VINqEJ0bSB3s353&open=AZ2a2VINqEJ0bSB3s353&pullRequest=9857

#ifndef USERMODEL_H
#define USERMODEL_H

#include <QAbstractListModel>

Check failure on line 9 in src/gui/tray/usermodel.h

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.h:9:10 [clang-diagnostic-error]

'QAbstractListModel' file not found
#include <QImage>
#include <QDateTime>
#include <QJsonDocument>
Expand Down Expand Up @@ -53,7 +53,7 @@
FolderType _folderType = Folder;
};

class User : public QObject

Check warning on line 56 in src/gui/tray/usermodel.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this structure so it has no more than 20 fields, rather than the 30 it currently has.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VINqEJ0bSB3s354&open=AZ2a2VINqEJ0bSB3s354&pullRequest=9857
{
Q_OBJECT
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Expand All @@ -68,6 +68,9 @@
Q_PROPERTY(QString statusMessage READ statusMessage NOTIFY statusChanged)
Q_PROPERTY(bool desktopNotificationsAllowed READ isDesktopNotificationsAllowed NOTIFY desktopNotificationsAllowedChanged)
Q_PROPERTY(bool hasLocalFolder READ hasLocalFolder NOTIFY hasLocalFolderChanged)
#ifdef BUILD_FILE_PROVIDER_MODULE
Q_PROPERTY(bool hasFileProvider READ hasFileProvider NOTIFY accountStateChanged)
#endif
Q_PROPERTY(bool isFeaturedAppEnabled READ isFeaturedAppEnabled NOTIFY featuredAppChanged)
Q_PROPERTY(QString featuredAppIcon READ featuredAppIcon NOTIFY featuredAppChanged)
Q_PROPERTY(QString featuredAppAccessibleName READ featuredAppAccessibleName NOTIFY featuredAppChanged)
Expand All @@ -87,7 +90,7 @@
Q_PROPERTY(bool assistantRequestInProgress READ assistantRequestInProgress NOTIFY assistantRequestInProgressChanged)

public:
User(AccountStatePtr &account, const bool &isCurrent = false, QObject *parent = nullptr);

Check failure on line 93 in src/gui/tray/usermodel.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add the "explicit" keyword to this constructor.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VINqEJ0bSB3s355&open=AZ2a2VINqEJ0bSB3s355&pullRequest=9857

[[nodiscard]] AccountPtr account() const;
[[nodiscard]] AccountStatePtr accountState() const;
Expand All @@ -100,10 +103,16 @@
ActivityListModel *getActivityModel();
[[nodiscard]] UnifiedSearchResultsListModel *getUnifiedSearchResultsListModel() const;
void openLocalFolder() const;
#ifdef BUILD_FILE_PROVIDER_MODULE
void openFileProviderDomain() const;
#endif
void openFolderLocallyOrInBrowser(const QString &fullRemotePath);
[[nodiscard]] QString name() const;
[[nodiscard]] QString server(bool shortened = true) const;
[[nodiscard]] bool hasLocalFolder() const;
#ifdef BUILD_FILE_PROVIDER_MODULE
[[nodiscard]] bool hasFileProvider() const;
#endif
[[nodiscard]] bool isFeaturedAppEnabled() const;
[[nodiscard]] QString featuredAppIcon() const;
[[nodiscard]] QString featuredAppAccessibleName() const;
Expand Down Expand Up @@ -159,7 +168,7 @@
void assistantResponseChanged();
void assistantErrorChanged();
void assistantMessagesChanged();
void assistantRequestInProgressChanged();

Check warning on line 171 in src/gui/tray/usermodel.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this identifier to be shorter or equal to 31 characters.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VINqEJ0bSB3s356&open=AZ2a2VINqEJ0bSB3s356&pullRequest=9857

public slots:
void slotItemCompleted(const QString &folder, const OCC::SyncFileItemPtr &item);
Expand Down Expand Up @@ -245,7 +254,7 @@
// no query for notifications is started.
int _notificationRequestsRunning = 0;

int _lastTalkNotificationsReceivedCount = 0;

Check warning on line 257 in src/gui/tray/usermodel.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this identifier to be shorter or equal to 31 characters.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ2a2VINqEJ0bSB3s357&open=AZ2a2VINqEJ0bSB3s357&pullRequest=9857

bool _isNotificationFetchRunning = false;

Expand Down Expand Up @@ -338,6 +347,9 @@
public slots:
void fetchCurrentActivityModel();
void openCurrentAccountLocalFolder();
#ifdef BUILD_FILE_PROVIDER_MODULE
void openCurrentAccountFileProviderDomain();
#endif
void openCurrentAccountServer();
void openCurrentAccountFolderFromTrayInfo(const QString &fullRemotePath);
void openCurrentAccountFeaturedApp();
Expand Down
Loading