diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-12-12 19:39:24 +0300 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-12-12 19:39:24 +0300 |
commit | d438c08e11d17dc9c005806a6036e1aeb769c54b (patch) | |
tree | 2c7e36ab0cfcfc2d14d24eff11c6e455a3cebaed /lib/connection.cpp | |
parent | ec3ddd6930991b04d13cdb12720f141482f9a6eb (diff) | |
download | libquotient-d438c08e11d17dc9c005806a6036e1aeb769c54b.tar.gz libquotient-d438c08e11d17dc9c005806a6036e1aeb769c54b.zip |
Connection::uploadFile/Content(): refactoring around QIODevice::open()
No more "The file is already open" log messages.
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index c830557c..999f4382 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -624,12 +624,17 @@ UploadContentJob* Connection::uploadContent(QIODevice* contentSource, const QString& filename, const QString& overrideContentType) const { + Q_ASSERT(contentSource != nullptr); auto contentType = overrideContentType; if (contentType.isEmpty()) { contentType = QMimeDatabase() .mimeTypeForFileNameAndData(filename, contentSource) .name(); - contentSource->open(QIODevice::ReadOnly); + if (!contentSource->open(QIODevice::ReadOnly)) { + qCWarning(MAIN) << "Couldn't open content source" << filename + << "for reading:" << contentSource->errorString(); + return nullptr; + } } return callApi<UploadContentJob>(contentSource, filename, contentType); } @@ -638,11 +643,6 @@ UploadContentJob* Connection::uploadFile(const QString& fileName, const QString& overrideContentType) { auto sourceFile = new QFile(fileName); - if (!sourceFile->open(QIODevice::ReadOnly)) { - qCWarning(MAIN) << "Couldn't open" << sourceFile->fileName() - << "for reading"; - return nullptr; - } return uploadContent(sourceFile, QFileInfo(*sourceFile).fileName(), overrideContentType); } |