/* 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 .
*/
using Gtk;
using Hildon;
class MoviePilotPlugin : Plugin {
List sources;
public override void hello (Gtk.Window window, Osso.Context context) {
stdout.printf ("MoviePilot Plugin Loaded.\n");
var source = new MoviePilotSource ();
sources = new List ();
sources.append (source);
// FIXME - this forces the inclusion of config.h
(void) Config.GETTEXT_PACKAGE;
}
public override unowned List get_sources () {
return sources;
}
public override List get_actions (Movie _movie, Gtk.Window window) {
return new List ();
}
public override void settings_dialog (Gtk.Window window) {
MoviePilotSource source = (MoviePilotSource) sources.data;
var dialog = new Gtk.Dialog ();
dialog.set_transient_for (window);
dialog.set_title (_("MoviePilot plugin settings"));
var content = (VBox) dialog.get_content_area ();
var sizegroup = new Gtk.SizeGroup (SizeGroupMode.HORIZONTAL);
// User name
var hbox = new Gtk.HBox (false, MARGIN_DOUBLE);
var label = new Gtk.Label (_("User name"));
sizegroup.add_widget (label);
var entry = new Hildon.Entry (SizeType.FINGER_HEIGHT);
hbox.pack_start (label, false, false, 0);
hbox.pack_start (entry, true, true, 0);
content.pack_start (hbox, true, true, 0);
// Password
hbox = new Gtk.HBox (false, MARGIN_DOUBLE);
label = new Gtk.Label ("Password");
sizegroup.add_widget (label);
entry = new Hildon.Entry (SizeType.FINGER_HEIGHT);
hbox.pack_start (label, false, false, 0);
hbox.pack_start (entry, true, true, 0);
content.pack_start (hbox, true, true, 0);
dialog.add_button (_("Save"), ResponseType.ACCEPT);
dialog.show_all ();
int res = dialog.run ();
if (res == ResponseType.ACCEPT) {
/* ... */
}
dialog.destroy ();
}
public override unowned string get_name () {
return "MoviePilot";
}
}
class MoviePilotSource : MovieSource {
public string location;
public string description;
public MovieSource.ReceiveMovieFunction callback;
dynamic DBus.Object search;
public override bool active { get; set construct; }
public MoviePilotSource () {
GLib.Object (active: true);
}
SourceFunc get_movies_callback;
public override async int get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction _callback, int limit, Cancellable? cancellable) {
try {
string search_path;
dynamic DBus.Object server;
var conn = DBus.Bus.get (DBus.BusType.SESSION);
server = conn.get_object ("org.maemo.cinaest.MoviePilot",
"/org/maemo/cinaest/moviepilot",
"org.maemo.cinaest.MovieService");
server.NewSearch (out search_path);
search = conn.get_object ("org.maemo.cinaest.MoviePilot",
search_path,
"org.maemo.cinaest.MovieSearch");
callback = _callback;
search.MoviesFound.connect (on_movies_found);
print ("get_movies (%s)\n", filter.title);
search.start (filter.title);
} catch (Error e1) {
Banner.show_information (null, null, e1.message);
return 0;
}
get_movies_callback = get_movies.callback;
if (cancellable != null)
cancellable.cancelled.connect (() => { search.abort (); Idle.add (get_movies_callback); });
yield;
return 1 /* FIXME: n */;
}
private void on_movies_found (DBus.Object sender, string[] movies, bool finished) {
print ("found %d movies\n", movies.length);
var parser = new Json.Parser ();
var result = new SList ();
for (int i = 0; i < movies.length; i++) {
var movie = new Movie ();
try {
parser.load_from_data (movies[i], -1);
} catch (Error e) {
stderr.printf ("Error: %s\n%s\n", e.message, movies[i]);
}
var object = parser.get_root ().get_object ();
movie.title = object.get_string_member ("title");
movie.year = (int) object.get_int_member ("year");
movie.rating = (int) object.get_double_member ("rating");
movie.secondary = object.get_string_member ("genres").replace (",", ", ");
result.append (movie);
}
callback (result);
if (finished) {
search = null;
Idle.add (get_movies_callback);
}
}
public override void add_movie (Movie movie) {
}
public override void delete_movie (Movie movie) {
}
public override unowned string get_name () {
return _("MoviePilot");
}
public override unowned string get_description () {
description = _("Movies on MoviePilot");
return description;
}
public override SourceFlags get_flags () {
return SourceFlags.ONLINE;
}
}
[ModuleInit]
public Type register_plugin (TypeModule module) {
// types are registered automatically
return typeof (MoviePilotPlugin);
}