30 QgsWebDAVExternalStorageStoreTask::QgsWebDAVExternalStorageStoreTask(
const QUrl &url,
const QString &filePath,
const QString &authCfg )
31 :
QgsTask( tr(
"Storing %1" ).arg( QFileInfo( filePath ).baseName() ) )
33 , mFilePath( filePath )
39 bool QgsWebDAVExternalStorageStoreTask::run()
44 QNetworkRequest req( mUrl );
47 QFile *f =
new QFile( mFilePath );
48 f->open( QIODevice::ReadOnly );
52 if ( !isCanceled() && bytesTotal > 0 )
54 const int progress = ( bytesReceived * 100 ) / bytesTotal;
55 setProgress( progress );
69 void QgsWebDAVExternalStorageStoreTask::cancel()
75 QString QgsWebDAVExternalStorageStoreTask::errorString()
const
80 QgsWebDAVExternalStorageStoredContent::QgsWebDAVExternalStorageStoredContent(
const QString &filePath,
const QString &url,
const QString &authcfg )
82 QString storageUrl = url;
83 if ( storageUrl.endsWith(
"/" ) )
84 storageUrl.append( QFileInfo( filePath ).fileName() );
86 mUploadTask =
new QgsWebDAVExternalStorageStoreTask( storageUrl, filePath, authcfg );
97 reportError( mUploadTask->errorString() );
102 emit progressChanged( progress );
106 void QgsWebDAVExternalStorageStoredContent::store()
113 void QgsWebDAVExternalStorageStoredContent::cancel()
125 mUploadTask->cancel();
128 QString QgsWebDAVExternalStorageStoredContent::url()
const
134 QgsWebDAVExternalStorageFetchedContent::QgsWebDAVExternalStorageFetchedContent(
QgsFetchedContent *fetchedContent )
135 : mFetchedContent( fetchedContent )
141 reportError( errorMsg );
145 void QgsWebDAVExternalStorageFetchedContent::fetch()
147 if ( !mFetchedContent )
151 mFetchedContent->download();
161 QString QgsWebDAVExternalStorageFetchedContent::filePath()
const
163 return mFetchedContent ? mFetchedContent->filePath() : QString();
166 void QgsWebDAVExternalStorageFetchedContent::onFetched()
168 if ( !mFetchedContent )
178 void QgsWebDAVExternalStorageFetchedContent::cancel()
180 mFetchedContent->cancel();
183 QString QgsWebDAVExternalStorage::type()
const
185 return QStringLiteral(
"WebDAV" );
188 QString QgsWebDAVExternalStorage::displayName()
const
190 return QObject::tr(
"WebDAV Storage" );
195 return new QgsWebDAVExternalStorageStoredContent( filePath, url, authcfg );
202 return new QgsWebDAVExternalStorageFetchedContent( fetchedContent );
@ Canceled
Content fetching/storing has been canceled.
@ Running
Content fetching/storing is in progress.
@ Finished
Content fetching/storing is finished and successful.
static QgsNetworkContentFetcherRegistry * networkContentFetcherRegistry()
Returns the application's network content registry used for fetching temporary files during QGIS sess...
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
A thread safe class for performing blocking (sync) network requests, with full support for QGIS proxy...
ErrorCode put(QNetworkRequest &request, QIODevice *data, QgsFeedback *feedback=nullptr)
Performs a "put" operation on the specified request, using the given data.
void setAuthCfg(const QString &authCfg)
Sets the authentication config id which should be used during the request.
QString errorMessage() const
Returns the error message string, after a get() or post() request has been made.
void uploadProgress(qint64, qint64)
Emitted when when data are sent during a request.
@ NoError
No error was encountered.
Class for QgsExternalStorage fetched content.
Class for QgsExternalStorage stored content.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
FetchedContent holds useful information about a network content being fetched.
void errorOccurred(QNetworkReply::NetworkError code, const QString &errorMsg)
Emitted when an error with code error occurred while processing the request errorMsg is a textual des...
@ Finished
Download finished and successful.
void fetched()
Emitted when the file is fetched and accessible.
QgsFetchedContent * fetch(const QString &url, Qgis::ActionStart fetchingMode=Qgis::ActionStart::Deferred, const QString &authConfig=QString())
Initialize a download for the given URL.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Abstract base class for long running background tasks.
void taskCompleted()
Will be emitted by task to indicate its successful completion.
void progressChanged(double progress)
Will be emitted by task when its progress changes.
virtual void cancel()
Notifies the task that it should terminate.
void taskTerminated()
Will be emitted by task if it has terminated for any reason other then completion (e....
#define QgsSetRequestInitiatorClass(request, _class)