Call to save updater, confirm final input of a day
This commit is contained in:
@@ -28,6 +28,10 @@ void Day::set_time_break(double value)
|
||||
time_break = value;
|
||||
}
|
||||
|
||||
void Day::set_validate(bool value) {
|
||||
validate = value;
|
||||
}
|
||||
|
||||
QTime Day::get_start()
|
||||
{
|
||||
return start;
|
||||
@@ -48,7 +52,8 @@ QJsonObject Day::to_json()
|
||||
QJsonObject obj{
|
||||
{KEY_START, start.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_END, end.toString(Qt::DateFormat::ISODate)},
|
||||
{KEY_BREAK, time_break}
|
||||
{KEY_BREAK, time_break},
|
||||
{KEY_VALIDATE, validate}
|
||||
};
|
||||
|
||||
return obj;
|
||||
@@ -61,6 +66,11 @@ Day Day::from_json(QJsonObject obj)
|
||||
result.start = QTime::fromString(obj[KEY_START].toString(), Qt::DateFormat::ISODate);
|
||||
result.end = QTime::fromString(obj[KEY_END].toString(), Qt::DateFormat::ISODate);
|
||||
result.time_break = obj[KEY_BREAK].toDouble();
|
||||
result.validate = obj[KEY_VALIDATE].toBool();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Day::get_validate() {
|
||||
return validate;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#define KEY_START "start"
|
||||
#define KEY_END "end"
|
||||
#define KEY_BREAK "break"
|
||||
#define KEY_VALIDATE "validate"
|
||||
|
||||
#include <QTime>
|
||||
#include <QJsonObject>
|
||||
@@ -16,6 +17,7 @@ private:
|
||||
QTime start;
|
||||
QTime end;
|
||||
double time_break;
|
||||
bool validate;
|
||||
|
||||
public:
|
||||
Day();
|
||||
@@ -23,10 +25,12 @@ public:
|
||||
void set_start(QTime value);
|
||||
void set_end(QTime value);
|
||||
void set_time_break(double value);
|
||||
void set_validate(bool);
|
||||
|
||||
QTime get_start();
|
||||
QTime get_end();
|
||||
double get_time_break();
|
||||
bool get_validate();
|
||||
QJsonObject to_json();
|
||||
|
||||
double get_total();
|
||||
|
||||
@@ -67,8 +67,9 @@ void MainWindow::init() {
|
||||
connect(ui->wed_button, &QPushButton::clicked, this, &MainWindow::edit);
|
||||
connect(ui->thu_button, &QPushButton::clicked, this, &MainWindow::edit);
|
||||
connect(ui->fri_button, &QPushButton::clicked, this, &MainWindow::edit);
|
||||
|
||||
highlightDayOfWeek();
|
||||
todayWeekNumber = QDate::currentDate().weekNumber();
|
||||
dayOfWeek = QDate::currentDate().dayOfWeek();
|
||||
saveLoaded = false;
|
||||
|
||||
if (QFile::exists(get_save_file_path())) {
|
||||
open_save();
|
||||
@@ -77,34 +78,42 @@ void MainWindow::init() {
|
||||
w.exec();
|
||||
week_template = w.get_result();
|
||||
}
|
||||
set_date_to_now();
|
||||
compute_time();
|
||||
if (saveLoaded) {
|
||||
set_date_to_now();
|
||||
compute_time();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::highlightDayOfWeek() {
|
||||
int dayOfWeek = QDate::currentDate().dayOfWeek();
|
||||
switch (dayOfWeek) {
|
||||
case 1: {
|
||||
ui->monLabel->setText(QString("> %1 <").arg(ui->monLabel->text()));
|
||||
break;
|
||||
ui->monLabel->setText("Lundi");
|
||||
ui->tueLabel->setText("Mardi");
|
||||
ui->wedLabel->setText("Mercredi");
|
||||
ui->thuLabel->setText("Jeudi");
|
||||
ui->friLabel->setText("Friday");
|
||||
if (todayWeekNumber == current_week.getWeekNumber()) {
|
||||
switch (dayOfWeek) {
|
||||
case 1: {
|
||||
ui->monLabel->setText(QString("> %1 <").arg(ui->monLabel->text()));
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
ui->tueLabel->setText(QString("> %1 <").arg(ui->tueLabel->text()));
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
ui->wedLabel->setText(QString("> %1 <").arg(ui->wedLabel->text()));
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
ui->thuLabel->setText(QString("> %1 <").arg(ui->thuLabel->text()));
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
ui->friLabel->setText(QString("> %1 <").arg(ui->friLabel->text()));
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
case 2: {
|
||||
ui->tueLabel->setText(QString("> %1 <").arg(ui->tueLabel->text()));
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
ui->wedLabel->setText(QString("> %1 <").arg(ui->wedLabel->text()));
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
ui->thuLabel->setText(QString("> %1 <").arg(ui->thuLabel->text()));
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
ui->friLabel->setText(QString("> %1 <").arg(ui->friLabel->text()));
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,18 +136,30 @@ void MainWindow::open_save() {
|
||||
for (QJsonValue val : arr) {
|
||||
weeks[val.toObject()["weekNumber"].toInt()] = Week::from_json(val.toObject());
|
||||
}
|
||||
saveLoaded = true;
|
||||
} else if (obj[KEY_SAVE_FILE_VERSION].toInt() < SAVE_FILE_VERSION) {
|
||||
QString updater = QCoreApplication::applicationDirPath() + "/save-updater.exe";
|
||||
if (QFile::exists(updater)) {
|
||||
QProcess* process = new QProcess(this);
|
||||
process->execute(updater, QStringList({"update"}));
|
||||
delete process;
|
||||
open_save();
|
||||
} else {
|
||||
panic_dialog("Cette application n'a pas pu démarrer car save-updater.exe est introuvable.\n"
|
||||
"La réinstallation de cette application peut corriger ce problème");
|
||||
}
|
||||
} else {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText("Le fichier de sauvegarde n'est pas à jour, "
|
||||
"des changements ont été apporté a la structure du fichier lors de la dernière mise à jour");
|
||||
msgBox.setInformativeText("Mettez à jour votre fichier de sauvegarde puis relancez l'application");
|
||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
msgBox.exec();
|
||||
QTimer::singleShot(0, this, &MainWindow::close);
|
||||
panic_dialog("Votre fichier de sauvegarde a été enregistré depuis une version plus récente de Chronos\n"
|
||||
"Mettez à jour Chronos pour pouvoir utiliser ce fichier");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::panic_dialog(QString text) {
|
||||
QMessageBox::critical(this, tr("Chronos"), text,
|
||||
QMessageBox::Ok, QMessageBox::Ok);
|
||||
QTimer::singleShot(0, this, &MainWindow::close);
|
||||
}
|
||||
|
||||
void MainWindow::save_to_file() {
|
||||
QJsonArray arr;
|
||||
for (Week w : weeks) {
|
||||
@@ -178,6 +199,7 @@ void MainWindow::compute_week_number(const QDateTime &dt) {
|
||||
save_to_file();
|
||||
}
|
||||
compute_time();
|
||||
highlightDayOfWeek();
|
||||
}
|
||||
|
||||
void MainWindow::compute_time() {
|
||||
@@ -190,6 +212,7 @@ void MainWindow::compute_time() {
|
||||
updateStartLabel();
|
||||
updateBreakLabel();
|
||||
updateEndLabel();
|
||||
updateValidIcon();
|
||||
|
||||
double late = 0.0;
|
||||
double overtime = 0.0;
|
||||
@@ -205,6 +228,14 @@ void MainWindow::compute_time() {
|
||||
ui->overtime_time_label->setText(Tools::double_to_string_time((overtime > 0.0) ? overtime : 0.0));
|
||||
}
|
||||
|
||||
void MainWindow::updateValidIcon() {
|
||||
ui->mondayValidate->setVisible(current_week.getMon().get_validate());
|
||||
ui->tuesdayValidate->setVisible(current_week.getTue().get_validate());
|
||||
ui->wednesdayValidate->setVisible(current_week.getWed().get_validate());
|
||||
ui->thurdayValidate->setVisible(current_week.getThu().get_validate());
|
||||
ui->fridayValidate->setVisible(current_week.getFri().get_validate());
|
||||
}
|
||||
|
||||
void MainWindow::updateStartLabel() {
|
||||
ui->monStartLabel->setText(current_week.getMon().get_start().toString("HH:mm"));
|
||||
ui->tueStartLabel->setText(current_week.getTue().get_start().toString("HH:mm"));
|
||||
@@ -254,7 +285,8 @@ void MainWindow::edit() {
|
||||
}
|
||||
|
||||
Day MainWindow::modify_value(Day d) {
|
||||
SetDayDialog sdd(d, this);
|
||||
bool isNotValidable = (current_week.getWeekNumber() > todayWeekNumber);
|
||||
SetDayDialog sdd(d, isNotValidable, this);
|
||||
int result = sdd.exec();
|
||||
if (result == QDialog::Accepted) {
|
||||
return sdd.get_result();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define KEY_TEMPLATE "template"
|
||||
#define KEY_WEEKS "weeks"
|
||||
#define SAVE_FILENAME "data.json"
|
||||
#define SAVE_FILE_VERSION 1
|
||||
#define SAVE_FILE_VERSION 2
|
||||
#define KEY_SAVE_FILE_VERSION "version"
|
||||
|
||||
#include <QMouseEvent>
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <QMapIterator>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QProcess>
|
||||
#include <QDir>
|
||||
|
||||
#include "week.h"
|
||||
#include "welcome.h"
|
||||
@@ -45,12 +47,14 @@ private:
|
||||
void init();
|
||||
void open_save();
|
||||
void save_to_file();
|
||||
void panic_dialog(QString text);
|
||||
|
||||
// UI Update
|
||||
void updateStartLabel();
|
||||
void updateBreakLabel();
|
||||
void updateEndLabel();
|
||||
void highlightDayOfWeek();
|
||||
void updateValidIcon();
|
||||
|
||||
QString get_save_file_path();
|
||||
Identifier get_identifier(QString objectName);
|
||||
@@ -60,6 +64,9 @@ private:
|
||||
Week current_week;
|
||||
QMap<int, Week> weeks;
|
||||
QMap<QString, Identifier> objectId;
|
||||
int todayWeekNumber;
|
||||
int dayOfWeek;
|
||||
bool saveLoaded;
|
||||
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "setdaydialog.h"
|
||||
#include "ui_setdaydialog.h"
|
||||
|
||||
SetDayDialog::SetDayDialog(Day d, QWidget *parent) :
|
||||
SetDayDialog::SetDayDialog(Day d, bool isNotValidable, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::SetDayDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->validateButton->setEnabled(!isNotValidable);
|
||||
this->d = d;
|
||||
init();
|
||||
}
|
||||
@@ -21,6 +22,7 @@ void SetDayDialog::init() {
|
||||
ui->break_edit->setValue(d.get_time_break());
|
||||
connect(ui->start_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->end_edit, &QTimeEdit::timeChanged, this, &SetDayDialog::compute_time);
|
||||
connect(ui->validateButton, &QPushButton::clicked, this, &SetDayDialog::validate);
|
||||
connect(ui->break_edit, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &SetDayDialog::compute_time);
|
||||
ui->total_label->setText(Tools::double_to_string_time(d.get_total()));
|
||||
}
|
||||
@@ -35,3 +37,8 @@ void SetDayDialog::compute_time() {
|
||||
Day SetDayDialog::get_result() {
|
||||
return d;
|
||||
}
|
||||
|
||||
void SetDayDialog::validate() {
|
||||
d.set_validate(true);
|
||||
accept();
|
||||
}
|
||||
|
||||
@@ -15,13 +15,14 @@ class SetDayDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SetDayDialog(Day d, QWidget *parent = nullptr);
|
||||
explicit SetDayDialog(Day d, bool isNotValidable, QWidget *parent = nullptr);
|
||||
~SetDayDialog();
|
||||
|
||||
Day get_result();
|
||||
|
||||
public slots:
|
||||
void compute_time();
|
||||
void validate();
|
||||
|
||||
private:
|
||||
Ui::SetDayDialog *ui;
|
||||
|
||||
@@ -65,7 +65,7 @@ void Welcome::edit() {
|
||||
}
|
||||
|
||||
Day Welcome::modify_value(Day d) {
|
||||
SetDayDialog sdd(d, this);
|
||||
SetDayDialog sdd(d, true, this);
|
||||
int result = sdd.exec();
|
||||
if (result == QDialog::Accepted) {
|
||||
return sdd.get_result();
|
||||
|
||||
Reference in New Issue
Block a user