diff --git a/src/sugar/activity/namingalert.py b/src/sugar/activity/namingalert.py
index 724d76a..11b7688 100644
a
|
b
|
|
16 | 16 | # Boston, MA 02111-1307, USA. |
17 | 17 | |
18 | 18 | import gettext |
| 19 | import os |
19 | 20 | |
| 21 | import gio |
20 | 22 | import gtk |
21 | 23 | import gobject |
22 | 24 | import hippo |
… |
… |
from sugar.graphics import style |
26 | 28 | from sugar.graphics.icon import Icon |
27 | 29 | from sugar.graphics.xocolor import XoColor |
28 | 30 | from sugar.graphics.icon import CanvasIcon |
| 31 | from sugar.graphics.icon import get_icon_file_name |
29 | 32 | from sugar.graphics.entry import CanvasEntry |
30 | 33 | from sugar.graphics.toolbutton import ToolButton |
31 | 34 | from sugar.graphics.canvastextview import CanvasTextView |
… |
… |
from sugar.bundle.activitybundle import ActivityBundle |
34 | 37 | |
35 | 38 | _ = lambda msg: gettext.dgettext('sugar-toolkit', msg) |
36 | 39 | |
| 40 | def _get_icon_name(metadata): |
| 41 | file_name = None |
| 42 | |
| 43 | mime_type = metadata.get('mime_type', '') |
| 44 | if not file_name and mime_type: |
| 45 | icons = gio.content_type_get_icon(mime_type) |
| 46 | for icon_name in icons.props.names: |
| 47 | file_name = get_icon_file_name(icon_name) |
| 48 | if file_name is not None: |
| 49 | break |
| 50 | |
| 51 | if file_name is None or not os.path.exists(file_name): |
| 52 | file_name = get_icon_file_name('application-octet-stream') |
| 53 | |
| 54 | return file_name |
| 55 | |
37 | 56 | class NamingToolbar(gtk.Toolbar): |
38 | 57 | """ Toolbar of the naming alert |
39 | 58 | """ |
… |
… |
class NamingAlert(gtk.Window): |
212 | 231 | self._favorite_icon = self._create_favorite_icon() |
213 | 232 | header.append(self._favorite_icon) |
214 | 233 | |
215 | | activity_icon = self._create_activity_icon() |
216 | | header.append(activity_icon) |
| 234 | entry_icon = self._create_entry_icon() |
| 235 | header.append(entry_icon) |
217 | 236 | |
218 | 237 | self._title = self._create_title() |
219 | 238 | header.append(self._title, hippo.PACK_EXPAND) |
… |
… |
class NamingAlert(gtk.Window): |
233 | 252 | favorite_icon = FavoriteIcon(False) |
234 | 253 | return favorite_icon |
235 | 254 | |
236 | | def _create_activity_icon(self): |
237 | | activity_bundle = ActivityBundle(self._bundle_path) |
238 | | activity_icon = CanvasIcon(file_name=activity_bundle.get_icon()) |
| 255 | def _create_entry_icon(self): |
| 256 | bundle_id = self._activity.metadata.get('activity', '') |
| 257 | if not bundle_id: |
| 258 | bundle_id = self._activity.metadata.get('bundle_id', '') |
| 259 | |
| 260 | if bundle_id == '': |
| 261 | file_name = _get_icon_name(self._activity.metadata) |
| 262 | else: |
| 263 | activity_bundle = ActivityBundle(self._bundle_path) |
| 264 | file_name = activity_bundle.get_icon() |
| 265 | entry_icon = CanvasIcon(file_name=file_name) |
239 | 266 | if self._activity.metadata.has_key('icon-color') and \ |
240 | 267 | self._activity.metadata['icon-color']: |
241 | | activity_icon.props.xo_color = XoColor( \ |
| 268 | entry_icon.props.xo_color = XoColor( \ |
242 | 269 | self._activity.metadata['icon-color']) |
243 | | return activity_icon |
| 270 | return entry_icon |
244 | 271 | |
245 | 272 | def _create_title(self): |
246 | 273 | title = CanvasEntry() |
diff --git a/src/sugar/graphics/icon.py b/src/sugar/graphics/icon.py
index f901519..6057652 100644
a
|
b
|
def get_icon_state(base_name, perc, step=5): |
926 | 926 | return icon_name |
927 | 927 | |
928 | 928 | strength = strength + step |
| 929 | |
| 930 | def get_icon_file_name(icon_name): |
| 931 | icon_theme = gtk.icon_theme_get_default() |
| 932 | info = icon_theme.lookup_icon(icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR, 0) |
| 933 | if not info: |
| 934 | return None |
| 935 | filename = info.get_filename() |
| 936 | del info |
| 937 | return filename |
| 938 | |