Skip to content
Draft
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
21 changes: 19 additions & 2 deletions src/gui/FoldersGui/accountfolderscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ AccountFoldersController::AccountFoldersController(AccountState *state, AccountF
_sortModel = weightedModel;
*/

_view->setItemModel(model);
_view->setItemModels(model, modelController->selectionModel());

buildMenuActions();

connect(_view, &AccountFoldersView::addFolderTriggered, this, &AccountFoldersController::slotAddFolder);
// ui->quickWidget->engine()->addImageProvider(QStringLiteral("space"), new Spaces::SpaceImageProvider(_accountState->account()->spacesManager()));
Expand Down Expand Up @@ -123,28 +125,40 @@ void AccountFoldersController::slotFolderWizardAccepted(OCC::FolderMan::SyncConn

void AccountFoldersController::buildMenuActions()
{
QList<QAction *> itemActions;

// show in finder
_showInSystemFolder = new QAction(CommonStrings::showInFileBrowser(), this);
itemActions.push_back(_showInSystemFolder);
connect(_showInSystemFolder, &QAction::triggered, this, &AccountFoldersController::onShowInSystemFolder);

if (_accountState->account()->capabilities().privateLinkPropertyAvailable()) {
_showInBrowser = new QAction(CommonStrings::showInWebBrowser(), this);
itemActions.push_back(_showInBrowser);
connect(_showInBrowser, &QAction::triggered, this, &AccountFoldersController::onShowInBrowser);
}

QAction *separator = new QAction(this);
separator->setSeparator(true);
itemActions.push_back(separator);

_forceSync = new QAction(tr("Force sync now"), this);
itemActions.push_back(_forceSync);
connect(_forceSync, &QAction::triggered, this, &AccountFoldersController::onForceSync);

_pauseSync = new QAction(this);
itemActions.push_back(_pauseSync);
connect(_pauseSync, &QAction::triggered, this, &AccountFoldersController::onTogglePauseSync);

_removeSync = new QAction(tr("Remove folder sync connection"), this);
itemActions.push_back(_removeSync);
connect(_removeSync, &QAction::triggered, this, &AccountFoldersController::onRemoveSync);

// we may want to treat this similar to the enable vfs option, because choose sync can only be activated
// if the folder is not using vfs. So the idea is if force vfs is on the user will never be able to choose
// so showing the option at all is probably not great
_chooseSync = new QAction(tr("Choose what to sync"), this);
itemActions.push_back(_chooseSync);
connect(_chooseSync, &QAction::triggered, this, &AccountFoldersController::onChooseSync);


Expand Down Expand Up @@ -176,6 +190,9 @@ void AccountFoldersController::buildMenuActions()
}
_enableVfs = new QAction(this);
*/

connect(_view, &AccountFoldersView::requestActionsUpdate, this, &AccountFoldersController::updateActions);
_view->setFolderActions(itemActions);
}


Expand Down Expand Up @@ -337,7 +354,7 @@ void AccountFoldersController::buildMenuActions()

void AccountFoldersController::updateActions()
{
if (!_currentFolder)
if (!_currentFolder) // probably disable all actions here
return;

_showInSystemFolder->setEnabled(QFileInfo::exists(_currentFolder->path()));
Expand Down
3 changes: 2 additions & 1 deletion src/gui/FoldersGui/accountfolderscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ protected slots:
QPointer<Folder> _currentFolder = nullptr;
AccountFoldersView *_view = nullptr;
FolderModelController *_modelController = nullptr;

void buildMenuActions();
void updateActions();

// menu actions:
QAction *_showInSystemFolder = nullptr;
Expand All @@ -73,6 +75,5 @@ protected slots:
void onTogglePauseSync();
void onRemoveSync();
void onChooseSync();
void updateActions();
};
}
29 changes: 27 additions & 2 deletions src/gui/FoldersGui/accountfoldersview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTreeView>
Expand All @@ -29,6 +30,7 @@ AccountFoldersView::AccountFoldersView(QWidget *parent)
: QWidget{parent}
{
buildView();
_itemMenu = new QMenu(this);
}

