Skip to content

Commit fd8a62a

Browse files
committed
SpacesBrowser: Hide already sacned spaces
Fixes: #11752
1 parent 280223b commit fd8a62a

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

changelog/unreleased/11752

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHange: Only allow to add unsyced spaces
2+
3+
We now prevent users from syncing the same space multiple times.
4+
5+
6+
https://github.com/owncloud/client/issues/11752
7+
https://github.com/owncloud/client/pull/11759

src/gui/spaces/spacesbrowser.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
using namespace OCC;
2828
using namespace OCC::Spaces;
2929

30+
namespace {
31+
class SpaceFilter : public QSortFilterProxyModel
32+
{
33+
using QSortFilterProxyModel::QSortFilterProxyModel;
34+
35+
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
36+
{
37+
auto index = sourceModel()->index(sourceRow, 0, sourceParent);
38+
return index.data(static_cast<int>(SpacesModel::Roles::Enabled)).toBool() && !index.data(static_cast<int>(SpacesModel::Roles::IsSynced)).toBool();
39+
}
40+
};
41+
}
42+
3043
SpacesBrowser::SpacesBrowser(QWidget *parent)
3144
: QWidget(parent)
3245
, ui(new Ui::SpacesBrowser)
@@ -35,8 +48,7 @@ SpacesBrowser::SpacesBrowser(QWidget *parent)
3548
_model = new SpacesModel(this);
3649

3750

38-
_sortModel = new QSortFilterProxyModel(this);
39-
_sortModel->setFilterRole(static_cast<int>(SpacesModel::Roles::Enabled));
51+
_sortModel = new SpaceFilter(this);
4052
_sortModel->setSourceModel(_model);
4153
_sortModel->setSortRole(static_cast<int>(SpacesModel::Roles::Priority));
4254
_sortModel->sort(0, Qt::DescendingOrder);

src/gui/spaces/spacesmodel.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
#include "spacesmodel.h"
1515

16+
#include "gui/folderman.h"
1617
#include "libsync/graphapi/spacesmanager.h"
1718

1819
#include <QIcon>
@@ -38,11 +39,10 @@ QVariant SpacesModel::data(const QModelIndex &index, int role) const
3839
{
3940
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid));
4041

41-
const auto *space = _spacesList.at(index.row());
42+
auto *space = _spacesList.at(index.row());
4243
switch (static_cast<Roles>(role)) {
43-
case Roles::Sync:
44-
// TODO: return true if we alreaddy sync the space
45-
return false;
44+
case Roles::IsSynced:
45+
return FolderMan::instance()->isSpaceSynced(space);
4646
case Roles::Name:
4747
return space->displayName();
4848
case Roles::Subtitle:

src/gui/spaces/spacesmodel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SpacesModel : public QAbstractListModel
3030
public:
3131
enum class Roles {
3232
AccessibleDescriptionRole = Qt::AccessibleDescriptionRole,
33-
Sync = Qt::UserRole + 1,
33+
IsSynced = Qt::UserRole + 1,
3434
Name,
3535
Subtitle,
3636
WebUrl,

0 commit comments

Comments
 (0)