1 /*
2 SPDX-FileCopyrightText: 2008, 2009, 2012 Rolf Eike Beer <kde@opensource.sf-tec.de>
3 SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6 #include "kgpgaddphoto.h"
7
8 #include <KLocalizedString>
9 #include <KMessageBox>
10
KGpgAddPhoto(QObject * parent,const QString & keyid,const QString & imagepath)11 KGpgAddPhoto::KGpgAddPhoto(QObject *parent, const QString &keyid, const QString &imagepath)
12 : KGpgEditKeyTransaction(parent, keyid, QLatin1String( "addphoto" ), false)
13 {
14 setImagePath(imagepath);
15 }
16
~KGpgAddPhoto()17 KGpgAddPhoto::~KGpgAddPhoto()
18 {
19 }
20
21 bool
nextLine(const QString & line)22 KGpgAddPhoto::nextLine(const QString &line)
23 {
24 if (!line.startsWith(QLatin1String("[GNUPG:] ")))
25 return false;
26
27 if (line.contains(QLatin1String( "GOOD_PASSPHRASE" ))) {
28 setSuccess(TS_MSG_SEQUENCE);
29 } else if (line.endsWith(QLatin1String("photoid.jpeg.add"))) {
30 write(m_photourl.toUtf8());
31 setSuccess(TS_OK);
32 } else {
33 return KGpgEditKeyTransaction::nextLine(line);
34 }
35
36 return false;
37 }
38
boolQuestion(const QString & line)39 KGpgTransaction::ts_boolanswer KGpgAddPhoto::boolQuestion(const QString &line)
40 {
41 if (line == QLatin1String("photoid.jpeg.size")) {
42 if (KMessageBox::questionYesNo(nullptr, i18n("This image is very large. Use it anyway?"), QString(), KGuiItem(i18n("Use Anyway")), KGuiItem(i18n("Do Not Use"))) == KMessageBox::Yes) {
43 return BA_YES;
44 } else {
45 setSuccess(TS_USER_ABORTED);
46 return BA_NO;
47 }
48 }
49
50 return BA_UNKNOWN;
51 }
52
53 void
setImagePath(const QString & photourl)54 KGpgAddPhoto::setImagePath(const QString &photourl)
55 {
56 m_photourl = photourl;
57 }
58