From 405a1de6f1728c69b884af5dee0cb311c9027fc1 Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Tue, 8 Sep 2020 19:11:34 +0200
Subject: [PATCH] Directly delete contacts, reliably

Fixes #60. Now we need to either implement #63 or #64.
---
 briar-gtk/briar_gtk/containers/main_window.py | 15 +----
 .../briar_gtk/widgets/undo_notification.py    | 58 -------------------
 briar-gtk/po/ar.po                            |  6 --
 briar-gtk/po/briar-gtk.pot                    |  6 --
 briar-gtk/po/de.po                            | 12 ++--
 briar-gtk/po/es.po                            | 12 ++--
 6 files changed, 15 insertions(+), 94 deletions(-)
 delete mode 100644 briar-gtk/briar_gtk/widgets/undo_notification.py

diff --git a/briar-gtk/briar_gtk/containers/main_window.py b/briar-gtk/briar_gtk/containers/main_window.py
index 911181d..5ead622 100644
--- a/briar-gtk/briar_gtk/containers/main_window.py
+++ b/briar-gtk/briar_gtk/containers/main_window.py
@@ -15,7 +15,6 @@ from briar_gtk.containers.private_chat import PrivateChatContainer
 from briar_gtk.define import APP
 from briar_gtk.widgets.about_dialog import AboutDialogWidget
 from briar_gtk.widgets.contact_row import ContactRowWidget
-from briar_gtk.widgets.undo_notification import UndoNotification
 
 
 class MainWindowContainer(Container):
@@ -93,17 +92,9 @@ class MainWindowContainer(Container):
         if self._current_contact_id == 0:
             raise Exception("Can't delete contact with ID 0")
 
-        def _timeout_action():
-            Contacts(APP().api).delete(self._current_contact_id)
-            self._refresh_contacts()
-            self.show_sidebar()
-
-        notification = UndoNotification(
-            _("Contact will be deleted"),
-            _timeout_action)
-        self.add_overlay(notification)
-        notification.show()
-        notification.set_reveal_child(True)
+        Contacts(APP().api).delete(self._current_contact_id)
+        self._refresh_contacts()
+        self.show_sidebar()
 
     def _prepare_chat_view(self, contact_name):
         if self._no_chat_opened():
diff --git a/briar-gtk/briar_gtk/widgets/undo_notification.py b/briar-gtk/briar_gtk/widgets/undo_notification.py
deleted file mode 100644
index ce5b3ce..0000000
--- a/briar-gtk/briar_gtk/widgets/undo_notification.py
+++ /dev/null
@@ -1,58 +0,0 @@
-# Copyright (c) 2020 Nico Alt
-# Copyright (c) 2014-2020 Cedric Bellegarde <cedric.bellegarde@adishatz.org>
-# SPDX-License-Identifier: AGPL-3.0-only
-# License-Filename: LICENSE.md
-#
-# Initial version based on GNOME Lollypop
-# https://gitlab.gnome.org/World/lollypop/-/blob/1.3.6/lollypop/app_notification.py
-
-from gettext import gettext as _
-from gi.repository import Gtk, GLib, Pango
-
-
-class UndoNotification(Gtk.Revealer):
-
-    _TIMEOUT = 5000
-
-    _execute_action = True
-
-    def __init__(self, message, timeout_action):
-        """
-        Implementation of
-        https://developer.gnome.org/hig/stable/in-app-notifications.html.en
-
-        Parameters
-        ==========
-        message: str
-        timeout_action: callback
-        """
-        Gtk.Revealer.__init__(self)
-        widget = Gtk.Grid()
-        widget.get_style_context().add_class("app-notification")
-        widget.set_column_spacing(5)
-        label = Gtk.Label.new(message)
-        label.set_line_wrap_mode(Pango.WrapMode.WORD)
-        label.set_line_wrap(True)
-        widget.add(label)
-
-        button = Gtk.Button.new()
-        button.set_label(_("Undo"))
-        button.connect("clicked", self._on_undo_clicked)
-        button.set_property("valign", Gtk.Align.START)
-        widget.add(button)
-        widget.show_all()
-        self.add(widget)
-        self.set_property("halign", Gtk.Align.CENTER)
-        self.set_property("valign", Gtk.Align.START)
-        GLib.timeout_add(self._TIMEOUT, self._on_destroy, timeout_action)
-
-    # pylint: disable=unused-argument
-    def _on_undo_clicked(self, button, action=None):
-        self._execute_action = False
-        self.destroy()
-
-    # pylint: disable=unused-argument
-    def _on_destroy(self, action):
-        if self._execute_action:
-            action()
-        self.destroy()
diff --git a/briar-gtk/po/ar.po b/briar-gtk/po/ar.po
index cbcdc1b..3fb8ce2 100644
--- a/briar-gtk/po/ar.po
+++ b/briar-gtk/po/ar.po
@@ -152,12 +152,6 @@ msgstr ""
 msgid "Myself"
 msgstr ""
 
-msgid "Undo"
-msgstr ""
-
-msgid "Contact will be deleted"
-msgstr ""
-
 msgid "Please enter a password"
 msgstr ""
 
diff --git a/briar-gtk/po/briar-gtk.pot b/briar-gtk/po/briar-gtk.pot
index 453ed04..38b008a 100644
--- a/briar-gtk/po/briar-gtk.pot
+++ b/briar-gtk/po/briar-gtk.pot
@@ -162,12 +162,6 @@ msgstr ""
 msgid "Myself"
 msgstr ""
 
-msgid "Undo"
-msgstr ""
-
-msgid "Contact will be deleted"
-msgstr ""
-
 msgid "Please enter a password"
 msgstr ""
 
diff --git a/briar-gtk/po/de.po b/briar-gtk/po/de.po
index eeee68b..69ae041 100644
--- a/briar-gtk/po/de.po
+++ b/briar-gtk/po/de.po
@@ -152,12 +152,6 @@ msgstr "Briar-Funktionalität von"
 msgid "Myself"
 msgstr "Ich"
 
-msgid "Undo"
-msgstr "Rückgängig machen"
-
-msgid "Contact will be deleted"
-msgstr "Kontakt wird gelöscht"
-
 msgid "Please enter a password"
 msgstr "Bitte gib ein Passwort ein"
 
@@ -178,3 +172,9 @@ msgstr "Bitte gib einen Link ein"
 
 msgid "Enter your contact's link, not your own"
 msgstr "Gib den Link deines Kontakts ein, nicht deinen eigenen"
+
+#~ msgid "Undo"
+#~ msgstr "Rückgängig machen"
+
+#~ msgid "Contact will be deleted"
+#~ msgstr "Kontakt wird gelöscht"
diff --git a/briar-gtk/po/es.po b/briar-gtk/po/es.po
index a947760..1c9cfd1 100644
--- a/briar-gtk/po/es.po
+++ b/briar-gtk/po/es.po
@@ -152,12 +152,6 @@ msgstr "Funcionalidad de Briar de"
 msgid "Myself"
 msgstr "Yo"
 
-msgid "Undo"
-msgstr "Deshacer"
-
-msgid "Contact will be deleted"
-msgstr "Contacto será eliminado"
-
 msgid "Please enter a password"
 msgstr "Por favor, introduce una contraseña"
 
@@ -178,3 +172,9 @@ msgstr "Introduce un enlace, por favor"
 
 msgid "Enter your contact's link, not your own"
 msgstr "Introduce el enlace del contacto, no el de ti"
+
+#~ msgid "Undo"
+#~ msgstr "Deshacer"
+
+#~ msgid "Contact will be deleted"
+#~ msgstr "Contacto será eliminado"
-- 
GitLab