Provide plugins with Osso context
[cinaest] / src / plugins / imdb-plugin.vala
index f91f3cd..b2a5f05 100644 (file)
@@ -22,8 +22,9 @@ using Hildon;
 class IMDbPlugin : Plugin {
        private dynamic DBus.Object server;
        List<MovieSource> sources;
+       private weak Osso.Context osso_context;
 
-       public override void hello (Gtk.Window window) {
+       public override void hello (Gtk.Window window, Osso.Context context) {
                string filename = Path.build_filename (Environment.get_user_cache_dir(),
                                                       "cinaest", "imdb.db", null);
                stdout.printf ("IMDb Plugin Loaded. Cache Db: %s\n", filename);
@@ -43,6 +44,11 @@ class IMDbPlugin : Plugin {
 
                sources = new List<MovieSource> ();
                sources.append (source);
+
+               osso_context = context;
+
+               // FIXME - this forces the inclusion of config.h
+               (void) Config.GETTEXT_PACKAGE;
        }
 
        private void download_imdb (Gtk.Window window) {
@@ -84,6 +90,37 @@ class IMDbPlugin : Plugin {
                return sources;
        }
 
+       public override void settings_dialog (Gtk.Window window) {
+               var dialog = new Gtk.Dialog ();
+               dialog.set_transient_for (window);
+               dialog.set_title (_("IMDb plugin settings"));
+
+               string filename = Path.build_filename (Environment.get_user_cache_dir(),
+                                                      "cinaest", "imdb.db", null);
+               var file = File.new_for_path (filename);
+               var info = file.query_info (FILE_ATTRIBUTE_TIME_MODIFIED, FileQueryInfoFlags.NONE, null);
+               TimeVal tv;
+               info.get_modification_time (out tv);
+
+               var date = Date ();
+               date.set_time_val (tv);
+               char[] s = new char[64];
+               date.strftime (s, "%x");
+
+               var download = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, _("Download"), "Last update: " + (string) s);
+
+               VBox content = (VBox) dialog.get_content_area ();
+               content.pack_start (download, true, true, 0);
+
+               download.clicked.connect (() => {
+                       download_imdb (window);
+               });
+
+               dialog.show_all ();
+               dialog.run ();
+               dialog.destroy ();
+       }
+
        public override unowned string get_name () {
                return "IMDb";
        }
@@ -91,7 +128,7 @@ class IMDbPlugin : Plugin {
 
 class IMDBSource : MovieSource {
        MovieSource.ReceiveMovieFunction _get_callback;
-       public override void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit) {
+       public override async void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) {
                // IMDb has too many movies
                if (filter.title == "")
                        return;
@@ -99,7 +136,7 @@ class IMDBSource : MovieSource {
                                             "cinaest", "imdb.db", null));
 
                _get_callback = callback;
-               sqlite.query (filter, receive_movie);
+               yield sqlite.query (filter, receive_movie, cancellable);
        }
 
        private void receive_movie (string title, int year, int rating, int genres) {
@@ -108,6 +145,8 @@ class IMDBSource : MovieSource {
                movie.year = year;
                movie.rating = rating;
                movie.genres.field = genres;
+               // TODO - depending on settings, this could be something else, like director info or runtime
+               movie.secondary = movie.genres.to_string ();
                _get_callback (movie);
        }