diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp index 9c8482250..0b0ac83c3 100644 --- a/src/gui/sharemanager.cpp +++ b/src/gui/sharemanager.cpp @@ -278,6 +278,34 @@ void LinkShare::slotNameSet(const QJsonDocument &, const QVariant &value) emit nameSet(); } +UserGroupShare::UserGroupShare(AccountPtr account, + const QString &id, + const QString &owner, + const QString &ownerDisplayName, + const QString &path, + const ShareType shareType, + const Permissions permissions, + const QSharedPointer shareWith) + : Share(account, id, owner, ownerDisplayName, path, shareType, permissions, shareWith) +{ + Q_ASSERT(shareType == TypeUser || shareType == TypeGroup); + Q_ASSERT(shareWith); +} + +void UserGroupShare::setNote(const QString ¬e) +{ + auto *job = new OcsShareJob(_account); + connect(job, &OcsShareJob::shareJobFinished, this, &UserGroupShare::slotNoteSet); + connect(job, &OcsJob::ocsError, this, &UserGroupShare::slotOcsError); + job->setNote(getId(), note); +} + +void UserGroupShare::slotNoteSet(const QJsonDocument &, const QVariant ¬e) +{ + _note = note.toString(); + emit noteSet(); +} + ShareManager::ShareManager(AccountPtr account, QObject *parent) : QObject(parent) , _account(account) @@ -390,6 +418,8 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply) if (shareType == Share::TypeLink) { newShare = parseLinkShare(data); + } else if (shareType == Share::TypeGroup || shareType == Share::TypeUser) { + newShare = parseUserGroupShare(data); } else { newShare = parseShare(data); } @@ -401,6 +431,22 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply) emit sharesFetched(shares); } +QSharedPointer ShareManager::parseUserGroupShare(const QJsonObject &data) +{ + QSharedPointer sharee(new Sharee(data.value("share_with").toString(), + data.value("share_with_displayname").toString(), + static_cast(data.value("share_type").toInt()))); + + return QSharedPointer(new UserGroupShare(_account, + data.value("id").toVariant().toString(), // "id" used to be an integer, support both + data.value("uid_owner").toVariant().toString(), + data.value("displayname_owner").toVariant().toString(), + data.value("path").toString(), + static_cast(data.value("share_type").toInt()), + static_cast(data.value("permissions").toInt()), + sharee)); +} + QSharedPointer ShareManager::parseLinkShare(const QJsonObject &data) { QUrl url; diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h index 64a860d14..b43d35ef4 100644 --- a/src/gui/sharemanager.h +++ b/src/gui/sharemanager.h @@ -259,6 +259,30 @@ private: QUrl _url; }; +class UserGroupShare : public Share +{ + Q_OBJECT +public: + UserGroupShare(AccountPtr account, + const QString &id, + const QString &owner, + const QString &ownerDisplayName, + const QString &path, + const ShareType shareType, + const Permissions permissions, + const QSharedPointer shareWith); + + void setNote(const QString ¬e); + + void slotNoteSet(const QJsonDocument &, const QVariant ¬e); + +signals: + void noteSet(); + +private: + QString _note; +}; + /** * The share manager allows for creating, retrieving and deletion * of shares. It abstracts away from the OCS Share API, all the usages @@ -331,6 +355,7 @@ private slots: void slotOcsError(int statusCode, const QString &message); private: QSharedPointer parseLinkShare(const QJsonObject &data); + QSharedPointer parseUserGroupShare(const QJsonObject &data); QSharedPointer parseShare(const QJsonObject &data); AccountPtr _account; diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index 0a5ea2531..51f662130 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -228,7 +228,10 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> _ui->mainOwnerLabel->setText(QString("Shared with you by ").append(share->getOwnerDisplayName())); } - auto *s = new ShareUserLine(share, _maxSharingPermissions, _isFile, _parentScrollArea); + + Q_ASSERT(share->getShareType() == Share::TypeUser || share->getShareType() == Share::TypeGroup); + auto userGroupShare = qSharedPointerDynamicCast(share); + auto *s = new ShareUserLine(userGroupShare, _maxSharingPermissions, _isFile, _parentScrollArea); connect(s, &ShareUserLine::resizeRequested, this, &ShareUserGroupWidget::slotAdjustScrollWidgetSize); connect(s, &ShareUserLine::visualDeletionDone, this, &ShareUserGroupWidget::getShares); s->setBackgroundRole(layout->count() % 2 == 0 ? QPalette::Base : QPalette::AlternateBase); @@ -267,12 +270,19 @@ void ShareUserGroupWidget::slotSharesFetched(const QList> void ShareUserGroupWidget::slotAdjustScrollWidgetSize() { QScrollArea *scrollArea = _parentScrollArea; - int count = scrollArea->findChildren().count(); - scrollArea->setVisible(count > 0); - if (count > 0 && count <= 3) { + const auto shareUserLineChilds = scrollArea->findChildren(); + + // Ask the child widgets to calculate their size + for (const auto shareUserLineChild : shareUserLineChilds) { + shareUserLineChild->adjustSize(); + } + + const auto shareUserLineChildsCount = shareUserLineChilds.count(); + scrollArea->setVisible(shareUserLineChildsCount > 0); + if (shareUserLineChildsCount > 0 && shareUserLineChildsCount <= 3) { scrollArea->setFixedHeight(scrollArea->widget()->sizeHint().height()); } - scrollArea->setFrameShape(count > 3 ? QFrame::StyledPanel : QFrame::NoFrame); + scrollArea->setFrameShape(shareUserLineChildsCount > 3 ? QFrame::StyledPanel : QFrame::NoFrame); } void ShareUserGroupWidget::slotPrivateLinkShare() @@ -413,7 +423,7 @@ void ShareUserGroupWidget::activateShareeLineEdit() _ui->shareeLineEdit->setFocus(); } -ShareUserLine::ShareUserLine(QSharedPointer share, +ShareUserLine::ShareUserLine(QSharedPointer share, SharePermissions maxSharingPermissions, bool isFile, QWidget *parent) @@ -434,6 +444,7 @@ ShareUserLine::ShareUserLine(QSharedPointer share, maxSharingPermissions & SharePermissionDelete); _ui->permissionsEdit->setEnabled(enabled); connect(_ui->permissionsEdit, &QAbstractButton::clicked, this, &ShareUserLine::slotEditPermissionsChanged); + connect(_ui->noteConfirmButton, &QAbstractButton::clicked, this, &ShareUserLine::onNoteConfirmButtonClicked); // create menu with checkable permissions auto *menu = new QMenu(this); @@ -443,6 +454,11 @@ ShareUserLine::ShareUserLine(QSharedPointer share, menu->addAction(_permissionReshare); connect(_permissionReshare, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged); + _noteLinkAction = new QAction(tr("Note to recipient")); + _noteLinkAction->setCheckable(true); + menu->addAction(_noteLinkAction); + connect(_noteLinkAction, &QAction::triggered, this, &ShareUserLine::toggleNoteOptions); + menu->addSeparator(); // Adds action to delete share widget @@ -500,6 +516,7 @@ ShareUserLine::ShareUserLine(QSharedPointer share, } loadAvatar(); + toggleNoteOptions(false); customizeStyle(); } @@ -708,6 +725,43 @@ void ShareUserLine::customizeStyle() QIcon deleteicon = QIcon::fromTheme(QLatin1String("user-trash"),Theme::createColorAwareIcon(QLatin1String(":/client/theme/delete.svg"))); _deleteShareButton->setIcon(deleteicon); + + _ui->noteConfirmButton->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg")); } +void ShareUserLine::showNoteOptions(bool show) +{ + _ui->noteLabel->setVisible(show); + _ui->noteTextEdit->setVisible(show); + _ui->noteConfirmButton->setVisible(show); + emit resizeRequested(); +} + + +void ShareUserLine::toggleNoteOptions(bool enable) +{ + showNoteOptions(enable); + + if (enable) { + _ui->noteTextEdit->setFocus(); + } else { + // 'deletes' note + if (_share) + _share->setNote(QString()); + } +} + +void ShareUserLine::onNoteConfirmButtonClicked() +{ + setNote(_ui->noteTextEdit->toPlainText()); +} + +void ShareUserLine::setNote(const QString ¬e) +{ + if (_share) { + // slotToggleAnimation(true); + // _ui->errorLabel->hide(); + _share->setNote(note); + } +} } diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index fe45d1e36..79dc3216e 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -16,6 +16,7 @@ #define SHAREUSERGROUPWIDGET_H #include "accountfwd.h" +#include "sharemanager.h" #include "sharepermissions.h" #include "sharee.h" #include "QProgressIndicator.h" @@ -119,7 +120,7 @@ class ShareUserLine : public QWidget Q_OBJECT public: - explicit ShareUserLine(QSharedPointer Share, + explicit ShareUserLine(QSharedPointer share, SharePermissions maxSharingPermissions, bool isFile, QWidget *parent = nullptr); @@ -150,16 +151,22 @@ private: void loadAvatar(); void customizeStyle(); - Ui::ShareUserLine *_ui; - QSharedPointer _share; - bool _isFile; + void showNoteOptions(bool show); + void toggleNoteOptions(bool enable); + void onNoteConfirmButtonClicked(); + void setNote(const QString ¬e); - // _permissionEdit is a checkbox - QAction *_permissionReshare; - QAction *_deleteShareButton; - QAction *_permissionCreate; - QAction *_permissionChange; - QAction *_permissionDelete; + Ui::ShareUserLine *_ui; + QSharedPointer _share; + bool _isFile; + + // _permissionEdit is a checkbox + QAction *_permissionReshare; + QAction *_deleteShareButton; + QAction *_permissionCreate; + QAction *_permissionChange; + QAction *_permissionDelete; + QAction *_noteLinkAction; }; } diff --git a/src/gui/shareuserline.ui b/src/gui/shareuserline.ui index a9b9b807c..6fdebefbb 100644 --- a/src/gui/shareuserline.ui +++ b/src/gui/shareuserline.ui @@ -6,8 +6,8 @@ 0 0 - 360 - 58 + 523 + 208 @@ -27,79 +27,143 @@ - - - - 0 - 0 - + + + 0 - - - 40 - 40 - + + 0 - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - Username - - - Qt::PlainText - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - can edit - - - - - - - - :/client/theme/more.svg:/client/theme/more.svg - - - true - - + + + + 0 + + + + + + 0 + 0 + + + + + 40 + 40 + + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Username + + + Qt::PlainText + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + can edit + + + + + + + + :/client/theme/more.svg:/client/theme/more.svg + + + true + + + + + + + + + QLayout::SetMinimumSize + + + + + Note: + + + + + + + + 0 + 0 + + + + + 0 + 60 + + + + QAbstractScrollArea::AdjustToContents + + + + + + + ... + + + + :/client/theme/confirm.svg:/client/theme/confirm.svg + + + true + + + + + +