X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=launcher-item.cc;h=6487f283ef60338f2513af6f41a40868a6a8ce8b;hb=64824ee0d49f15f057dc86e3b4e97e9a062a86a0;hp=d7343d871c969da79931d7f58fe067a0503f7912;hpb=01c9f9655e70b2c241d667cc85d6afd6c1ac338a;p=simple-launcher diff --git a/launcher-item.cc b/launcher-item.cc index d7343d8..6487f28 100644 --- a/launcher-item.cc +++ b/launcher-item.cc @@ -1,6 +1,6 @@ // This file is a part of Simple Launcher // -// Copyright (C) 2006, Mikhail Sobolev +// Copyright (C) 2006, 2007, Mikhail Sobolev // // Simple Launcher is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License version 2 as published by @@ -17,19 +17,26 @@ #include +#include + #include #include #include "launcher-item.h" -GtkIconTheme *LauncherItem::ourTheme = 0; +GtkIconTheme *LauncherItem::ourTheme = NULL; static const char *DESKTOP_ENTRY_GROUP = "Desktop Entry", *DESKTOP_ENTRY_TYPE_FIELD = "Type", *DESKTOP_ENTRY_ICON_FIELD = "Icon", *DESKTOP_ENTRY_NAME_FIELD = "Name", *DESKTOP_ENTRY_COMMENT_FIELD = "Comment", - *DESKTOP_ENTRY_SERVICE_FIELD = "X-Osso-Service"; + *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: @@ -38,16 +45,16 @@ public: } ~GKeyFileWrapper() { - if (myKeyFile != 0) { + if (myKeyFile != NULL) { g_key_file_free(myKeyFile); } } bool load(const std::string& name) { - GError *error = 0; + GError *error = NULL; bool result = g_key_file_load_from_file(myKeyFile, name.c_str(), G_KEY_FILE_NONE, &error); - if (error != 0) { + if (error != NULL) { g_error_free(error); } @@ -55,10 +62,10 @@ public: } std::string getString(const gchar *group, const gchar *itemName) { - gchar *tempo = g_key_file_get_string(myKeyFile, group, itemName, 0); + gchar *tempo = g_key_file_get_string(myKeyFile, group, itemName, NULL); std::string result; - if (tempo != 0) { + if (tempo != NULL) { result.assign(tempo); g_free(tempo); @@ -68,10 +75,10 @@ public: } std::string getLocaleString(const gchar *group, const gchar *itemName) { - gchar *tempo = g_key_file_get_locale_string(myKeyFile, group, itemName, 0, 0); + gchar *tempo = g_key_file_get_locale_string(myKeyFile, group, itemName, NULL, NULL); std::string result; - if (tempo != 0) { + if (tempo != NULL) { result.assign(tempo); g_free(tempo); @@ -90,10 +97,20 @@ LauncherItem::LauncherItem(): myEnabled(false) { LauncherItem::~LauncherItem() { } +std::string LauncherItem::translateString(const std::string& what) const { + if (what.empty()) { + return what; + } else { + return dgettext(myTextDomain.empty() ? DEFAULT_TEXT_DOMAIN : myTextDomain.c_str(), what.c_str()); + } +} + bool LauncherItem::load(const std::string& filename) { GKeyFileWrapper key_file; for (;;) { + myFileName = filename; + if (!key_file.load(filename)) { break; } @@ -106,26 +123,36 @@ 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; } - return !(myName.empty() || myIcon.empty() || myService.empty()); + return (myEnabled = checkSanity()); } GdkPixbuf *LauncherItem::getIcon(int icon_size) const { - GdkPixbuf *pixbuf = 0; + if (ourTheme == NULL) { + ourTheme = gtk_icon_theme_get_default(); + } + + GdkPixbuf *pixbuf = NULL; + GError *error = NULL; if (!myIcon.empty()) { - if (ourTheme == 0) { - 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 = 0; + 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 != 0) { + if (error != NULL) { g_error_free(error); error = NULL; }