[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-i18n-doc
Subject:    [krita/krita/4.3] libs/ui: Change autosave recovery dialog for existing files
From:       Agata Cacko <null () kde ! org>
Date:       2020-05-14 13:47:46
Message-ID: 20200514134746.87B921240475 () leptone ! kde ! org
[Download RAW message or body]

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     [License: 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/5149f63f60337eda8ffc5245b1249d7c4a3df1ed

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 <mutex>
 #include "kis_config_notifier.h"
@@ -1411,17 +1412,17 @@ bool KisDocument::openUrl(const QUrl &_url, OpenFlags flags)
             kisApp->hideSplashScreen();
             //qDebug() <<"asf=" << asf;
             // ## TODO compare timestamps ?
-            int res = 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 = dlg.result();
+
             switch (res) {
-            case QMessageBox::Yes :
+            case KisRecoverNamedAutosaveDialog::OpenAutosave :
                 original = file;
                 url.setPath(asf);
                 autosaveOpened = 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/dialogs/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 <cacko.azh@gmail.com>>
+ *
+ *  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-1301, USA.
+ */
+
+#include "KisRecoverNamedAutosaveDialog.h"
+#include "ui_KisRecoverNamedAutosaveDialog.h"
+
+#include <QTimer>
+#include <QElapsedTimer>
+#include <QThread>
+
+#include "kis_debug.h"
+#include "kis_image.h"
+#include "kis_composite_progress_proxy.h"
+
+#include <KisFileIconCreator.h>
+
+
+KisRecoverNamedAutosaveDialog::KisRecoverNamedAutosaveDialog(QWidget *parent, \
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(slotCancelRequested()));
+
+    ui->lblExplanation->setText(i18nc("Recover an autosave for an already existing \
file: explanation in the recovery dialog", +                                      "An \
autosave for this file exists. How do you want to proceed?\n" +                       \
"Warning: if you discard the autosave now, it will be removed.")); +
+    KisFileIconCreator creator;
+    QIcon mainFileIcon, autosaveFileIcon;
+
+    QSize size = ui->rbOpenAutosave->iconSize();
+    size = size*4;
+    bool success = creator.createFileIcon(mainFile, mainFileIcon, \
devicePixelRatioF()); +    if (success) {
+        ui->rbDiscardAutosave->setIcon(mainFileIcon);
+        ui->rbDiscardAutosave->setIconSize(size);
+    }
+    success = creator.createFileIcon(autosaveFile, autosaveFileIcon, \
devicePixelRatioF()); +    if (success) {
+        ui->rbOpenAutosave->setIcon(autosaveFileIcon);
+        ui->rbOpenAutosave->setIconSize(size);
+    }
+
+    ui->rbOpenAutosave->setChecked(true); // it should be selected by default
+
+}
+
+KisRecoverNamedAutosaveDialog::~KisRecoverNamedAutosaveDialog()
+{
+    delete ui;
+}
+
+void KisRecoverNamedAutosaveDialog::slotOkRequested()
+{
+    close();
+    setResult(ui->rbOpenAutosave->isChecked() ? OpenAutosave : OpenMainFile);
+}
+
+void KisRecoverNamedAutosaveDialog::slotCancelRequested()
+{
+    close();
+    setResult(Cancel);
+}
+
diff --git a/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.h \
b/libs/ui/dialogs/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 <cacko.azh@gmail.com>
+ *
+ *  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-1301, USA.
+ */
+
+#ifndef KIS_RECOVER_NAMED_AUTOSAVE_DIALOG_H
+#define KIS_RECOVER_NAMED_AUTOSAVE_DIALOG_H
+
+#include <QDialog>
+#include <QScopedPointer>
+#include "kis_types.h"
+
+namespace Ui {
+class KisRecoverNamedAutosaveDialog;
+}
+
+/**
+ * @brief The KisRecoverNamedAutosaveDialog class is a dialog to recover already \
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, often there is an autosave left behind + * in the directory of the file. \
This dialog allows choosing whether to open 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 = open the autosaved file
+     * OpenMainFile = discard the autosave and open the original file
+     * Cancel = 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 thumbnail)
+     */
+    explicit KisRecoverNamedAutosaveDialog(QWidget *parent = 0, QString mainFile = \
"", QString autosaveFile = ""); +    /**
+     * @brief ~KisRecoverNamedAutosaveDialog basic destructor
+     */
+    ~KisRecoverNamedAutosaveDialog() override;
+
+private Q_SLOTS:
+    /**
+     * @brief slotOkRequested sets the correct result of the dialog in case 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, depending 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/dialogs/KisRecoverNamedAutosaveDialog.ui new file mode 100644
index 0000000000..4c6a84e486
--- /dev/null
+++ b/libs/ui/dialogs/KisRecoverNamedAutosaveDialog.ui
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>KisRecoverNamedAutosaveDialog</class>
+ <widget class="QDialog" name="KisRecoverNamedAutosaveDialog">
+  <property name="windowModality">
+   <enum>Qt::WindowModal</enum>
+  </property>
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>308</width>
+    <height>115</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Krita</string>
+  </property>
+  <property name="modal">
+   <bool>true</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="lblExplanation">
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QRadioButton" name="rbOpenAutosave">
+     <property name="text">
+      <string>Open the autosave file</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QRadioButton" name="rbDiscardAutosave">
+     <property name="text">
+      <string>Discard autosave, open the main file</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QPushButton" name="btOk">
+       <property name="text">
+        <string>OK</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="btCancel">
+       <property name="text">
+        <string>Cancel</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic