Sharing: Allow only one share dialog per path #3184
authorChristian Kamm <mail@ckamm.de>
Wed, 20 Jan 2016 12:17:54 +0000 (13:17 +0100)
committerChristian Kamm <mail@ckamm.de>
Wed, 20 Jan 2016 12:17:54 +0000 (13:17 +0100)
src/gui/owncloudgui.cpp
src/gui/owncloudgui.h

index 5db9f5bddd0a09a5130656b3aad5d7d6d4ceaf67..b97a637f70b405fc8243ec886e38e6d1a514bc27 100644 (file)
@@ -771,12 +771,33 @@ void ownCloudGui::slotShowShareDialog(const QString &sharePath, const QString &l
 
     const auto accountState = folder->accountState();
 
-    qDebug() << Q_FUNC_INFO << "Opening share dialog" << sharePath << localPath;
-    ShareDialog *w = new ShareDialog(accountState->account(), sharePath, localPath, resharingAllowed);
-    w->getShares();
-    w->setAttribute( Qt::WA_DeleteOnClose, true );
+    ShareDialog *w = 0;
+    if (_shareDialogs.contains(localPath) && _shareDialogs[localPath]) {
+        qDebug() << Q_FUNC_INFO << "Raising share dialog" << sharePath << localPath;
+        w = _shareDialogs[localPath];
+    } else {
+        qDebug() << Q_FUNC_INFO << "Opening share dialog" << sharePath << localPath;
+        w = new ShareDialog(accountState->account(), sharePath, localPath, resharingAllowed);
+        w->getShares();
+        w->setAttribute( Qt::WA_DeleteOnClose, true );
+
+        _shareDialogs[localPath] = w;
+        connect(w, SIGNAL(destroyed(QObject*)), SLOT(slotRemoveDestroyedShareDialogs()));
+    }
     raiseDialog(w);
 }
 
+void ownCloudGui::slotRemoveDestroyedShareDialogs()
+{
+    QMutableMapIterator<QString, QPointer<ShareDialog> > it(_shareDialogs);
+    while (it.hasNext()) {
+        it.next();
+        if (! it.value() || it.value() == sender()) {
+            it.remove();
+            qDebug() << "REMOVED";
+        }
+    }
+}
+
 
 } // end namespace
index 891bd74d715a79d359567d8404cc307a5af036f6..0b5395b8909b115fb578c2912033b3a72b187f6a 100644 (file)
@@ -31,6 +31,7 @@ class Folder;
 
 class SettingsDialog;
 class SettingsDialogMac;
+class ShareDialog;
 class Application;
 class LogBrowser;
 class AccountState;
@@ -77,6 +78,7 @@ public slots:
     void slotOpenPath(const QString& path);
     void slotAccountStateChanged();
     void slotShowShareDialog(const QString &sharePath, const QString &localPath, bool resharingAllowed);
+    void slotRemoveDestroyedShareDialogs();
 
 private slots:
     void slotDisplayIdle();
@@ -99,6 +101,7 @@ private:
     QMenu *_recentActionsMenu;
     QVector<QMenu*> _accountMenus;
     bool _qdbusmenuWorkaround;
+    QMap<QString, QPointer<ShareDialog> > _shareDialogs;
 
     QAction *_actionLogin;
     QAction *_actionLogout;