Commit 9a584ae7 authored by Ahmad Samir's avatar Ahmad Samir Committed by Ingo Klöcker
Browse files

Port signal/slot that use action_data struct to PMF/Functor syntax

We have to use a std::function because some of the lambdas have captures,
as using a plain function pointer 'void (*func)(bool)' won't work.
parent e27d777a
......@@ -424,42 +424,42 @@ void MainWindow::Private::setupActions()
#ifndef Q_OS_WIN
{
"tools_start_kwatchgnupg", i18n("GnuPG Log Viewer"), QString(),
"kwatchgnupg", q, SLOT(gnupgLogViewer()), QString(), false, true
"kwatchgnupg", q, [this](bool) { gnupgLogViewer(); }, QString(), false, true
},
#endif
{
"tools_restart_backend", i18nc("@action:inmenu", "Restart Background Processes"),
i18nc("@info:tooltip", "Restart the background processes, e.g. after making changes to the configuration."),
"view-refresh", q, SLOT(restartDaemons()), {}, false, true
"view-refresh", q, [this](bool) { restartDaemons(); }, {}, false, true
},
// Help menu
#ifdef Q_OS_WIN
{
"help_check_updates", i18n("Check for updates"), QString(),
"gpg4win-compact", q, SLOT(forceUpdateCheck()), QString(), false, true
"gpg4win-compact", q, [this](bool) { forceUpdateCheck(); }, QString(), false, true
},
#endif
// View menu
{
"view_certificate_overview", i18nc("@action show certificate overview", "Certificates"),
i18n("Show certificate overview"), "view-certificate", q, SLOT(showCertificateView()), QString(), false, true
i18n("Show certificate overview"), "view-certificate", q, [this](bool) { showCertificateView(); }, QString(), false, true
},
{
"pad_view", i18nc("@action show input / output area for encrypting/signing resp. decrypting/verifying text", "Notepad"),
i18n("Show pad for encrypting/decrypting and signing/verifying text"), "note", q, SLOT(showPadView()), QString(), false, true
i18n("Show pad for encrypting/decrypting and signing/verifying text"), "note", q, [this](bool) { showPadView(); }, QString(), false, true
},
{
"manage_smartcard", i18nc("@action show smartcard management view", "Smartcards"),
i18n("Show smartcard management"), "auth-sim-locked", q, SLOT(showSmartcardView()), QString(), false, true
i18n("Show smartcard management"), "auth-sim-locked", q, [this](bool) { showSmartcardView(); }, QString(), false, true
},
// Settings menu
{
"settings_self_test", i18n("Perform Self-Test"), QString(),
nullptr, q, SLOT(selfTest()), QString(), false, true
nullptr, q, [this](bool) { selfTest(); }, QString(), false, true
},
{
"configure_groups", i18n("Configure Groups..."), QString(),
"group", q, SLOT(configureGroups()), QString(), false, true
"group", q, [this](bool) { configureGroups(); }, QString(), false, true
}
};
......
......@@ -41,17 +41,10 @@ private:
class Private;
kdtools::pimpl_ptr<Private> d;
Q_PRIVATE_SLOT(d, void closeAndQuit())
Q_PRIVATE_SLOT(d, void selfTest())
Q_PRIVATE_SLOT(d, void configureToolbars())
Q_PRIVATE_SLOT(d, void configureGroups())
Q_PRIVATE_SLOT(d, void editKeybindings())
Q_PRIVATE_SLOT(d, void gnupgLogViewer())
Q_PRIVATE_SLOT(d, void slotConfigCommitted())
Q_PRIVATE_SLOT(d, void slotContextMenuRequested(QAbstractItemView *, QPoint))
Q_PRIVATE_SLOT(d, void slotFocusQuickSearch())
Q_PRIVATE_SLOT(d, void showCertificateView())
Q_PRIVATE_SLOT(d, void showPadView())
Q_PRIVATE_SLOT(d, void showSmartcardView())
Q_PRIVATE_SLOT(d, void forceUpdateCheck())
Q_PRIVATE_SLOT(d, void restartDaemons())
};
......@@ -29,11 +29,11 @@ QAction *Kleo::createAction(const action_data &ad, KActionCollection *coll)
if (ad.icon) {
a->setIcon(QIcon::fromTheme(QLatin1String(ad.icon)));
}
if (ad.receiver && ad.slot) {
if (ad.receiver && ad.func) {
if (ad.toggle) {
QObject::connect(a, SIGNAL(toggled(bool)), ad.receiver, ad.slot);
QObject::connect(a, &KToggleAction::toggled, ad.receiver, ad.func);
} else {
QObject::connect(a, SIGNAL(triggered()), ad.receiver, ad.slot);
QObject::connect(a, &QAction::triggered, ad.receiver, ad.func);
}
}
a->setEnabled(ad.enabled);
......
......@@ -10,6 +10,8 @@
#pragma once
#include <QString>
#include <functional>
#include <vector>
class QObject;
......@@ -25,7 +27,7 @@ struct action_data {
QString tooltip;
const char *icon;
const QObject *receiver;
const char *slot;
std::function<void(bool)> func;
QString shortcut;
bool toggle;
bool enabled;
......
......@@ -421,7 +421,7 @@ void KeyListController::createActions(KActionCollection *coll)
},
{
"view_stop_operations", i18n("Stop Operation"), QString(),
"process-stop", this, SLOT(cancelCommands()), QStringLiteral("Escape"), false, false
"process-stop", this, [this](bool) { cancelCommands(); }, QStringLiteral("Escape"), false, false
},
{
"view_certificate_details", i18n("Details"), QString(),
......
......@@ -811,7 +811,7 @@ void TabWidget::createActions(KActionCollection *coll)
}
const action_data actionDataNew = {
"window_new_tab", i18n("New Tab"), i18n("Open a new tab"),
"tab-new-background", this, SLOT(slotNewTab()), QStringLiteral("CTRL+SHIFT+N"), false, true
"tab-new-background", this, [this](bool) { d->slotNewTab(); }, QStringLiteral("CTRL+SHIFT+N"), false, true
};
d->newAction = make_action_from_data(actionDataNew, coll);
......@@ -819,35 +819,35 @@ void TabWidget::createActions(KActionCollection *coll)
const std::vector<action_data> actionData = {
{
Actions::Rename, i18n("Rename Tab..."), i18n("Rename this tab"),
"edit-rename", this, SLOT(slotRenameCurrentTab()), QStringLiteral("CTRL+SHIFT+R"), false, false
"edit-rename", this, [this](bool) { d->slotRenameCurrentTab(); }, QStringLiteral("CTRL+SHIFT+R"), false, false
},
{
Actions::Duplicate, i18n("Duplicate Tab"), i18n("Duplicate this tab"),
"tab-duplicate", this, SLOT(slotDuplicateCurrentTab()), QStringLiteral("CTRL+SHIFT+D"), false, true
"tab-duplicate", this, [this](bool) { d->slotDuplicateCurrentTab(); }, QStringLiteral("CTRL+SHIFT+D"), false, true
},
{
Actions::Close, i18n("Close Tab"), i18n("Close this tab"),
"tab-close", this, SLOT(slotCloseCurrentTab()), QStringLiteral("CTRL+SHIFT+W"), false, false
"tab-close", this, [this](bool) { d->slotCloseCurrentTab(); }, QStringLiteral("CTRL+SHIFT+W"), false, false
}, // ### CTRL-W when available
{
Actions::MoveLeft, i18n("Move Tab Left"), i18n("Move this tab left"),
nullptr, this, SLOT(slotMoveCurrentTabLeft()), QStringLiteral("CTRL+SHIFT+LEFT"), false, false
nullptr, this, [this](bool) { d->slotMoveCurrentTabLeft(); }, QStringLiteral("CTRL+SHIFT+LEFT"), false, false
},
{
Actions::MoveRight, i18n("Move Tab Right"), i18n("Move this tab right"),
nullptr, this, SLOT(slotMoveCurrentTabRight()), QStringLiteral("CTRL+SHIFT+RIGHT"), false, false
nullptr, this, [this](bool) { d->slotMoveCurrentTabRight(); }, QStringLiteral("CTRL+SHIFT+RIGHT"), false, false
},
{
Actions::Hierarchical, i18n("Hierarchical Certificate List"), QString(),
nullptr, this, SLOT(slotToggleHierarchicalView(bool)), QString(), true, false
nullptr, this, [this](bool on) { d->slotToggleHierarchicalView(on); }, QString(), true, false
},
{
Actions::ExpandAll, i18n("Expand All"), QString(),
nullptr, this, SLOT(slotExpandAll()), QStringLiteral("CTRL+."), false, false
nullptr, this, [this](bool) { d->slotExpandAll(); }, QStringLiteral("CTRL+."), false, false
},
{
Actions::CollapseAll, i18n("Collapse All"), QString(),
nullptr, this, SLOT(slotCollapseAll()), QStringLiteral("CTRL+,"), false, false
nullptr, this, [this](bool) { d->slotCollapseAll(); }, QStringLiteral("CTRL+,"), false, false
},
};
......
......@@ -82,16 +82,6 @@ Q_SIGNALS:
private:
class Private;
kdtools::pimpl_ptr<Private> d;
Q_PRIVATE_SLOT(d, void slotRenameCurrentTab())
Q_PRIVATE_SLOT(d, void slotNewTab())
Q_PRIVATE_SLOT(d, void slotDuplicateCurrentTab())
Q_PRIVATE_SLOT(d, void slotCloseCurrentTab())
Q_PRIVATE_SLOT(d, void slotMoveCurrentTabLeft())
Q_PRIVATE_SLOT(d, void slotMoveCurrentTabRight())
Q_PRIVATE_SLOT(d, void slotToggleHierarchicalView(bool))
Q_PRIVATE_SLOT(d, void slotExpandAll())
Q_PRIVATE_SLOT(d, void slotCollapseAll())
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment