File indexing completed on 2024-04-14 05:43:28

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 "kgpgaddphoto.h"
0007 
0008 #include <KLocalizedString>
0009 #include <KMessageBox>
0010 
0011 KGpgAddPhoto::KGpgAddPhoto(QObject *parent, const QString &keyid, const QString &imagepath)
0012     : KGpgEditKeyTransaction(parent, keyid, QLatin1String( "addphoto" ), false)
0013 {
0014     setImagePath(imagepath);
0015 }
0016 
0017 bool
0018 KGpgAddPhoto::nextLine(const QString &line)
0019 {
0020     if (!line.startsWith(QLatin1String("[GNUPG:] ")))
0021         return false;
0022 
0023     if (line.contains(QLatin1String( "GOOD_PASSPHRASE" ))) {
0024         setSuccess(TS_MSG_SEQUENCE);
0025     } else if (line.endsWith(QLatin1String("photoid.jpeg.add"))) {
0026         write(m_photourl.toUtf8());
0027         setSuccess(TS_OK);
0028     } else {
0029         return KGpgEditKeyTransaction::nextLine(line);
0030     }
0031 
0032     return false;
0033 }
0034 
0035 KGpgTransaction::ts_boolanswer KGpgAddPhoto::boolQuestion(const QString &line)
0036 {
0037     if (line == QLatin1String("photoid.jpeg.size")) {
0038         if (KMessageBox::questionTwoActions(nullptr, i18n("This image is very large. Use it anyway?"), QString(), KGuiItem(i18n("Use Anyway")), KGuiItem(i18n("Do Not Use"))) == KMessageBox::PrimaryAction) {
0039             return BA_YES;
0040         } else {
0041             setSuccess(TS_USER_ABORTED);
0042             return BA_NO;
0043         }
0044     }
0045 
0046     return BA_UNKNOWN;
0047 }
0048 
0049 void
0050 KGpgAddPhoto::setImagePath(const QString &photourl)
0051 {
0052     m_photourl = photourl;
0053 }