diff --git a/cmake/qet_compilation_vars.cmake b/cmake/qet_compilation_vars.cmake index 207a2719b..88366a91a 100644 --- a/cmake/qet_compilation_vars.cmake +++ b/cmake/qet_compilation_vars.cmake @@ -632,6 +632,8 @@ set(QET_SRC_FILES ${QET_DIR}/sources/ui/diagrampropertieseditordockwidget.h ${QET_DIR}/sources/ui/diagramselection.cpp ${QET_DIR}/sources/ui/diagramselection.h + ${QET_DIR}/sources/ui/backupdialog.cpp + ${QET_DIR}/sources/ui/backupdialog.h ${QET_DIR}/sources/ui/dialogwaiting.cpp ${QET_DIR}/sources/ui/dialogwaiting.h ${QET_DIR}/sources/ui/dynamicelementtextitemeditor.cpp diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index f8f2a3b1d..da9c09083 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -37,6 +37,7 @@ #include "recentfiles.h" #include "ui/bomexportdialog.h" #include "ui/diagrampropertieseditordockwidget.h" +#include "ui/backupdialog.h" #include "ui/dialogwaiting.h" #include "undocommand/addelementtextcommand.h" #include "undocommand/rotateselectioncommand.h" @@ -47,7 +48,9 @@ #include "TerminalStrip/ui/addterminalstripitemdialog.h" #include "wiringlistexport.h" #include "ui/terminalnumberingdialog.h" +#include #include +#include #ifdef BUILD_WITHOUT_KF5 # include "ui/nokde/kautosavefile.h" #else @@ -1187,6 +1190,16 @@ bool QETDiagramEditor::openAndAddProject( QETApp::projectsRecentFiles() -> fileWasOpened(filepath); addProject(project); DialogWaiting::dropInstance(); + + BackupDialog backup_dialog(this); + if (backup_dialog.exec() == QDialog::Accepted) + { + QString backup_path = filepath_info.absolutePath() + QDir::separator() + + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm") + "_" + + filepath_info.fileName(); + QFile::copy(filepath, backup_path); + } + return true; } diff --git a/sources/ui/backupdialog.cpp b/sources/ui/backupdialog.cpp new file mode 100644 index 000000000..7f4134d63 --- /dev/null +++ b/sources/ui/backupdialog.cpp @@ -0,0 +1,63 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ + +#include "backupdialog.h" + +#include +#include +#include +#include + +/** + @brief BackupDialog::BackupDialog + @param parent parent widget +*/ +BackupDialog::BackupDialog(QWidget *parent) : + QDialog(parent) +{ + setWindowTitle(tr("Créer une copie de sauvegarde ?", "window title")); + setFixedSize(450, 100); + + auto main_layout = new QVBoxLayout(this); + + auto label = new QLabel( + tr("Souhaitez-vous créer une copie de sauvegarde ?", + "dialog message")); + label->setWordWrap(true); + main_layout->addWidget(label); + + main_layout->addStretch(); + + auto button_layout = new QHBoxLayout(); + button_layout->addStretch(); + + auto yes_button = new QPushButton(tr("Oui", "yes button")); + auto no_button = new QPushButton(tr("Non", "no button")); + + button_layout->addWidget(yes_button); + button_layout->addWidget(no_button); + main_layout->addLayout(button_layout); + + connect(yes_button, &QPushButton::clicked, this, &QDialog::accept); + connect(no_button, &QPushButton::clicked, this, &QDialog::reject); +} + +/** + @brief BackupDialog::~BackupDialog +*/ +BackupDialog::~BackupDialog() = default; diff --git a/sources/ui/backupdialog.h b/sources/ui/backupdialog.h new file mode 100644 index 000000000..35b5d713c --- /dev/null +++ b/sources/ui/backupdialog.h @@ -0,0 +1,32 @@ +/* + Copyright 2006-2026 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ + +#ifndef BACKUPDIALOG_H +#define BACKUPDIALOG_H + +#include + +class BackupDialog : public QDialog +{ + Q_OBJECT + public: + explicit BackupDialog(QWidget *parent = nullptr); + ~BackupDialog() override; +}; + +#endif // BACKUPDIALOG_H