removed the use of QFileDialog
This commit is contained in:
parent
8f6aa950cd
commit
e8862a3811
22 changed files with 224 additions and 164 deletions
|
|
@ -13,7 +13,6 @@
|
|||
#include "core/errorstrings.h"
|
||||
#include "fileUtilites.h"
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "platforms/android/android_controller.h"
|
||||
#include "platforms/android/androidutils.h"
|
||||
#endif
|
||||
#include "qrcodegen.hpp"
|
||||
|
|
@ -201,35 +200,9 @@ QList<QString> ExportController::getQrCodes()
|
|||
return m_qrCodes;
|
||||
}
|
||||
|
||||
void ExportController::saveFile(const QString &fileExtension, const QString &caption, const QString &fileName)
|
||||
void ExportController::saveFile(const QString &fileName)
|
||||
{
|
||||
#if defined Q_OS_IOS
|
||||
// ext.replace("*", "");
|
||||
// QString fileName = QDir::tempPath() + "/" + suggestedName;
|
||||
//
|
||||
// if (fileName.isEmpty())
|
||||
// return;
|
||||
// if (!fileName.endsWith(ext))
|
||||
// fileName.append(ext);
|
||||
//
|
||||
// QFile::remove(fileName);
|
||||
//
|
||||
// QFile save(fileName);
|
||||
// save.open(QIODevice::WriteOnly);
|
||||
// save.write(data.toUtf8());
|
||||
// save.close();
|
||||
//
|
||||
// QStringList filesToSend;
|
||||
// filesToSend.append(fileName);
|
||||
// MobileUtils::shareText(filesToSend);
|
||||
// return;
|
||||
#endif
|
||||
#if defined Q_OS_ANDROID
|
||||
AndroidController::instance()->shareConfig(m_config, "amnezia_config");
|
||||
return;
|
||||
#endif
|
||||
|
||||
FileUtilites::saveFile(fileExtension, caption, fileName, m_config);
|
||||
FileUtilites::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 &fileExtension, const QString &caption, const QString &fileName);
|
||||
void saveFile(const QString &fileName);
|
||||
|
||||
signals:
|
||||
void generateConfig(int type);
|
||||
|
|
|
|||
|
|
@ -85,23 +85,9 @@ ImportController::ImportController(const QSharedPointer<ServersModel> &serversMo
|
|||
#endif
|
||||
}
|
||||
|
||||
void ImportController::extractConfigFromFile()
|
||||
void ImportController::extractConfigFromFile(const QString &fileName)
|
||||
{
|
||||
QString fileName = FileUtilites::getFileName(Q_NULLPTR, tr("Open config file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
|
||||
"*.vpn *.ovpn *.conf");
|
||||
QFile file(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();
|
||||
}
|
||||
#endif
|
||||
QFile file(FileUtilites::getFileName(fileName));
|
||||
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
QString data = file.readAll();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void importConfig();
|
||||
void extractConfigFromFile();
|
||||
void extractConfigFromFile(const QString &fileName);
|
||||
void extractConfigFromData(QString &data);
|
||||
void extractConfigFromCode(QString code);
|
||||
bool extractConfigFromQr(const QByteArray &data);
|
||||
|
|
|
|||
|
|
@ -68,9 +68,9 @@ void SettingsController::openLogsFolder()
|
|||
Logger::openLogsFolder();
|
||||
}
|
||||
|
||||
void SettingsController::exportLogsFile()
|
||||
void SettingsController::exportLogsFile(const QString &fileName)
|
||||
{
|
||||
FileUtilites::saveFile(".log", tr("Save log"), "AmneziaVPN", Logger::getLogFile());
|
||||
FileUtilites::saveFile(fileName, Logger::getLogFile());
|
||||
}
|
||||
|
||||
void SettingsController::clearLogs()
|
||||
|
|
@ -79,35 +79,17 @@ void SettingsController::clearLogs()
|
|||
Logger::clearServiceLogs();
|
||||
}
|
||||
|
||||
void SettingsController::backupAppConfig()
|
||||
void SettingsController::backupAppConfig(const QString &fileName)
|
||||
{
|
||||
FileUtilites::saveFile(".backup", tr("Backup application config"), "AmneziaVPN", m_settings->backupAppConfig());
|
||||
FileUtilites::saveFile(fileName, m_settings->backupAppConfig());
|
||||
}
|
||||
|
||||
void SettingsController::restoreAppConfig()
|
||||
void SettingsController::restoreAppConfig(const QString &fileName)
|
||||
{
|
||||
QString fileName =
|
||||
FileUtilites::getFileName(Q_NULLPTR, tr("Open backup"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.backup");
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(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();
|
||||
}
|
||||
#endif
|
||||
QFile file(FileUtilites::getFileName(fileName));
|
||||
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
QByteArray data = file.readAll();
|
||||
|
||||
bool ok = m_settings->restoreAppConfig(data);
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@ public slots:
|
|||
void toggleLogging(bool enable);
|
||||
|
||||
void openLogsFolder();
|
||||
void exportLogsFile();
|
||||
void exportLogsFile(const QString &fileName);
|
||||
void clearLogs();
|
||||
|
||||
void backupAppConfig();
|
||||
void restoreAppConfig();
|
||||
void backupAppConfig(const QString &fileName);
|
||||
void restoreAppConfig(const QString &fileName);
|
||||
|
||||
QString getAppVersion();
|
||||
|
||||
|
|
|
|||
|
|
@ -79,28 +79,9 @@ void SitesController::removeSite(int index)
|
|||
emit finished(tr("Site removed: ") + hostname);
|
||||
}
|
||||
|
||||
void SitesController::importSites(bool replaceExisting)
|
||||
void SitesController::importSites(const QString &fileName, bool replaceExisting)
|
||||
{
|
||||
QString fileName =
|
||||
FileUtilites::getFileName(Q_NULLPTR, tr("Open sites file"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.json");
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(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();
|
||||
}
|
||||
#endif
|
||||
QFile file(FileUtilites::getFileName(fileName));
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
emit errorOccurred(tr("Can't open file: ") + fileName);
|
||||
|
|
@ -149,7 +130,7 @@ void SitesController::importSites(bool replaceExisting)
|
|||
emit finished(tr("Import completed"));
|
||||
}
|
||||
|
||||
void SitesController::exportSites()
|
||||
void SitesController::exportSites(const QString &fileName)
|
||||
{
|
||||
auto sites = m_sitesModel->getCurrentSites();
|
||||
|
||||
|
|
@ -163,7 +144,7 @@ void SitesController::exportSites()
|
|||
QJsonDocument jsonDocument(jsonArray);
|
||||
QByteArray jsonData = jsonDocument.toJson();
|
||||
|
||||
FileUtilites::saveFile(".json", tr("Export sites file"), "sites", jsonData);
|
||||
FileUtilites::saveFile(fileName, jsonData);
|
||||
|
||||
emit finished(tr("Export completed"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ public slots:
|
|||
void addSite(QString hostname);
|
||||
void removeSite(int index);
|
||||
|
||||
void importSites(bool replaceExisting);
|
||||
void exportSites();
|
||||
void importSites(const QString &fileName, bool replaceExisting);
|
||||
void exportSites(const QString &fileName);
|
||||
|
||||
signals:
|
||||
void errorOccurred(const QString &errorMessage);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ import QtQuick.Controls
|
|||
import QtQuick.Layouts
|
||||
import QtQuick.Dialogs
|
||||
|
||||
import QtCore
|
||||
|
||||
import SortFilterProxyModel 0.2
|
||||
|
||||
import PageEnum 1.0
|
||||
|
|
@ -67,8 +69,19 @@ DrawerType {
|
|||
text: qsTr("Share")
|
||||
imageSource: "qrc:/images/controls/share-2.svg"
|
||||
|
||||
onClicked: {
|
||||
ExportController.saveFile(configExtension, configCaption, configFileName)
|
||||
onClicked: fileDialog.open()
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,4 +146,14 @@ Item {
|
|||
color: "#EB5757"
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: root
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
onPressed: function(mouse) {
|
||||
textField.forceActiveFocus()
|
||||
mouse.accepted = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Dialogs
|
||||
|
||||
import QtCore
|
||||
|
||||
import PageEnum 1.0
|
||||
|
||||
|
|
@ -74,14 +77,36 @@ PageType {
|
|||
}
|
||||
|
||||
BasicButtonType {
|
||||
id: makeBackupButton
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 14
|
||||
|
||||
text: qsTr("Make a backup")
|
||||
|
||||
onClicked: {
|
||||
if (GC.isMobile()) {
|
||||
backupAppConfig("AmneziaVPN.backup")
|
||||
} else {
|
||||
saveFileDialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
SettingsController.backupAppConfig()
|
||||
SettingsController.backupAppConfig(fileName)
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
|
|
@ -100,9 +125,18 @@ PageType {
|
|||
text: qsTr("Restore from backup")
|
||||
|
||||
onClicked: {
|
||||
PageController.showBusyIndicator(true)
|
||||
SettingsController.restoreAppConfig()
|
||||
PageController.showBusyIndicator(false)
|
||||
openFileDialog.open()
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: openFileDialog
|
||||
acceptLabel: qsTr("Open backup file")
|
||||
nameFilters: [ "Backup files (*.backup)" ]
|
||||
onAccepted: {
|
||||
PageController.showBusyIndicator(true)
|
||||
SettingsController.restoreAppConfig(openFileDialog.selectedFile.toString())
|
||||
PageController.showBusyIndicator(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Dialogs
|
||||
|
||||
import QtCore
|
||||
|
||||
import PageEnum 1.0
|
||||
|
||||
|
|
@ -97,7 +100,20 @@ PageType {
|
|||
|
||||
image: "qrc:/images/controls/save.svg"
|
||||
|
||||
onClicked: SettingsController.exportLogsFile()
|
||||
onClicked: fileDialog.open()
|
||||
|
||||
FileDialog {
|
||||
id: fileDialog
|
||||
acceptLabel: qsTr("Save logs")
|
||||
nameFilters: [ "Logs files (*.log)" ]
|
||||
fileMode: FileDialog.SaveFile
|
||||
|
||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/AmneziaVPN"
|
||||
defaultSuffix: ".log"
|
||||
onAccepted: {
|
||||
ExportController.saveFile(fileDialog.currentFile.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CaptionTextType {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Dialogs
|
||||
|
||||
import QtCore
|
||||
|
||||
import SortFilterProxyModel 0.2
|
||||
|
||||
|
|
@ -41,6 +44,8 @@ PageType {
|
|||
allExceptSites
|
||||
]
|
||||
|
||||
property bool replaceExistingSites
|
||||
|
||||
QtObject {
|
||||
id: onlyForwardSites
|
||||
property string name: qsTr("Only the addresses in the list must be opened via VPN")
|
||||
|
|
@ -295,8 +300,21 @@ PageType {
|
|||
text: qsTr("Save site list")
|
||||
|
||||
clickedFunction: function() {
|
||||
SitesController.exportSites()
|
||||
moreActionsDrawer.close()
|
||||
saveFileDialog.open()
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: saveFileDialog
|
||||
acceptLabel: qsTr("Save sites")
|
||||
nameFilters: [ "Sites files (*.json)" ]
|
||||
fileMode: FileDialog.SaveFile
|
||||
|
||||
currentFile: StandardPaths.standardLocations(StandardPaths.DocumentsLocation) + "/sites"
|
||||
defaultSuffix: ".json"
|
||||
onAccepted: {
|
||||
SitesController.exportSites(saveFileDialog.currentFile.toString())
|
||||
moreActionsDrawer.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -331,6 +349,7 @@ PageType {
|
|||
anchors.bottom: parent.bottom
|
||||
|
||||
contentHeight: importSitesDrawerContent.height
|
||||
|
||||
ColumnLayout {
|
||||
id: importSitesDrawerContent
|
||||
|
||||
|
|
@ -351,9 +370,8 @@ PageType {
|
|||
text: qsTr("Replace site list")
|
||||
|
||||
clickedFunction: function() {
|
||||
SitesController.importSites(true)
|
||||
importSitesDrawer.close()
|
||||
moreActionsDrawer.close()
|
||||
root.replaceExistingSites = true
|
||||
openFileDialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -364,13 +382,23 @@ PageType {
|
|||
text: qsTr("Add imported sites to existing ones")
|
||||
|
||||
clickedFunction: function() {
|
||||
SitesController.importSites(false)
|
||||
importSitesDrawer.close()
|
||||
moreActionsDrawer.close()
|
||||
root.replaceExistingSites = false
|
||||
openFileDialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
DividerType {}
|
||||
|
||||
FileDialog {
|
||||
id: openFileDialog
|
||||
acceptLabel: qsTr("Open sites file")
|
||||
nameFilters: [ "Sites files (*.json)" ]
|
||||
onAccepted: {
|
||||
SitesController.importSites(openFileDialog.selectedFile.toString(), replaceExistingSites)
|
||||
importSitesDrawer.close()
|
||||
moreActionsDrawer.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,8 +70,17 @@ It's okay as long as it's from someone you trust.")
|
|||
leftImageSource: "qrc:/images/controls/folder-open.svg"
|
||||
|
||||
clickedFunction: function() {
|
||||
ImportController.extractConfigFromFile()
|
||||
goToPage(PageEnum.PageSetupWizardViewConfig)
|
||||
fileDialog.open()
|
||||
}
|
||||
|
||||
FileDialog {
|
||||
id: fileDialog
|
||||
acceptLabel: qsTr("Open config file")
|
||||
nameFilters: [ "Config files (*.vpn *.ovpn *.conf)" ]
|
||||
onAccepted: {
|
||||
ImportController.extractConfigFromFile(fileDialog.selectedFile.toString())
|
||||
goToPage(PageEnum.PageSetupWizardViewConfig)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
|
|
@ -175,7 +174,8 @@ void UiLogic::showOnStartup()
|
|||
void UiLogic::onUpdateAllPages()
|
||||
{
|
||||
for (auto logic : m_logicMap) {
|
||||
if (dynamic_cast<ClientInfoLogic*>(logic) || dynamic_cast<ClientManagementLogic*>(logic) || dynamic_cast<QrDecoderLogic*>(logic)) {
|
||||
if (dynamic_cast<ClientInfoLogic *>(logic) || dynamic_cast<ClientManagementLogic *>(logic)
|
||||
|| dynamic_cast<QrDecoderLogic *>(logic)) {
|
||||
continue;
|
||||
}
|
||||
logic->onUpdatePage();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue