dock:: fix gtk gets theme icon failed.

gtk will get theme icon failed sometimes for unknown reason.
just skip this error and return the icon and frontend must make
a validity check for icon.

Change-Id: I1ba3a1d0c420d1d50ff53f558f13fe42a557ef46
This commit is contained in:
liliqiang 2015-04-07 17:46:30 +08:00 committed by Deepin Code Review
parent 632cb1c318
commit ffe9c0e7c7
3 changed files with 15 additions and 7 deletions

View File

@ -640,7 +640,8 @@ char* icon_name_to_path(const char* name, int size)
char* pic_name = g_strndup(name, pic_name_len);
GtkIconTheme* them = gtk_icon_theme_get_default(); //do not ref or unref it
if (them == NULL) {
g_debug("get theme failed");
// NOTE: the g_message won't be recorded on log,
g_message("error get default icon theme failed");
return NULL;
}

View File

@ -49,7 +49,8 @@ func get_theme_icon(name string, size int) string {
}()
cPath := C.icon_name_to_path(iconName, C.int(size))
defer C.free(unsafe.Pointer(cPath))
return C.GoString(cPath)
path := C.GoString(cPath)
return path
}
func initDeepin() {

View File

@ -47,30 +47,36 @@ func getAppIcon(core *gio.DesktopAppInfo) string {
icon := gioIcon.ToString()
logger.Debug("GetIcon:", icon)
if icon == "" {
logger.Warning("get icon from theme failed")
logger.Warning("gioIcon to string failed")
return ""
}
iconPath := get_theme_icon(icon, 48)
if iconPath == "" {
logger.Warning("get icon from theme failed")
return ""
// return a empty string might be a better idea here.
// However, gtk will get theme icon failed sometimes for unknown reason.
// frontend must make a validity check for icon.
iconPath = icon
}
logger.Debug("get_theme_icon:", icon)
ext := filepath.Ext(iconPath)
if ext == "" {
logger.Info("get app icon:", icon)
return icon
}
// the filepath.Ext return ".xxx"
// strip the '.' before extension name,
// filepath.Ext function will return ".xxx"
ext = ext[1:]
logger.Debug("ext:", ext)
if strings.EqualFold(ext, "xpm") {
logger.Debug("change xpm to data uri")
logger.Info("change xpm to data uri")
return xpm_to_dataurl(iconPath)
}
logger.Debug("get_theme_icon:", icon)
logger.Info("get app icon:", icon)
return icon
}