1 /***************************************************************************
2   qgswebdavexternalstorage.h
3   --------------------------------------
4   Date                 : March 2021
5   Copyright            : (C) 2021 by Julien Cabieces
6   Email                : julien dot cabieces at oslandia dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef QGSWEBDAVEXTERNALSTORAGE_H
17 #define QGSWEBDAVEXTERNALSTORAGE_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgstaskmanager.h"
22 
23 #include "externalstorage/qgsexternalstorage.h"
24 
25 #include <QPointer>
26 #include <QUrl>
27 
28 class QgsFeedback;
29 class QgsWebDAVExternalStorageStoreTask;
30 class QgsFetchedContent;
31 
32 ///@cond PRIVATE
33 #define SIP_NO_FILE
34 
35 /**
36  * \ingroup core
37  * \brief External storage implementation using the protocol WebDAV.
38  *
39  * \since QGIS 3.22
40  */
41 class CORE_EXPORT QgsWebDAVExternalStorage : public QgsExternalStorage
42 {
43   public:
44 
45     QString type() const override;
46 
47     QString displayName() const override;
48 
49   protected:
50 
51     QgsExternalStorageStoredContent *doStore( const QString &filePath, const QString &url, const QString &authcfg = QString() ) const override;
52 
53     QgsExternalStorageFetchedContent *doFetch( const QString &url, const QString &authConfig = QString() ) const override;
54 };
55 
56 /**
57  * \ingroup core
58  * \brief Class for WebDAV stored content
59  *
60  * \since QGIS 3.22
61  */
62 class QgsWebDAVExternalStorageStoredContent  : public QgsExternalStorageStoredContent
63 {
64     Q_OBJECT
65 
66   public:
67 
68     QgsWebDAVExternalStorageStoredContent( const QString &filePath, const QString &url, const QString &authcfg = QString() );
69 
70     void cancel() override;
71 
72     QString url() const override;
73 
74     void store() override;
75 
76   private:
77 
78     QPointer<QgsWebDAVExternalStorageStoreTask> mUploadTask;
79     QString mUrl;
80 };
81 
82 /**
83  * \ingroup core
84  * \brief Class for WebDAV fetched content
85  *
86  * \since QGIS 3.22
87  */
88 class QgsWebDAVExternalStorageFetchedContent : public QgsExternalStorageFetchedContent
89 {
90     Q_OBJECT
91 
92   public:
93 
94     QgsWebDAVExternalStorageFetchedContent( QgsFetchedContent *fetchedContent );
95 
96     QString filePath() const override;
97 
98     void cancel() override;
99 
100     void fetch() override;
101 
102   private slots:
103 
104     void onFetched();
105 
106   private:
107 
108     QPointer<QgsFetchedContent> mFetchedContent;
109 };
110 
111 
112 /**
113  * \ingroup core
114  * \brief Task to store a file to a given WebDAV url
115  *
116  * \since QGIS 3.22
117  */
118 class QgsWebDAVExternalStorageStoreTask : public QgsTask
119 {
120     Q_OBJECT
121 
122   public:
123 
124     QgsWebDAVExternalStorageStoreTask( const QUrl &url, const QString &filePath, const QString &authCfg );
125 
126     bool run() override;
127 
128     void cancel() override;
129 
130     QString errorString() const;
131 
132   private:
133 
134     const QUrl mUrl;
135     const QString mFilePath;
136     const QString mAuthCfg;
137     std::unique_ptr<QgsFeedback> mFeedback;
138     QString mErrorString;
139 };
140 
141 
142 ///@endcond
143 #endif // QGSWEBDAVEXTERNALSTORAGE_H
144