X-Git-Url: http://git.maemo.org/git/?p=simple-launcher;a=blobdiff_plain;f=launcher-item.cc;h=1b10593b58e78ddae5632e94efd1b5b7d84dbebc;hp=39fa27420aef783bde2a722b81cc9283f4b1111f;hb=b843813af2067326837dcebbee364b1efcd56518;hpb=e7014881d2c994dd0e60427078c0c4bf6f4d1cdf diff --git a/launcher-item.cc b/launcher-item.cc index 39fa274..1b10593 100644 --- a/launcher-item.cc +++ b/launcher-item.cc @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -91,7 +92,7 @@ private: GKeyFile *myKeyFile; }; -LauncherItem::LauncherItem(): myIsGood(false), myEnabled(false) { +LauncherItem::LauncherItem(): myEnabled(false) { } LauncherItem::~LauncherItem() { @@ -108,8 +109,6 @@ std::string LauncherItem::translateString(const std::string& what) const { bool LauncherItem::load(const std::string& filename) { GKeyFileWrapper key_file; - myIsGood = false; - for (;;) { myFileName = filename; @@ -121,8 +120,6 @@ bool LauncherItem::load(const std::string& filename) { break; } - myIsGood = true; - myName = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_NAME_FIELD); myComment = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_COMMENT_FIELD); myIcon = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_ICON_FIELD); @@ -136,6 +133,29 @@ 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(); @@ -162,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; }