File indexing completed on 2024-05-19 05:05:45
0001 /*************************************************************************** 0002 * SPDX-License-Identifier: GPL-2.0-or-later 0003 * * 0004 * SPDX-FileCopyrightText: 2004-2019 Thomas Fischer <fischer@unix-ag.uni-kl.de> 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, see <https://www.gnu.org/licenses/>. * 0018 ***************************************************************************/ 0019 0020 #ifndef KBIBTEX_NETWORKING_FINDPDF_H 0021 #define KBIBTEX_NETWORKING_FINDPDF_H 0022 0023 #include "kbibtexnetworking_export.h" 0024 0025 #include <QObject> 0026 #include <QList> 0027 #include <QSet> 0028 #include <QUrl> 0029 0030 #include <Entry> 0031 0032 class QNetworkAccessManager; 0033 class QNetworkReply; 0034 class QTemporaryFile; 0035 0036 /** 0037 * Search known Internet resources (search engines) for PDF files 0038 * matching a given bibliography entry. 0039 * 0040 * @author Thomas Fischer <fischer@unix-ag.uni-kl.de> 0041 */ 0042 class KBIBTEXNETWORKING_EXPORT FindPDF : public QObject 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 /// Used in a later stage (user interface, @see FindPDFUI); 0048 /// tells the system if ... 0049 enum class DownloadMode { 0050 No = 0, ///< Ignore this result item (no PDF file downloading) 0051 PDFfile = 1, ///< Download and store this PDF file in a user-specified location 0052 URLonly = 2 ///< Keep only the URL of the PDF; this URL will be inserted in the bib entry 0053 }; 0054 0055 /// Structure to store data about every found PDF (potential search hit) 0056 typedef struct { 0057 QUrl url; ///< Where has this PDF been found? 0058 QString textPreview; ///< Text extracted from the PDF file 0059 QTemporaryFile *tempFilename; ///< Local temporary copy 0060 float relevance; /// Assessment of relevance (useful for sorting results) 0061 DownloadMode downloadMode; /// User's preference what to do with this hit (default is NoDownload) 0062 } ResultItem; 0063 0064 explicit FindPDF(QObject *parent = nullptr); 0065 ~FindPDF() override; 0066 0067 /** 0068 * Initiate a search for PDF files matching a given entry. 0069 * 0070 * @param entry entry to search PDF files for 0071 * @return @c true if the search could be started @c false if another search is still running 0072 */ 0073 bool search(const Entry &entry); 0074 0075 /** 0076 * Once a search has been complete (signal @see finished), 0077 * this function allows to retrieve the collected results 0078 * @return @c After a search, list of results, @c before or during a search, an empty list 0079 */ 0080 QList<ResultItem> results(); 0081 0082 Q_SIGNALS: 0083 /** 0084 * A search initiated by @see search has been finished. 0085 */ 0086 void finished(); 0087 0088 /** 0089 * Some update on the ongoing search. 0090 * Just of eye candy, can be safely ignored if no visualization of progress is possible. 0091 * 0092 * @param visitedPages how many web pages have been visited 0093 * @param runningJobs how many download/search operations are running in parallel 0094 * @param foundDocuments how many PDF files have been found 0095 */ 0096 void progress(int visitedPages, int runningJobs, int foundDocuments); 0097 0098 public Q_SLOTS: 0099 /** 0100 * Abort any running downloads. 0101 */ 0102 void abort(); 0103 0104 private Q_SLOTS: 0105 void downloadFinished(); 0106 0107 private: 0108 class Private; 0109 Private *const d; 0110 }; 0111 0112 #endif // KBIBTEX_NETWORKING_FINDPDF_H