[Xfce4-commits] <xfdesktop:jannis/port-to-gio> Generate tooltips of regular/special icons from the GFileInfo.
Jannis Pohlmann
noreply at xfce.org
Wed Oct 27 22:14:02 CEST 2010
Updating branch refs/heads/jannis/port-to-gio
to 37b0d08f2e0a833ea274825f01677a7528f0a783 (commit)
from 459404a4060bf7ff0be3db53e8e4f8feb4e76459 (commit)
commit 37b0d08f2e0a833ea274825f01677a7528f0a783
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Wed Oct 27 22:12:29 2010 +0200
Generate tooltips of regular/special icons from the GFileInfo.
src/xfdesktop-regular-file-icon.c | 43 +++++++++++++++----------
src/xfdesktop-special-file-icon.c | 64 ++++++++++++++++++++++++++-----------
2 files changed, 71 insertions(+), 36 deletions(-)
diff --git a/src/xfdesktop-regular-file-icon.c b/src/xfdesktop-regular-file-icon.c
index 5f136a0..2b23c3b 100644
--- a/src/xfdesktop-regular-file-icon.c
+++ b/src/xfdesktop-regular-file-icon.c
@@ -445,24 +445,33 @@ xfdesktop_regular_file_icon_peek_tooltip(XfdesktopIcon *icon)
{
XfdesktopRegularFileIcon *regular_file_icon = XFDESKTOP_REGULAR_FILE_ICON(icon);
- if(!regular_file_icon->priv->info)
- return NULL; /* FIXME: implement something here */
-
if(!regular_file_icon->priv->tooltip) {
- gchar mod[64], *kind, sizebuf[64], *size;
- struct tm *tm = localtime(®ular_file_icon->priv->info->mtime);
-
- strftime(mod, 64, "%Y-%m-%d %H:%M:%S", tm);
- kind = xfdesktop_file_utils_get_file_kind(regular_file_icon->priv->info, NULL);
- thunar_vfs_humanize_size(regular_file_icon->priv->info->size, sizebuf, 64);
- size = g_strdup_printf(_("%s (%" G_GINT64_FORMAT " Bytes)"), sizebuf,
- (gint64)regular_file_icon->priv->info->size);
-
- regular_file_icon->priv->tooltip = g_strdup_printf(_("Kind: %s\nModified:%s\nSize: %s"),
- kind, mod, size);
-
- g_free(kind);
- g_free(size);
+ GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon));
+ const gchar *content_type;
+ gchar *description, *size_string, *time_string;
+ guint64 size, mtime;
+
+ if(!info)
+ return NULL;
+
+ content_type = g_file_info_get_content_type(info);
+ description = g_content_type_get_description(content_type);
+
+ size = g_file_info_get_attribute_uint64(info,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE);
+ size_string = g_format_size_for_display(size);
+
+ mtime = g_file_info_get_attribute_uint64(info,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ time_string = xfdesktop_file_utils_format_time_for_display(mtime);
+
+ regular_file_icon->priv->tooltip =
+ g_strdup_printf(_("Type: %s\nSize: %s\nLast modified: %s"),
+ description, size_string, time_string);
+
+ g_free(time_string);
+ g_free(size_string);
+ g_free(description);
}
return regular_file_icon->priv->tooltip;
diff --git a/src/xfdesktop-special-file-icon.c b/src/xfdesktop-special-file-icon.c
index d2e93b0..828b806 100644
--- a/src/xfdesktop-special-file-icon.c
+++ b/src/xfdesktop-special-file-icon.c
@@ -383,27 +383,53 @@ xfdesktop_special_file_icon_peek_tooltip(XfdesktopIcon *icon)
XfdesktopSpecialFileIcon *special_file_icon = XFDESKTOP_SPECIAL_FILE_ICON(icon);
if(!special_file_icon->priv->tooltip) {
+ GFileInfo *info = xfdesktop_file_icon_peek_file_info(XFDESKTOP_FILE_ICON(icon));
+
+ if(!info)
+ return NULL;
+
if(XFDESKTOP_SPECIAL_FILE_ICON_TRASH == special_file_icon->priv->type) {
- /* FIXME: also display # of items in trash */
- special_file_icon->priv->tooltip = g_strdup(_("Kind: Trash"));
+ guint item_count = g_file_info_get_attribute_uint32(info,
+ G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT);
+
+ if(item_count == 0) {
+ special_file_icon->priv->tooltip = g_strdup(_("Trash is empty"));
+ } else {
+ special_file_icon->priv->tooltip = g_strdup_printf(g_dngettext(GETTEXT_PACKAGE,
+ _("Trash contains one item"),
+ _("Trash contains %d items"),
+ item_count),
+
+ item_count);
+ }
} else {
- gchar mod[64], *kind, sizebuf[64], *size;
- struct tm *tm = localtime(&special_file_icon->priv->info->mtime);
-
- strftime(mod, 64, "%Y-%m-%d %H:%M:%S", tm);
- kind = xfdesktop_file_utils_get_file_kind(special_file_icon->priv->info,
- NULL);
- thunar_vfs_humanize_size(special_file_icon->priv->info->size,
- sizebuf, 64);
- size = g_strdup_printf(_("%s (%" G_GINT64_FORMAT " Bytes)"),
- sizebuf,
- (gint64)special_file_icon->priv->info->size);
-
- special_file_icon->priv->tooltip = g_strdup_printf(_("Kind: %s\nModified:%s\nSize: %s"),
- kind, mod, size);
-
- g_free(kind);
- g_free(size);
+ const gchar *description;
+ gchar *size_string, *time_string;
+ guint64 size, mtime;
+
+ if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_FILESYSTEM)
+ description = _("File System");
+ else if(special_file_icon->priv->type == XFDESKTOP_SPECIAL_FILE_ICON_HOME)
+ description = _("Home");
+ else {
+ description = g_file_info_get_attribute_string(info,
+ G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
+ }
+
+ size = g_file_info_get_attribute_uint64(info,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE);
+ size_string = g_format_size_for_display(size);
+
+ mtime = g_file_info_get_attribute_uint64(info,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ time_string = xfdesktop_file_utils_format_time_for_display(mtime);
+
+ special_file_icon->priv->tooltip =
+ g_strdup_printf(_("%s\nSize: %s\nLast modified: %s"),
+ description, size_string, time_string);
+
+ g_free(size_string);
+ g_free(time_string);
}
}
More information about the Xfce4-commits
mailing list