~ubuntu-branches/ubuntu/raring/almanah/raring

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2012-04-03 14:25:25 UTC
  • mfrom: (11.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20120403142525-ugk3fb0blonrl2b9
Tags: 0.9.0-1
* debian/watch: Update for .xz
* Imported Upstream version 0.9.0
* debian/patches/01_largefile_support.patch: Remove, applied upstream
* debian/patches/02_gtkspell-3.0.patch: Remove, applied upstream
* Remove dh_autoreconf stuff
* debian/copyright: Update upstream years

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
2
/*
3
3
 * Almanah
4
 
 * Copyright (C) Philip Withnall 2008-2009 <philip@tecnocode.co.uk>
 
4
 * Copyright (C) Philip Withnall 2008, 2009, 2011 <philip@tecnocode.co.uk>
5
5
 * 
6
6
 * Almanah is free software: you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
18
18
 */
19
19
 
20
20
#include <config.h>
21
 
#include <stdlib.h>
22
 
#include <gtk/gtk.h>
23
 
#include <glib/gi18n.h>
 
21
#include <glib.h>
24
22
#include <gio/gio.h>
25
23
 
26
 
#include "main.h"
27
 
#include "storage-manager.h"
28
 
#include "event-manager.h"
29
 
#include "main-window.h"
30
 
 
31
 
Almanah *almanah;
32
 
 
33
 
static G_GNUC_NORETURN void
34
 
storage_manager_disconnected_cb (AlmanahStorageManager *self, const gchar *gpgme_error_message, const gchar *warning_message, gpointer user_data)
35
 
{
36
 
        if (gpgme_error_message != NULL || warning_message != NULL) {
37
 
                GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
38
 
                                                            _("Error encrypting database"));
39
 
 
40
 
                if (gpgme_error_message != NULL && warning_message != NULL)
41
 
                        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s %s", warning_message, gpgme_error_message);
42
 
                else if (gpgme_error_message != NULL)
43
 
                        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", gpgme_error_message);
44
 
                else
45
 
                        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", warning_message);
46
 
 
47
 
                gtk_dialog_run (GTK_DIALOG (dialog));
48
 
                gtk_widget_destroy (dialog);
49
 
        }
50
 
 
51
 
        g_object_unref (almanah->storage_manager);
52
 
        g_object_unref (almanah->settings);
53
 
        g_object_unref (almanah->page_setup);
54
 
        g_object_unref (almanah->print_settings);
55
 
 
56
 
        g_free (almanah);
57
 
 
58
 
        if (gtk_main_level () > 0)
59
 
                gtk_main_quit ();
60
 
 
61
 
        exit (0);
62
 
}
63
 
 
64
 
gboolean
65
 
almanah_run_on_screen (GdkScreen *screen, const gchar *commandline, GError **error)
66
 
{
67
 
        gboolean retval;
68
 
        GAppInfo *appinfo;
69
 
        GdkAppLaunchContext *context;
70
 
 
71
 
        appinfo = g_app_info_create_from_commandline (commandline,
72
 
                                                "Almanah Execute",
73
 
                                                G_APP_INFO_CREATE_NONE,
74
 
                                                error);
75
 
 
76
 
        if (!appinfo)
77
 
                return FALSE;
78
 
 
79
 
        context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
80
 
        gdk_app_launch_context_set_screen (context, screen);
81
 
 
82
 
        retval = g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (context), error);
83
 
 
84
 
        g_object_unref (context);
85
 
        g_object_unref (appinfo);
86
 
 
87
 
        return retval;
88
 
}
89
 
 
90
 
void
91
 
almanah_quit (void)
92
 
{
93
 
        g_signal_connect (almanah->storage_manager, "disconnected", G_CALLBACK (storage_manager_disconnected_cb), NULL);
94
 
        almanah_storage_manager_disconnect (almanah->storage_manager, NULL);
95
 
 
96
 
        if (almanah->add_definition_dialog != NULL)
97
 
                gtk_widget_destroy (almanah->add_definition_dialog);
98
 
        if (almanah->search_dialog != NULL)
99
 
                gtk_widget_destroy (almanah->search_dialog);
100
 
        if (almanah->date_entry_dialog != NULL)
101
 
                gtk_widget_destroy (almanah->date_entry_dialog);
102
 
#ifdef ENABLE_ENCRYPTION
103
 
        if (almanah->preferences_dialog != NULL)
104
 
                gtk_widget_destroy (almanah->preferences_dialog);
105
 
#endif /* ENABLE_ENCRYPTION */
106
 
        if (almanah->definition_manager_window != NULL)
107
 
                gtk_widget_destroy (almanah->definition_manager_window);
108
 
        gtk_widget_destroy (almanah->main_window);
109
 
 
110
 
        g_object_unref (almanah->event_manager);
111
 
 
112
 
        /* Quitting is actually done in storage_manager_disconnected_cb, which is called once
113
 
         * the storage manager has encrypted the DB and disconnected from it. */
114
 
}
 
