29 #include <KMessageBox>
33 #include <QTextStream>
35 using namespace KgpgCore;
39 const QString tmp(name.simplified() + QLatin1Char(
' ' ));
40 QFile qfile(configfile);
42 if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
43 QTextStream t(&qfile);
45 QString result(t.readLine().simplified());
46 if (result.startsWith(tmp)) {
47 result = result.mid(tmp.length()).simplified();
48 return result.section(QLatin1Char(
' ' ), 0, 0);
61 if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
62 const QString temp(name + QLatin1Char(
' ' ));
65 QTextStream t(&qfile);
68 QString result = t.readLine();
69 if (result.simplified().startsWith(temp)) {
71 result = temp + QLatin1Char(
' ' ) + value;
77 texttowrite += result + QLatin1Char(
'\n' );
81 if ((!found) && (!value.isEmpty()))
82 texttowrite += QLatin1Char(
'\n' ) + temp + QLatin1Char(
' ' ) + value;
84 if (qfile.open(QIODevice::WriteOnly)) {
85 QTextStream t(&qfile);
94 QFile qfile(configfile);
95 if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
96 QTextStream t(&qfile);
98 if (t.readLine().simplified().startsWith(name))
110 if (qfile.open(QIODevice::ReadOnly) && (qfile.exists())) {
113 QTextStream t(&qfile);
116 QString result(t.readLine());
118 if (result.simplified().startsWith(name)) {
127 texttowrite += result + QLatin1Char(
'\n' );
131 if ((!found) && (enable))
134 if (qfile.open(QIODevice::WriteOnly)) {
135 QTextStream t(&qfile);
153 unsigned int idIndex = 0;
157 while ((items = p.
readln(lsp)) >= 0) {
158 if ((lsp.at(0) == QLatin1String(
"pub" )) && (items >= 10)) {
159 KgpgSubKeyType subtype;
160 KgpgSubKeyType keytype;
163 const QString &caps = lsp.at(11);
165 enabled = !caps.contains(QLatin1Char(
'D'), Qt::CaseSensitive);
173 QDateTime::fromTime_t(lsp.at(5).toUInt()));
175 publickey = &publiclistkeys.last();
179 if (lsp.at(6).isEmpty())
182 publickey->
setExpiration(QDateTime::fromTime_t(lsp.at(6).toUInt()));
187 }
else if (publickey && (lsp.at(0) == QLatin1String(
"fpr" )) && (items >= 10)) {
188 const QString fingervalue(lsp.at(9));
191 }
else if (publickey && (lsp.at(0) == QLatin1String(
"sub" )) && (items >= 7)) {
192 KgpgSubKeyType subtype;
198 Convert::toAlgo(lsp.at(3).toInt()), subtype, QDateTime::fromTime_t(lsp.at(5).toUInt()));
204 sub.setValid(!lsp.at(11).contains(QLatin1Char(
'D' )));
206 if (lsp.at(6).isEmpty())
207 sub.setExpiration(QDateTime());
209 sub.setExpiration(QDateTime::fromTime_t(lsp.at(6).toUInt()));
211 publickey->
subList()->append(sub);
212 if (readNode == NULL)
216 }
else if (publickey && (lsp.at(0) == QLatin1String(
"uat" ))) {
218 if (readNode != NULL) {
219 currentSNode =
new KGpgUatNode(readNode, idIndex, lsp);
221 }
else if (publickey && (lsp.at(0) == QLatin1String(
"uid" )) && (items >= 10)) {
223 QString fullname(lsp.at(9));
225 if (fullname.contains(QLatin1Char(
'<' )) ) {
228 if (fullname.contains(QLatin1Char(
')' )) )
229 kmail = kmail.section(QLatin1Char(
')' ), 1);
231 kmail = kmail.section(QLatin1Char(
'<' ), 1);
232 kmail.truncate(kmail.length() - 1);
234 if (kmail.contains(QLatin1Char(
'<' ))) {
236 kmail = kmail.replace(QLatin1Char(
'>' ), QLatin1Char(
';' ));
237 kmail.remove(QLatin1Char(
'<' ));
241 QString kname(fullname.section( QLatin1String(
" <" ), 0, 0));
243 if (fullname.contains(QLatin1Char(
'(' )) ) {
244 kname = kname.section( QLatin1String(
" (" ), 0, 0);
245 comment = fullname.section(QLatin1Char(
'(' ), 1, 1);
246 comment = comment.section(QLatin1Char(
')' ), 0, 0);
254 currentSNode = readNode;
257 if (readNode != NULL) {
258 currentSNode =
new KGpgUidNode(readNode, idIndex, lsp);
261 }
else if (publickey && ((lsp.at(0) == QLatin1String(
"sig" )) || (lsp.at(0) == QLatin1String(
"rev" ))) && (items >= 11)) {
263 const QString
signature = lsp.join(QLatin1String(
":"));
265 if (currentSNode != NULL)
268 log += lsp.join(QString(QLatin1Char(
':' ))) + QLatin1Char(
'\n' );
272 if (p.exitCode() != 0) {
273 KMessageBox::detailedError(NULL, i18n(
"An error occurred while scanning your keyring"), log);
277 return publiclistkeys;
284 QLatin1String(
"--with-colons") <<
285 QLatin1String(
"--with-fingerprint") <<
286 QLatin1String(
"--fixed-list-mode") <<
287 QLatin1String(
"--list-keys") <<
290 process.setOutputChannelMode(KProcess::MergedChannels);
293 process.waitForFinished(-1);
301 QLatin1String(
"--with-colons") <<
302 QLatin1String(
"--with-fingerprint") <<
303 QLatin1String(
"--fixed-list-mode") <<
304 QLatin1String(
"--list-sigs") <<
307 process.setOutputChannelMode(KProcess::MergedChannels);
310 process.waitForFinished(-1);
324 while ( (items = p.
readln(lsp)) >= 0 ) {
325 if ((lsp.at(0) == QLatin1String(
"sec" )) && (items >= 10)) {
326 KgpgSubKeyType subtype;
327 KgpgSubKeyType keytype;
330 const QString &caps = lsp.at(11);
338 QDateTime::fromTime_t(lsp.at(5).toUInt()));
340 secretkey = &result.last();
344 if (lsp.at(6).isEmpty())
347 secretkey->
setExpiration(QDateTime::fromTime_t(lsp.at(6).toUInt()));
349 }
else if ((lsp.at(0) == QLatin1String(
"uid" )) && (items >= 10)) {
355 const QString fullname(lsp.at(9));
356 if (fullname.contains(QLatin1Char(
'<' ) )) {
357 QString kmail(fullname);
359 if (fullname.contains(QLatin1Char(
')' ) ))
360 kmail = kmail.section(QLatin1Char(
')' ), 1);
362 kmail = kmail.section(QLatin1Char(
'<' ), 1);
363 kmail.truncate(kmail.length() - 1);
365 if (kmail.contains(QLatin1Char(
'<' ) )) {
366 kmail = kmail.replace(QLatin1Char(
'>' ), QLatin1Char(
';' ));
367 kmail.remove(QLatin1Char(
'<' ));
375 QString kname(fullname.section( QLatin1String(
" <" ), 0, 0));
376 if (fullname.contains(QLatin1Char(
'(' ) )) {
377 kname = kname.section( QLatin1String(
" (" ), 0, 0);
378 QString comment = fullname.section(QLatin1Char(
'(' ), 1, 1);
379 comment = comment.section(QLatin1Char(
')' ), 0, 0);
386 }
else if ((lsp.at(0) == QLatin1String(
"fpr" )) && (items >= 10)) {
398 QLatin1String(
"--with-colons") <<
399 QLatin1String(
"--list-secret-keys") <<
400 QLatin1String(
"--with-fingerprint") <<
401 QLatin1String(
"--fixed-list-mode") <<
405 process.waitForFinished(-1);
411 #include "kgpginterface.moc"
void setName(const QString &name)
A interface to GnuPG handling UTF8 recoding correctly.
void setFingerprint(const QString &fingerprint)
void setGpgBoolSetting(const QString &name, const bool enable, const QString &url)
int readln(QString &line, const bool colons=false)
Reads a line of text (excluding '\n').
virtual QString getId() const
bool getGpgBoolSetting(const QString &name, const QString &configfile)
KgpgKeyTrust toTrust(const QChar &c)
void setEmail(const QString &email)
void setValid(const bool valid)
void setGpgSetting(const QString &name, const QString &value, const QString &url)
void setComment(const QString &comment)
A public key with or without corresponding secret key.
void setExpiration(const QDateTime &date)
void start()
Starts the process.
KgpgKeyOwnerTrust toOwnerTrust(const QChar &c)
void readSignatures(KGpgKeyNode *node)
KgpgCore::KgpgKeyList readPublicKeys(const QStringList &ids=QStringList())
KgpgSubKeyType toSubType(const QString &capString, bool upper)
parse the GnuPG capabilities field
a subkey of a public key or key pair
KgpgCore::KgpgKeyList readSecretKeys(const QStringList &ids=QStringList())
void setOwnerTrust(const KgpgKeyOwnerTrust &owtrust)
A user id of a public key or key pair.
A signature to another key object.
static KgpgCore::KgpgKeyList readSecretKeysProcess(GPGProc &p)
static KgpgCore::KgpgKeyList readPublicKeysProcess(GPGProc &p, KGpgKeyNode *readNode)
void setSecret(const bool secret)
KgpgKeyAlgo toAlgo(const uint v)
An object that may have KGpgSignNode children.
QString getGpgSetting(const QString &name, const QString &configfile)
KgpgKeySubListPtr subList() const