Fix compiler warnings for main.c
[maepad.git] / src / main.c
blobfafa815d6dc93bc88f3c1b80c5ef2ee2eba7a144
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>
26 #include <gtk/gtkmain.h>
27 #include <hildon/hildon-program.h>
28 #include <hildon/hildon-note.h>
29 #include <libintl.h>
30 #include <locale.h>
31 #include <libosso.h>
33 #define _(String) gettext(String)
35 #include <config.h>
36 #include <appdata.h>
38 gint
39 dbus_callback (const gchar *interface, const gchar *method,
40 GArray *arguments, gpointer data,
41 osso_rpc_t *retval)
43 printf ("maemopad+ dbus: %s, %s\n", interface, method);
45 if (!strcmp (method, "top_application"))
46 gtk_window_present (GTK_WINDOW (data));
48 retval->type = DBUS_TYPE_INVALID;
49 return OSSO_OK;
52 int main(int argc, char *argv[])
54 AppData *data;
55 HildonProgram *app;
56 MainView *main_view;
57 gboolean do_quit = FALSE;
59 /* Initialise the locale stuff */
60 setlocale(LC_ALL, "");
61 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
62 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
63 textdomain(GETTEXT_PACKAGE);
65 /* Init the gtk - must be called before any hildon stuff */
66 gtk_init(&argc, &argv);
68 /* Create the hildon application and setup the title */
69 app = HILDON_PROGRAM ( hildon_program_get_instance () );
70 g_set_application_name ("MæPad");
72 /* Create the data and views for our application */
73 data = g_new0(AppData, 1);
74 data->osso = osso_initialize("maepad", VERSION, FALSE, NULL);
75 g_assert(data->osso);
76 data->app = app;
77 main_view = interface_main_view_new(data);
78 hildon_program_add_window(data->app, HILDON_WINDOW(data->main_view));
80 osso_return_t ossores;
82 /* Add handler for hardware D-BUS messages */
83 ossores = osso_hw_set_event_cb(data->osso, NULL, hw_event_handler, (gpointer) main_view);
84 if (ossores != OSSO_OK)
86 g_print("Error setting HW state callback (%d)\n", ossores);
87 return OSSO_ERROR;
90 ossores = osso_rpc_set_default_cb_f (data->osso, dbus_callback, data->main_view);
91 if (ossores != OSSO_OK)
93 fprintf (stderr, "osso_rpc_set_default_cb_f failed: %d.\n", ossores);
94 return 1;
97 data->gconf = gconf_client_get_default();
98 gchar *gcfilename = gconf_client_get_string(data->gconf, "/apps/maemopadPlus/general/lastdocument", NULL);
100 gtk_widget_show(GTK_WIDGET(data->main_view));
102 gtk_widget_hide(main_view->scrolledwindow);
104 gtk_widget_show(sketchwidget_get_mainwidget(main_view->sk));
105 gtk_widget_realize(sketchwidget_get_drawingarea(main_view->sk));
107 /* gtk_widget_map(sketchwidget_get_drawingarea(main_view->sk));
109 gtk_widget_hide(sketchwidget_get_mainwidget(main_view->sk));
111 if (gcfilename)
113 open_file(gcfilename, main_view);
114 g_free(gcfilename);
119 do {
120 if (main_view->file_name == NULL) {
121 switch (interface_initial_setup(main_view)) {
122 case RESPONSE_CREATE_NEW:
123 callback_file_new(NULL, main_view);
124 break;
125 case RESPONSE_OPEN_FILE:
126 callback_file_open(NULL, main_view);
127 break;
128 case RESPONSE_QUIT:
129 do_quit = TRUE;
130 break;
133 } while (main_view->file_name == NULL && !do_quit);
135 if (main_view->file_name == NULL)
136 break;
138 /* Begin the main app */
139 gtk_widget_show(GTK_WIDGET(data->main_view));
140 gtk_main();
142 if (main_view->file_name)
144 printf("exit:*%s*\n", main_view->file_name);
145 gconf_client_set_string(data->gconf, "/apps/maemopadPlus/general/lastdocument", main_view->file_name, NULL);
147 } while(FALSE);
149 /* Clean up */
150 if (main_view->db)
151 sqlite3_close(main_view->db);
153 sketchwidget_destroy(main_view->sk);
154 interface_main_view_destroy(main_view);
156 osso_deinitialize(data->osso);
157 g_free(data);
159 return 0;