From: Philipp Zabel Date: Fri, 13 Aug 2010 15:51:33 +0000 (+0200) Subject: IMDb plugin: optionally download actors and actresses X-Git-Url: http://git.maemo.org/git/?p=cinaest;a=commitdiff_plain;h=0895fbdb5e3cc7aac90107695122edb937c8924b IMDb plugin: optionally download actors and actresses Enable download and parsing of actors, actresses, directors and writers lists. --- diff --git a/src/imdb/imdb-sqlite.vala b/src/imdb/imdb-sqlite.vala index 11adef8..a49160c 100644 --- a/src/imdb/imdb-sqlite.vala +++ b/src/imdb/imdb-sqlite.vala @@ -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) { diff --git a/src/plugins/imdb-download-dialog.vala b/src/plugins/imdb-download-dialog.vala index 0811b74..165c6c9 100644 --- a/src/plugins/imdb-download-dialog.vala +++ b/src/plugins/imdb-download-dialog.vala @@ -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) { diff --git a/src/plugins/imdb-plugin.vala b/src/plugins/imdb-plugin.vala index 4ac86c5..b37e653 100644 --- a/src/plugins/imdb-plugin.vala +++ b/src/plugins/imdb-plugin.vala @@ -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 ();