QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 mUrl = mCopyTask->destination();
36 emit stored();
37 } );
38
39 connect( mCopyTask, &QgsTask::taskTerminated, this, [this] { reportError( mCopyTask->errorString() ); } );
40
41 connect( mCopyTask, &QgsTask::progressChanged, this, [this]( double progress ) { emit progressChanged( progress ); } );
42}
43
44void QgsSimpleCopyExternalStorageStoredContent::store()
45{
48}
49
50void QgsSimpleCopyExternalStorageStoredContent::cancel()
51{
52 if ( !mCopyTask )
53 return;
54
55 disconnect( mCopyTask, &QgsTask::taskTerminated, this, nullptr );
56 connect( mCopyTask, &QgsTask::taskTerminated, this, [this] {
58 emit canceled();
59 } );
60
61 mCopyTask->cancel();
62}
63
64QString QgsSimpleCopyExternalStorageStoredContent::url() const
65{
66 return mUrl;
67}
68
69QgsSimpleCopyExternalStorageFetchedContent::QgsSimpleCopyExternalStorageFetchedContent( const QString &filePath )
70 : mFilePath( filePath )
71{}
72
73void QgsSimpleCopyExternalStorageFetchedContent::fetch()
74{
75 // no fetching process, we read directly from its location
76 if ( !QFileInfo::exists( mFilePath ) )
77 {
78 reportError( tr( "File '%1' does not exist" ).arg( mFilePath ) );
79 }
80 else
81 {
83 mResultFilePath = mFilePath;
84 emit fetched();
85 }
86}
87
88QString QgsSimpleCopyExternalStorageFetchedContent::filePath() const
89{
90 return mResultFilePath;
91}
92
93QString QgsSimpleCopyExternalStorage::type() const
94{
95 return u"SimpleCopy"_s;
96};
97
98QString QgsSimpleCopyExternalStorage::displayName() const
99{
100 return QObject::tr( "Simple copy" );
101};
102
103QgsExternalStorageStoredContent *QgsSimpleCopyExternalStorage::doStore( const QString &filePath, const QString &url, const QString &authcfg ) const
104{
105 return new QgsSimpleCopyExternalStorageStoredContent( filePath, url, authcfg );
106};
107
108QgsExternalStorageFetchedContent *QgsSimpleCopyExternalStorage::doFetch( const QString &url, const QString &authConfig ) const
109{
110 Q_UNUSED( authConfig );
111
112 return new QgsSimpleCopyExternalStorageFetchedContent( url );
113}
114
@ Canceled
Content fetching/storing has been canceled.
Definition qgis.h:1929
@ Running
Content fetching/storing is in progress.
Definition qgis.h:1926
@ Finished
Content fetching/storing is finished and successful.
Definition qgis.h:1927
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....