| 1 |
/* |
| 2 |
Copyright 2013-2014 Canonical Ltd. |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify it |
| 5 |
under the terms of the GNU General Public License version 3, as published |
| 6 |
by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but |
| 9 |
WITHOUT ANY WARRANTY; without even the implied warranties of |
| 10 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. See the GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License along |
| 14 |
with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
// Package cappinfo wraps C functions to access app information |
| 18 |
|
| 19 |
package cappinfo |
| 20 |
|
| 21 |
/* |
| 22 |
#cgo pkg-config: gio-unix-2.0 |
| 23 |
#include <glib.h> |
| 24 |
#include <gio/gdesktopappinfo.h> |
| 25 |
|
| 26 |
gchar* app_icon_filename_from_desktop_id (gchar* desktop_id) { |
| 27 |
gchar* filename = NULL; |
| 28 |
GAppInfo* app_info = (GAppInfo*)g_desktop_app_info_new (desktop_id); |
| 29 |
if (app_info != NULL) { |
| 30 |
GIcon* icon = g_app_info_get_icon (app_info); |
| 31 |
if (icon != NULL) { |
| 32 |
filename = g_icon_to_string (icon); |
| 33 |
// g_app_info_get_icon has "transfer none" |
| 34 |
} |
| 35 |
g_object_unref (app_info); |
| 36 |
} |
| 37 |
g_free (desktop_id); |
| 38 |
return filename; |
| 39 |
} |
| 40 |
|
| 41 |
gchar* app_symbolic_icon_from_desktop_id (gchar* desktop_id) { |
| 42 |
gchar* x_symbolic_icon; |
| 43 |
GIcon* symbolic_icon; |
| 44 |
GDesktopAppInfo* app_info = g_desktop_app_info_new (desktop_id); |
| 45 |
if (app_info != NULL) { |
| 46 |
if((x_symbolic_icon = g_desktop_app_info_get_string(app_info, "X-Ubuntu-SymbolicIcon"))) { |
| 47 |
GFile *file; |
| 48 |
file = g_file_new_for_path(x_symbolic_icon); |
| 49 |
symbolic_icon = g_file_icon_new (file); |
| 50 |
g_object_unref (file); |
| 51 |
g_free(x_symbolic_icon); |
| 52 |
g_object_unref (app_info); |
| 53 |
return g_icon_to_string(symbolic_icon); |
| 54 |
} |
| 55 |
g_object_unref (app_info); |
| 56 |
} |
| 57 |
g_free (desktop_id); |
| 58 |
return NULL; |
| 59 |
} |
| 60 |
*/ |
| 61 |
import "C" |
| 62 |
|
| 63 |
func AppIconFromDesktopId(desktopId string) string { |
| 64 |
name := C.app_icon_filename_from_desktop_id((*C.gchar)(C.CString(desktopId))) |
| 65 |
defer C.g_free((C.gpointer)(name)) |
| 66 |
return C.GoString((*C.char)(name)) |
| 67 |
} |
| 68 |
|
| 69 |
func appSymbolicIconFromDesktopId(desktopId string) string { |
| 70 |
name := C.app_symbolic_icon_from_desktop_id((*C.gchar)(C.CString(desktopId))) |
| 71 |
if name == nil { |
| 72 |
return "" |
| 73 |
} |
| 74 |
defer C.g_free((C.gpointer)(name)) |
| 75 |
return C.GoString((*C.char)(name)) |
| 76 |
} |
| 77 |
|
| 78 |
var AppSymbolicIconFromDesktopId = appSymbolicIconFromDesktopId |