[ontv] Use get_channels instead of direct access



commit c34304713d7b8e42095520c2ae55d460641d2ded
Author: Olof Kindgren <olki src gnome org>
Date:   Sun Mar 6 22:27:47 2011 +0100

    Use get_channels instead of direct access
    
    Make channels list private in listings and use an accessor
    function instead

 ontv/dialogs.py    |   12 ++++++------
 ontv/listings.py   |   40 ++++++++++++++++++++++++----------------
 ontv/window.py     |    8 ++++----
 ontv/xmltv_file.py |    4 ++--
 4 files changed, 36 insertions(+), 28 deletions(-)
---
diff --git a/ontv/dialogs.py b/ontv/dialogs.py
index 5dab49f..4d5af89 100644
--- a/ontv/dialogs.py
+++ b/ontv/dialogs.py
@@ -269,12 +269,12 @@ class PreferencesDialog:
 
     def __crpixbuf_cell_sel_data_func(self, column, cell, model, iter):
         channel_name = model.get_value(iter, 0)
-        channel = self.listings.channels[channel_name]
+        channel = self.listings.get_channel(channel_name)
         cell.props.pixbuf = channel.logo
 
     def __crtext_cell_sel_data_func(self, column, cell, model, iter):
         channel_name = model.get_value(iter, 0)
-        channel = self.listings.channels[channel_name]
+        channel = self.listings.get_channel(channel_name)
         markup = "<b>%s</b>"
         cell.props.markup = markup % channel.markup_escaped_name
 
@@ -383,7 +383,7 @@ class PreferencesDialog:
 
             if selected:
                 channel_name = model.get_value(iter, 0)
-                self.selected_channel = self.listings.channels[channel_name]
+                self.selected_channel = self.listings.get_channel(channel_name)
 
                 row, = model.get_path(iter)
                 if row == 0:
@@ -463,7 +463,7 @@ class PreferencesDialog:
         if iter:
             channel_name = model.get_value(iter, 0)
 
-            channel = self.listings.channels[channel_name]
+            channel = self.listings.get_channel(channel_name)
             channel.selected = False
             self.unselected_channels_filter.refilter()
             self.listings.set_channel_selected(channel_name, False)
@@ -763,8 +763,8 @@ class SearchDialog:
 
 
     def init_model(self):
-        for channel in self.listings.channels:
-            for program in self.listings.channels[channel].programs:
+        for channel in self.listings.get_channel("All"):
+            for program in self.listings.get_channel(channel).programs:
                 time = "<b>%s-%s</b>\n<i>%s</i>" % (program.start_time,
                                                     program.stop_time,
                                                     program.date)
diff --git a/ontv/listings.py b/ontv/listings.py
index 554b9c2..2996f0c 100644
--- a/ontv/listings.py
+++ b/ontv/listings.py
@@ -37,7 +37,7 @@ class Listings(object):
     def __init(self, *args):
         self.config = args[0]
         self.file = os.path.join(self.config.base_dir, "listings.p")
-        self.channels = {}
+        self._channels = {}
         self.selected_channels = []
 
         self.mtime = None
@@ -51,25 +51,32 @@ class Listings(object):
         self.__dict__.update(listings)
 
     def channel_has_custom_logo(self, channel):
-        if self.channels.has_key(channel.name):
-            return self.channels[channel.name].custom_logo
+        if self._channels.has_key(channel.name):
+            return self._channels[channel.name].custom_logo
         return False
 
     def add_channel(self, channel):
-        if self.channels.has_key(channel.name):
-            if self.channels[channel.name].logo_file != "":
-                channel.logo_file = self.channels[channel.name].logo_file
-                channel.set_logo(self.channels[channel.name].logo_file)
-            if self.channels[channel.name].custom_logo:
-                channel.custom_logo = self.channels[channel.name].custom_logo
+        if self._channels.has_key(channel.name):
+            if self._channels[channel.name].logo_file != "":
+                channel.logo_file = self._channels[channel.name].logo_file
+                channel.set_logo(self._channels[channel.name].logo_file)
+            if self._channels[channel.name].custom_logo:
+                channel.custom_logo = self._channels[channel.name].custom_logo
             if channel.name in self.selected_channels:
                 channel.selected = True
-        self.channels[channel.name] = channel
+        self._channels[channel.name] = channel
 
     def add_program(self, program, channel_name):
-        if self.channels.has_key(channel_name):
-            program.channel = self.channels[channel_name]
-            self.channels[channel_name].programs.append(program)
+        if self._channels.has_key(channel_name):
+            program.channel = self._channels[channel_name]
+            self._channels[channel_name].programs.append(program)
+
+    def get_channel(self, channel_name):
+        if channel_name == "All":
+            return self._channels
+        if self._channels.has_key(channel_name):
+            return self._channels[channel_name]
+        return None
 
     def __save_in_thread(self):
         file = open(self.file, 'w')
@@ -99,14 +106,15 @@ class Listings(object):
         matches = []
         for term in search_terms:
             if channel == _("All"):
-                for channel in self.channels:
-                    for program in self.channels[channel].programs:
+                for channel in self._channels:
+                    for program in self._channels[channel].programs:
                         if term in program.title.lower():
                             matches.append(program)
             else:
-                for program in self.channels[channel].programs:
+                for program in self._channels[channel].programs:
                     if term in program.title.lower():
                         matches.append(program)
         return matches
 
+
 # vim: set sw=4 et sts=4 tw=79 fo+=l:
diff --git a/ontv/window.py b/ontv/window.py
index 5f46dba..22f61da 100644
--- a/ontv/window.py
+++ b/ontv/window.py
@@ -165,8 +165,8 @@ class CurrentProgramTable(ProgramTable):
     def set_programs(self):
         self.programs = []
         for channel_name in self.listings.selected_channels:
-            if self.listings.channels.has_key(channel_name):
-                channel = self.listings.channels[channel_name]
+            channel = self.listings.get_channel(channel_name)
+            if channel:
                 current_program = channel.get_current_program()
                 if current_program:
                     self.programs.append(current_program)
@@ -243,8 +243,8 @@ class UpcomingProgramTable(ProgramTable):
     def set_programs(self):
         self.programs = []
         for channel_name in self.listings.selected_channels:
-            if self.listings.channels.has_key(channel_name):
-                channel = self.listings.channels[channel_name]
+            channel = self.listings.get_channel(channel_name)
+            if channel:
                 upcoming_program = channel.get_upcoming_program()
                 if upcoming_program:
                     self.programs.append(upcoming_program)
diff --git a/ontv/xmltv_file.py b/ontv/xmltv_file.py
index 6331b1d..82e3f16 100644
--- a/ontv/xmltv_file.py
+++ b/ontv/xmltv_file.py
@@ -120,12 +120,12 @@ class XMLTVFile(gobject.GObject):
                 self.emit("loading-done", (None))
                 return
 
-            for channel in self.listings.channels.values():
+            for channel in self.listings.get_channel("All").values():
                 channel.programs.sort()
 
             self.listings.save()
         else:
-            for channel in self.listings.channels.values():
+            for channel in self.listings.get_channel("All").values():
                 gtk.gdk.threads_enter()
                 self.emit("loaded-channel", (channel))
                 gtk.gdk.threads_leave()



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