2 * Copyright (C) 2009 Nokia Corporation.
4 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
5 * <zeeshan.ali@nokia.com>
7 * This file is part of Rygel.
9 * Rygel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Rygel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 public class Rygel.MediaExportPrefSection : PreferencesSection {
27 const string ENABLED_CHECK = "-enabled-checkbutton";
28 const string NAME = "MediaExport";
29 const string URIS_KEY = "uris";
30 const string URIS_LABEL = URIS_KEY + "-label";
31 const string URIS_TEXTVIEW = URIS_KEY + "-treeview";
32 const string URIS_LISTSTORE = URIS_KEY + "-liststore";
33 const string URIS_DIALOG = URIS_KEY + "-dialog";
34 const string ADD_BUTTON = "add-button";
35 const string REMOVE_BUTTON = "remove-button";
36 const string CLEAR_BUTTON = "clear-button";
38 private CheckButton enabled_check;
39 private ArrayList<Widget> widgets; // All widgets in this section
41 private TreeView treeview;
42 private ListStore liststore;
43 private FileChooserDialog dialog;
45 public MediaExportPrefSection (Builder builder,
46 WritableUserConfig config) {
49 this.widgets = new ArrayList<Widget> ();
51 this.enabled_check = (CheckButton) builder.get_object (name.down () +
53 assert (this.enabled_check != null);
56 this.enabled_check.active = config.get_enabled (name);
57 } catch (GLib.Error err) {
58 this.enabled_check.active = false;
61 this.enabled_check.toggled.connect (this.on_enabled_check_toggled);
63 this.treeview = (TreeView) builder.get_object (URIS_TEXTVIEW);
64 assert (this.treeview != null);
65 this.liststore = (ListStore) builder.get_object (URIS_LISTSTORE);
66 assert (this.liststore != null);
67 this.dialog = (FileChooserDialog) builder.get_object (URIS_DIALOG);
68 assert (this.dialog != null);
70 treeview.insert_column_with_attributes (-1,
72 new CellRendererText (),
76 this.widgets.add (this.treeview);
79 var uris = config.get_string_list (this.name, URIS_KEY);
80 foreach (var uri in uris) {
83 this.liststore.append (out iter);
84 this.liststore.set (iter, 0, uri, -1);
86 } catch (GLib.Error err) {} // Nevermind
88 this.dialog.set_current_folder (Environment.get_home_dir ());
89 this.dialog.show_hidden = false;
91 var button = (Button) builder.get_object (ADD_BUTTON);
92 button.clicked.connect (this.on_add_button_clicked);
93 this.widgets.add (button);
95 button = (Button) builder.get_object (REMOVE_BUTTON);
96 button.clicked.connect (this.on_remove_button_clicked);
97 this.widgets.add (button);
99 button = (Button) builder.get_object (CLEAR_BUTTON);
100 button.clicked.connect (this.on_clear_button_clicked);
101 this.widgets.add (button);
103 var label = (Label) builder.get_object (URIS_LABEL);
104 assert (label != null);
105 this.widgets.add (label);
107 // Initialize the sensitivity of all widgets
108 this.reset_widgets_sensitivity ();
111 public override void save () {
112 this.config.set_bool (this.name,
113 UserConfig.ENABLED_KEY,
114 this.enabled_check.active);
117 var uri_list = new ArrayList<string> ();
119 if (this.liststore.get_iter_first (out iter)) {
123 this.liststore.get (iter, 0, out uri, -1);
125 } while (this.liststore.iter_next (ref iter));
128 this.config.set_string_list (this.name, URIS_KEY, uri_list);
131 private void reset_widgets_sensitivity () {
132 this.title_entry.sensitive = this.enabled_check.active;
134 foreach (var widget in this.widgets) {
135 widget.sensitive = enabled_check.active;
139 private void on_enabled_check_toggled (ToggleButton enabled_check) {
140 this.reset_widgets_sensitivity ();
143 private void on_add_button_clicked (Button button) {
144 if (this.dialog.run () == ResponseType.OK) {
147 var dirs = this.dialog.get_files ();
149 foreach (var dir in dirs) {
150 string path = dir.get_path ();
153 path = dir.get_uri ();
156 this.liststore.append (out iter);
157 this.liststore.set (iter, 0, path, -1);
164 private void on_remove_button_clicked (Button button) {
165 var selection = this.treeview.get_selection ();
166 var rows = selection.get_selected_rows (null);
168 // First get permanent references to rows
169 var row_refs = new ArrayList<TreeRowReference> ();
170 foreach (var row in rows) {
171 row_refs.add (new TreeRowReference (this.liststore, row));
174 // Now we can safely remove rows
175 foreach (var row_ref in row_refs) {
178 var path = row_ref.get_path ();
179 this.liststore.get_iter (out iter, path);
181 this.liststore.remove (iter);
185 private void on_clear_button_clicked (Button button) {
186 this.liststore.clear ();