[Sugar-devel] [PATCH v4 sugar] Journal: don't fail to load if an activity icon is broken (fixes SL#3200)

Sascha Silbe silbe at activitycentral.com
Tue Oct 18 11:32:03 EDT 2011


If the activity-provided icon could not be loaded, the Journal previously
died on start-up, rendering Sugar effectively unusable. Now we fall back to
the standard icon (in the "What" filter combo box).

SL#3203 has been filed to remind us to audit the code for similar breakages.

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
v3->v4: Improved warning wording some more.
v2->v3: Improve warning to mention that we fall back to a default icon.
        Created TODO ticket SL#3203, mention it in the description.
v1->v2: Created ticket with test case, mention it in the summary.
        No code changes.

 src/jarabe/journal/journaltoolbox.py |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index cdf6a77..2aa4153 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -24,6 +24,7 @@ import time

 import gobject
 import gio
+import glib
 import gtk

 from sugar.graphics.palette import Palette
@@ -319,19 +320,33 @@ class SearchToolbar(gtk.Toolbar):

             for service_name in model.get_unique_values('activity'):
                 activity_info = registry.get_bundle(service_name)
-                if not activity_info is None:
-                    if os.path.exists(activity_info.get_icon()):
+                if activity_info is None:
+                    continue
+
+                if service_name == current_value:
+                    combo_model = self._what_search_combo.get_model()
+                    current_value_index = len(combo_model)
+
+                # try activity-provided icon
+                if os.path.exists(activity_info.get_icon()):
+                    try:
                         self._what_search_combo.append_item(service_name,
                                 activity_info.get_name(),
                                 file_name=activity_info.get_icon())
+                    except glib.GError, exception:
+                        logging.warning('Falling back to default icon for'
+                                        ' "what" filter because %r (%r) has an'
+                                        ' invalid icon: %s',
+                                        activity_info.get_name(),
+                                        str(service_name), exception)
                     else:
-                        self._what_search_combo.append_item(service_name,
-                                activity_info.get_name(),
-                                icon_name='application-octet-stream')
+                        continue
+
+                # fall back to generic icon
+                self._what_search_combo.append_item(service_name,
+                        activity_info.get_name(),
+                        icon_name='application-octet-stream')

-                    if service_name == current_value:
-                        current_value_index = \
-                                len(self._what_search_combo.get_model()) - 1
         finally:
             self._what_search_combo.handler_unblock(
                     self._what_combo_changed_sid)
--
1.7.6.3



More information about the Sugar-devel mailing list