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
EXTRA_DIST = \
- main.c
+ main.c
\ No newline at end of file
#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);
-
}
#ifndef EXTRA_SCENES_PROVIDER_H_
#define EXTRA_SCENES_PROVIDER_H_
-int has_stingers(const char *movie);
+#include <hildon/hildon.h>
+
+gboolean has_stingers(const gchar *movie);
#endif /* EXTRA_SCENES_PROVIDER_H_ */
--- /dev/null
+/*
+ * movie.c
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 spenap <spenap@gmail.com>
+ *
+ * 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);
+}
+
--- /dev/null
+/*
+ * movie.h
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 spenap <spenap@gmail.com>
+ *
+ * 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 <hildon/hildon.h>
+
+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_ */
--- /dev/null
+/*
+ * maevies_window.c
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 spenap <spenap@gmail.com>
+ *
+ * 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);
+}
--- /dev/null
+/*
+ * maevies_window.h
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 spenap <spenap@gmail.com>
+ *
+ * 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 <hildon/hildon.h>
+#include <libosso.h>
+
+#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_ */
#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
#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;
}
#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;
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);
/* 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);
}
#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_ */