1- #ifdef Q_OS_ANDROID
2- #include < QJniObject>
3- #include < QtCore/qnativeinterface.h>
4- #endif
51#include " StatusQ/systemutilsinternal.h"
62
7- #include < QDir>
83#include < QGuiApplication>
94#include < QMimeDatabase>
105#include < QNetworkAccessManager>
116#include < QNetworkReply>
127#include < QProcess>
138#include < QSaveFile>
9+ #include < QStandardPaths>
1410
1511#ifdef Q_OS_ANDROID
1612#include < QJniObject>
1713#include < QtCore/qnativeinterface.h>
1814#endif
1915
16+ #ifdef Q_OS_IOS
2017#include " ios_utils.h"
18+ #endif
2119
2220class QuitFilter : public QObject
2321{
@@ -26,7 +24,7 @@ class QuitFilter : public QObject
2624public:
2725 using QObject::QObject;
2826
29- bool eventFilter (QObject* obj, QEvent* ev)
27+ bool eventFilter (QObject* obj, QEvent* ev) override
3028 {
3129 if (ev->type () == QEvent::Quit)
3230 emit quit (ev->spontaneous ());
@@ -60,12 +58,6 @@ void SystemUtilsInternal::restartApplication() const
6058 QMetaObject::invokeMethod (QCoreApplication::instance (), &QCoreApplication::exit, Qt::QueuedConnection, EXIT_SUCCESS);
6159}
6260
63- #if defined(Q_OS_IOS)
64- void save (const QByteArray& imageData)
65- {
66- saveImageToPhotosAlbum (imageData);
67- }
68- #else
6961void save (const QByteArray& imageData, const QString& targetDir)
7062{
7163
@@ -99,7 +91,6 @@ void save(const QByteArray& imageData, const QString& targetDir)
9991 " Downloading image failed while saving to file:"
10092 << targetFile;
10193}
102- #endif
10394
10495void SystemUtilsInternal::downloadImageByUrl (
10596 const QUrl& url, const QString& path) const
@@ -110,10 +101,15 @@ void SystemUtilsInternal::downloadImageByUrl(
110101 QNetworkReply *reply = manager.get (QNetworkRequest (url));
111102
112103 // accept both "file:/foo/bar" and "/foo/bar"
113- auto targetDir = QUrl::fromUserInput (path).toLocalFile ();
104+ auto targetDir = QUrl::fromUserInput (path)
105+ #ifndef Q_OS_ANDROID
106+ .toLocalFile ();
107+ #else
108+ .toString (); // don't touch the "content://" URI
109+ #endif
114110
115111 if (targetDir.isEmpty ())
116- targetDir = QDir::homePath ( );
112+ targetDir = QStandardPaths::writableLocation (QStandardPaths::PicturesLocation );
117113
118114 QObject::connect (reply, &QNetworkReply::finished, this , [reply, targetDir] {
119115 if (reply->error () != QNetworkReply::NoError) {
@@ -125,11 +121,11 @@ void SystemUtilsInternal::downloadImageByUrl(
125121 // Extract the image data to be able to load and save it
126122 const auto btArray = reply->readAll ();
127123 Q_ASSERT (!btArray.isEmpty ());
128- #ifdef Q_OS_IOS
129- save (btArray);
130- #else
124+ #ifdef Q_OS_IOS
125+ saveImageToPhotosAlbum (btArray);
126+ #else
131127 save (btArray, targetDir);
132- #endif
128+ #endif
133129 });
134130}
135131
0 commit comments