Skip to content
Permalink
Browse files

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
  • Loading branch information
elpaso committed Jan 25, 2019
1 parent a90fb87 commit cf0d45e5adfc263df858ff41fb0958ccdc2acaad
Showing with 92 additions and 46 deletions.
  1. +41 −5 src/providers/ogr/qgsogrsourceselect.cpp
  2. +51 −41 src/ui/qgsogrsourceselectbase.ui
@@ -28,6 +28,7 @@
#include "qgsvectordataprovider.h"
#include "qgssettings.h"
#include "qgsproviderregistry.h"
#include "qgsfiledownloader.h"
#include "ogr/qgsnewogrconnection.h"
#include "ogr/qgsogrhelperfunctions.h"

@@ -304,6 +305,7 @@ void QgsOgrSourceSelect::setProtocolWidgetsVisibility()
labelKey->show();
mKey->show();
mAuthWarning->show();
mDownloadCheckBox->hide();
}
else
{
@@ -315,6 +317,7 @@ void QgsOgrSourceSelect::setProtocolWidgetsVisibility()
labelKey->hide();
mKey->hide();
mAuthWarning->hide();
mDownloadCheckBox->show();
}
}

@@ -397,12 +400,45 @@ void QgsOgrSourceSelect::addButtonClicked()
{
uri = protocolURI->text();
}
if ( cloudType || ! mDownloadCheckBox->isChecked() )
{

mDataSources << createProtocolURI( cmbProtocolTypes->currentText(),
uri,
mAuthSettingsProtocol->configId(),
mAuthSettingsProtocol->username(),
mAuthSettingsProtocol->password() );
}
else
{
QTemporaryFile tempFile;
tempFile.setAutoRemove( false );
tempFile.open();
tempFile.close();
QString filePath { tempFile.fileName() };
QString fileEncoding { encoding() };
QString dsType { dataSourceType() };
QUrl url { uri };
url.setUserName( mAuthSettingsProtocol->username() );
url.setPassword( mAuthSettingsProtocol->password() );
// QgsFileDownloader will self destruct, no leaks here
// As long as the application keeps the data source select dialog
// alive for the whole application lifetime, the lambdas below are
// safe regarding to "this".
QgsFileDownloader *downloader = new QgsFileDownloader( url, filePath, mAuthSettingsProtocol->configId() );
connect( downloader, &QgsFileDownloader::downloadCompleted, [ = ]
{
emit addVectorLayers( QStringList() << filePath, fileEncoding, dsType );
} );
connect( downloader, &QgsFileDownloader::downloadError, [ = ]( QStringList errorMessages )
{
QMessageBox::warning( this,
tr( "Error downloading layer data" ),
errorMessages.join( "<br/>" ) );
} );

}

mDataSources << createProtocolURI( cmbProtocolTypes->currentText(),
uri,
mAuthSettingsProtocol->configId(),
mAuthSettingsProtocol->username(),
mAuthSettingsProtocol->password() );
}
else if ( radioSrcFile->isChecked() )
{
@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>450</width>
<height>658</height>
<width>478</width>
<height>756</height>
</rect>
</property>
<property name="sizePolicy">
@@ -126,29 +126,6 @@
<string>Protocol</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QComboBox" name="cmbProtocolTypes"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelProtocolURI">
<property name="text">
<string>&amp;URI</string>
</property>
<property name="buddy">
<cstring>protocolURI</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="protocolURI"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelBucket">
<property name="text">
@@ -157,38 +134,48 @@
<property name="buddy">
<cstring>mBucket</cstring>
</property>
</widget>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mBucket"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelKey">
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="mAuthWarning">
<property name="text">
<string>Object key</string>
</property>
<property name="buddy">
<cstring>mKey</cstring>
<string>…</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="mKey"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="mAuthWarning">
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string></string>
<string>Type</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="1" column="0">
<widget class="QLabel" name="labelProtocolURI">
<property name="text">
<string>&amp;URI</string>
</property>
<property name="buddy">
<cstring>protocolURI</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cmbProtocolTypes"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="mKey"/>
</item>
<item row="6" column="0" colspan="2">
<widget class="QGroupBox" name="mAuthGroupBox">
<property name="title">
<string>Authentication</string>
@@ -219,6 +206,29 @@
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="protocolURI"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelKey">
<property name="text">
<string>Object key</string>
</property>
<property name="buddy">
<cstring>mKey</cstring>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="mDownloadCheckBox">
<property name="toolTip">
<string>This option is useful if the service is a streaming service.</string>
</property>
<property name="text">
<string>Download all data before opening</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit cf0d45e

Please sign in to comment.
You can’t perform that action at this time.