• 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
  • editor
kgpgeditor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
3  * Copyright (C) 2007,2008,2009,2010,2011 Rolf Eike Beer <kde@opensource.sf-tec.de>
4  */
5 
6 /***************************************************************************
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  ***************************************************************************/
14 
15 #include "kgpgeditor.h"
16 
17 #include "detailedconsole.h"
18 #include "selectsecretkey.h"
19 #include "kgpgmd5widget.h"
20 #include "kgpgsettings.h"
21 #include "keyservers.h"
22 #include "sourceselect.h"
23 #include "kgpg.h"
24 #include "keysmanager.h"
25 #include "editor/kgpgtextedit.h"
26 #include "transactions/kgpgdecrypt.h"
27 #include "transactions/kgpgkeyservergettransaction.h"
28 #include "transactions/kgpgsigntext.h"
29 #include "transactions/kgpgverify.h"
30 #include <kgpgexternalactions.h>
31 
32 #include <KAction>
33 #include <KActionCollection>
34 #include <KDebug>
35 #include <KEncodingFileDialog>
36 #include <KFind>
37 #include <KFindDialog>
38 #include <KIcon>
39 #include <KLocale>
40 #include <KMenuBar>
41 #include <KMessageBox>
42 #include <KRecentFilesAction>
43 #include <KShortcut>
44 #include <KStandardAction>
45 #include <KTemporaryFile>
46 #include <KToggleAction>
47 #include <KToolBar>
48 #include <QPainter>
49 #include <QTextCodec>
50 #include <QTextStream>
51 #include <QVBoxLayout>
52 #include <QWidget>
53 #include <QtDBus/QtDBus>
54 #include <QtGui/QPrintDialog>
55 #include <QtGui/QPrinter>
56 #include <kio/netaccess.h>
57 #include <kio/renamedialog.h>
58 
59 class KgpgView : public QWidget {
60 public:
61  KgpgView(QWidget *parent, KgpgTextEdit *editor, KToolBar *toolbar);
62 };
63 
64 KgpgView::KgpgView(QWidget *parent, KgpgTextEdit *editor, KToolBar *toolbar)
65  : QWidget(parent)
66 {
67  QVBoxLayout *vb = new QVBoxLayout(this);
68  vb->setSpacing(3);
69  vb->addWidget(editor);
70  vb->addWidget(toolbar);
71 
72  setAcceptDrops(true);
73 }
74 
75 KgpgEditor::KgpgEditor(KeysManager *parent, KGpgItemModel *model, Qt::WFlags f)
76  : KXmlGuiWindow(0, f),
77  m_editor(new KgpgTextEdit(this, model, parent)),
78  m_recentfiles(NULL),
79  m_find(0),
80  m_textchanged(false),
81  m_emptytext(true),
82  m_model(model),
83  m_parent(parent)
84 {
85  // call inits to invoke all other construction parts
86  initActions();
87 
88  connect(m_editor, SIGNAL(resetEncoding(bool)), SLOT(slotResetEncoding(bool)));
89  KgpgView *kb = new KgpgView(this, m_editor, toolBar(QLatin1String( "gpgToolBar" )));
90  setCentralWidget(kb);
91  setCaption(i18n("Untitled"), false);
92  m_editredo->setEnabled(false);
93  m_editundo->setEnabled(false);
94  m_editcopy->setEnabled(false);
95  m_editcut->setEnabled(false);
96 
97  setObjectName( QLatin1String("editor" ));
98  slotSetFont(KGpgSettings::font());
99  setupGUI((ToolBar | Keys | StatusBar | Save | Create), QLatin1String( "kgpgeditor.rc" ));
100  setAutoSaveSettings(QLatin1String( "Editor" ), true);
101 
102  connect(m_editor, SIGNAL(textChanged()), SLOT(modified()));
103  connect(m_editor, SIGNAL(newText()), SLOT(newText()));
104  connect(m_editor, SIGNAL(undoAvailable(bool)), SLOT(slotUndoAvailable(bool)));
105  connect(m_editor, SIGNAL(redoAvailable(bool)), SLOT(slotRedoAvailable(bool)));
106  connect(m_editor, SIGNAL(copyAvailable(bool)), SLOT(slotCopyAvailable(bool)));
107 }
108 
109 KgpgEditor::~KgpgEditor()
110 {
111  m_recentfiles->saveEntries( KConfigGroup(KGlobal::config(), "Recent Files" ) );
112 }
113 
114 void KgpgEditor::openDocumentFile(const KUrl& url, const QString &encoding)
115 {
116  QString tempopenfile;
117  if(KIO::NetAccess::download(url, tempopenfile, this))
118  {
119  QFile qfile(tempopenfile);
120  if (qfile.open(QIODevice::ReadOnly))
121  {
122  QTextStream t(&qfile);
123  t.setCodec(encoding.toAscii());
124  m_editor->setPlainText(t.readAll());
125  qfile.close();
126  m_docname = url;
127  m_textchanged = false;
128  m_emptytext = false;
129  setCaption(url.fileName(), false);
130  m_recentfiles->addUrl(url);
131  }
132  KIO::NetAccess::removeTempFile(tempopenfile);
133  }
134 }
135 
136 void KgpgEditor::openEncryptedDocumentFile(const KUrl& url)
137 {
138  m_editor->slotDroppedFile(url);
139 }
140 
141 void KgpgEditor::slotSetFont(QFont myFont)
142 {
143  m_editor->setFont(myFont);
144 }
145 
146 void KgpgEditor::closeWindow()
147 {
148  m_recentfiles->saveEntries( KConfigGroup(KGlobal::config(), "Recent Files" ) );
149  close();
150 }
151 
152 void KgpgEditor::saveOptions()
153 {
154  KGpgSettings::setFirstRun(false);
155  KGpgSettings::self()->writeConfig();
156 }
157 
158 void KgpgEditor::initActions()
159 {
160  KStandardAction::openNew(this, SLOT(slotFileNew()), actionCollection());
161  KStandardAction::open(this, SLOT(slotFileOpen()), actionCollection());
162  KStandardAction::save(this, SLOT(slotFileSave()), actionCollection());
163  KStandardAction::saveAs(this, SLOT(slotFileSaveAs()), actionCollection());
164  KStandardAction::close(this, SLOT(slotFileClose()), actionCollection());
165  KStandardAction::paste(this, SLOT(slotEditPaste()), actionCollection());
166  KStandardAction::print(this, SLOT(slotFilePrint()), actionCollection());
167  KStandardAction::selectAll(this, SLOT(slotSelectAll()), actionCollection());
168  KStandardAction::find(this, SLOT(slotFind()), actionCollection());
169  KStandardAction::findNext(this, SLOT(slotFindNext()), actionCollection());
170  KStandardAction::findPrev(this, SLOT(slotFindPrev()), actionCollection());
171  actionCollection()->addAction(KStandardAction::Preferences, QLatin1String( "options_configure" ),
172  this, SLOT(slotOptions()));
173 
174  m_editundo = KStandardAction::undo(this, SLOT(slotundo()), actionCollection());
175  m_editredo = KStandardAction::redo(this, SLOT(slotredo()), actionCollection());
176  m_editcopy = KStandardAction::copy(this, SLOT(slotEditCopy()), actionCollection());
177  m_editcut = KStandardAction::cut(this, SLOT(slotEditCut()), actionCollection());
178 
179  m_recentfiles = KStandardAction::openRecent(this, SLOT(openDocumentFile(KUrl)), this);
180  menuBar()->addAction(m_recentfiles);
181 
182  m_recentfiles->loadEntries( KConfigGroup(KGlobal::config(), "Recent Files" ) );
183  m_recentfiles->setMaxItems(KGpgSettings::recentFiles());
184 
185  KAction *action = actionCollection()->addAction(QLatin1String("file_encrypt"), this, SLOT(slotFilePreEnc()));
186  action->setIcon(KIcon( QLatin1String( "document-encrypt" )));
187  action->setText(i18n("&Encrypt File..."));
188 
189  action = actionCollection()->addAction(QLatin1String("file_decrypt"), this, SLOT(slotFilePreDec()));
190  action->setIcon(KIcon( QLatin1String( "document-decrypt" )));
191  action->setText(i18n("&Decrypt File..."));
192 
193  action = actionCollection()->addAction(QLatin1String("key_manage"), this, SLOT(slotKeyManager()));
194  action->setIcon(KIcon( QLatin1String( "kgpg" )));
195  action->setText(i18n("&Open Key Manager"));
196 
197  action = actionCollection()->addAction(QLatin1String("sign_generate"), this, SLOT(slotPreSignFile()));
198  action->setText(i18n("&Generate Signature..."));
199  action->setIcon(KIcon( QLatin1String( "document-sign-key" )));
200 
201  action = actionCollection()->addAction(QLatin1String("sign_verify"), this, SLOT(slotPreVerifyFile()));
202  action->setText(i18n("&Verify Signature..."));
203 
204  action = actionCollection()->addAction(QLatin1String("sign_check"), this, SLOT(slotCheckMd5()));
205  action->setText(i18n("&Check MD5 Sum..."));
206 
207  m_encodingaction = actionCollection()->add<KToggleAction>(QLatin1String("charsets"), this, SLOT(slotSetCharset()));
208  m_encodingaction->setText(i18n("&Unicode (utf-8) Encoding"));
209 
210  actionCollection()->addAction(m_recentfiles->objectName(), m_recentfiles);
211 
212  action = actionCollection()->addAction(QLatin1String("text_encrypt"), m_editor, SLOT(slotEncode()));
213  action->setIcon(KIcon( QLatin1String( "document-encrypt" )));
214  action->setText(i18n("En&crypt"));
215 
216  action = actionCollection()->addAction(QLatin1String("text_decrypt"), m_editor, SLOT(slotDecode()));
217  action->setIcon(KIcon( QLatin1String( "document-decrypt" )));
218  action->setText(i18n("&Decrypt"));
219 
220  action = actionCollection()->addAction(QLatin1String("text_sign_verify"), m_editor, SLOT(slotSignVerify()));
221  action->setIcon(KIcon( QLatin1String( "document-sign-key" )));
222  action->setText(i18n("S&ign/Verify"));
223 }
224 
225 bool KgpgEditor::queryClose()
226 {
227  bool b = saveBeforeClear();
228  if (b) {
229  m_editor->clear();
230  newText();
231  }
232  return b;
233 }
234 
235 bool KgpgEditor::saveBeforeClear()
236 {
237  if (m_textchanged)
238  {
239  QString fname;
240  if (m_docname.fileName().isEmpty())
241  fname = i18n("Untitled");
242  else
243  fname = m_docname.fileName();
244 
245  QString msg = i18n("The document \"%1\" has changed.\nDo you want to save it?", fname);
246  QString caption = i18n("Close the document");
247  int res = KMessageBox::warningYesNoCancel(this, msg, caption, KStandardGuiItem::save(), KStandardGuiItem::discard());
248  if (res == KMessageBox::Yes)
249  return slotFileSave();
250  else
251  if (res == KMessageBox::No)
252  return true;
253  else
254  return false;
255  }
256 
257  return true;
258 }
259 
260 void KgpgEditor::slotFileNew()
261 {
262  if (saveBeforeClear())
263  {
264  m_editor->clear();
265  newText();
266  }
267 }
268 
269 void KgpgEditor::slotFileOpen()
270 {
271  if (saveBeforeClear())
272  {
273  KEncodingFileDialog::Result loadResult;
274  loadResult = KEncodingFileDialog::getOpenUrlAndEncoding(QString(), QString(), QString(), this);
275  KUrl url = loadResult.URLs.first();
276  m_textencoding = loadResult.encoding;
277 
278  if(!url.isEmpty())
279  openDocumentFile(url, m_textencoding);
280  }
281 }
282 
283 bool KgpgEditor::slotFileSave()
284 {
285  QString filn = m_docname.path();
286  if (filn.isEmpty())
287  return slotFileSaveAs();
288 
289  QTextCodec *cod = QTextCodec::codecForName(m_textencoding.toAscii());
290 
291  if (cod == NULL) {
292  KMessageBox::sorry(this, i18n("The document could not been saved, as the selected codec is not supported."));
293  return false;
294  }
295 
296  if (!checkEncoding(cod))
297  {
298  KMessageBox::sorry(this, i18n("The document could not been saved, as the selected encoding cannot encode every unicode character in it."));
299  return false;
300  }
301 
302  if (m_docname.isLocalFile())
303  {
304  QFile f(filn);
305  if (!f.open(QIODevice::WriteOnly))
306  {
307  KMessageBox::sorry(this, i18n("The document could not be saved, please check your permissions and disk space."));
308  return false;
309  }
310 
311  QTextStream t(&f);
312  t.setCodec(cod);
313  t << m_editor->toPlainText();
314  f.close();
315  }
316  else
317  {
318  KTemporaryFile tmpfile;
319  tmpfile.open();
320  QTextStream stream(&tmpfile);
321  stream.setCodec(cod);
322  stream << m_editor->toPlainText();
323 
324  if(!KIO::NetAccess::upload(tmpfile.fileName(), m_docname, this))
325  {
326  KMessageBox::sorry(this, i18n("The document could not be saved, please check your permissions and disk space."));
327  return false;
328  }
329  }
330 
331  m_textchanged = false;
332  m_emptytext = false;
333  setCaption(m_docname.fileName(), false);
334  return true;
335 }
336 
337 bool KgpgEditor::slotFileSaveAs()
338 {
339  KEncodingFileDialog::Result saveResult;
340  saveResult = KEncodingFileDialog::getSaveUrlAndEncoding(QString(), QString(), QString(), this);
341  KUrl url;
342 
343  if (!saveResult.URLs.empty())
344  url = saveResult.URLs.first();
345 
346  if(!url.isEmpty()) {
347  const QString selectedEncoding = saveResult.encoding;
348  if (url.isLocalFile()) {
349  QString filn = url.path();
350  QFile f(url.path());
351  if (f.exists()) {
352  const QString message = i18n("Overwrite existing file %1?", url.fileName());
353  int result = KMessageBox::warningContinueCancel(this, message, QString(), KStandardGuiItem::overwrite());
354  if (result == KMessageBox::Cancel)
355  return false;
356  }
357  f.close();
358  } else if (KIO::NetAccess::exists(url, KIO::NetAccess::DestinationSide, this)) {
359  const QString message = i18n("Overwrite existing file %1?", url.fileName());
360  int result = KMessageBox::warningContinueCancel(this, message, QString(), KStandardGuiItem::overwrite());
361  if (result == KMessageBox::Cancel)
362  return false;
363  }
364 
365  m_docname = url;
366  m_textencoding = selectedEncoding;
367  slotFileSave();
368  return true;
369  }
370 
371  return false;
372 }
373 
374 void KgpgEditor::slotFilePrint()
375 {
376  QPrinter prt;
377  QPointer<QPrintDialog> printDialog = new QPrintDialog(&prt, this);
378  if (printDialog->exec() == QDialog::Accepted) {
379  int width = prt.width();
380  int height = prt.height();
381  QPainter painter(&prt);
382  painter.drawText(0, 0, width, height, Qt::AlignLeft | Qt::AlignTop | Qt::TextDontClip, m_editor->toPlainText());
383  }
384  delete printDialog;
385 }
386 
387 void KgpgEditor::slotFind()
388 {
389  QPointer<KFindDialog> fd = new KFindDialog(this);
390 
391  if (m_find) {
392  fd->setOptions(m_find->options());
393  fd->setPattern(m_find->pattern());
394  }
395 
396  if (fd->exec() != QDialog::Accepted) {
397  delete fd;
398  return;
399  }
400 
401  if (!m_find) {
402  m_find = new KFind(fd->pattern(), fd->options(), this);
403 
404  if (m_find->options() & KFind::FromCursor)
405  m_find->setData(m_editor->toPlainText(), m_editor->textCursor().selectionStart());
406  else
407  m_find->setData(m_editor->toPlainText());
408  connect(m_find, SIGNAL(highlight(QString,int,int)), m_editor, SLOT(slotHighlightText(QString,int,int)));
409  connect(m_find, SIGNAL(findNext()), this, SLOT(slotFindText()));
410  } else {
411  m_find->setPattern(fd->pattern());
412  m_find->setOptions(fd->options());
413  m_find->resetCounts();
414  }
415 
416  slotFindText();
417  delete fd;
418 }
419 
420 void KgpgEditor::slotFindNext()
421 {
422  slotFindText();
423 }
424 
425 void KgpgEditor::slotFindPrev()
426 {
427  if(!m_find)
428  {
429  slotFind();
430  return;
431  }
432  long oldopt = m_find->options();
433  long newopt = oldopt ^ KFind::FindBackwards;
434  m_find->setOptions(newopt);
435  slotFindText();
436  m_find->setOptions(oldopt);
437 }
438 
439 void KgpgEditor::slotFindText()
440 {
441  if (!m_find)
442  {
443  slotFind();
444  return;
445  }
446 
447  if (m_find->find() == KFind::NoMatch)
448  {
449  if (m_find->numMatches() == 0)
450  {
451  m_find->displayFinalDialog();
452  delete m_find;
453  m_find = 0;
454  }
455  else
456  {
457  if (m_find->shouldRestart(true, false))
458  {
459  m_find->setData(m_editor->toPlainText());
460  slotFindText();
461  }
462  else
463  m_find->closeFindNextDialog();
464  }
465  }
466 }
467 
468 void KgpgEditor::slotFilePreEnc()
469 {
470  KUrl::List urls = KFileDialog::getOpenUrls(KUrl(), i18n("*|All Files"), this, i18n("Open File to Encode"));
471  if (urls.isEmpty())
472  return;
473 
474  KGpgExternalActions::encryptFiles(m_parent, urls);
475 }
476 
477 void KgpgEditor::slotFilePreDec()
478 {
479  KUrl url = KFileDialog::getOpenUrl(KUrl(), i18n("*|All Files"), this, i18n("Open File to Decode"));
480  if (url.isEmpty())
481  return;
482 
483  QString oldname = url.fileName();
484  QString newname;
485 
486  if (oldname.endsWith(QLatin1String(".gpg")) || oldname.endsWith(QLatin1String(".asc")) || oldname.endsWith(QLatin1String(".pgp")))
487  oldname.chop(4);
488  else
489  oldname.append(QLatin1String( ".clear" ));
490  oldname.prepend(url.directory(KUrl::AppendTrailingSlash));
491 
492  QPointer<KDialog> popn = new KDialog(this);
493  popn->setCaption( i18n("Decrypt File To") );
494  popn->setButtons( KDialog::Ok | KDialog::Cancel );
495  popn->setDefaultButton( KDialog::Ok );
496  popn->setModal( true );
497 
498  SrcSelect *page = new SrcSelect();
499  popn->setMainWidget(page);
500  page->newFilename->setUrl(oldname);
501  page->newFilename->setMode(KFile::File);
502  page->newFilename->setWindowTitle(i18n("Save File"));
503 
504  page->checkClipboard->setText(i18n("Editor"));
505  page->resize(page->minimumSize());
506  popn->resize(popn->minimumSize());
507  if (popn->exec() == QDialog::Accepted)
508  {
509  if (page->checkFile->isChecked())
510  newname = page->newFilename->url().path();
511  }
512  else
513  {
514  delete popn;
515  return;
516  }
517  delete popn;
518 
519  if (!newname.isEmpty())
520  {
521  QFile fgpg(newname);
522  if (fgpg.exists()) {
523  QPointer<KIO::RenameDialog> over = new KIO::RenameDialog(this, i18n("File Already Exists"), KUrl(), KUrl::fromPath(newname), KIO::M_OVERWRITE);
524 
525  if (over->exec() != QDialog::Accepted) {
526  delete over;
527  return;
528  }
529  newname = over->newDestUrl().path();
530  delete over;
531  }
532 
533  KGpgDecrypt *decr = new KGpgDecrypt(this, url, KUrl(newname));
534  connect(decr, SIGNAL(done(int)), SLOT(slotLibraryDone()));
535  decr->start();
536  }
537  else
538  openEncryptedDocumentFile(url);
539 }
540 
541 void
542 KgpgEditor::slotLibraryDone()
543 {
544  sender()->deleteLater();
545 }
546 
547 void KgpgEditor::slotKeyManager()
548 {
549  m_parent->show();
550  m_parent->raise();
551 }
552 
553 void KgpgEditor::slotFileClose()
554 {
555  saveOptions();
556  close();
557 }
558 
559 void KgpgEditor::slotundo()
560 {
561  m_editor->undo();
562 }
563 
564 void KgpgEditor::slotredo()
565 {
566  m_editor->redo();
567 }
568 
569 void KgpgEditor::slotEditCut()
570 {
571  m_editor->cut();
572 }
573 
574 void KgpgEditor::slotEditCopy()
575 {
576  m_editor->copy();
577 }
578 
579 void KgpgEditor::slotEditPaste()
580 {
581  m_editor->paste();
582 }
583 
584 void KgpgEditor::slotSelectAll()
585 {
586  m_editor->selectAll();
587 }
588 
589 void KgpgEditor::slotSetCharset()
590 {
591  if (!m_encodingaction->isChecked())
592  m_editor->setPlainText(QString::fromUtf8(m_editor->toPlainText().toAscii()));
593  else
594  {
595  if (checkEncoding(QTextCodec::codecForLocale()))
596  return;
597  m_editor->setPlainText(QLatin1String( m_editor->toPlainText().toUtf8() ));
598  }
599 }
600 
601 bool KgpgEditor::checkEncoding(QTextCodec *codec)
602 {
603  return codec->canEncode(m_editor->toPlainText());
604 }
605 
606 void KgpgEditor::slotResetEncoding(bool enc)
607 {
608  m_encodingaction->setChecked(enc);
609 }
610 
611 void KgpgEditor::slotPreSignFile()
612 {
613  // create a detached signature for a chosen file
614  KUrl url = KFileDialog::getOpenUrl(KUrl(), i18n("*|All Files"), this, i18n("Open File to Sign"));
615  if (!url.isEmpty())
616  slotSignFile(url);
617 }
618 
619 void KgpgEditor::slotSignFile(const KUrl &url)
620 {
621  // create a detached signature for a chosen file
622  if (!url.isEmpty())
623  {
624  QString signKeyID;
625  QPointer<KgpgSelectSecretKey> opts = new KgpgSelectSecretKey(this, m_model, false);
626  if (opts->exec() == QDialog::Accepted) {
627  signKeyID = opts->getKeyID();
628  } else {
629  delete opts;
630  return;
631  }
632 
633  delete opts;
634 
635  KGpgSignText::SignOptions sopts = KGpgSignText::DetachedSignature;
636  if (KGpgSettings::asciiArmor())
637  sopts |= KGpgSignText::AsciiArmored;
638 
639  KGpgSignText *signt = new KGpgSignText(this, signKeyID, KUrl::List(url), sopts);
640  connect(signt, SIGNAL(done(int)), SLOT(slotSignFileFin()));
641  signt->start();
642  }
643 }
644 
645 void KgpgEditor::slotSignFileFin()
646 {
647  sender()->deleteLater();
648 }
649 
650 void KgpgEditor::slotPreVerifyFile()
651 {
652  KUrl url = KFileDialog::getOpenUrl(KUrl(), i18n("*|All Files"), this, i18n("Open File to Verify"));
653  slotVerifyFile(url);
654 }
655 
656 void KgpgEditor::slotVerifyFile(const KUrl &url)
657 {
658  if (!url.isEmpty())
659  {
660  QString sigfile;
661  if (!url.fileName().endsWith(QLatin1String(".sig")))
662  {
663  sigfile = url.path() + QLatin1String( ".sig" );
664  QFile fsig(sigfile);
665  if (!fsig.exists())
666  {
667  sigfile = url.path() + QLatin1String( ".asc" );
668  QFile fsig(sigfile);
669  // if no .asc or .sig signature file included, assume the file is internally signed
670  if (!fsig.exists())
671  sigfile.clear();
672  }
673  }
674 
675  KUrl::List chkfiles;
676  if (sigfile.isEmpty())
677  chkfiles << url;
678  else
679  chkfiles << KUrl::fromPath(sigfile);
680 
681  KGpgVerify *verify = new KGpgVerify(this, chkfiles);
682  connect(verify, SIGNAL(done(int)), m_editor, SLOT(slotVerifyDone(int)));
683  verify->start();
684  }
685 }
686 
687 void KgpgEditor::slotCheckMd5()
688 {
689  // display md5 sum for a chosen file
690  KUrl url = KFileDialog::getOpenUrl(KUrl(), i18n("*|All Files"), this, i18n("Open File to Verify"));
691  if (!url.isEmpty()) {
692  QPointer<Md5Widget> mdwidget = new Md5Widget(this, url);
693  mdwidget->exec();
694  delete mdwidget;
695  }
696 }
697 
698 void KgpgEditor::importSignatureKey(const QString &id, const QString &fileName)
699 {
700  sender()->deleteLater();
701 
702  if (KMessageBox::questionYesNo(0,
703  i18n("<qt><b>Missing signature:</b><br />Key id: %1<br /><br />Do you want to import this key from a keyserver?</qt>", id),
704  fileName, KGuiItem(i18n("Import")), KGuiItem(i18n("Do Not Import"))) != KMessageBox::Yes)
705  return;
706 
707  KeyServer *ks = new KeyServer(this);
708 
709  connect(ks, SIGNAL(importFinished(QStringList)), SLOT(slotDownloadKeysFinished(QStringList)));
710  connect(ks, SIGNAL(importFailed()), ks, SLOT(deleteLater()));
711 
712  ks->startImport(QStringList(id), QString(),QLatin1String( qgetenv("http_proxy") ));
713 }
714 
715 void KgpgEditor::slotDownloadKeysFinished(QStringList ids)
716 {
717  m_parent->refreshKeys(ids);
718 
719  sender()->deleteLater();
720 }
721 
722 void
723 KgpgEditor::slotVerifyFinished(const QString &id, const QString &message)
724 {
725  sender()->deleteLater();
726 
727  QString showId;
728 
729  if (id.isEmpty())
730  showId = i18n("No signature found.");
731  else
732  showId = id;
733 
734  (void) new KgpgDetailedInfo(this, showId, message, QStringList(),
735  i18nc("Caption of message box", "Verification Finished"));
736 }
737 
738 void KgpgEditor::slotOptions()
739 {
740  m_parent->showOptions();
741 }
742 
743 void KgpgEditor::modified()
744 {
745  QString capt = m_docname.fileName();
746  if (m_emptytext) {
747  m_textchanged = !m_editor->toPlainText().isEmpty();
748  if (capt.isEmpty())
749  capt = i18n("Untitled");
750  } else if (!m_textchanged) {
751  m_textchanged = true;
752  }
753  setCaption(capt, m_textchanged);
754  m_editor->document()->setModified(m_textchanged);
755 }
756 
757 void KgpgEditor::slotUndoAvailable(const bool v)
758 {
759  m_editundo->setEnabled(v);
760 }
761 
762 void KgpgEditor::slotRedoAvailable(const bool v)
763 {
764  m_editredo->setEnabled(v);
765 }
766 
767 void KgpgEditor::slotCopyAvailable(const bool v)
768 {
769  m_editcopy->setEnabled(v);
770  m_editcut->setEnabled(v);
771 }
772 
773 void KgpgEditor::newText()
774 {
775  m_textchanged = false;
776  m_emptytext = true;
777  m_docname.clear();
778  setCaption(i18n("Untitled"), false);
779  slotResetEncoding(false);
780 }
781 
782 #include "kgpgeditor.moc"
QTextStream::setCodec
void setCodec(QTextCodec *codec)
KgpgEditor::m_editor
KgpgTextEdit *const m_editor
Definition: kgpgeditor.h:45
KGpgItemModel
Definition: kgpgitemmodel.h:44
KGpgSignText::AsciiArmored
output the data as printable ASCII as opposed to binary data
Definition: kgpgsigntext.h:37
KGpgDecrypt
decrypt the given text or files
Definition: kgpgdecrypt.h:29
QWidget
QString::append
QString & append(QChar ch)
kgpg.h
KgpgEditor::saveOptions
void saveOptions()
Definition: kgpgeditor.cpp:152
kgpgsigntext.h
KeyServer
Definition: keyservers.h:51
KeysManager::showOptions
void showOptions()
Definition: keysmanager.cpp:1173
QPrinter
QString::prepend
QString & prepend(QChar ch)
KGpgVerify
verify the signature of the given text or files
Definition: kgpgverify.h:31
QFont
QPointer
selectsecretkey.h
KDialog
KGpgTransaction::start
void start()
Start the operation.
Definition: kgpgtransaction.cpp:390
QString::chop
void chop(int n)
KgpgEditor::KgpgView
friend class KgpgView
Definition: kgpgeditor.h:36
QFile
QTextCodec::codecForLocale
QTextCodec * codecForLocale()
kgpgexternalactions.h
QTextStream
KgpgEditor::m_recentfiles
KRecentFilesAction * m_recentfiles
Definition: kgpgeditor.h:46
QString::clear
void clear()
QPaintDevice::width
int width() const
kgpgmd5widget.h
KGpgSettings::font
static QFont font()
Get Font.
Definition: kgpgsettings.h:858
KeysManager::refreshKeys
void refreshKeys(const QStringList &ids)
Definition: keysmanager.cpp:2177
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
kgpgeditor.h
KXmlGuiWindow
KGpgSettings::asciiArmor
static bool asciiArmor()
Get Use ASCII armored encryption.
Definition: kgpgsettings.h:174
KgpgDetailedInfo
Definition: detailedconsole.h:23
QPrintDialog
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
KgpgEditor::openEncryptedDocumentFile
void openEncryptedDocumentFile(const KUrl &url)
Definition: kgpgeditor.cpp:136
Md5Widget
Definition: kgpgmd5widget.h:22
QPainter
QString::isEmpty
bool isEmpty() const
KgpgEditor::~KgpgEditor
~KgpgEditor()
Definition: kgpgeditor.cpp:109
QVBoxLayout
KeysManager
Definition: keysmanager.h:66
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
KgpgTextEdit
Definition: kgpgtextedit.h:29
KeyServer::startImport
void startImport(const QStringList &keys, QString server=QString(), const QString &proxy=QString())
import the given keys
Definition: keyservers.cpp:110
kgpgdecrypt.h
QString
Qt::WFlags
typedef WFlags
QTextCodec
KgpgEditor::closeWindow
void closeWindow()
Definition: kgpgeditor.cpp:146
KGpgSettings::setFirstRun
static void setFirstRun(bool v)
Set Is the first time the application runs.
Definition: kgpgsettings.h:335
KgpgEditor::queryClose
bool queryClose()
Definition: kgpgeditor.cpp:225
KGpgSignText
sign the given text or files
Definition: kgpgsigntext.h:29
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QStringList
kgpgtextedit.h
sourceselect.h
KgpgEditor::initActions
void initActions()
Definition: kgpgeditor.cpp:158
QFile::close
virtual void close()
kgpgsettings.h
KGpgSettings::self
static KGpgSettings * self()
Definition: kgpgsettings.cpp:17
keyservers.h
kgpgkeyservergettransaction.h
KGpgSettings::recentFiles
static uint recentFiles()
Get The number of recently opened files shown in the editor menu.
Definition: kgpgsettings.h:687
QLatin1String
KgpgEditor::openDocumentFile
void openDocumentFile(const KUrl &url, const QString &encoding=QString())
Definition: kgpgeditor.cpp:114
KgpgEditor::saveBeforeClear
bool saveBeforeClear()
Definition: kgpgeditor.cpp:235
QTextCodec::codecForName
QTextCodec * codecForName(const QByteArray &name)
keysmanager.h
QTextCodec::canEncode
bool canEncode(QChar ch) const
kgpgverify.h
detailedconsole.h
QPaintDevice::height
int height() const
KgpgTextEdit::slotDroppedFile
void slotDroppedFile(const KUrl &url)
Definition: kgpgtextedit.cpp:77
QTextStream::readAll
QString readAll()
KgpgEditor::slotSetFont
void slotSetFont(QFont myFont)
Definition: kgpgeditor.cpp:141
QBoxLayout::setSpacing
void setSpacing(int spacing)
QString::toAscii
QByteArray toAscii() const
KgpgSelectSecretKey
Definition: selectsecretkey.h:23
KGpgSignText::DetachedSignature
save the signature in a separate file
Definition: kgpgsigntext.h:38
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