QGIS API Documentation 3.99.0-Master (357b655ed83)
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#include <QString>
22
23using namespace Qt::StringLiterals;
24
26
27QgsSimpleCopyExternalStorageStoredContent::QgsSimpleCopyExternalStorageStoredContent( const QString &filePath, const QString &url, const QString &authcfg )
28{
29 Q_UNUSED( authcfg );
30
31 mCopyTask = new QgsCopyFileTask( filePath, url );
32
33 connect( mCopyTask, &QgsTask::taskCompleted, this, [this]
34 {
35 mUrl = mCopyTask->destination();
37 emit stored();
38 } );
39
40 connect( mCopyTask, &QgsTask::taskTerminated, this, [this]
41 {
42 reportError( mCopyTask->errorString() );
43 } );
44
45 connect( mCopyTask, &QgsTask::progressChanged, this, [this]( double progress )
46 {
47 emit progressChanged( progress );
48 } );
49}
50
51void QgsSimpleCopyExternalStorageStoredContent::store()
52{
55}
56
57void QgsSimpleCopyExternalStorageStoredContent::cancel()
58{
59 if ( !mCopyTask )
60 return;
61
62 disconnect( mCopyTask, &QgsTask::taskTerminated, this, nullptr );
63 connect( mCopyTask, &QgsTask::taskTerminated, this, [this]
64 {
66 emit canceled();
67 } );
68
69 mCopyTask->cancel();
70}
71
72QString QgsSimpleCopyExternalStorageStoredContent::url() const
73{
74 return mUrl;
75}
76
77QgsSimpleCopyExternalStorageFetchedContent::QgsSimpleCopyExternalStorageFetchedContent( const QString &filePath )
78 : mFilePath( filePath )
79{
80}
81
82void QgsSimpleCopyExternalStorageFetchedContent::fetch()
83{
84 // no fetching process, we read directly from its location
85 if ( !QFileInfo::exists( mFilePath ) )
86 {
87 reportError( tr( "File '%1' does not exist" ).arg( mFilePath ) );
88 }
89 else
90 {
92 mResultFilePath = mFilePath;
93 emit fetched();
94 }
95}
96
97QString QgsSimpleCopyExternalStorageFetchedContent::filePath() const
98{
99 return mResultFilePath;
100}
101
102QString QgsSimpleCopyExternalStorage::type() const
103{
104 return u"SimpleCopy"_s;
105};
106
107QString QgsSimpleCopyExternalStorage::displayName() const
108{
109 return QObject::tr( "Simple copy" );
110};
111
112QgsExternalStorageStoredContent *QgsSimpleCopyExternalStorage::doStore( const QString &filePath, const QString &url, const QString &authcfg ) const
113{
114 return new QgsSimpleCopyExternalStorageStoredContent( filePath, url, authcfg );
115};
116
117QgsExternalStorageFetchedContent *QgsSimpleCopyExternalStorage::doFetch( const QString &url, const QString &authConfig ) const
118{
119 Q_UNUSED( authConfig );
120
121 return new QgsSimpleCopyExternalStorageFetchedContent( url );
122}
123
@ Canceled
Content fetching/storing has been canceled.
Definition qgis.h:1908
@ Running
Content fetching/storing is in progress.
Definition qgis.h:1905
@ Finished
Content fetching/storing is finished and successful.
Definition qgis.h:1906
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....