1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
5 * Cinaest is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Cinaest is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
22 class CatalogPlugin : Plugin {
23 List<CatalogSource> sources;
24 private CatalogSqlite sqlite;
25 private Gtk.Dialog dialog;
27 public override void hello (Gtk.Window window, Osso.Context context) {
28 string data_dir = Path.build_filename (Environment.get_user_data_dir(), "cinaest");
29 string filename = Path.build_filename (data_dir, "catalog.db");
31 // Make sure the data directory is available
32 DirUtils.create_with_parents (data_dir, 0770);
34 sqlite = new CatalogSqlite (filename);
35 sources = new List<CatalogSource> ();
37 var source = new CatalogSource ("Collection", _("Collection"), _("Personal movie list"), sqlite);
38 sources.append (source);
40 source = new CatalogSource ("Loaned", _("Loaned movies"), _("Movies loaned to friends"), sqlite);
41 sources.append (source);
43 source = new CatalogSource ("Watchlist", _("Watchlist"), _("Movies of interest"), sqlite);
44 sources.append (source);
46 stdout.printf ("Catalog Plugin Loaded.\n");
49 public override unowned List<MovieSource> get_sources () {
50 return (List<MovieSource>) sources;
53 public override List<MovieAction> get_actions (Movie movie, Gtk.Window window) {
54 var list = new List<MovieAction> ();
56 list.append (new MovieAction (_("Add to catalog"), on_add_to_catalog, movie, window));
61 private void on_add_to_catalog (Movie movie, Gtk.Window window) {
62 dialog = new Gtk.Dialog ();
63 dialog.set_transient_for (window);
64 dialog.set_title (_("Add movie to catalog - Select list"));
67 var available_sources = new List<MovieSource> ();
68 foreach (CatalogSource s in sources) {
69 if (!s.contains (movie)) {
70 available_sources.append ((MovieSource) s);
75 var source_list = new SourceListView (available_sources, true);
77 var content = (VBox) dialog.get_content_area ();
78 content.pack_start (source_list, true, true, 0);
81 content.set_size_request (-1, i*70);
84 source_list.source_activated.connect (on_source_activated);
87 int res = dialog.run ();
89 var source = sources.nth_data (res);
90 source.add_movie (movie);
92 var banner = (Banner) Banner.show_information_with_markup (window, null, _("'%s' added to list '%s'").printf (movie.title, source.get_name ()));
93 banner.set_timeout (1500);
99 private void on_source_activated (MovieSource source) {
100 int n = sources.index ((CatalogSource) source);
105 public override void settings_dialog (Gtk.Window window) {
106 var dialog = new Gtk.Dialog ();
107 dialog.set_transient_for (window);
108 dialog.set_title (_("Catalog plugin settings"));
110 var button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL);
111 button.set_title (_("Select active movie lists"));
112 button.set_value (_("Collection, Loaned movies, Watchlist"));
114 var content = (VBox) dialog.get_content_area ();
115 content.pack_start (button, true, true, 0);
117 dialog.add_button (_("Done"), ResponseType.ACCEPT);
120 int res = dialog.run ();
121 if (res == ResponseType.ACCEPT) {
126 public override unowned string get_name () {
131 class CatalogSource : MovieSource {
132 private string table;
134 private string description;
135 private CatalogSqlite sqlite;
137 public CatalogSource (string _table, string _name, string _description, CatalogSqlite _sqlite) {
138 GLib.Object (active: true);
141 description = _description;
145 public override bool active { get; set construct; }
147 public override async void get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) {
148 yield sqlite.query (table, filter, callback, limit, cancellable);
151 public override void add_movie (Movie movie) {
152 sqlite.add_movie (table, movie);
155 public override void delete_movie (Movie movie) {
156 sqlite.delete_movie (table, movie);
159 internal bool contains (Movie movie) {
160 return sqlite.contains (table, movie);
163 public override unowned string get_name () {
167 public override unowned string get_description () {
171 public override bool get_editable () {
177 public Type register_plugin () {
178 // types are registered automatically
179 return typeof (CatalogPlugin);