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