[telegnome] Move default channel list into a separate file



commit a99a9a39374ae09b18da55aba1bd8c20448d0407
Author: Colin Watson <cjwatson debian org>
Date:   Mon Feb 15 13:31:21 2016 +0000

    Move default channel list into a separate file
    
    * src/default-channels.cfg: New file.
    * src/telegnome.gresource.xml: Add default-channels.cfg.
    * src/gui.vala (Gui.get_default_channel_value): New method.
    (Gui.reload_channels): Read default channels from resource.

 src/default-channels.cfg    |   61 +++++++++++++++++++++++++
 src/gui.vala                |  102 ++++++++++++++++++++-----------------------
 src/telegnome.gresource.xml |    1 +
 3 files changed, 109 insertions(+), 55 deletions(-)
---
diff --git a/src/default-channels.cfg b/src/default-channels.cfg
new file mode 100644
index 0000000..c278752
--- /dev/null
+++ b/src/default-channels.cfg
@@ -0,0 +1,61 @@
+# Copyright (C) 2016 Colin Watson <cjwatson debian org>
+#  
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#  
+# This program 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 General Public License for more details.
+#  
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# Default channels for TeleGNOME, which will be used if no channels are
+# currently configured.  Keep these in order of the English country name.
+# To reset all configuration including channels to default values, run:
+#   dconf reset -f /org/gnome/telegnome/
+
+[cz]
+Name=Teletext ČT, Czech Republic
+Description=Czech teletext
+PageURL=http://www.ceskatelevize.cz/services/teletext/picture.php?channel=CT1&page=%03d
+Country=cz
+
+[fi-yle]
+Name=YLE Teksti-TV, Finland
+Description=Finnish teletext (YLE)
+PageURL=http://www.yle.fi/tekstitv/images/P%03d_01.gif
+SubpageURL=http://www.yle.fi/tekstitv/images/P%03d_%02d.gif
+Country=fi
+
+[fi-mtv]
+Name=MTV3 Tekstikanava, Finland
+Description=Finnish teletext (MTV3)
+PageURL=http://www.mtvtekstikanava.fi/new2008/images/%03d-01.gif
+SubpageURL=http://www.mtvtekstikanava.fi/new2008/images/%03d-%02d.gif
+Country=fi
+
+[hu]
+Name=MTV1, Hungary
+Description=Hungarian teletext
+PageURL=http://www.teletext.hu/mtv1/images/%03d-01.gif
+SubpageURL=http://www.teletext.hu/mtv1/images/%03d-%02d.gif
+Country=hu
+
+[it]
+Name=Televideo RAI, Italia
+Description=Televideo (RAI)
+PageURL=http://www.servizitelevideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-%03d.png
+SubpageURL=http://www.servizitelevideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-%03d.%d.png
+Country=it
+
+[gb]
+Name=Ceefax, United Kingdom
+Description=UK teletext (BBC)
+PageURL=http://www.ceefax.tv/cgi-bin/gfx.cgi?page=%03d_0&font=big&channel=bbc1
+SubpageURL=http://www.ceefax.tv/cgi-bin/gfx.cgi?page=%03d_%d&font=big&channel=bbc1
+Country=gb
diff --git a/src/gui.vala b/src/gui.vala
index 493019a..efa6945 100644
--- a/src/gui.vala
+++ b/src/gui.vala
@@ -215,6 +215,19 @@ public class Gui : Object {
                }
        }
 
+       private string? get_default_channel_value (KeyFile file,
+                                                  string group, string key,
+                                                  bool missing_ok = false) {
+               try {
+                       return file.get_string (group, key);
+               } catch (KeyFileError e) {
+                       if (missing_ok)
+                               return null;
+                       else
+                               assert_not_reached ();
+               }
+       }
+
        /**
         * reload_channels:
         *
@@ -230,61 +243,40 @@ public class Gui : Object {
 
                if (channels == null) {
                        /* Nothing set up yet; fill in some defaults. */
