1 // This file is a part of Simple Launcher
3 // Copyright (C) 2006, 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
20 #include <glib/gmem.h>
21 #include <glib/gkeyfile.h>
23 #include "launcher-item.h"
25 GtkIconTheme *LauncherItem::ourTheme = 0;
27 static const char *DESKTOP_ENTRY_GROUP = "Desktop Entry",
28 *DESKTOP_ENTRY_TYPE_FIELD = "Type",
29 *DESKTOP_ENTRY_ICON_FIELD = "Icon",
30 *DESKTOP_ENTRY_NAME_FIELD = "Name",
31 *DESKTOP_ENTRY_COMMENT_FIELD = "Comment",
32 *DESKTOP_ENTRY_SERVICE_FIELD = "X-Osso-Service";
34 inline std::string getStringWrapper(GKeyFile *keyFile, const gchar *group, const gchar *itemName) {
35 gchar *tempo = g_key_file_get_string(keyFile, group, itemName, 0);
47 inline std::string getLocaleStringWrapper(GKeyFile *keyFile, const gchar *group, const gchar *itemName) {
48 gchar *tempo = g_key_file_get_locale_string(keyFile, group, itemName, 0, 0);
60 LauncherItem::LauncherItem() {
63 LauncherItem::~LauncherItem() {
66 bool LauncherItem::load(const std::string& filename) {
67 GKeyFile *key_file = 0;
71 if ((key_file = g_key_file_new()) == 0) {
75 if (!g_key_file_load_from_file(key_file, filename.c_str(), G_KEY_FILE_NONE, &error)) {
79 if (getStringWrapper(key_file, DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_TYPE_FIELD) != "Application") {
83 myName = getStringWrapper(key_file, DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_NAME_FIELD);
84 myComment = getLocaleStringWrapper(key_file, DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_COMMENT_FIELD);
85 myIcon = getStringWrapper(key_file, DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_ICON_FIELD);
86 myService = getStringWrapper(key_file, DESKTOP_ENTRY_GROUP, DESKTOP_ENTRY_SERVICE_FIELD);
97 g_key_file_free(key_file);
100 return !(myName.empty() || myIcon.empty() || myService.empty());
103 GdkPixbuf *LauncherItem::getIcon(int icon_size) const {
104 GdkPixbuf *pixbuf = 0;
106 if (!myIcon.empty()) {
108 ourTheme = gtk_icon_theme_get_default();
113 pixbuf = gtk_icon_theme_load_icon(ourTheme, myIcon.c_str(), icon_size, GTK_ICON_LOOKUP_NO_SVG, &error);