From 946a51e4c1282378b642a6e74a7de93bb8ace314 Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Wed, 14 Apr 2021 16:36:16 +0200 Subject: [PATCH 1/6] Add note to user and group share Fixes #3104 Signed-off-by: Felix Weilbach --- src/gui/sharemanager.cpp | 46 +++++++ src/gui/sharemanager.h | 25 ++++ src/gui/shareusergroupwidget.cpp | 66 +++++++++- src/gui/shareusergroupwidget.h | 27 ++-- src/gui/shareuserline.ui | 210 ++++++++++++++++++++----------- 5 files changed, 285 insertions(+), 89 deletions(-) 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 + + + + + + From 22a3b19e08f685865a2cee8e3ef847697cc8daee Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Thu, 15 Apr 2021 13:06:53 +0200 Subject: [PATCH 2/6] Add expire date to user and group share Fixes #3100 Signed-off-by: Felix Weilbach --- src/gui/sharemanager.cpp | 41 ++++++++++++++++++++++++-- src/gui/sharemanager.h | 11 ++++++- src/gui/shareusergroupwidget.cpp | 50 +++++++++++++++++++++++++++++++- src/gui/shareusergroupwidget.h | 5 ++++ src/gui/shareuserline.ui | 46 ++++++++++++++++++++++++++++- 5 files changed, 148 insertions(+), 5 deletions(-) diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp index 0b0ac83c3..5224fc34e 100644 --- a/src/gui/sharemanager.cpp +++ b/src/gui/sharemanager.cpp @@ -285,8 +285,10 @@ UserGroupShare::UserGroupShare(AccountPtr account, const QString &path, const ShareType shareType, const Permissions permissions, - const QSharedPointer shareWith) + const QSharedPointer shareWith, + const QDate &expireDate) : Share(account, id, owner, ownerDisplayName, path, shareType, permissions, shareWith) + , _expireDate(expireDate) { Q_ASSERT(shareType == TypeUser || shareType == TypeGroup); Q_ASSERT(shareWith); @@ -306,6 +308,35 @@ void UserGroupShare::slotNoteSet(const QJsonDocument &, const QVariant ¬e) emit noteSet(); } +QDate UserGroupShare::getExpireDate() const +{ + return _expireDate; +} + +void UserGroupShare::setExpireDate(const QDate &date) +{ + auto *job = new OcsShareJob(_account); + connect(job, &OcsShareJob::shareJobFinished, this, &UserGroupShare::slotExpireDateSet); + connect(job, &OcsJob::ocsError, this, &UserGroupShare::slotOcsError); + job->setExpireDate(getId(), date); +} + +void UserGroupShare::slotExpireDateSet(const QJsonDocument &reply, const QVariant &value) +{ + auto data = reply.object().value("ocs").toObject().value("data").toObject(); + + /* + * If the reply provides a data back (more REST style) + * they use this date. + */ + if (data.value("expiration").isString()) { + _expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00"); + } else { + _expireDate = value.toDate(); + } + emit expireDateSet(); +} + ShareManager::ShareManager(AccountPtr account, QObject *parent) : QObject(parent) , _account(account) @@ -437,6 +468,11 @@ QSharedPointer ShareManager::parseUserGroupShare(const QJsonObje data.value("share_with_displayname").toString(), static_cast(data.value("share_type").toInt()))); + QDate expireDate; + if (data.value("expiration").isString()) { + expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00"); + } + return QSharedPointer(new UserGroupShare(_account, data.value("id").toVariant().toString(), // "id" used to be an integer, support both data.value("uid_owner").toVariant().toString(), @@ -444,7 +480,8 @@ QSharedPointer ShareManager::parseUserGroupShare(const QJsonObje data.value("path").toString(), static_cast(data.value("share_type").toInt()), static_cast(data.value("permissions").toInt()), - sharee)); + sharee, + expireDate)); } QSharedPointer ShareManager::parseLinkShare(const QJsonObject &data) diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h index b43d35ef4..c17ed31bf 100644 --- a/src/gui/sharemanager.h +++ b/src/gui/sharemanager.h @@ -270,17 +270,26 @@ public: const QString &path, const ShareType shareType, const Permissions permissions, - const QSharedPointer shareWith); + const QSharedPointer shareWith, + const QDate &expireDate); void setNote(const QString ¬e); void slotNoteSet(const QJsonDocument &, const QVariant ¬e); + void setExpireDate(const QDate &date); + + QDate getExpireDate() const; + + void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value); + signals: void noteSet(); + void expireDateSet(); private: QString _note; + QDate _expireDate; }; /** diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index 51f662130..a233168fa 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -445,6 +445,8 @@ ShareUserLine::ShareUserLine(QSharedPointer share, _ui->permissionsEdit->setEnabled(enabled); connect(_ui->permissionsEdit, &QAbstractButton::clicked, this, &ShareUserLine::slotEditPermissionsChanged); connect(_ui->noteConfirmButton, &QAbstractButton::clicked, this, &ShareUserLine::onNoteConfirmButtonClicked); + connect(_ui->confirmExpirationDate, &QAbstractButton::clicked, this, &ShareUserLine::setExpireDate); + connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareUserLine::setExpireDate); // create menu with checkable permissions auto *menu = new QMenu(this); @@ -454,11 +456,24 @@ ShareUserLine::ShareUserLine(QSharedPointer share, menu->addAction(_permissionReshare); connect(_permissionReshare, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged); + toggleNoteOptions(false); _noteLinkAction = new QAction(tr("Note to recipient")); _noteLinkAction->setCheckable(true); menu->addAction(_noteLinkAction); connect(_noteLinkAction, &QAction::triggered, this, &ShareUserLine::toggleNoteOptions); + toggleExpireDateOptions(false); + _expirationDateLinkAction = new QAction(tr("Set expiration date")); + _expirationDateLinkAction->setCheckable(true); + menu->addAction(_expirationDateLinkAction); + connect(_expirationDateLinkAction, &QAction::triggered, this, &ShareUserLine::toggleExpireDateOptions); + const auto expireDate = _share.data()->getExpireDate().isValid() ? share.data()->getExpireDate() : QDate(); + if (!expireDate.isNull()) { + _ui->calendar->setDate(expireDate); + _expirationDateLinkAction->setChecked(true); + showExpireDateOptions(true); + } + menu->addSeparator(); // Adds action to delete share widget @@ -516,7 +531,6 @@ ShareUserLine::ShareUserLine(QSharedPointer share, } loadAvatar(); - toggleNoteOptions(false); customizeStyle(); } @@ -727,6 +741,7 @@ void ShareUserLine::customizeStyle() _deleteShareButton->setIcon(deleteicon); _ui->noteConfirmButton->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg")); + _ui->confirmExpirationDate->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg")); } void ShareUserLine::showNoteOptions(bool show) @@ -764,4 +779,37 @@ void ShareUserLine::setNote(const QString ¬e) _share->setNote(note); } } + +void ShareUserLine::toggleExpireDateOptions(bool enable) +{ + showExpireDateOptions(enable); + + if (enable) { + const QDate date = QDate::currentDate().addDays(1); + _ui->calendar->setDate(date); + _ui->calendar->setMinimumDate(date); + _ui->calendar->setFocus(); + } else { + // 'deletes' expire date + if (_share) + _share->setExpireDate(QDate()); + } +} + +void ShareUserLine::showExpireDateOptions(bool show) +{ + _ui->expirationLabel->setVisible(show); + _ui->calendar->setVisible(show); + _ui->confirmExpirationDate->setVisible(show); + emit resizeRequested(); +} + +void ShareUserLine::setExpireDate() +{ + if (!_share) { + return; + } + + _share->setExpireDate(_ui->calendar->date()); +} } diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index 79dc3216e..80b70933b 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -156,6 +156,10 @@ private: void onNoteConfirmButtonClicked(); void setNote(const QString ¬e); + void toggleExpireDateOptions(bool enable); + void showExpireDateOptions(bool show); + void setExpireDate(); + Ui::ShareUserLine *_ui; QSharedPointer _share; bool _isFile; @@ -167,6 +171,7 @@ private: QAction *_permissionChange; QAction *_permissionDelete; QAction *_noteLinkAction; + QAction *_expirationDateLinkAction; }; } diff --git a/src/gui/shareuserline.ui b/src/gui/shareuserline.ui index 6fdebefbb..2bc0f997b 100644 --- a/src/gui/shareuserline.ui +++ b/src/gui/shareuserline.ui @@ -6,7 +6,7 @@ 0 0 - 523 + 486 208 @@ -163,6 +163,50 @@ + + + + + + + 78 + 0 + + + + Expires: + + + Qt::AlignCenter + + + + + + + + 1 + 0 + + + + + + + + ... + + + + :/client/theme/confirm.svg:/client/theme/confirm.svg + + + true + + + + + From 28515285959b6bf3d58f7a1a70a97f8bb98776ce Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Thu, 15 Apr 2021 15:47:10 +0200 Subject: [PATCH 3/6] Show user/group note on share if already set Signed-off-by: Felix Weilbach --- src/gui/sharemanager.cpp | 17 +++++++++++++++-- src/gui/sharemanager.h | 5 ++++- src/gui/shareusergroupwidget.cpp | 15 +++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp index 5224fc34e..e50390fbf 100644 --- a/src/gui/sharemanager.cpp +++ b/src/gui/sharemanager.cpp @@ -286,9 +286,11 @@ UserGroupShare::UserGroupShare(AccountPtr account, const ShareType shareType, const Permissions permissions, const QSharedPointer shareWith, - const QDate &expireDate) + const QDate &expireDate, + const QString ¬e) : Share(account, id, owner, ownerDisplayName, path, shareType, permissions, shareWith) , _expireDate(expireDate) + , _note(note) { Q_ASSERT(shareType == TypeUser || shareType == TypeGroup); Q_ASSERT(shareWith); @@ -302,6 +304,11 @@ void UserGroupShare::setNote(const QString ¬e) job->setNote(getId(), note); } +QString UserGroupShare::getNote() const +{ + return _note; +} + void UserGroupShare::slotNoteSet(const QJsonDocument &, const QVariant ¬e) { _note = note.toString(); @@ -473,6 +480,11 @@ QSharedPointer ShareManager::parseUserGroupShare(const QJsonObje expireDate = QDate::fromString(data.value("expiration").toString(), "yyyy-MM-dd 00:00:00"); } + QString note; + if (data.value("note").isString()) { + note = data.value("note").toString(); + } + return QSharedPointer(new UserGroupShare(_account, data.value("id").toVariant().toString(), // "id" used to be an integer, support both data.value("uid_owner").toVariant().toString(), @@ -481,7 +493,8 @@ QSharedPointer ShareManager::parseUserGroupShare(const QJsonObje static_cast(data.value("share_type").toInt()), static_cast(data.value("permissions").toInt()), sharee, - expireDate)); + expireDate, + note)); } QSharedPointer ShareManager::parseLinkShare(const QJsonObject &data) diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h index c17ed31bf..6477edc46 100644 --- a/src/gui/sharemanager.h +++ b/src/gui/sharemanager.h @@ -271,10 +271,13 @@ public: const ShareType shareType, const Permissions permissions, const QSharedPointer shareWith, - const QDate &expireDate); + const QDate &expireDate, + const QString ¬e); void setNote(const QString ¬e); + QString getNote() const; + void slotNoteSet(const QJsonDocument &, const QVariant ¬e); void setExpireDate(const QDate &date); diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index a233168fa..c2501a83f 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -461,13 +461,17 @@ ShareUserLine::ShareUserLine(QSharedPointer share, _noteLinkAction->setCheckable(true); menu->addAction(_noteLinkAction); connect(_noteLinkAction, &QAction::triggered, this, &ShareUserLine::toggleNoteOptions); + if (!_share->getNote().isEmpty()) { + _noteLinkAction->setChecked(true); + toggleNoteOptions(true); + } toggleExpireDateOptions(false); _expirationDateLinkAction = new QAction(tr("Set expiration date")); _expirationDateLinkAction->setCheckable(true); menu->addAction(_expirationDateLinkAction); connect(_expirationDateLinkAction, &QAction::triggered, this, &ShareUserLine::toggleExpireDateOptions); - const auto expireDate = _share.data()->getExpireDate().isValid() ? share.data()->getExpireDate() : QDate(); + const auto expireDate = _share->getExpireDate().isValid() ? share.data()->getExpireDate() : QDate(); if (!expireDate.isNull()) { _ui->calendar->setDate(expireDate); _expirationDateLinkAction->setChecked(true); @@ -758,11 +762,16 @@ void ShareUserLine::toggleNoteOptions(bool enable) showNoteOptions(enable); if (enable) { + const auto note = _share->getNote(); + if (!note.isEmpty()) { + _ui->noteTextEdit->setText(note); + } _ui->noteTextEdit->setFocus(); } else { // 'deletes' note - if (_share) + if (_share) { _share->setNote(QString()); + } } } @@ -774,8 +783,6 @@ void ShareUserLine::onNoteConfirmButtonClicked() void ShareUserLine::setNote(const QString ¬e) { if (_share) { - // slotToggleAnimation(true); - // _ui->errorLabel->hide(); _share->setNote(note); } } From 8711d5bf4988527c96feafd60408fd6283b3df3e Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Fri, 16 Apr 2021 12:35:35 +0200 Subject: [PATCH 4/6] Don't use unnecessary layout element Signed-off-by: Felix Weilbach --- src/gui/shareuserline.ui | 332 +++++++++++++++++++-------------------- 1 file changed, 161 insertions(+), 171 deletions(-) diff --git a/src/gui/shareuserline.ui b/src/gui/shareuserline.ui index 2bc0f997b..aaf563e0a 100644 --- a/src/gui/shareuserline.ui +++ b/src/gui/shareuserline.ui @@ -6,8 +6,8 @@ 0 0 - 486 - 208 + 980 + 210 @@ -25,187 +25,177 @@ false - + - + 0 - - 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 - - - 0 + + + Note: - - - - - 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 + + + + 0 + 0 + - - - - Note: - - - - - - - - 0 - 0 - - - - - 0 - 60 - - - - QAbstractScrollArea::AdjustToContents - - - - - - - ... - - - - :/client/theme/confirm.svg:/client/theme/confirm.svg - - - true - - - - + + + 0 + 60 + + + + QAbstractScrollArea::AdjustToContents + + - - - - - - 78 - 0 - - - - Expires: - - - Qt::AlignCenter - - - - - - - - 1 - 0 - - - - - - - - ... - - - - :/client/theme/confirm.svg:/client/theme/confirm.svg - - - true - - - - + + + ... + + + + :/client/theme/confirm.svg:/client/theme/confirm.svg + + + true + + + + + + + + + + + + 78 + 0 + + + + Expires: + + + Qt::AlignCenter + + + + + + + + 1 + 0 + + + + + + + + ... + + + + :/client/theme/confirm.svg:/client/theme/confirm.svg + + + true + + From c3fac23903e158c26fedbb9a9b1979229339a781 Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Fri, 16 Apr 2021 12:36:56 +0200 Subject: [PATCH 5/6] Don't delete note and expiration date on toggle Signed-off-by: Felix Weilbach --- src/gui/shareusergroupwidget.cpp | 47 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index c2501a83f..3e57496cd 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -12,6 +12,7 @@ * for more details. */ +#include "sharee.h" #include "ui_shareusergroupwidget.h" #include "ui_shareuserline.h" #include "shareusergroupwidget.h" @@ -456,17 +457,17 @@ ShareUserLine::ShareUserLine(QSharedPointer share, menu->addAction(_permissionReshare); connect(_permissionReshare, &QAction::triggered, this, &ShareUserLine::slotPermissionsChanged); - toggleNoteOptions(false); + showNoteOptions(false); _noteLinkAction = new QAction(tr("Note to recipient")); _noteLinkAction->setCheckable(true); menu->addAction(_noteLinkAction); connect(_noteLinkAction, &QAction::triggered, this, &ShareUserLine::toggleNoteOptions); if (!_share->getNote().isEmpty()) { _noteLinkAction->setChecked(true); - toggleNoteOptions(true); + showNoteOptions(true); } - toggleExpireDateOptions(false); + showExpireDateOptions(false); _expirationDateLinkAction = new QAction(tr("Set expiration date")); _expirationDateLinkAction->setCheckable(true); menu->addAction(_expirationDateLinkAction); @@ -753,6 +754,13 @@ void ShareUserLine::showNoteOptions(bool show) _ui->noteLabel->setVisible(show); _ui->noteTextEdit->setVisible(show); _ui->noteConfirmButton->setVisible(show); + + if (show) { + const auto note = _share->getNote(); + _ui->noteTextEdit->setText(note); + _ui->noteTextEdit->setFocus(); + } + emit resizeRequested(); } @@ -761,17 +769,9 @@ void ShareUserLine::toggleNoteOptions(bool enable) { showNoteOptions(enable); - if (enable) { - const auto note = _share->getNote(); - if (!note.isEmpty()) { - _ui->noteTextEdit->setText(note); - } - _ui->noteTextEdit->setFocus(); - } else { - // 'deletes' note - if (_share) { - _share->setNote(QString()); - } + if (_share && !enable) { + // Delete note + _share->setNote(QString()); } } @@ -791,15 +791,8 @@ void ShareUserLine::toggleExpireDateOptions(bool enable) { showExpireDateOptions(enable); - if (enable) { - const QDate date = QDate::currentDate().addDays(1); - _ui->calendar->setDate(date); - _ui->calendar->setMinimumDate(date); - _ui->calendar->setFocus(); - } else { - // 'deletes' expire date - if (_share) - _share->setExpireDate(QDate()); + if (_share && !enable) { + _share->setExpireDate(QDate()); } } @@ -808,6 +801,14 @@ void ShareUserLine::showExpireDateOptions(bool show) _ui->expirationLabel->setVisible(show); _ui->calendar->setVisible(show); _ui->confirmExpirationDate->setVisible(show); + + if (show) { + const QDate date = QDate::currentDate().addDays(1); + _ui->calendar->setDate(date); + _ui->calendar->setMinimumDate(date); + _ui->calendar->setFocus(); + } + emit resizeRequested(); } From 275e46f0db142de1e94d71578fb4b79bd836dcad Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Fri, 16 Apr 2021 13:17:09 +0200 Subject: [PATCH 6/6] Show progess indicator Signed-off-by: Felix Weilbach --- src/gui/sharemanager.cpp | 2 ++ src/gui/shareusergroupwidget.cpp | 35 ++++++++++++++++++++++++-------- src/gui/shareusergroupwidget.h | 3 +++ src/gui/shareuserline.ui | 9 ++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp index e50390fbf..2401305b4 100644 --- a/src/gui/sharemanager.cpp +++ b/src/gui/sharemanager.cpp @@ -23,6 +23,8 @@ #include #include +Q_LOGGING_CATEGORY(lcUserGroupShare, "nextcloud.gui.usergroupshare", QtInfoMsg) + namespace OCC { /** diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp index 3e57496cd..480d58cc4 100644 --- a/src/gui/shareusergroupwidget.cpp +++ b/src/gui/shareusergroupwidget.cpp @@ -433,6 +433,7 @@ ShareUserLine::ShareUserLine(QSharedPointer share, , _share(share) , _isFile(isFile) { + Q_ASSERT(_share); _ui->setupUi(this); _ui->sharedWith->setElideMode(Qt::ElideRight); @@ -449,6 +450,9 @@ ShareUserLine::ShareUserLine(QSharedPointer share, connect(_ui->confirmExpirationDate, &QAbstractButton::clicked, this, &ShareUserLine::setExpireDate); connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareUserLine::setExpireDate); + connect(_share.data(), &UserGroupShare::noteSet, this, &ShareUserLine::disableProgessIndicatorAnimation); + connect(_share.data(), &UserGroupShare::expireDateSet, this, &ShareUserLine::disableProgessIndicatorAnimation); + // create menu with checkable permissions auto *menu = new QMenu(this); _permissionReshare= new QAction(tr("Can reshare"), this); @@ -747,6 +751,7 @@ void ShareUserLine::customizeStyle() _ui->noteConfirmButton->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg")); _ui->confirmExpirationDate->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg")); + _ui->progressIndicator->setColor(QGuiApplication::palette().color(QPalette::WindowText)); } void ShareUserLine::showNoteOptions(bool show) @@ -769,7 +774,7 @@ void ShareUserLine::toggleNoteOptions(bool enable) { showNoteOptions(enable); - if (_share && !enable) { + if (!enable) { // Delete note _share->setNote(QString()); } @@ -782,16 +787,15 @@ void ShareUserLine::onNoteConfirmButtonClicked() void ShareUserLine::setNote(const QString ¬e) { - if (_share) { - _share->setNote(note); - } + enableProgessIndicatorAnimation(true); + _share->setNote(note); } void ShareUserLine::toggleExpireDateOptions(bool enable) { showExpireDateOptions(enable); - if (_share && !enable) { + if (!enable) { _share->setExpireDate(QDate()); } } @@ -814,10 +818,23 @@ void ShareUserLine::showExpireDateOptions(bool show) void ShareUserLine::setExpireDate() { - if (!_share) { - return; - } - + enableProgessIndicatorAnimation(true); _share->setExpireDate(_ui->calendar->date()); } + +void ShareUserLine::enableProgessIndicatorAnimation(bool enable) +{ + if (enable) { + if (!_ui->progressIndicator->isAnimated()) { + _ui->progressIndicator->startAnimation(); + } + } else { + _ui->progressIndicator->stopAnimation(); + } +} + +void ShareUserLine::disableProgessIndicatorAnimation() +{ + enableProgessIndicatorAnimation(false); +} } diff --git a/src/gui/shareusergroupwidget.h b/src/gui/shareusergroupwidget.h index 80b70933b..c69c64012 100644 --- a/src/gui/shareusergroupwidget.h +++ b/src/gui/shareusergroupwidget.h @@ -160,6 +160,9 @@ private: void showExpireDateOptions(bool show); void setExpireDate(); + void enableProgessIndicatorAnimation(bool enable); + void disableProgessIndicatorAnimation(); + Ui::ShareUserLine *_ui; QSharedPointer _share; bool _isFile; diff --git a/src/gui/shareuserline.ui b/src/gui/shareuserline.ui index aaf563e0a..a40015bc3 100644 --- a/src/gui/shareuserline.ui +++ b/src/gui/shareuserline.ui @@ -66,6 +66,9 @@ + + + @@ -207,6 +210,12 @@ QLabel
elidedlabel.h
+ + QProgressIndicator + QWidget +
QProgressIndicator.h
+ 1 +