1
Subject: Almanah doesn't encrypt the database when the application close
2
Author: Alvaro Peña <alvaropg@gmail.com>
3
Orirgin: upstream, https://git.gnome.org/browse/almanah/commit/?id=0e4fb167c6eb478e0bcdb1cce5dd18f36f3f2656
4
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=695117
5
Reviewed-by: Angel Abad <angel@debian.org>
7
--- a/src/application.c
8
+++ b/src/application.c
10
static void startup (GApplication *application);
11
static void activate (GApplication *application);
12
static gint handle_command_line (GApplication *application, GApplicationCommandLine *command_line);
13
-static void quit_main_loop (GApplication *application);
14
+static void window_removed (GtkApplication *application, GtkWindow *window);
16
static void almanah_application_init_actions (AlmanahApplication *self);
20
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
21
GApplicationClass *gapplication_class = G_APPLICATION_CLASS (klass);
22
+ GtkApplicationClass *gtkapplication_class = GTK_APPLICATION_CLASS (klass);
24
g_type_class_add_private (klass, sizeof (AlmanahApplicationPrivate));
27
gapplication_class->startup = startup;
28
gapplication_class->activate = activate;
29
gapplication_class->command_line = handle_command_line;
30
- gapplication_class->quit_mainloop = quit_main_loop;
32
+ gtkapplication_class->window_removed = window_removed;
34
g_object_class_install_property (gobject_class, PROP_DEBUG,
35
g_param_spec_boolean ("debug",
40
-storage_manager_disconnected_cb (AlmanahStorageManager *self, const gchar *gpgme_error_message, const gchar *warning_message, GApplication *application)
41
+storage_manager_disconnected_cb (AlmanahStorageManager *self, const gchar *gpgme_error_message, const gchar *warning_message, GtkApplication *application)
43
if (gpgme_error_message != NULL || warning_message != NULL) {
44
GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
46
gtk_widget_destroy (dialog);
49
- /* Chain up to the parent class */
50
- G_APPLICATION_CLASS (almanah_application_parent_class)->quit_mainloop (application);
51
+ /* Allow the end of the applaction */
52
+ g_application_release (G_APPLICATION (application));
56
-quit_main_loop (GApplication *application)
57
+window_removed (GtkApplication *application, GtkWindow *window)
59
- AlmanahApplicationPrivate *priv = ALMANAH_APPLICATION (application)->priv;
60
+ /* This would normally result in the end of the application, but we need to close the database connection first
61
+ to prevent an unencrypted database in the filesystem, and we don't want a bug like that.
62
+ So, we append a reference to the application when the user close the main window. When the application disconnect
63
+ from the database, allowing the encryption if necessary, we remove this reference with g_application_release.
64
+ See: https://bugzilla.gnome.org/show_bug.cgi?id=695117 */
65
+ if (ALMANAH_IS_MAIN_WINDOW (window)) {
66
+ AlmanahApplicationPrivate *priv = ALMANAH_APPLICATION (application)->priv;
68
- /* This would normally result in gtk_main_quit() being called, but we need to close the database connection first. */
69
- g_signal_connect (priv->storage_manager, "disconnected", (GCallback) storage_manager_disconnected_cb, application);
70
- almanah_storage_manager_disconnect (priv->storage_manager, NULL);
71
+ g_application_hold (G_APPLICATION (application));
73
+ g_signal_connect (priv->storage_manager, "disconnected", (GCallback) storage_manager_disconnected_cb, application);
74
+ almanah_storage_manager_disconnect (priv->storage_manager, NULL);
77
- /* Quitting is actually done in storage_manager_disconnected_cb, which is called once
78
- * the storage manager has encrypted the DB and disconnected from it. */
79
+ GTK_APPLICATION_CLASS (almanah_application_parent_class)->window_removed (application, window);