From 54c98f4f09c6399b86bb9201c1d544ac396e1f8c Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Wed, 27 May 2009 17:56:51 +0300 Subject: [PATCH] Handle 'Folders' textview Get/Set folders from/to configuration to/from 'Folders' textview --- src/ui/Makefile.am | 7 +++- src/ui/rygel-folder-pref-section.vala | 77 +++++++++++++++++++++++++++++++++++ src/ui/rygel-plugin-pref-section.vala | 3 +- src/ui/rygel-preferences-dialog.vala | 5 +-- 4 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 src/ui/rygel-folder-pref-section.vala diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am index f9fa45a..ec8a302 100644 --- a/src/ui/Makefile.am +++ b/src/ui/Makefile.am @@ -23,7 +23,8 @@ bin_PROGRAMS = rygel-preferences BUILT_SOURCES = rygel-preferences-dialog.c \ rygel-preferences-section.c \ rygel-general-pref-section.c \ - rygel-plugin-pref-section.c + rygel-plugin-pref-section.c \ + rygel-folder-pref-section.c $(BUILT_SOURCES) : rygel.stamp @@ -34,7 +35,9 @@ rygel_preferences_SOURCES = rygel-preferences-dialog.c \ rygel-general-pref-section.c \ rygel-general-pref-section.vala \ rygel-plugin-pref-section.c \ - rygel-plugin-pref-section.vala + rygel-plugin-pref-section.vala \ + rygel-folder-pref-section.c \ + rygel-folder-pref-section.vala rygel.stamp: $(filter %.vala,$(rygel_preferences_SOURCES)) $(VALAC) -C --vapidir=$(rygeldir) \ diff --git a/src/ui/rygel-folder-pref-section.vala b/src/ui/rygel-folder-pref-section.vala new file mode 100644 index 0000000..2948380 --- /dev/null +++ b/src/ui/rygel-folder-pref-section.vala @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2009 Nokia Corporation, all rights reserved. + * + * 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.FolderPrefSection : Rygel.PluginPrefSection { + const string NAME = "Folder"; + const string FOLDERS_KEY = "folders"; + const string FOLDERS_TEXTVIEW = FOLDERS_KEY + "-textview"; + const string FOLDERS_TEXTBUFFER = FOLDERS_KEY + "-textbuffer"; + + private TextView text_view; + private TextBuffer text_buffer; + + public FolderPrefSection (Builder builder, + Configuration config) { + base (builder, config, NAME); + + this.text_view = (TextView) builder.get_object (FOLDERS_TEXTVIEW); + assert (this.text_view != null); + this.text_buffer = (TextBuffer) builder.get_object (FOLDERS_TEXTBUFFER); + assert (this.text_buffer != null); + + var folders = config.get_string_list (this.name, FOLDERS_KEY); + string text = ""; + foreach (var folder in folders) { + text += folder + "\n"; + } + this.text_buffer.set_text (text, -1); + } + + public override void save () { + TextIter start; + TextIter end; + + this.text_buffer.get_start_iter (out start); + this.text_buffer.get_end_iter (out end); + + var text = this.text_buffer.get_text (start, end, false); + + var folders = text.split ("\n", -1); + var folder_list = new ArrayList (); + + foreach (var folder in folders) { + folder_list.add (folder); + } + + this.config.set_string_list (this.name, FOLDERS_KEY, folder_list); + } + + protected override void on_enabled_check_toggled ( + CheckButton enabled_check) { + base.on_enabled_check_toggled (enabled_check); + + this.text_view.sensitive = enabled_check.active; + } +} diff --git a/src/ui/rygel-plugin-pref-section.vala b/src/ui/rygel-plugin-pref-section.vala index 27451d1..4c4f61f 100644 --- a/src/ui/rygel-plugin-pref-section.vala +++ b/src/ui/rygel-plugin-pref-section.vala @@ -62,7 +62,8 @@ public class Rygel.PluginPrefSection : PreferencesSection { this.config.set_string (this.name, Configuration.TITLE_KEY, title); } - private void on_enabled_check_toggled (CheckButton enabled_check) { + protected virtual void on_enabled_check_toggled ( + CheckButton enabled_check) { this.title_entry.sensitive = enabled_check.active; } } diff --git a/src/ui/rygel-preferences-dialog.vala b/src/ui/rygel-preferences-dialog.vala index a940848..c14fe9c 100644 --- a/src/ui/rygel-preferences-dialog.vala +++ b/src/ui/rygel-preferences-dialog.vala @@ -49,10 +49,9 @@ public class Rygel.PreferencesDialog : GLib.Object { "Tracker")); this.sections.add (new PluginPrefSection (this.builder, config, - "Folder")); - this.sections.add (new PluginPrefSection (this.builder, - config, "DVB")); + this.sections.add (new FolderPrefSection (this.builder, + config)); this.dialog.response += this.on_response; this.dialog.delete_event += (dialog, event) => { -- 2.7.4