Skip to content

Commit cf0d45e

Browse files
committedJan 25, 2019
OGR: add a download option to the protocol data source
Fixes #21091 The issue was due to the /vsicurl/ not being able to open a streaming endpoint. “Things are not always what they seem; the first appearance deceives many; [...]” ― Phaedrus
1 parent a90fb87 commit cf0d45e

File tree

2 files changed

+92
-46
lines changed

2 files changed

+92
-46
lines changed
 

‎src/providers/ogr/qgsogrsourceselect.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsvectordataprovider.h"
2929
#include "qgssettings.h"
3030
#include "qgsproviderregistry.h"
31+
#include "qgsfiledownloader.h"
3132
#include "ogr/qgsnewogrconnection.h"
3233
#include "ogr/qgsogrhelperfunctions.h"
3334

@@ -304,6 +305,7 @@ void QgsOgrSourceSelect::setProtocolWidgetsVisibility()
304305
labelKey->show();
305306
mKey->show();
306307
mAuthWarning->show();
308+
mDownloadCheckBox->hide();
307309
}
308310
else
309311
{
@@ -315,6 +317,7 @@ void QgsOgrSourceSelect::setProtocolWidgetsVisibility()
315317
labelKey->hide();
316318
mKey->hide();
317319
mAuthWarning->hide();
320+
mDownloadCheckBox->show();
318321
}
319322
}
320323

@@ -397,12 +400,45 @@ void QgsOgrSourceSelect::addButtonClicked()
397400
{
398401
uri = protocolURI->text();
399402
}
403+
if ( cloudType || ! mDownloadCheckBox->isChecked() )
404+
{
405+
406+
mDataSources << createProtocolURI( cmbProtocolTypes->currentText(),
407+
uri,
408+
mAuthSettingsProtocol->configId(),
409+
mAuthSettingsProtocol->username(),
410+
mAuthSettingsProtocol->password() );
411+
}
412+
else
413+
{
414+
QTemporaryFile tempFile;
415+
tempFile.setAutoRemove( false );
416+
tempFile.open();
417+
tempFile.close();
418+
QString filePath { tempFile.fileName() };
419+
QString fileEncoding { encoding() };
420+
QString dsType { dataSourceType() };
421+
QUrl url { uri };
422+
url.setUserName( mAuthSettingsProtocol->username() );
423+
url.setPassword( mAuthSettingsProtocol->password() );
424+
// QgsFileDownloader will self destruct, no leaks here
425+
// As long as the application keeps the data source select dialog
426+
// alive for the whole application lifetime, the lambdas below are
427+
// safe regarding to "this".
428+
QgsFileDownloader *downloader = new QgsFileDownloader( url, filePath, mAuthSettingsProtocol->configId() );
429+
connect( downloader, &QgsFileDownloader::downloadCompleted, [ = ]
430+
{
431+
emit addVectorLayers( QStringList() << filePath, fileEncoding, dsType );
432+
} );
433+
connect( downloader, &QgsFileDownloader::downloadError, [ = ]( QStringList errorMessages )
434+
{
435+
QMessageBox::warning( this,
436+
tr( "Error downloading layer data" ),
437+
errorMessages.join( "<br/>" ) );
438+
} );
439+
440+
}
400441

