ShareLinkWidget::getLinkShare()
-{
- return _linkShare;
-}
-
-void ShareLinkWidget::focusPasswordLineEdit()
-{
- _ui->lineEdit_password->setFocus();
-}
-
-void ShareLinkWidget::setupUiOptions()
-{
- connect(_linkShare.data(), &LinkShare::noteSet, this, &ShareLinkWidget::slotNoteSet);
- connect(_linkShare.data(), &LinkShare::passwordSet, this, &ShareLinkWidget::slotPasswordSet);
- connect(_linkShare.data(), &LinkShare::passwordSetError, this, &ShareLinkWidget::slotPasswordSetError);
- connect(_linkShare.data(), &LinkShare::labelSet, this, &ShareLinkWidget::slotLabelSet);
-
- // Prepare permissions check and create group action
- const QDate expireDate = _linkShare.data()->getExpireDate().isValid() ? _linkShare.data()->getExpireDate() : QDate();
- const SharePermissions perm = _linkShare.data()->getPermissions();
- auto checked = false;
- auto *permissionsGroup = new QActionGroup(this);
-
- // Prepare sharing menu
- _linkContextMenu = new QMenu(this);
-
- // radio button style
- permissionsGroup->setExclusive(true);
-
- if (_isFile) {
- checked = (perm & SharePermissionRead) && (perm & SharePermissionUpdate);
- _allowEditingLinkAction = _linkContextMenu->addAction(tr("Allow editing"));
- _allowEditingLinkAction->setCheckable(true);
- _allowEditingLinkAction->setChecked(checked);
-
- } else {
- checked = (perm == SharePermissionRead);
- _readOnlyLinkAction = permissionsGroup->addAction(tr("View only"));
- _readOnlyLinkAction->setCheckable(true);
- _readOnlyLinkAction->setChecked(checked);
-
- checked = (perm & SharePermissionRead) && (perm & SharePermissionCreate)
- && (perm & SharePermissionUpdate) && (perm & SharePermissionDelete);
- _allowUploadEditingLinkAction = permissionsGroup->addAction(tr("Allow upload and editing"));
- _allowUploadEditingLinkAction->setCheckable(true);
- _allowUploadEditingLinkAction->setChecked(checked);
-
- checked = (perm == SharePermissionCreate);
- _allowUploadLinkAction = permissionsGroup->addAction(tr("File drop (upload only)"));
- _allowUploadLinkAction->setCheckable(true);
- _allowUploadLinkAction->setChecked(checked);
- }
-
- _shareLinkElidedLabel = new OCC::ElidedLabel(this);
- _shareLinkElidedLabel->setElideMode(Qt::ElideRight);
- displayShareLinkLabel();
- _ui->horizontalLayout->insertWidget(2, _shareLinkElidedLabel);
-
- _shareLinkLayout = new QHBoxLayout(this);
-
- _shareLinkLabel = new QLabel(this);
- _shareLinkLabel->setPixmap(QString(":/client/theme/black/edit.svg"));
- _shareLinkLayout->addWidget(_shareLinkLabel);
-
- _shareLinkEdit = new QLineEdit(this);
- connect(_shareLinkEdit, &QLineEdit::returnPressed, this, &ShareLinkWidget::slotCreateLabel);
- _shareLinkEdit->setPlaceholderText(tr("Link name"));
- _shareLinkEdit->setText(_linkShare.data()->getLabel());
- _shareLinkLayout->addWidget(_shareLinkEdit);
-
- _shareLinkButton = new QToolButton(this);
- connect(_shareLinkButton, &QToolButton::clicked, this, &ShareLinkWidget::slotCreateLabel);
- _shareLinkButton->setIcon(QIcon(":/client/theme/confirm.svg"));
- _shareLinkButton->setToolButtonStyle(Qt::ToolButtonIconOnly);
- _shareLinkLayout->addWidget(_shareLinkButton);
-
- _shareLinkProgressIndicator = new QProgressIndicator(this);
- _shareLinkProgressIndicator->setVisible(false);
- _shareLinkLayout->addWidget(_shareLinkProgressIndicator);
-
- _shareLinkDefaultWidget = new QWidget(this);
- _shareLinkDefaultWidget->setLayout(_shareLinkLayout);
-
- _shareLinkWidgetAction = new QWidgetAction(this);
- _shareLinkWidgetAction->setDefaultWidget(_shareLinkDefaultWidget);
- _shareLinkWidgetAction->setCheckable(true);
- _linkContextMenu->addAction(_shareLinkWidgetAction);
-
- // Adds permissions actions (radio button style)
- if (_isFile) {
- _linkContextMenu->addAction(_allowEditingLinkAction);
- } else {
- _linkContextMenu->addAction(_readOnlyLinkAction);
- _linkContextMenu->addAction(_allowUploadEditingLinkAction);
- _linkContextMenu->addAction(_allowUploadLinkAction);
- }
-
- // Adds action to display note widget (check box)
- _noteLinkAction = _linkContextMenu->addAction(tr("Note to recipient"));
- _noteLinkAction->setCheckable(true);
-
- if (_linkShare->getNote().isSimpleText() && !_linkShare->getNote().isEmpty()) {
- _ui->textEdit_note->setText(_linkShare->getNote());
- _noteLinkAction->setChecked(true);
- toggleNoteOptions();
- }
-
- // Adds action to display password widget (check box)
- _passwordProtectLinkAction = _linkContextMenu->addAction(tr("Password protect"));
- _passwordProtectLinkAction->setCheckable(true);
-
- if (_linkShare.data()->isPasswordSet()) {
- _passwordProtectLinkAction->setChecked(true);
- _ui->lineEdit_password->setPlaceholderText(QString::fromUtf8(passwordIsSetPlaceholder));
- togglePasswordOptions();
- }
-
- // If password is enforced then don't allow users to disable it
- if (_account->capabilities().sharePublicLinkEnforcePassword()) {
- if (_linkShare.data()->isPasswordSet()) {
- _passwordProtectLinkAction->setChecked(true);
- _passwordProtectLinkAction->setEnabled(false);
- }
- _passwordRequired = true;
- }
-
- // Adds action to display expiration date widget (check box)
- _expirationDateLinkAction = _linkContextMenu->addAction(tr("Set expiration date"));
- _expirationDateLinkAction->setCheckable(true);
- if (!expireDate.isNull()) {
- _ui->calendar->setDate(expireDate);
- _expirationDateLinkAction->setChecked(true);
- toggleExpireDateOptions();
- }
- connect(_ui->calendar, &QDateTimeEdit::dateChanged, this, &ShareLinkWidget::slotSetExpireDate);
- connect(_linkShare.data(), &LinkShare::expireDateSet, this, &ShareLinkWidget::slotExpireDateSet);
-
-
- // If expiredate is enforced do not allow disable and set max days
- if (_account->capabilities().sharePublicLinkEnforceExpireDate()) {
- _ui->calendar->setMaximumDate(QDate::currentDate().addDays(
- _account->capabilities().sharePublicLinkExpireDateDays()));
- _expirationDateLinkAction->setChecked(true);
- _expirationDateLinkAction->setEnabled(false);
- _expiryRequired = true;
- }
-
- // Adds action to unshare widget (check box)
- _unshareLinkAction.reset(_linkContextMenu->addAction(QIcon(":/client/theme/delete.svg"),
- tr("Delete link")));
-
- _linkContextMenu->addSeparator();
-
- _addAnotherLinkAction.reset(_linkContextMenu->addAction(QIcon(":/client/theme/add.svg"),
- tr("Add another link")));
-
- _ui->enableShareLink->setIcon(QIcon(":/client/theme/copy.svg"));
- disconnect(_ui->enableShareLink, &QPushButton::clicked, this, &ShareLinkWidget::slotCreateShareLink);
- connect(_ui->enableShareLink, &QPushButton::clicked, this, &ShareLinkWidget::slotCopyLinkShare);
-
- connect(_linkContextMenu, &QMenu::triggered,
- this, &ShareLinkWidget::slotLinkContextMenuActionTriggered);
-
- _ui->shareLinkToolButton->setMenu(_linkContextMenu);
- _ui->shareLinkToolButton->setEnabled(true);
- _ui->enableShareLink->setEnabled(true);
- _ui->enableShareLink->setChecked(true);
-
- // show sharing options
- _ui->shareLinkToolButton->show();
-
- customizeStyle();
-}
-
-void ShareLinkWidget::slotCreateNote()
-{
- const auto note = _ui->textEdit_note->toPlainText();
- if (!_linkShare || _linkShare->getNote() == note || note.isEmpty()) {
- return;
- }
-
- toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction);
- _ui->errorLabel->hide();
- _linkShare->setNote(note);
-}
-
-void ShareLinkWidget::slotNoteSet()
-{
- toggleButtonAnimation(_ui->confirmNote, _ui->noteProgressIndicator, _noteLinkAction);
-}
-
-void ShareLinkWidget::slotCopyLinkShare(const bool clicked) const
-{
- Q_UNUSED(clicked);
-
- QApplication::clipboard()->setText(_linkShare->getLink().toString());
-}
-
-void ShareLinkWidget::slotExpireDateSet()
-{
- toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction);
-}
-
-void ShareLinkWidget::slotSetExpireDate()
-{
- if (!_linkShare) {
- return;
- }
-
- toggleButtonAnimation(_ui->confirmExpirationDate, _ui->expirationDateProgressIndicator, _expirationDateLinkAction);
- _ui->errorLabel->hide();
- _linkShare->setExpireDate(_ui->calendar->date());
-}
-
-void ShareLinkWidget::slotCreatePassword()
-{
- if (!_linkShare || _ui->lineEdit_password->text().isEmpty()) {
- return;
- }
-
- toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction);
- _ui->errorLabel->hide();
- emit createPassword(_ui->lineEdit_password->text());
-}
-
-void ShareLinkWidget::slotCreateShareLink(const bool clicked)
-{
- Q_UNUSED(clicked);
- slotToggleShareLinkAnimation(true);
- emit createLinkShare();
-}
-
-void ShareLinkWidget::slotPasswordSet()
-{
- toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction);
-
- _ui->lineEdit_password->setText({});
-
- if (_linkShare->isPasswordSet()) {
- _ui->lineEdit_password->setEnabled(true);
- _ui->lineEdit_password->setPlaceholderText(QString::fromUtf8(passwordIsSetPlaceholder));
- } else {
- _ui->lineEdit_password->setPlaceholderText({});
- }
-
- emit createPasswordProcessed();
-}
-
-void ShareLinkWidget::slotPasswordSetError(const int code, const QString &message)
-{
- toggleButtonAnimation(_ui->confirmPassword, _ui->passwordProgressIndicator, _passwordProtectLinkAction);
-
- slotServerError(code, message);
- togglePasswordOptions();
- _ui->lineEdit_password->setFocus();
- emit createPasswordProcessed();
-}
-
-void ShareLinkWidget::slotDeleteShareFetched()
-{
- slotToggleShareLinkAnimation(false);
-
- _linkShare.clear();
- togglePasswordOptions(false);
- toggleNoteOptions(false);
- toggleExpireDateOptions(false);
- emit deleteLinkShare();
-}
-
-void ShareLinkWidget::toggleNoteOptions(const bool enable)
-{
- _ui->noteLabel->setVisible(enable);
- _ui->textEdit_note->setVisible(enable);
- _ui->confirmNote->setVisible(enable);
- _ui->textEdit_note->setText(enable && _linkShare ? _linkShare->getNote() : QString());
-
- if (!enable && _linkShare && !_linkShare->getNote().isEmpty()) {
- _linkShare->setNote({});
- }
-}
-
-void ShareLinkWidget::slotCreateLabel()
-{
- const auto labelText = _shareLinkEdit->text();
- if (!_linkShare || _linkShare->getLabel() == labelText || labelText.isEmpty()) {
- return;
- }
- _shareLinkWidgetAction->setChecked(true);
- toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction);
- _ui->errorLabel->hide();
- _linkShare->setLabel(_shareLinkEdit->text());
-}
-
-void ShareLinkWidget::slotLabelSet()
-{
- toggleButtonAnimation(_shareLinkButton, _shareLinkProgressIndicator, _shareLinkWidgetAction);
- displayShareLinkLabel();
-}
-
-void ShareLinkWidget::slotCreateShareRequiresPassword(const QString &message)
-{
- slotToggleShareLinkAnimation(message.isEmpty());
-
- if (!message.isEmpty()) {
- _ui->errorLabel->setText(message);
- _ui->errorLabel->show();
- }
-
- _passwordRequired = true;
-
- togglePasswordOptions();
-}
-
-void ShareLinkWidget::togglePasswordOptions(const bool enable)
-{
- _ui->passwordLabel->setVisible(enable);
- _ui->lineEdit_password->setVisible(enable);
- _ui->confirmPassword->setVisible(enable);
- _ui->lineEdit_password->setFocus();
-
- if (!enable && _linkShare && _linkShare->isPasswordSet()) {
- _linkShare->setPassword({});
- }
-}
-
-void ShareLinkWidget::toggleExpireDateOptions(const bool enable)
-{
- _ui->expirationLabel->setVisible(enable);
- _ui->calendar->setVisible(enable);
- _ui->confirmExpirationDate->setVisible(enable);
-
- const auto date = enable ? _linkShare->getExpireDate() : QDate::currentDate().addDays(1);
- _ui->calendar->setDate(date);
- _ui->calendar->setMinimumDate(QDate::currentDate().addDays(1));
-
- if(_account->capabilities().sharePublicLinkEnforceExpireDate()) {
- _ui->calendar->setMaximumDate(QDate::currentDate().addDays(_account->capabilities().sharePublicLinkExpireDateDays()));
- }
-
- _ui->calendar->setFocus();
-
- if (!enable && _linkShare && _linkShare->getExpireDate().isValid()) {
- _linkShare->setExpireDate({});
- }
-}
-
-void ShareLinkWidget::confirmAndDeleteShare()
-{
- auto messageBox = new QMessageBox(
- QMessageBox::Question,
- tr("Confirm Link Share Deletion"),
- tr("Do you really want to delete the public link share %1?
"
- "Note: This action cannot be undone.
")
- .arg(shareName()),
- QMessageBox::NoButton,
- this);
- QPushButton *yesButton =
- messageBox->addButton(tr("Delete"), QMessageBox::YesRole);
- messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
-
- connect(messageBox, &QMessageBox::finished, this,
- [messageBox, yesButton, this]() {
- if (messageBox->clickedButton() == yesButton) {
- this->slotToggleShareLinkAnimation(true);
- this->_linkShare->deleteShare();
- }
- });
- messageBox->open();
-}
-
-QString ShareLinkWidget::shareName() const
-{
- QString name = _linkShare->getName();
- if (!name.isEmpty())
- return name;
- if (!_namesSupported)
- return tr("Public link");
- return _linkShare->getToken();
-}
-
-void ShareLinkWidget::slotContextMenuButtonClicked()
-{
- _linkContextMenu->exec(QCursor::pos());
-}
-
-void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action)
-{
- const auto state = action->isChecked();
- SharePermissions perm = SharePermissionRead;
-
- if (action == _addAnotherLinkAction.data()) {
- emit createLinkShare();
-
- } else if (action == _readOnlyLinkAction && state) {
- _linkShare->setPermissions(perm);
-
- } else if (action == _allowEditingLinkAction && state) {
- perm |= SharePermissionUpdate;
- _linkShare->setPermissions(perm);
-
- } else if (action == _allowUploadEditingLinkAction && state) {
- perm |= SharePermissionCreate | SharePermissionUpdate | SharePermissionDelete;
- _linkShare->setPermissions(perm);
-
- } else if (action == _allowUploadLinkAction && state) {
- perm = SharePermissionCreate;
- _linkShare->setPermissions(perm);
-
- } else if (action == _passwordProtectLinkAction) {
- togglePasswordOptions(state);
-
- } else if (action == _expirationDateLinkAction) {
- toggleExpireDateOptions(state);
-
- } else if (action == _noteLinkAction) {
- toggleNoteOptions(state);
-
- } else if (action == _unshareLinkAction.data()) {
- confirmAndDeleteShare();
- }
-}
-
-void ShareLinkWidget::slotServerError(const int code, const QString &message)
-{
- slotToggleShareLinkAnimation(false);
-
- qCWarning(lcSharing) << "Error from server" << code << message;
- displayError(message);
-}
-
-void ShareLinkWidget::displayError(const QString &errMsg)
-{
- _ui->errorLabel->setText(errMsg);
- _ui->errorLabel->show();
-}
-
-void ShareLinkWidget::slotStyleChanged()
-{
- customizeStyle();
-}
-
-void ShareLinkWidget::customizeStyle()
-{
- if(_unshareLinkAction) {
- _unshareLinkAction->setIcon(Theme::createColorAwareIcon(":/client/theme/delete.svg"));
- }
-
- if(_addAnotherLinkAction) {
- _addAnotherLinkAction->setIcon(Theme::createColorAwareIcon(":/client/theme/add.svg"));
- }
-
- _ui->enableShareLink->setIcon(Theme::createColorAwareIcon(":/client/theme/copy.svg"));
-
- _ui->shareLinkIconLabel->setPixmap(Theme::createColorAwarePixmap(":/client/theme/public.svg"));
-
- _ui->shareLinkToolButton->setIcon(Theme::createColorAwareIcon(":/client/theme/more.svg"));
-
- _ui->confirmNote->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg"));
- _ui->confirmPassword->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg"));
- _ui->confirmExpirationDate->setIcon(Theme::createColorAwareIcon(":/client/theme/confirm.svg"));
-
- _ui->passwordProgressIndicator->setColor(QGuiApplication::palette().color(QPalette::Text));
-}
-
-void ShareLinkWidget::displayShareLinkLabel()
-{
- _shareLinkElidedLabel->clear();
- if (!_linkShare->getLabel().isEmpty()) {
- _shareLinkElidedLabel->setText(QString("(%1)").arg(_linkShare->getLabel()));
- }
-}
-
-}
diff --git a/src/gui/sharelinkwidget.h b/src/gui/sharelinkwidget.h
deleted file mode 100644
index 7ecd9691e..000000000
--- a/src/gui/sharelinkwidget.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) by Roeland Jago Douma
- * Copyright (C) 2015 by Klaas Freitag
- *
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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 SHARELINKWIDGET_H
-#define SHARELINKWIDGET_H
-
-#include "accountfwd.h"
-#include "sharepermissions.h"
-#include "QProgressIndicator.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-class QMenu;
-class QTableWidgetItem;
-
-namespace OCC {
-
-namespace Ui {
- class ShareLinkWidget;
-}
-
-class AbstractCredentials;
-class SyncResult;
-class LinkShare;
-class Share;
-class ElidedLabel;
-
-/**
- * @brief The ShareDialog class
- * @ingroup gui
- */
-class ShareLinkWidget : public QWidget
-{
- Q_OBJECT
-
-public:
- explicit ShareLinkWidget(AccountPtr account,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- QWidget *parent = nullptr);
- ~ShareLinkWidget() override;
-
- void toggleButton(bool show);
- void setupUiOptions();
-
- void setLinkShare(QSharedPointer linkShare);
- QSharedPointer getLinkShare();
-
- void focusPasswordLineEdit();
-
-public slots:
- void slotDeleteShareFetched();
- void slotToggleShareLinkAnimation(const bool start);
- void slotServerError(const int code, const QString &message);
- void slotCreateShareRequiresPassword(const QString &message);
- void slotStyleChanged();
-
-private slots:
- void slotCreateShareLink(const bool clicked);
- void slotCopyLinkShare(const bool clicked) const;
-
- void slotCreatePassword();
- void slotPasswordSet();
- void slotPasswordSetError(const int code, const QString &message);
-
- void slotCreateNote();
- void slotNoteSet();
-
- void slotSetExpireDate();
- void slotExpireDateSet();
-
- void slotContextMenuButtonClicked();
- void slotLinkContextMenuActionTriggered(QAction *action);
-
- void slotCreateLabel();
- void slotLabelSet();
-
-signals:
- void createLinkShare();
- void deleteLinkShare();
- void visualDeletionDone();
- void createPassword(const QString &password);
- void createPasswordProcessed();
-
-private:
- void displayError(const QString &errMsg);
-
- void togglePasswordOptions(const bool enable = true);
- void toggleNoteOptions(const bool enable = true);
- void toggleExpireDateOptions(const bool enable = true);
- void toggleButtonAnimation(QToolButton *button, QProgressIndicator *progressIndicator, const QAction *checkedAction) const;
-
- /** Confirm with the user and then delete the share */
- void confirmAndDeleteShare();
-
- /** Retrieve a share's name, accounting for _namesSupported */
- [[nodiscard]] QString shareName() const;
-
- void customizeStyle();
-
- void displayShareLinkLabel();
-
- Ui::ShareLinkWidget *_ui;
- AccountPtr _account;
- QString _sharePath;
- QString _localPath;
- QString _shareUrl;
-
- QSharedPointer _linkShare;
-
- bool _isFile;
- bool _passwordRequired;
- bool _expiryRequired;
- bool _namesSupported;
- bool _noteRequired;
-
- QMenu *_linkContextMenu;
- QAction *_readOnlyLinkAction;
- QAction *_allowEditingLinkAction;
- QAction *_allowUploadEditingLinkAction;
- QAction *_allowUploadLinkAction;
- QAction *_passwordProtectLinkAction;
- QAction *_expirationDateLinkAction;
- QScopedPointer _unshareLinkAction;
- QScopedPointer _addAnotherLinkAction;
- QAction *_noteLinkAction;
- QHBoxLayout *_shareLinkLayout{};
- QLabel *_shareLinkLabel{};
- ElidedLabel *_shareLinkElidedLabel{};
- QLineEdit *_shareLinkEdit{};
- QToolButton *_shareLinkButton{};
- QProgressIndicator *_shareLinkProgressIndicator{};
- QWidget *_shareLinkDefaultWidget{};
- QWidgetAction *_shareLinkWidgetAction{};
-};
-}
-
-#endif // SHARELINKWIDGET_H
diff --git a/src/gui/sharelinkwidget.ui b/src/gui/sharelinkwidget.ui
deleted file mode 100644
index a0d5f3df9..000000000
--- a/src/gui/sharelinkwidget.ui
+++ /dev/null
@@ -1,439 +0,0 @@
-
-
- OCC::ShareLinkWidget
-
-
-
- 0
- 0
- 400
- 238
-
-
-
-
- 0
- 0
-
-
-
-
- 0
-
-
- 12
-
-
- 0
-
-
- 20
-
-
- 0
-
- -
-
-
- 6
-
-
- 0
-
-
-
-
-
-
-
-
- :/client/theme/public.svg
-
-
- Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
-
-
-
- -
-
-
- Share link
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 25
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 28
- 27
-
-
-
-
- -
-
-
- Qt::Horizontal
-
-
-
- 40
- 25
-
-
-
-
- -
-
-
-
-
-
-
- :/client/theme/add.svg:/client/theme/add.svg
-
-
- false
-
-
- true
-
-
-
- -
-
-
- false
-
-
-
- 0
- 0
-
-
-
-
- :/client/theme/more.svg:/client/theme/more.svg
-
-
- QToolButton::InstantPopup
-
-
- true
-
-
-
-
-
- -
-
-
- 22
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- 78
- 0
-
-
-
- Note
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
-
-
- 0
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 0
- 60
-
-
-
- QAbstractScrollArea::AdjustToContents
-
-
-
- -
-
-
-
- 28
- 27
-
-
-
-
- :/client/theme/confirm.svg:/client/theme/confirm.svg
-
-
- true
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 28
- 27
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 78
- 0
-
-
-
- Set password
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
-
-
- 0
-
-
-
- -
-
-
-
- 1
- 0
-
-
-
- QLineEdit::Password
-
-
-
- -
-
-
-
- 28
- 27
-
-
-
-
- :/client/theme/confirm.svg:/client/theme/confirm.svg
-
-
- true
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 28
- 27
-
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 78
- 0
-
-
-
- Expires
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter
-
-
- 0
-
-
-
- -
-
-
-
- 1
- 0
-
-
-
-
- -
-
-
-
- 28
- 27
-
-
-
-
- :/client/theme/confirm.svg:/client/theme/confirm.svg
-
-
- true
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 28
- 27
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
- 255
- 0
- 0
-
-
-
-
-
-
-
-
- 255
- 0
- 0
-
-
-
-
-
-
-
-
- 123
- 121
- 134
-
-
-
-
-
-
-
- TextLabel
-
-
- Qt::PlainText
-
-
- true
-
-
-
-
-
-
-
-
-
-
- QProgressIndicator
- QWidget
-
- 1
-
-
-
-
-
-
-
diff --git a/src/gui/sharemanager.cpp b/src/gui/sharemanager.cpp
index 154bcbec3..7a264557d 100644
--- a/src/gui/sharemanager.cpp
+++ b/src/gui/sharemanager.cpp
@@ -58,7 +58,7 @@ Share::Share(AccountPtr account,
const ShareType shareType,
bool isPasswordSet,
const Permissions permissions,
- const QSharedPointer shareWith)
+ const ShareePtr shareWith)
: _account(account)
, _id(id)
, _uidowner(uidowner)
@@ -101,7 +101,7 @@ Share::ShareType Share::getShareType() const
return _shareType;
}
-QSharedPointer Share::getShareWith() const
+ShareePtr Share::getShareWith() const
{
return _shareWith;
}
@@ -316,7 +316,7 @@ UserGroupShare::UserGroupShare(AccountPtr account,
const ShareType shareType,
bool isPasswordSet,
const Permissions permissions,
- const QSharedPointer shareWith,
+ const ShareePtr shareWith,
const QDate &expireDate,
const QString ¬e)
: Share(account, id, owner, ownerDisplayName, path, shareType, isPasswordSet, permissions, shareWith)
@@ -461,7 +461,7 @@ void ShareManager::slotShareCreated(const QJsonDocument &reply)
{
//Parse share
auto data = reply.object().value("ocs").toObject().value("data").toObject();
- QSharedPointer share(parseShare(data));
+ SharePtr share(parseShare(data));
emit shareCreated(share);
@@ -482,14 +482,14 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
const QString versionString = _account->serverVersion();
qCDebug(lcSharing) << versionString << "Fetched" << tmpShares.count() << "shares";
- QList> shares;
+ QList shares;
foreach (const auto &share, tmpShares) {
auto data = share.toObject();
auto shareType = data.value("share_type").toInt();
- QSharedPointer newShare;
+ SharePtr newShare;
if (shareType == Share::TypeLink) {
newShare = parseLinkShare(data);
@@ -499,7 +499,7 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
newShare = parseShare(data);
}
- shares.append(QSharedPointer(newShare));
+ shares.append(SharePtr(newShare));
}
qCDebug(lcSharing) << "Sending " << shares.count() << "shares";
@@ -508,7 +508,7 @@ void ShareManager::slotSharesFetched(const QJsonDocument &reply)
QSharedPointer ShareManager::parseUserGroupShare(const QJsonObject &data)
{
- QSharedPointer sharee(new Sharee(data.value("share_with").toString(),
+ ShareePtr sharee(new Sharee(data.value("share_with").toString(),
data.value("share_with_displayname").toString(),
static_cast(data.value("share_type").toInt())));
@@ -577,13 +577,13 @@ QSharedPointer ShareManager::parseLinkShare(const QJsonObject &data)
data.value("label").toString()));
}
-QSharedPointer ShareManager::parseShare(const QJsonObject &data)
+SharePtr ShareManager::parseShare(const QJsonObject &data) const
{
- QSharedPointer sharee(new Sharee(data.value("share_with").toString(),
+ ShareePtr sharee(new Sharee(data.value("share_with").toString(),
data.value("share_with_displayname").toString(),
(Sharee::Type)data.value("share_type").toInt()));
- return QSharedPointer(new Share(_account,
+ return SharePtr(new Share(_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(),
diff --git a/src/gui/sharemanager.h b/src/gui/sharemanager.h
index 16d2e47c3..1d9918f04 100644
--- a/src/gui/sharemanager.h
+++ b/src/gui/sharemanager.h
@@ -36,6 +36,15 @@ class OcsShareJob;
class Share : public QObject
{
Q_OBJECT
+ Q_PROPERTY(AccountPtr account READ account CONSTANT)
+ Q_PROPERTY(QString path READ path CONSTANT)
+ Q_PROPERTY(QString id READ getId CONSTANT)
+ Q_PROPERTY(QString uidOwner READ getUidOwner CONSTANT)
+ Q_PROPERTY(QString ownerDisplayName READ getOwnerDisplayName CONSTANT)
+ Q_PROPERTY(ShareType shareType READ getShareType CONSTANT)
+ Q_PROPERTY(ShareePtr shareWith READ getShareWith CONSTANT)
+ Q_PROPERTY(Permissions permissions READ getPermissions WRITE setPermissions NOTIFY permissionsSet)
+ Q_PROPERTY(bool isPasswordSet READ isPasswordSet NOTIFY passwordSet)
public:
/**
@@ -43,14 +52,16 @@ public:
* Need to be in sync with Sharee::Type
*/
enum ShareType {
+ TypePlaceholderLink = -1,
TypeUser = Sharee::User,
TypeGroup = Sharee::Group,
TypeLink = 3,
TypeEmail = Sharee::Email,
TypeRemote = Sharee::Federated,
TypeCircle = Sharee::Circle,
- TypeRoom = Sharee::Room
+ TypeRoom = Sharee::Room,
};
+ Q_ENUM(ShareType);
using Permissions = SharePermissions;
@@ -65,7 +76,7 @@ public:
const ShareType shareType,
bool isPasswordSet = false,
const Permissions permissions = SharePermissionDefault,
- const QSharedPointer shareWith = QSharedPointer(nullptr));
+ const ShareePtr shareWith = ShareePtr(nullptr));
/**
* The account the share is defined on.
@@ -97,13 +108,36 @@ public:
/*
* Get the shareWith
*/
- [[nodiscard]] QSharedPointer getShareWith() const;
+ [[nodiscard]] ShareePtr getShareWith() const;
/*
* Get permissions
*/
[[nodiscard]] Permissions getPermissions() const;
+ [[nodiscard]] bool isPasswordSet() const;
+
+ /*
+ * Is it a share with a user or group (local or remote)
+ */
+ [[nodiscard]] static bool isShareTypeUserGroupEmailRoomOrRemote(const ShareType type);
+
+signals:
+ void permissionsSet();
+ void shareDeleted();
+ void serverError(int code, const QString &message);
+ void passwordSet();
+ void passwordSetError(int statusCode, const QString &message);
+
+public slots:
+ /*
+ * Deletes a share
+ *
+ * On success the shareDeleted signal is emitted
+ * In case of a server error the serverError signal is emitted.
+ */
+ void deleteShare();
+
/*
* Set the permissions of a share
*
@@ -120,28 +154,6 @@ public:
*/
void setPassword(const QString &password);
- [[nodiscard]] bool isPasswordSet() const;
-
- /*
- * Deletes a share
- *
- * On success the shareDeleted signal is emitted
- * In case of a server error the serverError signal is emitted.
- */
- void deleteShare();
-
- /*
- * Is it a share with a user or group (local or remote)
- */
- static bool isShareTypeUserGroupEmailRoomOrRemote(const ShareType type);
-
-signals:
- void permissionsSet();
- void shareDeleted();
- void serverError(int code, const QString &message);
- void passwordSet();
- void passwordSetError(int statusCode, const QString &message);
-
protected:
AccountPtr _account;
QString _id;
@@ -151,7 +163,7 @@ protected:
ShareType _shareType;
bool _isPasswordSet;
Permissions _permissions;
- QSharedPointer _shareWith;
+ ShareePtr _shareWith;
protected slots:
void slotOcsError(int statusCode, const QString &message);
@@ -163,6 +175,8 @@ private slots:
void slotPermissionsSet(const QJsonDocument &, const QVariant &value);
};
+using SharePtr = QSharedPointer;
+
/**
* A Link share is just like a regular share but then slightly different.
* There are several methods in the API that either work differently for
@@ -171,6 +185,16 @@ private slots:
class LinkShare : public Share
{
Q_OBJECT
+ Q_PROPERTY(QUrl link READ getLink CONSTANT)
+ Q_PROPERTY(QUrl directDownloadLink READ getDirectDownloadLink CONSTANT)
+ Q_PROPERTY(bool publicCanUpload READ getPublicUpload CONSTANT)
+ Q_PROPERTY(bool publicCanReadDirectory READ getShowFileListing CONSTANT)
+ Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameSet)
+ Q_PROPERTY(QString note READ getNote WRITE setNote NOTIFY noteSet)
+ Q_PROPERTY(QString label READ getLabel WRITE setLabel NOTIFY labelSet)
+ Q_PROPERTY(QDate expireDate READ getExpireDate WRITE setExpireDate NOTIFY expireDateSet)
+ Q_PROPERTY(QString token READ getToken CONSTANT)
+
public:
explicit LinkShare(AccountPtr account,
const QString &id,
@@ -221,6 +245,23 @@ public:
*/
[[nodiscard]] QString getLabel() const;
+ /*
+ * Returns the token of the link share.
+ */
+ [[nodiscard]] QString getToken() const;
+
+ /*
+ * Get the expiration date
+ */
+ [[nodiscard]] QDate getExpireDate() const;
+
+ /*
+ * Create OcsShareJob and connect to signal/slots
+ */
+ template
+ OcsShareJob *createShareJob(const LinkShareSlot slotFunction);
+
+public slots:
/*
* Set the name of the link share.
*
@@ -233,16 +274,6 @@ public:
*/
void setNote(const QString ¬e);
- /*
- * Returns the token of the link share.
- */
- [[nodiscard]] QString getToken() const;
-
- /*
- * Get the expiration date
- */
- [[nodiscard]] QDate getExpireDate() const;
-
/*
* Set the expiration date
*
@@ -250,19 +281,12 @@ public:
* In case of a server error the serverError signal is emitted.
*/
void setExpireDate(const QDate &expireDate);
-
+
/*
* Set the label of the share link.
*/
void setLabel(const QString &label);
- /*
- * Create OcsShareJob and connect to signal/slots
- */
- template
- OcsShareJob *createShareJob(const LinkShareSlot slotFunction);
-
-
signals:
void expireDateSet();
void noteSet();
@@ -287,6 +311,8 @@ private:
class UserGroupShare : public Share
{
Q_OBJECT
+ Q_PROPERTY(QString note READ getNote WRITE setNote NOTIFY noteSet)
+ Q_PROPERTY(QDate expireDate READ getExpireDate WRITE setExpireDate NOTIFY expireDateSet)
public:
UserGroupShare(AccountPtr account,
const QString &id,
@@ -296,27 +322,26 @@ public:
const ShareType shareType,
bool isPasswordSet,
const Permissions permissions,
- const QSharedPointer shareWith,
+ const ShareePtr shareWith,
const QDate &expireDate,
const QString ¬e);
- void setNote(const QString ¬e);
-
[[nodiscard]] QString getNote() const;
-
- void slotNoteSet(const QJsonDocument &, const QVariant ¬e);
-
- void setExpireDate(const QDate &date);
-
[[nodiscard]] QDate getExpireDate() const;
- void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value);
+public slots:
+ void setNote(const QString ¬e);
+ void setExpireDate(const QDate &date);
signals:
void noteSet();
void noteSetError();
void expireDateSet();
+private slots:
+ void slotNoteSet(const QJsonDocument &json, const QVariant ¬e);
+ void slotExpireDateSet(const QJsonDocument &reply, const QVariant &value);
+
private:
QString _note;
QDate _expireDate;
@@ -375,9 +400,9 @@ public:
void fetchShares(const QString &path);
signals:
- void shareCreated(const QSharedPointer &share);
+ void shareCreated(const SharePtr &share);
void linkShareCreated(const QSharedPointer &share);
- void sharesFetched(const QList> &shares);
+ void sharesFetched(const QList &shares);
void serverError(int code, const QString &message);
/** Emitted when creating a link share with password fails.
@@ -396,10 +421,12 @@ private slots:
private:
QSharedPointer parseLinkShare(const QJsonObject &data);
QSharedPointer parseUserGroupShare(const QJsonObject &data);
- QSharedPointer parseShare(const QJsonObject &data);
+ SharePtr parseShare(const QJsonObject &data) const;
AccountPtr _account;
};
}
+Q_DECLARE_METATYPE(OCC::SharePtr);
+
#endif // SHAREMANAGER_H
diff --git a/src/gui/shareusergroupwidget.cpp b/src/gui/shareusergroupwidget.cpp
deleted file mode 100644
index 024e1266e..000000000
--- a/src/gui/shareusergroupwidget.cpp
+++ /dev/null
@@ -1,1129 +0,0 @@
-/*
- * 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; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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 "ocsprofileconnector.h"
-#include "sharee.h"
-#include "tray/usermodel.h"
-#include "ui_shareusergroupwidget.h"
-#include "ui_shareuserline.h"
-#include "shareusergroupwidget.h"
-#include "account.h"
-#include "folderman.h"
-#include "folder.h"
-#include "accountmanager.h"
-#include "theme.h"
-#include "configfile.h"
-#include "capabilities.h"
-#include "guiutility.h"
-#include "thumbnailjob.h"
-#include "sharemanager.h"
-#include "theme.h"
-#include "iconutils.h"
-
-#include "QProgressIndicator.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-namespace {
-const char *passwordIsSetPlaceholder = "●●●●●●●●";
-
-}
-
-namespace OCC {
-
-AvatarEventFilter::AvatarEventFilter(QObject *parent)
- : QObject(parent)
-{
-}
-
-
-bool AvatarEventFilter::eventFilter(QObject *obj, QEvent *event)
-{
- if (event->type() == QEvent::ContextMenu) {
- const auto contextMenuEvent = dynamic_cast(event);
- if (!contextMenuEvent) {
- return false;
- }
- emit contextMenu(contextMenuEvent->globalPos());
- return true;
- }
- return QObject::eventFilter(obj, event);
-}
-
-ShareUserGroupWidget::ShareUserGroupWidget(AccountPtr account,
- const QString &sharePath,
- const QString &localPath,
- SharePermissions maxSharingPermissions,
- const QString &privateLinkUrl,
- QWidget *parent)
- : QWidget(parent)
- , _ui(new Ui::ShareUserGroupWidget)
- , _account(account)
- , _sharePath(sharePath)
- , _localPath(localPath)
- , _maxSharingPermissions(maxSharingPermissions)
- , _privateLinkUrl(privateLinkUrl)
- , _disableCompleterActivated(false)
-{
- setAttribute(Qt::WA_DeleteOnClose);
- setObjectName("SharingDialogUG"); // required as group for saveGeometry call
-
- _ui->setupUi(this);
-
- //Is this a file or folder?
- _isFile = QFileInfo(localPath).isFile();
-
- _completer = new QCompleter(this);
- _completerModel = new ShareeModel(_account,
- _isFile ? QLatin1String("file") : QLatin1String("folder"),
- _completer);
- connect(_completerModel, &ShareeModel::shareesReady, this, &ShareUserGroupWidget::slotShareesReady);
- connect(_completerModel, &ShareeModel::displayErrorMessage, this, &ShareUserGroupWidget::displayError);
-
- _completer->setModel(_completerModel);
- _completer->setCaseSensitivity(Qt::CaseInsensitive);
- _completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
- _ui->shareeLineEdit->setCompleter(_completer);
-
- _searchGloballyAction.reset(new QAction(_ui->shareeLineEdit));
- _searchGloballyAction->setIcon(Theme::createColorAwareIcon(":/client/theme/magnifying-glass.svg"));
- _searchGloballyAction->setToolTip(tr("Search globally"));
-
- connect(_searchGloballyAction.data(), &QAction::triggered, this, [this]() {
- searchForSharees(ShareeModel::GlobalSearch);
- });
-
- _ui->shareeLineEdit->addAction(_searchGloballyAction.data(), QLineEdit::LeadingPosition);
-
- _manager = new ShareManager(_account, this);
- connect(_manager, &ShareManager::sharesFetched, this, &ShareUserGroupWidget::slotSharesFetched);
- connect(_manager, &ShareManager::shareCreated, this, &ShareUserGroupWidget::slotShareCreated);
- connect(_manager, &ShareManager::serverError, this, &ShareUserGroupWidget::displayError);
- connect(_ui->shareeLineEdit, &QLineEdit::returnPressed, this, &ShareUserGroupWidget::slotLineEditReturn);
- connect(_ui->confirmShare, &QAbstractButton::clicked, this, &ShareUserGroupWidget::slotLineEditReturn);
- //TODO connect(_ui->privateLinkText, &QLabel::linkActivated, this, &ShareUserGroupWidget::slotPrivateLinkShare);
-
- // By making the next two QueuedConnections we can override
- // the strings the completer sets on the line edit.
- connect(_completer, SIGNAL(activated(QModelIndex)), SLOT(slotCompleterActivated(QModelIndex)),
- Qt::QueuedConnection);
- connect(_completer, SIGNAL(highlighted(QModelIndex)), SLOT(slotCompleterHighlighted(QModelIndex)),
- Qt::QueuedConnection);
-
- // Queued connection so this signal is recieved after textChanged
- connect(_ui->shareeLineEdit, &QLineEdit::textEdited,
- this, &ShareUserGroupWidget::slotLineEditTextEdited, Qt::QueuedConnection);
- _ui->shareeLineEdit->installEventFilter(this);
- connect(&_completionTimer, &QTimer::timeout, this, [this]() {
- searchForSharees(ShareeModel::LocalSearch);
- });
- _completionTimer.setSingleShot(true);
- _completionTimer.setInterval(600);
-
- _ui->errorLabel->hide();
-
- _parentScrollArea = parentWidget()->findChild("scrollArea");
- _shareUserGroup = new QVBoxLayout(_parentScrollArea);
- _shareUserGroup->setContentsMargins(0, 0, 0, 0);
- customizeStyle();
-}
-
-QVBoxLayout *ShareUserGroupWidget::shareUserGroupLayout()
-{
- return _shareUserGroup;
-}
-
-ShareUserGroupWidget::~ShareUserGroupWidget()
-{
- delete _ui;
-}
-
-void ShareUserGroupWidget::on_shareeLineEdit_textChanged(const QString &)
-{
- _completionTimer.stop();
- emit togglePublicLinkShare(false);
-}
-
-void ShareUserGroupWidget::slotLineEditTextEdited(const QString &text)
-{
- _disableCompleterActivated = false;
- // First textChanged is called first and we stopped the timer when the text is changed, programatically or not
- // Then we restart the timer here if the user touched a key
- if (!text.isEmpty()) {
- _completionTimer.start();
- emit togglePublicLinkShare(true);
- }
-}
-
-void ShareUserGroupWidget::slotLineEditReturn()
-{
- _disableCompleterActivated = false;
- // did the user type in one of the options?
- const auto text = _ui->shareeLineEdit->text();
- for (int i = 0; i < _completerModel->rowCount(); ++i) {
- const auto sharee = _completerModel->getSharee(i);
- if (sharee->format() == text
- || sharee->displayName() == text
- || sharee->shareWith() == text) {
- slotCompleterActivated(_completerModel->index(i));
- // make sure we do not send the same item twice (because return is called when we press
- // return to activate an item inthe completer)
- _disableCompleterActivated = true;
- return;
- }
- }
-
- // nothing found? try to refresh completion
- _completionTimer.start();
-}
-
-void ShareUserGroupWidget::searchForSharees(ShareeModel::LookupMode lookupMode)
-{
- if (_ui->shareeLineEdit->text().isEmpty()) {
- return;
- }
-
- _ui->shareeLineEdit->setEnabled(false);
- _completionTimer.stop();
- _pi_sharee.startAnimation();
- ShareeModel::ShareeSet blacklist;
-
- // Add the current user to _sharees since we can't share with ourself
- QSharedPointer currentUser(new Sharee(_account->credentials()->user(), "", Sharee::Type::User));
- blacklist << currentUser;
-
- foreach (auto sw, _parentScrollArea->findChildren()) {
- blacklist << sw->share()->getShareWith();
- }
- _ui->errorLabel->hide();
- _completerModel->fetch(_ui->shareeLineEdit->text(), blacklist, lookupMode);
-}
-
-void ShareUserGroupWidget::getShares()
-{
- _manager->fetchShares(_sharePath);
-}
-
-void ShareUserGroupWidget::slotShareCreated(const QSharedPointer &share)
-{
- if (share && _account->capabilities().shareEmailPasswordEnabled() && !_account->capabilities().shareEmailPasswordEnforced()) {
- // remember this share Id so we can set it's password Line Edit to focus later
- _lastCreatedShareId = share->getId();
- }
- // fetch all shares including the one we've just created
- getShares();
-}
-
-void ShareUserGroupWidget::slotSharesFetched(const QList> &shares)
-{
- int x = 0;
- QList linkOwners({});
-
- ShareUserLine *justCreatedShareThatNeedsPassword = nullptr;
-
- while (QLayoutItem *shareUserLine = _shareUserGroup->takeAt(0)) {
- delete shareUserLine->widget();
- delete shareUserLine;
- }
-
- foreach (const auto &share, shares) {
- // We don't handle link shares, only TypeUser or TypeGroup
- if (share->getShareType() == Share::TypeLink) {
- if(!share->getUidOwner().isEmpty() &&
- share->getUidOwner() != share->account()->davUser()){
- linkOwners.append(share->getOwnerDisplayName());
- }
- continue;
- }
-
- // the owner of the file that shared it first
- // leave out if it's the current user
- if(x == 0 && !share->getUidOwner().isEmpty() && !(share->getUidOwner() == _account->credentials()->user())) {
- _ui->mainOwnerLabel->setText(QString("Shared with you by ").append(share->getOwnerDisplayName()));
- }
-
-
- Q_ASSERT(Share::isShareTypeUserGroupEmailRoomOrRemote(share->getShareType()));
- auto userGroupShare = qSharedPointerDynamicCast(share);
- auto *s = new ShareUserLine(_account, userGroupShare, _maxSharingPermissions, _isFile, _parentScrollArea);
- connect(s, &ShareUserLine::visualDeletionDone, this, &ShareUserGroupWidget::getShares);
- s->setBackgroundRole(_shareUserGroup->count() % 2 == 0 ? QPalette::Base : QPalette::AlternateBase);
-
- // Connect styleChanged events to our widget, so it can adapt (Dark-/Light-Mode switching)
- connect(this, &ShareUserGroupWidget::styleChanged, s, &ShareUserLine::slotStyleChanged);
- _shareUserGroup->addWidget(s);
-
- if (!_lastCreatedShareId.isEmpty() && share->getId() == _lastCreatedShareId) {
- _lastCreatedShareId = QString();
- if (_account->capabilities().shareEmailPasswordEnabled() && !_account->capabilities().shareEmailPasswordEnforced()) {
- justCreatedShareThatNeedsPassword = s;
- }
- }
-
- x++;
- }
-
- foreach (const QString &owner, linkOwners) {
- auto ownerLabel = new QLabel(QString(owner + " shared via link"));
- _shareUserGroup->addWidget(ownerLabel);
- ownerLabel->setVisible(true);
- }
-
- _disableCompleterActivated = false;
- activateShareeLineEdit();
-
- if (justCreatedShareThatNeedsPassword) {
- // always set focus to a password Line Edit when the new email share is created on a server with optional passwords enabled for email shares
- justCreatedShareThatNeedsPassword->focusPasswordLineEdit();
- }
-}
-
-void ShareUserGroupWidget::slotPrivateLinkShare()
-{
- auto menu = new QMenu(this);
- menu->setAttribute(Qt::WA_DeleteOnClose);
-
- // this icon is not handled by slotStyleChanged() -> customizeStyle but we can live with that
- menu->addAction(Theme::createColorAwareIcon(":/client/theme/copy.svg"),
- tr("Copy link"),
- this, SLOT(slotPrivateLinkCopy()));
-
- menu->exec(QCursor::pos());
-}
-
-void ShareUserGroupWidget::slotShareesReady()
-{
- activateShareeLineEdit();
-
- _pi_sharee.stopAnimation();
- if (_completerModel->rowCount() == 0) {
- displayError(0, tr("No results for \"%1\"").arg(_completerModel->currentSearch()));
- }
-
- // if no rows are present in the model - complete() will hide the completer
- _completer->complete();
-}
-
-void ShareUserGroupWidget::slotCompleterActivated(const QModelIndex &index)
-{
- if (_disableCompleterActivated)
- return;
- // The index is an index from the QCompletion model which is itelf a proxy
- // model proxying the _completerModel
- auto sharee = qvariant_cast>(index.data(Qt::UserRole));
- if (sharee.isNull()) {
- return;
- }
-
- /*
- * Don't send the reshare permissions for federated shares for servers <9.1
- * https://github.com/owncloud/core/issues/22122#issuecomment-185637344
- * https://github.com/owncloud/client/issues/4996
- */
- _lastCreatedShareId = QString();
-
- QString password;
- if (sharee->type() == Sharee::Email && _account->capabilities().shareEmailPasswordEnforced()) {
- _ui->shareeLineEdit->clear();
- // always show a dialog for password-enforced email shares
- bool ok = false;
-
- do {
- password = QInputDialog::getText(
- this,
- tr("Password for share required"),
- tr("Please enter a password for your email share:"),
- QLineEdit::Password,
- QString(),
- &ok);
- } while (password.isEmpty() && ok);
-
- if (!ok) {
- return;
- }
- }
-
- _manager->createShare(_sharePath, Share::ShareType(sharee->type()),
- sharee->shareWith(), _maxSharingPermissions, password);
-
- _ui->shareeLineEdit->setEnabled(false);
- _ui->shareeLineEdit->clear();
-}
-
-void ShareUserGroupWidget::slotCompleterHighlighted(const QModelIndex &index)
-{
- // By default the completer would set the text to EditRole,
- // override that here.
- _ui->shareeLineEdit->setText(index.data(Qt::DisplayRole).toString());
-}
-
-void ShareUserGroupWidget::displayError(int code, const QString &message)
-{
- _pi_sharee.stopAnimation();
-
- // Also remove the spinner in the widget list, if any
- foreach (auto pi, _parentScrollArea->findChildren