summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrius Štikonas <andrius@stikonas.eu>2016-07-13 18:05:10 (GMT)
committerAndrius Štikonas <andrius@stikonas.eu>2016-07-13 20:19:00 (GMT)
commite14b55e783d8f86bc388be7837b0d9b491b52728 (patch)
treed9e2c1150a2e0483143556a6c70792afe1c747f7
parentdc1008fe0439c6fd607ac51e43591e1f8ba889a8 (diff)
Port away from KUniqueApplication to QApplication + KDBusService.
REVIEW: 128433
-rw-r--r--CMakeLists.txt2
-rw-r--r--keysmanager.cpp15
-rw-r--r--kgpg.cpp29
-rw-r--r--kgpg.h9
-rw-r--r--main.cpp44
5 files changed, 57 insertions, 42 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 77d1bd1..a829d33 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,6 +34,7 @@ find_package(KF5 5.23 REQUIRED
DocTools
Codecs
CoreAddons
+ DBusAddons
I18n
IconThemes
KIO
@@ -232,6 +233,7 @@ target_link_libraries(kgpg
KF5::Codecs
KF5::Contacts
KF5::CoreAddons
+ KF5::DBusAddons
KF5::IconThemes
KF5::KDELibs4Support
KF5::KIOCore
diff --git a/keysmanager.cpp b/keysmanager.cpp
index 48e2c7d..1256e4f 100644
--- a/keysmanager.cpp
+++ b/keysmanager.cpp
@@ -3,6 +3,7 @@
* Copyright (C) 2007,2008,2009,2010,2011,2012,2013
* Rolf Eike Beer <kde@opensource.sf-tec.de>
* Copyright (C) 2011 Luis Ángel Fernández Fernández <laffdez@gmail.com>
+ * Copyright (C) 2016 Andrius Štikonas <andrius@stikonas.eu>
*/
/***************************************************************************
@@ -1151,7 +1152,7 @@ void KeysManager::saveToggleOpts(void)
void KeysManager::readOptions()
{
m_clipboardmode = QClipboard::Clipboard;
- if (KGpgSettings::useMouseSelection() && (kapp->clipboard()->supportsSelection()))
+ if (KGpgSettings::useMouseSelection() && (qApp->clipboard()->supportsSelection()))
m_clipboardmode = QClipboard::Selection;
if (imodel != Q_NULLPTR)
@@ -1538,7 +1539,7 @@ void KeysManager::slotProcessExportClip(int result)
Q_ASSERT(exp != Q_NULLPTR);
if (result == KGpgTransaction::TS_OK) {
- kapp->clipboard()->setText(QLatin1String( exp->getOutputData() ), m_clipboardmode);
+ qApp->clipboard()->setText(QLatin1String( exp->getOutputData() ), m_clipboardmode);
} else {
KMessageBox::sorry(this, i18n("Your public key could not be exported\nCheck the key."));
}
@@ -2557,7 +2558,7 @@ void KeysManager::slotPreImportKey()
if (!ids.isEmpty())
importRemoteKeys(ids.split(QLatin1Char( ' ' )));
} else {
- slotImport(kapp->clipboard()->text(m_clipboardmode));
+ slotImport(qApp->clipboard()->text(m_clipboardmode));
}
}
@@ -2723,7 +2724,7 @@ KeysManager::goDefaultShortcut() const
void
KeysManager::clipEncrypt()
{
- const QString cliptext(kapp->clipboard()->text(m_clipboardmode));
+ const QString cliptext(qApp->clipboard()->text(m_clipboardmode));
if (cliptext.isEmpty()) {
Q_ASSERT(m_trayicon != Q_NULLPTR);
@@ -2769,7 +2770,7 @@ KeysManager::slotSetClip(int result)
if (result != KGpgTransaction::TS_OK)
return;
- kapp->clipboard()->setText(enc->encryptedText().join(QLatin1String("\n")), m_clipboardmode);
+ qApp->clipboard()->setText(enc->encryptedText().join(QLatin1String("\n")), m_clipboardmode);
Q_ASSERT(m_trayicon != Q_NULLPTR);
m_trayicon->showMessage(QString(), i18n("Text successfully encrypted."), QLatin1String( "kgpg" ));
@@ -2818,7 +2819,7 @@ KeysManager::slotOpenKeyUrl()
void
KeysManager::clipDecrypt()
{
- const QString cliptext(kapp->clipboard()->text(m_clipboardmode).trimmed());
+ const QString cliptext(qApp->clipboard()->text(m_clipboardmode).trimmed());
if (cliptext.isEmpty()) {
Q_ASSERT(m_trayicon != Q_NULLPTR);
@@ -2837,7 +2838,7 @@ KeysManager::clipDecrypt()
void
KeysManager::clipSign()
{
- QString cliptext = kapp->clipboard()->text(m_clipboardmode);
+ QString cliptext = qApp->clipboard()->text(m_clipboardmode);
if (cliptext.isEmpty()) {
Q_ASSERT(m_trayicon != Q_NULLPTR);
m_trayicon->showMessage(QString(), i18n("Clipboard is empty."), QLatin1String( "kgpg" ));
diff --git a/kgpg.cpp b/kgpg.cpp
index 6e63607..2433d1d 100644
--- a/kgpg.cpp
+++ b/kgpg.cpp
@@ -2,6 +2,7 @@
* Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
* Copyright (C) 2007,2008,2009,2010,2011,2012,2013,2014
* Rolf Eike Beer <kde@opensource.sf-tec.de>
+ * Copyright (C) 2016 Andrius Štikonas <andrius@stikonas.eu>
*/
/***************************************************************************
@@ -25,19 +26,19 @@
#include "editor/kgpgeditor.h"
#include "transactions/kgpgimport.h"
+#include <QCommandLineParser>
#include <QFile>
#include <QMimeDatabase>
#include <QMimeType>
#include <QTextStream>
-#include <KCmdLineArgs>
#include <KMessageBox>
#include <KWindowSystem>
using namespace KgpgCore;
-KGpgApp::KGpgApp()
- : KUniqueApplication(),
+KGpgApp::KGpgApp(int &argc, char **argv)
+ : QApplication(argc, argv),
running(false),
w(Q_NULLPTR),
s_keyManager(0)
@@ -64,7 +65,7 @@ void KGpgApp::assistantOver(const QString &defaultKeyId)
s_keyManager->raise();
}
-int KGpgApp::newInstance()
+int KGpgApp::newInstance(QCommandLineParser& parser)
{
if (!running) {
running = true;
@@ -73,7 +74,7 @@ int KGpgApp::newInstance()
if (!gpgError.isEmpty()) {
running = false;
KMessageBox::detailedError(0, i18n("GnuPG failed to start.<br />You must fix the GnuPG error first before running KGpg."), gpgError, i18n("GnuPG error"));
- KApplication::quit();
+ QApplication::quit();
}
s_keyManager = new KeysManager();
@@ -100,22 +101,20 @@ int KGpgApp::newInstance()
}
}
- KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
-
// parsing of command line args
- if (args->isSet("k") || (!KGpgSettings::showSystray() && (args->count() == 0) && !args->isSet("d"))) {
+ if (parser.isSet("k") || (!KGpgSettings::showSystray() && (parser.positionalArguments().count() == 0) && !parser.isSet("d"))) {
s_keyManager->show();
KWindowSystem::setOnDesktop(s_keyManager->winId(), KWindowSystem::currentDesktop()); //set on the current desktop
KWindowSystem::unminimizeWindow(s_keyManager->winId()); //de-iconify window
s_keyManager->raise(); // set on top
- } else if (args->isSet("d")) {
+ } else if (parser.isSet("d")) {
s_keyManager->slotOpenEditor();
s_keyManager->hide();
} else {
QList<QUrl> urlList;
- for (int ct = 0; ct < args->count(); ct++)
- urlList.append(args->url(ct));
+ foreach (const auto &arg, parser.positionalArguments())
+ urlList.append(QUrl::fromLocalFile(arg));
bool directoryInside = false;
foreach (const QUrl &url, urlList) {
@@ -126,28 +125,28 @@ int KGpgApp::newInstance()
}
}
- if (args->isSet("e")) {
+ if (parser.isSet("e")) {
if (urlList.isEmpty())
KMessageBox::sorry(0, i18n("No files given."));
else if (!directoryInside)
KGpgExternalActions::encryptFiles(s_keyManager, urlList);
else
KGpgExternalActions::encryptFolders(s_keyManager, urlList);
- } else if (args->isSet("s")) {
+ } else if (parser.isSet("s")) {
if (urlList.isEmpty())
KMessageBox::sorry(0, i18n("No files given."));
else if (!directoryInside)
w->showDroppedFile(urlList.first());
else
KMessageBox::sorry(0, i18n("Cannot decrypt and show folder."));
- } else if (args->isSet("S")) {
+ } else if (parser.isSet("S")) {
if (urlList.isEmpty())
KMessageBox::sorry(0, i18n("No files given."));
else if (!directoryInside)
KGpgExternalActions::signFiles(s_keyManager, urlList);
else
KMessageBox::sorry(0, i18n("Cannot sign folder."));
- } else if (args->isSet("V") != 0) {
+ } else if (parser.isSet("V") != 0) {
if (urlList.isEmpty())
KMessageBox::sorry(0, i18n("No files given."));
else if (!directoryInside)
diff --git a/kgpg.h b/kgpg.h
index 6bfd4fe..08b07a2 100644
--- a/kgpg.h
+++ b/kgpg.h
@@ -18,13 +18,14 @@
#ifndef KGPGAPPLET_H
#define KGPGAPPLET_H
-#include <KUniqueApplication>
+#include <QApplication>
#include <QKeySequence>
#include <KLocale>
class KeysManager;
class KGpgExternalActions;
+class QCommandLineParser;
class QString;
static const char * const EMailTemplateText=I18N_NOOP(
@@ -38,15 +39,15 @@ static const char * const EMailTemplateText=I18N_NOOP(
"With KGpg you can right click on the key once you imported all user ids and choose `Export Public Key...`.\n\n"
"If you have any questions, don't hesitate to ask.\n");
-class KGpgApp : public KUniqueApplication
+class KGpgApp : public QApplication
{
Q_OBJECT
public:
- KGpgApp();
+ KGpgApp(int &argc, char **argv);
~KGpgApp();
- int newInstance ();
+ int newInstance (QCommandLineParser&);
bool running;
QKeySequence goHome;
diff --git a/main.cpp b/main.cpp
index 1015cd2..a5c8e96 100644
--- a/main.cpp
+++ b/main.cpp
@@ -2,6 +2,7 @@
* Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
* Copyright (C) 2007,2008,2009,2010,2011,2012,2013,2014,2015,2016
* Rolf Eike Beer <kde@opensource.sf-tec.de>
+ * Copyright (C) 2016 Andrius Štikonas <andrius@stikonas.eu>
*/
/***************************************************************************
@@ -15,10 +16,13 @@
#include "kgpg.h"
+#include <QCommandLineOption>
+#include <QCommandLineParser>
+
#include <K4AboutData>
-#include <KCmdLineArgs>
+#include <KAboutData>
+#include <KDBusService>
#include <KLocalizedString>
-#include <KUniqueApplication>
static const char description[] =
I18N_NOOP("KGpg - simple gui for GnuPG");
@@ -26,6 +30,9 @@ static const char description[] =
int main(int argc, char *argv[])
{
K4AboutData about("kgpg", 0, ki18n("KGpg"), KGPG_VERSION, ki18n(description), K4AboutData::License_GPL, ki18n("&copy; 2003-2016, The KGpg Developers"));
+ KGpgApp *app = new KGpgApp(argc, argv);
+
+ KLocalizedString::setApplicationDomain("kgpg");
about.addAuthor(ki18n("Rolf Eike Beer"), ki18n("Maintainer"), "kde@opensource.sf-tec.de");
about.addAuthor(ki18n("Jean-Baptiste Mardelle"), ki18n("Author and former maintainer"), "bj@altern.org");
@@ -33,23 +40,28 @@ int main(int argc, char *argv[])
about.setHomepage("http://utils.kde.org/projects/kgpg");
- KCmdLineArgs::init(argc, argv, &about);
+ KAboutData::setApplicationData(about);
- KCmdLineOptions options;
- options.add("e", ki18n("Encrypt file"));
- options.add("k", ki18n("Open key manager"));
- options.add("d", ki18n("Open editor"));
- options.add("s", ki18n("Show encrypted file"));
- options.add("S", ki18n("Sign File"));
- options.add("V", ki18n("Verify signature"));
- options.add("+[File]", ki18n("File to open"));
- KCmdLineArgs::addCmdLineOptions(options);
- KUniqueApplication::addCmdLineOptions();
+ QCommandLineParser parser;
+ parser.setApplicationDescription(about.shortDescription());
+ parser.addVersionOption();
+ parser.addHelpOption();
+ KAboutData(about).setupCommandLine(&parser);
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("e"), i18n("Encrypt file")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("k"), i18n("Open key manager")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("d"), i18n("Open editor")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("s"), i18n("Show encrypted file")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("S"), i18n("Sign File")));
+ parser.addOption(QCommandLineOption(QStringList() << QLatin1String("V"), i18n("Verify signature")));
+ parser.addPositionalArgument(QLatin1String("[File]"), i18n("File to open"));
- if (!KUniqueApplication::start())
- return 0;
+ parser.process(*app);
+ KAboutData(about).processCommandLine(&parser);
- KApplication *app = new KGpgApp();
app->setQuitOnLastWindowClosed(false);
+ KDBusService service(KDBusService::Unique);
+
+ app->newInstance(parser);
+
return app->exec();
}