401-
mDataSources << createProtocolURI( cmbProtocolTypes->currentText(),
402-
uri,
403-
mAuthSettingsProtocol->configId(),
404-
mAuthSettingsProtocol->username(),
405-
mAuthSettingsProtocol->password() );
406442
}
407443
else if ( radioSrcFile->isChecked() )
408444
{

‎src/ui/qgsogrsourceselectbase.ui

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<rect>
1010
<x>0</x>
1111
<y>0</y>
12-
<width>450</width>
13-
<height>658</height>
12+
<width>478</width>
13+
<height>756</height>
1414
</rect>
1515
</property>
1616
<property name="sizePolicy">
@@ -126,29 +126,6 @@
126126
<string>Protocol</string>
127127
</property>
128128
<layout class="QGridLayout" name="gridLayout_2">
129-
<item row="0" column="1">
130-
<widget class="QComboBox" name="cmbProtocolTypes"/>
131-
</item>
132-
<item row="0" column="0">
133-
<widget class="QLabel" name="label_2">
134-
<property name="text">
135-
<string>Type</string>
136-
</property>
137-
</widget>
138-
</item>
139-
<item row="1" column="0">
140-
<widget class="QLabel" name="labelProtocolURI">
141-
<property name="text">
142-
<string>&amp;URI</string>
143-
</property>
144-
<property name="buddy">
145-
<cstring>protocolURI</cstring>
146-
</property>
147-
</widget>
148-
</item>
149-
<item row="1" column="1">
150-
<widget class="QLineEdit" name="protocolURI"/>
151-
</item>
152129
<item row="2" column="0">
153130
<widget class="QLabel" name="labelBucket">
154131
<property name="text">
@@ -157,38 +134,48 @@
157134
<property name="buddy">
158135
<cstring>mBucket</cstring>
159136
</property>
160-
</widget>
137+
</widget>
161138
</item>
162139
<item row="2" column="1">
163140
<widget class="QLineEdit" name="mBucket"/>
164141
</item>
165-
<item row="3" column="0">
166-
<widget class="QLabel" name="labelKey">
142+
<item row="5" column="0" colspan="2">
143+
<widget class="QLabel" name="mAuthWarning">
167144
<property name="text">
168-
<string>Object key</string>
169-
</property>
170-
<property name="buddy">
171-
<cstring>mKey</cstring>
145+
<string>…</string>
172146
</property>
173-
</widget>
174-
</item>
175-
<item row="3" column="1">
176-
<widget class="QLineEdit" name="mKey"/>
177-
</item>
178-
<item row="4" column="0" colspan="2">
179-
<widget class="QLabel" name="mAuthWarning">
180147
<property name="wordWrap">
181148
<bool>true</bool>
182149
</property>
183150
<property name="openExternalLinks">
184151
<bool>true</bool>
185152
</property>
153+
</widget>
154+
</item>
155+
<item row="0" column="0">
156+
<widget class="QLabel" name="label_2">
186157
<property name="text">
187-
<string></string>
158+
<string>Type</string>
188159
</property>
189160
</widget>
190161
</item>
191-
<item row="5" column="0" colspan="2">
162+
<item row="1" column="0">
163+
<widget class="QLabel" name="labelProtocolURI">
164+
<property name="text">
165+
<string>&amp;URI</string>
166+
</property>
167+
<property name="buddy">
168+
<cstring>protocolURI</cstring>
169+
</property>
170+
</widget>
171+
</item>
172+
<item row="0" column="1">
173+
<widget class="QComboBox" name="cmbProtocolTypes"/>
174+
</item>
175+
<item row="3" column="1">
176+
<widget class="QLineEdit" name="mKey"/>
177+
</item>
178+
<item row="6" column="0" colspan="2">
192179
<widget class="QGroupBox" name="mAuthGroupBox">
193180
<property name="title">
194181
<string>Authentication</string>
@@ -219,6 +206,29 @@
219206
</layout>
220207
</widget>
221208
</item>
209+
<item row="1" column="1">
210+
<widget class="QLineEdit" name="protocolURI"/>
211+
</item>
212+
<item row="3" column="0">
213+
<widget class="QLabel" name="labelKey">
214+
<property name="text">
215+
<string>Object key</string>
216+
</property>
217+
<property name="buddy">
218+
<cstring>mKey</cstring>
219+
</property>
220+
</widget>
221+
</item>
222+
<item row="4" column="0" colspan="2">
223+
<widget class="QCheckBox" name="mDownloadCheckBox">
224+
<property name="toolTip">
225+
<string>This option is useful if the service is a streaming service.</string>
226+
</property>
227+
<property name="text">
228+
<string>Download all data before opening</string>
229+
</property>
230+
</widget>
231+
</item>
222232
</layout>
223233
</widget>
224234
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.