ui: Several UI changes
[maevies] / test / mvs-minfo-provider-test.c
1 /*
2  * mvs-minfo-provider-test.c
3  *
4  * This file is part of maevies
5  * Copyright (C) 2010 Simón Pena <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 <stdio.h>
20 #include <glib.h>
21
22 #include "mvs-minfo-provider.h"
23 #include "mvs-tmdb-movie.h"
24 #include "mvs-watc-movie.h"
25
26 static GMainLoop *loop = NULL;
27 static gchar *query = "Zombieland";
28 static gboolean watc = FALSE;
29 static gboolean tmdb = FALSE;
30
31 static GOptionEntry entries[] = {
32         { "watc", 'w', 0, G_OPTION_ARG_NONE, &watc, "Query WATC service", NULL },
33         { "tmdb", 't', 0, G_OPTION_ARG_NONE, &tmdb, "Query TMDB service (default)", NULL },
34         { "query", 'q', 0, G_OPTION_ARG_STRING, &query, "query", "query term" },
35         { NULL }
36 };
37
38 static void
39 response_received_callback (MvsMInfoProvider *minfo_provider, GList *list,
40                             gpointer user_data)
41 {
42         GList *tmp = NULL;
43
44         for (tmp = list; tmp; tmp = tmp->next) {
45
46                 if (MVS_IS_TMDB_MOVIE (tmp->data)) {
47
48                         MvsTmdbMovie *tmdb_movie = MVS_TMDB_MOVIE (tmp->data);
49
50                         mvs_tmdb_movie_print (tmdb_movie);
51                         g_print ("\n");
52
53                         g_object_unref (tmdb_movie);
54                 }
55                 else if (MVS_IS_WATC_MOVIE (tmp->data)) {
56
57                         MvsWatcMovie *watc_movie = MVS_WATC_MOVIE (tmp->data);
58
59                         mvs_watc_movie_print (watc_movie);
60                         g_print ("\n");
61
62                         g_object_unref (watc_movie);
63                 }
64         }
65
66         g_list_free (list);
67         g_main_loop_quit (loop);
68 }
69
70 int
71 main (int argc, char **argv)
72 {
73         MvsMInfoProvider *minfo_provider = NULL;
74         GOptionContext *context = NULL;
75         GOptionGroup *gst_option_group = NULL;
76         GError *error = NULL;
77         MvsService service = MVS_SERVICE_TMDB;
78
79         g_type_init ();
80
81         g_thread_init (NULL);
82
83         context = g_option_context_new (" - Tests data provider behavior");
84         g_option_context_add_main_entries (context, entries, NULL);
85         if (!g_option_context_parse (context, &argc, &argv, &error)) {
86                 g_critical ("option parsing failed: %s", error->message);
87                 return -1;
88         }
89
90         if (watc)
91                 service = MVS_SERVICE_WATC;
92         else if (tmdb)
93                 service = MVS_SERVICE_TMDB;
94
95         minfo_provider = mvs_minfo_provider_new ();
96         g_signal_connect (minfo_provider, "response-received",
97                           G_CALLBACK (response_received_callback), NULL);
98
99         loop = g_main_loop_new (NULL, FALSE);
100
101         mvs_minfo_provider_query (minfo_provider, service,
102                                   query);
103
104         g_main_loop_run (loop);
105         g_object_unref (minfo_provider);
106         g_main_loop_unref (loop);
107
108         return 0;
109 }