Savefile for iOS
This commit is contained in:
parent
810da0db61
commit
0eda42f29f
1 changed files with 18 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#include "fileUtilites.h"
|
#include "fileUtilites.h"
|
||||||
|
#include "platforms/ios/MobileUtils.h"
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
@ -6,9 +7,15 @@
|
||||||
void FileUtilites::saveFile(const QString &fileExtension, const QString &caption, const QString &fileName,
|
void FileUtilites::saveFile(const QString &fileExtension, const QString &caption, const QString &fileName,
|
||||||
const QString &data)
|
const QString &data)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
QUrl fileUrl = QDir::tempPath() + "/" + fileName;
|
||||||
|
#else
|
||||||
QString docDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
QString docDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
||||||
QUrl fileUrl = QFileDialog::getSaveFileUrl(nullptr, caption, QUrl::fromLocalFile(docDir + "/" + fileName),
|
QUrl fileUrl = QFileDialog::getSaveFileUrl(nullptr, caption, QUrl::fromLocalFile(docDir + "/" + fileName),
|
||||||
"*" + fileExtension);
|
"*" + fileExtension);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fileUrl.isEmpty())
|
if (fileUrl.isEmpty())
|
||||||
return;
|
return;
|
||||||
if (!fileUrl.toString().endsWith(fileExtension)) {
|
if (!fileUrl.toString().endsWith(fileExtension)) {
|
||||||
|
|
@ -17,13 +24,24 @@ void FileUtilites::saveFile(const QString &fileExtension, const QString &caption
|
||||||
if (fileUrl.isEmpty())
|
if (fileUrl.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
QFile save(fileUrl.toString());
|
||||||
|
#else
|
||||||
QFile save(fileUrl.toLocalFile());
|
QFile save(fileUrl.toLocalFile());
|
||||||
|
#endif
|
||||||
|
|
||||||
// todo check if save successful
|
// todo check if save successful
|
||||||
save.open(QIODevice::WriteOnly);
|
save.open(QIODevice::WriteOnly);
|
||||||
save.write(data.toUtf8());
|
save.write(data.toUtf8());
|
||||||
save.close();
|
save.close();
|
||||||
|
|
||||||
|
#ifdef Q_OS_IOS
|
||||||
|
QStringList filesToSend;
|
||||||
|
filesToSend.append(fileUrl.toString());
|
||||||
|
MobileUtils::shareText(filesToSend);
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
QFileInfo fi(fileUrl.toLocalFile());
|
QFileInfo fi(fileUrl.toLocalFile());
|
||||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue