mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Add note to user and group share
Fixes #3104 Signed-off-by: Felix Weilbach <felix.weilbach@nextcloud.com>
This commit is contained in:
parent
87f3073b87
commit
946a51e4c1
5 changed files with 285 additions and 89 deletions
|
@ -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<Sharee> 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<UserGroupShare> ShareManager::parseUserGroupShare(const QJsonObject &data)
|
||||
{
|
||||
QSharedPointer<Sharee> sharee(new Sharee(data.value("share_with").toString(),
|
||||
data.value("share_with_displayname").toString(),
|
||||
static_cast<Sharee::Type>(data.value("share_type").toInt())));
|
||||
|
||||
return QSharedPointer<UserGroupShare>(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<Share::ShareType>(data.value("share_type").toInt()),
|
||||
static_cast<Share::Permissions>(data.value("permissions").toInt()),
|
||||
sharee));
|
||||
}
|
||||
|
||||
QSharedPointer<LinkShare> ShareManager::parseLinkShare(const QJsonObject &data)
|
||||
{
|
||||
QUrl url;
|
||||
|
|
|
@ -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<Sharee> 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<LinkShare> parseLinkShare(const QJsonObject &data);
|
||||
QSharedPointer<UserGroupShare> parseUserGroupShare(const QJsonObject &data);
|
||||
QSharedPointer<Share> parseShare(const QJsonObject &data);
|
||||
|
||||
AccountPtr _account;
|
||||
|
|
|
@ -228,7 +228,10 @@ void ShareUserGroupWidget::slotSharesFetched(const QList<QSharedPointer<Share>>
|
|||
_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<UserGroupShare>(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<QSharedPointer<Share>>
|
|||
void ShareUserGroupWidget::slotAdjustScrollWidgetSize()
|
||||
{
|
||||
QScrollArea *scrollArea = _parentScrollArea;
|
||||
int count = scrollArea->findChildren<ShareUserLine *>().count();
|
||||
scrollArea->setVisible(count > 0);
|
||||
if (count > 0 && count <= 3) {
|
||||
const auto shareUserLineChilds = scrollArea->findChildren<ShareUserLine *>();
|
||||
|
||||
// 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> share,
|
||||
ShareUserLine::ShareUserLine(QSharedPointer<UserGroupShare> share,
|
||||
SharePermissions maxSharingPermissions,
|
||||
bool isFile,
|
||||
QWidget *parent)
|
||||
|
@ -434,6 +444,7 @@ ShareUserLine::ShareUserLine(QSharedPointer<Share> 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> 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> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> Share,
|
||||
explicit ShareUserLine(QSharedPointer<UserGroupShare> share,
|
||||
SharePermissions maxSharingPermissions,
|
||||
bool isFile,
|
||||
QWidget *parent = nullptr);
|
||||
|
@ -150,16 +151,22 @@ private:
|
|||
void loadAvatar();
|
||||
void customizeStyle();
|
||||
|
||||
Ui::ShareUserLine *_ui;
|
||||
QSharedPointer<Share> _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<UserGroupShare> _share;
|
||||
bool _isFile;
|
||||
|
||||
// _permissionEdit is a checkbox
|
||||
QAction *_permissionReshare;
|
||||
QAction *_deleteShareButton;
|
||||
QAction *_permissionCreate;
|
||||
QAction *_permissionChange;
|
||||
QAction *_permissionDelete;
|
||||
QAction *_noteLinkAction;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>360</width>
|
||||
<height>58</height>
|
||||
<width>523</width>
|
||||
<height>208</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -27,79 +27,143 @@
|
|||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="avatar">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="OCC::ElidedLabel" name="sharedWith">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Username</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="permissionsEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>can edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="permissionToolButton">
|
||||
<property name="icon">
|
||||
<iconset resource="../../theme.qrc">
|
||||
<normaloff>:/client/theme/more.svg</normaloff>:/client/theme/more.svg</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="avatar">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="OCC::ElidedLabel" name="sharedWith">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Username</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="permissionsEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>can edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="permissionToolButton">
|
||||
<property name="icon">
|
||||
<iconset resource="../../theme.qrc">
|
||||
<normaloff>:/client/theme/more.svg</normaloff>:/client/theme/more.svg</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="noteLabel">
|
||||
<property name="text">
|
||||
<string>Note:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="noteTextEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>60</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="noteConfirmButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../theme.qrc">
|
||||
<normaloff>:/client/theme/confirm.svg</normaloff>:/client/theme/confirm.svg</iconset>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
Loading…
Reference in a new issue