Git commit 5149f63f60337eda8ffc5245b1249d7c4a3df1ed by Agata Cacko. Committed on 14/05/2020 at 13:45. Pushed by tymond into branch 'krita/4.3'. Change autosave recovery dialog for existing files Before this commit, the autosave recovery dialog was confusing for our users. This commit makes the message hopefully more clear. The user can choose which file to open (and is provided with thumbnails so they are more informed what both of the files contain) and there is a warning that discarding the autosave file means losing it. Warning: this commit contains new strings to translate. CCMAIL:kde-i18n-doc@kde.org M +2 -0 libs/ui/CMakeLists.txt M +7 -6 libs/ui/KisDocument.cpp A +83 -0 libs/ui/dialogs/KisRecoverNamedAutosaveDialog.cpp [Licen= se: GPL (v2+)] A +92 -0 libs/ui/dialogs/KisRecoverNamedAutosaveDialog.h [License= : GPL (v2+)] A +66 -0 libs/ui/dialogs/KisRecoverNamedAutosaveDialog.ui https://invent.kde.org/kde/krita/commit/5149f63f60337eda8ffc5245b1249d7c4a3= df1ed diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt index 77d31bbeb8..377552eee4 100644 --- a/libs/ui/CMakeLists.txt +++ b/libs/ui/CMakeLists.txt @@ -70,6 +70,7 @@ set(kritaui_LIB_SRCS dialogs/KisSessionManagerDialog.cpp dialogs/KisNewWindowLayoutDialog.cpp dialogs/KisDlgChangeCloneSource.cpp + dialogs/KisRecoverNamedAutosaveDialog.cpp flake/kis_node_dummies_graph.cpp flake/kis_dummies_facade_base.cpp flake/kis_dummies_facade.cpp @@ -530,6 +531,7 @@ ki18n_wrap_ui(kritaui_LIB_SRCS = brushhud/kis_dlg_brush_hud_config.ui dialogs/kis_delayed_save_dialog.ui + dialogs/KisRecoverNamedAutosaveDialog.ui input/config/kis_input_configuration_page.ui input/config/kis_edit_profiles_dialog.ui input/config/kis_input_configuration_page_item.ui diff --git a/libs/ui/KisDocument.cpp b/libs/ui/KisDocument.cpp index e777c9f081..0742c444ad 100644 --- a/libs/ui/KisDocument.cpp +++ b/libs/ui/KisDocument.cpp @@ -119,6 +119,7 @@ #include "kis_guides_config.h" #include "kis_image_barrier_lock_adapter.h" #include "KisReferenceImagesLayer.h" +#include "dialogs/KisRecoverNamedAutosaveDialog.h" = #include #include "kis_config_notifier.h" @@ -1411,17 +1412,17 @@ bool KisDocument::openUrl(const QUrl &_url, OpenFla= gs flags) kisApp->hideSplashScreen(); //qDebug() <<"asf=3D" << asf; // ## TODO compare timestamps ? - int res =3D QMessageBox::warning(0, - i18nc("@title:window", "Krita"), - i18n("An autosaved file exists = for this document.\nDo you want to open the autosaved file instead?"), - QMessageBox::Yes | QMessageBox:= :No | QMessageBox::Cancel, QMessageBox::Yes); + KisRecoverNamedAutosaveDialog dlg(0, file, asf); + dlg.exec(); + int res =3D dlg.result(); + switch (res) { - case QMessageBox::Yes : + case KisRecoverNamedAutosaveDialog::OpenAutosave : original =3D file; url.setPath(asf); autosaveOpened =3D true; break; - case QMessageBox::No : + case KisRecoverNamedAutosaveDialog::OpenMainFile : KisUsageLogger::log(QString("Removing autosave file: %1").= arg(asf)); QFile::remove(asf); break; diff --git a/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.cpp b/libs/ui/di= alogs/KisRecoverNamedAutosaveDialog.cpp new file mode 100644 index 0000000000..c2a408ec97 --- /dev/null +++ b/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2020 Agata Cacko > + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-13= 01, USA. + */ + +#include "KisRecoverNamedAutosaveDialog.h" +#include "ui_KisRecoverNamedAutosaveDialog.h" + +#include +#include +#include + +#include "kis_debug.h" +#include "kis_image.h" +#include "kis_composite_progress_proxy.h" + +#include + + +KisRecoverNamedAutosaveDialog::KisRecoverNamedAutosaveDialog(QWidget *pare= nt, QString mainFile, QString autosaveFile) + : QDialog(parent), + ui(new Ui::KisRecoverNamedAutosaveDialog) +{ + + ui->setupUi(this); + + connect(ui->btOk, SIGNAL(clicked()), this, SLOT(slotOkRequested())); + connect(ui->btCancel, SIGNAL(clicked()), this, SLOT(slotCancelRequeste= d())); + + ui->lblExplanation->setText(i18nc("Recover an autosave for an already = existing file: explanation in the recovery dialog", + "An autosave for this file exists. H= ow do you want to proceed?\n" + "Warning: if you discard the autosav= e now, it will be removed.")); + + KisFileIconCreator creator; + QIcon mainFileIcon, autosaveFileIcon; + + QSize size =3D ui->rbOpenAutosave->iconSize(); + size =3D size*4; + bool success =3D creator.createFileIcon(mainFile, mainFileIcon, device= PixelRatioF()); + if (success) { + ui->rbDiscardAutosave->setIcon(mainFileIcon); + ui->rbDiscardAutosave->setIconSize(size); + } + success =3D creator.createFileIcon(autosaveFile, autosaveFileIcon, dev= icePixelRatioF()); + if (success) { + ui->rbOpenAutosave->setIcon(autosaveFileIcon); + ui->rbOpenAutosave->setIconSize(size); + } + + ui->rbOpenAutosave->setChecked(true); // it should be selected by defa= ult + +} + +KisRecoverNamedAutosaveDialog::~KisRecoverNamedAutosaveDialog() +{ + delete ui; +} + +void KisRecoverNamedAutosaveDialog::slotOkRequested() +{ + close(); + setResult(ui->rbOpenAutosave->isChecked() ? OpenAutosave : OpenMainFil= e); +} + +void KisRecoverNamedAutosaveDialog::slotCancelRequested() +{ + close(); + setResult(Cancel); +} + diff --git a/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.h b/libs/ui/dial= ogs/KisRecoverNamedAutosaveDialog.h new file mode 100644 index 0000000000..d3ea7d5636 --- /dev/null +++ b/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2020 Agata Cacko + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-13= 01, USA. + */ + +#ifndef KIS_RECOVER_NAMED_AUTOSAVE_DIALOG_H +#define KIS_RECOVER_NAMED_AUTOSAVE_DIALOG_H + +#include +#include +#include "kis_types.h" + +namespace Ui { +class KisRecoverNamedAutosaveDialog; +} + +/** + * @brief The KisRecoverNamedAutosaveDialog class is a dialog to recover a= lready existing files from autosave + * + * When the user saves a file, then works on it a bit more, and then Krita= crashes or something else + * unexpected happens that makes it impossible to close Krita correctly, o= ften there is an autosave left behind + * in the directory of the file. This dialog allows choosing whether to op= en the autosaved file or the original file. + */ +class KisRecoverNamedAutosaveDialog : public QDialog +{ + Q_OBJECT + +public: + /** + * @brief The ResultType enum represents three possible decisions for = the user + * + * OpenAutosave =3D open the autosaved file + * OpenMainFile =3D discard the autosave and open the original file + * Cancel =3D Do nothing + */ + enum ResultType { + OpenAutosave, + OpenMainFile, + Cancel + }; + +public: + /** + * @brief KisRecoverNamedAutosaveDialog basic constructor + * @param parent parent widget + * @param mainFile path to the main file (used to create a thumbnail) + * @param autosaveFile path to the autosaved file (used to create a th= umbnail) + */ + explicit KisRecoverNamedAutosaveDialog(QWidget *parent =3D 0, QString = mainFile =3D "", QString autosaveFile =3D ""); + /** + * @brief ~KisRecoverNamedAutosaveDialog basic destructor + */ + ~KisRecoverNamedAutosaveDialog() override; + +private Q_SLOTS: + /** + * @brief slotOkRequested sets the correct result of the dialog in cas= e the user pressed OK button and closes the dialog + * + * This is a slot for button pressed signal for the OK button. + * It sets the result to either OpenMainFile or OpenAutosave, dependin= g on which radio button is checked. + * Then it closes the dialog. + */ + void slotOkRequested(); + /** + * @brief slotCancelRequested sets the correct result of the dialog in= case the user pressed Cancel button and closes the dialog + * + * This is a slot for button pressed signal for the Cancel button. + * It sets the result to Cancel. + * Then it closes the dialog. + */ + void slotCancelRequested(); + + +private: + Ui::KisRecoverNamedAutosaveDialog *ui; + +}; + +#endif // KIS_RECOVER_NAMED_AUTOSAVE_DIALOG_H diff --git a/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.ui b/libs/ui/dia= logs/KisRecoverNamedAutosaveDialog.ui new file mode 100644 index 0000000000..4c6a84e486 --- /dev/null +++ b/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.ui @@ -0,0 +1,66 @@ + + + KisRecoverNamedAutosaveDialog + + + Qt::WindowModal + + + + 0 + 0 + 308 + 115 + + + + Krita + + + true + + + + + + + + + + + + + Open the autosave file + + + + + + + Discard autosave, open the main file + + + + + + + + + OK + + + + + + + Cancel + + + + + + + + + +