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
--- /dev/null
+/* 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;
+ }
+}
* 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);
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);
+ }
}
}
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]