[Sugar-devel] [PATCH sugar] Journal: don't fail to load if an activity icon is broken

Sascha Silbe silbe at activitycentral.com
Sun Oct 16 10:46:09 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).

Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
 src/jarabe/journal/journaltoolbox.py |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index cdf6a77..714782d 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,30 @@ 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('%r (%r) has invalid icon: %s',
+                            activity_info.get_name(), 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