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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue