Link share: Remove direct download if unavailable #5837
authorChristian Kamm <mail@ckamm.de>
Thu, 15 Jun 2017 14:03:24 +0000 (16:03 +0200)
committerckamm <mail@ckamm.de>
Fri, 7 Jul 2017 09:23:32 +0000 (11:23 +0200)
It would have been much nicer to keep the menu assigned to the
QToolButton, but if one switches away from InstantPopup (to adjust the
entries before they're displayed), the button always gets a menu
indicator that can't be removed.

src/gui/sharelinkwidget.cpp
src/gui/sharelinkwidget.h

index 79973b8e47aada89dc2883afe37f2a993072ddce..bba3151bbbc3017541a838968595e60ddcb05dd6 100644 (file)
@@ -156,6 +156,8 @@ ShareLinkWidget::ShareLinkWidget(AccountPtr account,
     // Prepare sharing menu
 
     _shareLinkMenu = new QMenu(this);
+    connect(_shareLinkMenu, SIGNAL(triggered(QAction *)),
+        SLOT(slotShareLinkActionTriggered(QAction *)));
     _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)"));
@@ -245,9 +247,7 @@ void ShareLinkWidget::slotSharesFetched(const QList<QSharedPointer<Share>> &shar
         auto shareButton = new QToolButton;
         shareButton->setText("...");
         shareButton->setProperty(propertyShareC, QVariant::fromValue(linkShare));
-        shareButton->setMenu(_shareLinkMenu);
-        shareButton->setPopupMode(QToolButton::InstantPopup);
-        connect(shareButton, SIGNAL(triggered(QAction *)), SLOT(slotShareLinkButtonTriggered(QAction *)));
+        connect(shareButton, SIGNAL(clicked(bool)), SLOT(slotShareLinkButtonClicked()));
         table->setCellWidget(row, 1, shareButton);
 
         auto deleteButton = new QToolButton;
@@ -514,7 +514,18 @@ void ShareLinkWidget::openShareLink(const QUrl &url)
     Utility::openBrowser(url, this);
 }
 
-void ShareLinkWidget::slotShareLinkButtonTriggered(QAction *action)
+void ShareLinkWidget::slotShareLinkButtonClicked()
+{
+    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());
+}
+
+void ShareLinkWidget::slotShareLinkActionTriggered(QAction *action)
 {
     auto share = sender()->property(propertyShareC).value<QSharedPointer<LinkShare>>();
 
index 4dd5f1ec695b2d12350dd0105e63a2043a4285ea..1d8397505c54670b91c27b38b3e1690521eae4f2 100644 (file)
@@ -70,7 +70,8 @@ private slots:
     void slotPasswordChanged(const QString &newText);
     void slotNameEdited(QTableWidgetItem *item);
 
-    void slotShareLinkButtonTriggered(QAction *action);
+    void slotShareLinkButtonClicked();
+    void slotShareLinkActionTriggered(QAction *action);
 
     void slotDeleteShareFetched();
     void slotCreateShareFetched(const QSharedPointer<LinkShare> share);