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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ if(BUILD_CLIENT)
endif()
endif()

if (LINUX)
find_package(KF6DBusAddons)
endif()

option(BUILD_WITH_WEBENGINE "BUILD_WITH_WEBENGINE" ON)
if (BUILD_WITH_WEBENGINE)
find_package(Qt${QT_VERSION_MAJOR}WebEngineCore ${REQUIRED_QT_VERSION} CONFIG QUIET)
Expand Down
1 change: 1 addition & 0 deletions NEXTCLOUD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ set( APPLICATION_ICON_SET "SVG" )
set( APPLICATION_SERVER_URL "" CACHE STRING "URL for the server to use. If entered, the UI field will be pre-filled with it" )
set( APPLICATION_SERVER_URL_ENFORCE ON ) # If set and APPLICATION_SERVER_URL is defined, the server can only connect to the pre-defined URL
set( APPLICATION_REV_DOMAIN "com.nextcloud.desktopclient" )
set( APPLICATION_REV_DOMAIN_DBUS "desktopclient.nextcloud.com" )
set( DEVELOPMENT_TEAM "NKUJUXUJ3B" CACHE STRING "Apple Development Team ID" )
set( APPLICATION_VIRTUALFILE_SUFFIX "nextcloud" CACHE STRING "Virtual file suffix (not including the .)")
set( APPLICATION_OCSP_STAPLING_ENABLED OFF )
Expand Down
4 changes: 4 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#cmakedefine APPLICATION_VENDOR "@APPLICATION_VENDOR@"
#cmakedefine APPLICATION_DOMAIN "@APPLICATION_DOMAIN@"
#cmakedefine APPLICATION_REV_DOMAIN "@APPLICATION_REV_DOMAIN@"
#cmakedefine APPLICATION_REV_DOMAIN_DBUS "@APPLICATION_REV_DOMAIN_DBUS@"
#cmakedefine APPLICATION_SHORTNAME "@APPLICATION_SHORTNAME@"
#cmakedefine APPLICATION_EXECUTABLE "@APPLICATION_EXECUTABLE@"
#cmakedefine APPLICATION_CONFIG_NAME "@APPLICATION_CONFIG_NAME@"
Expand All @@ -24,6 +25,7 @@
#cmakedefine APPLICATION_SERVER_URL R"(@APPLICATION_SERVER_URL@)"
#cmakedefine APPLICATION_SERVER_URL_ENFORCE "@APPLICATION_SERVER_URL_ENFORCE@"
#cmakedefine LINUX_APPLICATION_ID "@LINUX_APPLICATION_ID@"
#cmakedefine LINUX_PACKAGE_SHORTNAME "@LINUX_PACKAGE_SHORTNAME@"
#cmakedefine APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "@APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR@"
#cmakedefine NEXTCLOUD_BACKGROUND_COLOR "@NEXTCLOUD_BACKGROUND_COLOR@"
#cmakedefine APPLICATION_WIZARD_HEADER_TITLE_COLOR "@APPLICATION_WIZARD_HEADER_TITLE_COLOR@"
Expand Down Expand Up @@ -65,6 +67,8 @@

#cmakedefine01 NEXTCLOUD_DEV

#cmakedefine01 KF6DBusAddons_FOUND

#cmakedefine WITH_WEBENGINE

