From 57161b530271d57be64affbe27bec1d563139439 Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Thu, 10 Sep 2020 00:58:01 +0200
Subject: [PATCH] Confirm contact deletion

Fixes #63.
---
 briar-gtk/briar_gtk/actions/window.py         |  7 +++--
 briar-gtk/briar_gtk/containers/main_window.py | 29 +++++++++++++++----
 briar-gtk/data/ui/chat_menu.ui                |  2 +-
 briar-gtk/po/ar.po                            |  8 ++++-
 briar-gtk/po/briar-gtk.pot                    |  6 ++++
 briar-gtk/po/de.po                            |  8 ++++-
 briar-gtk/po/es.po                            |  6 ++++
 7 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/briar-gtk/briar_gtk/actions/window.py b/briar-gtk/briar_gtk/actions/window.py
index 7751e60..d759f44 100644
--- a/briar-gtk/briar_gtk/actions/window.py
+++ b/briar-gtk/briar_gtk/actions/window.py
@@ -36,7 +36,8 @@ class WindowActions(Actions):
         )
 
     def _setup_delete_contact_action(self):
-        self._setup_action("delete-contact", None, self._delete_contact)
+        self._setup_action("delete-contact-dialog", None,
+                           self._delete_contact_dialog)
 
     def _setup_open_about_page_action(self):
         self._setup_action("open-about-dialog", None, self._open_about_page)
@@ -57,8 +58,8 @@ class WindowActions(Actions):
             self.widget.current_container.show_sidebar()
 
     # pylint: disable=unused-argument
-    def _delete_contact(self, action, parameter):
-        self.widget.current_container.delete_contact()
+    def _delete_contact_dialog(self, action, parameter):
+        self.widget.current_container.open_delete_contact_dialog()
 
     # pylint: disable=unused-argument
     def _open_about_page(self, action, parameter):
diff --git a/briar-gtk/briar_gtk/containers/main_window.py b/briar-gtk/briar_gtk/containers/main_window.py
index 3e7c316..86a5df0 100644
--- a/briar-gtk/briar_gtk/containers/main_window.py
+++ b/briar-gtk/briar_gtk/containers/main_window.py
@@ -5,7 +5,8 @@
 # Initial version based on GNOME Fractal
 # https://gitlab.gnome.org/GNOME/fractal/-/tags/4.2.2
 
-from gi.repository import GLib
+from gettext import gettext as _
+from gi.repository import GLib, Gtk
 
 from briar_wrapper.models.contacts import Contacts
 
@@ -88,13 +89,31 @@ class MainWindowContainer(Container):
         self.contact_name_label.set_text("")
         self._current_contact_id = 0
 
-    def delete_contact(self):
+    def open_delete_contact_dialog(self):
         if self._current_contact_id == 0:
             raise Exception("Can't delete contact with ID 0")
 
-        Contacts(APP().api).delete(self._current_contact_id)
-        self._refresh_contacts()
-        self.show_sidebar()
+        confirmation_dialog = Gtk.MessageDialog(
+            transient_for=APP().window,
+            flags=Gtk.DialogFlags.MODAL,
+            message_type=Gtk.MessageType.WARNING,
+            buttons=Gtk.ButtonsType.OK_CANCEL,
+            text=_("Confirm Contact Deletion"),
+        )
+        confirmation_dialog.format_secondary_text(
+            _("Are you sure that you want to remove this contact and "
+              "all messages exchanged with this contact?")
+        )
+
+        confirmation_dialog.connect("response", self._delete_contact)
+        confirmation_dialog.show_all()
+
+    def _delete_contact(self, widget, response_id):
+        if response_id == Gtk.ResponseType.OK:
+            Contacts(APP().api).delete(self._current_contact_id)
+            self._refresh_contacts()
+            self.show_sidebar()
+        widget.destroy()
 
     def _prepare_chat_view(self, contact_name):
         if self._no_chat_opened():
