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: 5 additions & 1 deletion src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ void AccountManager::saveAccountHelper(const AccountPtr &account, QSettings &set
{
qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName();
settings.setValue(QLatin1String(versionC), maxAccountVersion);
settings.setValue(QLatin1String(urlC), account->_url.toString());
if (account->isPublicShareLink()) {
settings.setValue(QLatin1String(urlC), account->publicShareLinkUrl().toString());
} else {
settings.setValue(QLatin1String(urlC), account->_url.toString());
}
settings.setValue(QLatin1String(davUserC), account->_davUser);
settings.setValue(QLatin1String(displayNameC), account->davDisplayName());
settings.setValue(QLatin1String(serverVersionC), account->_serverVersion);
Expand Down
7 changes: 7 additions & 0 deletions src/gui/connectionvalidator.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 <QJsonDocument>

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

View workflow job for this annotation

GitHub Actions / build

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

'QJsonDocument' file not found
#include <QJsonObject>
#include <QJsonArray>
#include <QLoggingCategory>
Expand Down Expand Up @@ -272,6 +272,13 @@
_account->fetchDirectEditors(directEditingURL, directEditingETag);

checkServerTermsOfService();

if (_account->isPublicShareLink()) {
slotUserFetched(nullptr);
return;
}

fetchUser();
}

void ConnectionValidator::fetchUser()
Expand Down
26 changes: 25 additions & 1 deletion src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2012 ownCloud GmbH
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "accessmanager.h"

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

View workflow job for this annotation

GitHub Actions / build

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

'accessmanager.h' file not found
#include "account.h"
#include "accountmanager.h"
#include "clientproxy.h"
Expand All @@ -19,6 +19,7 @@
#include "sslerrordialog.h"
#include "wizard/owncloudwizard.h"
#include "wizard/owncloudwizardcommon.h"
#include "account.h"

Check warning on line 22 in src/gui/owncloudsetupwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/owncloudsetupwizard.cpp:22:1 [readability-duplicate-include]

duplicate include

#include "creds/credentialsfactory.h"
#include "creds/abstractcredentials.h"
Expand Down Expand Up @@ -300,7 +301,11 @@
qCInfo(lcWizard) << " was redirected to" << url.toString();
}

slotDetermineAuthType();
if (_ocWizard->account()->isPublicShareLink()) {
_ocWizard->setAuthType(DetermineAuthTypeJob::Basic);
} else {
slotDetermineAuthType();
}
}

void OwncloudSetupWizard::slotNoServerFound(QNetworkReply *reply)
Expand Down Expand Up @@ -352,6 +357,19 @@
creds->persist();
}

if (_ocWizard->account()->isPublicShareLink()) {
_ocWizard->account()->setDavUser(creds->user());
_ocWizard->account()->setDavDisplayName(creds->user());

_ocWizard->setField(QLatin1String("OCUrl"), url);
_ocWizard->appendToConfigurationLog(tr("Trying to connect to %1 at %2 …")
.arg(Theme::instance()->appNameGUI())
.arg(url));

testOwnCloudConnect();
return;
}

