From 9f17e26a9647902702e96c7ae67fc76b175b586a Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Mon, 14 Feb 2011 18:01:58 +0200 Subject: [PATCH] ui: Merge PluginPrefSection into MediaExportPrefSection --- po/POTFILES.in | 1 - src/ui/Makefile.am | 1 - src/ui/rygel-media-export-pref-section.vala | 66 +++++++++++++++++++- src/ui/rygel-plugin-pref-section.vala | 97 ----------------------------- 4 files changed, 63 insertions(+), 102 deletions(-) delete mode 100644 src/ui/rygel-plugin-pref-section.vala diff --git a/po/POTFILES.in b/po/POTFILES.in index 2c35cf3..5426e42 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -148,7 +148,6 @@ src/rygel/rygel-xbox-hacks.vala src/rygel/rygel-changelog.vala src/ui/rygel-general-pref-section.vala src/ui/rygel-media-export-pref-section.vala -src/ui/rygel-plugin-pref-section.vala src/ui/rygel-preferences-dialog.vala src/ui/rygel-preferences-section.vala src/ui/rygel-writable-user-config.vala diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index 79d65b6..0680585 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -27,7 +27,6 @@ rygel_preferences_SOURCES = \ rygel-preferences-dialog.vala \ rygel-preferences-section.vala \ rygel-general-pref-section.vala \ - rygel-plugin-pref-section.vala \ rygel-media-export-pref-section.vala \ rygel-writable-user-config.vala diff --git a/src/ui/rygel-media-export-pref-section.vala b/src/ui/rygel-media-export-pref-section.vala index 37a4e3b..ba32731 100644 --- a/src/ui/rygel-media-export-pref-section.vala +++ b/src/ui/rygel-media-export-pref-section.vala @@ -23,7 +23,10 @@ using Gtk; using Gee; -public class Rygel.MediaExportPrefSection : Rygel.PluginPrefSection { +public class Rygel.MediaExportPrefSection : PreferencesSection { + const string ENABLED_CHECK = "-enabled-checkbutton"; + const string TITLE_LABEL = "-title-label"; + const string TITLE_ENTRY = "-title-entry"; const string NAME = "MediaExport"; const string URIS_KEY = "uris"; const string URIS_LABEL = URIS_KEY + "-label"; @@ -34,13 +37,51 @@ public class Rygel.MediaExportPrefSection : Rygel.PluginPrefSection { const string REMOVE_BUTTON = "remove-button"; const string CLEAR_BUTTON = "clear-button"; + private CheckButton enabled_check; + private Entry title_entry; + + private ArrayList widgets; // All widgets in this section + private TreeView treeview; private ListStore liststore; private FileChooserDialog dialog; public MediaExportPrefSection (Builder builder, WritableUserConfig config) { - base (builder, config, NAME); + base (config, NAME); + + this.widgets = new ArrayList (); + + this.enabled_check = (CheckButton) builder.get_object (name.down () + + ENABLED_CHECK); + assert (this.enabled_check != null); + this.title_entry = (Entry) builder.get_object (name.down () + + TITLE_ENTRY); + assert (this.title_entry != null); + var title_label = (Label) builder.get_object (name.down () + + TITLE_LABEL); + assert (title_label != null); + this.widgets.add (title_label); + + try { + this.enabled_check.active = config.get_enabled (name); + } catch (GLib.Error err) { + this.enabled_check.active = false; + } + + string title; + try { + title = config.get_title (name); + } catch (GLib.Error err) { + title = name; + } + + title = title.replace ("@REALNAME@", "%n"); + title = title.replace ("@USERNAME@", "%u"); + title = title.replace ("@HOSTNAME@", "%h"); + this.title_entry.set_text (title); + + this.enabled_check.toggled.connect (this.on_enabled_check_toggled); this.treeview = (TreeView) builder.get_object (URIS_TEXTVIEW); assert (this.treeview != null); @@ -91,7 +132,14 @@ public class Rygel.MediaExportPrefSection : Rygel.PluginPrefSection { } public override void save () { - base.save (); + this.config.set_bool (this.name, + UserConfig.ENABLED_KEY, + this.enabled_check.active); + + var title = this.title_entry.get_text ().replace ("%n", "@REALNAME@"); + title = title.replace ("%u", "@USERNAME@"); + title = title.replace ("%h", "@HOSTNAME@"); + this.config.set_string (this.name, UserConfig.TITLE_KEY, title); TreeIter iter; var uri_list = new ArrayList (); @@ -108,6 +156,18 @@ public class Rygel.MediaExportPrefSection : Rygel.PluginPrefSection { this.config.set_string_list (this.name, URIS_KEY, uri_list); } + private void reset_widgets_sensitivity () { + this.title_entry.sensitive = this.enabled_check.active; + + foreach (var widget in this.widgets) { + widget.sensitive = enabled_check.active; + } + } + + private void on_enabled_check_toggled (ToggleButton enabled_check) { + this.reset_widgets_sensitivity (); + } + private void on_add_button_clicked (Button button) { if (this.dialog.run () == ResponseType.OK) { TreeIter iter; diff --git a/src/ui/rygel-plugin-pref-section.vala b/src/ui/rygel-plugin-pref-section.vala deleted file mode 100644 index c048128..0000000 --- a/src/ui/rygel-plugin-pref-section.vala +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2009 Nokia Corporation. - * - * Author: Zeeshan Ali (Khattak) - * - * - * This file is part of Rygel. - * - * Rygel is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Rygel 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 Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -using Gtk; -using Gee; - -public class Rygel.PluginPrefSection : PreferencesSection { - const string ENABLED_CHECK = "-enabled-checkbutton"; - const string TITLE_LABEL = "-title-label"; - const string TITLE_ENTRY = "-title-entry"; - - private CheckButton enabled_check; - private Entry title_entry; - - protected ArrayList widgets; // All widgets in this section - - public PluginPrefSection (Builder builder, - WritableUserConfig config, - string name) { - base (config, name); - - this.widgets = new ArrayList (); - - this.enabled_check = (CheckButton) builder.get_object (name.down () + - ENABLED_CHECK); - assert (this.enabled_check != null); - this.title_entry = (Entry) builder.get_object (name.down () + - TITLE_ENTRY); - assert (this.title_entry != null); - var title_label = (Label) builder.get_object (name.down () + - TITLE_LABEL); - assert (title_label != null); - this.widgets.add (title_label); - - try { - this.enabled_check.active = config.get_enabled (name); - } catch (GLib.Error err) { - this.enabled_check.active = false; - } - - string title; - try { - title = config.get_title (name); - } catch (GLib.Error err) { - title = name; - } - - title = title.replace ("@REALNAME@", "%n"); - title = title.replace ("@USERNAME@", "%u"); - title = title.replace ("@HOSTNAME@", "%h"); - this.title_entry.set_text (title); - - this.enabled_check.toggled.connect (this.on_enabled_check_toggled); - } - - public override void save () { - this.config.set_bool (this.name, - UserConfig.ENABLED_KEY, - this.enabled_check.active); - - var title = this.title_entry.get_text ().replace ("%n", "@REALNAME@"); - title = title.replace ("%u", "@USERNAME@"); - title = title.replace ("%h", "@HOSTNAME@"); - this.config.set_string (this.name, UserConfig.TITLE_KEY, title); - } - - protected void reset_widgets_sensitivity () { - this.title_entry.sensitive = this.enabled_check.active; - - foreach (var widget in this.widgets) { - widget.sensitive = enabled_check.active; - } - } - - private void on_enabled_check_toggled (ToggleButton enabled_check) { - this.reset_widgets_sensitivity (); - } -} -- 2.7.4