diff --git a/briar-gtk/data/ui/chat_menu.ui b/briar-gtk/data/ui/chat_menu.ui
index 619ecbc..1f4be7a 100644
--- a/briar-gtk/data/ui/chat_menu.ui
+++ b/briar-gtk/data/ui/chat_menu.ui
@@ -26,7 +26,7 @@
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">False</property>
-            <property name="action_name">win.delete-contact</property>
+            <property name="action_name">win.delete-contact-dialog</property>
             <property name="text" translatable="yes">Delete contact</property>
           </object>
           <packing>
diff --git a/briar-gtk/po/ar.po b/briar-gtk/po/ar.po
index 3fb8ce2..0181ef8 100644
--- a/briar-gtk/po/ar.po
+++ b/briar-gtk/po/ar.po
@@ -92,7 +92,7 @@ msgid "Next"
 msgstr "التالي"
 
 msgid "Delete contact"
-msgstr ""
+msgstr "حذف جهة الإتصال"
 
 msgid "Password"
 msgstr "كلمة السّر"
@@ -152,6 +152,12 @@ msgstr ""
 msgid "Myself"
 msgstr ""
 
+msgid "Confirm Contact Deletion"
+msgstr "تأكيد حذف جهة الإتصال"
+
+msgid "Are you sure that you want to remove this contact and all messages exchanged with this contact?"
+msgstr "هل أنت متأكد/ة من أنك تريد حذف جهة الإتصال هذه وكل الرسائل المتبادلة بينكما؟"
+
 msgid "Please enter a password"
 msgstr ""
 
diff --git a/briar-gtk/po/briar-gtk.pot b/briar-gtk/po/briar-gtk.pot
index 38b008a..3242ea4 100644
--- a/briar-gtk/po/briar-gtk.pot
+++ b/briar-gtk/po/briar-gtk.pot
@@ -162,6 +162,12 @@ msgstr ""
 msgid "Myself"
 msgstr ""
 
+msgid "Confirm Contact Deletion"
+msgstr ""
+
+msgid "Are you sure that you want to remove this contact and all messages exchanged with this contact?"
+msgstr ""
+
 msgid "Please enter a password"
 msgstr ""
 
diff --git a/briar-gtk/po/de.po b/briar-gtk/po/de.po
index 69ae041..e33a587 100644
--- a/briar-gtk/po/de.po
+++ b/briar-gtk/po/de.po
@@ -92,7 +92,7 @@ msgid "Next"
 msgstr "Weiter"
 
 msgid "Delete contact"
-msgstr "Kontakt entfernen"
+msgstr "Kontakt löschen"
 
 msgid "Password"
 msgstr "Passwort"
@@ -152,6 +152,12 @@ msgstr "Briar-Funktionalität von"
 msgid "Myself"
 msgstr "Ich"
 
+msgid "Confirm Contact Deletion"
+msgstr "Löschen des Kontakts bestätigen"
+
+msgid "Are you sure that you want to remove this contact and all messages exchanged with this contact?"
+msgstr "Bist du sicher, dass du diesen Kontakt und alle dazugehörigen Nachrichten löschen möchtest?"
+
 msgid "Please enter a password"
 msgstr "Bitte gib ein Passwort ein"
 
diff --git a/briar-gtk/po/es.po b/briar-gtk/po/es.po
index 1c9cfd1..cef368a 100644
--- a/briar-gtk/po/es.po
+++ b/briar-gtk/po/es.po
@@ -152,6 +152,12 @@ msgstr "Funcionalidad de Briar de"
 msgid "Myself"
 msgstr "Yo"
 
+msgid "Confirm Contact Deletion"
+msgstr "Confirmar eliminación de contacto"
+
+msgid "Are you sure that you want to remove this contact and all messages exchanged with this contact?"
+msgstr "¿Seguro que quieres eliminar este contacto y todos los mensajes intercambiados entre vosotros?"
+
 msgid "Please enter a password"
 msgstr "Por favor, introduce una contraseña"
 
-- 
GitLab