701195c83c6d961a7eaedf304f80b4a01c8115c5
[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         public IMDbDownloadDialog (Gtk.Window window) {
24                 transient_parent = window;
25         }
26
27         construct {
28                 note_type = NoteType.PROGRESSBAR;
29                 progressbar = new ProgressBar ();
30         }
31
32         public new void run (dynamic DBus.Object server, string mirror) {
33                 int res;
34                 try {
35                         server.Progress += this.on_progress;
36                         server.DescriptionChanged += this.on_description_changed;
37
38                         server.download (mirror, IMDbDownloader.MOVIES | IMDbDownloader.GENRES | IMDbDownloader.RATINGS | IMDbDownloader.AKAS);
39                 } catch (DBus.Error e) {
40                         warning ("Failed to invoke IMDb downloader: %s", e.message);
41                 }
42
43                 show_all ();
44
45                 res = base.run ();
46                 if (res == ResponseType.CANCEL)
47                         server.cancel ();
48         }
49
50         private void on_progress (dynamic DBus.Object server, int percent) {
51                 if (percent < 100) {
52                         progressbar.set_fraction (0.01 * percent);
53                 } else {
54                         close ();
55                 }
56         }
57
58         private void on_description_changed (dynamic DBus.Object server, string _description) {
59                 description = _description;
60         }
61 }