Skip to content

Commit

Permalink
Move SpaceImageProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Apr 9, 2024
1 parent 40aa630 commit 8cbcb2c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "gui/accountmodalwidget.h"
#include "gui/models/models.h"
#include "gui/selectivesyncwidget.h"
#include "gui/spaces/spaceimageprovider.h"
#include "guiutility.h"
#include "oauthloginwidget.h"
#include "quotainfo.h"
Expand Down Expand Up @@ -72,7 +73,7 @@ AccountSettings::AccountSettings(const AccountStatePtr &accountState, QWidget *p
_sortModel = weightedModel;

ui->quickWidget->rootContext()->setContextProperty(QStringLiteral("ctx"), this);
ui->quickWidget->engine()->addImageProvider(QStringLiteral("space"), new SpaceImageProvider(_accountState));
ui->quickWidget->engine()->addImageProvider(QStringLiteral("space"), new Spaces::SpaceImageProvider(_accountState->account()));
ui->quickWidget->engine()->addImageProvider(QStringLiteral("ownCloud"), new Resources::CoreImageProvider());
ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/qml/FolderDelegate.qml")));
Expand Down
25 changes: 0 additions & 25 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,29 +469,4 @@ void FolderStatusModel::resetFolders()
setAccountState(_accountState);
}


SpaceImageProvider::SpaceImageProvider(AccountStatePtr accountStat)
: QQuickImageProvider(QQuickImageProvider::Pixmap, QQuickImageProvider::ForceAsynchronousImageLoading)
, _accountStat(accountStat)
{
}

QPixmap SpaceImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
// TODO: the url hast random parts to enforce a reload
const auto ids = id.split(QLatin1Char('/'));
const auto *space = _accountStat->account()->spacesManager()->space(ids.last());
QIcon icon;
if (space) {
icon = space->image();
} else {
icon = Resources::getCoreIcon(QStringLiteral("space"));
}
const QSize actualSize = requestedSize.isValid() ? requestedSize : icon.availableSizes().first();
if (size) {
*size = actualSize;
}
return icon.pixmap(actualSize);
}

} // namespace OCC
12 changes: 0 additions & 12 deletions src/gui/folderstatusmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,5 @@ private Q_SLOTS:
};


class SpaceImageProvider : public QQuickImageProvider
{
Q_OBJECT
public:
SpaceImageProvider(AccountStatePtr accountStat);
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override;


private:
AccountStatePtr _accountStat;
};

} // namespace OCC
#endif // FOLDERSTATUSMODEL_H
6 changes: 4 additions & 2 deletions src/gui/spaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ add_library(spaces
spacesmodel.cpp
spacesdelegate.cpp
spacesbrowser.cpp
spacesbrowser.ui)
target_link_libraries(spaces PUBLIC Qt::Widgets libsync owncloudResources)
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)
43 changes: 43 additions & 0 deletions src/gui/spaces/spaceimageprovider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 "spaceimageprovider.h"
#include "libsync/graphapi/spacesmanager.h"
#include "resources/resources.h"

using namespace OCC;
using namespace Spaces;

SpaceImageProvider::SpaceImageProvider(const AccountPtr &account)
: QQuickImageProvider(QQuickImageProvider::Pixmap, QQuickImageProvider::ForceAsynchronousImageLoading)
, _account(account)
{
}

QPixmap SpaceImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
// TODO: the url hast random parts to enforce a reload
const auto ids = id.split(QLatin1Char('/'));
const auto *space = _account->spacesManager()->space(ids.last());
QIcon icon;
if (space) {
icon = space->image();
} else {
icon = Resources::getCoreIcon(QStringLiteral("space"));
}
const QSize actualSize = requestedSize.isValid() ? requestedSize : icon.availableSizes().first();
if (size) {
*size = actualSize;
}
return icon.pixmap(actualSize);
}
36 changes: 36 additions & 0 deletions src/gui/spaces/spaceimageprovider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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


#include "gui/spaces/spaceslib.h"
#include "libsync/account.h"

#include <QQuickImageProvider>

namespace OCC::Spaces {
class SPACES_EXPORT SpaceImageProvider : public QQuickImageProvider
{
Q_OBJECT
public:
SpaceImageProvider(const AccountPtr &account);
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override;


private:
AccountPtr _account;
};

}

0 comments on commit 8cbcb2c

Please sign in to comment.