1
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4
* Copyright (C) Philip Withnall 2008 <philip@tecnocode.co.uk>
4
* Copyright (C) Philip Withnall 2008-2009 <philip@tecnocode.co.uk>
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.
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.
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/>.
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 */
29
27
#include "storage-manager.h"
30
#include "interface.h"
35
diary->quitting = TRUE;
36
diary_storage_manager_disconnect (diary->storage_manager);
38
gtk_widget_destroy (diary->add_link_dialog);
39
gtk_widget_destroy (diary->search_dialog);
40
gtk_widget_destroy (diary->main_window);
42
/* Quitting is actually done in the idle handler for disconnection
43
* which calls diary_quit_real. */
47
diary_quit_real (void)
49
g_object_unref (diary->storage_manager);
50
#ifdef ENABLE_ENCRYPTION
51
g_object_unref (diary->gconf_client);
52
#endif /* ENABLE_ENCRYPTION */
28
#include "event-manager.h"
29
#include "main-window.h"
34
storage_manager_disconnected_cb (AlmanahStorageManager *self, gpointer user_data)
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);
55
43
if (gtk_main_level () > 0)
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);
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);
76
g_object_unref (almanah->event_manager);
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. */
83
storage_manager_disconnected_cb (almanah->storage_manager, NULL);
62
88
main (int argc, char *argv[])
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;
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 },
94
121
GTK_MESSAGE_ERROR,
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);
104
132
g_option_context_free (context);
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;
111
#ifdef ENABLE_ENCRYPTION
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);
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);
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);
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);
163
/* Create the event manager */
164
almanah->event_manager = almanah_event_manager_new ();
166
/* Set up printing objects */
167
almanah->print_settings = gtk_print_settings_new ();
168
almanah->page_setup = gtk_page_setup_new ();
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);