• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
kgpg.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  kgpg.cpp - description
3  -------------------
4  begin : Mon Nov 18 2002
5  copyright : (C) 2002 by Jean-Baptiste Mardelle
6  email : bj@altern.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "kgpg.h"
19 
20 #include "gpgproc.h"
21 #include "kgpgsettings.h"
22 #include "keysmanager.h"
23 #include "kgpg_interface.h"
24 #include "kgpgexternalactions.h"
25 #include "kgpginterface.h"
26 #include "core/images.h"
27 #include "editor/kgpgeditor.h"
28 #include "transactions/kgpgimport.h"
29 
30 #include <KCmdLineArgs>
31 #include <KMessageBox>
32 #include <KWindowSystem>
33 #include <KMimeType>
34 #include <QApplication>
35 #include <QtDBus/QtDBus>
36 
37 using namespace KgpgCore;
38 
39 KGpgApp::KGpgApp()
40  : KUniqueApplication(),
41  running(false),
42  w(NULL),
43  s_keyManager(0)
44 {
45 }
46 
47 KGpgApp::~KGpgApp()
48 {
49  delete s_keyManager;
50 }
51 
52 void KGpgApp::slotHandleQuit()
53 {
54  s_keyManager->saveToggleOpts();
55  quit();
56 }
57 
58 void KGpgApp::assistantOver(const QString &defaultKeyId)
59 {
60  if (!defaultKeyId.isEmpty())
61  s_keyManager->slotSetDefaultKey(defaultKeyId);
62 
63  s_keyManager->show();
64  s_keyManager->raise();
65 }
66 
67 int KGpgApp::newInstance()
68 {
69  if (!running) {
70  running = true;
71 
72  const QString gpgPath(KGpgSettings::gpgConfigPath());
73 
74  const QString gpgError = GPGProc::getGpgStartupError(KGpgSettings::gpgBinaryPath());
75  if (!gpgError.isEmpty()) {
76  KMessageBox::detailedError(0, i18n("GnuPG failed to start.<br />You must fix the GnuPG error first before running KGpg."), gpgError, i18n("GnuPG error"));
77  KApplication::quit();
78  }
79 
80  s_keyManager = new KeysManager();
81 
82  w = new KGpgExternalActions(s_keyManager, s_keyManager->getModel());
83 
84  connect(s_keyManager, SIGNAL(readAgainOptions()), w, SLOT(readOptions()));
85  connect(w, SIGNAL(updateDefault(QString)), SLOT(assistantOver(QString)));
86  connect(w, SIGNAL(createNewKey()), s_keyManager, SLOT(slotGenerateKey()));
87 
88  if (!gpgPath.isEmpty()) {
89  if ((KgpgInterface::getGpgBoolSetting(QLatin1String( "use-agent" ), gpgPath)) && (qgetenv("GPG_AGENT_INFO").isEmpty()))
90  KMessageBox::sorry(0, i18n("<qt>The use of <b>GnuPG Agent</b> is enabled in GnuPG's configuration file (%1).<br />"
91  "However, the agent does not seem to be running. This could result in problems with signing/decryption.<br />"
92  "Please disable GnuPG Agent from KGpg settings, or fix the agent.</qt>", gpgPath));
93  }
94  }
95 
96  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
97 
98  // parsing of command line args
99  if (args->isSet("k") || (!KGpgSettings::showSystray() && (args->count() == 0) && !args->isSet("d"))) {
100  s_keyManager->show();
101  KWindowSystem::setOnDesktop(s_keyManager->winId(), KWindowSystem::currentDesktop()); //set on the current desktop
102  KWindowSystem::unminimizeWindow(s_keyManager->winId()); //de-iconify window
103  s_keyManager->raise(); // set on top
104  } else if (args->isSet("d")) {
105  s_keyManager->slotOpenEditor();
106  s_keyManager->hide();
107  } else {
108  KUrl::List urlList;
109 
110  for (int ct = 0; ct < args->count(); ct++)
111  urlList.append(args->url(ct));
112 
113  bool directoryInside = false;
114  foreach (const KUrl &url, urlList)
115  if (KMimeType::findByUrl(url)->name() == QLatin1String( "inode/directory" )) {
116  directoryInside = true;
117  break;
118  }
119 
120  if (args->isSet("e")) {
121  if (urlList.isEmpty())
122  KMessageBox::sorry(0, i18n("No files given."));
123  else if (!directoryInside)
124  KGpgExternalActions::encryptFiles(s_keyManager, urlList);
125  else
126  KGpgExternalActions::encryptFolders(s_keyManager, urlList);
127  } else if (args->isSet("s")) {
128  if (urlList.isEmpty())
129  KMessageBox::sorry(0, i18n("No files given."));
130  else if (!directoryInside)
131  w->showDroppedFile(urlList.first());
132  else
133  KMessageBox::sorry(0, i18n("Cannot decrypt and show folder."));
134  } else if (args->isSet("S")) {
135  if (urlList.isEmpty())
136  KMessageBox::sorry(0, i18n("No files given."));
137  else if (!directoryInside)
138  KGpgExternalActions::signFiles(s_keyManager, urlList);
139  else
140  KMessageBox::sorry(0, i18n("Cannot sign folder."));
141  } else if (args->isSet("V") != 0) {
142  if (urlList.isEmpty())
143  KMessageBox::sorry(0, i18n("No files given."));
144  else if (!directoryInside)
145  w->verifyFile(urlList.first());
146  else
147  KMessageBox::sorry(0, i18n("Cannot verify folder."));
148  } else {
149  if (directoryInside && (urlList.count() > 1)) {
150  KMessageBox::sorry(0, i18n("Unable to perform requested operation.\nPlease select only one folder, or several files, but do not mix files and folders."));
151  return 0;
152  }
153 
154  if (urlList.isEmpty()) {
155  /* do nothing */
156  } else if (urlList.first().fileName().endsWith(QLatin1String(".sig"))) {
157  w->verifyFile(urlList.first());
158  } else {
159  bool haskeys = false;
160  bool hastext = false;
161  foreach (const KUrl &url, urlList) {
162  QFile qfile(url.path());
163  if (qfile.open(QIODevice::ReadOnly)) {
164  const int probelen = 4096;
165  QTextStream t(&qfile);
166  QString probetext(t.read(probelen));
167  qfile.close();
168 
169  if (KGpgImport::isKey(probetext, probetext.length() == probelen))
170  haskeys = true;
171  else
172  hastext = true;
173  }
174  }
175 
176  if (hastext) {
177  KGpgExternalActions::decryptFiles(s_keyManager, urlList);
178  } else if (haskeys) {
179  s_keyManager->slotImport(urlList);
180  }
181  }
182  }
183  }
184 
185  return 0;
186 }
187 
188 #include "kgpg.moc"
kgpgimport.h
kgpg.h
KGpgSettings::gpgConfigPath
static QString gpgConfigPath()
Get The path of the gpg configuration file.
Definition: kgpgsettings.h:288
KGpgExternalActions::decryptFiles
static void decryptFiles(KeysManager *parent, const KUrl::List &urls)
Definition: kgpgexternalactions.cpp:337
KeysManager::slotOpenEditor
void slotOpenEditor()
Definition: keysmanager.cpp:545
KGpgApp::running
bool running
Definition: kgpg.h:51
KgpgInterface::getGpgBoolSetting
bool getGpgBoolSetting(const QString &name, const QString &configfile)
Definition: kgpginterface.cpp:93
KGpgSettings::showSystray
static bool showSystray()
Get Show the systray icon.
Definition: kgpgsettings.h:668
images.h
QFile
KeysManager::saveToggleOpts
void saveToggleOpts(void)
Definition: keysmanager.cpp:1139
kgpgexternalactions.h
QTextStream
KeysManager::getModel
KGpgItemModel * getModel()
Definition: keysmanager.cpp:2634
KGpgExternalActions::verifyFile
void verifyFile(KUrl url)
Definition: kgpgexternalactions.cpp:238
KeysManager::slotSetDefaultKey
void slotSetDefaultKey(const QString &newID)
Definition: keysmanager.cpp:1201
GPGProc::getGpgStartupError
static QString getGpgStartupError(const QString &binary)
run GnuPG and check if it complains about anything
Definition: gpgproc.cpp:317
kgpgeditor.h
KGpgSettings::gpgBinaryPath
static QString gpgBinaryPath()
Get The path of the gpg binary used by KGpg.
Definition: kgpgsettings.h:307
KeysManager::slotImport
void slotImport(const QString &text)
Definition: keysmanager.cpp:2561
KGpgExternalActions::encryptFiles
static void encryptFiles(KeysManager *parent, const KUrl::List &urls)
create a new object, encrypt the given files, and destroy the object
Definition: kgpgexternalactions.cpp:66
KGpgApp::newInstance
int newInstance()
Definition: kgpg.cpp:67
QString::isEmpty
bool isEmpty() const
gpgproc.h
KeysManager
Definition: keysmanager.h:66
kgpginterface.h
KGpgApp::~KGpgApp
~KGpgApp()
Definition: kgpg.cpp:47
QString
KGpgExternalActions
handle actions called from outside the application
Definition: kgpgexternalactions.h:41
KGpgApp::KGpgApp
KGpgApp()
Definition: kgpg.cpp:39
QTextStream::read
QString read(qint64 maxlen)
KGpgExternalActions::encryptFolders
static void encryptFolders(KeysManager *parent, const KUrl::List &urls)
Definition: kgpgexternalactions.cpp:128
kgpgsettings.h
QLatin1String
keysmanager.h
KGpgExternalActions::signFiles
static void signFiles(KeysManager *parent, const KUrl::List &urls)
create a detached signature for the given files
Definition: kgpgexternalactions.cpp:292
KUniqueApplication
KGpgImport::isKey
static int isKey(const QString &text, const bool incomplete=false)
check if the given text contains a private or public key
Definition: kgpgimport.cpp:276
KGpgExternalActions::showDroppedFile
void showDroppedFile(const KUrl &file)
Definition: kgpgexternalactions.cpp:414
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal