Skip to content

Commit

Permalink
Fix qt warnings thrown by QgsFileDownloader
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 18, 2017
1 parent 587072c commit 30da28a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions src/core/qgsfiledownloader.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down Expand Up @@ -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();
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/gui/testqgsfiledownloader.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsfiledownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_InvalidFile(self):
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()
Expand Down

0 comments on commit 30da28a

Please sign in to comment.