diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-02-24 16:51:15 +0300 |
---|---|---|
committer | Hannah von Reth <hannah.vonreth@owncloud.com> | 2022-02-25 13:38:10 +0300 |
commit | a88386c36015228c65938e78f7093e4edeb5af30 (patch) | |
tree | 2a1c93ac6ec4ccf9f544b6354074b1eab4f45482 | |
parent | f49aa279c3694c73ea0e1b9b75805d0d1f4591b1 (diff) |
wipwork/spaces3
-rw-r--r-- | src/gui/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/gui/folder.cpp | 4 | ||||
-rw-r--r-- | src/gui/spaces/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/gui/spaces/spacesbrowser.cpp | 35 | ||||
-rw-r--r-- | src/gui/spaces/spacesbrowser.h | 27 | ||||
-rw-r--r-- | src/gui/spaces/spacesbrowser.ui | 34 | ||||
-rw-r--r-- | src/gui/spaces/spacesmodel.cpp | 80 | ||||
-rw-r--r-- | src/gui/spaces/spacesmodel.h | 35 | ||||
-rw-r--r-- | src/libsync/creds/oauth.cpp | 5 |
9 files changed, 223 insertions, 3 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 2ddb35127..30ed7cf7d 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -140,6 +140,10 @@ target_compile_definitions(owncloudCore QT_NO_FOREACH ) + +add_subdirectory(spaces) + + add_subdirectory(socketapi) target_include_directories(owncloudCore PUBLIC diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 005f912e5..2e895d18a 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -29,11 +29,13 @@ #include "filesystem.h" #include "folder.h" #include "folderman.h" +#include "graphapi/drives.h" #include "localdiscoverytracker.h" #include "logger.h" #include "networkjobs.h" #include "settingsdialog.h" #include "socketapi/socketapi.h" +#include "spaces/spacesbrowser.h" #include "syncengine.h" #include "syncresult.h" #include "syncrunfilelog.h" @@ -169,6 +171,8 @@ Folder::Folder(const FolderDefinition &definition, // Initialize the vfs plugin startVfs(); } + + // auto *w = new SpacesBrowser(_accountState->account()); } Folder::~Folder() diff --git a/src/gui/spaces/CMakeLists.txt b/src/gui/spaces/CMakeLists.txt new file mode 100644 index 000000000..796f6aae5 --- /dev/null +++ b/src/gui/spaces/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(owncloudCore PRIVATE +${CMAKE_CURRENT_SOURCE_DIR}/spacesmodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/spacesbrowser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/spacesbrowser.ui)
\ No newline at end of file diff --git a/src/gui/spaces/spacesbrowser.cpp b/src/gui/spaces/spacesbrowser.cpp new file mode 100644 index 000000000..3c5e6b354 --- /dev/null +++ b/src/gui/spaces/spacesbrowser.cpp @@ -0,0 +1,35 @@ +#include "spacesbrowser.h" +#include "ui_spacesbrowser.h" + + +#include "spacesmodel.h" + +#include "graphapi/drives.h" + +#include <QTimer> + + +SpacesBrowser::SpacesBrowser(OCC::AccountPtr acc, QWidget *parent) + : QWidget(parent) + , ui(new Ui::SpacesBrowser) + , _acc(acc) +{ + ui->setupUi(this); + _model = new SpacesModel(this); + ui->tableView->setModel(_model); + + + QTimer::singleShot(5000, this, [this] { + auto drive = new OCC::GraphApi::Drives(_acc); + connect(drive, &OCC::GraphApi::Drives::finishedSignal, [drive, this] { + _model->setData(drive->drives()); + show(); + }); + drive->start(); + }); +} + +SpacesBrowser::~SpacesBrowser() +{ + delete ui; +} diff --git a/src/gui/spaces/spacesbrowser.h b/src/gui/spaces/spacesbrowser.h new file mode 100644 index 000000000..b4e729f43 --- /dev/null +++ b/src/gui/spaces/spacesbrowser.h @@ -0,0 +1,27 @@ +#pragma once + + +#include <QWidget> + +#include "account.h" + +class SpacesModel; + +namespace Ui { +class SpacesBrowser; +} + +class SpacesBrowser : public QWidget +{ + Q_OBJECT + +public: + explicit SpacesBrowser(OCC::AccountPtr acc, QWidget *parent = nullptr); + ~SpacesBrowser(); + +private: + Ui::SpacesBrowser *ui; + + OCC::AccountPtr _acc; + SpacesModel *_model; +}; diff --git a/src/gui/spaces/spacesbrowser.ui b/src/gui/spaces/spacesbrowser.ui new file mode 100644 index 000000000..43b1dfa0e --- /dev/null +++ b/src/gui/spaces/spacesbrowser.ui @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SpacesBrowser</class> + <widget class="QWidget" name="SpacesBrowser"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QTableView" name="tableView"> + <attribute name="horizontalHeaderVisible"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <attribute name="verticalHeaderHighlightSections"> + <bool>false</bool> + </attribute> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/gui/spaces/spacesmodel.cpp b/src/gui/spaces/spacesmodel.cpp new file mode 100644 index 000000000..6e59d7dd0 --- /dev/null +++ b/src/gui/spaces/spacesmodel.cpp @@ -0,0 +1,80 @@ +#include "spacesmodel.h" + +SpacesModel::SpacesModel(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +QVariant SpacesModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal) { + const auto actionRole = static_cast<Drives>(section); + switch (role) { + case Qt::DisplayRole: + switch (actionRole) { + case Drives::Name: + return tr("Name"); + case Drives::Description: + return tr("Description"); + case Drives::WebUrl: + return tr("Web URL"); + case Drives::WebDavUrl: + return tr("Web Dav URL"); + case Drives::ColumnCount: + Q_UNREACHABLE(); + break; + } + } + } + return QAbstractTableModel::headerData(section, orientation, role); +} + +int SpacesModel::rowCount(const QModelIndex &parent) const +{ + Q_ASSERT(checkIndex(parent)); + if (parent.isValid()) + return 0; + return static_cast<int>(_data.size()); +} + +int SpacesModel::columnCount(const QModelIndex &parent) const +{ + Q_ASSERT(checkIndex(parent)); + if (parent.isValid()) { + return 0; + } + return static_cast<int>(Drives::ColumnCount); +} + +QVariant SpacesModel::data(const QModelIndex &index, int role) const +{ + Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid)); + + const auto column = static_cast<Drives>(index.column()); + const auto &item = _data.at(index.row()); + switch (role) { + case Qt::DisplayRole: + switch (column) { + case Drives::Name: + return item.getName(); + case Drives::Description: + return item.getDescription(); + case Drives::WebUrl: + return item.getWebUrl(); + case Drives::WebDavUrl: + return item.getRoot().getWebDavUrl(); + case Drives::ColumnCount: + Q_UNREACHABLE(); + break; + } + break; + } + return {}; +} + +void SpacesModel::setData(const QList<OpenAPI::OAIDrive> &data) +{ + beginResetModel(); + _data = data; + endResetModel(); +} diff --git a/src/gui/spaces/spacesmodel.h b/src/gui/spaces/spacesmodel.h new file mode 100644 index 000000000..9c13c9aac --- /dev/null +++ b/src/gui/spaces/spacesmodel.h @@ -0,0 +1,35 @@ +#pragma once + +#include <QAbstractItemModel> + +#include <graphapi/drives.h> + +class SpacesModel : public QAbstractTableModel +{ + Q_OBJECT + +public: + enum class Drives { + Name, + Description, + WebUrl, + WebDavUrl, + + ColumnCount + }; + Q_ENUM(Drives) + explicit SpacesModel(QObject *parent = nullptr); + + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + void setData(const QList<OpenAPI::OAIDrive> &data); + +private: + QList<OpenAPI::OAIDrive> _data; +}; diff --git a/src/libsync/creds/oauth.cpp b/src/libsync/creds/oauth.cpp index f7756feb0..26b5dfbdb 100644 --- a/src/libsync/creds/oauth.cpp +++ b/src/libsync/creds/oauth.cpp @@ -431,17 +431,16 @@ QByteArray OAuth::generateRandomString(size_t size) const QUrl OAuth::authorisationLink() const { Q_ASSERT(_server.isListening()); - QUrlQuery query; const QByteArray code_challenge = QCryptographicHash::hash(_pkceCodeVerifier, QCryptographicHash::Sha256) .toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); - query.setQueryItems({ { QStringLiteral("response_type"), QStringLiteral("code") }, + QUrlQuery query { { QStringLiteral("response_type"), QStringLiteral("code") }, { QStringLiteral("client_id"), _clientId }, { QStringLiteral("redirect_uri"), QStringLiteral("%1:%2").arg(_redirectUrl, QString::number(_server.serverPort())) }, { QStringLiteral("code_challenge"), QString::fromLatin1(code_challenge) }, { QStringLiteral("code_challenge_method"), QStringLiteral("S256") }, { QStringLiteral("scope"), Theme::instance()->openIdConnectScopes() }, { QStringLiteral("prompt"), Theme::instance()->openIdConnectPrompt() }, - { QStringLiteral("state"), QString::fromUtf8(_state) } }); + { QStringLiteral("state"), QString::fromUtf8(_state) } }; if (!_davUser.isEmpty()) { const QString davUser = QString::fromUtf8(QUrl::toPercentEncoding(_davUser)); // Issue #7762; |