Skip to content

Commit

Permalink
Port spaces browser to qml
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Apr 11, 2024
1 parent 267d554 commit 156e465
Show file tree
Hide file tree
Showing 25 changed files with 314 additions and 438 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/11595
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Change: Rewrite of the spaces browser

https://github.com/owncloud/client/pull/11595
12 changes: 10 additions & 2 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,25 @@ add_subdirectory(newwizard)
add_subdirectory(folderwizard)
add_subdirectory(loginrequireddialog)

# TODO: find a proper home
add_library(qmlutils STATIC qmlutils.cpp)
target_link_libraries(qmlutils PUBLIC owncloudResources Qt::QuickWidgets)
set_target_properties(qmlutils PROPERTIES AUTOUIC ON AUTORCC ON)
apply_common_target_settings(qmlutils)

add_library(owncloudGui SHARED ${final_src})
set_target_properties(owncloudGui PROPERTIES AUTOUIC ON AUTORCC ON)
# for the generated qml module
target_include_directories(owncloudGui PRIVATE models)
target_link_libraries(owncloudGui
PUBLIC
Qt::Widgets Qt::Network Qt::Xml Qt::Quick Qt::QuickWidgets Qt::QuickControls2
newwizard folderwizard spaces loginrequireddialog
newwizard folderwizard loginrequireddialog
libsync
Qt6Keychain::Qt6Keychain
PRIVATE
ownCloudSpaces
qmlutils
)

