File indexing completed on 2024-04-21 05:50:42
0001 /* 0002 SPDX-FileCopyrightText: 2009, 2012 Rolf Eike Beer <kde@opensource.sf-tec.de> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "kgpgkeyservertransaction.h" 0007 0008 #include "gpgproc.h" 0009 0010 #include <KLocalizedString> 0011 0012 #include <QLabel> 0013 #include <QProgressDialog> 0014 0015 KGpgKeyserverTransaction::KGpgKeyserverTransaction(QObject *parent, const QString &keyserver, const bool withProgress, const QString &proxy) 0016 : KGpgTransaction(parent), 0017 m_progress(nullptr), 0018 m_showprogress(false) 0019 { 0020 addArgument(QLatin1String( "--status-fd=1" )); 0021 addArgument(QLatin1String( "--command-fd=0" )); 0022 addArgument(QLatin1String( "--keyserver-options" )); 0023 m_proxypos = addArgument(QString()); 0024 addArgument(QLatin1String( "--keyserver" )); 0025 m_keyserverpos = addArgument(QString()); 0026 0027 setKeyserver(keyserver); 0028 setProxy(proxy); 0029 0030 setProgressEnable(withProgress); 0031 } 0032 0033 KGpgKeyserverTransaction::~KGpgKeyserverTransaction() 0034 { 0035 delete m_progress; 0036 } 0037 0038 void 0039 KGpgKeyserverTransaction::setKeyserver(const QString &server) 0040 { 0041 m_keyserver = server; 0042 0043 replaceArgument(m_keyserverpos, server); 0044 } 0045 0046 void 0047 KGpgKeyserverTransaction::setProxy(const QString &proxy) 0048 { 0049 m_proxy = proxy; 0050 0051 replaceArgument(m_proxypos, proxy); 0052 } 0053 0054 void 0055 KGpgKeyserverTransaction::finish() 0056 { 0057 if (m_progress != nullptr) 0058 m_progress->hide(); 0059 } 0060 0061 bool 0062 KGpgKeyserverTransaction::preStart() 0063 { 0064 if (m_showprogress) { 0065 Q_ASSERT(m_progress != nullptr); 0066 m_progress->show(); 0067 } 0068 0069 return true; 0070 } 0071 0072 void 0073 KGpgKeyserverTransaction::slotAbort() 0074 { 0075 // no idea if this works on Windows, maybe we need ->kill() there 0076 getProcess()->terminate(); 0077 setSuccess(TS_USER_ABORTED); 0078 } 0079 0080 void 0081 KGpgKeyserverTransaction::setProgressEnable(const bool b) 0082 { 0083 m_showprogress = b; 0084 0085 if (b && (m_progress == nullptr)) { 0086 m_progress = new QProgressDialog(qobject_cast<QWidget *>(parent())); 0087 QLabel *label = new QLabel(i18n("<b>Connecting to the server...</b>")); 0088 m_progress->setWindowTitle(i18n("Keyserver")); 0089 m_progress->setLabel(label); 0090 0091 m_progress->hide(); 0092 m_progress->setModal(true); 0093 m_progress->setRange(0, 0); 0094 0095 connect(m_progress, &QProgressDialog::canceled, this, &KGpgKeyserverTransaction::slotAbort); 0096 } 0097 }