Gui: Use lambda instead of QSignalMapper
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 20 Sep 2017 14:49:41 +0000 (16:49 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:34 +0000 (22:01 +0200)
It's simpler, and QSignalMapper is deprecated in Qt 5.10

src/gui/folderman.h
src/gui/owncloudgui.cpp
src/gui/owncloudgui.h

index a504cc99b6dc99bbc48ad6beb3540d6cbe54d3c0..5802789c84879d4d9d0f165da8f439157cb915f8 100644 (file)
@@ -24,7 +24,6 @@
 #include "folderwatcher.h"
 #include "syncfileitem.h"
 
-class QSignalMapper;
 class TestFolderMan;
 
 namespace OCC {
index e5a398c8e12b7aaca37062bf60de7cbf4c7f8dc0..225cbf3b34194673ff3c6625aed114ee97a71c66 100644 (file)
@@ -38,7 +38,6 @@
 #include <QDesktopServices>
 #include <QDir>
 #include <QMessageBox>
-#include <QSignalMapper>
 
 #if defined(Q_OS_X11)
 #include <QX11Info>
@@ -63,8 +62,6 @@ ownCloudGui::ownCloudGui(Application *parent)
     , _contextMenuVisibleOsx(false)
     , _recentActionsMenu(0)
     , _qdbusmenuWorkaround(false)
-    , _folderOpenActionMapper(new QSignalMapper(this))
-    , _recentItemsMapper(new QSignalMapper(this))
     , _app(parent)
 {
     _tray = new Systray();
@@ -81,13 +78,6 @@ ownCloudGui::ownCloudGui(Application *parent)
 
     _tray->show();
 
-    /* use a signal mapper to map the open requests to the alias names */
-    connect(_folderOpenActionMapper, SIGNAL(mapped(QString)),
-        this, SLOT(slotFolderOpenAction(QString)));
-
-    connect(_recentItemsMapper, SIGNAL(mapped(QString)),
-        this, SLOT(slotOpenPath(QString)));
-
     ProgressDispatcher *pd = ProgressDispatcher::instance();
     connect(pd, SIGNAL(progressInfo(QString, ProgressInfo)), this,
         SLOT(slotUpdateProgress(QString, ProgressInfo)));
@@ -337,9 +327,8 @@ void ownCloudGui::addAccountContextMenu(AccountStatePtr accountState, QMenu *men
         }
 
         QAction *action = new QAction(tr("Open folder '%1'").arg(folder->shortGuiLocalPath()), menu);
-        connect(action, SIGNAL(triggered()), _folderOpenActionMapper, SLOT(map()));
-        _folderOpenActionMapper->setMapping(action, folder->alias());
-        menu->addAction(action);
+        auto alias = folder->alias();
+        connect(action, &QAction::triggered, this, [this, alias] { this->slotFolderOpenAction(alias); });
     }
 
     menu->addSeparator();
@@ -805,8 +794,7 @@ void ownCloudGui::slotUpdateProgress(const QString &folder, const ProgressInfo &
         if (f) {
             QString fullPath = f->path() + '/' + progress._lastCompletedItem._file;
             if (QFile(fullPath).exists()) {
-                _recentItemsMapper->setMapping(action, fullPath);
-                connect(action, SIGNAL(triggered()), _recentItemsMapper, SLOT(map()));
+                connect(action, &QAction::triggered, this, [this, fullPath] { this->slotOpenPath(fullPath); });
             } else {
                 action->setEnabled(false);
             }
index c24fa173a87ce4bdb227a4a5215625fa817b6165..da4ae38a204a0747c0368e8c3098aca7cad9227c 100644 (file)
@@ -23,7 +23,6 @@
 #include <QPointer>
 #include <QAction>
 #include <QMenu>
-#include <QSignalMapper>
 #include <QSize>
 #include <QTimer>
 
@@ -144,10 +143,6 @@ private:
     QAction *_actionCrash;
 
     QList<QAction *> _recentItemsActions;
-
-    QSignalMapper *_folderOpenActionMapper;
-    QSignalMapper *_recentItemsMapper;
-
     Application *_app;
 };