added output of notifications/errors after installation/import
This commit is contained in:
parent
0411792ca5
commit
1092abe776
39 changed files with 488 additions and 303 deletions
|
@ -204,25 +204,25 @@ QList<QString> ExportController::getQrCodes()
|
|||
void ExportController::saveFile()
|
||||
{
|
||||
#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;
|
||||
// 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");
|
||||
|
|
|
@ -149,9 +149,7 @@ void ImportController::importConfig()
|
|||
if (credentials.isValid() || m_config.contains(config_key::containers)) {
|
||||
m_serversModel->addServer(m_config);
|
||||
|
||||
if (!m_config.value(config_key::containers).toArray().isEmpty()) {
|
||||
m_serversModel->setDefaultServerIndex(m_serversModel->getServersCount() - 1);
|
||||
}
|
||||
m_serversModel->setDefaultServerIndex(m_serversModel->getServersCount() - 1);
|
||||
|
||||
emit importFinished();
|
||||
} else {
|
||||
|
|
|
@ -88,14 +88,20 @@ void InstallController::installServer(DockerContainer container, QJsonObject &co
|
|||
QMap<DockerContainer, QJsonObject> installedContainers;
|
||||
ErrorCode errorCode =
|
||||
serverController.getAlreadyInstalledContainers(m_currentlyInstalledServerCredentials, installedContainers);
|
||||
|
||||
QString finishMessage = "";
|
||||
|
||||
if (!installedContainers.contains(container)) {
|
||||
errorCode = serverController.setupContainer(m_currentlyInstalledServerCredentials, container, config);
|
||||
installedContainers.insert(container, config);
|
||||
finishMessage = ContainerProps::containerHumanNames().value(container) + tr(" installed successfully. ");
|
||||
} else {
|
||||
finishMessage =
|
||||
ContainerProps::containerHumanNames().value(container) + tr(" is already installed on the server. ");
|
||||
}
|
||||
|
||||
bool isInstalledContainerFound = false;
|
||||
if (!installedContainers.isEmpty()) {
|
||||
isInstalledContainerFound = true;
|
||||
if (installedContainers.size() > 1) {
|
||||
finishMessage += tr("\nAlready installed containers were found on the server. "
|
||||
"All installed containers have been added to the application");
|
||||
}
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
|
@ -117,7 +123,7 @@ void InstallController::installServer(DockerContainer container, QJsonObject &co
|
|||
m_serversModel->addServer(server);
|
||||
m_serversModel->setDefaultServerIndex(m_serversModel->getServersCount() - 1);
|
||||
|
||||
emit installServerFinished(false); // todo incorrect notification about found containers
|
||||
emit installServerFinished(finishMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -135,16 +141,19 @@ void InstallController::installContainer(DockerContainer container, QJsonObject
|
|||
QMap<DockerContainer, QJsonObject> installedContainers;
|
||||
ErrorCode errorCode = serverController.getAlreadyInstalledContainers(serverCredentials, installedContainers);
|
||||
|
||||
bool isInstalledContainerFound = false;
|
||||
if (!installedContainers.isEmpty()) {
|
||||
isInstalledContainerFound = true;
|
||||
}
|
||||
QString finishMessage = "";
|
||||
|
||||
if (!installedContainers.contains(container)) {
|
||||
errorCode = serverController.setupContainer(serverCredentials, container, config);
|
||||
installedContainers.insert(container, config);
|
||||
finishMessage = ContainerProps::containerHumanNames().value(container) + tr(" installed successfully. ");
|
||||
} else {
|
||||
finishMessage =
|
||||
ContainerProps::containerHumanNames().value(container) + tr(" is already installed on the server. ");
|
||||
}
|
||||
|
||||
bool isInstalledContainerAddedToGui = false;
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
for (auto iterator = installedContainers.begin(); iterator != installedContainers.end(); iterator++) {
|
||||
auto modelIndex = m_containersModel->index(iterator.key());
|
||||
|
@ -153,10 +162,17 @@ void InstallController::installContainer(DockerContainer container, QJsonObject
|
|||
if (containerConfig.isEmpty()) {
|
||||
m_containersModel->setData(m_containersModel->index(iterator.key()), iterator.value(),
|
||||
ContainersModel::Roles::ConfigRole);
|
||||
if (container != iterator.key()) { // skip the newly installed container
|
||||
isInstalledContainerAddedToGui = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isInstalledContainerAddedToGui) {
|
||||
finishMessage += tr("\nAlready installed containers were found on the server. "
|
||||
"All installed containers have been added to the application");
|
||||
}
|
||||
|
||||
emit installContainerFinished(false); // todo incorrect notification about found containers
|
||||
emit installContainerFinished(finishMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -233,11 +249,55 @@ void InstallController::updateContainer(QJsonObject config)
|
|||
emit installationErrorOccurred(errorString(errorCode));
|
||||
}
|
||||
|
||||
void InstallController::removeCurrentlyProcessedServer()
|
||||
{
|
||||
int serverIndex = m_serversModel->getCurrentlyProcessedServerIndex();
|
||||
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
||||
|
||||
m_serversModel->removeServer();
|
||||
emit removeCurrentlyProcessedServerFinished(tr("Server '") + serverName + tr("' was removed"));
|
||||
}
|
||||
|
||||
void InstallController::removeAllContainers()
|
||||
{
|
||||
int serverIndex = m_serversModel->getCurrentlyProcessedServerIndex();
|
||||
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
||||
|
||||
ErrorCode errorCode = m_containersModel->removeAllContainers();
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit removeAllContainersFinished(tr("All containers from server '") + serverName + ("' have been removed"));
|
||||
return;
|
||||
}
|
||||
emit installationErrorOccurred(errorString(errorCode));
|
||||
}
|
||||
|
||||
void InstallController::removeCurrentlyProcessedContainer()
|
||||
{
|
||||
int serverIndex = m_serversModel->getCurrentlyProcessedServerIndex();
|
||||
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
||||
|
||||
int container = m_containersModel->getCurrentlyProcessedContainerIndex();
|
||||
QString containerName = m_containersModel->data(container, ContainersModel::Roles::NameRole).toString();
|
||||
|
||||
ErrorCode errorCode = m_containersModel->removeCurrentlyProcessedContainer();
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit removeCurrentlyProcessedContainerFinished(containerName + tr(" has been removed from the server '")
|
||||
+ serverName + "'");
|
||||
return;
|
||||
}
|
||||
emit installationErrorOccurred(errorString(errorCode));
|
||||
}
|
||||
|
||||
QRegularExpression InstallController::ipAddressPortRegExp()
|
||||
{
|
||||
return Utils::ipAddressPortRegExp();
|
||||
}
|
||||
|
||||
QRegularExpression InstallController::ipAddressRegExp()
|
||||
{
|
||||
return Utils::ipAddressRegExp();
|
||||
}
|
||||
|
||||
void InstallController::setCurrentlyInstalledServerCredentials(const QString &hostName, const QString &userName,
|
||||
const QString &secretData)
|
||||
{
|
||||
|
|
|
@ -28,18 +28,27 @@ public slots:
|
|||
|
||||
void updateContainer(QJsonObject config);
|
||||
|
||||
void removeCurrentlyProcessedServer();
|
||||
void removeAllContainers();
|
||||
void removeCurrentlyProcessedContainer();
|
||||
|
||||
QRegularExpression ipAddressPortRegExp();
|
||||
QRegularExpression ipAddressRegExp();
|
||||
|
||||
void mountSftpDrive(const QString &port, const QString &password, const QString &username);
|
||||
|
||||
signals:
|
||||
void installContainerFinished(bool isInstalledContainerFound);
|
||||
void installServerFinished(bool isInstalledContainerFound);
|
||||
void installContainerFinished(QString finishMessage);
|
||||
void installServerFinished(QString finishMessage);
|
||||
|
||||
void updateContainerFinished();
|
||||
|
||||
void scanServerFinished(bool isInstalledContainerFound);
|
||||
|
||||
void removeCurrentlyProcessedServerFinished(QString finishedMessage);
|
||||
void removeAllContainersFinished(QString finishedMessage);
|
||||
void removeCurrentlyProcessedContainerFinished(QString finishedMessage);
|
||||
|
||||
void installationErrorOccurred(QString errorMessage);
|
||||
|
||||
void serverAlreadyExists(int serverIndex);
|
||||
|
@ -57,7 +66,9 @@ private:
|
|||
|
||||
bool m_shouldCreateServer;
|
||||
|
||||
#ifndef Q_OS_IOS
|
||||
QList<QSharedPointer<QProcess>> m_sftpMountProcesses;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // INSTALLCONTROLLER_H
|
||||
|
|
|
@ -84,7 +84,7 @@ signals:
|
|||
void replaceStartPage();
|
||||
|
||||
void showErrorMessage(QString errorMessage);
|
||||
void showInfoMessage(QString message);
|
||||
void showNotificationMessage(QString message);
|
||||
|
||||
void showBusyIndicator(bool visible);
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
#include "protocolSettingsController.h"
|
||||
|
||||
ProtocolSettingsController::ProtocolSettingsController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
const std::shared_ptr<Settings> &settings, QObject *parent)
|
||||
: QObject(parent), m_serversModel(serversModel), m_containersModel(containersModel), m_settings(settings)
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray ProtocolSettingsController::getOpenVpnConfig()
|
||||
{
|
||||
auto containerIndex = m_containersModel->index(m_containersModel->getCurrentlyProcessedContainerIndex());
|
||||
auto config = m_containersModel->data(containerIndex, ContainersModel::Roles::ConfigRole);
|
||||
return QByteArray();
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef PROTOCOLSETTINGSCONTROLLER_H
|
||||
#define PROTOCOLSETTINGSCONTROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "containers/containers_defs.h"
|
||||
#include "core/defs.h"
|
||||
#include "ui/models/containers_model.h"
|
||||
#include "ui/models/servers_model.h"
|
||||
|
||||
class ProtocolSettingsController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProtocolSettingsController(const QSharedPointer<ServersModel> &serversModel,
|
||||
const QSharedPointer<ContainersModel> &containersModel,
|
||||
const std::shared_ptr<Settings> &settings,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
QByteArray getOpenVpnConfig();
|
||||
|
||||
signals:
|
||||
|
||||
private:
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
QSharedPointer<ContainersModel> m_containersModel;
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
};
|
||||
|
||||
#endif // PROTOCOLSETTINGSCONTROLLER_H
|
|
@ -84,9 +84,10 @@ void SettingsController::restoreAppConfig()
|
|||
Utils::getFileName(Q_NULLPTR, tr("Open backup"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.backup");
|
||||
|
||||
// todo error processing
|
||||
if (fileName.isEmpty())
|
||||
if (fileName.isEmpty()) {
|
||||
emit changeSettingsErrorOccurred(tr("Backup file is empty"));
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
@ -94,7 +95,10 @@ void SettingsController::restoreAppConfig()
|
|||
|
||||
bool ok = m_settings->restoreAppConfig(data);
|
||||
if (ok) {
|
||||
// emit uiLogic()->showWarningMessage(tr("Can't import config, file is corrupted."));
|
||||
m_serversModel->resetModel();
|
||||
emit restoreBackupFinished();
|
||||
} else {
|
||||
emit changeSettingsErrorOccurred(tr("Backup file is corrupted"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,4 +110,5 @@ QString SettingsController::getAppVersion()
|
|||
void SettingsController::clearSettings()
|
||||
{
|
||||
m_settings->clearSettings();
|
||||
m_serversModel->resetModel();
|
||||
}
|
||||
|
|
|
@ -47,6 +47,9 @@ signals:
|
|||
void secondaryDnsChanged();
|
||||
void loggingStateChanged();
|
||||
|
||||
void restoreBackupFinished();
|
||||
void changeSettingsErrorOccurred(QString errorMessage);
|
||||
|
||||
private:
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
QSharedPointer<ContainersModel> m_containersModel;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue