Added an example to test the WATC module. It lets you query whatsafterthecredits...
[maevies] / src / maevies_window.c
1 /*
2  * maevies_window.c
3  *
4  * This file is part of maevies
5  * Copyright (C) 2009 spenap <spenap@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  */
18
19 #include "maevies_window.h"
20
21 static void hello_item_clicked(GtkButton *button, gpointer data);
22
23 G_DEFINE_TYPE(MaeviesWindow, maevies_window, HILDON_TYPE_WINDOW)
24
25 static void maevies_window_dispose(GObject *object) {
26
27         MaeviesWindow *self = MAEVIES_WINDOW(object);
28
29         /* Free member data.
30          * Note that the child widgets are destroyed automatically.
31          */
32
33         G_OBJECT_CLASS (maevies_window_parent_class)->dispose(object);
34 }
35
36 static void maevies_window_finalize(GObject *object) {
37         G_OBJECT_CLASS (maevies_window_parent_class)->finalize(object);
38 }
39
40 static void maevies_window_class_init(MaeviesWindowClass *klass) {
41         GObjectClass *object_class = G_OBJECT_CLASS (klass);
42
43         object_class->dispose = maevies_window_dispose;
44         object_class->finalize = maevies_window_finalize;
45 }
46
47 static void maevies_window_init(MaeviesWindow *self) {
48
49         /* Create button and add it to main view */
50         self->hello_item = gtk_button_new_with_label("Hello World!!!");
51         gtk_container_add(GTK_CONTAINER(self), self->hello_item);
52
53         g_signal_connect(G_OBJECT(self->hello_item), "clicked", G_CALLBACK(hello_item_clicked),
54                         self);
55
56         /* Init movie */
57         self->movie = maevies_movie_new("Zombieland");
58 }
59
60 MaeviesWindow* maevies_window_new(osso_context_t *osso) {
61         MaeviesWindow *self = MAEVIES_WINDOW(g_object_new(MAEVIES_TYPE_WINDOW,
62                                         NULL));
63
64         /* Avoid adding extra code such as this to a _new() function when writing
65          * widgets that should be reusable. This should really be a GObject property.
66          */
67         self->osso = osso;
68
69         return self;
70 }
71
72 static void hello_item_clicked(GtkButton* button, gpointer data) {
73
74         MaeviesWindow *self = MAEVIES_WINDOW(data);
75         gchar *has_stingers = NULL;
76
77         g_assert(self);
78
79         movie_get_info(self->movie, NULL);
80
81
82         if (self->movie->has_stingers)
83                 has_stingers = "Con escenas";
84         else
85                 has_stingers = "Sin escenas";
86
87         gtk_button_set_label(button, has_stingers);
88 }