20
20
#include <config.h>
23
#include <glib/gi18n.h>
24
22
#include <gio/gio.h>
27
#include "storage-manager.h"
28
#include "event-manager.h"
29
#include "main-window.h"
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)
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"));
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);
45
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", warning_message);
47
gtk_dialog_run (GTK_DIALOG (dialog));
48
gtk_widget_destroy (dialog);
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);
58
if (gtk_main_level () > 0)
65
almanah_run_on_screen (GdkScreen *screen, const gchar *commandline, GError **error)
69
GdkAppLaunchContext *context;
71
appinfo = g_app_info_create_from_commandline (commandline,
73
G_APP_INFO_CREATE_NONE,
79
context = gdk_display_get_app_launch_context (gdk_screen_get_display (screen));
80
gdk_app_launch_context_set_screen (context, screen);
82
retval = g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (context), error);
84
g_object_unref (context);
85
g_object_unref (appinfo);
93
g_signal_connect (almanah->storage_manager, "disconnected", G_CALLBACK (storage_manager_disconnected_cb), NULL);
94
almanah_storage_manager_disconnect (almanah->storage_manager, NULL);
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);
110
g_object_unref (almanah->event_manager);
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. */
24
#include "application.h"
117
27
main (int argc, char *argv[])
119
GOptionContext *context;
120
GError *error = NULL;
121
gboolean debug = FALSE;
124
const GOptionEntry options[] = {
125
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debug mode"), NULL },
130
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
131
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
132
textdomain (GETTEXT_PACKAGE);
29
AlmanahApplication *application;
32
#if !GLIB_CHECK_VERSION (2, 31, 0)
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");
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);
145
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
147
GtkWidget *dialog = gtk_message_dialog_new (NULL,
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);
156
g_error_free (error);
160
g_option_context_free (context);
163
almanah = g_new0 (Almanah, 1);
164
almanah->debug = debug;
167
almanah->settings = g_settings_new ("org.gnome.almanah");
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);
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);
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);
189
/* Create the event manager */
190
almanah->event_manager = almanah_event_manager_new ();
192
/* Set up printing objects */
193
almanah->print_settings = gtk_print_settings_new ();
194
almanah->page_setup = gtk_page_setup_new ();
196
/* Create and show the interface */
197
almanah->main_window = GTK_WIDGET (almanah_main_window_new ());
198
gtk_widget_show_all (almanah->main_window);
37
application = almanah_application_new ();
38
status = g_application_run (G_APPLICATION (application), argc, argv);
39
g_object_unref (application);