File indexing completed on 2024-04-21 05:50:41

0001 /*
0002     SPDX-FileCopyrightText: 2008-2022 Rolf Eike Beer <kde@opensource.sf-tec.de>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "kgpgadduid.h"
0007 
0008 #include <KEmailAddress>
0009 
0010 KGpgAddUid::KGpgAddUid(QObject *parent, const QString &keyid, const QString &name, const QString &email, const QString &comment)
0011     : KGpgEditKeyTransaction(parent, keyid, QLatin1String("adduid"), false, true)
0012 {
0013     setName(name);
0014     setEmail(email);
0015     setComment(comment);
0016 }
0017 
0018 bool
0019 KGpgAddUid::preStart()
0020 {
0021     if (!KGpgEditKeyTransaction::preStart())
0022         return false;
0023 
0024     if (!m_email.isEmpty() && !KEmailAddress::isValidSimpleAddress(m_email)) {
0025         setSuccess(TS_INVALID_EMAIL);
0026         return false;
0027     }
0028 
0029     return true;
0030 }
0031 
0032 bool
0033 KGpgAddUid::nextLine(const QString &line)
0034 {
0035     if (!line.startsWith(QLatin1String("[GNUPG:] ")))
0036         return false;
0037 
0038     if (line.contains(QLatin1String( "GOOD_PASSPHRASE" ))) {
0039         setSuccess(TS_OK);
0040     } else if (line.contains(QLatin1String( "keygen.name" ))) {
0041         write(m_name.toUtf8());
0042     } else if (line.contains(QLatin1String( "keygen.email" ))) {
0043         write(m_email.toLatin1());
0044     } else if (line.contains(QLatin1String( "keygen.comment" ))) {
0045         write(m_comment.toUtf8());
0046     } else {
0047         return KGpgEditKeyTransaction::nextLine(line);
0048     }
0049 
0050     return false;
0051 }
0052 
0053 void
0054 KGpgAddUid::setName(const QString &name)
0055 {
0056     m_name = name;
0057 }
0058 
0059 void
0060 KGpgAddUid::setEmail(const QString &email)
0061 {
0062     m_email = email;
0063 }
0064 
0065 void
0066 KGpgAddUid::setComment(const QString &comment)
0067 {
0068     m_comment = comment;
0069 }