Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kamm <mail@ckamm.de>2017-11-15 17:01:48 +0300
committerMarkus Goetz <markus@woboq.com>2017-11-16 13:16:47 +0300
commiteff401d4187047b9a08fe5e21ca7b9e4fce32816 (patch)
tree9415defed1423edc263b0fcc78eb74a23e5b5e3d /src/gui/sharelinkwidget.cpp
parent7049ccd7ab977b78c87293c7e93b248e480feb97 (diff)
Share links: Confirm deletion explicitly #6163
Also add the "Delete" action to the "..." menu.
Diffstat (limited to 'src/gui/sharelinkwidget.cpp')
-rw-r--r--src/gui/sharelinkwidget.cpp84
1 files changed, 57 insertions, 27 deletions
diff --git a/src/gui/sharelinkwidget.cpp b/src/gui/sharelinkwidget.cpp
index 124e617aa..3c4a21726 100644
--- a/src/gui/sharelinkwidget.cpp
+++ b/src/gui/sharelinkwidget.cpp
@@ -155,14 +155,15 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account,
// Prepare sharing menu
- _shareLinkMenu = new QMenu(this);
- connect(_shareLinkMenu, &QMenu::triggered,
- this, &ShareLinkWidget::slotShareLinkActionTriggered);
- _openLinkAction = _shareLinkMenu->addAction(tr("Open link in browser"));
- _copyLinkAction = _shareLinkMenu->addAction(tr("Copy link to clipboard"));
- _copyDirectLinkAction = _shareLinkMenu->addAction(tr("Copy link to clipboard (direct download)"));
- _emailLinkAction = _shareLinkMenu->addAction(tr("Send link by email"));
- _emailDirectLinkAction = _shareLinkMenu->addAction(tr("Send link by email (direct download)"));
+ _linkContextMenu = new QMenu(this);
+ connect(_linkContextMenu, &QMenu::triggered,
+ this, &ShareLinkWidget::slotLinkContextMenuActionTriggered);
+ _deleteLinkAction = _linkContextMenu->addAction(tr("Delete"));
+ _openLinkAction = _linkContextMenu->addAction(tr("Open link in browser"));
+ _copyLinkAction = _linkContextMenu->addAction(tr("Copy link to clipboard"));
+ _copyDirectLinkAction = _linkContextMenu->addAction(tr("Copy link to clipboard (direct download)"));
+ _emailLinkAction = _linkContextMenu->addAction(tr("Send link by email"));
+ _emailDirectLinkAction = _linkContextMenu->addAction(tr("Send link by email (direct download)"));
/*
* Create the share manager and connect it properly
@@ -231,24 +232,19 @@ void ShareLinkWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shar
table->insertRow(row);
auto nameItem = new QTableWidgetItem;
- QString name = linkShare->getName();
- if (name.isEmpty()) {
- if (!_namesSupported) {
- name = tr("Public link");
- nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
- } else {
- name = linkShare->getToken();
- }
+ auto name = shareName(*linkShare);
+ if (!_namesSupported) {
+ nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
}
nameItem->setText(name);
nameItem->setData(Qt::UserRole, QVariant::fromValue(linkShare));
table->setItem(row, 0, nameItem);
- auto shareButton = new QToolButton;
- shareButton->setText("...");
- shareButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
- connect(shareButton, &QAbstractButton::clicked, this, &ShareLinkWidget::slotShareLinkButtonClicked);
- table->setCellWidget(row, 1, shareButton);
+ auto dotdotdotButton = new QToolButton;
+ dotdotdotButton->setText("...");
+ dotdotdotButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
+ connect(dotdotdotButton, &QAbstractButton::clicked, this, &ShareLinkWidget::slotContextMenuButtonClicked);
+ table->setCellWidget(row, 1, dotdotdotButton);
auto deleteButton = new QToolButton;
deleteButton->setIcon(deleteIcon);
@@ -515,22 +511,56 @@ void ShareLinkWidget::openShareLink(const QUrl &url)
Utility::openBrowser(url, this);
}
-void ShareLinkWidget::slotShareLinkButtonClicked()
+void ShareLinkWidget::confirmAndDeleteShare(const QSharedPointer<LinkShare> &share)
+{
+ auto messageBox = new QMessageBox(
+ QMessageBox::Question,
+ tr("Confirm Link Share Deletion"),
+ tr("<p>Do you really want to delete the public link share <i>%1</i>?</p>"
+ "<p>Note: This action cannot be undone.</p>")
+ .arg(shareName(*share)),
+ QMessageBox::NoButton,
+ this);
+ QPushButton *yesButton =
+ messageBox->addButton(tr("Delete"), QMessageBox::YesRole);
+ messageBox->addButton(tr("Cancel"), QMessageBox::NoRole);
+
+ connect(messageBox, &QMessageBox::finished, this,
+ [messageBox, yesButton, share]() {
+ if (messageBox->clickedButton() == yesButton)
+ share->deleteShare();
+ });
+ messageBox->open();
+}
+
+QString ShareLinkWidget::shareName(const LinkShare &share) const
+{
+ QString name = share.getName();
+ if (!name.isEmpty())
+ return name;
+ if (!_namesSupported)
+ return tr("Public link");
+ return share.getToken();
+}
+
+void ShareLinkWidget::slotContextMenuButtonClicked()
{
auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
bool downloadEnabled = share->getShowFileListing();
_copyDirectLinkAction->setVisible(downloadEnabled);
_emailDirectLinkAction->setVisible(downloadEnabled);
- _shareLinkMenu->setProperty(propertyShareC, QVariant::fromValue(share));
- _shareLinkMenu->exec(QCursor::pos());
+ _linkContextMenu->setProperty(propertyShareC, QVariant::fromValue(share));
+ _linkContextMenu->exec(QCursor::pos());
}
-void ShareLinkWidget::slotShareLinkActionTriggered(QAction *action)
+void ShareLinkWidget::slotLinkContextMenuActionTriggered(QAction *action)
{
auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
- if (action == _copyLinkAction) {
+ if (action == _deleteLinkAction) {
+ confirmAndDeleteShare(share);
+ } else if (action == _copyLinkAction) {
QApplication::clipboard()->setText(share->getLink().toString());
} else if (action == _copyDirectLinkAction) {
QApplication::clipboard()->setText(share->getDirectDownloadLink().toString());
@@ -546,7 +576,7 @@ void ShareLinkWidget::slotShareLinkActionTriggered(QAction *action)
void ShareLinkWidget::slotDeleteShareClicked()
{
auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
- share->deleteShare();
+ confirmAndDeleteShare(share);
}
void ShareLinkWidget::slotPermissionsCheckboxClicked()