X-Git-Url: http://git.maemo.org/git/?p=simple-launcher;a=blobdiff_plain;f=launcher-item.cc;h=1b10593b58e78ddae5632e94efd1b5b7d84dbebc;hp=36653d8fb8313521a306f5a5e65ee60f69bdcc03;hb=f878e3159dae33edbe62bddbccedf087cec84aba;hpb=1d57b7cf5f090bbe31657cf2b351849cd1ba0ecd diff --git a/launcher-item.cc b/launcher-item.cc index 36653d8..1b10593 100644 --- a/launcher-item.cc +++ b/launcher-item.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -31,10 +32,12 @@ static const char *DESKTOP_ENTRY_GROUP = "Desktop Entry", *DESKTOP_ENTRY_ICON_FIELD = "Icon", *DESKTOP_ENTRY_NAME_FIELD = "Name", *DESKTOP_ENTRY_COMMENT_FIELD = "Comment", + *DESKTOP_ENTRY_EXEC_FIELD = "Exec", *DESKTOP_ENTRY_SERVICE_FIELD = "X-Osso-Service", *DESKTOP_ENTRY_TEXT_DOMAIN = "X-Text-Domain"; static const char *DEFAULT_TEXT_DOMAIN = "maemo-af-desktop"; +static const char *DEFAULT_APP_ICON = "qgn_list_gene_default_app"; class GKeyFileWrapper { public: @@ -121,6 +124,7 @@ bool LauncherItem::load(const std::string& filename) { myComment = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_COMMENT_FIELD); myIcon = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_ICON_FIELD); myService = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_SERVICE_FIELD); + myExec = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_EXEC_FIELD); myTextDomain = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_TEXT_DOMAIN); break; @@ -129,17 +133,48 @@ bool LauncherItem::load(const std::string& filename) { return (myEnabled = checkSanity()); } +// The function below is taken verbatim from exo library -- xfce supporting library +static GdkPixbuf *exo_gdk_pixbuf_scale_ratio(GdkPixbuf *source, gint dest_size) { + gdouble wratio, hratio; + gint source_width, source_height; + gint dest_width, dest_height; + + source_width = gdk_pixbuf_get_width(source); + source_height = gdk_pixbuf_get_height(source); + + wratio = (gdouble)source_width / (gdouble)dest_size; + hratio = (gdouble)source_height / (gdouble)dest_size; + + if (hratio > wratio) { + dest_width = (gint)rint(source_width / hratio); + dest_height = dest_size; + } else { + dest_width = dest_size; + dest_height = (gint)rint(source_height / wratio); + } + + return gdk_pixbuf_scale_simple(source, MAX(dest_width, 1), MAX(dest_height, 1), GDK_INTERP_BILINEAR); +} + GdkPixbuf *LauncherItem::getIcon(int icon_size) const { + if (ourTheme == NULL) { + ourTheme = gtk_icon_theme_get_default(); + } + GdkPixbuf *pixbuf = NULL; + GError *error = NULL; if (!myIcon.empty()) { - if (ourTheme == NULL) { - ourTheme = gtk_icon_theme_get_default(); - } + pixbuf = gtk_icon_theme_load_icon(ourTheme, myIcon.c_str(), icon_size, GTK_ICON_LOOKUP_NO_SVG, &error); - GError *error = NULL; + if (error != NULL) { + g_error_free(error); + error = NULL; + } + } - pixbuf = gtk_icon_theme_load_icon(ourTheme, myIcon.c_str(), icon_size, GTK_ICON_LOOKUP_NO_SVG, &error); + if (pixbuf == NULL) { + pixbuf = gtk_icon_theme_load_icon(ourTheme, DEFAULT_APP_ICON, icon_size, GTK_ICON_LOOKUP_NO_SVG, &error); if (error != NULL) { g_error_free(error); @@ -147,6 +182,20 @@ GdkPixbuf *LauncherItem::getIcon(int icon_size) const { } } + if (pixbuf != NULL) { + GdkPixbuf *tempo; + + if (gdk_pixbuf_get_width(pixbuf) > icon_size || gdk_pixbuf_get_height(pixbuf) > icon_size) { + tempo = exo_gdk_pixbuf_scale_ratio(pixbuf, icon_size); + } else { + tempo = gdk_pixbuf_copy(pixbuf); + } + + g_object_unref(pixbuf); + + pixbuf = tempo; + } + return pixbuf; }