40
40
static void startup (GApplication *application);
41
41
static void activate (GApplication *application);
42
42
static gint handle_command_line (GApplication *application, GApplicationCommandLine *command_line);
43
static void quit_main_loop (GApplication *application);
43
static void window_removed (GtkApplication *application, GtkWindow *window);
45
45
static void almanah_application_init_actions (AlmanahApplication *self);
88
88
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
89
89
GApplicationClass *gapplication_class = G_APPLICATION_CLASS (klass);
90
GtkApplicationClass *gtkapplication_class = GTK_APPLICATION_CLASS (klass);
91
92
g_type_class_add_private (klass, sizeof (AlmanahApplicationPrivate));
98
99
gapplication_class->startup = startup;
99
100
gapplication_class->activate = activate;
100
101
gapplication_class->command_line = handle_command_line;
101
gapplication_class->quit_mainloop = quit_main_loop;
103
gtkapplication_class->window_removed = window_removed;
103
105
g_object_class_install_property (gobject_class, PROP_DEBUG,
104
106
g_param_spec_boolean ("debug",
359
storage_manager_disconnected_cb (AlmanahStorageManager *self, const gchar *gpgme_error_message, const gchar *warning_message, GApplication *application)
361
storage_manager_disconnected_cb (AlmanahStorageManager *self, const gchar *gpgme_error_message, const gchar *warning_message, GtkApplication *application)
361
363
if (gpgme_error_message != NULL || warning_message != NULL) {
362
364
GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
373
375
gtk_widget_destroy (dialog);
376
/* Chain up to the parent class */
377
G_APPLICATION_CLASS (almanah_application_parent_class)->quit_mainloop (application);
378
/* Allow the end of the applaction */
379
g_application_release (G_APPLICATION (application));
381
quit_main_loop (GApplication *application)
383
window_removed (GtkApplication *application, GtkWindow *window)
383
AlmanahApplicationPrivate *priv = ALMANAH_APPLICATION (application)->priv;
385
/* This would normally result in gtk_main_quit() being called, but we need to close the database connection first. */
386
g_signal_connect (priv->storage_manager, "disconnected", (GCallback) storage_manager_disconnected_cb, application);
387
almanah_storage_manager_disconnect (priv->storage_manager, NULL);
389
/* Quitting is actually done in storage_manager_disconnected_cb, which is called once
390
* the storage manager has encrypted the DB and disconnected from it. */
385
/* This would normally result in the end of the application, but we need to close the database connection first
386
to prevent an unencrypted database in the filesystem, and we don't want a bug like that.
387
So, we append a reference to the application when the user close the main window. When the application disconnect
388
from the database, allowing the encryption if necessary, we remove this reference with g_application_release.
389
See: https://bugzilla.gnome.org/show_bug.cgi?id=695117 */
390
if (ALMANAH_IS_MAIN_WINDOW (window)) {
391
AlmanahApplicationPrivate *priv = ALMANAH_APPLICATION (application)->priv;
393
g_application_hold (G_APPLICATION (application));
395
g_signal_connect (priv->storage_manager, "disconnected", (GCallback) storage_manager_disconnected_cb, application);
396
almanah_storage_manager_disconnect (priv->storage_manager, NULL);
399
GTK_APPLICATION_CLASS (almanah_application_parent_class)->window_removed (application, window);