Add IMDb download dialog
authorPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 30 Oct 2009 22:15:12 +0000 (23:15 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 30 Oct 2009 22:30:20 +0000 (23:30 +0100)
Downloads and parses the gzipped plaintext database files using the IMDb
plaintext downloader D-Bus service.

Makefile
src/plugins/imdb-download-dialog.vala [new file with mode: 0644]
src/plugins/imdb-plugin.vala

index 3fa5938..4e115be 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,9 +19,11 @@ imdb_plugin_SOURCES = \
        src/imdb/plaintext-downloader-interface.vala \
        src/movie.vala \
        src/plugin-interface.vala \
+       src/plugins/imdb-download-dialog.vala \
        src/plugins/imdb-plugin.vala
 
 imdb_plugin_CSOURCES = \
+       src/plugins/imdb-download-dialog.c \
        src/plugins/imdb-plugin.c
 
 imdb_plugin_VALAFLAGS = --vapidir ./vapi --pkg dbus-glib-1 --pkg hildon-1
diff --git a/src/plugins/imdb-download-dialog.vala b/src/plugins/imdb-download-dialog.vala
new file mode 100644 (file)
index 0000000..ba52c8d
--- /dev/null
@@ -0,0 +1,61 @@
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2009 Philipp Zabel
+ *
+ * Cinaest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cinaest is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+using Hildon;
+
+class IMDbDownloadDialog : Note {
+       public IMDbDownloadDialog (Gtk.Window window) {
+               transient_parent = window;
+       }
+
+       construct {
+               note_type = NoteType.PROGRESSBAR;
+               progressbar = new ProgressBar ();
+       }
+
+       public new void run (dynamic DBus.Object server, string mirror) {
+               int res;
+               try {
+                       server.Progress += this.on_progress;
+                       server.DescriptionChanged += this.on_description_changed;
+
+                       server.download (mirror, IMDbDownloader.MOVIES | IMDbDownloader.GENRES | IMDbDownloader.RATINGS);
+               } catch (DBus.Error e) {
+                       warning ("Failed to invoke IMDb downloader: %s", e.message);
+               }
+
+               show_all ();
+
+               res = base.run ();
+               if (res == ResponseType.CANCEL)
+                       server.cancel ();
+       }
+
+       private void on_progress (dynamic DBus.Object server, int percent) {
+               if (percent < 100) {
+                       progressbar.set_fraction (0.01 * percent);
+               } else {
+                       close ();
+               }
+       }
+
+       private void on_description_changed (dynamic DBus.Object server, string _description) {
+               description = _description;
+       }
+}
index c4a3f01..fedd325 100644 (file)
  * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
  */
 
+using Gtk;
 using Hildon;
 
 class IMDbPlugin : Plugin {
+       private dynamic DBus.Object server;
+
        public override void hello (Gtk.Window window) {
                string filename = Path.build_filename (Environment.get_user_cache_dir(),
                                                       "cinaest", "imdb.db", null);
@@ -27,8 +30,12 @@ class IMDbPlugin : Plugin {
                if (!FileUtils.test (filename, FileTest.EXISTS)) {
                        var note = new Note.confirmation (window, "There is no local copy of the Internet Movie Database (IMDb). Download it now?\n\nThis can be started later from the Settings dialog.");
 
-                       note.run ();
+                       var response = note.run ();
                        note.destroy ();
+
+                       if (response == ResponseType.OK) {
+                               download_imdb (window);
+                       }
                }
        }
 
@@ -37,6 +44,41 @@ class IMDbPlugin : Plugin {
 
        public override void add_movie (Movie movie) {
        }
+
+       private void download_imdb (Gtk.Window window) {
+               var picker = new PickerDialog (window);
+               var selector = new TouchSelector.text ();
+               string[] mirrors;
+
+               try {
+                       var conn = DBus.Bus.get (DBus.BusType.SESSION);
+                       server = conn.get_object (IMDbDownloader.DBUS_SERVICE,
+                                                 IMDbDownloader.DBUS_OBJECT,
+                                                 IMDbDownloader.DBUS_IFACE);
+
+                       mirrors = server.get_mirrors ();
+               } catch (DBus.Error e) {
+                       warning ("Failed connect to IMDb downloader: %s", e.message);
+                       return;
+               }
+
+               foreach (string mirror in mirrors) {
+                       selector.append_text (mirror);
+               }
+
+               picker.set_title ("Please select a source mirror");
+               picker.set_selector (selector);
+
+               int res = picker.run();
+               string mirror = selector.get_current_text ();
+               picker.destroy();
+
+               if (res == ResponseType.OK) {
+                       var download = new IMDbDownloadDialog (window);
+                       download.run (server, mirror);
+                       download.destroy ();
+               }
+       }
 }
 
 [ModuleInit]