mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Fix qt warnings thrown by QgsFileDownloader
This commit is contained in:
parent
587072cae9
commit
30da28a7b0
24
src/core/qgsfiledownloader.cpp
Executable file → Normal file
24
src/core/qgsfiledownloader.cpp
Executable file → Normal file
@ -25,14 +25,14 @@
|
||||
#include <QSslError>
|
||||
#endif
|
||||
|
||||
QgsFileDownloader::QgsFileDownloader(const QUrl &url, const QString &outputFileName, const QString &authcfg , bool delayStart)
|
||||
QgsFileDownloader::QgsFileDownloader( const QUrl &url, const QString &outputFileName, const QString &authcfg, bool delayStart )
|
||||
: mUrl( url )
|
||||
, mDownloadCanceled( false )
|
||||
{
|
||||
mFile.setFileName( outputFileName );
|
||||
mAuthCfg = authcfg;
|
||||
if ( !delayStart )
|
||||
startDownload();
|
||||
startDownload();
|
||||
}
|
||||
|
||||
|
||||
@ -124,7 +124,12 @@ void QgsFileDownloader::error( const QString &errorMessage )
|
||||
void QgsFileDownloader::onReadyRead()
|
||||
{
|
||||
Q_ASSERT( mReply );
|
||||
if ( ! mFile.isOpen() && ! mFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
|
||||
if ( mFile.fileName().isEmpty() )
|
||||
{
|
||||
error( tr( "No output filename specified" ) );
|
||||
onFinished();
|
||||
}
|
||||
else if ( ! mFile.isOpen() && ! mFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
|
||||
{
|
||||
error( tr( "Cannot open output file: %1" ).arg( mFile.fileName() ) );
|
||||
onFinished();
|
||||
@ -141,14 +146,19 @@ void QgsFileDownloader::onFinished()
|
||||
// when canceled
|
||||
if ( ! mErrors.isEmpty() || mDownloadCanceled )
|
||||
{
|
||||
mFile.close();
|
||||
mFile.remove();
|
||||
if ( mFile.isOpen() )
|
||||
mFile.close();
|
||||
if ( mFile.exists() )
|
||||
mFile.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
// download finished normally
|
||||
mFile.flush();
|
||||
mFile.close();
|
||||
if ( mFile.isOpen() )
|
||||
{
|
||||
mFile.flush();
|
||||
mFile.close();
|
||||
}
|
||||
|
||||
// get redirection url
|
||||
QVariant redirectionTarget = mReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
|
||||
|
2
tests/src/gui/testqgsfiledownloader.cpp
Executable file → Normal file
2
tests/src/gui/testqgsfiledownloader.cpp
Executable file → Normal file
@ -185,7 +185,7 @@ void TestQgsFileDownloader::testInvalidFile()
|
||||
QVERIFY( !mCompleted );
|
||||
QVERIFY( mError );
|
||||
QVERIFY( !mCanceled );
|
||||
QCOMPARE( mErrorMessage, QString( "Cannot open output file: " ) );
|
||||
QCOMPARE( mErrorMessage, QString( "No output filename specified" ) );
|
||||
}
|
||||
|
||||
void TestQgsFileDownloader::testInvalidUrl()
|
||||
|
@ -107,7 +107,7 @@ class TestQgsFileDownloader(unittest.TestCase):
|
||||
self.assertFalse(self.completed_was_called)
|
||||
self.assertFalse(self.canceled_was_called)
|
||||
self.assertTrue(self.error_was_called)
|
||||
self.assertEqual(self.error_args[1], [u"Cannot open output file: "])
|
||||
self.assertEqual(self.error_args[1], [u"No output filename specified"])
|
||||
|
||||
def test_BlankUrl(self):
|
||||
destination = tempfile.mktemp()
|
||||
|
Loading…
x
Reference in New Issue
Block a user