728f85c7a46fe48144570dbca12fe214ed40f276
[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 /* Defines to add the application to dbus and keep it running
27  * Please do not modify "APP_NAME" (or other defines) to different name
28  */
29 #define APP_NAME "maevies"
30 #define APP_VER "0.1"
31 #define APP_SERVICE "com.nokia.maevies"
32 #define APP_METHOD "/com/nokia/maevies"
33 /* end defines */
34
35 static void button_clicked (GtkButton* button, gpointer data)
36 {
37     gtk_main_quit();
38 }
39
40 static gint
41 dbus_callback (const gchar *interface, const gchar *method,
42                GArray *arguments, gpointer data,
43                osso_rpc_t *retval)
44 {
45   printf ("dbus: %s, %s\n", interface, method);
46
47   if (!strcmp (method, "top_application"))
48       gtk_window_present (GTK_WINDOW (data));
49
50   return DBUS_TYPE_INVALID;
51 }
52
53 int main( int argc, char* argv[] )
54 {
55     /* Create needed variables */
56     HildonProgram *program;
57     HildonWindow *window;
58     GtkWidget *button;
59     osso_context_t *osso_cont;
60         osso_return_t ret;
61
62         locale_init();
63
64     osso_cont = osso_initialize(APP_NAME, APP_VER, TRUE, NULL);
65         if (osso_cont == NULL)
66     {
67         fprintf (stderr, "osso_initialize failed.\n");
68         exit (1);
69     }
70
71     /* Initialize the GTK. */
72     gtk_init( &argc, &argv );
73
74     /* Create the hildon program and setup the title */
75     program = HILDON_PROGRAM(hildon_program_get_instance());
76     g_set_application_name("Maevies");
77
78     /* Create HildonWindow and set it to HildonProgram */
79     window = HILDON_WINDOW(hildon_window_new());
80     hildon_program_add_window(program, window);
81
82     /* Quit program when window is closed. */
83     g_signal_connect (G_OBJECT (window), "delete_event",
84                       G_CALLBACK (gtk_main_quit), NULL);
85
86     /* Quit program when window is otherwise destroyed. */
87     g_signal_connect (G_OBJECT (window), "destroy",
88                       G_CALLBACK (gtk_main_quit), NULL);
89
90     /* Create button and add it to main view */
91     button = gtk_button_new_with_label(_("Hello World!!!"));
92     gtk_container_add(GTK_CONTAINER(window),
93                       button);
94
95     g_signal_connect (G_OBJECT (button), "clicked",
96                       G_CALLBACK (button_clicked), NULL);
97
98     ret = osso_rpc_set_cb_f (osso_cont,
99                            APP_SERVICE,
100                            APP_METHOD,
101                            APP_SERVICE,
102                            dbus_callback, GTK_WIDGET( window ));
103         if (ret != OSSO_OK) {
104                 fprintf (stderr, "osso_rpc_set_cb_f failed: %d.\n", ret);
105             exit (1);
106         }
107
108     /* Begin the main application */
109     gtk_widget_show_all ( GTK_WIDGET ( window ) );
110     gtk_main();
111
112     /* Exit */
113     return 0;
114 }