apply_common_target_settings(owncloudGui)
Expand All @@ -117,7 +126,6 @@ ecm_add_qml_module(owncloudGui
VERSION 1.0
NAMESPACE OCC
QML_FILES
qml/SpaceDelegate.qml
qml/FolderDelegate.qml
qml/FolderError.qml
)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
#include "folderwizard/folderwizard.h"
#include "gui/accountmodalwidget.h"
#include "gui/models/models.h"
#include "gui/qmlutils.h"
#include "gui/selectivesyncwidget.h"
#include "gui/spaces/spaceimageprovider.h"
#include "guiutility.h"
#include "oauthloginwidget.h"
#include "quotainfo.h"
#include "resources/resources.h"
#include "scheduling/syncscheduler.h"
#include "settingsdialog.h"
#include "theme.h"
Expand Down Expand Up @@ -74,7 +74,7 @@ AccountSettings::AccountSettings(const AccountStatePtr &accountState, QWidget *p

ui->quickWidget->rootContext()->setContextProperty(QStringLiteral("ctx"), this);
ui->quickWidget->engine()->addImageProvider(QStringLiteral("space"), new Spaces::SpaceImageProvider(_accountState->account()));
Utility::initQuickWidget(ui->quickWidget, QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/qml/FolderDelegate.qml")));
QmlUtils::initQuicWidget(ui->quickWidget, QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/qml/FolderDelegate.qml")));

createAccountToolbox();
connect(FolderMan::instance(), &FolderMan::folderListChanged, _model, &FolderStatusModel::resetFolders);
Expand Down
13 changes: 7 additions & 6 deletions src/gui/folderwizard/folderwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "gui/folderman.h"
#include "gui/spaces/spacesmodel.h"

#include "libsync/graphapi/space.h"

#include <QDesktopServices>
#include <QDir>
#include <QEvent>
Expand Down Expand Up @@ -97,8 +99,7 @@ FolderWizardPrivate::FolderWizardPrivate(FolderWizard *q, const AccountStatePtr
QString FolderWizardPrivate::initialLocalPath() const
{
if (_account->supportsSpaces()) {
return FolderMan::findGoodPathForNewSyncFolder(
defaultSyncRoot(), _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::Name).toString(), FolderMan::NewFolderType::SpacesSyncRoot);
return FolderMan::findGoodPathForNewSyncFolder(defaultSyncRoot(), _spacesPage->currentSpace()->displayName(), FolderMan::NewFolderType::SpacesSyncRoot);
}

// Split default sync root:
Expand All @@ -114,15 +115,15 @@ QString FolderWizardPrivate::remotePath() const
uint32_t FolderWizardPrivate::priority() const
{
if (_account->supportsSpaces()) {
return _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::Priority).toUInt();
return _spacesPage->currentSpace()->priority();
}
return 0;
}

QUrl FolderWizardPrivate::davUrl() const
{
if (_account->supportsSpaces()) {
auto url = _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::WebDavUrl).toUrl();
auto url = _spacesPage->currentSpace()->webdavUrl();
if (!url.path().endsWith(QLatin1Char('/'))) {
url.setPath(url.path() + QLatin1Char('/'));
}
Expand All @@ -134,15 +135,15 @@ QUrl FolderWizardPrivate::davUrl() const
QString FolderWizardPrivate::spaceId() const
{
if (_account->supportsSpaces()) {
return _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::SpaceId).toString();
return _spacesPage->currentSpace()->id();
}
return {};
}

QString FolderWizardPrivate::displayName() const
{
if (_account->supportsSpaces()) {
return _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::Name).toString();
return _spacesPage->currentSpace()->displayName();
}
return QString();
}
Expand Down
8 changes: 4 additions & 4 deletions src/gui/folderwizard/spacespage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SpacesPage::SpacesPage(AccountPtr acc, QWidget *parent)

ui->widget->setAccount(acc);

connect(ui->widget, &Spaces::SpacesBrowser::selectionChanged, this, &QWizardPage::completeChanged);
connect(ui->widget, &Spaces::SpacesBrowser::currentSpaceChanged, this, &QWizardPage::completeChanged);
}

SpacesPage::~SpacesPage()
Expand All @@ -36,10 +36,10 @@ SpacesPage::~SpacesPage()

bool OCC::SpacesPage::isComplete() const
{
return ui->widget->currentSpace().isValid();
return ui->widget->currentSpace();
}

QVariant OCC::SpacesPage::selectedSpaceData(Spaces::SpacesModel::Columns column) const
GraphApi::Space *OCC::SpacesPage::currentSpace() const
{
return ui->widget->currentSpace().siblingAtColumn(static_cast<int>(column)).data();
return ui->widget->currentSpace();
}
2 changes: 1 addition & 1 deletion src/gui/folderwizard/spacespage.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SpacesPage : public QWizardPage
bool isComplete() const override;


QVariant selectedSpaceData(Spaces::SpacesModel::Columns column) const;
GraphApi::Space *currentSpace() const;

private:
Ui::SpacesPage *ui;
Expand Down
3 changes: 0 additions & 3 deletions src/gui/guiutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include <QUrl>
#include <QWidget>


class QQuickWidget;

namespace OCC {

Q_DECLARE_LOGGING_CATEGORY(lcGuiUtility)
Expand Down
1 change: 1 addition & 0 deletions src/gui/qml/FolderDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import org.ownCloud.gui 1.0
import org.ownCloud.gui.spaces 1.0

Pane {
// TODO: not cool
Expand Down
33 changes: 33 additions & 0 deletions src/gui/qmlutils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) by Hannah von Reth <hannah.vonreth@owncloud.com>
*
* 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 "gui/qmlutils.h"

#include "resources/resources.h"

#include <QMessageBox>
#include <QQuickWidget>

void OCC::QmlUtils::initQuicWidget(QQuickWidget *widget, const QUrl &src)
{
widget->engine()->addImageProvider(QStringLiteral("ownCloud"), new OCC::Resources::CoreImageProvider());
widget->setResizeMode(QQuickWidget::SizeRootObjectToView);
widget->setSource(src);
if (!widget->errors().isEmpty()) {
auto box = new QMessageBox(QMessageBox::Critical, QStringLiteral("QML Error"), QDebug::toString(widget->errors()));
box->setAttribute(Qt::WA_DeleteOnClose);
box->exec();
qFatal("A qml error occured %s", qPrintable(QDebug::toString(widget->errors())));
}
}
24 changes: 24 additions & 0 deletions src/gui/qmlutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) by Hannah von Reth <hannah.vonreth@owncloud.com>
*
* 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


class QQuickWidget;
class QUrl;

namespace OCC::QmlUtils {

void initQuicWidget(QQuickWidget *widget, const QUrl &src);
}
25 changes: 19 additions & 6 deletions src/gui/spaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
add_library(spaces
STATIC
add_library(ownCloudSpaces SHARED
spacesmodel.cpp
spacesdelegate.cpp
spacesbrowser.cpp
spacesbrowser.ui
spaceimageprovider.cpp
)
target_link_libraries(spaces PUBLIC Qt::Widgets Qt::QuickWidgets libsync owncloudResources)
set_target_properties(spaces PROPERTIES AUTOUIC ON AUTORCC ON)
apply_common_target_settings(spaces)
target_link_libraries(ownCloudSpaces PRIVATE Qt::Widgets Qt::QuickWidgets libsync owncloudResources qmlutils)
set_target_properties(ownCloudSpaces PROPERTIES AUTOUIC ON AUTORCC ON)
apply_common_target_settings(ownCloudSpaces)
generate_export_header(ownCloudSpaces
EXPORT_MACRO_NAME
SPACES_EXPORT
EXPORT_FILE_NAME spaceslib.h)

ecm_add_qml_module(ownCloudSpaces
URI org.ownCloud.gui.spaces
VERSION 1.0
NAMESPACE OCC
QML_FILES
qml/SpaceDelegate.qml
qml/SpacesView.qml
)

ecm_finalize_qml_module(ownCloudSpaces DESTINATION ${KDE_INSTALL_QMLDIR})
File renamed without changes.
95 changes: 95 additions & 0 deletions src/gui/spaces/qml/SpacesView.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (C) by Hannah von Reth <hannah.vonreth@owncloud.com>
*
* 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.
*/

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import org.ownCloud.gui 1.0
import org.ownCloud.libsync 1.0

Pane {
// TODO: not cool
readonly property real normalSize: 170

//property SpacesBrowser spacesBrowser

ScrollView {
id: scrollView
anchors.fill: parent
clip: true
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ScrollBar.vertical.policy: ScrollBar.AlwaysOn

ListView {
id: listView
anchors.fill: parent
spacing: 20
focus:true

Component.onCompleted: {
// clear the selection delayed, else the palette is messed up
currentIndex = -1
}

model: spacesBrowser.model
onCurrentItemChanged: {
spacesBrowser.currentSpace = currentItem ? currentItem.space : null
}

delegate: Pane {
id: spaceDelegate

required property int index

required property string name
required property string subtitle
required property url imageUrl
required property Space space

clip: true
width: ListView.view.width - scrollView.ScrollBar.vertical.width - 10

implicitHeight: normalSize
background: Rectangle {
color: spaceDelegate.ListView.isCurrentItem ? scrollView.palette.highlight : scrollView.palette.base
}

RowLayout {
anchors.fill: parent

spacing: 10
SpaceDelegate {
Layout.fillWidth: true
Layout.fillHeight: true

title: spaceDelegate.name
description: spaceDelegate.subtitle
imageSource: spaceDelegate.imageUrl
descriptionWrapMode: Label.WordWrap

}
}

MouseArea {
anchors.fill: parent
onClicked: {
spaceDelegate.ListView.view.currentIndex = spaceDelegate.index
spaceDelegate.forceActiveFocus()
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion src/gui/spaces/spaceimageprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
*/

#pragma once
#include "gui/spaces/spaceslib.h"

#include "libsync/account.h"

#include <QQuickImageProvider>

namespace OCC::Spaces {
class SpaceImageProvider : public QQuickImageProvider
class SPACES_EXPORT SpaceImageProvider : public QQuickImageProvider
{
Q_OBJECT
public:
Expand Down
Loading

0 comments on commit 156e465

Please sign in to comment.