void AccountFoldersView::buildView()
Expand Down Expand Up @@ -56,7 +58,10 @@ void AccountFoldersView::buildView()
// I'm not sure always off is good but that's what we currently have
_treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_treeView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
_treeView->setLineWidth(2);

_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(_treeView, &QWidget::customContextMenuRequested, this, &AccountFoldersView::popItemMenu);

mainLayout->addWidget(_treeView);


Expand All @@ -67,9 +72,14 @@ void AccountFoldersView::buildView()
setLayout(mainLayout);
}

void AccountFoldersView::setItemModel(QStandardItemModel *model)
void AccountFoldersView::setItemModels(QStandardItemModel *model, QItemSelectionModel *selectionModel)
{
// order here is important, if you set the selection model before the main model the selection model for the view
// reverts to the "default" selectionModel.
// also the tree view doesn't manage the lifetime of the selection model so we could/possibly should delete the default here
// I'll check that out
_treeView->setModel(model);
_treeView->setSelectionModel(selectionModel);
}

void AccountFoldersView::setSyncedFolderCount(int synced, int total)
Expand All @@ -81,4 +91,19 @@ void AccountFoldersView::enableAddFolder(bool enableAdd)
{
_addFolderButton->setEnabled(enableAdd);
}

void AccountFoldersView::setFolderActions(QList<QAction *> actions)
{
if (_itemMenu) {
_itemMenu->clear();
_itemMenu->addActions(actions);
}
}

void AccountFoldersView::popItemMenu(const QPoint &pos)
{
emit requestActionsUpdate();

_itemMenu->exec(_treeView->viewport()->mapToGlobal(pos));
}
}
8 changes: 7 additions & 1 deletion src/gui/FoldersGui/accountfoldersview.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include <QWidget>

class QStandardItemModel;
class QItemSelectionModel;
class QTreeView;
class QLabel;
class QPushButton;
class QMenu;

namespace OCC {

Expand All @@ -28,19 +30,23 @@ class AccountFoldersView : public QWidget
public:
explicit AccountFoldersView(QWidget *parent = nullptr);

void setItemModel(QStandardItemModel *model);
void setItemModels(QStandardItemModel *model, QItemSelectionModel *selectionModel);
void setFolderActions(QList<QAction *> actions);
void setSyncedFolderCount(int synced, int total);
void enableAddFolder(bool enableAdd);
void setMenuActions(QList<QAction *> actions);

signals:
void addFolderTriggered();
void requestActionsUpdate();

private:
void buildView();
void popItemMenu(const QPoint &pos);

QTreeView *_treeView = nullptr;
QLabel *_syncedFolderCountLabel = nullptr;
QPushButton *_addFolderButton = nullptr;
QMenu *_itemMenu = nullptr;
};
}
1 change: 1 addition & 0 deletions src/gui/FoldersGui/foldermodelcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FolderModelController : public QObject
explicit FolderModelController(const QUuid &accountId, QObject *parent);

QStandardItemModel *itemModel() const { return _model; }
QItemSelectionModel *selectionModel() const { return _selectionModel; }

// getting creative to allow connecting to folderman via dependency injection. its a bit weird but let's see how it is
// note we don't want to pass folderman to the ctr as we only need to connect to it, don't want it to be a member,
Expand Down
1 change: 1 addition & 0 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ void FolderMan::addFolderFromGui(AccountState *accountState, const SyncConnectio

if (_unsyncedSpaces.contains(accountId) && _unsyncedSpaces[accountId].contains(f->spaceId()))
{
_unsyncedSpaces[accountId].remove(f->spaceId());
emit unsyncedSpaceCountChanged(accountId, _unsyncedSpaces[accountId].count(), accountState->account()->spacesManager()->spacesCount());
}

Expand Down
Loading