1 // This file is a part of Simple Launcher
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <glib/gmem.h>
23 #include <glib/gkeyfile.h>
25 #include "launcher-item.h"
27 GtkIconTheme *LauncherItem::ourTheme = NULL;
29 static const char *DESKTOP_ENTRY_GROUP = "Desktop Entry",
30 *DESKTOP_ENTRY_TYPE_FIELD = "Type",
31 *DESKTOP_ENTRY_ICON_FIELD = "Icon",
32 *DESKTOP_ENTRY_NAME_FIELD = "Name",
33 *DESKTOP_ENTRY_COMMENT_FIELD = "Comment",
34 *DESKTOP_ENTRY_EXEC_FIELD = "Exec",
35 *DESKTOP_ENTRY_SERVICE_FIELD = "X-Osso-Service",
36 *DESKTOP_ENTRY_TEXT_DOMAIN = "X-Text-Domain";
38 static const char *DEFAULT_TEXT_DOMAIN = "maemo-af-desktop";
39 static const char *DEFAULT_APP_ICON = "qgn_list_gene_default_app";
41 class GKeyFileWrapper {
44 myKeyFile = g_key_file_new();
48 if (myKeyFile != NULL) {
49 g_key_file_free(myKeyFile);
53 bool load(const std::string& name) {
55 bool result = g_key_file_load_from_file(myKeyFile, name.c_str(), G_KEY_FILE_NONE, &error);
64 std::string getString(const gchar *group, const gchar *itemName) {
65 gchar *tempo = g_key_file_get_string(myKeyFile, group, itemName, NULL);
77 std::string getLocaleString(const gchar *group, const gchar *itemName) {
78 gchar *tempo = g_key_file_get_locale_string(myKeyFile, group, itemName, NULL, NULL);
94 LauncherItem::LauncherItem(): myEnabled(false) {
97 LauncherItem::~LauncherItem() {
100 std::string LauncherItem::translateString(const std::string& what) const {
104 return dgettext(myTextDomain.empty() ? DEFAULT_TEXT_DOMAIN : myTextDomain.c_str(), what.c_str());
108 bool LauncherItem::load(const std::string& filename) {
109 GKeyFileWrapper key_file;
112 myFileName = filename;
114 if (!key_file.load(filename)) {
118 if (key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_TYPE_FIELD) != "Application") {
122 myName = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_NAME_FIELD);
123 myComment = key_file.getLocaleString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_COMMENT_FIELD);
124 myIcon = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_ICON_FIELD);
125 myService = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_SERVICE_FIELD);
126 myExec = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_EXEC_FIELD);
127 myTextDomain = key_file.getString(DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_TEXT_DOMAIN);
132 return (myEnabled = checkSanity());
135 GdkPixbuf *LauncherItem::getIcon(int icon_size) const {
136 if (ourTheme == NULL) {
137 ourTheme = gtk_icon_theme_get_default();
140 GdkPixbuf *pixbuf = NULL;
141 GError *error = NULL;
143 if (!myIcon.empty()) {
144 pixbuf = gtk_icon_theme_load_icon(ourTheme, myIcon.c_str(), icon_size, GTK_ICON_LOOKUP_NO_SVG, &error);
152 if (pixbuf == NULL) {
153 pixbuf = gtk_icon_theme_load_icon(ourTheme, DEFAULT_APP_ICON, icon_size, GTK_ICON_LOOKUP_NO_SVG, &error);