-                       /* TODO: This is terrible; move into a separate
-                        * file.
-                        */
-                       string[] children = new string[7];
-                       var i = 0;
-                       Channel channel;
-
-                       channel = new Channel.with_parameters
-                               ("Teletext ČT, Czech Republic",
-                                "Czech teletext",
-                                
"http://www.ceskatelevize.cz/services/teletext/picture.php?channel=CT1&page=%03d";,
-                                null,
-                                "cz");
-                       channels.append (channel);
-                       children[i++] = channel.uuid;
-                       channel = new Channel.with_parameters
-                               ("YLE Teksti-TV, Finland",
-                                "Finnish teletext (YLE)",
-                                "http://www.yle.fi/tekstitv/images/P%03d_01.gif";,
-                                "http://www.yle.fi/tekstitv/images/P%03d_%02d.gif";,
-                                "fi");
-                       channels.append (channel);
-                       children[i++] = channel.uuid;
-                       channel = new Channel.with_parameters
-                               ("MTV3 Tekstikanava, Finland",
-                                "Finnish teletext (MTV3)",
-                                "http://www.mtvtekstikanava.fi/new2008/images/%03d-01.gif";,
-                                "http://www.mtvtekstikanava.fi/new2008/images/%03d-%02d.gif";,
-                                "fi");
-                       channels.append (channel);
-                       children[i++] = channel.uuid;
-                       channel = new Channel.with_parameters
-                               ("MTV1, Hungary",
-                                "Hungarian teletext",
-                                "http://www.teletext.hu/mtv1/images/%03d-01.gif";,
-                                "http://www.teletext.hu/mtv1/images/%03d-%02d.gif";,
-                                "hu");
-                       channels.append (channel);
-                       children[i++] = channel.uuid;
-                       channel = new Channel.with_parameters
-                               ("Televideo RAI, Italia",
-                                "Televideo (RAI)",
-                                
"http://www.servizitelevideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-%03d.png";,
-                                
"http://www.servizitelevideo.rai.it/televideo/pub/tt4web/Nazionale/16_9_page-%03d.%d.png";,
-                                "it");
-                       channels.append (channel);
-                       children[i++] = channel.uuid;
-                       channel = new Channel.with_parameters
-                               ("Ceefax, United Kingdom",
-                                "UK teletext (BBC)",
-                                "http://www.ceefax.tv/cgi-bin/gfx.cgi?page=%03d_0&font=big&channel=bbc1";,
-                                "http://www.ceefax.tv/cgi-bin/gfx.cgi?page=%03d_%d&font=big&channel=bbc1";,
-                                "gb");
-                       channels.append (channel);
-                       children[i++] = channel.uuid;
+                       string[] children = {};
+                       Bytes bytes;
+                       try {
+                               bytes = resources_lookup_data
+                                       ("/org/gnome/telegnome/default-channels.cfg",
+                                        ResourceLookupFlags.NONE);
+                       } catch (Error e) {
+                               assert_not_reached ();
+                       }
+                       var file = new KeyFile ();
+                       try {
+                               file.load_from_data
+                                       ((string) bytes.get_data (), bytes.length,
+                                        KeyFileFlags.NONE);
+                       } catch (Error e) {
+                               assert_not_reached ();
+                       }
+                       foreach (unowned string group in file.get_groups ()) {
+                               var name = get_default_channel_value
+                                       (file, group, "Name");
+                               var description = get_default_channel_value
+                                       (file, group, "Description");
+                               var page_url = get_default_channel_value
+                                       (file, group, "PageURL");
+                               var subpage_url = get_default_channel_value
+                                       (file, group, "SubpageURL", true);
+                               var country = get_default_channel_value
+                                       (file, group, "Country");
+                               var channel = new Channel.with_parameters
+                                       (name, description,
+                                        page_url, subpage_url, country);
+                               channels.append (channel);
+                               children += channel.uuid;
+                       }
                        settings.set_strv ("channel-children", children);
                }
 
diff --git a/src/telegnome.gresource.xml b/src/telegnome.gresource.xml
index 9dfcc42..99dffc5 100644
--- a/src/telegnome.gresource.xml
+++ b/src/telegnome.gresource.xml
@@ -23,5 +23,6 @@
     <file alias="gtk/menus.ui">menus.ui</file>
     <file>telegnome.ui</file>
     <file>prefs.ui</file>
+    <file>default-channels.cfg</file>
   </gresource>
 </gresources>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]