1 | /* |
2 | SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org> |
3 | |
4 | SPDX-License-Identifier: MIT |
5 | */ |
6 | |
7 | #ifndef KSYNTAXHIGHLIGHTING_DEFINITIONDOWNLOADER_H |
8 | #define KSYNTAXHIGHLIGHTING_DEFINITIONDOWNLOADER_H |
9 | |
10 | #include "ksyntaxhighlighting_export.h" |
11 | |
12 | #include <QObject> |
13 | #include <memory> |
14 | |
15 | namespace KSyntaxHighlighting |
16 | { |
17 | class DefinitionDownloaderPrivate; |
18 | class Repository; |
19 | |
20 | /*! |
21 | * \class KSyntaxHighlighting::DefinitionDownloader |
22 | * \inheaderfile KSyntaxHighlighting/DefinitionDownloader |
23 | * \inmodule KSyntaxHighlighting |
24 | * |
25 | * \brief Helper class to download definition file updates. |
26 | * |
27 | * With the DefinitionDownloader you can download new and update existing |
28 | * syntax highlighting definition files (xml files). |
29 | * |
30 | * An example that updates the highlighting Definition%s and prints the current |
31 | * update progress to the console may look as follows: |
32 | * |
33 | * \code |
34 | * auto downloader = new DefinitionDownloader(repo); // repo is a pointer to a Repository |
35 | * |
36 | * // print update progress to console |
37 | * QObject::connect(downloader, &DefinitionDownloader::informationMessage, [](const QString &msg) { |
38 | * std::cout << qPrintable(msg) << std::endl; |
39 | * }); |
40 | * |
41 | * // connect to signal done to delete the downloader later |
42 | * QObject::connect(downloader, &DefinitionDownloader::done, |
43 | * downloader, &DefinitionDownloader::deleteLater); |
44 | * downloader->start(); |
45 | * \endcode |
46 | * |
47 | * \sa Repository, Definition |
48 | * \since 5.28 |
49 | */ |
50 | class KSYNTAXHIGHLIGHTING_EXPORT DefinitionDownloader : public QObject |
51 | { |
52 | Q_OBJECT |
53 | public: |
54 | /*! |
55 | * Constructor. |
56 | * The Repository \a repo is used as reference to compare the versions of |
57 | * the existing Definition%s with the ones that are available online. |
58 | * |
59 | * Optionally, \a parent is a pointer to the owner of this instance. |
60 | */ |
61 | explicit DefinitionDownloader(Repository *repo, QObject *parent = nullptr); |
62 | |
63 | ~DefinitionDownloader() override; |
64 | |
65 | /*! |
66 | * Starts the update procedure. |
67 | * Once no more updates are available (i.e. either the local definition files |
68 | * are up-to-date, or all updates have been downloaded), the signal done() |
69 | * is emitted. |
70 | * |
71 | * During the update process, the signal informationMessage() can be used |
72 | * to display the current update progress to the user. |
73 | * |
74 | * \sa done(), informationMessage() |
75 | */ |
76 | void start(); |
77 | |
78 | Q_SIGNALS: |
79 | /*! |
80 | * Prints the information about the current state of the definition files. |
81 | * If all files are up-to-date, this signal is emitted informing you that |
82 | * all highlighting files are up-to-date. If there are updates, this signal |
83 | * is emitted for each update being downloaded. |
84 | */ |
85 | void informationMessage(const QString &msg); |
86 | |
87 | /*! |
88 | * This signal is emitted when there are no pending downloads anymore. |
89 | */ |
90 | void done(); |
91 | |
92 | private: |
93 | std::unique_ptr<DefinitionDownloaderPrivate> d; |
94 | }; |
95 | } |
96 | |
97 | #endif // KSYNTAXHIGHLIGHTING_DEFINITIONDOWNLOADER_H |
98 | |