[nautilus] file: use a GIcon to store the custom icon of desktop files
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] file: use a GIcon to store the custom icon of desktop files
- Date: Mon, 4 Apr 2011 21:29:01 +0000 (UTC)
commit 2afe78a92cc402207e7f3a0189eca95311651076
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Apr 4 17:01:50 2011 -0400
file: use a GIcon to store the custom icon of desktop files
Instead of a filename string.
This also has the side-effect of fixing
https://bugzilla.gnome.org/show_bug.cgi?id=615509
libnautilus-private/nautilus-directory-async.c | 20 +++--
libnautilus-private/nautilus-file-private.h | 2 +-
libnautilus-private/nautilus-file.c | 10 +--
libnautilus-private/nautilus-link.c | 99 +++++++++++++++---------
libnautilus-private/nautilus-link.h | 2 +-
5 files changed, 79 insertions(+), 54 deletions(-)
---
diff --git a/libnautilus-private/nautilus-directory-async.c b/libnautilus-private/nautilus-directory-async.c
index 214ef4f..a998c60 100644
--- a/libnautilus-private/nautilus-directory-async.c
+++ b/libnautilus-private/nautilus-directory-async.c
@@ -194,7 +194,7 @@ static void link_info_done (NautilusDirectory
NautilusFile *file,
const char *uri,
const char *name,
- const char *icon,
+ GIcon *icon,
gboolean is_launcher,
gboolean is_foreign);
static void move_file_to_low_priority_queue (NautilusDirectory *directory,
@@ -3548,7 +3548,7 @@ link_info_done (NautilusDirectory *directory,
NautilusFile *file,
const char *uri,
const char *name,
- const char *icon,
+ GIcon *icon,
gboolean is_launcher,
gboolean is_foreign)
{
@@ -3565,16 +3565,16 @@ link_info_done (NautilusDirectory *directory,
}
file->details->got_link_info = TRUE;
- g_free (file->details->custom_icon);
- file->details->custom_icon = NULL;
+ g_clear_object (&file->details->custom_icon);
+
if (uri) {
g_free (file->details->activation_uri);
file->details->activation_uri = NULL;
file->details->got_custom_activation_uri = TRUE;
file->details->activation_uri = g_strdup (uri);
}
- if (is_trusted) {
- file->details->custom_icon = g_strdup (icon);
+ if (is_trusted && (icon != NULL)) {
+ file->details->custom_icon = g_object_ref (icon);
}
file->details->is_launcher = is_launcher;
file->details->is_foreign_link = is_foreign;
@@ -3623,7 +3623,8 @@ link_info_got_data (NautilusDirectory *directory,
goffset bytes_read,
char *file_contents)
{
- char *link_uri, *uri, *name, *icon;
+ char *link_uri, *uri, *name;
+ GIcon *icon;
gboolean is_launcher;
gboolean is_foreign;
@@ -3652,7 +3653,10 @@ link_info_got_data (NautilusDirectory *directory,
g_free (uri);
g_free (name);
- g_free (icon);
+
+ if (icon != NULL) {
+ g_object_unref (icon);
+ }
nautilus_directory_unref (directory);
}
diff --git a/libnautilus-private/nautilus-file-private.h b/libnautilus-private/nautilus-file-private.h
index 8cc5795..cc14b3e 100644
--- a/libnautilus-private/nautilus-file-private.h
+++ b/libnautilus-private/nautilus-file-private.h
@@ -106,7 +106,7 @@ struct NautilusFileDetails
char *top_left_text;
/* Info you might get from a link (.desktop, .directory or nautilus link) */
- char *custom_icon;
+ GIcon *custom_icon;
char *activation_uri;
/* used during DND, for checking whether source and destination are on
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index 5ebc29e..0f31e5d 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -800,8 +800,8 @@ finalize (GObject *object)
g_free (file->details->selinux_context);
g_free (file->details->description);
g_free (file->details->top_left_text);
- g_free (file->details->custom_icon);
g_free (file->details->activation_uri);
+ g_clear_object (&file->details->custom_icon);
if (file->details->thumbnail) {
g_object_unref (file->details->thumbnail);
@@ -3923,13 +3923,7 @@ get_custom_icon (NautilusFile *file)
}
if (icon == NULL && file->details->got_link_info && file->details->custom_icon != NULL) {
- if (g_path_is_absolute (file->details->custom_icon)) {
- icon_file = g_file_new_for_path (file->details->custom_icon);
- icon = g_file_icon_new (icon_file);
- g_object_unref (icon_file);
- } else {
- icon = g_themed_icon_new (file->details->custom_icon);
- }
+ icon = g_object_ref (file->details->custom_icon);
}
return icon;
diff --git a/libnautilus-private/nautilus-link.c b/libnautilus-private/nautilus-link.c
index e3d4191..2c56c0f 100644
--- a/libnautilus-private/nautilus-link.c
+++ b/libnautilus-private/nautilus-link.c
@@ -440,50 +440,77 @@ nautilus_link_get_link_name_from_desktop (GKeyFile *key_file)
return g_key_file_get_locale_string (key_file, MAIN_GROUP, "Name", NULL, NULL);
}
-static char *
+static GIcon *
nautilus_link_get_link_icon_from_desktop (GKeyFile *key_file)
{
- char *icon_uri, *icon, *p, *type;
-
- icon_uri = g_key_file_get_string (key_file, MAIN_GROUP, "X-Nautilus-Icon", NULL);
- if (icon_uri != NULL) {
- return icon_uri;
- }
-
- icon = g_key_file_get_string (key_file, MAIN_GROUP, "Icon", NULL);
- if (icon != NULL) {
- if (!g_path_is_absolute (icon)) {
- /* Strip out any extension on non-filename icons. Old desktop files may have this */
- p = strchr (icon, '.');
- /* Only strip known icon extensions */
- if ((p != NULL) &&
- ((g_ascii_strcasecmp (p, ".png") == 0)
- || (g_ascii_strcasecmp (p, ".svn") == 0)
- || (g_ascii_strcasecmp (p, ".jpg") == 0)
- || (g_ascii_strcasecmp (p, ".xpm") == 0)
- || (g_ascii_strcasecmp (p, ".bmp") == 0)
- || (g_ascii_strcasecmp (p, ".jpeg") == 0))) {
- *p = 0;
- }
- }
- return icon;
+ char *icon_str, *p, *type = NULL;
+ GFile *file;
+ GIcon *icon;
+
+ /* Look at the Icon: key */
+ icon_str = g_key_file_get_string (key_file, MAIN_GROUP, "Icon", NULL);
+
+ /* if it's an absolute path, return a GFileIcon for that path */
+ if (icon_str != NULL && g_path_is_absolute (icon_str)) {
+ file = g_file_new_for_path (icon_str);
+ icon = g_file_icon_new (file);
+
+ g_object_unref (file);
+
+ goto out;
}
type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
- if (g_strcmp0 (type, "Application") == 0) {
- icon = g_strdup ("gnome-fs-executable");
- } else if (g_strcmp0 (type, "Link") == 0) {
- icon = g_strdup ("gnome-dev-symlink");
- } else if (g_strcmp0 (type, "FSDevice") == 0) {
- icon = g_strdup ("gnome-dev-harddisk");
- } else if (g_strcmp0 (type, "Directory") == 0) {
- icon = g_strdup (NAUTILUS_ICON_FOLDER);
- } else if (g_strcmp0 (type, "Service") == 0 ||
- g_strcmp0 (type, "ServiceType") == 0) {
- icon = g_strdup ("gnome-fs-web");
+
+ if (icon_str == NULL) {
+ if (g_strcmp0 (type, "Application") == 0) {
+ icon_str = g_strdup ("application-x-executable");
+ } else if (g_strcmp0 (type, "FSDevice") == 0) {
+ icon_str = g_strdup ("drive-harddisk");
+ } else if (g_strcmp0 (type, "Directory") == 0) {
+ icon_str = g_strdup (NAUTILUS_ICON_FOLDER);
+ } else if (g_strcmp0 (type, "Service") == 0 ||
+ g_strcmp0 (type, "ServiceType") == 0) {
+ icon_str = g_strdup ("folder-remote");
+ } else {
+ icon_str = g_strdup ("text-x-preview");
+ }
} else {
- icon = g_strdup ("gnome-fs-regular");
+ /* Strip out any extension on non-filename icons. Old desktop files may have this */
+ p = strchr (icon_str, '.');
+ /* Only strip known icon extensions */
+ if ((p != NULL) &&
+ ((g_ascii_strcasecmp (p, ".png") == 0)
+ || (g_ascii_strcasecmp (p, ".svn") == 0)
+ || (g_ascii_strcasecmp (p, ".jpg") == 0)
+ || (g_ascii_strcasecmp (p, ".xpm") == 0)
+ || (g_ascii_strcasecmp (p, ".bmp") == 0)
+ || (g_ascii_strcasecmp (p, ".jpeg") == 0))) {
+ *p = 0;
+ }
+ }
+
+ icon = g_themed_icon_new_with_default_fallbacks (icon_str);
+
+ /* apply a link emblem if it's a link */
+ if (g_strcmp0 (type, "Link") == 0) {
+ GIcon *emblemed, *emblem_icon;
+ GEmblem *emblem;
+
+ emblem_icon = g_themed_icon_new ("emblem-symbolic-link");
+ emblem = g_emblem_new (emblem_icon);
+
+ emblemed = g_emblemed_icon_new (icon, emblem);
+
+ g_object_unref (icon);
+ g_object_unref (emblem_icon);
+ g_object_unref (emblem);
+
+ icon = emblemed;
}
+
+ out:
+ g_free (icon_str);
g_free (type);
return icon;
@@ -533,7 +560,7 @@ nautilus_link_get_link_info_given_file_contents (const char *file_contents,
const char *file_uri,
char **uri,
char **name,
- char **icon,
+ GIcon **icon,
gboolean *is_launcher,
gboolean *is_foreign)
{
diff --git a/libnautilus-private/nautilus-link.h b/libnautilus-private/nautilus-link.h
index 5031990..fbb4016 100644
--- a/libnautilus-private/nautilus-link.h
+++ b/libnautilus-private/nautilus-link.h
@@ -47,7 +47,7 @@ void nautilus_link_get_link_info_given_file_contents (const char
const char *file_uri,
char **uri,
char **name,
- char **icon,
+ GIcon **icon,
gboolean *is_launcher,
gboolean *is_foreign);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]