Alkimia API

alkdownloadengine.h
1/*
2 SPDX-FileCopyrightText: 2024 Ralf Habacker ralf.habacker @freenet.de
3
4 This file is part of libalkimia.
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7*/
8
9#ifndef ALKDOWNLOADENGINE_H
10#define ALKDOWNLOADENGINE_H
11
12#include <alkimia/alk_export.h>
13
14#include <QMetaType>
15#include <QObject>
16#include <QUrl>
17
18class AlkWebPage;
19
20/**
21 * The DownloadEngine class provides a general interface for
22 * the supported implementation for downloading page content
23 */
24class ALK_EXPORT AlkDownloadEngine : public QObject
25{
26 Q_OBJECT
27public:
28 enum Type {
29 QtEngine,
30 WebKitEngine,
31 WebEngine,
32 DefaultEngine, ///< Use Qt network support
33 JavaScriptEngine, ///< Use an HTML engine with Javascript support
34 JavaScriptEngineCSS, ///< Use an HTML engine with Javascript support, @see AlkDownloadEngine::finishedPage for details
35 };
36
37 /**
38 * Constructor
39 * @param parent Parent object
40 */
41 explicit AlkDownloadEngine(QObject *parent = nullptr);
42
43 /**
44 * Destructor
45 */
47
48 /**
49 * Specifies a custom instance of the HTML engine that is used to download content.
50 * If this method is not called, an internal instance is used.
51 * @param webPage Instance of HTML engine
52 */
53 void setWebPage(AlkWebPage *webPage);
54
55 /**
56 * Download content from a URL using the engine specified by the \p type.
57 * This method blocks until the download is complete. The status and result
58 * of the download is returned via the available signals.
59 * @param url Url to download
60 * @param type Type of engine to use for downloading
61 * @param timeout Timeout for fetching the content [msec]
62 * @return true - fetching succeded
63 * @return false - fetching failed
64 */
65 bool downloadUrl(const QUrl &url, Type type);
66
67 /**
68 * Set specific language to be accepted for the download.
69 * The supported format of the specified language is described at
70 * https://www.rfc-editor.org/rfc/rfc9110.html#field.accept-language.
71 * @param language String with the accepted language
72 */
73 void setAcceptedLanguage(const QString &language);
74
75 /**
76 * Set timeout for download operation
77 * A \p timeout value of -1 disables timeout support
78 * @param timeout Timeout in milliseconds
79 */
80 void setTimeout(int timeout = -1);
81
82 /**
83 * Return timeout for download operation
84 * @return timeout in milliseconds
85 */
86 int timeout();
87
89 /**
90 * Emitted in case of of errors
91 * @param url The url from which the error has been recognzied
92 * @param message Error message
93 */
94 void error(const QUrl &url, const QString &message);
95
96 /**
97 * Is emitted if the type parameter of AlkDownloadEngine::downloadUrl()
98 * is AlkDownloadEngine::DefaultEngine or AlkDownloadEngine::JavaScriptEngine.
99 * @param url The url from which the data is returned
100 * @param data The returned data
101 */
102 void finished(const QUrl &url, const QString &data);
103
104 /**
105 * Is emitted if the type parameter of AlkDownloadEngine::downloadUrl()
106 * is JavaScriptEngineCSS.
107 * @param url The url from which the data is returned
108 * @param page The page instance containing the returned data
109 */
110 void finishedPage(const QUrl &url, AlkWebPage *page);
111
112 /**
113 * Is emitted if the download has been started
114 * @param url The associated url
115 */
116 void started(const QUrl &url);
117
118 /**
119 * Is emitted if the url has been redirected
120 * @param url The associated url
121 * @param newurl The redirected url
122 */
123 void redirected(const QUrl &url, const QUrl &newUrl);
124
125 /**
126 * Is emitted if the download request has been timed out
127 * @param url The url which has been timeout out
128 */
129 void timeout(const QUrl &url);
130
131private:
132 class Private;
133 Private *d;
134};
135
136Q_DECLARE_METATYPE(AlkDownloadEngine::Type)
137
138#endif // ALKDOWNLOADENGINE_H
The DownloadEngine class provides a general interface for the supported implementation for downloadin...
@ JavaScriptEngine
Use an HTML engine with Javascript support.
@ JavaScriptEngineCSS
Use an HTML engine with Javascript support,.
@ DefaultEngine
Use Qt network support.
void started(const QUrl &url)
Is emitted if the download has been started.
void error(const QUrl &url, const QString &message)
Emitted in case of of errors.
void finishedPage(const QUrl &url, AlkWebPage *page)
Is emitted if the type parameter of AlkDownloadEngine::downloadUrl() is JavaScriptEngineCSS.
void redirected(const QUrl &url, const QUrl &newUrl)
Is emitted if the url has been redirected.
void finished(const QUrl &url, const QString &data)
Is emitted if the type parameter of AlkDownloadEngine::downloadUrl() is AlkDownloadEngine::DefaultEng...
void timeout(const QUrl &url)
Is emitted if the download request has been timed out.
The AlkWebPage class provides an object to load and view web documents to provide functionality like ...
Definition alkwebpage.h:100
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.