b6604dfb99669d5aa126efa375ef8942628671f0
[maevies] / src / main.c
1 /*******************************************************************************
2  * Copyright (c) 2007-2008 INdT, (c) 2009 Nokia.
3  *
4  * This code example is licensed under a MIT-style license,
5  * that can be found in the file called "COPYING" in the package
6  *
7  */
8
9 /*
10  ============================================================================
11  Name        : main.c
12  Author      : Simón Pena
13  Version     : 0.1
14  Description : Hildon GUI Application in C
15  ============================================================================
16  */
17 /* Includes */
18 #include <hildon/hildon-program.h>
19 #include <gtk/gtkmain.h>
20 #include <gtk/gtkbutton.h>
21 #include <libosso.h>
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include "localisation.h"
26 #include "extra_scenes_provider.h"
27 #include "maevies_window.h"
28
29 /* Defines to add the application to dbus and keep it running
30  * Please do not modify "APP_NAME" (or other defines) to different name
31  */
32 #define APP_NAME "maevies"
33 #define APP_VER "0.1"
34 #define APP_SERVICE "com.nokia.maevies"
35 #define APP_METHOD "/com/nokia/maevies"
36 /* end defines */
37
38 typedef struct _AppData AppData;
39
40 struct _AppData {
41
42         HildonProgram *program;
43         MaeviesWindow *window;
44
45 };
46
47 static gint dbus_callback(const gchar *interface, const gchar *method,
48                 GArray *arguments, gpointer data, osso_rpc_t *retval);
49
50 gint main(gint argc, gchar* argv[]) {
51
52         osso_context_t *osso_cont;
53         osso_return_t ret;
54         AppData *data = g_new0(AppData,1);
55
56         locale_init();
57
58         osso_cont = osso_initialize(APP_NAME, APP_VER, TRUE, NULL);
59         g_assert(osso_cont);
60
61         /* Initialize the GTK. */
62         gtk_init(&argc, &argv);
63
64         /* Initialize thread system */
65         g_thread_init(NULL);
66
67         /* Create the hildon program and setup the title */
68         data->program = HILDON_PROGRAM(hildon_program_get_instance());
69         g_set_application_name("Maevies");
70
71         /* Create HildonWindow and set it to HildonProgram */
72         data->window = maevies_window_new(osso_cont);
73         hildon_program_add_window(data->program, HILDON_WINDOW(data->window));
74
75         ret = osso_rpc_set_cb_f(data->window->osso, APP_SERVICE, APP_METHOD,
76                         APP_SERVICE, dbus_callback, GTK_WIDGET(data->window));
77         if (ret != OSSO_OK) {
78                 fprintf(stderr, "osso_rpc_set_cb_f failed: %d.\n", ret);
79                 exit(1);
80         }
81
82         /* Begin the main application */
83         gtk_widget_show_all(GTK_WIDGET(data->window));
84
85         /* Quit program when window is closed. */
86         g_signal_connect(G_OBJECT(data->window), "delete_event",
87                         G_CALLBACK(gtk_main_quit), NULL);
88
89         /* Quit program when window is otherwise destroyed. */
90         g_signal_connect(G_OBJECT(data->window), "destroy", G_CALLBACK(gtk_main_quit),
91                         NULL);
92
93         gtk_main();
94
95         /* Clean up: */
96         gtk_widget_destroy(GTK_WIDGET (data->window));
97         g_free(data);
98
99         /* Exit */
100         return 0;
101 }
102
103 static gint dbus_callback(const gchar *interface, const gchar *method,
104                 GArray *arguments, gpointer data, osso_rpc_t *retval) {
105         printf("dbus: %s, %s\n", interface, method);
106
107         if (!strcmp(method, "top_application"))
108                 gtk_window_present(GTK_WINDOW(data));
109
110         return DBUS_TYPE_INVALID;
111 }