IMDb plugin: make plot downloading optional
authorPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 9 Jan 2010 13:13:56 +0000 (14:13 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 9 Jan 2010 13:14:47 +0000 (14:14 +0100)
src/plugins/imdb-download-dialog.vala
src/plugins/imdb-plugin.vala

index 701195c..8173c0d 100644 (file)
@@ -20,8 +20,11 @@ using Gtk;
 using Hildon;
 
 class IMDbDownloadDialog : Note {
-       public IMDbDownloadDialog (Gtk.Window window) {
+       private bool plots;
+
+       public IMDbDownloadDialog (Gtk.Window window, bool _plots) {
                transient_parent = window;
+               plots = _plots;
        }
 
        construct {
@@ -35,7 +38,11 @@ class IMDbDownloadDialog : Note {
                        server.Progress += this.on_progress;
                        server.DescriptionChanged += this.on_description_changed;
 
-                       server.download (mirror, IMDbDownloader.MOVIES | IMDbDownloader.GENRES | IMDbDownloader.RATINGS | IMDbDownloader.AKAS);
+                       int flags = IMDbDownloader.MOVIES | IMDbDownloader.GENRES | IMDbDownloader.RATINGS | IMDbDownloader.AKAS;
+                       if (plots)
+                               flags |= IMDbDownloader.PLOTS;
+
+                       server.download (mirror, flags);
                } catch (DBus.Error e) {
                        warning ("Failed to invoke IMDb downloader: %s", e.message);
                }
index 887b79a..2fbf482 100644 (file)
@@ -36,7 +36,7 @@ class IMDbPlugin : Plugin {
                        note.destroy ();
 
                        if (response == ResponseType.OK) {
-                               download_imdb (window);
+                               download_imdb (window, false);
                        }
                }
 
@@ -51,7 +51,7 @@ class IMDbPlugin : Plugin {
                (void) Config.GETTEXT_PACKAGE;
        }
 
-       private void download_imdb (Gtk.Window window) {
+       private void download_imdb (Gtk.Window window, bool plots) {
                var picker = new PickerDialog (window);
                var selector = new TouchSelector.text ();
                string[] mirrors;
@@ -80,7 +80,7 @@ class IMDbPlugin : Plugin {
                picker.destroy();
 
                if (res == ResponseType.OK) {
-                       var download = new IMDbDownloadDialog (window);
+                       var download = new IMDbDownloadDialog (window, plots);
                        download.run (server, mirror);
                        download.destroy ();
                }
@@ -118,6 +118,19 @@ class IMDbPlugin : Plugin {
                dialog.set_transient_for (window);
                dialog.set_title (_("IMDb plugin settings"));
 
+               bool download_plots;
+               try {
+                       var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (),
+                                                    "cinaest", "imdb.db", null));
+                       download_plots = sqlite.has_plots ();
+               } catch (Error e) {
+                       download_plots = false;
+               }
+
+               var plots = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+               plots.set_label (_("Download and store movie plots"));
+               plots.set_active (download_plots);
+
                string updated;
                string filename = Path.build_filename (Environment.get_user_cache_dir(),
                                                       "cinaest", "imdb.db", null);
@@ -139,10 +152,16 @@ class IMDbPlugin : Plugin {
                var download = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, _("Download"), _("Last update: ") + updated);
 
                VBox content = (VBox) dialog.get_content_area ();
+               content.pack_start (plots, true, true, 0);
                content.pack_start (download, true, true, 0);
 
+               // Connect signals
+               plots.toggled.connect (() => {
+                       if (download_plots != plots.get_active ())
+                               Hildon.Banner.show_information (window, null, _("Redownload the IMDb for this change to take effect."));
+               });
                download.clicked.connect (() => {
-                       download_imdb (window);
+                       download_imdb (window, plots.get_active ());
                });
 
                dialog.show_all ();