/* 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 CatalogPlugin : Plugin { List sources; private CatalogSqlite sqlite; private Gtk.Dialog dialog; public override void hello (Gtk.Window window, Osso.Context context) { string data_dir = Path.build_filename (Environment.get_user_data_dir(), "cinaest"); string filename = Path.build_filename (data_dir, "catalog.db"); // Make sure the data directory is available DirUtils.create_with_parents (data_dir, 0770); sqlite = new CatalogSqlite (filename); sources = new List (); var source = new CatalogSource ("Collection", _("Collection"), _("Personal movie list"), sqlite); sources.append (source); source = new CatalogSource ("Loaned", _("Loaned movies"), _("Movies loaned to friends"), sqlite); sources.append (source); source = new CatalogSource ("Watchlist", _("Watchlist"), _("Movies of interest"), sqlite); sources.append (source); stdout.printf ("Catalog Plugin Loaded.\n"); } public override unowned List get_sources () { return (List) sources; } public override List get_actions (Movie movie, Gtk.Window window) { var list = new List (); list.append (new MovieAction (_("Add to catalog"), on_add_to_catalog, movie, window)); return list; } private void on_add_to_catalog (Movie movie, Gtk.Window window) { dialog = new Gtk.Dialog (); dialog.set_transient_for (window); dialog.set_title (_("Add movie to catalog - Select list")); int i = 0; var available_sources = new List (); foreach (CatalogSource s in sources) { if (!s.contains (movie)) { available_sources.append ((MovieSource) s); i++; } } var source_list = new SourceListView (available_sources, true); var content = (VBox) dialog.get_content_area (); content.pack_start (source_list, true, true, 0); if (i > 5) i = 5; content.set_size_request (-1, i*70); // Connect signals source_list.source_activated.connect (on_source_activated); dialog.show_all (); int res = dialog.run (); if (res >= 0) { var source = sources.nth_data (res); source.add_movie (movie); var banner = (Banner) Banner.show_information_with_markup (window, null, _("'%s' added to list '%s'").printf (movie.title, source.get_name ())); banner.set_timeout (1500); } dialog.destroy (); dialog = null; } private void on_source_activated (MovieSource source) { int n = sources.index ((CatalogSource) source); dialog.response (n); } public override void settings_dialog (Gtk.Window window) { var dialog = new Gtk.Dialog (); dialog.set_transient_for (window); dialog.set_title (_("Catalog plugin settings")); var button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL); button.set_title (_("Select active movie lists")); button.set_value (_("Collection, Loaned movies, Watchlist")); var content = (VBox) dialog.get_content_area (); content.pack_start (button, true, true, 0); dialog.add_button (_("Done"), ResponseType.ACCEPT); dialog.show_all (); int res = dialog.run (); if (res == ResponseType.ACCEPT) { } dialog.destroy (); } public override unowned string get_name () { return _("Catalog"); } } class CatalogSource : MovieSource { private string table; private string name; private string description; private CatalogSqlite sqlite; public CatalogSource (string _table, string _name, string _description, CatalogSqlite _sqlite) { GLib.Object (active: true); table = _table; name = _name; description = _description; sqlite = _sqlite; } public override bool active { get; set construct; } public override async void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) { yield sqlite.query (table, filter, callback, limit, cancellable); } public override void add_movie (Movie movie) { sqlite.add_movie (table, movie); } public override void delete_movie (Movie movie) { sqlite.delete_movie (table, movie); } internal bool contains (Movie movie) { return sqlite.contains (table, movie); } public override unowned string get_name () { return name; } public override unowned string get_description () { return description; } public override bool get_editable () { return true; } } [ModuleInit] public Type register_plugin () { // types are registered automatically return typeof (CatalogPlugin); }