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
6 changes: 4 additions & 2 deletions src/gui/FoldersGui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
target_sources(owncloudGui PRIVATE
folderitem.cpp
folderitem.h
folderitemdelegate.cpp
folderitemdelegate.h
foldererroritem.cpp
foldererroritem.h
foldermodelcontroller.cpp
foldermodelcontroller.h
folderstatusupdater.cpp
folderstatusupdater.h
accountfoldersview.cpp
accountfoldersview.h
folderitemupdater.cpp
folderitemupdater.h
accountfolderscontroller.cpp
accountfolderscontroller.h
buttondelegate.cpp
buttondelegate.h
)

39 changes: 16 additions & 23 deletions src/gui/FoldersGui/accountfolderscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,20 @@ AccountFoldersController::AccountFoldersController(AccountState *state, AccountF
return;

_accountId = _accountState->account()->uuid();

buildMenuActions();

FolderModelController *modelController = new FolderModelController(_accountId, this);
connect(modelController, &FolderModelController::currentFolderChanged, this, &AccountFoldersController::onFolderChanged);

QStandardItemModel *model = modelController->itemModel();

/* we should probably simplify to use QStandardItemModel::sort with the sort
* data role on the folder item specialized to do the calc.
*
* auto weightedModel = new QSortFilterProxyModel(this);
weightedModel->setSourceModel(model);
weightedModel->setSortRole(static_cast<int>(FolderStatusModel::Roles::Priority));
weightedModel->sort(0, Qt::DescendingOrder);

_sortModel = weightedModel;
*/

_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()));
// ui->quickWidget->setOCContext(QUrl(QStringLiteral("qrc:/qt/qml/org/ownCloud/gui/qml/FolderDelegate.qml")), this);


FolderMan *folderMan = FolderMan::instance();
modelController->connectSignals(folderMan);
// next step: move the synced folder watching out of folder man and put it in a separate class. this can be used
// for updating the synced folder count and for managing the unsynced list in the folder wizard

connect(folderMan, &FolderMan::unsyncedSpaceCountChanged, this, &AccountFoldersController::onUnsyncedSpaceCountChanged);
}

Expand All @@ -92,7 +77,14 @@ void AccountFoldersController::onUnsyncedSpaceCountChanged(const QUuid &accountI

void AccountFoldersController::onFolderChanged(OCC::Folder *folder)
{
if (_currentFolder == folder)
return;

_currentFolder = folder;
// thought to only do this here instead of trying to trigger the refresh before showing the menu since it's more complicated
// to trigger the refresh from the menu button.
// this doesn't really work eg if you use the menu to pause sync, then open the menu again - it won't get refreshed to show resume sync
updateActions();
}

void AccountFoldersController::slotAddFolder()
Expand Down Expand Up @@ -152,10 +144,6 @@ void AccountFoldersController::buildMenuActions()
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);

_chooseSync = new QAction(tr("Choose what to sync"), this);

Vfs::Mode mode = VfsPluginManager::instance().bestAvailableVfsMode();
Expand Down Expand Up @@ -183,6 +171,10 @@ void AccountFoldersController::buildMenuActions()
connect(_chooseSync, &QAction::triggered, this, &AccountFoldersController::onChooseSync);
}

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

connect(_view, &AccountFoldersView::requestActionsUpdate, this, &AccountFoldersController::updateActions);
_view->setFolderActions(itemActions);
}
Expand Down Expand Up @@ -229,6 +221,7 @@ void AccountFoldersController::updateActions()
// obvs we don't want to try to access values that aren't there
// furthermore, we do need to disable if the current folder selection
// is empty so it's actually a key part of the evaluation for action state here
// so doing a general if(!_curentFolder) return; handling is not correct
_showInSystemFolder->setEnabled(_currentFolder && QFileInfo::exists(_currentFolder->path()));

if (_showInBrowser)
Expand Down
34 changes: 30 additions & 4 deletions src/gui/FoldersGui/accountfoldersview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
#include "accountfoldersview.h"

#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QMenu>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTreeView>
#include <QVBoxLayout>

#include "buttondelegate.h"
#include "folderitemdelegate.h"
#include "theme.h"