#cmakedefine01 CLIENTSIDEENCRYPTION_ENFORCE_USB_TOKEN
Expand Down
29 changes: 0 additions & 29 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
QString Utility::formatFingerprint(const QByteArray &fmhash, bool colonSeparated)
{
QByteArray hash;
int steps = fmhash.length() / 2;

Check warning on line 78 in src/common/utility.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=AZ5zxw8u4zARl5cMgvHO&open=AZ5zxw8u4zARl5cMgvHO&pullRequest=10088
for (int i = 0; i < steps; i++) {
hash.append(fmhash[i * 2]);
hash.append(fmhash[i * 2 + 1]);
Expand All @@ -94,7 +94,7 @@
QString Utility::octetsToString(const qint64 octets)
{
auto unitName = QCoreApplication::translate("Utility", "%L1 B");
qreal dataSize = octets;

Check warning on line 97 in src/common/utility.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

implicit conversion from 'const qint64' (aka 'const long long') to 'qreal' (aka 'double') may lose precision

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

// Display decimals when value < TB and unit < 10
auto showDecimals = true;
Expand Down Expand Up @@ -386,35 +386,6 @@
return static_cast<int>(convertVar);
}

// read the output of the owncloud --version command from the owncloud
// version that is on disk. This works for most versions of the client,
// because clients that do not yet know the --version flag return the
// version in the first line of the help output :-)
//
// This version only delivers output on linux, as Mac and Win get their
// restarting from the installer.
QByteArray Utility::versionOfInstalledBinary(const QString &command)
{
QByteArray re;
if (isLinux()) {
QString binary(command);
if (binary.isEmpty()) {
binary = qApp->arguments()[0];
}
QStringList params;
params << QStringLiteral("--version");
QProcess process;
process.start(binary, params);
process.waitForFinished(); // sets current thread to sleep and waits for pingProcess end
re = process.readAllStandardOutput();
int newline = re.indexOf('\n');
if (newline > 0) {
re.truncate(newline);
}
}
return re;
}

QString Utility::timeAgoInWords(const QDateTime &dt, const QDateTime &from)
{
QDateTime now = QDateTime::currentDateTimeUtc();
Expand Down Expand Up @@ -512,7 +483,7 @@
QCollator collator;
collator.setNumericMode(true);
collator.setCaseSensitivity(Qt::CaseInsensitive);
std::sort(fileNames.begin(), fileNames.end(), collator);

Check warning on line 486 in src/common/utility.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=AZ5zxw8u4zARl5cMgvHS&open=AZ5zxw8u4zARl5cMgvHS&pullRequest=10088
}

QUrl Utility::concatUrlPath(const QUrl &url, const QString &concatPath,
Expand Down Expand Up @@ -541,13 +512,13 @@
{
QString conflictFileName(fn);
// Add conflict tag before the extension.
int dotLocation = conflictFileName.lastIndexOf(QLatin1Char('.'));

Check warning on line 515 in src/common/utility.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=AZ5zxw8u4zARl5cMgvHQ&open=AZ5zxw8u4zARl5cMgvHQ&pullRequest=10088
// If no extension, add it at the end (take care of cases like foo/.hidden or foo.bar/file)
if (dotLocation <= conflictFileName.lastIndexOf(QLatin1Char('/')) + 1) {
dotLocation = conflictFileName.size();
}

QString conflictMarker = QStringLiteral(" (conflicted copy ");

Check warning on line 521 in src/common/utility.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw8u4zARl5cMgvHT&open=AZ5zxw8u4zARl5cMgvHT&pullRequest=10088
if (!user.isEmpty()) {
// Don't allow parens in the user name, to ensure
// we can find the beginning and end of the conflict tag.
Expand All @@ -562,7 +533,7 @@

bool Utility::isConflictFile(const QString &name)
{
auto bname = name.mid(name.lastIndexOf(QLatin1Char('/')) + 1);

Check warning on line 536 in src/common/utility.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "bname" of type "class QString" should be const-qualified.

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

if (bname.contains(QStringLiteral("_conflict-"))) {
return true;
Expand Down Expand Up @@ -692,9 +663,9 @@
return path.size() > 1 && path.endsWith(slash) ? path.chopped(1) : path;
}

QString Utility::fullRemotePathToRemoteSyncRootRelative(const QString &fullRemotePath, const QString &remoteSyncRoot)

Check warning on line 666 in src/common/utility.cpp

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=AZ5zxw8u4zARl5cMgvHV&open=AZ5zxw8u4zARl5cMgvHV&pullRequest=10088
{
const auto remoteSyncRootNoLeadingSlashWithTrailingSlash = Utility::trailingSlashPath(noLeadingSlashPath(remoteSyncRoot));

Check warning on line 668 in src/common/utility.cpp

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=AZ5zxw8u4zARl5cMgvHW&open=AZ5zxw8u4zARl5cMgvHW&pullRequest=10088
const auto fullRemotePathNoLeadingSlash = noLeadingSlashPath(fullRemotePath);

if (remoteSyncRootNoLeadingSlashWithTrailingSlash == QStringLiteral("/")) {
Expand Down
7 changes: 0 additions & 7 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
ulong processId;
QString processName;
};
/**
* @brief Queries the OS for processes that are keeping the file open(using it)
*
* @param filePath absolute file path
* @return list of ProcessInfosForOpenFile
*/

Check warning on line 49 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHX&open=AZ5zxxCy4zARl5cMgvHX&pullRequest=10088
OCSYNC_EXPORT QVector<ProcessInfosForOpenFile> queryProcessInfosKeepingFileOpen(const QString &filePath);

Check warning on line 50 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHe&open=AZ5zxxCy4zARl5cMgvHe&pullRequest=10088

#ifdef Q_OS_WIN
class OCSYNC_EXPORT Handle
Expand Down Expand Up @@ -98,11 +98,11 @@
OCSYNC_EXPORT void sleep(int sec);
OCSYNC_EXPORT void usleep(int usec);
OCSYNC_EXPORT QString formatFingerprint(const QByteArray &, bool colonSeparated = true);
/**
* @brief Create favorite link for sync folder with application name and icon
*
* @param folder absolute file path to folder
*/

Check warning on line 105 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHY&open=AZ5zxxCy4zARl5cMgvHY&pullRequest=10088
OCSYNC_EXPORT void setupFavLink(const QString &folder);
/**
* @brief Migrate favorite link for sync folder with new application name and icon
Expand All @@ -110,26 +110,26 @@
* @param folder absolute file path to folder
*/
OCSYNC_EXPORT void migrateFavLink(const QString &folder);
/**
* @brief Creates or overwrite the Desktop.ini file to use new folder IconResource shown as a favorite link
*
* @param folder absolute file path to folder
* @param localizedResourceName new folder name to be used as display name (migration)
*/

Check warning on line 118 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHa&open=AZ5zxxCy4zARl5cMgvHa&pullRequest=10088
OCSYNC_EXPORT void setupDesktopIni(const QString &folder, const QString localizedResourceName = {});
/**
* @brief Removes the Desktop.ini file which contains the folder IconResource shown as a favorite link
*
* @param folder absolute file path to folder
*/

Check warning on line 124 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHb&open=AZ5zxxCy4zARl5cMgvHb&pullRequest=10088
OCSYNC_EXPORT void removeFavLink(const QString &folder);
/**
* @brief Return the display name of a folder - to be used in fav links and sync root name (VFS).x
* e.g. Nextcloud1 will become NewAppName1, NewAppName2 or FolderName will be kept as is.
*
* @param currentDisplayName current folder display name string
* @param newName new name to be used for the folder
*/

Check warning on line 132 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHc&open=AZ5zxxCy4zARl5cMgvHc&pullRequest=10088
OCSYNC_EXPORT QString syncFolderDisplayName(const QString &currentDisplayName, const QString &newName);

// convenience system path to links folder
Expand All @@ -150,7 +150,7 @@
OCSYNC_EXPORT bool hasSystemLaunchOnStartup(const QString &appName);
OCSYNC_EXPORT bool hasLaunchOnStartup(const QString &appName);
OCSYNC_EXPORT void setLaunchOnStartup(const QString &appName, const QString &guiName, const bool launch);
/** On macOS, returns true when the login item is registered but awaiting user approval

Check warning on line 153 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHd&open=AZ5zxxCy4zARl5cMgvHd&pullRequest=10088
* in System Settings → General → Login Items. Always returns false on other platforms. */
OCSYNC_EXPORT bool launchOnStartupRequiresApproval();
OCSYNC_EXPORT uint convertSizeToUint(size_t &convertVar);
Expand Down Expand Up @@ -232,13 +232,6 @@
// case sensitivity.
OCSYNC_EXPORT bool fileNamesEqual(const QString &fn1, const QString &fn2);

// Call the given command with the switch --version and rerun the first line
// of the output.
// If command is empty, the function calls the running application which, on
// Linux, might have changed while this one is running.
// For Mac and Windows, it returns QString()
OCSYNC_EXPORT QByteArray versionOfInstalledBinary(const QString &command = QString());

OCSYNC_EXPORT QString fileNameForGuiUse(const QString &fName);

OCSYNC_EXPORT QByteArray normalizeEtag(QByteArray etag);
Expand Down Expand Up @@ -341,7 +334,7 @@
OCSYNC_EXPORT QString trailingSlashPath(const QString &path);
OCSYNC_EXPORT QString noLeadingSlashPath(const QString &path);
OCSYNC_EXPORT QString noTrailingSlashPath(const QString &path);
OCSYNC_EXPORT QString fullRemotePathToRemoteSyncRootRelative(const QString &fullRemotePath, const QString &remoteSyncRoot);

Check warning on line 337 in src/common/utility.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=AZ5zxxCy4zARl5cMgvHf&open=AZ5zxxCy4zARl5cMgvHf&pullRequest=10088

#ifdef Q_OS_WIN
OCSYNC_EXPORT bool registryKeyExists(HKEY hRootKey, const QString &subKey);
Expand Down Expand Up @@ -416,7 +409,7 @@
#endif
}

inline constexpr bool Utility::isMac()

Check warning on line 412 in src/common/utility.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "constexpr" function should not be declared "inline".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxxCy4zARl5cMgvHh&open=AZ5zxxCy4zARl5cMgvHh&pullRequest=10088
{
#ifdef Q_OS_MACOS
return true;
Expand All @@ -425,7 +418,7 @@
#endif
}

inline constexpr bool Utility::isUnix()

Check warning on line 421 in src/common/utility.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "constexpr" function should not be declared "inline".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxxCy4zARl5cMgvHi&open=AZ5zxxCy4zARl5cMgvHi&pullRequest=10088
{
#ifdef Q_OS_UNIX
return true;
Expand All @@ -434,7 +427,7 @@
#endif
}

inline constexpr bool Utility::isLinux()

Check warning on line 430 in src/common/utility.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "constexpr" function should not be declared "inline".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxxCy4zARl5cMgvHj&open=AZ5zxxCy4zARl5cMgvHj&pullRequest=10088
{
#if defined(Q_OS_LINUX)
return true;
Expand All @@ -443,7 +436,7 @@
#endif
}

inline constexpr bool Utility::isBSD()

Check warning on line 439 in src/common/utility.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

A "constexpr" function should not be declared "inline".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxxCy4zARl5cMgvHk&open=AZ5zxxCy4zARl5cMgvHk&pullRequest=10088
{
#if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD) || defined(Q_OS_OPENBSD)
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ if(KF6GuiAddons_FOUND)
add_definitions(-DHAVE_KGUIADDONS)
endif()

if(KF6DBusAddons_FOUND)
target_link_libraries(nextcloudCore PUBLIC KF6::DBusAddons)
endif()

add_subdirectory(socketapi)

# skip unity inclusion for files which cause problems with a CMake unity build
Expand Down
9 changes: 9 additions & 0 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
{
ConfigFile configFile;
const auto shouldTryToMigrate = configFile.shouldTryToMigrate();
if (!shouldTryToMigrate) {

Check warning on line 128 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvG1&open=AZ5zxw4K4zARl5cMgvG1&pullRequest=10088
qCInfo(lcApplication) << "This is not an upgrade/downgrade/migration. Proceed to read current application config file.";
configFile.setMigrationPhase(ConfigFile::MigrationPhase::Done);
return false;
Expand Down Expand Up @@ -228,6 +228,9 @@
Application::Application(int &argc, char **argv)
: QApplication{argc, argv}
, _gui(nullptr)
#if defined KF6DBusAddons_FOUND && KF6DBusAddons_FOUND
, _dbusService{KDBusService::StartupOption::NoExitOnFailure | KDBusService::StartupOption::Unique}
#endif
, _theme(Theme::instance())
{
_startedAt.start();
Expand Down Expand Up @@ -275,6 +278,12 @@
return;
}

#if defined KF6DBusAddons_FOUND && KF6DBusAddons_FOUND
if (!_dbusService.isRegistered()) {
return;
}
#endif

if (!_singleApp.isPrimaryInstance()) {
return;
}
Expand All @@ -301,7 +310,7 @@
qCDebug(lcApplication) << "Failed to move the old config directory to its new location (" << legacyDir << "to" << confDir << ")";

// Try to move the files one by one
if (QFileInfo(confDir).isDir() || QDir().mkdir(confDir)) {

Check failure on line 313 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this TOCTOU race condition window when accessing files

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvG3&open=AZ5zxw4K4zARl5cMgvG3&pullRequest=10088
const QStringList filesList = QDir(legacyDir).entryList(QDir::Files);
qCDebug(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
Expand All @@ -313,7 +322,7 @@
} else {
#ifndef Q_OS_WIN
// Create a symbolic link so a downgrade of the client would still find the config.
QFile::link(confDir, legacyDir);

Check failure on line 325 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this TOCTOU race condition window when accessing files

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvG2&open=AZ5zxw4K4zARl5cMgvG2&pullRequest=10088
#endif
}
}
Expand All @@ -321,7 +330,7 @@
setupConfigFile();
}

if (_theme->doNotUseProxy()) {

Check warning on line 333 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "->" with "::" for access to "Theme::doNotUseProxy".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvG4&open=AZ5zxw4K4zARl5cMgvG4&pullRequest=10088
ConfigFile().setProxyType(QNetworkProxy::NoProxy);
const auto &allAccounts = AccountManager::instance()->accounts();
for (const auto &accountState : allAccounts) {
Expand Down Expand Up @@ -419,7 +428,7 @@
_gui->setupCloudProviders();
#endif

if (_theme->doNotUseProxy()) {

Check warning on line 431 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "->" with "::" for access to "Theme::doNotUseProxy".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvG5&open=AZ5zxw4K4zARl5cMgvG5&pullRequest=10088
ConfigFile().setProxyType(QNetworkProxy::NoProxy);
const auto &allAccounts = AccountManager::instance()->accounts();
for (const auto &accountState : allAccounts) {
Expand Down Expand Up @@ -609,7 +618,7 @@
const auto foldersRestoreMessage = foldersListSize > 1
? tr("%1 folders", "number of folders imported").arg(QString::number(foldersListSize))
: tr("1 folder");
const auto messageBox = new QMessageBox(QMessageBox::Information,

Check failure on line 621 in src/gui/application.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=AZ5zxw4K4zARl5cMgvG6&open=AZ5zxw4K4zARl5cMgvG6&pullRequest=10088
tr("Legacy import"),
tr("Imported %1 and %2 from a legacy desktop client.\n%3",
"number of accounts and folders imported. list of users.")
Expand All @@ -626,7 +635,7 @@
qCWarning(lcApplication) << accountsListSize << "account(s) migrated:" << prettyNamesList(accounts);
}

void Application::setupConfigFile()

Check warning on line 638 in src/gui/application.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=AZ5zxw4K4zARl5cMgvG7&open=AZ5zxw4K4zARl5cMgvG7&pullRequest=10088
{
// Migrate from version <= 2.4
setApplicationName(_theme->appNameGUI());
Expand Down Expand Up @@ -661,11 +670,11 @@
qCDebug(lcApplication) << "Failed to move the old config directory to its new location (" << oldDir << "to" << confDir << ")";

// Try to move the files one by one
if (QFileInfo(confDir).isDir() || QDir().mkdir(confDir)) {

Check failure on line 673 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this TOCTOU race condition window when accessing files

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvG9&open=AZ5zxw4K4zARl5cMgvG9&pullRequest=10088
const QStringList filesList = QDir(oldDir).entryList(QDir::Files);
qCDebug(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
if (!QFile::rename(oldDir + "/" + name, confDir + "/" + name)) {

Check failure on line 677 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvG8&open=AZ5zxw4K4zARl5cMgvG8&pullRequest=10088
qCDebug(lcApplication) << "Fallback move of " << name << "also failed";
}
}
Expand All @@ -678,7 +687,7 @@
}
}

AccountManager::AccountsRestoreResult Application::restoreLegacyAccount()

Check warning on line 690 in src/gui/application.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=AZ5zxw4K4zARl5cMgvG-&open=AZ5zxw4K4zARl5cMgvG-&pullRequest=10088
{
ConfigFile cfg;
const auto tryMigrate = cfg.overrideServerUrl().isEmpty();
Expand Down Expand Up @@ -757,7 +766,7 @@
// FIXME: This is not ideal yet since a ConnectionValidator might already be running and is in
// progress of timing out in some seconds.
// Maybe we need 2 validators, one triggered by timer, one by network configuration changes?
void Application::slotSystemOnlineConfigurationChanged()

Check warning on line 769 in src/gui/application.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=AZ5zxw4K4zARl5cMgvHB&open=AZ5zxw4K4zARl5cMgvHB&pullRequest=10088

Check warning on line 769 in src/gui/application.cpp

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=AZ5zxw4K4zARl5cMgvHA&open=AZ5zxw4K4zARl5cMgvHA&pullRequest=10088
{
if (QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Site ||
QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online) {
Expand Down Expand Up @@ -951,7 +960,7 @@
}
} else if (option == QStringLiteral("--overrideserverurl")) {
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
const auto overrideUrl = it.next();

Check warning on line 963 in src/gui/application.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=AZ5zxw4K4zARl5cMgvHC&open=AZ5zxw4K4zARl5cMgvHC&pullRequest=10088
const auto isUrlValid = (overrideUrl.startsWith(QStringLiteral("http://")) || overrideUrl.startsWith(QStringLiteral("https://")))
&& QUrl::fromUserInput(overrideUrl).isValid();
if (!isUrlValid) {
Expand Down Expand Up @@ -1094,7 +1103,7 @@
{
const ConfigFile cfg;
const auto configLanguage = cfg.language();
if (!configLanguage.isEmpty()) {

Check warning on line 1106 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvHD&open=AZ5zxw4K4zARl5cMgvHD&pullRequest=10088
// always prefer value from configuration
return configLanguage;
}
Expand Down Expand Up @@ -1146,8 +1155,8 @@
const QString qtBaseTrFile = QLatin1String("qtbase_") + choosenLanguage;
if (!qtTranslator->load(qtTrFile, qtTrPath)) {
if (!qtTranslator->load(qtTrFile, trPath)) {
if (!qtTranslator->load(qtBaseTrFile, qtTrPath)) {

Check failure on line 1158 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvHE&open=AZ5zxw4K4zARl5cMgvHE&pullRequest=10088
if (!qtTranslator->load(qtBaseTrFile, trPath)) {

Check warning on line 1159 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvHG&open=AZ5zxw4K4zARl5cMgvHG&pullRequest=10088
qCDebug(lcApplication()) << "impossible to load Qt translation catalog" << qtBaseTrFile;
}
}
Expand All @@ -1155,7 +1164,7 @@
}
const QString qtkeychainTrFile = QLatin1String("qtkeychain_") + choosenLanguage;
if (!qtkeychainTranslator->load(qtkeychainTrFile, qtTrPath)) {
if (!qtkeychainTranslator->load(qtkeychainTrFile, trPath)) {

Check warning on line 1167 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvHF&open=AZ5zxw4K4zARl5cMgvHF&pullRequest=10088
qCDebug(lcApplication()) << "impossible to load QtKeychain translation catalog" << qtkeychainTrFile;
}
}
Expand Down Expand Up @@ -1205,7 +1214,7 @@

void Application::openVirtualFile(const QString &filename)
{
QString virtualFileExt = QStringLiteral(APPLICATION_DOTVIRTUALFILE_SUFFIX);

Check warning on line 1217 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw4K4zARl5cMgvHH&open=AZ5zxw4K4zARl5cMgvHH&pullRequest=10088
if (!filename.endsWith(virtualFileExt)) {
qWarning(lcApplication) << "Can only handle file ending in .owncloud. Unable to open" << filename;
return;
Expand Down
8 changes: 8 additions & 0 deletions src/gui/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <KDSingleApplication>
#endif

#if defined KF6DBusAddons_FOUND && KF6DBusAddons_FOUND
#include <KDBusService>
#endif

#include <QApplication>
#include <QPointer>
#include <QQueue>
Expand Down Expand Up @@ -50,7 +54,7 @@
* @brief The Application class
* @ingroup gui
*/
class Application : public QApplication

Check warning on line 57 in src/gui/application.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 23 it currently has.

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

Check failure on line 57 in src/gui/application.h

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this class' destructor so that the class follows the rule of Zero.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw754zARl5cMgvHK&open=AZ5zxw754zARl5cMgvHK&pullRequest=10088
{
Q_OBJECT
public:
Expand Down Expand Up @@ -109,7 +113,7 @@
void slotCleanup();
void slotAccountStateAdded(OCC::AccountState *accountState);
void slotAccountStateRemoved(OCC::AccountState *accountState);
void slotSystemOnlineConfigurationChanged();

Check warning on line 116 in src/gui/application.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=AZ5zxw754zARl5cMgvHN&open=AZ5zxw754zARl5cMgvHN&pullRequest=10088
void slotGuiIsShowingSettings();

private:
Expand All @@ -135,6 +139,10 @@
KDSingleApplication _singleApp;
#endif

#if defined KF6DBusAddons_FOUND && KF6DBusAddons_FOUND
KDBusService _dbusService;
#endif

Theme *_theme;

bool _helpOnly = false;
Expand Down
5 changes: 5 additions & 0 deletions src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <QtGlobal>

Check failure on line 7 in src/gui/main.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/main.cpp:7:10 [clang-diagnostic-error]

'QtGlobal' file not found

#include <cmath>
#include <csignal>
Expand Down Expand Up @@ -39,7 +39,7 @@
{
QMessageBox::critical(
nullptr,
qApp->translate("main.cpp", "System Tray not available"),

Check warning on line 42 in src/gui/main.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "->" with "::" for access to "QApplication::translate".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxw464zARl5cMgvHI&open=AZ5zxw464zARl5cMgvHI&pullRequest=10088
qApp->translate("main.cpp", "%1 requires on a working system tray. "
"If you are running XFCE, please follow "
"<a href=\"http://docs.xfce.org/xfce/xfce4-panel/systray\">these instructions</a>. "
Expand Down Expand Up @@ -104,6 +104,11 @@

QQuickStyle::setStyle(qmlStyle);

#if defined KF6DBusAddons_FOUND && KF6DBusAddons_FOUND
QCoreApplication::setOrganizationDomain(QLatin1String(APPLICATION_REV_DOMAIN_DBUS));
QCoreApplication::setApplicationName(QLatin1String(APPLICATION_EXECUTABLE));
#endif

OCC::Application app(argc, argv);

if (!widgetsStyle.isEmpty()) {
Expand Down
19 changes: 0 additions & 19 deletions src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@

messageBoxStartInstaller->setAttribute(Qt::WA_DeleteOnClose);

connect(messageBoxStartInstaller, &QMessageBox::buttonClicked, this, [this, messageBoxStartInstaller](QAbstractButton *button) {

Check warning on line 109 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "button" of type "class QAbstractButton *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvGs&open=AZ5zxwtB4zARl5cMgvGs&pullRequest=10088
auto clicked = messageBoxStartInstaller->standardButton(button);

Check warning on line 110 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "clicked" of type "enum QMessageBox::StandardButton" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvGt&open=AZ5zxwtB4zARl5cMgvGt&pullRequest=10088
if (clicked == QMessageBox::Ok) {
slotStartInstaller();
}
Expand Down Expand Up @@ -168,9 +168,9 @@
return tr("Update status is unknown: Did not check for new updates.");
case UpToDate:
// fall through
default: {

Check warning on line 171 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Reduce this switch case number of lines from 6 to at most 5, for example by extracting code into methods.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvGv&open=AZ5zxwtB4zARl5cMgvGv&pullRequest=10088
ConfigFile configFile;

Check warning on line 172 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvGw&open=AZ5zxwtB4zARl5cMgvGw&pullRequest=10088
if (configFile.serverHasValidSubscription()) {

Check warning on line 173 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvGu&open=AZ5zxwtB4zARl5cMgvGu&pullRequest=10088
return tr("You are using the %1 update channel. Your installation is the latest version.")
.arg(configFile.currentUpdateChannel());
}
Expand Down Expand Up @@ -223,7 +223,7 @@
return QDir::toNativeSeparators(path);
};

QString msiLogFile = cfg.configPath() + msiLogFileNameC;

Check warning on line 226 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "msiLogFile" of type "class QString" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvGx&open=AZ5zxwtB4zARl5cMgvGx&pullRequest=10088
QString command = QStringLiteral("&{msiexec /i '%1' /L*V '%2'| Out-Null ; &'%3'}")
.arg(preparePathForPowershell(updateFile))
.arg(preparePathForPowershell(msiLogFile))
Expand Down Expand Up @@ -308,7 +308,7 @@
ConfigFile cfg;
QSettings settings(cfg.configFile(), QSettings::IniFormat);
QString updateFileName = settings.value(updateAvailableC).toString();
if (!updateFileName.isEmpty()) {

Check warning on line 311 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvGz&open=AZ5zxwtB4zARl5cMgvGz&pullRequest=10088
if (QFile::remove(updateFileName)) {
qCInfo(lcUpdater) << "Removed updater file:" << updateFileName;
} else {
Expand All @@ -317,7 +317,7 @@
}
// Also try to remove the msi log file (created when running msiexec)
const auto msiLogFileName = QString{cfg.configPath() + msiLogFileNameC};
if (QFile::exists(msiLogFileName)) {

Check warning on line 320 in src/gui/updater/ocupdater.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ5zxwtB4zARl5cMgvG0&open=AZ5zxwtB4zARl5cMgvG0&pullRequest=10088
if (QFile::remove(msiLogFileName)) {
qCInfo(lcUpdater) << "Removed msi log file:" << msiLogFileName;
} else {
Expand Down Expand Up @@ -563,25 +563,6 @@
PassiveUpdateNotifier::PassiveUpdateNotifier(const QUrl &url)
: OCUpdater(url)
{
// remember the version of the currently running binary. On Linux it might happen that the
// package management updates the package while the app is running. This is detected in the
// updater slot: If the installed binary on the hd has a different version than the one
// running, the running app is restarted. That happens in folderman.
_runningAppVersion = Utility::versionOfInstalledBinary();
}

void PassiveUpdateNotifier::backgroundCheckForUpdate()
{
if (Utility::isLinux()) {
// on linux, check if the installed binary is still the same version
// as the one that is running. If not, restart if possible.
const QByteArray fsVersion = Utility::versionOfInstalledBinary();
if (!(fsVersion.isEmpty() || _runningAppVersion.isEmpty()) && fsVersion != _runningAppVersion) {
emit requestRestart();
}
}

OCUpdater::backgroundCheckForUpdate();
}

void PassiveUpdateNotifier::versionInfoArrived(const UpdateInfo &info)
Expand Down
2 changes: 0 additions & 2 deletions src/gui/updater/ocupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ class PassiveUpdateNotifier : public OCUpdater
public:
explicit PassiveUpdateNotifier(const QUrl &url);
bool handleStartup() override { return false; }
void backgroundCheckForUpdate() override;

private:
void versionInfoArrived(const UpdateInfo &info) override;
QByteArray _runningAppVersion;
};
}

Expand Down
18 changes: 0 additions & 18 deletions test/testutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,6 @@ private slots:

}

void testVersionOfInstalledBinary()
{
if (isLinux()) {
// pass the cmd client from our build dir
// this is a bit inaccurate as it does not test the "real thing"
// but cmd and gui have the same --version handler by now
// and cmd works without X in CI
QString ver = versionOfInstalledBinary(QStringLiteral(OWNCLOUD_BIN_PATH "/" APPLICATION_EXECUTABLE "cmd"));
qDebug() << "Version of installed Nextcloud: " << ver;
QVERIFY(!ver.isEmpty());

const QRegularExpression rx(QRegularExpression::anchoredPattern(APPLICATION_SHORTNAME R"( version \d+\.\d+\.\d+.*)"));
QVERIFY(rx.match(ver).hasMatch());
} else {
QVERIFY(versionOfInstalledBinary().isEmpty());
}
}

void testTimeAgo()
{
// Both times in same timezone
Expand Down
Loading