From 7e4748e0410ecb65aaa66842d373303194b37e1c Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Thu, 10 Sep 2020 14:57:50 +0200
Subject: [PATCH] Warn users of closure

Closes #54
---
 briar-gtk/briar_gtk/window.py                 | 30 ++++++++++++++++++-
 briar-gtk/data/app.briar.gtk.gschema.xml      |  5 ----
 briar-gtk/data/meson.build                    |  4 ---
 briar-gtk/data/ui/app.briar.gtk.gresource.xml |  1 +
 briar-gtk/data/ui/app.briar.gtk.gschema.xml   | 10 +++++++
 briar-gtk/data/ui/meson.build                 |  4 +++
 briar-gtk/po/ar.po                            |  6 ++++
 briar-gtk/po/briar-gtk.pot                    |  6 ++++
 briar-gtk/po/de.po                            |  6 ++++
 briar-gtk/po/es.po                            |  6 ++++
 tools/generate_data.sh                        |  2 +-
 11 files changed, 69 insertions(+), 11 deletions(-)
 delete mode 100644 briar-gtk/data/app.briar.gtk.gschema.xml
 create mode 100644 briar-gtk/data/ui/app.briar.gtk.gschema.xml

diff --git a/briar-gtk/briar_gtk/window.py b/briar-gtk/briar_gtk/window.py
index ab71323..3ef2917 100644
--- a/briar-gtk/briar_gtk/window.py
+++ b/briar-gtk/briar_gtk/window.py
@@ -2,7 +2,8 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 # License-Filename: LICENSE.md
 
-from gi.repository import Gtk
+from gettext import gettext as _
+from gi.repository import Gio, Gtk
 
 from briar_gtk.actions.window import WindowActions
 from briar_gtk.containers.add_contact import AddContactContainer
@@ -29,6 +30,33 @@ class Window(Gtk.ApplicationWindow):
         self.current_container.destroy()
         self._setup_add_contact_container()
 
+    # pylint: disable=arguments-differ,unused-argument
+    def do_delete_event(self, event):
+        settings = Gio.Settings.new(APPLICATION_ID)
+        if settings.get_boolean("quit-dialog-shown"):
+            return False  # closes the window
+        settings.set_boolean("quit-dialog-shown", True)
+
+        confirmation_dialog = Gtk.MessageDialog(
+            transient_for=self,
+            flags=Gtk.DialogFlags.MODAL,
+            message_type=Gtk.MessageType.WARNING,
+            buttons=Gtk.ButtonsType.OK_CANCEL,
+            text=_("Are you sure you want to exit?")
+        )
+        confirmation_dialog.format_secondary_text(
+            _("Once you close Briar, you'll no longer receive or send "
+              "pending messages. Keep Briar open to stay connected "
+              "with your contacts.")
+        )
+        response = confirmation_dialog.run()
+        confirmation_dialog.destroy()
+
+        if response == Gtk.ResponseType.OK:
+            return False  # closes the window
+
+        return True  # keeps the window open
+
     def _initialize_gtk_application_window(self):
         Gtk.ApplicationWindow.__init__(self, application=APP(),
                                        title=APPLICATION_NAME,
diff --git a/briar-gtk/data/app.briar.gtk.gschema.xml b/briar-gtk/data/app.briar.gtk.gschema.xml
deleted file mode 100644
index acbc4ee..0000000
--- a/briar-gtk/data/app.briar.gtk.gschema.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<schemalist gettext-domain="briar_gtk">
-	<schema id="app.briar.gtk" path="/app/briar/gtk/">
-	</schema>
-</schemalist>
diff --git a/briar-gtk/data/meson.build b/briar-gtk/data/meson.build
index 047c577..5743dc9 100644
--- a/briar-gtk/data/meson.build
+++ b/briar-gtk/data/meson.build
@@ -33,10 +33,6 @@ if appstream_util.found()
   )
 endif
 