namespace OCC {
Expand All @@ -29,9 +32,10 @@ namespace OCC {
AccountFoldersView::AccountFoldersView(QWidget *parent)
: QWidget{parent}
{
buildView();
_itemMenu = new QMenu(this);
_itemMenu->setAccessibleName(tr("Sync options menu"));

buildView();
}

void AccountFoldersView::buildView()
Expand All @@ -54,18 +58,40 @@ void AccountFoldersView::buildView()
mainLayout->addLayout(buttonLineLayout);

_treeView = new QTreeView(this);
_treeView->setHeaderHidden(true);
_treeView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// I'm not sure always off is good but that's what we currently have
_treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_treeView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
_treeView->setIndentation(0);
_treeView->setSelectionMode(QAbstractItemView::SingleSelection);
_treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
_treeView->setAllColumnsShowFocus(true);

// I think this needs to move to a slot connected to QHeaderView::sectionCountChanged - in theory the logical indexes
// will have been created by that point?!
QHeaderView *header = _treeView->header();
header->setSectionsMovable(false);
header->setStretchLastSection(false); // this is useless - so far the last section still stretches
//_treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch); // ->this does not work/crashes.I think the "logical index" does not yet exist but
// WHEN does it get created?! I try updating the header after the model is set and it crashes there too. I do not get it.
header->setSectionResizeMode(QHeaderView::Stretch); // this at least splits the available space between first and second column.
_treeView->setHeaderHidden(true);


FolderItemDelegate *delegate = new FolderItemDelegate(_treeView);
_treeView->setItemDelegateForColumn(0, delegate);
ButtonDelegate *buttonDel = new ButtonDelegate(_treeView);
buttonDel->setMenu(_itemMenu);
_treeView->setItemDelegateForColumn(1, buttonDel);

// this works but only when the button item is current. this means I have to set the button column to current each time row selection
// changes but it works well so far.
_treeView->setEditTriggers(QAbstractItemView::CurrentChanged);
_treeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(_treeView, &QWidget::customContextMenuRequested, this, &AccountFoldersView::popItemMenu);

mainLayout->addWidget(_treeView);


_syncedFolderCountLabel = new QLabel("placeholder for sync count", this);
_syncedFolderCountLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
mainLayout->addWidget(_syncedFolderCountLabel, 0, Qt::AlignLeft);
Expand All @@ -80,7 +106,7 @@ void AccountFoldersView::setItemModels(QStandardItemModel *model, QItemSelection
// 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);
_treeView->setSelectionModel(selectionModel);
}

void AccountFoldersView::setSyncedFolderCount(int synced, int total)
Expand Down
72 changes: 72 additions & 0 deletions src/gui/FoldersGui/buttondelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) Lisa Reese <[email protected]>
*
* 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 "buttondelegate.h"

#include <QPainter>
#include <QPushButton>

namespace OCC {

ButtonDelegate::ButtonDelegate(QObject *parent)
: QItemDelegate{parent}
{
_button = new QPushButton("...");
}

void ButtonDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
drawBackground(painter, option, index);
drawDisplay(painter, option, option.rect, "...");
painter->save();
// QRect dotsRect = option.rect;
// painter->drawLine()
painter->setPen(QPen(QBrush("#807F7F7F"), 1));
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
painter->restore();

drawFocus(painter, option, option.rect);
}

QSize ButtonDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
return QSize(75, option.rect.height());
}

QWidget *ButtonDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(index);

if (_button->parent() != parent)
// the parent is actually the scroll area viewport. don't ask :D
_button->setParent(parent);
_button->setGeometry(option.rect);
// maybe we need to refresh the menu but I think the row will be auto-selected on any click, including in the button area
return _button;
}

void ButtonDelegate::destroyEditor(QWidget *widget, const QModelIndex &index) const
{
// base impl calls delete later on the editor widget.
// but we don't want to delete the button, just re-use it. it should go away naturally when the
// viewport is deleted.
}

void ButtonDelegate::setMenu(QMenu *menu)
{
_button->setMenu(menu);
}


}
38 changes: 38 additions & 0 deletions src/gui/FoldersGui/buttondelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) Lisa Reese <[email protected]>
*
* 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 <QItemDelegate>

class QPushButton;

namespace OCC {

class ButtonDelegate : public QItemDelegate
{
public:
ButtonDelegate(QObject *parent);

void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;

QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void destroyEditor(QWidget *editor, const QModelIndex &index) const override;
void setMenu(QMenu *menu);

private:
QPushButton *_button = nullptr;
};
}
9 changes: 8 additions & 1 deletion src/gui/FoldersGui/foldererroritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
#include "foldererroritem.h"
#include "folderitem.h"

namespace OCC {

FolderErrorItem::FolderErrorItem(FolderItem *parent) { }
FolderErrorItem::FolderErrorItem(FolderItem *parent)
: QStandardItem()
, _parent(parent)
{
}

}
9 changes: 6 additions & 3 deletions src/gui/FoldersGui/foldererroritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

#pragma once

#include <QStandardItem>

namespace OCC {

class FolderItem;

/**
Expand All @@ -22,12 +26,11 @@ class FolderItem;
* the error items will be children of the related FolderItem
*
*/
class FolderErrorItem
class FolderErrorItem : public QStandardItem
{
FolderErrorItem(FolderItem *parent);

private:
FolderItem *_parent;
};


}
Loading