reworking of getting the path to the file when saving/opening files
This commit is contained in:
parent
e1fa24c251
commit
b5dd48ad7b
21 changed files with 167 additions and 243 deletions
|
|
@ -1,79 +0,0 @@
|
||||||
#include "fileUtilites.h"
|
|
||||||
|
|
||||||
#include <QDesktopServices>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QFile>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QStandardPaths>
|
|
||||||
#include <QUrl>
|
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
|
||||||
#include "platforms/android/android_controller.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
#include "platforms/ios/MobileUtils.h"
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void FileUtilites::saveFile(QString fileName, const QString &data)
|
|
||||||
{
|
|
||||||
#if defined Q_OS_ANDROID
|
|
||||||
AndroidController::instance()->shareConfig(data, fileName);
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
QUrl fileUrl = QDir::tempPath() + "/" + fileName;
|
|
||||||
QFile file(fileUrl.toString());
|
|
||||||
#else
|
|
||||||
QUrl fileUrl = QUrl(fileName);
|
|
||||||
QFile file(fileUrl.toLocalFile());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// todo check if save successful
|
|
||||||
file.open(QIODevice::WriteOnly);
|
|
||||||
file.write(data.toUtf8());
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
QStringList filesToSend;
|
|
||||||
filesToSend.append(fileUrl.toString());
|
|
||||||
MobileUtils::shareText(filesToSend);
|
|
||||||
return;
|
|
||||||
#else
|
|
||||||
QFileInfo fi(fileUrl.toLocalFile());
|
|
||||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
QString FileUtilites::getFileName(QString fileName)
|
|
||||||
{
|
|
||||||
#ifdef Q_OS_IOS
|
|
||||||
CFURLRef url = CFURLCreateWithFileSystemPath(
|
|
||||||
kCFAllocatorDefault,
|
|
||||||
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
|
||||||
kCFURLPOSIXPathStyle, 0);
|
|
||||||
|
|
||||||
if (!CFURLStartAccessingSecurityScopedResource(url)) {
|
|
||||||
qDebug() << "Could not access path " << QUrl::fromLocalFile(fileName).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return fileName;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
|
||||||
// patch for files containing spaces etc
|
|
||||||
const QString sep { "raw%3A%2F" };
|
|
||||||
if (fileName.startsWith("content://") && fileName.contains(sep)) {
|
|
||||||
QString contentUrl = fileName.split(sep).at(0);
|
|
||||||
QString rawUrl = fileName.split(sep).at(1);
|
|
||||||
rawUrl.replace(" ", "%20");
|
|
||||||
fileName = contentUrl + sep + rawUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fileName;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return QUrl(fileName).toLocalFile();
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#ifndef FILEUTILITES_H
|
|
||||||
#define FILEUTILITES_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
class FileUtilites : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void saveFile(QString fileName, const QString &data);
|
|
||||||
static QString getFileName(QString fileName);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // FILEUTILITES_H
|
|
||||||
|
|
@ -4,15 +4,16 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
class MobileUtils : public QObject {
|
class MobileUtils : public QObject
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MobileUtils() = delete;
|
MobileUtils() = delete;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
static void shareText(const QStringList& filesToSend);
|
static void shareText(const QStringList &filesToSend);
|
||||||
|
static void openFile();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MOBILEUTILS_H
|
#endif // MOBILEUTILS_H
|
||||||
|
|
|
||||||
|
|
@ -35,3 +35,31 @@ void MobileUtils::shareText(const QStringList& filesToSend) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface MyFilePickerDelegate : NSObject <UIDocumentPickerDelegate>
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MyFilePickerDelegate
|
||||||
|
|
||||||
|
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
|
||||||
|
for (NSURL *url in urls) {
|
||||||
|
NSString *filePath = [url path];
|
||||||
|
|
||||||
|
NSData *fileData = [NSData dataWithContentsOfFile:filePath];
|
||||||
|
NSString *fileContent = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
|
||||||
|
NSLog(@"Содержимое файла: %@", fileContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
void MobileUtils::openFile() {
|
||||||
|
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.item"] inMode:UIDocumentPickerModeOpen];
|
||||||
|
|
||||||
|
MyFilePickerDelegate *filePickerDelegate = [[MyFilePickerDelegate alloc] init];
|
||||||
|
documentPicker.delegate = filePickerDelegate;
|
||||||
|
|
||||||
|
UIViewController *qtController = getViewController();
|
||||||
|
if (!qtController) return;
|
||||||
|
|
||||||
|
[qtController presentViewController:documentPicker animated:YES completion:nil];
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include "configurators/openvpn_configurator.h"
|
#include "configurators/openvpn_configurator.h"
|
||||||
#include "configurators/wireguard_configurator.h"
|
#include "configurators/wireguard_configurator.h"
|
||||||
#include "core/errorstrings.h"
|
#include "core/errorstrings.h"
|
||||||
#include "fileUtilites.h"
|
#include "systemController.h"
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
#include "platforms/android/androidutils.h"
|
#include "platforms/android/androidutils.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -200,9 +200,9 @@ QList<QString> ExportController::getQrCodes()
|
||||||
return m_qrCodes;
|
return m_qrCodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportController::saveFile(const QString &fileName)
|
void ExportController::exportConfig(const QString &fileName)
|
||||||
{
|
{
|
||||||
FileUtilites::saveFile(fileName, m_config);
|
SystemController::saveFile(fileName, m_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> ExportController::generateQrCodeImageSeries(const QByteArray &data)
|
QList<QString> ExportController::generateQrCodeImageSeries(const QByteArray &data)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public slots:
|
||||||
QString getConfig();
|
QString getConfig();
|
||||||
QList<QString> getQrCodes();
|
QList<QString> getQrCodes();
|
||||||
|
|
||||||
void saveFile(const QString &fileName);
|
void exportConfig(const QString &fileName);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void generateConfig(int type);
|
void generateConfig(int type);
|
||||||
|
|
@ -43,6 +43,8 @@ signals:
|
||||||
|
|
||||||
void exportConfigChanged();
|
void exportConfigChanged();
|
||||||
|
|
||||||
|
void saveFile(const QString &fileName, const QString &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QString> generateQrCodeImageSeries(const QByteArray &data);
|
QList<QString> generateQrCodeImageSeries(const QByteArray &data);
|
||||||
QString svgToBase64(const QString &image);
|
QString svgToBase64(const QString &image);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#endif
|
#endif
|
||||||
#include "fileUtilites.h"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
@ -88,11 +87,7 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
||||||
|
|
||||||
void ImportController::extractConfigFromFile(const QString &fileName)
|
void ImportController::extractConfigFromFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QQuickItem *obj = findChild<QQuickItem *>("saveFileDialog");
|
QFile file(fileName);
|
||||||
|
|
||||||
QUrl url(fileName);
|
|
||||||
QString path = url.toLocalFile();
|
|
||||||
QFile file(path);
|
|
||||||
|
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
QString data = file.readAll();
|
QString data = file.readAll();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include "core/errorstrings.h"
|
#include "core/errorstrings.h"
|
||||||
#include "core/servercontroller.h"
|
#include "core/servercontroller.h"
|
||||||
#include "fileUtilites.h"
|
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
|
||||||
|
|
@ -103,10 +103,6 @@ signals:
|
||||||
void showPassphraseRequestDrawer();
|
void showPassphraseRequestDrawer();
|
||||||
void passphraseRequestDrawerClosed(QString passphrase);
|
void passphraseRequestDrawerClosed(QString passphrase);
|
||||||
|
|
||||||
void setupFileDialogForConfig();
|
|
||||||
void setupFileDialogForSites(bool replaceExistingSites);
|
|
||||||
void setupFileDialogForBackup();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<ServersModel> m_serversModel;
|
QSharedPointer<ServersModel> m_serversModel;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include "fileUtilites.h"
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "systemController.h"
|
||||||
#include "ui/qautostart.h"
|
#include "ui/qautostart.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ void SettingsController::openLogsFolder()
|
||||||
|
|
||||||
void SettingsController::exportLogsFile(const QString &fileName)
|
void SettingsController::exportLogsFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
FileUtilites::saveFile(fileName, Logger::getLogFile());
|
SystemController::saveFile(fileName, Logger::getLogFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsController::clearLogs()
|
void SettingsController::clearLogs()
|
||||||
|
|
@ -81,12 +81,12 @@ void SettingsController::clearLogs()
|
||||||
|
|
||||||
void SettingsController::backupAppConfig(const QString &fileName)
|
void SettingsController::backupAppConfig(const QString &fileName)
|
||||||
{
|
{
|
||||||
FileUtilites::saveFile(fileName, m_settings->backupAppConfig());
|
SystemController::saveFile(fileName, m_settings->backupAppConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsController::restoreAppConfig(const QString &fileName)
|
void SettingsController::restoreAppConfig(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(FileUtilites::getFileName(fileName));
|
QFile file(fileName);
|
||||||
|
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ signals:
|
||||||
void changeSettingsFinished(const QString &finishedMessage);
|
void changeSettingsFinished(const QString &finishedMessage);
|
||||||
void changeSettingsErrorOccurred(const QString &errorMessage);
|
void changeSettingsErrorOccurred(const QString &errorMessage);
|
||||||
|
|
||||||
|
void saveFile(const QString &fileName, const QString &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedPointer<ServersModel> m_serversModel;
|
QSharedPointer<ServersModel> m_serversModel;
|
||||||
QSharedPointer<ContainersModel> m_containersModel;
|
QSharedPointer<ContainersModel> m_containersModel;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include <QHostInfo>
|
#include <QHostInfo>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include "fileUtilites.h"
|
#include "systemController.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
SitesController::SitesController(const std::shared_ptr<Settings> &settings,
|
SitesController::SitesController(const std::shared_ptr<Settings> &settings,
|
||||||
|
|
@ -82,7 +82,7 @@ void SitesController::removeSite(int index)
|
||||||
|
|
||||||
void SitesController::importSites(const QString &fileName, bool replaceExisting)
|
void SitesController::importSites(const QString &fileName, bool replaceExisting)
|
||||||
{
|
{
|
||||||
QFile file(FileUtilites::getFileName(fileName));
|
QFile file(fileName);
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
emit errorOccurred(tr("Can't open file: ") + fileName);
|
emit errorOccurred(tr("Can't open file: ") + fileName);
|
||||||
|
|
@ -145,7 +145,7 @@ void SitesController::exportSites(const QString &fileName)
|
||||||
QJsonDocument jsonDocument(jsonArray);
|
QJsonDocument jsonDocument(jsonArray);
|
||||||
QByteArray jsonData = jsonDocument.toJson();
|
QByteArray jsonData = jsonDocument.toJson();
|
||||||
|
|
||||||
FileUtilites::saveFile(fileName, jsonData);
|
SystemController::saveFile(fileName, jsonData);
|
||||||
|
|
||||||
emit finished(tr("Export completed"));
|
emit finished(tr("Export completed"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ signals:
|
||||||
void errorOccurred(const QString &errorMessage);
|
void errorOccurred(const QString &errorMessage);
|
||||||
void finished(const QString &message);
|
void finished(const QString &message);
|
||||||
|
|
||||||
|
void saveFile(const QString &fileName, const QString &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Settings> m_settings;
|
std::shared_ptr<Settings> m_settings;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@ void SystemController::saveFile(QString fileName, const QString &data)
|
||||||
QUrl fileUrl = QDir::tempPath() + "/" + fileName;
|
QUrl fileUrl = QDir::tempPath() + "/" + fileName;
|
||||||
QFile file(fileUrl.toString());
|
QFile file(fileUrl.toString());
|
||||||
#else
|
#else
|
||||||
QUrl fileUrl = QUrl(fileName);
|
QFile file(fileName);
|
||||||
QFile file(fileUrl.toLocalFile());
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// todo check if save successful
|
// todo check if save successful
|
||||||
|
|
@ -49,14 +48,18 @@ void SystemController::saveFile(QString fileName, const QString &data)
|
||||||
MobileUtils::shareText(filesToSend);
|
MobileUtils::shareText(filesToSend);
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
QFileInfo fi(fileUrl.toLocalFile());
|
QFileInfo fi(fileName);
|
||||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SystemController::getFileName()
|
QString SystemController::getFileName(const QString &acceptLabel, const QString &nameFilter,
|
||||||
|
const QString &selectedFile, const bool isSaveMode, const QString &defaultSuffix)
|
||||||
{
|
{
|
||||||
|
QString fileName;
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
|
MobileUtils::openFile();
|
||||||
|
|
||||||
CFURLRef url = CFURLCreateWithFileSystemPath(
|
CFURLRef url = CFURLCreateWithFileSystemPath(
|
||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
||||||
|
|
@ -69,17 +72,34 @@ QString SystemController::getFileName()
|
||||||
return fileName;
|
return fileName;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto mainFileDialog = m_qmlRoot->findChild<QObject>("mainFileDialog").parent();
|
QObject *mainFileDialog = m_qmlRoot->findChild<QObject>("mainFileDialog").parent();
|
||||||
if (!mainFileDialog) {
|
if (!mainFileDialog) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
QMetaObject::invokeMethod(mainFileDialog, "open", Qt::DirectConnection);
|
|
||||||
|
|
||||||
|
mainFileDialog->setProperty("acceptLabel", QVariant::fromValue(acceptLabel));
|
||||||
|
mainFileDialog->setProperty("nameFilters", QVariant::fromValue(QStringList(nameFilter)));
|
||||||
|
if (!selectedFile.isEmpty()) {
|
||||||
|
mainFileDialog->setProperty("selectedFile", QVariant::fromValue(selectedFile));
|
||||||
|
}
|
||||||
|
mainFileDialog->setProperty("isSaveMode", QVariant::fromValue(isSaveMode));
|
||||||
|
mainFileDialog->setProperty("defaultSuffix", QVariant::fromValue(defaultSuffix));
|
||||||
|
QMetaObject::invokeMethod(mainFileDialog, "open");
|
||||||
|
|
||||||
|
bool isFileDialogAccepted = false;
|
||||||
QEventLoop wait;
|
QEventLoop wait;
|
||||||
QObject::connect(this, &SystemController::fileDialogAccepted, &wait, &QEventLoop::quit);
|
QObject::connect(this, &SystemController::fileDialogClosed, [&wait, &isFileDialogAccepted](const bool isAccepted) {
|
||||||
|
isFileDialogAccepted = isAccepted;
|
||||||
|
wait.quit();
|
||||||
|
});
|
||||||
wait.exec();
|
wait.exec();
|
||||||
|
QObject::disconnect(this, &SystemController::fileDialogClosed, nullptr, nullptr);
|
||||||
|
|
||||||
auto fileName = mainFileDialog->property("selectedFile").toString();
|
if (!isFileDialogAccepted) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
fileName = mainFileDialog->property("selectedFile").toString();
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
// patch for files containing spaces etc
|
// patch for files containing spaces etc
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,16 @@ class SystemController : public QObject
|
||||||
public:
|
public:
|
||||||
explicit SystemController(const std::shared_ptr<Settings> &setting, QObject *parent = nullptr);
|
explicit SystemController(const std::shared_ptr<Settings> &setting, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
static void saveFile(QString fileName, const QString &data);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void saveFile(QString fileName, const QString &data);
|
QString getFileName(const QString &acceptLabel, const QString &nameFilter, const QString &selectedFile = "",
|
||||||
QString getFileName();
|
const bool isSaveMode = false, const QString &defaultSuffix = "");
|
||||||
|
|
||||||
void setQmlRoot(QObject *qmlRoot);
|
void setQmlRoot(QObject *qmlRoot);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void fileDialogAccepted();
|
void fileDialogClosed(const bool isAccepted);
|
||||||
void fileDialogRejected();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Settings> m_settings;
|
std::shared_ptr<Settings> m_settings;
|
||||||
|
|
|
||||||
|
|
@ -72,23 +72,20 @@ DrawerType {
|
||||||
imageSource: "qrc:/images/controls/share-2.svg"
|
imageSource: "qrc:/images/controls/share-2.svg"
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
var fileName = ""
|
||||||
if (GC.isMobile()) {
|
if (GC.isMobile()) {
|
||||||
ExportController.saveFile(configFileName)
|
fileName = configFileName
|
||||||
} else {
|
} else {
|
||||||
fileDialog.open()
|
fileName = SystemController.getFileName(configCaption,
|
||||||
|
qsTr("Config files (*" + configExtension + ")"),
|
||||||
|
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/" + configFileName,
|
||||||
|
true,
|
||||||
|
configExtension)
|
||||||
}
|
}
|
||||||
}
|
if (fileName !== "") {
|
||||||
|
PageController.showBusyIndicator(true)
|
||||||
FileDialog {
|
ExportController.exportConfig(fileName)
|
||||||
id: fileDialog
|
PageController.showBusyIndicator(false)
|
||||||
acceptLabel: configCaption
|
|
||||||
nameFilters: [ "Config files (*" + configExtension + ")" ]
|
|
||||||
fileMode: FileDialog.SaveFile
|
|
||||||
|
|
||||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/" + configFileName
|
|
||||||
defaultSuffix: configExtension
|
|
||||||
onAccepted: {
|
|
||||||
ExportController.saveFile(fileDialog.currentFile.toString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -84,32 +84,23 @@ PageType {
|
||||||
text: qsTr("Make a backup")
|
text: qsTr("Make a backup")
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
var fileName = ""
|
||||||
if (GC.isMobile()) {
|
if (GC.isMobile()) {
|
||||||
backupAppConfig("AmneziaVPN.backup")
|
fileName = "AmneziaVPN.backup"
|
||||||
} else {
|
} else {
|
||||||
saveFileDialog.open()
|
fileName = SystemController.getFileName(qsTr("Save backup file"),
|
||||||
|
qsTr("Backup files (*.backup)"),
|
||||||
|
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN",
|
||||||
|
true,
|
||||||
|
".backup")
|
||||||
}
|
}
|
||||||
}
|
if (fileName !== "") {
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: saveFileDialog
|
|
||||||
acceptLabel: qsTr("Save backup file")
|
|
||||||
nameFilters: [ "Backup files (*.backup)" ]
|
|
||||||
fileMode: FileDialog.SaveFile
|
|
||||||
|
|
||||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN"
|
|
||||||
defaultSuffix: ".backup"
|
|
||||||
onAccepted: {
|
|
||||||
makeBackupButton.backupAppConfig(saveFileDialog.currentFile.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function backupAppConfig(fileName) {
|
|
||||||
PageController.showBusyIndicator(true)
|
PageController.showBusyIndicator(true)
|
||||||
SettingsController.backupAppConfig(fileName)
|
SettingsController.backupAppConfig(fileName)
|
||||||
PageController.showBusyIndicator(false)
|
PageController.showBusyIndicator(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BasicButtonType {
|
BasicButtonType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
@ -125,8 +116,13 @@ PageType {
|
||||||
text: qsTr("Restore from backup")
|
text: qsTr("Restore from backup")
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
PageController.setupFileDialogForBackup()
|
var fileName = SystemController.getFileName(qsTr("Open backup file"),
|
||||||
SystemController.getFileName()
|
qsTr("Backup files (*.backup)"))
|
||||||
|
if (fileName !== "") {
|
||||||
|
PageController.showBusyIndicator(true)
|
||||||
|
SettingsController.restoreAppConfig(fileName)
|
||||||
|
PageController.showBusyIndicator(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,23 +101,20 @@ PageType {
|
||||||
image: "qrc:/images/controls/save.svg"
|
image: "qrc:/images/controls/save.svg"
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
var fileName = ""
|
||||||
if (GC.isMobile()) {
|
if (GC.isMobile()) {
|
||||||
SettingsController.exportLogsFile("AmneziaVPN.log")
|
fileName = "AmneziaVPN.log"
|
||||||
} else {
|
} else {
|
||||||
fileDialog.open()
|
fileName = SystemController.getFileName(qsTr("Save logs"),
|
||||||
|
qsTr("Logs files (*.log)"),
|
||||||
|
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN",
|
||||||
|
true,
|
||||||
|
".log")
|
||||||
}
|
}
|
||||||
}
|
if (fileName !== "") {
|
||||||
|
PageController.showBusyIndicator(true)
|
||||||
FileDialog {
|
SettingsController.exportLogsFile(fileName)
|
||||||
id: fileDialog
|
PageController.showBusyIndicator(false)
|
||||||
acceptLabel: qsTr("Save logs")
|
|
||||||
nameFilters: [ "Logs files (*.log)" ]
|
|
||||||
fileMode: FileDialog.SaveFile
|
|
||||||
|
|
||||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN"
|
|
||||||
defaultSuffix: ".log"
|
|
||||||
onAccepted: {
|
|
||||||
SettingsController.exportLogsFile(fileDialog.currentFile.toString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -300,25 +300,19 @@ PageType {
|
||||||
text: qsTr("Save site list")
|
text: qsTr("Save site list")
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
|
var fileName = ""
|
||||||
if (GC.isMobile()) {
|
if (GC.isMobile()) {
|
||||||
SitesController.exportSites("amezia_tunnel.json")
|
fileName = "amnezia_sites.json"
|
||||||
} else {
|
} else {
|
||||||
saveFileDialog.open()
|
fileName = SystemController.getFileName(qsTr("Save sites"),
|
||||||
|
qsTr("Sites files (*.json)"),
|
||||||
|
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/amnezia_sites",
|
||||||
|
true,
|
||||||
|
".json")
|
||||||
}
|
}
|
||||||
}
|
if (fileName !== "") {
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: saveFileDialog
|
|
||||||
objectName: saveFileDialog
|
|
||||||
acceptLabel: qsTr("Save sites")
|
|
||||||
nameFilters: [ "Sites files (*.json)" ]
|
|
||||||
fileMode: FileDialog.SaveFile
|
|
||||||
|
|
||||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/sites"
|
|
||||||
defaultSuffix: ".json"
|
|
||||||
onAccepted: {
|
|
||||||
PageController.showBusyIndicator(true)
|
PageController.showBusyIndicator(true)
|
||||||
SitesController.exportSites(saveFileDialog.currentFile.toString())
|
SitesController.exportSites(fileName)
|
||||||
moreActionsDrawer.close()
|
moreActionsDrawer.close()
|
||||||
PageController.showBusyIndicator(false)
|
PageController.showBusyIndicator(false)
|
||||||
}
|
}
|
||||||
|
|
@ -377,8 +371,11 @@ PageType {
|
||||||
text: qsTr("Replace site list")
|
text: qsTr("Replace site list")
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
PageController.setupFileDialogForSites(true)
|
var fileName = SystemController.getFileName(qsTr("Open sites file"),
|
||||||
SystemController.getFileName()
|
qsTr("Sites files (*.json)"))
|
||||||
|
if (fileName !== "") {
|
||||||
|
importSitesDrawerContent.importSites(fileName, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,12 +386,21 @@ PageType {
|
||||||
text: qsTr("Add imported sites to existing ones")
|
text: qsTr("Add imported sites to existing ones")
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
PageController.setupFileDialogForSites(false)
|
var fileName = SystemController.getFileName(qsTr("Open sites file"),
|
||||||
SystemController.getFileName()
|
qsTr("Sites files (*.json)"))
|
||||||
|
if (fileName !== "") {
|
||||||
|
importSitesDrawerContent.importSites(fileName, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function importSites(fileName, replaceExistingSites) {
|
||||||
|
PageController.showBusyIndicator(true)
|
||||||
|
SitesController.importSites(fileName, replaceExistingSites)
|
||||||
|
PageController.showBusyIndicator(false)
|
||||||
importSitesDrawer.close()
|
importSitesDrawer.close()
|
||||||
moreActionsDrawer.close()
|
moreActionsDrawer.close()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DividerType {}
|
DividerType {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,19 @@ It's okay as long as it's from someone you trust.")
|
||||||
leftImageSource: "qrc:/images/controls/folder-open.svg"
|
leftImageSource: "qrc:/images/controls/folder-open.svg"
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
PageController.setupFileDialogForConfig()
|
var nameFilter = !ServersModel.getServersCount() ? "Config or backup files (*.vpn *.ovpn *.conf *.backup)" :
|
||||||
SystemController.getFileName()
|
"Config files (*.vpn *.ovpn *.conf)"
|
||||||
|
var fileName = SystemController.getFileName(qsTr("Open config file"), nameFilter)
|
||||||
|
if (fileName !== "") {
|
||||||
|
if (fileName.indexOf(".backup") !== -1 && !ServersModel.getServersCount()) {
|
||||||
|
PageController.showBusyIndicator(true)
|
||||||
|
SettingsController.restoreAppConfig(fileName)
|
||||||
|
PageController.showBusyIndicator(false)
|
||||||
|
} else {
|
||||||
|
ImportController.extractConfigFromFile(fileName)
|
||||||
|
PageController.goToPage(PageEnum.PageSetupWizardViewConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,42 +81,6 @@ Window {
|
||||||
function onShowPassphraseRequestDrawer() {
|
function onShowPassphraseRequestDrawer() {
|
||||||
privateKeyPassphraseDrawer.open()
|
privateKeyPassphraseDrawer.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSetupFileDialogForConfig() {
|
|
||||||
mainFileDialog.acceptLabel = qsTr("Open config file")
|
|
||||||
mainFileDialog.nameFilters = !ServersModel.getServersCount() ? [ "Config or backup files (*.vpn *.ovpn *.conf *.backup)" ] :
|
|
||||||
[ "Config files (*.vpn *.ovpn *.conf)" ]
|
|
||||||
mainFileDialog.acceptFunction = function() {
|
|
||||||
if (mainFileDialog.selectedFile.toString().indexOf(".backup") !== -1 && !ServersModel.getServersCount()) {
|
|
||||||
PageController.showBusyIndicator(true)
|
|
||||||
SettingsController.restoreAppConfig(mainFileDialog.selectedFile.toString())
|
|
||||||
PageController.showBusyIndicator(false)
|
|
||||||
} else {
|
|
||||||
ImportController.extractConfigFromFile(mainFileDialog.selectedFile)
|
|
||||||
PageController.goToPage(PageEnum.PageSetupWizardViewConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSetupFileDialogForSites(replaceExistingSites) {
|
|
||||||
mainFileDialog.acceptLabel = qsTr("Open sites file")
|
|
||||||
mainFileDialog.nameFilters = [ "Sites files (*.json)" ]
|
|
||||||
mainFileDialog.acceptFunction = function() {
|
|
||||||
PageController.showBusyIndicator(true)
|
|
||||||
SitesController.importSites(mainFileDialog.selectedFile.toString(), replaceExistingSites)
|
|
||||||
PageController.showBusyIndicator(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSetupFileDialogForBackup() {
|
|
||||||
mainFileDialog.acceptLabel = qsTr("Open backup file")
|
|
||||||
mainFileDialog.nameFilters = [ "Backup files (*.backup)" ]
|
|
||||||
mainFileDialog.acceptFunction = function() {
|
|
||||||
PageController.showBusyIndicator(true)
|
|
||||||
SettingsController.restoreAppConfig(mainFileDialog.selectedFile.toString())
|
|
||||||
PageController.showBusyIndicator(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
|
@ -234,10 +198,12 @@ Window {
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: mainFileDialog
|
id: mainFileDialog
|
||||||
|
|
||||||
property var acceptFunction
|
property bool isSaveMode: false
|
||||||
|
|
||||||
objectName: "mainFileDialog"
|
objectName: "mainFileDialog"
|
||||||
|
fileMode: isSaveMode ? FileDialog.SaveFile : FileDialog.OpenFile
|
||||||
|
|
||||||
onAccepted: acceptFunction()
|
onAccepted: SystemController.fileDialogClosed(true)
|
||||||
|
onRejected: SystemController.fileDialogClosed(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue