File indexing completed on 2024-05-12 15:50:04
0001 /* 0002 SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #ifndef KSYNTAXHIGHLIGHTING_DEFINITIONDOWNLOADER_H 0008 #define KSYNTAXHIGHLIGHTING_DEFINITIONDOWNLOADER_H 0009 0010 #include "ksyntaxhighlighting_export.h" 0011 0012 #include <QObject> 0013 #include <memory> 0014 0015 namespace KSyntaxHighlighting 0016 { 0017 class DefinitionDownloaderPrivate; 0018 class Repository; 0019 0020 /** 0021 * Helper class to download definition file updates. 0022 * 0023 * With the DefinitionDownloader you can download new and update existing 0024 * syntax highlighting definition files (xml files). 0025 * 0026 * An example that updates the highlighting Definition%s and prints the current 0027 * update progress to the console may look as follows: 0028 * 0029 * @code 0030 * auto downloader = new DefinitionDownloader(repo); // repo is a pointer to a Repository 0031 * 0032 * // print update progress to console 0033 * QObject::connect(downloader, &DefinitionDownloader::informationMessage, [](const QString &msg) { 0034 * std::cout << qPrintable(msg) << std::endl; 0035 * }); 0036 * 0037 * // connect to signal done to delete the downloader later 0038 * QObject::connect(downloader, &DefinitionDownloader::done, 0039 * downloader, &DefinitionDownloader::deleteLater); 0040 * downloader->start(); 0041 * @endcode 0042 * 0043 * @see Repository, Definition 0044 * @since 5.28 0045 */ 0046 class KSYNTAXHIGHLIGHTING_EXPORT DefinitionDownloader : public QObject 0047 { 0048 Q_OBJECT 0049 public: 0050 /** 0051 * Constructor. 0052 * The Repository @p repo is used as reference to compare the versions of 0053 * the existing Definition%s with the ones that are available online. 0054 * 0055 * Optionally, @p parent is a pointer to the owner of this instance. 0056 */ 0057 explicit DefinitionDownloader(Repository *repo, QObject *parent = nullptr); 0058 0059 /** 0060 * Destructor. 0061 */ 0062 ~DefinitionDownloader() override; 0063 0064 /** 0065 * Starts the update procedure. 0066 * Once no more updates are available (i.e. either the local definition files 0067 * are up-to-date, or all updates have been downloaded), the signal done() 0068 * is emitted. 0069 * 0070 * During the update process, the signal informationMessage() can be used 0071 * to display the current update progress to the user. 0072 * 0073 * @see done(), informationMessage() 0074 */ 0075 void start(); 0076 0077 Q_SIGNALS: 0078 /** 0079 * Prints the information about the current state of the definition files. 0080 * If all files are up-to-date, this signal is emitted informing you that 0081 * all highlighting files are up-to-date. If there are updates, this signal 0082 * is emitted for each update being downloaded. 0083 */ 0084 void informationMessage(const QString &msg); 0085 0086 /** 0087 * This signal is emitted when there are no pending downloads anymore. 0088 */ 0089 void done(); 0090 0091 private: 0092 std::unique_ptr<DefinitionDownloaderPrivate> d; 0093 }; 0094 } 0095 0096 #endif // KSYNTAXHIGHLIGHTING_DEFINITIONDOWNLOADER_H