Handle 'Folders' textview
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 27 May 2009 14:56:51 +0000 (17:56 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 27 May 2009 14:56:51 +0000 (17:56 +0300)
Get/Set folders from/to configuration to/from 'Folders' textview

src/ui/Makefile.am
src/ui/rygel-folder-pref-section.vala [new file with mode: 0644]
src/ui/rygel-plugin-pref-section.vala
src/ui/rygel-preferences-dialog.vala

index f9fa45a..ec8a302 100644 (file)
@@ -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 (file)
index 0000000..2948380
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation, all rights reserved.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
+ *                               <zeeshan.ali@nokia.com>
+ *
+ * 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<string> ();
+
+        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;
+    }
+}
index 27451d1..4c4f61f 100644 (file)
@@ -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;
     }
 }
index a940848..c14fe9c 100644 (file)
@@ -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) => {