Disable threading - turn update thread into async method
[cinaest] / src / plugins / google-plugin.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2009 Philipp Zabel
4  *
5  * Cinaest is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Cinaest is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 using Gtk;
20 using Hildon;
21
22 class GooglePlugin : Plugin {
23         List<MovieSource> sources;
24
25         public override void hello (Gtk.Window window) {
26                 stdout.printf ("Google Plugin Loaded.\n");
27
28                 var source = new GoogleSource ();
29
30                 sources = new List<MovieSource> ();
31                 sources.append (source);
32
33                 // FIXME - this forces the inclusion of config.h
34                 (void) Config.GETTEXT_PACKAGE;
35         }
36
37         public override unowned List<MovieSource> get_sources () {
38                 return sources;
39         }
40
41         public override void settings_dialog (Gtk.Window window) {
42                 GoogleSource source = (GoogleSource) sources.data;
43                 var dialog = new Gtk.Dialog ();
44                 dialog.set_transient_for (window);
45                 dialog.set_title (_("Google plugin settings"));
46
47                 var selector = new TouchSelectorEntry.text ();
48                 selector.append_text ("Berlin");
49
50                 var button = new PickerButton (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
51                 button.set_title (_("Location"));
52                 button.set_selector (selector);
53                 button.set_value (source.location);
54
55                 var content = (VBox) dialog.get_content_area ();
56                 content.pack_start (button, true, true, 0);
57
58                 dialog.add_button ("Done", ResponseType.ACCEPT);
59
60                 dialog.show_all ();
61                 int res = dialog.run ();
62                 if (res == ResponseType.ACCEPT) {
63                         source.location = button.get_value ();
64                 }
65                 dialog.destroy ();
66         }
67
68         public override unowned string get_name () {
69                 return "Google";
70         }
71 }
72
73 class GoogleSource : MovieSource {
74         public string location;
75         public string description;
76
77         public override async void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) {
78                 var parser = new GoogleParser ();
79
80                 yield parser.query (filter, location, callback, cancellable);
81         }
82
83         public override void add_movie (Movie movie) {
84         }
85
86         public override unowned string get_name () {
87                 return _("Google");
88         }
89
90         public override unowned string get_description () {
91                 if (location != null && location != "") {
92                         description = _("Movie Showtimes near %s").printf (location);
93                 } else {
94                         description =  _("Movie Showtimes");
95                 }
96                 return description;
97         }
98 }
99
100 [ModuleInit]
101 public Type register_plugin () {
102         // types are registered automatically
103         return typeof (GooglePlugin);
104 }