Files
qelectrotech-source-mirror/sources/ui/backuprestoredialog.h
T
ispyisail 1dd56df048 Keep three crash-recovery snapshots instead of overwriting one
Discussion #598, reviving PR #654. The crash-recovery backup written
every 20 minutes went to a single file. If the project was already in a
bad state when a backup ran, that bad state replaced the only recovery
copy.

QETProject now writes the backups in turn to three KAutoSaveFile slots
(BackupGenerations), so one bad write only replaces the oldest
snapshot. Scope is crash recovery only; the opt-in autosave is
unchanged.

After a crash, the recovery prompt groups the snapshots by project and
offers one row per project with a list to pick the snapshot to reopen,
newest selected by default. The snapshots not picked are deleted.

Ported onto current master: writeBackup() keeps the "skip if nothing
changed" check (bugtracker #273) and offerBackupFiles() keeps its place
after the stale-file filter and before the crash report (#901).

Tested with the backup interval shortened to 4 s (test build only):
after three changes, master holds one recovery file, overwritten each
time; this branch holds three, with 4, 5 and 6 folios. After killing
QET, the prompt lists the project; picking the oldest snapshot reopens
4 folios, the default reopens 6. Twice each. ctest 34/34 with and
without KDE Frameworks; the carried-over KAutoSaveFile test passes in
the nokde build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 10:45:25 +13:00

61 lines
1.9 KiB
C++

/*
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 <http://www.gnu.org/licenses/>.
*/
#ifndef BACKUPRESTOREDIALOG_H
#define BACKUPRESTOREDIALOG_H
#include <QDialog>
#include <QHash>
#include <QList>
#include <QString>
class KAutoSaveFile;
class QComboBox;
/**
@brief Lets the user pick, per crashed project, which recovery
generation to reopen when the crash-recovery rotation
(@see QETProject::writeBackup) left more than one snapshot behind.
*/
class BackupRestoreDialog : public QDialog
{
Q_OBJECT
public:
/// @param groups : managed project file path -> its stale recovery
/// generations, each list already sorted newest-first. Ownership of
/// the KAutoSaveFile objects stays with the caller.
explicit BackupRestoreDialog(
const QHash<QString, QList<KAutoSaveFile *>> &groups,
QWidget *parent = nullptr);
~BackupRestoreDialog() override;
/// Valid once accepted: one entry per project, the chosen generation
/// (defaults to the most recent one).
QList<KAutoSaveFile *> selectedFiles() const;
/// The generations the user did not pick; the caller should discard
/// (release + delete) these.
QList<KAutoSaveFile *> discardedFiles() const;
private:
QHash<QString, QList<KAutoSaveFile *>> m_groups;
QHash<QString, QComboBox *> m_combo_for_path;
};
#endif // BACKUPRESTOREDIALOG_H