const auto fetchUserNameJob = new JsonApiJob(_ocWizard->account()->sharedFromThis(), QStringLiteral("/ocs/v1.php/cloud/user"));
connect(fetchUserNameJob, &JsonApiJob::jsonReceived, this, [this, url](const QJsonDocument &json, int statusCode) {
if (statusCode != 100) {
Expand Down Expand Up @@ -786,7 +804,13 @@
auto manager = AccountManager::instance();

auto newState = manager->addAccount(newAccount);

if (newAccount->isPublicShareLink()) {
qCInfo(lcWizard()) << "seeting up public share link account";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
qCInfo(lcWizard()) << "seeting up public share link account";
qCInfo(lcWizard()) << "setting up public share link account";

}

manager->saveAccount(newAccount);

return newState;
}

Expand Down
51 changes: 28 additions & 23 deletions src/gui/tray/UserLine.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.nextcloud.desktopclient
AbstractButton {
id: userLine

signal showUserStatusSelector(int id)
signal showUserStatusMessageSelector(int id)
signal showUserStatusSelector(int id)
signal showUserStatusMessageSelector(int id)


Accessible.role: Accessible.MenuItem
Expand Down Expand Up @@ -133,26 +133,31 @@ AbstractButton {
id: userMoreButtonMenu
closePolicy: Menu.CloseOnPressOutsideParent | Menu.CloseOnEscape

MenuItem {
visible: model.isConnected && model.serverHasUserStatus
height: visible ? implicitHeight : 0
text: qsTr("Set status")
font.pixelSize: Style.topLinePixelSize
hoverEnabled: true
onClicked: showUserStatusSelector(index)
}

MenuItem {
visible: model.isConnected && model.serverHasUserStatus
height: visible ? implicitHeight : 0
text: qsTr("Status message")
font.pixelSize: Style.topLinePixelSize
hoverEnabled: true
onClicked: showUserStatusMessageSelector(index)
}

MenuItem {
text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
<<<<<<< HEAD
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks
already fixed

MenuItem {
visible: model.isConnected && model.serverHasUserStatus
height: visible ? implicitHeight : 0
text: qsTr("Set status")
font.pixelSize: Style.topLinePixelSize
hoverEnabled: true
onClicked: showUserStatusSelector(index)
}

MenuItem {
visible: model.isConnected && model.serverHasUserStatus
height: visible ? implicitHeight : 0
text: qsTr("Status message")
font.pixelSize: Style.topLinePixelSize
hoverEnabled: true
onClicked: showUserStatusMessageSelector(index)
}

MenuItem {
text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
visible: model.canLogout
height: visible ? implicitHeight : 0
width: parent.width
text: model.isConnected ? qsTr("Log out") : qsTr("Log in")
font.pixelSize: Style.topLinePixelSize
hoverEnabled: true
onClicked: {
Expand All @@ -175,7 +180,7 @@ AbstractButton {

MenuItem {
id: removeAccountButton
text: qsTr("Remove account")
text: model.removeAccountText
font.pixelSize: Style.topLinePixelSize
hoverEnabled: true
onClicked: {
Expand Down
108 changes: 74 additions & 34 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand Down Expand Up @@ -900,7 +900,17 @@
return _trayFolderInfos;
}

bool User::canLogout() const

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:903:12 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return !isPublicShareLink();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without really knowing the context, reads very weird, that canLogout() doesn't care whether we are logged in.

}

bool User::isPublicShareLink() const

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:908:12 [modernize-use-trailing-return-type]

use a trailing return type for this function
{
return _account->account()->isPublicShareLink();
}

void User::slotItemCompleted(const QString &folder, const SyncFileItemPtr &item)

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:913:30 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'slotItemCompleted' of similar type ('const int &') are easily swapped by mistake

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:913:12 [readability-convert-member-functions-to-static]

method 'slotItemCompleted' can be made static
{
auto folderInstance = FolderMan::instance()->folder(folder);

Expand Down Expand Up @@ -1004,17 +1014,27 @@

QString User::name() const
{
if (isPublicShareLink()) {
return tr("Public Share Link");
}

return _account->account()->prettyName();
}

QString User::server(bool shortened) const
{
QString serverUrl = _account->account()->url().toString();
auto serverUrl = _account->account()->url();

if (isPublicShareLink()) {
serverUrl.setUserName({});
}
QString stringServerUrl = serverUrl.toString();

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1031:13 [cppcoreguidelines-init-variables]

variable 'stringServerUrl' is not initialized
if (shortened) {
serverUrl.replace(QLatin1String("https://"), QLatin1String(""));
serverUrl.replace(QLatin1String("http://"), QLatin1String(""));
stringServerUrl.replace(QLatin1String("https://"), QLatin1String(""));
stringServerUrl.replace(QLatin1String("http://"), QLatin1String(""));

}
return serverUrl;
return stringServerUrl;
}

UserStatus::OnlineStatus User::status() const
Expand Down Expand Up @@ -1579,36 +1599,54 @@

QVariant UserModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= _users.count()) {
return QVariant();
}

if (role == NameRole) {
return _users[index.row()]->name();
} else if (role == ServerRole) {
return _users[index.row()]->server();
} else if (role == ServerHasUserStatusRole) {
return _users[index.row()]->serverHasUserStatus();
} else if (role == StatusRole) {
return QVariant::fromValue(_users[index.row()]->status());
} else if (role == StatusIconRole) {
return _users[index.row()]->statusIcon();
} else if (role == StatusEmojiRole) {
return _users[index.row()]->statusEmoji();
} else if (role == StatusMessageRole) {
return _users[index.row()]->statusMessage();
} else if (role == DesktopNotificationsAllowedRole) {
return _users[index.row()]->isDesktopNotificationsAllowed();
} else if (role == AvatarRole) {
return _users[index.row()]->avatarUrl();
} else if (role == IsCurrentUserRole) {
return _users[index.row()]->isCurrentUser();
} else if (role == IsConnectedRole) {
return _users[index.row()]->isConnected();
} else if (role == IdRole) {
return index.row();
}
return QVariant();
auto result = QVariant{};
switch (static_cast<UserRoles>(role))
{
case NameRole:

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

View workflow job for this annotation

GitHub Actions / build

src/gui/tray/usermodel.cpp:1605:5 [bugprone-branch-clone]

switch has 14 consecutive identical branches
result = _users[index.row()]->name();
break;
case ServerRole:
result = _users[index.row()]->server();
break;
case ServerHasUserStatusRole:
result = _users[index.row()]->serverHasUserStatus();
break;
case StatusRole:
result = QVariant::fromValue(_users[index.row()]->status());
break;
case StatusIconRole:
result = _users[index.row()]->statusIcon();
break;
case StatusEmojiRole:
result = _users[index.row()]->statusEmoji();
break;
case StatusMessageRole:
result = _users[index.row()]->statusMessage();
break;
case DesktopNotificationsAllowedRole:
result = _users[index.row()]->isDesktopNotificationsAllowed();
break;
case AvatarRole:
result = _users[index.row()]->avatarUrl();
break;
case IsCurrentUserRole:
result = _users[index.row()]->isCurrentUser();
break;
case IsConnectedRole:
result = _users[index.row()]->isConnected();
break;
case IdRole:
result = index.row();
break;
case CanLogoutRole:
result = _users[index.row()]->canLogout();
break;
case RemoveAccountTextRole:
result = _users[index.row()]->isPublicShareLink() ? tr("Leave share") : tr("Remove account");
break;
}

return result;
}

QHash<int, QByteArray> UserModel::roleNames() const
Expand All @@ -1626,6 +1664,8 @@
roles[IsCurrentUserRole] = "isCurrentUser";
roles[IsConnectedRole] = "isConnected";
roles[IdRole] = "id";
roles[CanLogoutRole] = "canLogout";
roles[RemoveAccountTextRole] = "removeAccountText";
return roles;
}

Expand Down
7 changes: 6 additions & 1 deletion src/gui/tray/usermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#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 <QStringList>
Expand Down Expand Up @@ -71,6 +71,7 @@
Q_PROPERTY(bool needsToSignTermsOfService READ needsToSignTermsOfService NOTIFY accountStateChanged)
Q_PROPERTY(UnifiedSearchResultsListModel* unifiedSearchResultsListModel READ getUnifiedSearchResultsListModel CONSTANT)
Q_PROPERTY(QVariantList groupFolders READ groupFolders NOTIFY groupFoldersChanged)
Q_PROPERTY(bool canLogout READ canLogout CONSTANT)

public:
User(AccountStatePtr &account, const bool &isCurrent = false, QObject *parent = nullptr);
Expand Down Expand Up @@ -113,6 +114,8 @@
[[nodiscard]] QString statusEmoji() const;
void processCompletedSyncItem(const Folder *folder, const SyncFileItemPtr &item);
[[nodiscard]] const QVariantList &groupFolders() const;
[[nodiscard]] bool canLogout() const;
[[nodiscard]] bool isPublicShareLink() const;

signals:
void nameChanged();
Expand Down Expand Up @@ -256,7 +259,9 @@
AvatarRole,
IsCurrentUserRole,
IsConnectedRole,
IdRole
IdRole,
CanLogoutRole,
RemoveAccountTextRole,
};

[[nodiscard]] AccountAppList appList() const;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/userinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-2.0-or-later
Expand Down Expand Up @@ -66,7 +66,7 @@

bool UserInfo::canGetInfo() const
{
if (!_accountState || !_active) {
if (!_accountState || !_active || !_accountState->account() || _accountState->account()->isPublicShareLink()) {
return false;
}
AccountPtr account = _accountState->account();
Expand Down Expand Up @@ -130,8 +130,8 @@
_jobRestartTimer.start(defaultIntervalT);
_lastInfoReceived = QDateTime::currentDateTime();

if(_fetchAvatarImage) {
if(_fetchAvatarImage && !account->isPublicShareLink()) {
auto *job = new AvatarJob(account, account->davUser(), 128, this);

Check warning on line 134 in src/gui/userinfo.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/userinfo.cpp:134:15 [cppcoreguidelines-init-variables]

variable 'job' is not initialized
job->setTimeout(20 * 1000);
QObject::connect(job, &AvatarJob::avatarPixmap, this, &UserInfo::slotAvatarImage);
job->start();
Expand Down
5 changes: 5 additions & 0 deletions src/gui/wizard/owncloudadvancedsetuppage.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 <QDir>

Check failure on line 7 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View workflow job for this annotation

GitHub Actions / build

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

'QDir' file not found
#include <QFileDialog>
#include <QUrl>
#include <QTimer>
Expand Down Expand Up @@ -240,6 +240,11 @@
if (Theme::isHidpi()) {
avatarSize *= 2;
}

if (account->isPublicShareLink()) {
return;
}

const auto avatarJob = new AvatarJob(account, account->davUser(), avatarSize, this);
avatarJob->setTimeout(20 * 1000);
QObject::connect(avatarJob, &AvatarJob::avatarPixmap, this, [this](const QImage &avatarImage) {
Expand Down
14 changes: 9 additions & 5 deletions src/gui/wizard/owncloudhttpcredspage.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 "QProgressIndicator.h"

Check failure on line 7 in src/gui/wizard/owncloudhttpcredspage.cpp

View workflow job for this annotation

GitHub Actions / build

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

'QProgressIndicator.h' file not found

#include "creds/httpcredentialsgui.h"
#include "theme.h"
Expand Down Expand Up @@ -95,11 +95,15 @@
const QString user = url.userName();
const QString password = url.password();

_ui.leUsername->setText(user);
_ui.lePassword->setText(password);

if (!user.isEmpty()) {
_ui.leUsername->setText(user);
}
if (!password.isEmpty()) {
_ui.lePassword->setText(password);
_ui.errorLabel->setVisible(false);
startSpinner();

emit completeChanged();
emit connectToOCUrl(field("OCUrl").toString().simplified());
}
}
_ui.tokenLabel->setText(HttpCredentialsGui::requestAppPasswordText(ocWizard->account().data()));
Expand All @@ -115,7 +119,7 @@

bool OwncloudHttpCredsPage::validatePage()
{
if (_ui.leUsername->text().isEmpty() || _ui.lePassword->text().isEmpty()) {
if (_ui.leUsername->text().isEmpty()) {
return false;
}

Expand Down
Loading
Loading