IMDb plugin: optionally download actors and actresses
[cinaest] / src / plugins / imdb-download-dialog.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 IMDbDownloadDialog : Note {
23         private bool plots;
24         private bool actors;
25
26         public IMDbDownloadDialog (Gtk.Window window, bool _plots, bool _actors) {
27                 transient_parent = window;
28                 plots = _plots;
29                 actors = _actors;
30         }
31
32         construct {
33                 note_type = NoteType.PROGRESSBAR;
34                 progressbar = new ProgressBar ();
35         }
36
37         public new void run (dynamic DBus.Object server, string mirror) {
38                 int res;
39                 try {
40                         server.Progress.connect (this.on_progress);
41                         server.DescriptionChanged.connect (this.on_description_changed); 
42                         int flags = IMDbDownloader.MOVIES | IMDbDownloader.GENRES | IMDbDownloader.RATINGS | IMDbDownloader.AKAS;
43                         if (plots)
44                                 flags |= IMDbDownloader.PLOTS;
45                         if (actors)
46                                 flags |= IMDbDownloader.ACTORS;
47
48                         server.download (mirror, flags);
49                 } catch (DBus.Error e) {
50                         warning ("Failed to invoke IMDb downloader: %s", e.message);
51                 }
52
53                 show_all ();
54
55                 res = base.run ();
56                 if (res == ResponseType.CANCEL)
57                         server.cancel ();
58         }
59
60         private void on_progress (dynamic DBus.Object server, int percent) {
61                 if (percent < 100) {
62                         progressbar.set_fraction (0.01 * percent);
63                 } else {
64                         close ();
65                 }
66         }
67
68         private void on_description_changed (dynamic DBus.Object server, string _description) {
69                 description = _description;
70         }
71 }