Fix and remove some obsolete OSSO/D-Bus stuff
[maepad.git] / src / main.c
blobfed446f031d6732e296f1667c9ace6a37eb50399
1 /*
2 * This file is part of maemopad+
5 * This software is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
10 * This software is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this software; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
22 #include <ui/interface.h>
23 #include <ui/callbacks.h>
24 #include <string.h>
25 #include <stdlib.h>
27 #include <gtk/gtkmain.h>
28 #include <hildon/hildon-program.h>
29 #include <hildon/hildon-note.h>
30 #include <libintl.h>
31 #include <locale.h>
32 #include <libosso.h>
34 #define _(String) gettext(String)
36 #include <config.h>
37 #include <appdata.h>
39 AppData*
40 app_data_new()
42 AppData* app_data = g_new0(AppData, 1);
44 app_data->app = HILDON_PROGRAM(hildon_program_get_instance());
45 g_assert(app_data->app);
46 app_data->osso = osso_initialize("org.maemo.maepad", VERSION, FALSE, NULL);
47 g_assert(app_data->osso);
48 app_data->gconf = gconf_client_get_default();
49 g_assert(app_data->gconf);
51 return app_data;
54 void
55 app_data_destroy(AppData* app_data)
57 osso_deinitialize(app_data->osso);
58 g_object_unref(app_data->gconf);
60 g_free(app_data);
63 int main(int argc, char *argv[])
65 AppData *app_data;
66 MainView *main_view;
68 /* Initialise the locale stuff */
69 setlocale(LC_ALL, "");
70 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
71 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
72 textdomain(GETTEXT_PACKAGE);
74 /* Init the gtk - must be called before any hildon stuff */
75 gtk_init(&argc, &argv);
77 /* Create the hildon application and setup the title */
78 g_set_application_name ("MæPad");
80 /* Create the data and views for our application */
81 app_data = app_data_new();
82 main_view = interface_main_view_new(app_data);
84 /* Check if we can directly open the last document */
85 gchar* last_document = gconf_client_get_string(app_data->gconf, MAEPAD_GCONF_LAST_DOCUMENT, NULL);
87 if (last_document != NULL) {
88 open_file(last_document, main_view);
89 g_free(last_document);
92 gboolean do_quit = FALSE;
93 while (main_view->file_name == NULL && !do_quit) {
94 switch (interface_initial_setup(main_view)) {
95 case RESPONSE_CREATE_NEW:
96 callback_file_new(NULL, main_view);
97 break;
98 case RESPONSE_OPEN_FILE:
99 callback_file_open(NULL, main_view);
100 break;
101 case RESPONSE_QUIT:
102 do_quit = TRUE;
103 break;
107 if (main_view->file_name != NULL) {
108 /* Ready to begin the main loop */
109 gtk_main();
111 /* Remember last filename on close */
112 if (main_view->file_name != NULL) {
113 gconf_client_set_string(app_data->gconf, MAEPAD_GCONF_LAST_DOCUMENT, main_view->file_name, NULL);
117 /* Clean-up the interface and app data objects */
118 interface_main_view_destroy(main_view);
119 app_data_destroy(app_data);
121 return EXIT_SUCCESS;