filedialog for qml moved to main.qml
This commit is contained in:
parent
4ab006f065
commit
c166327835
11 changed files with 213 additions and 52 deletions
|
@ -10,6 +10,8 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
@ -130,6 +132,7 @@ void AmneziaApplication::init()
|
||||||
&ConnectionController::closeConnection);
|
&ConnectionController::closeConnection);
|
||||||
|
|
||||||
m_engine->load(url);
|
m_engine->load(url);
|
||||||
|
m_systemController->setQmlRoot(m_engine->rootObjects().value(0));
|
||||||
|
|
||||||
if (m_settings->isSaveLogs()) {
|
if (m_settings->isSaveLogs()) {
|
||||||
if (!Logger::init()) {
|
if (!Logger::init()) {
|
||||||
|
@ -345,4 +348,7 @@ void AmneziaApplication::initControllers()
|
||||||
|
|
||||||
m_sitesController.reset(new SitesController(m_settings, m_vpnConnection, m_sitesModel));
|
m_sitesController.reset(new SitesController(m_settings, m_vpnConnection, m_sitesModel));
|
||||||
m_engine->rootContext()->setContextProperty("SitesController", m_sitesController.get());
|
m_engine->rootContext()->setContextProperty("SitesController", m_sitesController.get());
|
||||||
|
|
||||||
|
m_systemController.reset(new SystemController(m_settings));
|
||||||
|
m_engine->rootContext()->setContextProperty("SystemController", m_systemController.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "ui/controllers/pageController.h"
|
#include "ui/controllers/pageController.h"
|
||||||
#include "ui/controllers/settingsController.h"
|
#include "ui/controllers/settingsController.h"
|
||||||
#include "ui/controllers/sitesController.h"
|
#include "ui/controllers/sitesController.h"
|
||||||
|
#include "ui/controllers/systemController.h"
|
||||||
#include "ui/models/containers_model.h"
|
#include "ui/models/containers_model.h"
|
||||||
#include "ui/models/languageModel.h"
|
#include "ui/models/languageModel.h"
|
||||||
#include "ui/models/protocols/cloakConfigModel.h"
|
#include "ui/models/protocols/cloakConfigModel.h"
|
||||||
|
@ -114,6 +115,7 @@ private:
|
||||||
QScopedPointer<ExportController> m_exportController;
|
QScopedPointer<ExportController> m_exportController;
|
||||||
QScopedPointer<SettingsController> m_settingsController;
|
QScopedPointer<SettingsController> m_settingsController;
|
||||||
QScopedPointer<SitesController> m_sitesController;
|
QScopedPointer<SitesController> m_sitesController;
|
||||||
|
QScopedPointer<SystemController> m_systemController;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AMNEZIA_APPLICATION_H
|
#endif // AMNEZIA_APPLICATION_H
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QQuickItem>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
#include "core/errorstrings.h"
|
#include "core/errorstrings.h"
|
||||||
|
@ -87,7 +88,11 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
||||||
|
|
||||||
void ImportController::extractConfigFromFile(const QString &fileName)
|
void ImportController::extractConfigFromFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile file(FileUtilites::getFileName(fileName));
|
QQuickItem *obj = findChild<QQuickItem *>("saveFileDialog");
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
|
@ -103,6 +103,10 @@ 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;
|
||||||
|
|
||||||
|
|
103
client/ui/controllers/systemController.cpp
Normal file
103
client/ui/controllers/systemController.cpp
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
#include "systemController.h"
|
||||||
|
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QQuickItem>
|
||||||
|
#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
|
||||||
|
|
||||||
|
SystemController::SystemController(const std::shared_ptr<Settings> &settings, QObject *parent)
|
||||||
|
: QObject(parent), m_settings(settings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemController::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 SystemController::getFileName()
|
||||||
|
{
|
||||||
|
auto mainFileDialog = m_qmlRoot->findChild<QObject>("mainFileDialog").parent();
|
||||||
|
if (!mainFileDialog) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
QMetaObject::invokeMethod(mainFileDialog, "open", Qt::DirectConnection);
|
||||||
|
|
||||||
|
QEventLoop wait;
|
||||||
|
QObject::connect(this, &SystemController::fileDialogAccepted, &wait, &QEventLoop::quit);
|
||||||
|
wait.exec();
|
||||||
|
|
||||||
|
auto fileName = mainFileDialog->property("selectedFile").toString();
|
||||||
|
|
||||||
|
#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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemController::setQmlRoot(QObject *qmlRoot)
|
||||||
|
{
|
||||||
|
m_qmlRoot = qmlRoot;
|
||||||
|
}
|
30
client/ui/controllers/systemController.h
Normal file
30
client/ui/controllers/systemController.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef SYSTEMCONTROLLER_H
|
||||||
|
#define SYSTEMCONTROLLER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
class SystemController : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SystemController(const std::shared_ptr<Settings> &setting, QObject *parent = nullptr);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void saveFile(QString fileName, const QString &data);
|
||||||
|
QString getFileName();
|
||||||
|
|
||||||
|
void setQmlRoot(QObject *qmlRoot);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void fileDialogAccepted();
|
||||||
|
void fileDialogRejected();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Settings> m_settings;
|
||||||
|
|
||||||
|
QObject *m_qmlRoot;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SYSTEMCONTROLLER_H
|
|
@ -125,18 +125,8 @@ PageType {
|
||||||
text: qsTr("Restore from backup")
|
text: qsTr("Restore from backup")
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
openFileDialog.open()
|
PageController.setupFileDialogForBackup()
|
||||||
}
|
SystemController.getFileName()
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: openFileDialog
|
|
||||||
acceptLabel: qsTr("Open backup file")
|
|
||||||
nameFilters: [ "Backup files (*.backup)" ]
|
|
||||||
onAccepted: {
|
|
||||||
PageController.showBusyIndicator(true)
|
|
||||||
SettingsController.restoreAppConfig(openFileDialog.selectedFile.toString())
|
|
||||||
PageController.showBusyIndicator(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ PageType {
|
||||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN"
|
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN"
|
||||||
defaultSuffix: ".log"
|
defaultSuffix: ".log"
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
ExportController.saveFile(fileDialog.currentFile.toString())
|
SettingsController.exportLogsFile(fileDialog.currentFile.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,6 @@ PageType {
|
||||||
allExceptSites
|
allExceptSites
|
||||||
]
|
]
|
||||||
|
|
||||||
property bool replaceExistingSites
|
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: onlyForwardSites
|
id: onlyForwardSites
|
||||||
property string name: qsTr("Only the addresses in the list must be opened via VPN")
|
property string name: qsTr("Only the addresses in the list must be opened via VPN")
|
||||||
|
@ -303,7 +301,7 @@ PageType {
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
if (Qt.platform.os === "ios") {
|
if (Qt.platform.os === "ios") {
|
||||||
ExportController.saveFile("amezia_tunnel.json")
|
SitesController.exportSites("amezia_tunnel.json")
|
||||||
} else {
|
} else {
|
||||||
saveFileDialog.open()
|
saveFileDialog.open()
|
||||||
}
|
}
|
||||||
|
@ -311,6 +309,7 @@ PageType {
|
||||||
|
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: saveFileDialog
|
id: saveFileDialog
|
||||||
|
objectName: saveFileDialog
|
||||||
acceptLabel: qsTr("Save sites")
|
acceptLabel: qsTr("Save sites")
|
||||||
nameFilters: [ "Sites files (*.json)" ]
|
nameFilters: [ "Sites files (*.json)" ]
|
||||||
fileMode: FileDialog.SaveFile
|
fileMode: FileDialog.SaveFile
|
||||||
|
@ -378,8 +377,8 @@ PageType {
|
||||||
text: qsTr("Replace site list")
|
text: qsTr("Replace site list")
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
root.replaceExistingSites = true
|
PageController.setupFileDialogForSites(true)
|
||||||
openFileDialog.open()
|
SystemController.getFileName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,25 +389,14 @@ PageType {
|
||||||
text: qsTr("Add imported sites to existing ones")
|
text: qsTr("Add imported sites to existing ones")
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
root.replaceExistingSites = false
|
PageController.setupFileDialogForSites(false)
|
||||||
openFileDialog.open()
|
SystemController.getFileName()
|
||||||
|
importSitesDrawer.close()
|
||||||
|
moreActionsDrawer.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DividerType {}
|
DividerType {}
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: openFileDialog
|
|
||||||
acceptLabel: qsTr("Open sites file")
|
|
||||||
nameFilters: [ "Sites files (*.json)" ]
|
|
||||||
onAccepted: {
|
|
||||||
PageController.showBusyIndicator(true)
|
|
||||||
SitesController.importSites(openFileDialog.selectedFile.toString(), replaceExistingSites)
|
|
||||||
importSitesDrawer.close()
|
|
||||||
moreActionsDrawer.close()
|
|
||||||
PageController.showBusyIndicator(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,28 +65,13 @@ It's okay as long as it's from someone you trust.")
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 16
|
Layout.topMargin: 16
|
||||||
|
|
||||||
text: qsTr("File with connection settings or backup")
|
text: !ServersModel.getServersCount() ? qsTr("File with connection settings or backup") : qsTr("File with connection settings")
|
||||||
rightImageSource: "qrc:/images/controls/chevron-right.svg"
|
rightImageSource: "qrc:/images/controls/chevron-right.svg"
|
||||||
leftImageSource: "qrc:/images/controls/folder-open.svg"
|
leftImageSource: "qrc:/images/controls/folder-open.svg"
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
fileDialog.open()
|
PageController.setupFileDialogForConfig()
|
||||||
}
|
SystemController.getFileName()
|
||||||
|
|
||||||
FileDialog {
|
|
||||||
id: fileDialog
|
|
||||||
acceptLabel: qsTr("Open config file")
|
|
||||||
nameFilters: [ "Config or backup files (*.vpn *.ovpn *.conf *.backup)" ]
|
|
||||||
onAccepted: {
|
|
||||||
if (fileDialog.selectedFile.toString().indexOf(".backup") != -1) {
|
|
||||||
PageController.showBusyIndicator(true)
|
|
||||||
SettingsController.restoreAppConfig(fileDialog.selectedFile.toString())
|
|
||||||
PageController.showBusyIndicator(false)
|
|
||||||
} else {
|
|
||||||
ImportController.extractConfigFromFile(fileDialog.selectedFile.toString())
|
|
||||||
PageController.goToPage(PageEnum.PageSetupWizardViewConfig)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import QtQuick
|
||||||
import QtQuick.Window
|
import QtQuick.Window
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
import QtQuick.Dialogs
|
||||||
|
|
||||||
import PageEnum 1.0
|
import PageEnum 1.0
|
||||||
|
|
||||||
|
@ -10,6 +11,7 @@ import "Controls2"
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: root
|
id: root
|
||||||
|
objectName: "mainWindow"
|
||||||
visible: true
|
visible: true
|
||||||
width: GC.screenWidth
|
width: GC.screenWidth
|
||||||
height: GC.screenHeight
|
height: GC.screenHeight
|
||||||
|
@ -79,6 +81,42 @@ 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 {
|
||||||
|
@ -192,4 +230,14 @@ Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDialog {
|
||||||
|
id: mainFileDialog
|
||||||
|
|
||||||
|
property var acceptFunction
|
||||||
|
|
||||||
|
objectName: "mainFileDialog"
|
||||||
|
|
||||||
|
onAccepted: acceptFunction()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue