Plugin interface: add delete_movie 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, Osso.Context context) {
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 List<MovieAction> get_actions (Movie movie, Gtk.Window window) {
42                 List<MovieAction> list = null;
43
44                 return list;
45         }
46
47         public override void settings_dialog (Gtk.Window window) {
48                 GoogleSource source = (GoogleSource) sources.data;
49                 var dialog = new Gtk.Dialog ();
50                 dialog.set_transient_for (window);
51                 dialog.set_title (_("Google plugin settings"));
52
53                 var selector = new TouchSelectorEntry.text ();
54                 selector.append_text ("Berlin");
55
56                 var button = new PickerButton (SizeType.FINGER_HEIGHT, ButtonArrangement.HORIZONTAL);
57                 button.set_title (_("Location"));
58                 button.set_selector (selector);
59                 button.set_value (source.location);
60
61                 var content = (VBox) dialog.get_content_area ();
62                 content.pack_start (button, true, true, 0);
63
64                 dialog.add_button ("Done", ResponseType.ACCEPT);
65
66                 dialog.show_all ();
67                 int res = dialog.run ();
68                 if (res == ResponseType.ACCEPT) {
69                         source.location = button.get_value ();
70                 }
71                 dialog.destroy ();
72         }
73
74         public override unowned string get_name () {
75                 return "Google";
76         }
77 }
78
79 class GoogleSource : MovieSource {
80         public string location;
81         public string description;
82
83         public override async void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) {
84                 var parser = new GoogleParser ();
85
86                 yield parser.query (filter, location, callback, cancellable);
87                 if (location == null) {
88                         location = parser.location;
89                 }
90         }
91
92         public override void add_movie (Movie movie) {
93         }
94
95         public override void delete_movie (Movie movie) {
96         }
97
98         public override unowned string get_name () {
99                 return _("Google");
100         }
101
102         public override unowned string get_description () {
103                 if (location != null && location != "") {
104                         description = _("Movie Showtimes near %s").printf (location);
105                 } else {
106                         description =  _("Movie Showtimes");
107                 }
108                 return description;
109         }
110
111         public override bool get_editable () {
112                 return false;
113         }
114 }
115
116 [ModuleInit]
117 public Type register_plugin () {
118         // types are registered automatically
119         return typeof (GooglePlugin);
120 }