2 * Camera Launcher for Maemo.
3 * Copyright (C) 2010 Roman Moravcik
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <gconf/gconf-client.h>
31 #include <glib/gi18n-lib.h>
34 #include <hildon/hildon.h>
39 get_desktop_file_info (const gchar *desktop_file)
41 DesktopFileInfo *dfinfo = NULL;
45 key_file = g_key_file_new ();
46 if (g_key_file_load_from_file (key_file, desktop_file, 0, NULL)) {
49 /* exclude non application desktop files */
50 if (g_key_file_has_key (key_file, "Desktop Entry", "Type", NULL)) {
51 type = g_key_file_get_string (key_file, "Desktop Entry", "Type", NULL);
53 if (strcmp (type, "Application")) {
61 dfinfo = g_new0 (DesktopFileInfo, 1);
63 /* get application icon */
64 if (g_key_file_has_key (key_file, "Desktop Entry", "Icon", NULL)) {
65 dfinfo->icon = g_key_file_get_string (key_file, "Desktop Entry", "Icon", NULL);
70 /* get application name */
71 if (g_key_file_has_key (key_file, "Desktop Entry", "X-Text-Domain", NULL)) {
72 textdomain (g_key_file_get_string (key_file, "Desktop Entry", "X-Text-Domain", NULL));
73 dfinfo->name = gettext (g_key_file_get_string (key_file, "Desktop Entry", "Name", NULL));
74 } else if (g_key_file_has_key (key_file, "Desktop Entry", "Name", NULL)) {
75 textdomain ("maemo-af-desktop");
76 dfinfo->name = gettext (g_key_file_get_string (key_file, "Desktop Entry", "Name", NULL));
81 /* get application osso_service */
82 if (g_key_file_has_key (key_file, "Desktop Entry", "X-Osso-Service", NULL)) {
83 dfinfo->osso_service = g_key_file_get_string (key_file, "Desktop Entry", "X-Osso-Service", NULL);
85 dfinfo->osso_service = NULL;
88 /* get application exec */
89 if (g_key_file_has_key (key_file, "Desktop Entry", "Exec", NULL)) {
90 dfinfo->exec = g_key_file_get_string (key_file, "Desktop Entry", "Exec", NULL);
97 g_key_file_free (key_file);
103 get_application_list (GtkListStore *store)
105 gboolean is_empty = TRUE;
106 GtkIconTheme *icon_theme;
110 icon_theme = gtk_icon_theme_get_default ();
112 dir = g_dir_open (CL_LAUNCHER_DESKTOP_DATADIR, 0, NULL);
114 const gchar *filename;
116 while ((filename = g_dir_read_name (dir)) != NULL) {
117 if (g_str_has_suffix (filename, ".desktop")) {
118 DesktopFileInfo *dfinfo = NULL;
119 GtkIconInfo *icon_info;
120 GdkPixbuf *icon_pixbuf = NULL;
121 gchar *desktop_file = NULL;
123 desktop_file = g_strdup_printf ("%s/%s", CL_LAUNCHER_DESKTOP_DATADIR, filename);
125 dfinfo = get_desktop_file_info (desktop_file);
128 dfinfo->icon = g_strdup ("tasklaunch_default_application");
131 icon_info = gtk_icon_theme_lookup_icon (icon_theme, dfinfo->icon, 48,
132 GTK_ICON_LOOKUP_NO_SVG);
134 const gchar *fname = gtk_icon_info_get_filename (icon_info);
135 icon_pixbuf = gdk_pixbuf_new_from_file_at_size (fname, 48, 48, 0);
136 gtk_icon_info_free (icon_info);
139 /* fill application store */
140 gtk_list_store_append (store, &iter);
141 gtk_list_store_set (store, &iter,
142 SELECTOR_COLUMN_NAME, dfinfo->name,
143 SELECTOR_COLUMN_ICON, icon_pixbuf,
144 SELECTOR_COLUMN_FILENAME, filename,
145 SELECTOR_COLUMN_OSSO_SERVICE, dfinfo->osso_service,
146 SELECTOR_COLUMN_EXEC, dfinfo->exec,
149 if (is_empty == TRUE)
153 g_object_unref (icon_pixbuf);
157 g_free (desktop_file);
168 get_application_list_from_list (GtkListStore *store, const GSList *list)
170 const GSList *application;
171 gboolean is_empty = TRUE;
172 GtkIconTheme *icon_theme;
175 icon_theme = gtk_icon_theme_get_default ();
177 for (application = list; application != NULL; application = application->next) {
178 const gchar *filename;
180 filename = gconf_value_get_string (application->data);
182 if (g_str_has_suffix (filename, ".desktop")) {
183 DesktopFileInfo *dfinfo = NULL;
184 GtkIconInfo *icon_info;
185 GdkPixbuf *icon_pixbuf = NULL;
186 gchar *desktop_file = NULL;
188 desktop_file = g_strdup_printf ("%s/%s", CL_LAUNCHER_DESKTOP_DATADIR, filename);
190 dfinfo = get_desktop_file_info (desktop_file);
193 dfinfo->icon = g_strdup ("tasklaunch_default_application");
196 icon_info = gtk_icon_theme_lookup_icon (icon_theme, dfinfo->icon, 48,
197 GTK_ICON_LOOKUP_NO_SVG);
199 const gchar *fname = gtk_icon_info_get_filename (icon_info);
200 icon_pixbuf = gdk_pixbuf_new_from_file_at_size (fname, 48, 48, 0);
201 gtk_icon_info_free (icon_info);
204 /* fill application store */
205 gtk_list_store_append (store, &iter);
206 gtk_list_store_set (store, &iter,
207 SELECTOR_COLUMN_NAME, dfinfo->name,
208 SELECTOR_COLUMN_ICON, icon_pixbuf,
209 SELECTOR_COLUMN_FILENAME, filename,
210 SELECTOR_COLUMN_OSSO_SERVICE, dfinfo->osso_service,
211 SELECTOR_COLUMN_EXEC, dfinfo->exec,
214 if (is_empty == TRUE)
218 g_object_unref (icon_pixbuf);
222 g_free (desktop_file);