From c28af67573f86e8b80b1a000667d8208842cc390 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Sat, 5 Dec 2009 10:08:55 +0100 Subject: [PATCH] Catalog plugin: enable configuration of visible movie lists The user might not be interested in a particular list (for example loaned movies), so this provides an option to remove them from the user interface. --- src/plugins/catalog-plugin.vala | 127 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 120 insertions(+), 7 deletions(-) diff --git a/src/plugins/catalog-plugin.vala b/src/plugins/catalog-plugin.vala index f42a2bc..38958f3 100644 --- a/src/plugins/catalog-plugin.vala +++ b/src/plugins/catalog-plugin.vala @@ -31,16 +31,31 @@ class CatalogPlugin : Plugin { // Make sure the data directory is available DirUtils.create_with_parents (data_dir, 0770); + string hidden_sources = null; + try { + var config_file = Path.build_filename (Environment.get_user_config_dir (), "cinaest", "cinaest.cfg"); + var keyfile = new KeyFile (); + if (keyfile.load_from_file (config_file, KeyFileFlags.NONE) + && keyfile.has_group ("CatalogPlugin")) { + if (keyfile.has_key ("CatalogPlugin", "HiddenSources")) { + hidden_sources = keyfile.get_string ("CatalogPlugin", "HiddenSources"); + } + } + } catch (Error e) { + if (!(e is KeyFileError.NOT_FOUND)) + stdout.printf ("Error loading configuration: %s\n", e.message); + } + sqlite = new CatalogSqlite (filename); sources = new List (); - var source = new CatalogSource ("Collection", _("Collection"), _("Personal movie list"), sqlite); + var source = new CatalogSource ("Collection", _("Collection"), _("Personal movie list"), sqlite, !("Collection" in hidden_sources)); sources.append (source); - source = new CatalogSource ("Loaned", _("Loaned movies"), _("Movies loaned to friends"), sqlite); + source = new CatalogSource ("Loaned", _("Loaned movies"), _("Movies loaned to friends"), sqlite, !("Loaned" in hidden_sources)); sources.append (source); - source = new CatalogSource ("Watchlist", _("Watchlist"), _("Movies of interest"), sqlite); + source = new CatalogSource ("Watchlist", _("Watchlist"), _("Movies of interest"), sqlite, !("Watchlist" in hidden_sources)); sources.append (source); stdout.printf ("Catalog Plugin Loaded.\n"); @@ -109,18 +124,116 @@ class CatalogPlugin : Plugin { var button = new Hildon.Button (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL); button.set_title (_("Select active movie lists")); - button.set_value (_("Collection, Loaned movies, Watchlist")); + button.set_value (active_sources_text ()); + button.set_style (ButtonStyle.PICKER); var content = (VBox) dialog.get_content_area (); content.pack_start (button, true, true, 0); dialog.add_button (_("Done"), ResponseType.ACCEPT); + // Connect signals + button.clicked.connect (() => { on_select_active_lists (button, window); }); + + dialog.show_all (); + int res = dialog.run (); + if (res == ResponseType.ACCEPT) { + } + dialog.destroy (); + } + + private void on_select_active_lists (Hildon.Button button, Gtk.Window window) { + dialog = new Gtk.Dialog (); + dialog.set_transient_for (window); + dialog.set_title (_("Select active movie lists")); + + var source_list = new SourceListView (sources, false); + source_list.set_hildon_ui_mode (UIMode.EDIT); + + var selection = source_list.get_selection (); + foreach (CatalogSource s in sources) { + var iter = TreeIter (); + + if (s.active && source_list.get_iter (s, out iter)) { + selection.select_iter (iter); + } + } + + var content = (VBox) dialog.get_content_area (); + content.pack_start (source_list, true, true, 0); + var i = sources.length (); + if (i > 5) + i = 5; + content.set_size_request (-1, (int) i*70); + + dialog.add_button (_("Done"), ResponseType.ACCEPT); + dialog.show_all (); int res = dialog.run (); if (res == ResponseType.ACCEPT) { + foreach (CatalogSource s in sources) { + TreeIter iter; + + if (source_list.get_iter (s, out iter)) { + s.active = selection.iter_is_selected (iter); + } + } + + var config_file = Path.build_filename (Environment.get_user_config_dir (), "cinaest", "cinaest.cfg"); + var keyfile = new KeyFile (); + try { + keyfile.load_from_file (config_file, KeyFileFlags.NONE); + } catch (Error e) { + if (!(e is KeyFileError.NOT_FOUND)) + stdout.printf ("Error loading configuration: %s\n", e.message); + } + keyfile.set_string ("CatalogPlugin", "HiddenSources", hidden_sources_list ()); + + try { + var file = File.new_for_path (config_file + ".part"); + var stream = file.create (FileCreateFlags.REPLACE_DESTINATION, null); + var data = keyfile.to_data (); + + stream.write (data, data.length, null); + FileUtils.rename (config_file + ".part", config_file); + } catch (Error e) { + stdout.printf ("Failed to store configuration: %s\n", e.message); + } + + button.set_value (active_sources_text ()); } dialog.destroy (); + dialog = null; + } + + private string active_sources_text () { + string text = null; + + foreach (CatalogSource s in sources) { + if (s.active) { + if (text == null) { + text = s.get_name (); + } else { + text += ", " + s.get_name (); + } + } + } + return text; + } + + private string hidden_sources_list () { + string list = ""; + + foreach (CatalogSource s in sources) { + if (!s.active) { + if (list == "") { + list = s.table; + } else { + list += ", " + s.table; + } + } + } + return list; } public override unowned string get_name () { @@ -129,13 +242,13 @@ class CatalogPlugin : Plugin { } class CatalogSource : MovieSource { - private string table; + internal 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); + public CatalogSource (string _table, string _name, string _description, CatalogSqlite _sqlite, bool _active) { + GLib.Object (active: _active); table = _table; name = _name; description = _description; -- 1.7.9.5