QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgssimplecopyexternalstorage.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssimplecopyexternalstorage.cpp
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#include "qgsapplication.h"
17#include "qgscopyfiletask.h"
19
20#include <QFileInfo>
21
23
24QgsSimpleCopyExternalStorageStoredContent::QgsSimpleCopyExternalStorageStoredContent( const QString &filePath, const QString &url, const QString &authcfg )
25{
26 Q_UNUSED( authcfg );
27
28 mCopyTask = new QgsCopyFileTask( filePath, url );
29
30 connect( mCopyTask, &QgsTask::taskCompleted, this, [this]
31 {
32 mUrl = mCopyTask->destination();
34 emit stored();
35 } );
36
37 connect( mCopyTask, &QgsTask::taskTerminated, this, [this]
38 {
39 reportError( mCopyTask->errorString() );
40 } );
41
42 connect( mCopyTask, &QgsTask::progressChanged, this, [this]( double progress )
43 {
44 emit progressChanged( progress );
45 } );
46}
47
48void QgsSimpleCopyExternalStorageStoredContent::store()
49{
52}
53
54void QgsSimpleCopyExternalStorageStoredContent::cancel()
55{
56 if ( !mCopyTask )
57 return;
58
59 disconnect( mCopyTask, &QgsTask::taskTerminated, this, nullptr );
60 connect( mCopyTask, &QgsTask::taskTerminated, this, [this]
61 {
63 emit canceled();
64 } );
65
66 mCopyTask->cancel();
67}
68
69QString QgsSimpleCopyExternalStorageStoredContent::url() const
70{
71 return mUrl;
72}
73
74QgsSimpleCopyExternalStorageFetchedContent::QgsSimpleCopyExternalStorageFetchedContent( const QString &filePath )
75 : mFilePath( filePath )
76{
77}
78
79void QgsSimpleCopyExternalStorageFetchedContent::fetch()
80{
81 // no fetching process, we read directly from its location
82 if ( !QFileInfo::exists( mFilePath ) )
83 {
84 reportError( tr( "File '%1' does not exist" ).arg( mFilePath ) );
85 }
86 else
87 {
89 mResultFilePath = mFilePath;
90 emit fetched();
91 }
92}
93
94QString QgsSimpleCopyExternalStorageFetchedContent::filePath() const
95{
96 return mResultFilePath;
97}
98
99QString QgsSimpleCopyExternalStorage::type() const
100{
101 return QStringLiteral( "SimpleCopy" );
102};
103
104QString QgsSimpleCopyExternalStorage::displayName() const
105{
106 return QObject::tr( "Simple copy" );
107};
108
109QgsExternalStorageStoredContent *QgsSimpleCopyExternalStorage::doStore( const QString &filePath, const QString &url, const QString &authcfg ) const
110{
111 return new QgsSimpleCopyExternalStorageStoredContent( filePath, url, authcfg );
112};
113
114QgsExternalStorageFetchedContent *QgsSimpleCopyExternalStorage::doFetch( const QString &url, const QString &authConfig ) const
115{
116 Q_UNUSED( authConfig );
117
118 return new QgsSimpleCopyExternalStorageFetchedContent( url );
119}
120
@ Canceled
Content fetching/storing has been canceled.
Definition qgis.h:1850
@ Running
Content fetching/storing is in progress.
Definition qgis.h:1847
@ Finished
Content fetching/storing is finished and successful.
Definition qgis.h:1848
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
Task to copy a file on disk.
Abstract base class for QgsExternalStorage fetched content.
Abstract base class for QgsExternalStorage stored content.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
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.
void taskTerminated()
Will be emitted by task if it has terminated for any reason other then completion (e....