starting cloud save

This commit is contained in:
Aurélie Delhaie
2022-01-09 21:21:18 +01:00
parent c49966b47c
commit ffebb3c7d7
26 changed files with 983 additions and 213 deletions

BIN
sources/.DS_Store vendored

Binary file not shown.

View File

@@ -1,7 +1,7 @@
#ifndef ABOUTBOX_H
#define ABOUTBOX_H
#define VERSION "2.0.0"
#define VERSION "2.1.0"
#include <QDialog>
#include <QMouseEvent>

View File

@@ -3,7 +3,7 @@
#include <QDialog>
#include "breakpoint.h"
#include "models/breakpoint.h"
namespace Ui {
class BreakDialog;

View File

@@ -0,0 +1,32 @@
#include "configurationdialog.h"
#include "ui_configurationdialog.h"
ConfigurationDialog::ConfigurationDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ConfigurationDialog)
{
ui->setupUi(this);
RefreshField();
}
ConfigurationDialog::~ConfigurationDialog()
{
delete ui;
}
void ConfigurationDialog::RefreshField()
{
Settings* s = mng.GetConfiguration();
ui->cloud_url->setText(s->GetCloudUrl());
ui->cloud_Email->setText(s->GetCloudEmail());
ui->cloud_password->setText(s->GetCloudPassword());
ui->cloud_agent->setText(s->GetCloudAgent());
ui->cloud_enable->setCheckState(s->GetCloudEnabled() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
bool cloudDisabled = !s->GetCloudEnabled();
ui->cloud_url->setDisabled(cloudDisabled);
ui->cloud_Email->setDisabled(cloudDisabled);
ui->cloud_password->setDisabled(cloudDisabled);
ui->cloud_agent->setDisabled(cloudDisabled);
}

View File

@@ -0,0 +1,28 @@
#ifndef CONFIGURATIONDIALOG_H
#define CONFIGURATIONDIALOG_H
#include <QDialog>
#include "configurationmanager.h"
namespace Ui {
class ConfigurationDialog;
}
class ConfigurationDialog : public QDialog
{
Q_OBJECT
public:
explicit ConfigurationDialog(QWidget *parent = nullptr);
~ConfigurationDialog();
private:
Ui::ConfigurationDialog *ui;
ConfigurationManager mng;
void RefreshField();
};
#endif // CONFIGURATIONDIALOG_H

View File

@@ -0,0 +1,51 @@
#include "configurationmanager.h"
ConfigurationManager::ConfigurationManager()
{
if (QFile::exists(GetPath())) {
QFile* file = new QFile(GetPath());
file->open(QIODevice::ReadOnly);
auto json = QString(file->readAll());
file->close();
delete file;
QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object();
this->s = Settings::FromJSON(obj);
} else {
this->s = new Settings();
Save();
}
}
ConfigurationManager::~ConfigurationManager()
{
delete s;
}
Settings *ConfigurationManager::GetConfiguration()
{
return s;
}
QString ConfigurationManager::GetPath() {
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
if (!QDir(path).exists()) {
QDir().mkpath(path);
}
path += "/";
if (!QDir(path).exists()) {
QDir().mkpath(path);
}
path += FILENAME;
return path;
}
void ConfigurationManager::Save() {
QJsonDocument doc(s->ToJSON());
QFile *f = new QFile(GetPath());
if (f->open(QIODevice::WriteOnly)) {
f->write(doc.toJson());
f->close();
}
delete f;
}

View File

@@ -0,0 +1,27 @@
#ifndef CONFIGURATIONMANAGER_H
#define CONFIGURATIONMANAGER_H
#define FILENAME "settings.json"
#include <QString>
#include <QDir>
#include <QStandardPaths>
#include <QJsonObject>
#include <QJsonDocument>
#include "models/settings.h"
class ConfigurationManager
{
private:
Settings *s;
QString GetPath();
void Save();
public:
ConfigurationManager();
~ConfigurationManager();
Settings* GetConfiguration();
};
#endif // CONFIGURATIONMANAGER_H

View File

@@ -22,8 +22,8 @@
#include <QProcess>
#include <QDir>
#include "week.h"
#include "year.h"
#include "models/week.h"
#include "models/year.h"
#include "welcome.h"
#include "tools.h"
#include "aboutbox.h"

View File

@@ -0,0 +1,96 @@
#include "settings.h"
Settings::Settings()
{
this->cloudEnabled = false;
this->cloudEmail = "";
this->cloudPassword = "";
this->cloudUrl = "";
this->cloudAgent = DEFAULT_AGENT_KEY;
}
Settings* Settings::FromJSON(QJsonObject obj)
{
Settings *s = new Settings();
if (obj["cloud"].isObject())
{
QJsonObject cloud = obj["cloud"].toObject();
s->cloudEnabled = cloud["enabled"].toBool(false);
s->cloudUrl = cloud["url"].toString("");
s->cloudEmail = cloud["email"].toString("");
s->cloudPassword = cloud["password"].toString("");
s->cloudAgent = cloud["agent"].toString(DEFAULT_AGENT_KEY);
}
return s;
}
QJsonObject Settings::ToJSON()
{
QJsonObject s;
QJsonObject cloud;
cloud["enabled"] = this->cloudEnabled;
cloud["url"] = this->cloudUrl;
cloud["email"] = this->cloudEmail;
cloud["password"] = this->cloudPassword;
cloud["agent"] = this->cloudAgent;
s["cloud"] = cloud;
return s;
}
bool Settings::GetCloudEnabled()
{
return this->cloudEnabled;
}
QString Settings::GetCloudUrl()
{
return this->cloudUrl;
}
QString Settings::GetCloudEmail()
{
return this->cloudEmail;
}
QString Settings::GetCloudPassword()
{
return this->cloudPassword;
}
QString Settings::GetCloudAgent()
{
return this->cloudAgent;
}
QString Settings::GetCloudAgentDefault()
{
return DEFAULT_AGENT;
}
void Settings::SetCloudEnabled(bool enabled)
{
this->cloudEnabled = enabled;
}
void Settings::SetCloudUrl(QString url)
{
this->cloudUrl = url;
}
void Settings::SetCloudEmail(QString email)
{
this->cloudEmail = email;
}
void Settings::SetCloudPassword(QString password)
{
this->cloudPassword = password;
}
void Settings::SetCloudAgent(QString agent)
{
this->cloudAgent = agent;
}

43
sources/models/settings.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#ifdef _WIN32
#define DEFAULT_AGENT "cagent.exe"
#else
#define DEFAULT_AGENT "cagent"
#endif
#define DEFAULT_AGENT_KEY "<default>"
#include <QString>
#include <QJsonObject>
class Settings
{
private:
bool cloudEnabled;
QString cloudUrl;
QString cloudEmail;
QString cloudPassword;
QString cloudAgent;
public:
Settings();
static Settings* FromJSON(QJsonObject obj);
QJsonObject ToJSON();
bool GetCloudEnabled();
QString GetCloudUrl();
QString GetCloudEmail();
QString GetCloudPassword();
QString GetCloudAgent();
QString GetCloudAgentDefault();
void SetCloudEnabled(bool enabled);
void SetCloudUrl(QString url);
void SetCloudEmail(QString email);
void SetCloudPassword(QString password);
void SetCloudAgent(QString agent);
};
#endif // SETTINGS_H

View File

@@ -4,10 +4,10 @@
#include <QDialog>
#include <QMouseEvent>
#include "day.h"
#include "models/day.h"
#include "tools.h"
#include "breakdialog.h"
#include "breakpoint.h"
#include "models/breakpoint.h"
namespace Ui {
class SetDayDialog;

View File

@@ -6,8 +6,8 @@
#include <QMouseEvent>
#include <math.h>
#include "week.h"
#include "day.h"
#include "models/week.h"
#include "models/day.h"
#include "tools.h"
#include "setdaydialog.h"