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 <QStringList>
|
||||
|
||||
class MobileUtils : public QObject {
|
||||
class MobileUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MobileUtils() = delete;
|
||||
|
||||
public slots:
|
||||
static void shareText(const QStringList& filesToSend);
|
||||
|
||||
static void shareText(const QStringList &filesToSend);
|
||||
static void openFile();
|
||||
};
|
||||
|
||||
#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/wireguard_configurator.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "fileUtilites.h"
|
||||
#include "systemController.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "platforms/android/androidutils.h"
|
||||
#endif
|
||||
|
@ -200,9 +200,9 @@ QList<QString> ExportController::getQrCodes()
|
|||
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)
|
||||
|
|
|
@ -35,7 +35,7 @@ public slots:
|
|||
QString getConfig();
|
||||
QList<QString> getQrCodes();
|
||||
|
||||
void saveFile(const QString &fileName);
|
||||
void exportConfig(const QString &fileName);
|
||||
|
||||
signals:
|
||||
void generateConfig(int type);
|
||||
|
@ -43,6 +43,8 @@ signals:
|
|||
|
||||
void exportConfigChanged();
|
||||
|
||||
void saveFile(const QString &fileName, const QString &data);
|
||||
|
||||
private:
|
||||
QList<QString> generateQrCodeImageSeries(const QByteArray &data);
|
||||
QString svgToBase64(const QString &image);
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#ifdef Q_OS_IOS
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
#include "fileUtilites.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -88,11 +87,7 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
|||
|
||||
void ImportController::extractConfigFromFile(const QString &fileName)
|
||||
{
|
||||
QQuickItem *obj = findChild<QQuickItem *>("saveFileDialog");
|
||||
|
||||
QUrl url(fileName);
|
||||
QString path = url.toLocalFile();
|
||||
QFile file(path);
|
||||
QFile file(fileName);
|
||||
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QString data = file.readAll();
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "core/errorstrings.h"
|
||||
#include "core/servercontroller.h"
|
||||
#include "fileUtilites.h"
|
||||
#include "utilities.h"
|
||||
|
||||
namespace
|
||||
|
|
|
@ -103,10 +103,6 @@ signals:
|
|||
void showPassphraseRequestDrawer();
|
||||
void passphraseRequestDrawerClosed(QString passphrase);
|
||||
|
||||
void setupFileDialogForConfig();
|
||||
void setupFileDialogForSites(bool replaceExistingSites);
|
||||
void setupFileDialogForBackup();
|
||||
|
||||
private:
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "fileUtilites.h"
|
||||
#include "logger.h"
|
||||
#include "systemController.h"
|
||||
#include "ui/qautostart.h"
|
||||
#include "version.h"
|
||||
|
||||
|
@ -70,7 +70,7 @@ void SettingsController::openLogsFolder()
|
|||
|
||||
void SettingsController::exportLogsFile(const QString &fileName)
|
||||
{
|
||||
FileUtilites::saveFile(fileName, Logger::getLogFile());
|
||||
SystemController::saveFile(fileName, Logger::getLogFile());
|
||||
}
|
||||
|
||||
void SettingsController::clearLogs()
|
||||
|
@ -81,12 +81,12 @@ void SettingsController::clearLogs()
|
|||
|
||||
void SettingsController::backupAppConfig(const QString &fileName)
|
||||
{
|
||||
FileUtilites::saveFile(fileName, m_settings->backupAppConfig());
|
||||
SystemController::saveFile(fileName, m_settings->backupAppConfig());
|
||||
}
|
||||
|
||||
void SettingsController::restoreAppConfig(const QString &fileName)
|
||||
{
|
||||
QFile file(FileUtilites::getFileName(fileName));
|
||||
QFile file(fileName);
|
||||
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
|
|
|
@ -63,6 +63,8 @@ signals:
|
|||
void changeSettingsFinished(const QString &finishedMessage);
|
||||
void changeSettingsErrorOccurred(const QString &errorMessage);
|
||||
|
||||
void saveFile(const QString &fileName, const QString &data);
|
||||
|
||||
private:
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
QSharedPointer<ContainersModel> m_containersModel;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QHostInfo>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "fileUtilites.h"
|
||||
#include "systemController.h"
|
||||
#include "utilities.h"
|
||||
|
||||
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)
|
||||
{
|
||||
QFile file(FileUtilites::getFileName(fileName));
|
||||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
emit errorOccurred(tr("Can't open file: ") + fileName);
|
||||
|
@ -145,7 +145,7 @@ void SitesController::exportSites(const QString &fileName)
|
|||
QJsonDocument jsonDocument(jsonArray);
|
||||
QByteArray jsonData = jsonDocument.toJson();
|
||||
|
||||
FileUtilites::saveFile(fileName, jsonData);
|
||||
SystemController::saveFile(fileName, jsonData);
|
||||
|
||||
emit finished(tr("Export completed"));
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ signals:
|
|||
void errorOccurred(const QString &errorMessage);
|
||||
void finished(const QString &message);
|
||||
|
||||
void saveFile(const QString &fileName, const QString &data);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
||||
|
|
|
@ -34,8 +34,7 @@ void SystemController::saveFile(QString fileName, const QString &data)
|
|||
QUrl fileUrl = QDir::tempPath() + "/" + fileName;
|
||||
QFile file(fileUrl.toString());
|
||||
#else
|
||||
QUrl fileUrl = QUrl(fileName);
|
||||
QFile file(fileUrl.toLocalFile());
|
||||
QFile file(fileName);
|
||||
#endif
|
||||
|
||||
// todo check if save successful
|
||||
|
@ -49,14 +48,18 @@ void SystemController::saveFile(QString fileName, const QString &data)
|
|||
MobileUtils::shareText(filesToSend);
|
||||
return;
|
||||
#else
|
||||
QFileInfo fi(fileUrl.toLocalFile());
|
||||
QFileInfo fi(fileName);
|
||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
#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
|
||||
MobileUtils::openFile();
|
||||
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(
|
||||
kCFAllocatorDefault,
|
||||
CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(fileName.unicode()), fileName.length()),
|
||||
|
@ -69,17 +72,34 @@ QString SystemController::getFileName()
|
|||
return fileName;
|
||||
#endif
|
||||
|
||||
auto mainFileDialog = m_qmlRoot->findChild<QObject>("mainFileDialog").parent();
|
||||
QObject *mainFileDialog = m_qmlRoot->findChild<QObject>("mainFileDialog").parent();
|
||||
if (!mainFileDialog) {
|
||||
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;
|
||||
QObject::connect(this, &SystemController::fileDialogAccepted, &wait, &QEventLoop::quit);
|
||||
QObject::connect(this, &SystemController::fileDialogClosed, [&wait, &isFileDialogAccepted](const bool isAccepted) {
|
||||
isFileDialogAccepted = isAccepted;
|
||||
wait.quit();
|
||||
});
|
||||
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
|
||||
// patch for files containing spaces etc
|
||||
|
|
|
@ -11,15 +11,16 @@ class SystemController : public QObject
|
|||
public:
|
||||
explicit SystemController(const std::shared_ptr<Settings> &setting, QObject *parent = nullptr);
|
||||
|
||||
static void saveFile(QString fileName, const QString &data);
|
||||
|
||||
public slots:
|
||||
void saveFile(QString fileName, const QString &data);
|
||||
QString getFileName();
|
||||
QString getFileName(const QString &acceptLabel, const QString &nameFilter, const QString &selectedFile = "",
|
||||
const bool isSaveMode = false, const QString &defaultSuffix = "");
|
||||
|
||||
void setQmlRoot(QObject *qmlRoot);
|
||||
|
||||
signals:
|
||||
void fileDialogAccepted();
|
||||
void fileDialogRejected();
|
||||
void fileDialogClosed(const bool isAccepted);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
|
|
|
@ -72,23 +72,20 @@ DrawerType {
|
|||
imageSource: "qrc:/images/controls/share-2.svg"
|
||||
|
||||
onClicked: {
|
||||
var fileName = ""
|
||||
if (GC.isMobile()) {
|
||||
ExportController.saveFile(configFileName)
|
||||
fileName = configFileName
|
||||
} else {
|
||||
fileDialog.open()
|
||||
fileName = SystemController.getFileName(configCaption,
|
||||
qsTr("Config files (*" + configExtension + ")"),
|
||||
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/" + configFileName,
|
||||
true,
|
||||
configExtension)
|
||||
}
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: fileDialog
|
||||
acceptLabel: configCaption
|
||||
nameFilters: [ "Config files (*" + configExtension + ")" ]
|
||||
fileMode: FileDialog.SaveFile
|
||||
|
||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/" + configFileName
|
||||
defaultSuffix: configExtension
|
||||
onAccepted: {
|
||||
ExportController.saveFile(fileDialog.currentFile.toString())
|
||||
if (fileName !== "") {
|
||||
PageController.showBusyIndicator(true)
|
||||
ExportController.exportConfig(fileName)
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,31 +84,22 @@ PageType {
|
|||
text: qsTr("Make a backup")
|
||||
|
||||
onClicked: {
|
||||
var fileName = ""
|
||||
if (GC.isMobile()) {
|
||||
backupAppConfig("AmneziaVPN.backup")
|
||||
fileName = "AmneziaVPN.backup"
|
||||
} else {
|
||||
saveFileDialog.open()
|
||||
fileName = SystemController.getFileName(qsTr("Save backup file"),
|
||||
qsTr("Backup files (*.backup)"),
|
||||
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN",
|
||||
true,
|
||||
".backup")
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
if (fileName !== "") {
|
||||
PageController.showBusyIndicator(true)
|
||||
SettingsController.backupAppConfig(fileName)
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
|
||||
function backupAppConfig(fileName) {
|
||||
PageController.showBusyIndicator(true)
|
||||
SettingsController.backupAppConfig(fileName)
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
|
||||
BasicButtonType {
|
||||
|
@ -125,8 +116,13 @@ PageType {
|
|||
text: qsTr("Restore from backup")
|
||||
|
||||
onClicked: {
|
||||
PageController.setupFileDialogForBackup()
|
||||
SystemController.getFileName()
|
||||
var fileName = SystemController.getFileName(qsTr("Open backup file"),
|
||||
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"
|
||||
|
||||
onClicked: {
|
||||
var fileName = ""
|
||||
if (GC.isMobile()) {
|
||||
SettingsController.exportLogsFile("AmneziaVPN.log")
|
||||
fileName = "AmneziaVPN.log"
|
||||
} else {
|
||||
fileDialog.open()
|
||||
fileName = SystemController.getFileName(qsTr("Save logs"),
|
||||
qsTr("Logs files (*.log)"),
|
||||
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN",
|
||||
true,
|
||||
".log")
|
||||
}
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: fileDialog
|
||||
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())
|
||||
if (fileName !== "") {
|
||||
PageController.showBusyIndicator(true)
|
||||
SettingsController.exportLogsFile(fileName)
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -300,25 +300,19 @@ PageType {
|
|||
text: qsTr("Save site list")
|
||||
|
||||
clickedFunction: function() {
|
||||
var fileName = ""
|
||||
if (GC.isMobile()) {
|
||||
SitesController.exportSites("amezia_tunnel.json")
|
||||
fileName = "amnezia_sites.json"
|
||||
} else {
|
||||
saveFileDialog.open()
|
||||
fileName = SystemController.getFileName(qsTr("Save sites"),
|
||||
qsTr("Sites files (*.json)"),
|
||||
StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/amnezia_sites",
|
||||
true,
|
||||
".json")
|
||||
}
|
||||
}
|
||||
|
||||
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: {
|
||||
if (fileName !== "") {
|
||||
PageController.showBusyIndicator(true)
|
||||
SitesController.exportSites(saveFileDialog.currentFile.toString())
|
||||
SitesController.exportSites(fileName)
|
||||
moreActionsDrawer.close()
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
|
@ -377,8 +371,11 @@ PageType {
|
|||
text: qsTr("Replace site list")
|
||||
|
||||
clickedFunction: function() {
|
||||
PageController.setupFileDialogForSites(true)
|
||||
SystemController.getFileName()
|
||||
var fileName = SystemController.getFileName(qsTr("Open sites file"),
|
||||
qsTr("Sites files (*.json)"))
|
||||
if (fileName !== "") {
|
||||
importSitesDrawerContent.importSites(fileName, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,13 +386,22 @@ PageType {
|
|||
text: qsTr("Add imported sites to existing ones")
|
||||
|
||||
clickedFunction: function() {
|
||||
PageController.setupFileDialogForSites(false)
|
||||
SystemController.getFileName()
|
||||
importSitesDrawer.close()
|
||||
moreActionsDrawer.close()
|
||||
var fileName = SystemController.getFileName(qsTr("Open sites file"),
|
||||
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()
|
||||
moreActionsDrawer.close()
|
||||
}
|
||||
|
||||
DividerType {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,19 @@ It's okay as long as it's from someone you trust.")
|
|||
leftImageSource: "qrc:/images/controls/folder-open.svg"
|
||||
|
||||
clickedFunction: function() {
|
||||
PageController.setupFileDialogForConfig()
|
||||
SystemController.getFileName()
|
||||
var nameFilter = !ServersModel.getServersCount() ? "Config or backup files (*.vpn *.ovpn *.conf *.backup)" :
|
||||
"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() {
|
||||
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 {
|
||||
|
@ -234,10 +198,12 @@ Window {
|
|||
FileDialog {
|
||||
id: mainFileDialog
|
||||
|
||||
property var acceptFunction
|
||||
property bool isSaveMode: false
|
||||
|
||||
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