-install_data('app.briar.gtk.gschema.xml',
-  install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas')
-)
-
 compile_schemas = find_program('glib-compile-schemas', required: false)
 if compile_schemas.found()
   test('Validate schema file', compile_schemas,
diff --git a/briar-gtk/data/ui/app.briar.gtk.gresource.xml b/briar-gtk/data/ui/app.briar.gtk.gresource.xml
index 6767e4c..a059c5c 100644
--- a/briar-gtk/data/ui/app.briar.gtk.gresource.xml
+++ b/briar-gtk/data/ui/app.briar.gtk.gresource.xml
@@ -10,5 +10,6 @@
     <file compressed="true" preprocess="xml-stripblanks">private_chat.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">registration.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">about_dialog.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">app.briar.gtk.gschema.xml</file>
   </gresource>
 </gresources>
diff --git a/briar-gtk/data/ui/app.briar.gtk.gschema.xml b/briar-gtk/data/ui/app.briar.gtk.gschema.xml
new file mode 100644
index 0000000..d143ff1
--- /dev/null
+++ b/briar-gtk/data/ui/app.briar.gtk.gschema.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist gettext-domain="briar_gtk">
+  <schema id="app.briar.gtk" path="/app/briar/gtk/" gettext-domain="briar-gtk">
+    <key name="quit-dialog-shown" type="b">
+      <default>false</default>
+      <summary>Quit dialog has been shown already</summary>
+      <description>It should only be shown once</description>
+    </key>
+  </schema>
+</schemalist>
diff --git a/briar-gtk/data/ui/meson.build b/briar-gtk/data/ui/meson.build
index cd985db..8387be5 100644
--- a/briar-gtk/data/ui/meson.build
+++ b/briar-gtk/data/ui/meson.build
@@ -16,3 +16,7 @@ gnome.compile_resources('briar-gtk',
     configuration: conf
   )
 )
+
+install_data('app.briar.gtk.gschema.xml',
+  install_dir: join_paths(get_option('datadir'), 'glib-2.0/schemas')
+)
diff --git a/briar-gtk/po/ar.po b/briar-gtk/po/ar.po
index 0181ef8..2e3e2c2 100644
--- a/briar-gtk/po/ar.po
+++ b/briar-gtk/po/ar.po
@@ -152,6 +152,12 @@ msgstr ""
 msgid "Myself"
 msgstr ""
 
+msgid "Are you sure you want to exit?"
+msgstr ""
+
+msgid "Once you close Briar, you'll no longer receive or send pending messages. Keep Briar open to stay connected with your contacts."
+msgstr ""
+
 msgid "Confirm Contact Deletion"
 msgstr "تأكيد حذف جهة الإتصال"
 
diff --git a/briar-gtk/po/briar-gtk.pot b/briar-gtk/po/briar-gtk.pot
index 3242ea4..9b93da8 100644
--- a/briar-gtk/po/briar-gtk.pot
+++ b/briar-gtk/po/briar-gtk.pot
@@ -162,6 +162,12 @@ msgstr ""
 msgid "Myself"
 msgstr ""
 
+msgid "Are you sure you want to exit?"
+msgstr ""
+
+msgid "Once you close Briar, you'll no longer receive or send pending messages. Keep Briar open to stay connected with your contacts."
+msgstr ""
+
 msgid "Confirm Contact Deletion"
 msgstr ""
 
diff --git a/briar-gtk/po/de.po b/briar-gtk/po/de.po
index e33a587..ac511a4 100644
--- a/briar-gtk/po/de.po
+++ b/briar-gtk/po/de.po
@@ -152,6 +152,12 @@ msgstr "Briar-Funktionalität von"
 msgid "Myself"
 msgstr "Ich"
 
+msgid "Are you sure you want to exit?"
+msgstr "Willst du Briar wirklich beenden?"
+
+msgid "Once you close Briar, you'll no longer receive or send pending messages. Keep Briar open to stay connected with your contacts."
+msgstr "Sobald du Briar schließt, wirst du keine ausstehenden Nachrichten mehr empfangen oder senden können. Lass Briar offen, um mit deinen Kontakten in Verbindung zu bleiben."
+
 msgid "Confirm Contact Deletion"
 msgstr "Löschen des Kontakts bestätigen"
 
diff --git a/briar-gtk/po/es.po b/briar-gtk/po/es.po
index cef368a..66ffb15 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 "Are you sure you want to exit?"
+msgstr "¿Estás seguro que quieres salir?"
+
+msgid "Once you close Briar, you'll no longer receive or send pending messages. Keep Briar open to stay connected with your contacts."
+msgstr "Cuando cierres Briar, no vas a recibir o enviar mensajes pendientes. Mantenlo abierto para permanecer conectado con tus contactos."
+
 msgid "Confirm Contact Deletion"
 msgstr "Confirmar eliminación de contacto"
 
diff --git a/tools/generate_data.sh b/tools/generate_data.sh
index de14b45..a12c691 100755
--- a/tools/generate_data.sh
+++ b/tools/generate_data.sh
@@ -17,7 +17,7 @@ function generate_resource()
         echo -n $(basename $file)
         echo '</file>'
     done
-    for file in briar-gtk/data/ui/*.ui about_dialog.ui
+    for file in briar-gtk/data/ui/*.ui about_dialog.ui briar-gtk/data/ui/app.briar.gtk.gschema.xml
     do
         echo -n '    <file compressed="true" preprocess="xml-stripblanks">'
         echo -n $(basename $file)
-- 
GitLab