IMDb plugin: optionally download actors and actresses
authorPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 13 Aug 2010 15:51:33 +0000 (17:51 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Mon, 16 Aug 2010 13:11:07 +0000 (15:11 +0200)
Enable download and parsing of actors, actresses, directors and writers lists.

src/imdb/imdb-sqlite.vala
src/plugins/imdb-download-dialog.vala
src/plugins/imdb-plugin.vala

index 11adef8..a49160c 100644 (file)
@@ -362,8 +362,25 @@ class IMDbSqlite : Object {
                return count;
        }
 
-       public bool has_plots () {
-               return (count ("Plots") > 0);
+       public bool has_table (string table) {
+               string sql = "SELECT * FROM sqlite_master WHERE type=\"table\" AND name=\"%s\"".printf (table);
+               Statement stmt;
+               int rc;
+
+               rc = db.prepare_v2 (sql, -1, out stmt);
+               if (rc != Sqlite.OK) {
+                       stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());
+                       db.progress_handler (0, null);
+                       return false;
+               }
+
+               do {
+                       rc = stmt.step ();
+                       if (rc == Sqlite.ROW)
+                               return true;
+               } while (rc == Sqlite.ROW);
+
+               return false;
        }
 
        public string get_plot (string title) {
index 0811b74..165c6c9 100644 (file)
@@ -21,10 +21,12 @@ using Hildon;
 
 class IMDbDownloadDialog : Note {
        private bool plots;
+       private bool actors;
 
-       public IMDbDownloadDialog (Gtk.Window window, bool _plots) {
+       public IMDbDownloadDialog (Gtk.Window window, bool _plots, bool _actors) {
                transient_parent = window;
                plots = _plots;
+               actors = _actors;
        }
 
        construct {
@@ -40,6 +42,8 @@ class IMDbDownloadDialog : Note {
                        int flags = IMDbDownloader.MOVIES | IMDbDownloader.GENRES | IMDbDownloader.RATINGS | IMDbDownloader.AKAS;
                        if (plots)
                                flags |= IMDbDownloader.PLOTS;
+                       if (actors)
+                               flags |= IMDbDownloader.ACTORS;
 
                        server.download (mirror, flags);
                } catch (DBus.Error e) {
index 4ac86c5..b37e653 100644 (file)
@@ -36,7 +36,7 @@ class IMDbPlugin : Plugin {
                        note.destroy ();
 
                        if (response == ResponseType.OK) {
-                               download_imdb (window, false);
+                               download_imdb (window, false, false);
                        }
                }
 
@@ -51,7 +51,7 @@ class IMDbPlugin : Plugin {
                (void) Config.GETTEXT_PACKAGE;
        }
 
-       private void download_imdb (Gtk.Window window, bool plots) {
+       private void download_imdb (Gtk.Window window, bool plots, bool actors) {
                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, plots);
+                       var download = new IMDbDownloadDialog (window, plots, actors);
                        download.run (server, mirror);
                        download.destroy ();
                }
@@ -119,18 +119,25 @@ class IMDbPlugin : Plugin {
                dialog.set_title (_("IMDb plugin settings"));
 
                bool download_plots;
+               bool download_actors;
                try {
                        var sqlite = new IMDbSqlite (Path.build_filename (Environment.get_user_cache_dir (),
                                                     "cinaest", "imdb.db", null));
-                       download_plots = sqlite.has_plots ();
+                       download_plots = sqlite.has_table ("Plots");
+                       download_actors = sqlite.has_table ("Actors");
                } catch (Error e) {
                        download_plots = false;
+                       download_actors = false;
                }
 
                var plots = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
                plots.set_label (_("Download and store movie plots"));
                plots.set_active (download_plots);
 
+               var actors = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
+               actors.set_label (_("Download and store actors and actresses"));
+               actors.set_active (download_actors);
+
                string updated;
                string filename = Path.build_filename (Environment.get_user_cache_dir(),
                                                       "cinaest", "imdb.db", null);
@@ -153,6 +160,7 @@ class IMDbPlugin : Plugin {
 
                VBox content = (VBox) dialog.get_content_area ();
                content.pack_start (plots, true, true, 0);
+               content.pack_start (actors, true, true, 0);
                content.pack_start (download, true, true, 0);
 
                 var sizegroup = new Gtk.SizeGroup (SizeGroupMode.HORIZONTAL);
@@ -184,8 +192,12 @@ class IMDbPlugin : Plugin {
                        if (download_plots != plots.get_active ())
                                Hildon.Banner.show_information (window, null, _("Redownload the IMDb for this change to take effect."));
                });
+               actors.toggled.connect (() => {
+                       if (download_actors != actors.get_active ())
+                               Hildon.Banner.show_information (window, null, _("Redownload the IMDb for this change to take effect."));
+               });
                download.clicked.connect (() => {
-                       download_imdb (window, plots.get_active ());
+                       download_imdb (window, plots.get_active (), actors.get_active ());
                });
 
                dialog.show_all ();