~ubuntu-branches/ubuntu/saucy/almanah/saucy

« back to all changes in this revision

Viewing changes to src/application.c

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2013-09-22 18:31:26 UTC
  • mfrom: (11.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20130922183126-lza1evcmmulsdv5q
Tags: 0.10.8-3
debian/patches/encrypt_database: Fix database encryption error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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);
44
44
 
45
45
static void almanah_application_init_actions (AlmanahApplication *self);
46
46
 
87
87
{
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);
90
91
 
91
92
        g_type_class_add_private (klass, sizeof (AlmanahApplicationPrivate));
92
93
 
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;
 
102
 
 
103
        gtkapplication_class->window_removed = window_removed;
102
104
 
103
105
        g_object_class_install_property (gobject_class, PROP_DEBUG,
104
106
                                         g_param_spec_boolean ("debug",
356
358
}
357
359
 
358
360
static void
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)
360
362
{
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);
374
376
        }
375
377
 
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));
378
380
}
379
381
 
380
382
static void
381
 
quit_main_loop (GApplication *application)
 
383
window_removed (GtkApplication *application, GtkWindow *window)
382
384
{
383
 
        AlmanahApplicationPrivate *priv = ALMANAH_APPLICATION (application)->priv;
384
 
 
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);
388
 
 
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;
 
392
 
 
393
                g_application_hold (G_APPLICATION (application));
 
394
 
 
395
                g_signal_connect (priv->storage_manager, "disconnected", (GCallback) storage_manager_disconnected_cb, application);
 
396
                almanah_storage_manager_disconnect (priv->storage_manager, NULL);
 
397
        }
 
398
 
 
399
        GTK_APPLICATION_CLASS (almanah_application_parent_class)->window_removed (application, window);
391
400
}
392
401
 
393
402
static void