• 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
  • transactions
kgpgchangepass.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008,2009,2010,2011,2012,2013 Rolf Eike Beer <kde@opensource.sf-tec.de>
3  */
4 
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 
14 #include "kgpgchangepass.h"
15 
16 #include <KLocale>
17 
18 KGpgChangePass::KGpgChangePass(QObject *parent, const QString &keyid)
19  : KGpgTransaction(parent),
20  m_seenold(false)
21 {
22  addArgument(QLatin1String( "--status-fd=1" ));
23  addArgument(QLatin1String( "--command-fd=0" ));
24  addArgument(QLatin1String( "--edit-key" ));
25  addArgument(keyid);
26  addArgument(QLatin1String( "passwd" ));
27 }
28 
29 KGpgChangePass::~KGpgChangePass()
30 {
31 }
32 
33 bool
34 KGpgChangePass::preStart()
35 {
36  setSuccess(TS_MSG_SEQUENCE);
37 
38  return true;
39 }
40 
41 bool
42 KGpgChangePass::nextLine(const QString &line)
43 {
44  if (!line.startsWith(QLatin1String("[GNUPG:] ")))
45  return false;
46 
47  if (line.contains(QLatin1String( "keyedit.prompt" ))) {
48  if (m_seenold && (getSuccess() != TS_USER_ABORTED)) {
49  setSuccess(TS_OK);
50  write("save");
51  } else {
52  // some sort of error, we already set the error code
53  return true;
54  }
55  } else if (line.contains(QLatin1String( "GET_" ))) {
56  setSuccess(TS_MSG_SEQUENCE);
57  return true;
58  }
59 
60  return false;
61 }
62 
63 bool
64 KGpgChangePass::passphraseRequested()
65 {
66  const QString userIDs = getIdHints();
67 
68  if (!m_seenold) {
69  return askPassphrase(i18n("Enter old passphrase for <b>%1</b>", userIDs));
70  } else {
71  askNewPassphrase(i18n("<qt>Enter new passphrase for <b>%1</b><br />If you forget this passphrase all your encrypted files and messages will be inaccessible.</qt>", userIDs));
72  }
73 
74  return true;
75 }
76 
77 bool
78 KGpgChangePass::passphraseReceived()
79 {
80  m_seenold = true;
81  setSuccess(TS_MSG_SEQUENCE);
82  return false;
83 }
84 
85 #include "kgpgchangepass.moc"
KGpgChangePass::~KGpgChangePass
virtual ~KGpgChangePass()
Definition: kgpgchangepass.cpp:29
KGpgTransaction::getSuccess
int getSuccess() const
get the success value that will be returned with the done signal
Definition: kgpgtransaction.cpp:442
KGpgChangePass::nextLine
virtual bool nextLine(const QString &line)
Called for every line the gpg process writes.
Definition: kgpgchangepass.cpp:42
KGpgTransaction::addArgument
int addArgument(const QString &arg)
add a command line argument to gpg process
Definition: kgpgtransaction.cpp:562
KGpgTransaction::TS_OK
everything went fine
Definition: kgpgtransaction.h:60
KGpgChangePass::passphraseReceived
virtual bool passphraseReceived()
called when GnuPG accepted the passphrase
Definition: kgpgchangepass.cpp:78
KGpgTransaction::write
void write(const QByteArray &a, const bool lf=true)
write data to standard input of gpg process
Definition: kgpgtransaction.cpp:413
KGpgTransaction::askPassphrase
bool askPassphrase(const QString &message=QString())
ask user for passphrase
Definition: kgpgtransaction.cpp:623
KGpgChangePass::KGpgChangePass
KGpgChangePass(QObject *parent, const QString &keyid)
Definition: kgpgchangepass.cpp:18
KGpgChangePass::preStart
virtual bool preStart()
Called before the gpg process is started.
Definition: kgpgchangepass.cpp:34
QObject
KGpgTransaction::askNewPassphrase
void askNewPassphrase(const QString &text)
Ask user for passphrase and send it to gpg process.
Definition: kgpgtransaction.cpp:428
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KGpgTransaction::getIdHints
QString getIdHints() const
get string of all userid hints
Definition: kgpgtransaction.cpp:550
QString
KGpgTransaction::TS_MSG_SEQUENCE
unexpected sequence of GnuPG messages
Definition: kgpgtransaction.h:62
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
KGpgTransaction::TS_USER_ABORTED
the user aborted the transaction
Definition: kgpgtransaction.h:63
QLatin1String
KGpgTransaction::setSuccess
void setSuccess(const int v)
set the success value that will be returned with the done signal
Definition: kgpgtransaction.cpp:448
KGpgChangePass::passphraseRequested
virtual bool passphraseRequested()
called when GnuPG asks for a passphrase
Definition: kgpgchangepass.cpp:64
KGpgTransaction
Process one GnuPG operation.
Definition: kgpgtransaction.h:44
kgpgchangepass.h
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