Skip to content

Implement spaces #9154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 2, 2022
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
3 changes: 3 additions & 0 deletions .craft.shelf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[General]
version = 2
blueprintrepositories = https://github.com/owncloud/craft-blueprints-owncloud.git|master|;https://invent.kde.org/packaging/craft-blueprints-kde.git|master|

[libs/libre-graph-api-cpp-qt-client]
version = v0.11.0
Copy link
Member

Choose a reason for hiding this comment

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

😍

4 changes: 3 additions & 1 deletion src/gui/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ void ConnectionValidator::checkAuthentication()
// simply GET the webdav root, will fail if credentials are wrong.
// continue in slotAuthCheck here :-)
qCDebug(lcConnectionValidator) << "# Check whether authenticated propfind works.";

// we explicitly use a legacy dav path here
PropfindJob *job = new PropfindJob(_account, _account->davUrl(), {}, this);
job->setAuthenticationJob(true); // don't retry
job->setTimeout(timeoutToUse);
job->setProperties(QList<QByteArray>() << "getlastmodified");
job->setProperties({ QByteArrayLiteral("getlastmodified") });
connect(job, &PropfindJob::finishedWithoutError, this, &ConnectionValidator::slotAuthSuccess);
connect(job, &PropfindJob::finishedWithError, this, &ConnectionValidator::slotAuthFailed);
job->start();
Expand Down
25 changes: 24 additions & 1 deletion src/gui/owncloudsetupwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "settingsdialog.h"

#include "creds/dummycredentials.h"
#include <graphapi/drives.h>

using namespace std::chrono_literals;

Expand Down Expand Up @@ -433,7 +434,29 @@ void OwncloudSetupWizard::slotAssistantFinished(int result)

if (!startFromScratch || ensureStartFromScratch(localFolder)) {
auto account = applyAccountChanges();
addFolder(account, localFolder, _ocWizard->remoteFolder(), account->account()->davUrl());
if (account->account()->capabilities().spacesSupport().enabled) {
auto *drive = new OCC::GraphApi::Drives(account->account());
connect(drive, &OCC::GraphApi::Drives::finishedSignal, [account, localFolder, result, drive, this] {
if (drive->parseError().error == QJsonParseError::NoError) {
const auto &drives = drive->drives();
if (!drives.isEmpty()) {
const QDir localDir(localFolder);
localDir.mkdir(".");
for (const auto &d : drives) {
const QDir driveLocalFolder = localDir.filePath(d.getName());
driveLocalFolder.mkdir(".");
addFolder(account, driveLocalFolder.absolutePath(), {}, QUrl::fromEncoded(d.getRoot().getWebDavUrl().toUtf8()));
}
}
}
// notify others.
emit ownCloudWizardDone(result);
});
drive->start();
return;
} else {
addFolder(account, localFolder, _ocWizard->remoteFolder(), account->account()->davUrl());
}
} else {
qCWarning(lcWizard) << "Failed to create local sync folder!";
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/quotainfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void QuotaInfo::slotRequestFailed()

bool QuotaInfo::canGetQuota() const
{
if (!_accountState || !_active) {
if (!_accountState || !_active || _accountState->account()->capabilities().spacesSupport().enabled) {
return false;
}
AccountPtr account = _accountState->account();
Expand Down
8 changes: 8 additions & 0 deletions src/libsync/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
find_package(LibreGraphAPI REQUIRED)

set(libsync_SRCS
account.cpp
bandwidthmanager.cpp
Expand Down Expand Up @@ -43,6 +45,8 @@ set(libsync_SRCS

abstractcorejob.cpp
determineauthtypejobfactory.cpp

graphapi/drives.cpp
)

if(TOKEN_AUTH_ONLY)
Expand Down Expand Up @@ -79,6 +83,7 @@ IF (NOT APPLE)
ENDIF(NOT APPLE)

add_library(libsync SHARED ${libsync_SRCS})

target_link_libraries(libsync PUBLIC
csync
Qt5::Core Qt5::Network
Expand All @@ -94,6 +99,9 @@ target_compile_definitions(libsync
QT_NO_FOREACH
)

target_link_libraries(libsync PUBLIC OpenAPI::LibreGraphAPI)
add_subdirectory(graphapi)

if ( APPLE )
target_link_libraries(libsync PUBLIC
/System/Library/Frameworks/CoreServices.framework
Expand Down
1 change: 1 addition & 0 deletions src/libsync/graphapi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target_sources(libsync PRIVATE drives.cpp)
46 changes: 46 additions & 0 deletions src/libsync/graphapi/drives.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) by Hannah von Reth <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/

#include "drives.h"

#include "account.h"

#include <QJsonArray>

#include <OAICollection_of_drives.h>
#include <OAIDrive.h>


using namespace OCC;
using namespace GraphApi;


Drives::Drives(const AccountPtr &account, QObject *parent)
: JsonJob(account, account->url(), QStringLiteral("/graph/v1.0/me/drives"), "GET", {}, {}, parent)
{
}

Drives::~Drives()
{
}

const QList<OpenAPI::OAIDrive> &Drives::drives() const
{
if (_drives.isEmpty() && parseError().error == QJsonParseError::NoError) {
OpenAPI::OAICollection_of_drives drives;
drives.fromJsonObject(data());
_drives = drives.getValue();
}
return _drives;
}
36 changes: 36 additions & 0 deletions src/libsync/graphapi/drives.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (C) by Hannah von Reth <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once

#include "networkjobs/jsonjob.h"

#include "owncloudlib.h"
#include <OAIDrive.h>

namespace OCC {
namespace GraphApi {
class OWNCLOUDSYNC_EXPORT Drives : public JsonJob
{
Q_OBJECT
public:
Drives(const AccountPtr &account, QObject *parent = nullptr);
~Drives();

const QList<OpenAPI::OAIDrive> &drives() const;

private:
mutable QList<OpenAPI::OAIDrive> _drives;
};
}
}