diff --git a/src/gui/ocssharejob.cpp b/src/gui/ocssharejob.cpp index 15884e012..489508455 100644 --- a/src/gui/ocssharejob.cpp +++ b/src/gui/ocssharejob.cpp @@ -73,6 +73,17 @@ void OcsShareJob::setPassword(const QString &shareId, const QString &password) start(); } +void OcsShareJob::setNote(const QString &shareId, const QString ¬e) +{ + appendPath(shareId); + setVerb("PUT"); + + addParam(QString::fromLatin1("note"), note); + _value = note; + + start(); +} + void OcsShareJob::setPublicUpload(const QString &shareId, bool publicUpload) { appendPath(shareId); diff --git a/src/gui/ocssharejob.h b/src/gui/ocssharejob.h index 97b840e53..726c0b8ce 100644 --- a/src/gui/ocssharejob.h +++ b/src/gui/ocssharejob.h @@ -61,6 +61,14 @@ public: */ void setExpireDate(const QString &shareId, const QDate &date); + /** + * Set note a share + * + * @param note The note to a share, if the note is empty the + * share will be removed + */ + void setNote(const QString &shareId, const QString ¬e); + /** * Set the password of a share * diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index bc45eed20..435de4a0c 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -165,7 +165,7 @@ void ShareDialog::initLinkShareWidget(){ _emptyShareLinkWidget = new ShareLinkWidget(_accountState->account(), _sharePath, _localPath, _maxSharingPermissions, this); _linkWidgetList.append(_emptyShareLinkWidget); -// connect(_emptyShareLinkWidget, &ShareLinkWidget::resizeRequested, this, &ShareDialog::slotAdjustScrollWidgetSize); + connect(_emptyShareLinkWidget, &ShareLinkWidget::resizeRequested, this, &ShareDialog::slotAdjustScrollWidgetSize); // connect(this, &ShareDialog::toggleAnimation, _emptyShareLinkWidget, &ShareLinkWidget::slotToggleAnimation); connect(_emptyShareLinkWidget, &ShareLinkWidget::createLinkShare, this, &ShareDialog::slotCreateLinkShare); @@ -206,7 +206,6 @@ void ShareDialog::slotSharesFetched(const QList> &shares) emit toggleAnimation(false); } -// TODO void ShareDialog::slotAdjustScrollWidgetSize() { int count = this->findChildren().count(); diff --git a/src/gui/sharedialog.ui b/src/gui/sharedialog.ui index 033c419a0..cb49c7cb8 100644 --- a/src/gui/sharedialog.ui +++ b/src/gui/sharedialog.ui @@ -6,159 +6,151 @@ 0 0 - 372 + 385 150 - - - 10 - + QLayout::SetFixedSize - - 10 - - - 10 - - - 10 - - - 10 - - - - 0 + + + QLayout::SetFixedSize - - 0 - - - 0 - - - 10 - - - + + + + 0 + + + 0 + + + 0 + + + 10 + + + + + + 0 + 0 + + + + + 315 + 0 + + + + share label + + + Qt::PlainText + + + true + + + + + + + + 0 + 0 + + + + + 315 + 0 + + + + + 50 + false + + + + Nextcloud Path: + + + Qt::PlainText + + + true + + + + + + + + 0 + 0 + + + + + 40 + 40 + + + + + 16777215 + 16777215 + + + + Icon + + + + + + + - + 0 0 - - - 315 - 0 - + + QFrame::NoFrame - - - 50 - false - + + Qt::ScrollBarAlwaysOff - - ownCloud Path: + + QAbstractScrollArea::AdjustIgnored - - Qt::PlainText - - + true - - - - - - - 0 - 0 - - - - - 315 - 0 - - - - share label - - - Qt::PlainText - - - true - - - - - - - - 0 - 0 - - - - - 40 - 40 - - - - - 16777215 - 16777215 - - - - Icon - + + + + 0 + 0 + 69 + 69 + + + + - - - - - 0 - 0 - - - - QFrame::NoFrame - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContentsOnFirstShow - - - true - - - - - 0 - 0 - 352 - 68 - - - - - - diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp index 51f3890fb..b201871dc 100644 --- a/src/gui/sharelinkwidget.cpp +++ b/src/gui/sharelinkwidget.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,7 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account, , _localPath(localPath) , _linkShare(nullptr) , _passwordRequired(false) + , _noteRequired(false) , _expiryRequired(false) , _namesSupported(true) , _linkContextMenu(nullptr) @@ -54,14 +56,13 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account, , _allowUploadEditingLinkAction(nullptr) , _allowUploadLinkAction(nullptr) , _passwordProtectLinkAction(nullptr) + , _noteLinkAction(nullptr) , _expirationDateLinkAction(nullptr) , _unshareLinkAction(nullptr) { _ui->setupUi(this); QSizePolicy sp = _ui->shareLinkToolButton->sizePolicy(); - sp.setRetainSizeWhenHidden(true); - _ui->shareLinkToolButton->setSizePolicy(sp); _ui->shareLinkToolButton->hide(); //Is this a file or folder? @@ -71,6 +72,8 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account, connect(_ui->enableShareLink, &QPushButton::clicked, this, &ShareLinkWidget::slotCreateShareLink); connect(_ui->lineEdit_password, &QLineEdit::returnPressed, this, &ShareLinkWidget::slotCreatePassword); connect(_ui->confirmPassword, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCreatePassword); + connect(_ui->textEdit_note, &QTextEdit::textChanged, this, &ShareLinkWidget::slotCreateNote); + connect(_ui->confirmNote, &QAbstractButton::clicked, this, &ShareLinkWidget::slotCreateNote); connect(_ui->confirmExpirationDate, &QAbstractButton::clicked, this, &ShareLinkWidget::slotSetExpireDate); connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareLinkWidget::slotSetExpireDate); @@ -96,6 +99,7 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account, togglePasswordOptions(false); toggleExpireDateOptions(false); + toggleNoteOptions(false); _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1)); // check if the file is already inside of a synced folder @@ -110,7 +114,8 @@ ShareLinkWidget::~ShareLinkWidget() delete _ui; } -void ShareLinkWidget::slotToggleAnimation(bool start){ +void ShareLinkWidget::slotToggleAnimation(bool start) +{ if (start) { if (!_ui->progressIndicator->isAnimated()) _ui->progressIndicator->startAnimation(); @@ -119,21 +124,25 @@ void ShareLinkWidget::slotToggleAnimation(bool start){ } } -void ShareLinkWidget::setLinkShare(QSharedPointer linkShare){ +void ShareLinkWidget::setLinkShare(QSharedPointer linkShare) +{ _linkShare = linkShare; } -QSharedPointer ShareLinkWidget::getLinkShare(){ +QSharedPointer ShareLinkWidget::getLinkShare() +{ return _linkShare; } -void ShareLinkWidget::setupUiOptions(){ +void ShareLinkWidget::setupUiOptions() +{ connect(_linkShare.data(), &LinkShare::expireDateSet, this, &ShareLinkWidget::slotExpireDateSet); + connect(_linkShare.data(), &LinkShare::noteSet, this, &ShareLinkWidget::slotNoteSet); connect(_linkShare.data(), &LinkShare::passwordSet, this, &ShareLinkWidget::slotPasswordSet); connect(_linkShare.data(), &LinkShare::passwordSetError, this, &ShareLinkWidget::slotPasswordSetError); // Prepare permissions check and create group action - const QDate expireDate = _linkShare.data()->getExpireDate().isValid()? _linkShare.data()->getExpireDate() : QDate(); + const QDate expireDate = _linkShare.data()->getExpireDate().isValid() ? _linkShare.data()->getExpireDate() : QDate(); const SharePermissions perm = _linkShare.data()->getPermissions(); bool checked = false; QActionGroup *permissionsGroup = new QActionGroup(this); @@ -144,7 +153,7 @@ void ShareLinkWidget::setupUiOptions(){ // radio button style permissionsGroup->setExclusive(true); - if(_isFile){ + if (_isFile) { checked = perm & (SharePermissionRead & SharePermissionUpdate); _allowEditingLinkAction = _linkContextMenu->addAction(tr("Allow Editing")); _allowEditingLinkAction->setCheckable(true); @@ -156,10 +165,7 @@ void ShareLinkWidget::setupUiOptions(){ _readOnlyLinkAction->setCheckable(true); _readOnlyLinkAction->setChecked(checked); - checked = perm & (SharePermissionRead & - SharePermissionCreate & - SharePermissionUpdate & - SharePermissionDelete); + checked = perm & (SharePermissionRead & SharePermissionCreate & SharePermissionUpdate & SharePermissionDelete); _allowUploadEditingLinkAction = permissionsGroup->addAction(tr("Allow Upload && Editing")); _allowUploadEditingLinkAction->setCheckable(true); _allowUploadEditingLinkAction->setChecked(checked); @@ -171,7 +177,7 @@ void ShareLinkWidget::setupUiOptions(){ } // Adds permissions actions (radio button style) - if(_isFile){ + if (_isFile) { _linkContextMenu->addAction(_allowEditingLinkAction); } else { _linkContextMenu->addAction(_readOnlyLinkAction); @@ -179,11 +185,21 @@ void ShareLinkWidget::setupUiOptions(){ _linkContextMenu->addAction(_allowUploadLinkAction); } + // Adds action to display note widget (check box) + _noteLinkAction = _linkContextMenu->addAction(tr("Add note to recipient")); + _noteLinkAction->setCheckable(true); + + if (_linkShare->getNote().isSimpleText()) { + _ui->textEdit_note->setText(_linkShare->getNote()); + _noteLinkAction->setChecked(true); + showNoteOptions(true); + } + // Adds action to display password widget (check box) _passwordProtectLinkAction = _linkContextMenu->addAction(tr("Password Protect")); _passwordProtectLinkAction->setCheckable(true); - if(_linkShare.data()->isPasswordSet()){ + if (_linkShare.data()->isPasswordSet()) { _passwordProtectLinkAction->setChecked(true); _ui->lineEdit_password->setPlaceholderText("********"); showPasswordOptions(true); @@ -199,7 +215,7 @@ void ShareLinkWidget::setupUiOptions(){ // Adds action to display expiration date widget (check box) _expirationDateLinkAction = _linkContextMenu->addAction(tr("Expiration Date")); _expirationDateLinkAction->setCheckable(true); - if(!expireDate.isNull()){ + if (!expireDate.isNull()) { _ui->calendar->setDate(expireDate); _expirationDateLinkAction->setChecked(true); showExpireDateOptions(true); @@ -216,12 +232,12 @@ void ShareLinkWidget::setupUiOptions(){ // Adds action to unshare widget (check box) _unshareLinkAction = _linkContextMenu->addAction(QIcon(":/client/resources/delete.png"), - tr("Unshare")); + tr("Unshare")); _linkContextMenu->addSeparator(); _addAnotherLinkAction = _linkContextMenu->addAction(QIcon(":/client/resources/add.png"), - tr("Add another link")); + tr("Add another link")); _ui->enableShareLink->setIcon(QIcon(":/client/resources/copy.svg")); disconnect(_ui->enableShareLink, &QPushButton::clicked, this, &ShareLinkWidget::slotCreateShareLink); @@ -242,7 +258,27 @@ void ShareLinkWidget::setupUiOptions(){ //startAnimation(0, height()); } -void ShareLinkWidget::slotCopyLinkShare(bool clicked){ +void ShareLinkWidget::setNote(const QString ¬e) +{ + if (_linkShare) { + slotToggleAnimation(true); + _ui->errorLabel->hide(); + _linkShare->setNote(note); + } +} + +void ShareLinkWidget::slotCreateNote() +{ + setNote(_ui->textEdit_note->toPlainText()); +} + +void ShareLinkWidget::slotNoteSet() +{ + slotToggleAnimation(false); +} + +void ShareLinkWidget::slotCopyLinkShare(bool clicked) +{ Q_UNUSED(clicked); QApplication::clipboard()->setText(_linkShare->getLink().toString()); @@ -255,7 +291,7 @@ void ShareLinkWidget::slotExpireDateSet() void ShareLinkWidget::slotSetExpireDate() { - if(!_linkShare){ + if (!_linkShare) { return; } @@ -295,8 +331,8 @@ void ShareLinkWidget::slotPasswordSet() slotToggleAnimation(false); } -void ShareLinkWidget::startAnimation(const int start, const int end){ - +void ShareLinkWidget::startAnimation(const int start, const int end) +{ QPropertyAnimation *animation = new QPropertyAnimation(this, "maximumHeight", this); animation->setDuration(500); @@ -304,7 +340,7 @@ void ShareLinkWidget::startAnimation(const int start, const int end){ animation->setEndValue(end); connect(animation, &QAbstractAnimation::finished, this, &ShareLinkWidget::slotAnimationFinished); - if(end < start) // that is to remove the widget, not to show it + if (end < start) // that is to remove the widget, not to show it connect(animation, &QAbstractAnimation::finished, this, &ShareLinkWidget::slotDeleteAnimationFinished); connect(animation, &QVariantAnimation::valueChanged, this, &ShareLinkWidget::resizeRequested); @@ -320,10 +356,32 @@ void ShareLinkWidget::slotDeleteShareFetched() _linkShare.clear(); togglePasswordOptions(false); + toggleNoteOptions(false); toggleExpireDateOptions(false); emit deleteLinkShare(); } +void ShareLinkWidget::showNoteOptions(bool show) +{ + _ui->noteLabel->setVisible(show); + _ui->textEdit_note->setVisible(show); + _ui->confirmNote->setVisible(show); +} + + +void ShareLinkWidget::toggleNoteOptions(bool enable) +{ + showNoteOptions(enable); + + if (enable) { + _ui->textEdit_note->setFocus(); + } else { + // 'deletes' note + if (_linkShare) + _linkShare->setNote(QString()); + } +} + void ShareLinkWidget::slotAnimationFinished() { emit resizeRequested(); @@ -364,11 +422,11 @@ void ShareLinkWidget::togglePasswordOptions(bool enable) { showPasswordOptions(enable); - if(enable) { + if (enable) { _ui->lineEdit_password->setFocus(); } else { // 'deletes' password - if(_linkShare) + if (_linkShare) _linkShare->setPassword(QString()); } } @@ -391,7 +449,7 @@ void ShareLinkWidget::toggleExpireDateOptions(bool enable) _ui->calendar->setFocus(); } else { // 'deletes' expire date - if(_linkShare) + if (_linkShare) _linkShare->setExpireDate(QDate()); } } @@ -412,11 +470,11 @@ void ShareLinkWidget::confirmAndDeleteShare() connect(messageBox, &QMessageBox::finished, this, [messageBox, yesButton, this]() { - if (messageBox->clickedButton() == yesButton) { - this->slotToggleAnimation(true); - this->_linkShare->deleteShare(); - } - }); + if (messageBox->clickedButton() == yesButton) { + this->slotToggleAnimation(true); + this->_linkShare->deleteShare(); + } + }); messageBox->open(); } @@ -437,11 +495,10 @@ void ShareLinkWidget::slotContextMenuButtonClicked() void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action) { - bool state = action->isChecked(); SharePermissions perm = SharePermissionRead; - if(action == _addAnotherLinkAction){ + if (action == _addAnotherLinkAction) { emit createLinkShare(); } else if (action == _readOnlyLinkAction && state) { @@ -465,6 +522,9 @@ void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action) } else if (action == _expirationDateLinkAction) { toggleExpireDateOptions(state); + } else if (action == _noteLinkAction) { + toggleNoteOptions(state); + } else if (action == _unshareLinkAction) { confirmAndDeleteShare(); } diff --git a/src/gui/sharelinkwidget.h b/src/gui/sharelinkwidget.h index 276dc88a0..34b2b3c3f 100644 --- a/src/gui/sharelinkwidget.h +++ b/src/gui/sharelinkwidget.h @@ -73,6 +73,9 @@ private slots: void slotPasswordSet(); void slotPasswordSetError(int code, const QString &message); + void slotCreateNote(); + void slotNoteSet(); + void slotSetExpireDate(); void slotExpireDateSet(); @@ -94,6 +97,10 @@ private: void showPasswordOptions(bool show); void togglePasswordOptions(bool enable); + void showNoteOptions(bool show); + void toggleNoteOptions(bool enable); + void setNote(const QString ¬e); + void showExpireDateOptions(bool show); void toggleExpireDateOptions(bool enable); @@ -119,6 +126,7 @@ private: bool _passwordRequired; bool _expiryRequired; bool _namesSupported; + bool _noteRequired; QMenu *_linkContextMenu; QAction *_readOnlyLinkAction; @@ -129,6 +137,7 @@ private: QAction *_expirationDateLinkAction; QAction *_unshareLinkAction; QAction *_addAnotherLinkAction; + QAction *_noteLinkAction; }; } diff --git a/src/gui/sharelinkwidget.ui b/src/gui/sharelinkwidget.ui index c2fe47103..9f79dad7f 100644 --- a/src/gui/sharelinkwidget.ui +++ b/src/gui/sharelinkwidget.ui @@ -6,8 +6,8 @@ 0 0 - 350 - 160 + 365 + 192 @@ -16,166 +16,26 @@ 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 1 - 0 - - - - - - - - - 1 - 0 - - - - Password: - - - 20 - - - - - - - false - - - - :/client/resources/more.svg:/client/resources/more.svg - - - QToolButton::InstantPopup - - - - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 123 - 121 - 134 - - - - - - - - TextLabel - - - Qt::PlainText - - - true - - - - - - - - 1 - 0 - - - - QLineEdit::Password - - - - - - - - :/client/resources/confirm.svg:/client/resources/confirm.svg - - - true - - - - - - - - :/client/resources/confirm.svg:/client/resources/confirm.svg - - - true - - - - + + - - - - 0 - 0 - - - - text-align: left - + - &Share link + - - - :/client/resources/public.svg:/client/resources/public.svg + + :/client/resources/public.svg - - true + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Share link @@ -225,21 +85,243 @@ + + + + false + + + + 0 + 0 + + + + + :/client/resources/more.svg:/client/resources/more.svg + + + QToolButton::InstantPopup + + + true + + + - - - - - 1 - 0 - + + + + QLayout::SetFixedSize + + + + + + 0 + 0 + + + + + 78 + 0 + + + + Note: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 10 + + + + + + + + 0 + 0 + + + + + 0 + 60 + + + + QAbstractScrollArea::AdjustToContents + + + + + + + + :/client/resources/confirm.svg:/client/resources/confirm.svg + + + true + + + + + + + + + + + + 0 + 0 + + + + + 78 + 0 + + + + Password: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 10 + + + + + + + + 1 + 0 + + + + QLineEdit::Password + + + + + + + + :/client/resources/confirm.svg:/client/resources/confirm.svg + + + true + + + + + + + + + + + + 0 + 0 + + + + + 78 + 0 + + + + Expires: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 10 + + + + + + + + 1 + 0 + + + + + + + + + :/client/resources/confirm.svg:/client/resources/confirm.svg + + + true + + + + + + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 123 + 121 + 134 + + + + + - Expiration date: + TextLabel - - 20 + + Qt::PlainText + + + true diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp index 1f96f2c6f..ca14c9b42 100644 --- a/src/gui/sharemanager.cpp +++ b/src/gui/sharemanager.cpp @@ -200,6 +200,11 @@ QString LinkShare::getName() const return _name; } +QString LinkShare::getNote() const +{ + return _note; +} + void LinkShare::setName(const QString &name) { OcsShareJob *job = new OcsShareJob(_account); @@ -208,6 +213,20 @@ void LinkShare::setName(const QString &name) job->setName(getId(), name); } +void LinkShare::setNote(const QString ¬e) +{ + OcsShareJob *job = new OcsShareJob(_account); + connect(job, &OcsShareJob::shareJobFinished, this, &LinkShare::slotNoteSet); + connect(job, &OcsJob::ocsError, this, &LinkShare::slotOcsError); + job->setNote(getId(), note); +} + +void LinkShare::slotNoteSet(const QJsonDocument &, const QVariant ¬e) +{ + _note = note.toString(); + emit noteSet(); +} + QString LinkShare::getToken() const { return _token; diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h index db48771b1..08de75f59 100644 --- a/src/gui/sharemanager.h +++ b/src/gui/sharemanager.h @@ -183,6 +183,12 @@ public: */ QString getName() const; + /* + * Returns the note of the link share. + */ + + QString getNote() const; + /* * Set the name of the link share. * @@ -190,6 +196,12 @@ public: */ void setName(const QString &name); + + /* + * Set the note of the link share. + */ + void setNote(const QString ¬e); + /* * Returns the token of the link share. */ @@ -224,11 +236,13 @@ public: signals: void expireDateSet(); void passwordSet(); + void noteSet(); void passwordSetError(int statusCode, const QString &message); void nameSet(); private slots: void slotPasswordSet(const QJsonDocument &, const QVariant &value); + void slotNoteSet(const QJsonDocument &, const QVariant &value); void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value); void slotSetPasswordError(int statusCode, const QString &message); void slotNameSet(const QJsonDocument &, const QVariant &value); @@ -237,6 +251,7 @@ private: QString _name; QString _token; bool _passwordSet; + QString _note; QDate _expireDate; QUrl _url; }; diff --git a/src/gui/shareusergroupwidget.ui b/src/gui/shareusergroupwidget.ui index ed1e43e7f..ab4c91797 100644 --- a/src/gui/shareusergroupwidget.ui +++ b/src/gui/shareusergroupwidget.ui @@ -7,7 +7,7 @@ 0 0 350 - 55 + 70 @@ -17,30 +17,24 @@ - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - + + + 0 + 0 + + - + + + 6 + 0 @@ -55,6 +49,12 @@ + + + 0 + 0 + + Share with users or groups ... diff --git a/src/gui/shareuserline.ui b/src/gui/shareuserline.ui index d586ef161..9336b12db 100644 --- a/src/gui/shareuserline.ui +++ b/src/gui/shareuserline.ui @@ -6,35 +6,26 @@ 0 0 - 350 - 45 + 360 + 58 - - 0 + + 1 0 + + + 360 + 0 + + true - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - + @@ -57,7 +48,7 @@ - + 0 0 @@ -70,6 +61,22 @@ + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + @@ -89,9 +96,12 @@ :/client/resources/more.svg:/client/resources/more.svg + + true + - +