24
#include "application.h"
115
25
 
116
26
int
117
27
main (int argc, char *argv[])
118
28
{
119
 
        GOptionContext *context;
120
 
        GError *error = NULL;
121
 
        gboolean debug = FALSE;
122
 
        gchar *db_filename;
123
 
 
124
 
        const GOptionEntry options[] = {
125
 
                { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debug mode"), NULL },
126
 
                { NULL }
127
 
        };
128
 
 
129
 
#ifdef ENABLE_NLS
130
 
        bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
131
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
132
 
        textdomain (GETTEXT_PACKAGE);
 
29
        AlmanahApplication *application;
 
30
        int status;
 
31
 
 
32
#if !GLIB_CHECK_VERSION (2, 31, 0)
 
33
        g_thread_init (NULL);
133
34
#endif
134
 
 
135
 
        g_thread_init (NULL);
136
 
        gtk_init (&argc, &argv);
137
 
        g_set_application_name (_("Almanah Diary"));
138
 
        gtk_window_set_default_icon_name ("almanah");
139
 
 
140
 
        /* Options */
141
 
        context = g_option_context_new (_("- Manage your diary"));
142
 
        g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
143
 
        g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
144
 
 
145
 
        if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
146
 
                /* Show an error */
147
 
                GtkWidget *dialog = gtk_message_dialog_new (NULL,
148
 
                                GTK_DIALOG_MODAL,
149
 
                                GTK_MESSAGE_ERROR,
150
 
                                GTK_BUTTONS_OK,
151
 
                                _("Command-line options could not be parsed"));
152
 
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
153
 
                gtk_dialog_run (GTK_DIALOG (dialog));
154
 
                gtk_widget_destroy (dialog);
155
 
 
156
 
                g_error_free (error);
157
 
                exit (1);
158
 
        }
159
 
 
160
 
        g_option_context_free (context);
161
 
 
162
 
        /* Setup */
163
 
        almanah = g_new0 (Almanah, 1);
164
 
        almanah->debug = debug;
165
 
 
166
 
        /* Open GSettings */
167
 
        almanah->settings = g_settings_new ("org.gnome.almanah");
168
 
 
169
 
        /* Ensure the DB directory exists */
170
 
        if (g_file_test (g_get_user_data_dir (), G_FILE_TEST_IS_DIR) == FALSE)
171
 
                g_mkdir_with_parents (g_get_user_data_dir (), 0700);
172
 
 
173
 
        /* Open the DB */
174
 
        db_filename = g_build_filename (g_get_user_data_dir (), "diary.db", NULL);
175
 
        almanah->storage_manager = almanah_storage_manager_new (db_filename);
176
 
        g_free (db_filename);
177
 
 
178
 
        if (almanah_storage_manager_connect (almanah->storage_manager, &error) == FALSE) {
179
 
                GtkWidget *dialog = gtk_message_dialog_new (NULL,
180
 
                                                            GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
181
 
                                                            _("Error opening database"));
182
 
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
183
 
                gtk_dialog_run (GTK_DIALOG (dialog));
184
 
                gtk_widget_destroy (dialog);
185
 
 
186
 
                almanah_quit ();
187
 
        }
188
 
 
189
 
        /* Create the event manager */
190
 
        almanah->event_manager = almanah_event_manager_new ();
191
 
 
192
 
        /* Set up printing objects */
193
 
        almanah->print_settings = gtk_print_settings_new ();
194
 
        almanah->page_setup = gtk_page_setup_new ();
195
 
 
196
 
        /* Create and show the interface */
197
 
        almanah->main_window = GTK_WIDGET (almanah_main_window_new ());
198
 
        gtk_widget_show_all (almanah->main_window);
199
 
 
200
 
        gtk_main ();
201
 
        return 0;
 
35
        g_type_init ();
 
36
 
 
37
        application = almanah_application_new ();
 
38
        status = g_application_run (G_APPLICATION (application), argc, argv);
 
39
        g_object_unref (application);
 
40
 
 
41
        return status;
202
42
}