diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 917739b28..f5939e91a 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -54,6 +54,7 @@ set(client_SRCS networksettings.cpp ocsjob.cpp ocssharejob.cpp + ocsshareejob.cpp openfilemanager.cpp owncloudgui.cpp owncloudsetupwizard.cpp @@ -63,6 +64,7 @@ set(client_SRCS share.cpp sharedialog.cpp shareusergroupdialog.cpp + sharee.cpp socketapi.cpp sslbutton.cpp sslerrordialog.cpp diff --git a/src/gui/ocsshareejob.cpp b/src/gui/ocsshareejob.cpp new file mode 100644 index 000000000..d62100190 --- /dev/null +++ b/src/gui/ocsshareejob.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (C) by Roeland Jago Douma + * + * 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; version 2 of the License. + * + * 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 "ocsshareejob.h" + +namespace OCC { + +OcsShareeJob::OcsShareeJob(AccountPtr account, QObject *parent) +: OcsJob(account, parent) +{ + setPath("ocs/v1.php/apps/files_sharing/api/v1/sharees"); + connect(this, SIGNAL(jobFinished(QVariantMap)), SLOT(jobDone(QVariantMap))); + +} + +void OcsShareeJob::getSharees(const QString search, + const QString itemType, + int page, + int perPage) +{ + setVerb("GET"); + + addParam(QString::fromLatin1("search"), search); + addParam(QString::fromLatin1("itemType"), itemType); + addParam(QString::fromLatin1("page"), QString::number(page)); + addParam(QString::fromLatin1("perPage"), QString::number(perPage)); + + start(); +} + +void OcsShareeJob::jobDone(const QVariantMap &reply) +{ + emit shareeJobFinished(reply); +} + +} diff --git a/src/gui/ocsshareejob.h b/src/gui/ocsshareejob.h new file mode 100644 index 000000000..208d0ff60 --- /dev/null +++ b/src/gui/ocsshareejob.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) by Roeland Jago Douma + * + * 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; version 2 of the License. + * + * 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. + */ + +#ifndef OCSSHAREEJOB_H +#define OCSSHAREEJOB_H + +#include "ocsjob.h" +#include + +namespace OCC { + +/** + * @brief The OcsShareeJob class + * @ingroup gui + * + * Fetching sharees from the OCS Sharee API + */ +class OcsShareeJob : public OcsJob { + Q_OBJECT +public: + + explicit OcsShareeJob(AccountPtr account, QObject *parent = 0); + + /** + * Get a list of sharees + * + * @param path Path to request shares for (default all shares) + */ + void getSharees(const QString search, + const QString itemType, + int page = 1, + int perPage = 50); +signals: + /** + * Result of the OCS request + * + * @param reply The reply + */ + void shareeJobFinished(const QVariantMap &reply); + +private slots: + void jobDone(const QVariantMap &reply); + +}; + +} + +#endif // OCSSHAREEJOB_H diff --git a/src/gui/sharedialogshare.ui b/src/gui/sharedialogshare.ui new file mode 100644 index 000000000..614dc94e2 --- /dev/null +++ b/src/gui/sharedialogshare.ui @@ -0,0 +1,77 @@ + + + OCC::ShareDialogShare + + + true + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + TextLabel + + + + + + + + + Permissions + + + + + + + Update + + + + + + + Create + + + + + + + Delete + + + + + + + Share + + + + + + + + + Delete + + + + + + + + diff --git a/src/gui/sharee.cpp b/src/gui/sharee.cpp new file mode 100644 index 000000000..9100f99cd --- /dev/null +++ b/src/gui/sharee.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (C) by Roeland Jago Douma + * + * 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; version 2 of the License. + * + * 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 "sharee.h" +#include "ocsshareejob.h" + +namespace OCC { + +Sharee::Sharee(const QString shareWith, + const QString displayName, + const Type type) +: _shareWith(shareWith), + _displayName(displayName), + _type(type) +{ +} + +QString Sharee::shareWith() const +{ + return _shareWith; +} + +QString Sharee::displayName() const +{ + return _displayName; +} + +Sharee::Type Sharee::type() const +{ + return _type; +} + + +ShareeModel::ShareeModel(AccountPtr account, + const QString search, + const QString type, + QObject *parent) +: QAbstractTableModel(parent), + _account(account), + _search(search), + _type(type) +{ + OcsShareeJob *job = new OcsShareeJob(_account, this); + connect(job, SIGNAL(shareeJobFinished(QVariantMap)), SLOT(shareesFetched(QVariantMap))); + job->getSharees(_search, _type, 1, 50); +} + +void ShareeModel::shareesFetched(const QVariantMap &reply) +{ + auto data = reply.value("ocs").toMap().value("data").toMap(); + + QVector> newSharees; + + /* + * Todo properly loop all of this + */ + auto exact = data.value("exact").toMap(); + { + auto user = exact.value("user").toMap(); + if (user.size() > 0) { + newSharees.append(parseSharee(user)); + } + auto group = exact.value("group").toMap(); + if (group.size() > 0) { + newSharees.append(parseSharee(group)); + } + auto remote = exact.value("remote").toMap(); + if (remote.size() > 0) { + newSharees.append(parseSharee(remote)); + } + } + + { + auto users = data.value("users").toList(); + foreach(auto user, users) { + newSharees.append(parseSharee(user.toMap())); + } + } + { + auto groups = data.value("groups").toList(); + foreach(auto group, groups) { + newSharees.append(parseSharee(group.toMap())); + } + } + { + auto remotes = data.value("remotes").toList(); + foreach(auto remote, remotes) { + newSharees.append(parseSharee(remote.toMap())); + } + } + + beginInsertRows(QModelIndex(), _sharees.size(), newSharees.size()); + _sharees += newSharees; + endInsertRows(); +} + +QSharedPointer ShareeModel::parseSharee(const QVariantMap &data) +{ + const QString displayName = data.value("label").toString(); + const QString shareWith = data.value("value").toMap().value("shareWith").toString(); + Sharee::Type type = (Sharee::Type)data.value("value").toMap().value("shareType").toInt(); + + return QSharedPointer(new Sharee(shareWith, shareWith, type)); +} + +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(); + } + } + + 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"; + } + } +} + +} diff --git a/src/gui/sharee.h b/src/gui/sharee.h new file mode 100644 index 000000000..86fcc8e79 --- /dev/null +++ b/src/gui/sharee.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) by Roeland Jago Douma + * + * 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; version 2 of the License. + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "accountfwd.h" + +namespace OCC { + +class Sharee : public QObject { +public: + + enum Type { + User = 0, + Group = 1, + Federated = 6 + }; + Q_DECLARE_FLAGS(Types, Type) + + explicit Sharee(const QString shareWith, + const QString displayName, + const Type type); + + QString shareWith() const; + QString displayName() const; + Type type() const; + + +private: + QString _shareWith; + QString _displayName; + Type _type; +}; + +class ShareeModel : public QAbstractTableModel { + Q_OBJECT +public: + explicit ShareeModel(AccountPtr account, + const QString search, + const QString type, + QObject *parent = 0); + + 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 parseSharee(const QVariantMap &data); + +private slots: + void shareesFetched(const QVariantMap &reply); + +private: + AccountPtr _account; + QString _search; + QString _type; + + QVector> _sharees; +}; + +} diff --git a/src/gui/shareusergroupdialog.cpp b/src/gui/shareusergroupdialog.cpp index 530f80b9b..0e561487a 100644 --- a/src/gui/shareusergroupdialog.cpp +++ b/src/gui/shareusergroupdialog.cpp @@ -25,12 +25,14 @@ #include "thumbnailjob.h" #include "share.h" +#include "sharee.h" #include "QProgressIndicator.h" #include #include #include #include +#include namespace OCC { @@ -50,8 +52,14 @@ ShareUserGroupDialog::ShareUserGroupDialog(AccountPtr account, const QString &sh //Is this a file or folder? _isFile = QFileInfo(localPath).isFile(); + _ui->searchPushButton->setEnabled(false); + _ui->shareeView->hide(); + _ui->searchMorePushButton->hide(); + _ui->sharePushButton->hide(); + _manager = new ShareManager(_account, this); connect(_manager, SIGNAL(sharesFetched(QList>)), SLOT(slotSharesFetched(QList>))); + connect(_manager, SIGNAL(shareCreated(QSharedPointer)), SLOT(getShares())); } void ShareUserGroupDialog::done( int r ) { @@ -65,6 +73,54 @@ ShareUserGroupDialog::~ShareUserGroupDialog() delete _ui; } +void ShareUserGroupDialog::on_shareeLineEdit_textEdited(const QString &text) +{ + if (text == "") { + _ui->searchPushButton->setEnabled(false); + } else { + _ui->searchPushButton->setEnabled(true); + } +} + +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 +} + +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::getShares() { _manager->fetchShares(_sharePath); diff --git a/src/gui/shareusergroupdialog.h b/src/gui/shareusergroupdialog.h index f6d4954fd..84afbd04f 100644 --- a/src/gui/shareusergroupdialog.h +++ b/src/gui/shareusergroupdialog.h @@ -74,12 +74,21 @@ public: bool resharingAllowed, QWidget *parent = 0); ~ShareUserGroupDialog(); + +public slots: void getShares(); private slots: void slotSharesFetched(const QList> &shares); void done( int r ); + + void on_shareeLineEdit_textEdited(const QString &text); + void on_searchPushButton_clicked(); + void on_searchMorePushButton_clicked(); + void on_sharePushButton_clicked(); + void on_shareeView_activated(); + private: Ui::ShareUserGroupDialog *_ui; AccountPtr _account; diff --git a/src/gui/shareusergroupdialog.ui b/src/gui/shareusergroupdialog.ui index 9759130c0..bdc540b1f 100644 --- a/src/gui/shareusergroupdialog.ui +++ b/src/gui/shareusergroupdialog.ui @@ -66,7 +66,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -92,21 +92,7 @@ - - - - - - - - - Share - - - - - - + @@ -117,6 +103,61 @@ + + + + + + + + + + + Search + + + + + + + + + false + + + false + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + + + Search more + + + + + + + Share + + + + + + +