Skip to content

Commit 30da28a

Browse files
committed
Fix qt warnings thrown by QgsFileDownloader
1 parent 587072c commit 30da28a

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/core/qgsfiledownloader.cpp

100755100644
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
#include <QSslError>
2626
#endif
2727

28-
QgsFileDownloader::QgsFileDownloader(const QUrl &url, const QString &outputFileName, const QString &authcfg , bool delayStart)
28+
QgsFileDownloader::QgsFileDownloader( const QUrl &url, const QString &outputFileName, const QString &authcfg, bool delayStart )
2929
: mUrl( url )
3030
, mDownloadCanceled( false )
3131
{
3232
mFile.setFileName( outputFileName );
3333
mAuthCfg = authcfg;
3434
if ( !delayStart )
35-
startDownload();
35+
startDownload();
3636
}
3737

3838

@@ -124,7 +124,12 @@ void QgsFileDownloader::error( const QString &errorMessage )
124124
void QgsFileDownloader::onReadyRead()
125125
{
126126
Q_ASSERT( mReply );
127-
if ( ! mFile.isOpen() && ! mFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
127+
if ( mFile.fileName().isEmpty() )
128+
{
129+
error( tr( "No output filename specified" ) );
130+
onFinished();
131+
}
132+
else if ( ! mFile.isOpen() && ! mFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
128133
{
129134
error( tr( "Cannot open output file: %1" ).arg( mFile.fileName() ) );
130135
onFinished();
@@ -141,14 +146,19 @@ void QgsFileDownloader::onFinished()
141146
// when canceled
142147
if ( ! mErrors.isEmpty() || mDownloadCanceled )
143148
{
144-
mFile.close();
145-
mFile.remove();
149+
if ( mFile.isOpen() )
150+
mFile.close();
151+
if ( mFile.exists() )
152+
mFile.remove();
146153
}
147154
else
148155
{
149156
// download finished normally
150-
mFile.flush();
151-
mFile.close();
157+
if ( mFile.isOpen() )
158+
{
159+
mFile.flush();
160+
mFile.close();
161+
}
152162

153163
// get redirection url
154164
QVariant redirectionTarget = mReply->attribute( QNetworkRequest::RedirectionTargetAttribute );

tests/src/gui/testqgsfiledownloader.cpp

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void TestQgsFileDownloader::testInvalidFile()
185185
QVERIFY( !mCompleted );
186186
QVERIFY( mError );
187187
QVERIFY( !mCanceled );
188-
QCOMPARE( mErrorMessage, QString( "Cannot open output file: " ) );
188+
QCOMPARE( mErrorMessage, QString( "No output filename specified" ) );
189189
}
190190

191191
void TestQgsFileDownloader::testInvalidUrl()

tests/src/python/test_qgsfiledownloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_InvalidFile(self):
107107
self.assertFalse(self.completed_was_called)
108108
self.assertFalse(self.canceled_was_called)
109109
self.assertTrue(self.error_was_called)
110-
self.assertEqual(self.error_args[1], [u"Cannot open output file: "])
110+
self.assertEqual(self.error_args[1], [u"No output filename specified"])
111111

112112
def test_BlankUrl(self):
113113
destination = tempfile.mktemp()

0 commit comments

Comments
 (0)