~ubuntu-branches/ubuntu/oneiric/almanah/oneiric

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2009-05-16 15:49:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090516154921-2uhvlj8btb4qygmd
Tags: 0.6.1-0ubuntu1
* New upstream release (LP: #368078)
* debian/control:
  - Bump Standards-Version to 3.8.1
  - Add intltool, libedataserver1.2-dev, libedataserverui1.2-dev, 
    libecal1.2-dev, libcryptui-dev as build dependency
  - Remove build dependency on autotools-dev and chrpath
* debian/{control/compat/rules}: Move to mimalistic dh7 style
* Update debian/watch
* Update copyright information

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
 
 * Diary
4
 
 * Copyright (C) Philip Withnall 2008 <philip@tecnocode.co.uk>
 
3
 * Almanah
 
4
 * Copyright (C) Philip Withnall 2008-2009 <philip@tecnocode.co.uk>
5
5
 * 
6
 
 * Diary is free software: you can redistribute it and/or modify
 
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
8
8
 * the Free Software Foundation, either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
 
 * Diary is distributed in the hope that it will be useful,
 
11
 * Almanah is distributed in the hope that it will be useful,
12
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with Diary.  If not, see <http://www.gnu.org/licenses/>.
 
17
 * along with Almanah.  If not, see <http://www.gnu.org/licenses/>.
18
18
 */
19
19
 
20
20
#include <config.h>
21
21
#include <stdlib.h>
22
22
#include <gtk/gtk.h>
23
23
#include <glib/gi18n.h>
24
 
#ifdef ENABLE_ENCRYPTION
25
24
#include <gconf/gconf.h>
26
 
#endif /* ENABLE_ENCRYPTION */
27
25
 
28
26
#include "main.h"
29
27
#include "storage-manager.h"
30
 
#include "interface.h"
31
 
 
32
 
void
33
 
diary_quit (void)
34
 
{
35
 
        diary->quitting = TRUE;
36
 
        diary_storage_manager_disconnect (diary->storage_manager);
37
 
 
38
 
        gtk_widget_destroy (diary->add_link_dialog);
39
 
        gtk_widget_destroy (diary->search_dialog);
40
 
        gtk_widget_destroy (diary->main_window);
41
 
 
42
 
        /* Quitting is actually done in the idle handler for disconnection
43
 
         * which calls diary_quit_real. */
44
 
}
45
 
 
46
 
void
47
 
diary_quit_real (void)
48
 
{
49
 
        g_object_unref (diary->storage_manager);
50
 
#ifdef ENABLE_ENCRYPTION
51
 
        g_object_unref (diary->gconf_client);
52
 
#endif /* ENABLE_ENCRYPTION */
53
 
        g_free (diary);
 
28
#include "event-manager.h"
 
29
#include "main-window.h"
 
30
 
 
31
Almanah *almanah;
 
32
 
 
33
static void
 
34
storage_manager_disconnected_cb (AlmanahStorageManager *self, gpointer user_data)
 
35
{
 
36
        g_object_unref (almanah->storage_manager);
 
37
        g_object_unref (almanah->gconf_client);
 
38
        g_object_unref (almanah->page_setup);
 
39
        g_object_unref (almanah->print_settings);
 
40
 
 
41
        g_free (almanah);
54
42
 
55
43
        if (gtk_main_level () > 0)
56
44
                gtk_main_quit ();
58
46
        exit (0);
59
47
}
60
48
 
 
49
void
 
50
almanah_quit (void)
 
51
{
 
52
        GError *error = NULL;
 
53
 
 
54
        g_signal_connect (almanah->storage_manager, "disconnected", G_CALLBACK (storage_manager_disconnected_cb), NULL);
 
55
        if (almanah_storage_manager_disconnect (almanah->storage_manager, &error) == FALSE) {
 
56
                GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW (almanah->main_window),
 
57
                                                            GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
 
58
                                                            _("Error closing database"));
 
59
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
 
60
                gtk_dialog_run (GTK_DIALOG (dialog));
 
61
                gtk_widget_destroy (dialog);
 
62
        }
 
63
 
 
64
        if (almanah->add_definition_dialog != NULL)
 
65
                gtk_widget_destroy (almanah->add_definition_dialog);
 
66
        if (almanah->search_dialog != NULL)
 
67
                gtk_widget_destroy (almanah->search_dialog);
 
68
#ifdef ENABLE_ENCRYPTION
 
69
        if (almanah->preferences_dialog != NULL)
 
70
                gtk_widget_destroy (almanah->preferences_dialog);
 
71
#endif /* ENABLE_ENCRYPTION */
 
72
        if (almanah->definition_manager_window != NULL)
 
73
                gtk_widget_destroy (almanah->definition_manager_window);
 
74
        gtk_widget_destroy (almanah->main_window);
 
75
 
 
76
        g_object_unref (almanah->event_manager);
 
77
 
 
78
        /* Quitting is actually done in storage_manager_disconnected_cb, which is called once
 
79
         * the storage manager has encrypted the DB and disconnected from it.
 
80
         * Unless, that is, disconnection failed. */
 
81
        if (error != NULL) {
 
82
                g_error_free (error);
 
83
                storage_manager_disconnected_cb (almanah->storage_manager, NULL);
 
84
        }
 
85
}
 
86
 
61
87
int
62
88
main (int argc, char *argv[])
63
89
{
64
90
        GOptionContext *context;
65
91
        GError *error = NULL;
66
 
        gboolean debug = FALSE;
 
92
        gboolean debug = FALSE, import_mode = FALSE;
67
93
        gchar *db_filename;
68
94
 
69
95
        const GOptionEntry options[] = {
70
96
                { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debug mode"), NULL },
 
97
                { "import-mode", 0, 0, G_OPTION_ARG_NONE, &import_mode, N_("Enable import mode"), NULL },
71
98
                { NULL }
72
99
        };
73
100
 
93
120
                                GTK_DIALOG_MODAL,
94
121
                                GTK_MESSAGE_ERROR,
95
122
                                GTK_BUTTONS_OK,
96
 
                                _("Command-line options could not be parsed. Error: %s"), error->message);
 
123
                                _("Command-line options could not be parsed"));
 
124
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
97
125
                gtk_dialog_run (GTK_DIALOG (dialog));
98
126
                gtk_widget_destroy (dialog);
99
127
 
104
132
        g_option_context_free (context);
105
133
 
106
134
        /* Setup */
107
 
        diary = g_new (Diary, 1);
108
 
        diary->debug = debug;
109
 
        diary->quitting = FALSE;
 
135
        almanah = g_new0 (Almanah, 1);
 
136
        almanah->debug = debug;
 
137
        almanah->import_mode = import_mode;
110
138
 
111
 
#ifdef ENABLE_ENCRYPTION
112
139
        /* Open GConf */
113
 
        diary->gconf_client = gconf_client_get_default ();
114
 
#endif /* ENABLE_ENCRYPTION */
 
140
        almanah->gconf_client = gconf_client_get_default ();
 
141
        gconf_client_add_dir (almanah->gconf_client, "/apps/almanah", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
 
142
 
 
143
        /* Ensure the DB directory exists */
 
144
        if (g_file_test (g_get_user_data_dir (), G_FILE_TEST_IS_DIR) == FALSE)
 
145
                g_mkdir_with_parents (g_get_user_data_dir (), 0700);
115
146
 
116
147
        /* Open the DB */
117
148
        db_filename = g_build_filename (g_get_user_data_dir (), "diary.db", NULL);
118
 
        diary->storage_manager = diary_storage_manager_new (db_filename);
 
149
        almanah->storage_manager = almanah_storage_manager_new (db_filename);
119
150
        g_free (db_filename);
120
151
 
121
 
        diary_storage_manager_connect (diary->storage_manager);
 
152
        if (almanah_storage_manager_connect (almanah->storage_manager, &error) == FALSE) {
 
153
                GtkWidget *dialog = gtk_message_dialog_new (NULL,
 
154
                                                            GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
 
155
                                                            _("Error opening database"));
 
156
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
 
157
                gtk_dialog_run (GTK_DIALOG (dialog));
 
158
                gtk_widget_destroy (dialog);
 
159
 
 
160
                almanah_quit ();
 
161
        }
 
162
 
 
163
        /* Create the event manager */
 
164
        almanah->event_manager = almanah_event_manager_new ();
 
165
 
 
166
        /* Set up printing objects */
 
167
        almanah->print_settings = gtk_print_settings_new ();
 
168
        almanah->page_setup = gtk_page_setup_new ();
122
169
 
123
170
        /* Create and show the interface */
124
 
        diary_create_interface ();
125
 
        gtk_widget_show_all (diary->main_window);
 
171
        almanah->main_window = GTK_WIDGET (almanah_main_window_new ());
 
172
        gtk_widget_show_all (almanah->main_window);
126
173
 
127
174
        gtk_main ();
128
175
        return 0;