[Pkg-owncloud-commits] [owncloud-client] 258/484: [Sharing] Allow sharing with users/groups from desktop
Sandro Knauß
hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:50 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 90cbd461ab3e7ce6c4a5bf5aa03117409f65e2ab
Author: Roeland Jago Douma <rullzer at owncloud.com>
Date: Wed Nov 4 22:00:35 2015 +0100
[Sharing] Allow sharing with users/groups from desktop
---
src/gui/share.cpp | 17 +++++++--
src/gui/share.h | 9 +++--
src/gui/sharee.cpp | 82 ++++++++++++++++++++--------------------
src/gui/sharee.h | 23 +++++++----
src/gui/shareusergroupdialog.cpp | 73 +++++++++++++++++------------------
src/gui/shareusergroupdialog.h | 16 +++++---
src/gui/shareusergroupdialog.ui | 53 +++-----------------------
7 files changed, 127 insertions(+), 146 deletions(-)
diff --git a/src/gui/share.cpp b/src/gui/share.cpp
index 0af7425..e5525a4 100644
--- a/src/gui/share.cpp
+++ b/src/gui/share.cpp
@@ -24,7 +24,7 @@ Share::Share(AccountPtr account,
const QString& path,
const ShareType shareType,
const Permissions permissions,
- const QString shareWith)
+ const QSharedPointer<Sharee> shareWith)
: _account(account),
_id(id),
_path(path),
@@ -45,6 +45,11 @@ Share::ShareType Share::getShareType() const
return _shareType;
}
+QSharedPointer<Sharee> Share::getShareWith() const
+{
+ return _shareWith;
+}
+
void Share::setPermissions(Permissions permissions)
{
OcsShareJob *job = new OcsShareJob(_account, this);
@@ -288,14 +293,18 @@ QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QVariantMap &data)
expireDate));
}
-QSharedPointer<Share> ShareManager::parseShare(const QVariantMap &data) {
-
+QSharedPointer<Share> ShareManager::parseShare(const QVariantMap &data)
+{
+ QSharedPointer<Sharee> sharee(new Sharee(data.value("share_with").toString(),
+ data.value("share_with_displayname").toString(),
+ (Sharee::Type)data.value("share_type").toInt()));
+
return QSharedPointer<Share>(new Share(_account,
data.value("id").toString(),
data.value("path").toString(),
(Share::ShareType)data.value("share_type").toInt(),
(Share::Permissions)data.value("permissions").toInt(),
- data.value("share_with").toString()));
+ sharee));
}
void ShareManager::slotOcsError(int statusCode, const QString &message)
diff --git a/src/gui/share.h b/src/gui/share.h
index 3962fca..ae052e0 100644
--- a/src/gui/share.h
+++ b/src/gui/share.h
@@ -15,6 +15,7 @@
#define SHARE_H
#include "accountfwd.h"
+#include "sharee.h"
#include <QObject>
#include <QDate>
@@ -37,7 +38,7 @@ public:
TypeUser = 0,
TypeGroup = 1,
TypeLink = 3,
- TypeRemote = 6,
+ TypeRemote = 6
};
Q_DECLARE_FLAGS(ShareTypes, ShareType)
@@ -61,7 +62,7 @@ public:
const QString& path,
const ShareType shareType,
const Permissions permissions,
- const QString shareWith = "");
+ const QSharedPointer<Sharee> shareWith = QSharedPointer<Sharee>(NULL));
/*
* Get the id
@@ -76,7 +77,7 @@ public:
/*
* Get the shareWith
*/
- QString getShareWith() const;
+ QSharedPointer<Sharee> getShareWith() const;
/*
* Get permissions
@@ -110,7 +111,7 @@ protected:
QString _path;
ShareType _shareType;
Permissions _permissions;
- QString _shareWith;
+ QSharedPointer<Sharee> _shareWith;
protected slots:
void slotOcsError(int statusCode, const QString &message);
diff --git a/src/gui/sharee.cpp b/src/gui/sharee.cpp
index 9100f99..0fb98d0 100644
--- a/src/gui/sharee.cpp
+++ b/src/gui/sharee.cpp
@@ -24,7 +24,20 @@ Sharee::Sharee(const QString shareWith,
_type(type)
{
}
-
+
+QString Sharee::format() const
+{
+ QString formatted = _displayName;
+
+ if (_type == Type::Group) {
+ formatted += QLatin1String(" (group)");
+ } else if (_type == Type::Federated) {
+ formatted += QLatin1String(" (remote)");
+ }
+
+ return formatted;
+}
+
QString Sharee::shareWith() const
{
return _shareWith;
@@ -40,16 +53,20 @@ Sharee::Type Sharee::type() const
return _type;
}
-
ShareeModel::ShareeModel(AccountPtr account,
const QString search,
const QString type,
QObject *parent)
-: QAbstractTableModel(parent),
+: QAbstractListModel(parent),
_account(account),
_search(search),
_type(type)
{
+
+}
+
+void ShareeModel::fetch()
+{
OcsShareeJob *job = new OcsShareeJob(_account, this);
connect(job, SIGNAL(shareeJobFinished(QVariantMap)), SLOT(shareesFetched(QVariantMap)));
job->getSharees(_search, _type, 1, 50);
@@ -66,17 +83,17 @@ void ShareeModel::shareesFetched(const QVariantMap &reply)
*/
auto exact = data.value("exact").toMap();
{
- auto user = exact.value("user").toMap();
- if (user.size() > 0) {
- newSharees.append(parseSharee(user));
+ auto users = exact.value("users").toList();
+ foreach(auto user, users) {
+ newSharees.append(parseSharee(user.toMap()));
}
- auto group = exact.value("group").toMap();
- if (group.size() > 0) {
- newSharees.append(parseSharee(group));
+ auto groups = exact.value("groups").toList();
+ foreach(auto group, groups) {
+ newSharees.append(parseSharee(group.toMap()));
}
- auto remote = exact.value("remote").toMap();
- if (remote.size() > 0) {
- newSharees.append(parseSharee(remote));
+ auto remotes = exact.value("remotes").toList();
+ foreach(auto remote, remotes) {
+ newSharees.append(parseSharee(remote.toMap()));
}
}
@@ -102,6 +119,8 @@ void ShareeModel::shareesFetched(const QVariantMap &reply)
beginInsertRows(QModelIndex(), _sharees.size(), newSharees.size());
_sharees += newSharees;
endInsertRows();
+
+ shareesReady();
}
QSharedPointer<Sharee> ShareeModel::parseSharee(const QVariantMap &data)
@@ -118,42 +137,25 @@ int ShareeModel::rowCount(const QModelIndex &) const
return _sharees.size();
}
-int ShareeModel::columnCount(const QModelIndex &) const
-{
- return 3;
-}
-
QVariant ShareeModel::data(const QModelIndex &index, int role) const
{
- if (role == Qt::DisplayRole) {
- auto sharee = _sharees.at(index.row());
-
- switch(index.column()) {
- case 0:
- return sharee->displayName();
- case 1:
- return sharee->type();
- case 2:
- return sharee->shareWith();
- }
+ if (index.row() < 0 || index.row() > _sharees.size()) {
+ return QVariant();
+ }
+
+ if (role == Qt::DisplayRole || role == Qt::EditRole) {
+ return _sharees.at(index.row())->format();
}
return QVariant();
}
-QVariant ShareeModel::headerData(int section, Qt::Orientation orientation, int role)
-{
- qDebug() << Q_FUNC_INFO << section << orientation << role;
- if (orientation == Qt::Horizontal) {
- switch(section) {
- case 0:
- return "Name";
- case 1:
- return "Type";
- case 2:
- return "Id";
- }
+QSharedPointer<Sharee> ShareeModel::getSharee(int at) {
+ if (at < 0 || at > _sharees.size()) {
+ return QSharedPointer<Sharee>(NULL);
}
+
+ return _sharees.at(at);
}
}
diff --git a/src/gui/sharee.h b/src/gui/sharee.h
index 86fcc8e..33a308b 100644
--- a/src/gui/sharee.h
+++ b/src/gui/sharee.h
@@ -11,9 +11,12 @@
* for more details.
*/
+#ifndef SHAREE_H
+#define SHAREE_H
+
#include <QObject>
#include <QFlags>
-#include <QAbstractTableModel>
+#include <QAbstractListModel>
#include <QModelIndex>
#include <QVariant>
#include <QSharedPointer>
@@ -23,7 +26,7 @@
namespace OCC {
-class Sharee : public QObject {
+class Sharee {
public:
enum Type {
@@ -37,10 +40,10 @@ public:
const QString displayName,
const Type type);
+ QString format() const;
QString shareWith() const;
QString displayName() const;
Type type() const;
-
private:
QString _shareWith;
@@ -48,7 +51,7 @@ private:
Type _type;
};
-class ShareeModel : public QAbstractTableModel {
+class ShareeModel : public QAbstractListModel {
Q_OBJECT
public:
explicit ShareeModel(AccountPtr account,
@@ -56,17 +59,21 @@ public:
const QString type,
QObject *parent = 0);
+ void fetch();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole);
- QSharedPointer<Sharee> parseSharee(const QVariantMap &data);
+ QSharedPointer<Sharee> getSharee(int at);
+
+signals:
+ void shareesReady();
private slots:
void shareesFetched(const QVariantMap &reply);
private:
+ QSharedPointer<Sharee> parseSharee(const QVariantMap &data);
+
AccountPtr _account;
QString _search;
QString _type;
@@ -75,3 +82,5 @@ private:
};
}
+
+#endif //SHAREE_H
diff --git a/src/gui/shareusergroupdialog.cpp b/src/gui/shareusergroupdialog.cpp
index 0e56148..0799869 100644
--- a/src/gui/shareusergroupdialog.cpp
+++ b/src/gui/shareusergroupdialog.cpp
@@ -52,14 +52,16 @@ ShareUserGroupDialog::ShareUserGroupDialog(AccountPtr account, const QString &sh
//Is this a file or folder?
_isFile = QFileInfo(localPath).isFile();
+ _completer = new QCompleter(this);
+ _ui->shareeLineEdit->setCompleter(_completer);
+
_ui->searchPushButton->setEnabled(false);
- _ui->shareeView->hide();
- _ui->searchMorePushButton->hide();
- _ui->sharePushButton->hide();
_manager = new ShareManager(_account, this);
connect(_manager, SIGNAL(sharesFetched(QList<QSharedPointer<Share>>)), SLOT(slotSharesFetched(QList<QSharedPointer<Share>>)));
connect(_manager, SIGNAL(shareCreated(QSharedPointer<Share>)), SLOT(getShares()));
+ connect(_ui->shareeLineEdit, SIGNAL(returnPressed()), SLOT(on_searchPushButton_clicked()));
+ connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex)));
}
void ShareUserGroupDialog::done( int r ) {
@@ -73,7 +75,7 @@ ShareUserGroupDialog::~ShareUserGroupDialog()
delete _ui;
}
-void ShareUserGroupDialog::on_shareeLineEdit_textEdited(const QString &text)
+void ShareUserGroupDialog::on_shareeLineEdit_textChanged(const QString &text)
{
if (text == "") {
_ui->searchPushButton->setEnabled(false);
@@ -84,41 +86,18 @@ void ShareUserGroupDialog::on_shareeLineEdit_textEdited(const QString &text)
void ShareUserGroupDialog::on_searchPushButton_clicked()
{
- ShareeModel *model = new ShareeModel(_account,
- _ui->shareeLineEdit->text(),
- _isFile ? QLatin1String("file") : QLatin1String("folder"),
- _ui->shareeView);
- _ui->shareeView->setModel(model);
-
- _ui->shareeView->show();
- _ui->searchMorePushButton->show();
- _ui->sharePushButton->show();
- _ui->sharePushButton->setEnabled(false);
-}
-
-void ShareUserGroupDialog::on_searchMorePushButton_clicked()
-{
- //TODO IMPLEMENT
+ _completerModel = new ShareeModel(_account,
+ _ui->shareeLineEdit->text(),
+ _isFile ? QLatin1String("file") : QLatin1String("folder"),
+ _completer);
+ connect(_completerModel, SIGNAL(shareesReady()), SLOT(slotUpdateCompletion()));
+ _completerModel->fetch();
}
-void ShareUserGroupDialog::on_shareeView_activated()
-{
- _ui->sharePushButton->setEnabled(true);
-}
-
-void ShareUserGroupDialog::on_sharePushButton_clicked()
-{
- const QModelIndex index = _ui->shareeView->currentIndex();
-
- auto model = _ui->shareeView->model();
-
- const QModelIndex shareWithIndex = model->index(index.row(), 2);
- const QModelIndex typeIndex = model->index(index.row(), 1);
-
- QString shareWith = model->data(shareWithIndex, Qt::DisplayRole).toString();
- int type = model->data(typeIndex, Qt::DisplayRole).toInt();
-
- _manager->createShare(_sharePath, (Share::ShareType)type, shareWith, Share::PermissionRead);
+void ShareUserGroupDialog::slotUpdateCompletion() {
+ _completer->setModel(_completerModel);
+ _ui->shareeLineEdit->setCompleter(_completer);
+ _completer->complete();
}
void ShareUserGroupDialog::getShares()
@@ -131,7 +110,10 @@ void ShareUserGroupDialog::slotSharesFetched(const QList<QSharedPointer<Share>>
const QString versionString = _account->serverVersion();
qDebug() << Q_FUNC_INFO << versionString << "Fetched" << shares.count() << "shares";
- // TODO clear old shares
+ QLayoutItem *child;
+ while ((child = _ui->sharesLayout->takeAt(0)) != 0) {
+ delete child;
+ }
foreach(const auto &share, shares) {
@@ -142,9 +124,20 @@ void ShareUserGroupDialog::slotSharesFetched(const QList<QSharedPointer<Share>>
ShareDialogShare *s = new ShareDialogShare(share, this);
_ui->sharesLayout->addWidget(s);
}
+ _ui->sharesLayout->invalidate();
+}
+
+void ShareUserGroupDialog::slotCompleterActivated(const QModelIndex & index) {
+ auto sharee = _completerModel->getSharee(index.row());
- // Add all new shares to share list
+ if (sharee.isNull()) {
+ return;
+ }
+ _manager->createShare(_sharePath,
+ (Share::ShareType)sharee->type(),
+ sharee->shareWith(),
+ Share::PermissionRead);
}
ShareDialogShare::ShareDialogShare(QSharedPointer<Share> share,
@@ -155,6 +148,8 @@ ShareDialogShare::ShareDialogShare(QSharedPointer<Share> share,
{
_ui->setupUi(this);
+ _ui->sharedWith->setText(share->getShareWith()->format());
+
if (share->getPermissions() & Share::PermissionUpdate) {
_ui->permissionUpdate->setCheckState(Qt::Checked);
}
diff --git a/src/gui/shareusergroupdialog.h b/src/gui/shareusergroupdialog.h
index 84afbd0..9a53432 100644
--- a/src/gui/shareusergroupdialog.h
+++ b/src/gui/shareusergroupdialog.h
@@ -22,6 +22,9 @@
#include <QSharedPointer>
#include <QList>
+
+class QCompleter;
+
namespace OCC {
namespace Ui {
@@ -34,6 +37,7 @@ class QuotaInfo;
class SyncResult;
class Share;
class ShareManager;
+class ShareeModel;
class ShareDialogShare : public QWidget
{
@@ -83,11 +87,11 @@ private slots:
void done( int r );
- void on_shareeLineEdit_textEdited(const QString &text);
+ void on_shareeLineEdit_textChanged(const QString &text);
void on_searchPushButton_clicked();
- void on_searchMorePushButton_clicked();
- void on_sharePushButton_clicked();
- void on_shareeView_activated();
+
+ void slotUpdateCompletion();
+ void slotCompleterActivated(const QModelIndex & index);
private:
Ui::ShareUserGroupDialog *_ui;
@@ -95,11 +99,13 @@ private:
QString _sharePath;
QString _localPath;
+ QCompleter *_completer;
+ ShareeModel *_completerModel;
+
bool _resharingAllowed;
bool _isFile;
ShareManager *_manager;
- QList<ShareDialogShare*> _shares;
};
}
diff --git a/src/gui/shareusergroupdialog.ui b/src/gui/shareusergroupdialog.ui
index bdc540b..99c337d 100644
--- a/src/gui/shareusergroupdialog.ui
+++ b/src/gui/shareusergroupdialog.ui
@@ -103,59 +103,18 @@
</item>
</layout>
</item>
- <item row="2" column="0">
- <layout class="QVBoxLayout" name="verticalLayout">
+ <item row="1" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLineEdit" name="shareeLineEdit"/>
- </item>
- <item>
- <widget class="QPushButton" name="searchPushButton">
- <property name="text">
- <string>Search</string>
- </property>
- </widget>
- </item>
- </layout>
+ <widget class="QLineEdit" name="shareeLineEdit"/>
</item>
<item>
- <widget class="QTableView" name="shareeView">
- <property name="showDropIndicator" stdset="0">
- <bool>false</bool>
- </property>
- <property name="dragDropOverwriteMode">
- <bool>false</bool>
- </property>
- <property name="selectionMode">
- <enum>QAbstractItemView::SingleSelection</enum>
- </property>
- <property name="selectionBehavior">
- <enum>QAbstractItemView::SelectRows</enum>
+ <widget class="QPushButton" name="searchPushButton">
+ <property name="text">
+ <string>Search</string>
</property>
- <attribute name="verticalHeaderVisible">
- <bool>false</bool>
- </attribute>
</widget>
</item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_3">
- <item>
- <widget class="QPushButton" name="searchMorePushButton">
- <property name="text">
- <string>Search more</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="sharePushButton">
- <property name="text">
- <string>Share</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
</layout>
</item>
</layout>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list