File indexing completed on 2024-12-01 04:33:14

0001 /**************************************************************************
0002  *   Copyright (C) 2009-2011 Matthias Fuchs <mat69@gmx.net>                *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0018  ***************************************************************************/
0019 
0020 #ifndef KEY_DOWNLOADER_H
0021 #define KEY_DOWNLOADER_H
0022 
0023 #include <QMultiHash>
0024 #include <QObject>
0025 
0026 class KJob;
0027 class Signature;
0028 
0029 /**
0030  * @class KeyDownloader
0031  *
0032  * @short Class to download Keys
0033  */
0034 class KeyDownloader : public QObject
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     KeyDownloader(QObject *parent = nullptr);
0040 
0041     /**
0042      * @return true if KeyDownloader is valid, i.e. has QPGME support
0043      */
0044     bool isValid() const;
0045 
0046     /**
0047      * Searches for a key with fignerprint
0048      * @param fingerprint the fingerprint of the key that is searched
0049      * @param sig Signature to notify of successful downloads
0050      */
0051     void downloadKey(QString fingerprint, Signature *sig);
0052 
0053 private Q_SLOTS:
0054     /**
0055      * Parses the downloaded data and if it is a key tries to add it to GnuPG,
0056      * if it is not a key try a different server.
0057      */
0058     void slotDownloaded(KJob *job);
0059 
0060 private:
0061     /**
0062      * Searches for a key with fignerprint
0063      * @param fingerprint the fingerprint of the key that is searched
0064      * @param sig Signature to notify of successful downloads
0065      * @param mirrorFailed if true another mirror will be tried
0066      */
0067     void downloadKey(QString fingerprint, Signature *sig, bool mirrorFailed);
0068 
0069 private:
0070     QMultiHash<QString, Signature *> m_downloading;
0071     QHash<KJob *, QString> m_jobs;
0072     QMultiHash<QString, QString> m_triedMirrors;
0073 };
0074 
0075 #endif