From: spenap Date: Sat, 7 Nov 2009 23:41:30 +0000 (+0000) Subject: The application GUI is now organized into a maevies_window, for the GTK things and... X-Git-Url: https://vcs.maemo.org/git/?p=maevies;a=commitdiff_plain;h=925bda108bed833f3426315e2f8a5070f75dcdb0 The application GUI is now organized into a maevies_window, for the GTK things and callbacks (the UI logic should be there), and a maevies_movie, for the logic and things related to the movies themselves. The UI part is connected to the core via the signals, and the next point should involve using asynchrounous callbacks. I also added a txt to describe the Google Movies API. git-svn-id: file:///svnroot/maevies/trunk@8 a96798e0-47ce-444a-94a4-1d14e63744fc --- diff --git a/Makefile.am b/Makefile.am index 8ea279f..b700ca0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,7 +24,9 @@ bin_PROGRAMS = \ maevies_SOURCES = \ src/main.c \ src/extra_scenes_provider.c \ - src/watc_provider.c + src/watc_provider.c \ + src/maevies_movie.c \ + src/maevies_window.c # /Sources # LDADD diff --git a/src/Makefile.am b/src/Makefile.am index 18de266..8a6de89 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,2 +1,2 @@ EXTRA_DIST = \ - main.c + main.c \ No newline at end of file diff --git a/src/extra_scenes_provider.c b/src/extra_scenes_provider.c index 9267df9..c4f2b43 100644 --- a/src/extra_scenes_provider.c +++ b/src/extra_scenes_provider.c @@ -19,14 +19,13 @@ #include "extra_scenes_provider.h" #include "watc_provider.h" -int has_stingers(const char *movie) { +gboolean has_stingers(const gchar *movie) { - /* Here there should be a mechanism + /* There should be a mechanism here * allowing us to dynamically load new libraries * dlopen - http://stackoverflow.com/questions/384121/creating-a-module-system-dynamic-loading-in-c * Until we get it, we'll use just one of the provided providers ;) */ return watc_has_stingers(movie); - } diff --git a/src/extra_scenes_provider.h b/src/extra_scenes_provider.h index 5685991..5093512 100644 --- a/src/extra_scenes_provider.h +++ b/src/extra_scenes_provider.h @@ -19,6 +19,8 @@ #ifndef EXTRA_SCENES_PROVIDER_H_ #define EXTRA_SCENES_PROVIDER_H_ -int has_stingers(const char *movie); +#include + +gboolean has_stingers(const gchar *movie); #endif /* EXTRA_SCENES_PROVIDER_H_ */ diff --git a/src/maevies_movie.c b/src/maevies_movie.c new file mode 100644 index 0000000..7393726 --- /dev/null +++ b/src/maevies_movie.c @@ -0,0 +1,39 @@ +/* + * movie.c + * + * This file is part of maevies + * Copyright (C) 2009 spenap + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include "maevies_movie.h" +#include "extra_scenes_provider.h" + +MaeviesMovie *maevies_movie_new(const gchar *name) { + + MaeviesMovie *movie = g_new0(MaeviesMovie,1); + + movie->title = name; + + return movie; +} + +void movie_get_info(MaeviesMovie *movie, GCallback callback) { + + /* Get movie info */ + + + /* Get movie stingers */ + movie->has_stingers = has_stingers(movie->title); +} + diff --git a/src/maevies_movie.h b/src/maevies_movie.h new file mode 100644 index 0000000..aeeb6d8 --- /dev/null +++ b/src/maevies_movie.h @@ -0,0 +1,45 @@ +/* + * movie.h + * + * This file is part of maevies + * Copyright (C) 2009 spenap + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#ifndef MOVIE_H_ +#define MOVIE_H_ + +#include + +G_BEGIN_DECLS + +typedef struct _MaeviesMovie MaeviesMovie; + +struct _MaeviesMovie { + + gboolean has_stingers; + const gchar *title; + gchar *director; + GSList *cast; + gint ranking; + gint year; + +}; + +MaeviesMovie *maevies_movie_new(const char *name); + +void movie_get_info(MaeviesMovie *movie, GCallback callback); + +G_END_DECLS + +#endif /* MOVIE_H_ */ diff --git a/src/maevies_window.c b/src/maevies_window.c new file mode 100644 index 0000000..7d5efa2 --- /dev/null +++ b/src/maevies_window.c @@ -0,0 +1,87 @@ +/* + * maevies_window.c + * + * This file is part of maevies + * Copyright (C) 2009 spenap + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#include "maevies_window.h" + +static void hello_item_clicked(GtkButton *button, gpointer data); + +G_DEFINE_TYPE(MaeviesWindow, maevies_window, HILDON_TYPE_WINDOW) + +static void maevies_window_dispose(GObject *object) { + + MaeviesWindow *self = MAEVIES_WINDOW(object); + + /* Free member data. + * Note that the child widgets are destroyed automatically. + */ + + G_OBJECT_CLASS (maevies_window_parent_class)->dispose(object); +} + +static void maevies_window_finalize(GObject *object) { + G_OBJECT_CLASS (maevies_window_parent_class)->finalize(object); +} + +static void maevies_window_class_init(MaeviesWindowClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = maevies_window_dispose; + object_class->finalize = maevies_window_finalize; +} + +static void maevies_window_init(MaeviesWindow *self) { + + /* Create button and add it to main view */ + self->hello_item = gtk_button_new_with_label("Hello World!!!"); + gtk_container_add(GTK_CONTAINER(self), self->hello_item); + + g_signal_connect(G_OBJECT(self->hello_item), "clicked", G_CALLBACK(hello_item_clicked), + self); + + /* Init movie */ + self->movie = maevies_movie_new("Zombieland"); +} + +MaeviesWindow* maevies_window_new(osso_context_t *osso) { + MaeviesWindow *self = MAEVIES_WINDOW(g_object_new(MAEVIES_TYPE_WINDOW, + NULL)); + + /* Avoid adding extra code such as this to a _new() function when writing + * widgets that should be reusable. This should really be a GObject property. + */ + self->osso = osso; + + return self; +} + +static void hello_item_clicked(GtkButton* button, gpointer data) { + + MaeviesWindow *self = MAEVIES_WINDOW(data); + g_assert(self); + + movie_get_info(self->movie, NULL); + + gchar *has_stingers = NULL; + + if (self->movie->has_stingers) + has_stingers = "Con escenas"; + else + has_stingers = "Sin escenas"; + + gtk_button_set_label(button, has_stingers); +} diff --git a/src/maevies_window.h b/src/maevies_window.h new file mode 100644 index 0000000..cb20c23 --- /dev/null +++ b/src/maevies_window.h @@ -0,0 +1,78 @@ +/* + * maevies_window.h + * + * This file is part of maevies + * Copyright (C) 2009 spenap + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + */ + +#ifndef MAEVIES_WINDOW_H_ +#define MAEVIES_WINDOW_H_ + +#include +#include + +#include "maevies_movie.h" + +G_BEGIN_DECLS + +#define MAEVIES_TYPE_WINDOW maevies_window_get_type() + +#define MAEVIES_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + MAEVIES_TYPE_WINDOW, MaeviesWindow)) + +#define MAEVIES_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + MAEVIES_TYPE_WINDOW, MaeviesWindowClass)) + +#define MAEVIES_IS_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + MAEVIES_TYPE_WINDOW)) + +#define MAEVIES_IS_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + MAEVIES_TYPE_WINDOW)) + +#define MAEVIES_WINDOW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + MAEVIES_TYPE_WINDOW, MaeviesWindowClass)) + +typedef struct _MaeviesWindow MaeviesWindow; +typedef struct _MaeviesWindowClass MaeviesWindowClass; + +struct _MaeviesWindow { + + /* The Hildon window */ + HildonWindow parent; + + /* Osso context */ + osso_context_t *osso; + + /* "Say hello world" button */ + GtkWidget *hello_item; + + MaeviesMovie *movie; +}; + +struct _MaeviesWindowClass { + HildonWindowClass parent_class; +}; + +GType maevies_window_get_type(void); + +MaeviesWindow* maevies_window_new(osso_context_t *osso); + +G_END_DECLS + +#endif /* MAEVIES_WINDOW_H_ */ diff --git a/src/main.c b/src/main.c index 790dd5f..b6604df 100644 --- a/src/main.c +++ b/src/main.c @@ -24,6 +24,7 @@ #include "localisation.h" #include "extra_scenes_provider.h" +#include "maevies_window.h" /* Defines to add the application to dbus and keep it running * Please do not modify "APP_NAME" (or other defines) to different name @@ -34,87 +35,77 @@ #define APP_METHOD "/com/nokia/maevies" /* end defines */ -static void button_clicked (GtkButton* button, gpointer data) -{ - if(has_stingers("Zombieland")) - printf("Movie has stingers\n"); - else - printf("Movie doesn't have stingers\n"); - gtk_main_quit(); -} +typedef struct _AppData AppData; -static gint -dbus_callback (const gchar *interface, const gchar *method, - GArray *arguments, gpointer data, - osso_rpc_t *retval) -{ - printf ("dbus: %s, %s\n", interface, method); +struct _AppData { - if (!strcmp (method, "top_application")) - gtk_window_present (GTK_WINDOW (data)); + HildonProgram *program; + MaeviesWindow *window; - return DBUS_TYPE_INVALID; -} +}; + +static gint dbus_callback(const gchar *interface, const gchar *method, + GArray *arguments, gpointer data, osso_rpc_t *retval); -int main( int argc, char* argv[] ) -{ - /* Create needed variables */ - HildonProgram *program; - HildonWindow *window; - GtkWidget *button; - osso_context_t *osso_cont; +gint main(gint argc, gchar* argv[]) { + + osso_context_t *osso_cont; osso_return_t ret; + AppData *data = g_new0(AppData,1); locale_init(); - osso_cont = osso_initialize(APP_NAME, APP_VER, TRUE, NULL); - if (osso_cont == NULL) - { - fprintf (stderr, "osso_initialize failed.\n"); - exit (1); - } - - /* Initialize the GTK. */ - gtk_init( &argc, &argv ); - - /* Create the hildon program and setup the title */ - program = HILDON_PROGRAM(hildon_program_get_instance()); - g_set_application_name("Maevies"); - - /* Create HildonWindow and set it to HildonProgram */ - window = HILDON_WINDOW(hildon_window_new()); - hildon_program_add_window(program, window); - - /* Quit program when window is closed. */ - g_signal_connect (G_OBJECT (window), "delete_event", - G_CALLBACK (gtk_main_quit), NULL); - - /* Quit program when window is otherwise destroyed. */ - g_signal_connect (G_OBJECT (window), "destroy", - G_CALLBACK (gtk_main_quit), NULL); - - /* Create button and add it to main view */ - button = gtk_button_new_with_label(_("Hello World!!!")); - gtk_container_add(GTK_CONTAINER(window), - button); - - g_signal_connect (G_OBJECT (button), "clicked", - G_CALLBACK (button_clicked), NULL); - - ret = osso_rpc_set_cb_f (osso_cont, - APP_SERVICE, - APP_METHOD, - APP_SERVICE, - dbus_callback, GTK_WIDGET( window )); + osso_cont = osso_initialize(APP_NAME, APP_VER, TRUE, NULL); + g_assert(osso_cont); + + /* Initialize the GTK. */ + gtk_init(&argc, &argv); + + /* Initialize thread system */ + g_thread_init(NULL); + + /* Create the hildon program and setup the title */ + data->program = HILDON_PROGRAM(hildon_program_get_instance()); + g_set_application_name("Maevies"); + + /* Create HildonWindow and set it to HildonProgram */ + data->window = maevies_window_new(osso_cont); + hildon_program_add_window(data->program, HILDON_WINDOW(data->window)); + + ret = osso_rpc_set_cb_f(data->window->osso, APP_SERVICE, APP_METHOD, + APP_SERVICE, dbus_callback, GTK_WIDGET(data->window)); if (ret != OSSO_OK) { - fprintf (stderr, "osso_rpc_set_cb_f failed: %d.\n", ret); - exit (1); + fprintf(stderr, "osso_rpc_set_cb_f failed: %d.\n", ret); + exit(1); } - /* Begin the main application */ - gtk_widget_show_all ( GTK_WIDGET ( window ) ); - gtk_main(); + /* Begin the main application */ + gtk_widget_show_all(GTK_WIDGET(data->window)); + + /* Quit program when window is closed. */ + g_signal_connect(G_OBJECT(data->window), "delete_event", + G_CALLBACK(gtk_main_quit), NULL); + + /* Quit program when window is otherwise destroyed. */ + g_signal_connect(G_OBJECT(data->window), "destroy", G_CALLBACK(gtk_main_quit), + NULL); + + gtk_main(); + + /* Clean up: */ + gtk_widget_destroy(GTK_WIDGET (data->window)); + g_free(data); + + /* Exit */ + return 0; +} + +static gint dbus_callback(const gchar *interface, const gchar *method, + GArray *arguments, gpointer data, osso_rpc_t *retval) { + printf("dbus: %s, %s\n", interface, method); + + if (!strcmp(method, "top_application")) + gtk_window_present(GTK_WINDOW(data)); - /* Exit */ - return 0; + return DBUS_TYPE_INVALID; } diff --git a/src/watc_provider.c b/src/watc_provider.c index b70b66f..9f5ae0e 100644 --- a/src/watc_provider.c +++ b/src/watc_provider.c @@ -19,7 +19,7 @@ #include "watc_provider.h" #include "string.h" -int watc_has_stingers(const char *name) { +gboolean watc_has_stingers(const gchar *name) { RestProxy *proxy; RestProxyCall *call; @@ -27,8 +27,8 @@ int watc_has_stingers(const char *name) { gssize len; /* Initialization: most probably done in the invoker */ - g_thread_init(NULL); - g_type_init(); + /* g_thread_init(NULL); + g_type_init(); */ /* Provider initialization, should be refactored. Maybe it can be reused between calls */ proxy = rest_proxy_new(WATC_SERVICE_URL, FALSE); @@ -63,7 +63,7 @@ int watc_has_stingers(const char *name) { /* Ad-hoc implementation. Will give a wrong result if the query had more than one result, * if the title has a * in its text, or if the conventions used in what's after the credits vary. */ -int parse_response(const gchar *response) { +gboolean parse_response(const gchar *response) { return (strpbrk(response, "*") != NULL); } diff --git a/src/watc_provider.h b/src/watc_provider.h index 91e1392..4192b50 100644 --- a/src/watc_provider.h +++ b/src/watc_provider.h @@ -24,6 +24,6 @@ #define WATC_SERVICE_URL "http://whatsafterthecredits.com/api.php" -int watc_has_stingers(const char *name); +gboolean watc_has_stingers(const gchar *name); #endif /* WATC_PROVIDER_H_ */