-
Notifications
You must be signed in to change notification settings - Fork 56
/
idownload.h
135 lines (120 loc) · 3.59 KB
/
idownload.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**********************************************************************
* LeechCraft - modular cross-platform feature rich internet client.
* Copyright (C) 2006-2014 Georg Rudoy
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
**********************************************************************/
#pragma once
#include <QUrl>
#include <QtPlugin>
#include <util/sll/eitherfwd.h>
#include "structures.h"
template<typename>
class QFuture;
struct EntityTestHandleResult;
/** @brief Common interface for all the downloaders.
*
* Plugins which provide downloading capabilities and want to be visible
* by LeechCraft and other plugins as download providers should
* implement this interface.
*
* Plugins implementing this interface are expected to have following
* signals:
* - jobFinished (int id)
* Indicates that a job with a given id has finished.
* - jobFinished (int id)
* Indicates that a job with a given id has been removed.
* - handleJobError (int id, IDownload::Error error)
* Indicates that an error occured while downloading a job with the
* given id.
*
* In order to obtain IDs for the tasks plugins are expected to use
* ICoreProxy::GetID() in order to avoid name clashes.
*
* @sa IJobHolder, IEntityHandler
*/
class Q_DECL_EXPORT IDownload
{
public:
struct Error
{
enum class Type
{
Unknown,
NoError,
NotFound,
Gone,
AccessDenied,
AuthRequired,
ProtocolError,
NetworkError,
ContentError,
ProxyError,
ServerError,
LocalError,
UserCanceled
} Type_;
QString Message_;
bool operator== (const Error& other) const
{
return Type_ == other.Type_ && Message_ == other.Message_;
}
};
struct Success {};
using Result = LC::Util::Either<Error, Success>;
/** @brief Returns download speed.
*
* Returns summed up download speed of the plugin. The value is
* primarily used in the interface as there are no ways of
* controlling of bandwidth's usage of a particular plugin.
*
* @return Download speed in bytes.
*
* @sa GetUploadSpeed
*/
virtual qint64 GetDownloadSpeed () const = 0;
/** @brief Returns upload speed.
*
* Returns summed up upload speed of the plugin. The value is
* primarily used in the interface as there are no ways of
* controlling of bandwidth's usage of a particular plugin.
*
* @return Upload speed in bytes.
*
* @sa GetDownloadSpeed
*/
virtual qint64 GetUploadSpeed () const = 0;
/** @brief Returns whether plugin can handle given entity.
*
* This function is used to query every loaded plugin providing the
* IDownload interface whether it could handle the entity entered by
* user or generated automatically with given task parameters.
* Entity could be anything from file name to URL to all kinds of
* hashes like Magnet links.
*
* @param[in] entity A Entity structure.
* @return The result of the test whether the \em entity can be
* handled.
*
* @sa AddJob
* @sa LC::Entity
*/
virtual EntityTestHandleResult CouldDownload (const LC::Entity& entity) const = 0;
/** @brief Adds the job with given parameters.
*
* Adds the job to the downloader and returns the ID of the newly
* added job back to identify it.
*
* @param[in] entity A Entity structure.
* @return ID of the job for the other plugins to use.
*
* @sa LC::Entity
*/
virtual QFuture<Result> AddJob (LC::Entity entity) = 0;
/** @brief Virtual destructor.
*/
virtual ~IDownload () {}
};
Q_DECLARE_INTERFACE (IDownload, "org.Deviant.LeechCraft.IDownload/1.0")
Q_DECLARE_METATYPE (QList<QUrl>)