Commit 61c9ff6a authored by Ahmad Samir's avatar Ahmad Samir Committed by Ingo Klöcker
Browse files

action_data: use enums instead of bool members to improve reability

Also use default args, it's QAction and Enabled by default.
parent 9a584ae7
Pipeline #179695 passed with stage
in 2 minutes and 22 seconds
......@@ -424,42 +424,42 @@ void MainWindow::Private::setupActions()
#ifndef Q_OS_WIN
{
"tools_start_kwatchgnupg", i18n("GnuPG Log Viewer"), QString(),
"kwatchgnupg", q, [this](bool) { gnupgLogViewer(); }, QString(), false, true
"kwatchgnupg", q, [this](bool) { gnupgLogViewer(); }, QString()
},
#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, [this](bool) { restartDaemons(); }, {}, false, true
"view-refresh", q, [this](bool) { restartDaemons(); }, {}
},
// Help menu
#ifdef Q_OS_WIN
{
"help_check_updates", i18n("Check for updates"), QString(),
"gpg4win-compact", q, [this](bool) { forceUpdateCheck(); }, QString(), false, true
"gpg4win-compact", q, [this](bool) { forceUpdateCheck(); }, QString()
},
#endif
// View menu
{
"view_certificate_overview", i18nc("@action show certificate overview", "Certificates"),
i18n("Show certificate overview"), "view-certificate", q, [this](bool) { showCertificateView(); }, QString(), false, true
i18n("Show certificate overview"), "view-certificate", q, [this](bool) { showCertificateView(); }, QString()
},
{
"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, [this](bool) { showPadView(); }, QString(), false, true
i18n("Show pad for encrypting/decrypting and signing/verifying text"), "note", q, [this](bool) { showPadView(); }, QString()
},
{
"manage_smartcard", i18nc("@action show smartcard management view", "Smartcards"),
i18n("Show smartcard management"), "auth-sim-locked", q, [this](bool) { showSmartcardView(); }, QString(), false, true
i18n("Show smartcard management"), "auth-sim-locked", q, [this](bool) { showSmartcardView(); }, QString()
},
// Settings menu
{
"settings_self_test", i18n("Perform Self-Test"), QString(),
nullptr, q, [this](bool) { selfTest(); }, QString(), false, true
nullptr, q, [this](bool) { selfTest(); }, QString()
},
{
"configure_groups", i18n("Configure Groups..."), QString(),
"group", q, [this](bool) { configureGroups(); }, QString(), false, true
"group", q, [this](bool) { configureGroups(); }, QString()
}
};
......
......@@ -20,7 +20,7 @@
QAction *Kleo::createAction(const action_data &ad, KActionCollection *coll)
{
QAction *const a = ad.toggle ? new KToggleAction(coll) : new QAction(coll);
QAction *const a = ad.actionType == KFToggleAction ? new KToggleAction(coll) : new QAction(coll);
a->setObjectName(QLatin1String(ad.name));
a->setText(ad.text);
if (!ad.tooltip.isEmpty()) {
......@@ -30,13 +30,13 @@ QAction *Kleo::createAction(const action_data &ad, KActionCollection *coll)
a->setIcon(QIcon::fromTheme(QLatin1String(ad.icon)));
}
if (ad.receiver && ad.func) {
if (ad.toggle) {
if (ad.actionType == KFToggleAction) {
QObject::connect(a, &KToggleAction::toggled, ad.receiver, ad.func);
} else {
QObject::connect(a, &QAction::triggered, ad.receiver, ad.func);
}
}
a->setEnabled(ad.enabled);
a->setEnabled(ad.actionState == Enabled);
coll->addAction(QLatin1String(ad.name), a);
return a;
}
......
......@@ -21,6 +21,16 @@ class KActionCollection;
namespace Kleo
{
enum ActionType {
RegularQAction,
KFToggleAction,
};
enum ActionDefaultState {
Enabled,
Disabled,
};
struct action_data {
const char *name;
QString text;
......@@ -29,8 +39,8 @@ struct action_data {
const QObject *receiver;
std::function<void(bool)> func;
QString shortcut;
bool toggle;
bool enabled;
ActionType actionType = RegularQAction;
ActionDefaultState actionState = Enabled;
};
void make_actions_from_data(const std::vector<action_data> &data, KActionCollection *collection);
......
......@@ -362,110 +362,110 @@ void KeyListController::createActions(KActionCollection *coll)
// File menu
{
"file_new_certificate", i18n("New Key Pair..."), QString(),
"view-certificate-add", nullptr, nullptr, QStringLiteral("Ctrl+N"), false, true
"view-certificate-add", nullptr, nullptr, QStringLiteral("Ctrl+N")
},
{
"file_export_certificates", i18n("Export..."), i18n("Export the selected certificate (public key) to a file"),
"view-certificate-export", nullptr, nullptr, QStringLiteral("Ctrl+E"), false, true
"view-certificate-export", nullptr, nullptr, QStringLiteral("Ctrl+E")
},
{
"file_export_certificates_to_server", i18n("Publish on Server..."), i18n("Publish the selected certificate (public key) on a public keyserver"),
"view-certificate-export-server", nullptr, nullptr, QStringLiteral("Ctrl+Shift+E"), false, true
"view-certificate-export-server", nullptr, nullptr, QStringLiteral("Ctrl+Shift+E")
},
#ifdef MAILAKONADI_ENABLED
{
"file_export_certificate_to_provider", i18n("Publish at Mail Provider..."), i18n("Publish the selected certificate (public key) at mail provider's Web Key Directory if offered"),
"view-certificate-export", nullptr, nullptr, QString(), false, true
"view-certificate-export", nullptr, nullptr, QString()
},
#endif // MAILAKONADI_ENABLED
{
"file_export_secret_keys", i18n("Backup Secret Keys..."), QString(),
"view-certificate-export-secret", nullptr, nullptr, QString(), false, true
"view-certificate-export-secret", nullptr, nullptr, QString()
},
{
"file_export_paper_key", i18n("Print Secret Key..."), QString(),
"document-print", nullptr, nullptr, QString(), false, true
"document-print", nullptr, nullptr, QString()
},
{
"file_lookup_certificates", i18n("Lookup on Server..."), i18n("Search for certificates online using a public keyserver"),
"edit-find", nullptr, nullptr, QStringLiteral("Shift+Ctrl+I"), false, true
"edit-find", nullptr, nullptr, QStringLiteral("Shift+Ctrl+I")
},
{
"file_import_certificates", i18n("Import..."), i18n("Import a certificate from a file"),
"view-certificate-import", nullptr, nullptr, QStringLiteral("Ctrl+I"), false, true
"view-certificate-import", nullptr, nullptr, QStringLiteral("Ctrl+I")
},
{
"file_decrypt_verify_files", i18n("Decrypt/Verify..."), i18n("Decrypt and/or verify files"),
"document-edit-decrypt-verify", nullptr, nullptr, QString(), false, true
"document-edit-decrypt-verify", nullptr, nullptr, QString()
},
{
"file_sign_encrypt_files", i18n("Sign/Encrypt..."), i18n("Encrypt and/or sign files"),
"document-edit-sign-encrypt", nullptr, nullptr, QString(), false, true
"document-edit-sign-encrypt", nullptr, nullptr, QString()
},
{
"file_sign_encrypt_folder", i18n("Sign/Encrypt Folder..."), i18n("Encrypt and/or sign folders"),
nullptr/*"folder-edit-sign-encrypt"*/, nullptr, nullptr, QString(), false, true
nullptr/*"folder-edit-sign-encrypt"*/, nullptr, nullptr, QString()
},
{
"file_checksum_create_files", i18n("Create Checksum Files..."), QString(),
nullptr/*"document-checksum-create"*/, nullptr, nullptr, QString(), false, true
nullptr/*"document-checksum-create"*/, nullptr, nullptr, QString()
},
{
"file_checksum_verify_files", i18n("Verify Checksum Files..."), QString(),
nullptr/*"document-checksum-verify"*/, nullptr, nullptr, QString(), false, true
nullptr/*"document-checksum-verify"*/, nullptr, nullptr, QString()
},
// View menu
{
"view_redisplay", i18n("Redisplay"), QString(),
"view-refresh", nullptr, nullptr, QStringLiteral("F5"), false, true
"view-refresh", nullptr, nullptr, QStringLiteral("F5")
},
{
"view_stop_operations", i18n("Stop Operation"), QString(),
"process-stop", this, [this](bool) { cancelCommands(); }, QStringLiteral("Escape"), false, false
"process-stop", this, [this](bool) { cancelCommands(); }, QStringLiteral("Escape"), RegularQAction, Disabled
},
{
"view_certificate_details", i18n("Details"), QString(),
"dialog-information", nullptr, nullptr, QString(), false, true
"dialog-information", nullptr, nullptr, QString()
},
// Certificate menu
#ifdef QGPGME_SUPPORTS_KEY_REVOCATION
{
"certificates_revoke", i18n("Revoke Certificate..."), i18n("Revoke the selected OpenPGP certificate"),
"view-certificate-revoke", nullptr, nullptr, {}, false, true
"view-certificate-revoke", nullptr, nullptr, {}
},
#endif
{
"certificates_delete", i18n("Delete"), i18n("Delete selected certificates"),
"edit-delete", nullptr, nullptr, QStringLiteral("Delete"), false, true
"edit-delete", nullptr, nullptr, QStringLiteral("Delete")
},
{
"certificates_certify_certificate", i18n("Certify..."), i18n("Certify the validity of the selected certificate"),
"view-certificate-sign", nullptr, nullptr, QString(), false, true
"view-certificate-sign", nullptr, nullptr, QString()
},
{
"certificates_revoke_certification", i18n("Revoke Certification..."), i18n("Revoke the certification of the selected certificate"),
"view-certificate-revoke", nullptr, nullptr, QString(), false, true
"view-certificate-revoke", nullptr, nullptr, QString()
},
{
"certificates_change_expiry", i18n("Change Expiry Date..."), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
{
"certificates_change_owner_trust", i18n("Change Certification Trust..."), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
{
"certificates_change_passphrase", i18n("Change Passphrase..."), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
{
"certificates_add_userid", i18n("Add User ID..."), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
// Tools menu
{
"tools_refresh_openpgp_certificates", i18n("Refresh OpenPGP Certificates"), QString(),
"view-refresh", nullptr, nullptr, QString(), false, true
"view-refresh", nullptr, nullptr, QString()
},
// Window menu
// (come from TabWidget)
......@@ -477,32 +477,32 @@ void KeyListController::createActions(KActionCollection *coll)
// Certificate menu
{
"certificates_trust_root", i18n("Trust Root Certificate"), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
{
"certificates_distrust_root", i18n("Distrust Root Certificate"), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
{
"certificates_dump_certificate", i18n("Technical Details"), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
// Tools menu
{
"tools_refresh_x509_certificates", i18n("Refresh S/MIME Certificates"), QString(),
"view-refresh", nullptr, nullptr, QString(), false, true
"view-refresh", nullptr, nullptr, QString()
},
{
"crl_clear_crl_cache", i18n("Clear CRL Cache"), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
{
"crl_dump_crl_cache", i18n("Dump CRL Cache"), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, QString()
},
{
"crl_import_crl", i18n("Import CRL From File..."), QString(),
nullptr, nullptr, nullptr, QString(), false, true
nullptr, nullptr, nullptr, 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, [this](bool) { d->slotNewTab(); }, QStringLiteral("CTRL+SHIFT+N"), false, true
"tab-new-background", this, [this](bool) { d->slotNewTab(); }, QStringLiteral("CTRL+SHIFT+N")
};
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, [this](bool) { d->slotRenameCurrentTab(); }, QStringLiteral("CTRL+SHIFT+R"), false, false
"edit-rename", this, [this](bool) { d->slotRenameCurrentTab(); }, QStringLiteral("CTRL+SHIFT+R"), RegularQAction, Disabled
},
{
Actions::Duplicate, i18n("Duplicate Tab"), i18n("Duplicate this tab"),
"tab-duplicate", this, [this](bool) { d->slotDuplicateCurrentTab(); }, QStringLiteral("CTRL+SHIFT+D"), false, true
"tab-duplicate", this, [this](bool) { d->slotDuplicateCurrentTab(); }, QStringLiteral("CTRL+SHIFT+D")
},
{
Actions::Close, i18n("Close Tab"), i18n("Close this tab"),
"tab-close", this, [this](bool) { d->slotCloseCurrentTab(); }, QStringLiteral("CTRL+SHIFT+W"), false, false
"tab-close", this, [this](bool) { d->slotCloseCurrentTab(); }, QStringLiteral("CTRL+SHIFT+W"), RegularQAction, Disabled
}, // ### CTRL-W when available
{
Actions::MoveLeft, i18n("Move Tab Left"), i18n("Move this tab left"),
nullptr, this, [this](bool) { d->slotMoveCurrentTabLeft(); }, QStringLiteral("CTRL+SHIFT+LEFT"), false, false
nullptr, this, [this](bool) { d->slotMoveCurrentTabLeft(); }, QStringLiteral("CTRL+SHIFT+LEFT"), RegularQAction, Disabled
},
{
Actions::MoveRight, i18n("Move Tab Right"), i18n("Move this tab right"),
nullptr, this, [this](bool) { d->slotMoveCurrentTabRight(); }, QStringLiteral("CTRL+SHIFT+RIGHT"), false, false
nullptr, this, [this](bool) { d->slotMoveCurrentTabRight(); }, QStringLiteral("CTRL+SHIFT+RIGHT"), RegularQAction, Disabled
},
{
Actions::Hierarchical, i18n("Hierarchical Certificate List"), QString(),
nullptr, this, [this](bool on) { d->slotToggleHierarchicalView(on); }, QString(), true, false
nullptr, this, [this](bool on) { d->slotToggleHierarchicalView(on); }, QString(), KFToggleAction, Disabled
},
{
Actions::ExpandAll, i18n("Expand All"), QString(),
nullptr, this, [this](bool) { d->slotExpandAll(); }, QStringLiteral("CTRL+."), false, false
nullptr, this, [this](bool) { d->slotExpandAll(); }, QStringLiteral("CTRL+."), RegularQAction, Disabled
},
{
Actions::CollapseAll, i18n("Collapse All"), QString(),
nullptr, this, [this](bool) { d->slotCollapseAll(); }, QStringLiteral("CTRL+,"), false, false
nullptr, this, [this](bool) { d->slotCollapseAll(); }, QStringLiteral("CTRL+,"), RegularQAction, Disabled
},
};
......@@ -862,7 +862,7 @@ void TabWidget::createActions(KActionCollection *coll)
if (ad.icon) {
action->setIcon(QIcon::fromTheme(QLatin1String(ad.icon)));
}
action->setEnabled(ad.enabled);
action->setEnabled(ad.actionState == Enabled);
d->otherPageActions.insert(ad.name, action);
}
......
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