[gnome-commander] Simplify code for create_nice_size_str()
- From: Piotr Eljasiak <epiotr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Simplify code for create_nice_size_str()
- Date: Tue, 28 Jun 2011 19:14:11 +0000 (UTC)
commit 03d64b2d5955c7241f0782fd15b39b769d103f00
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Tue Jun 28 20:33:26 2011 +0200
Simplify code for create_nice_size_str()
src/gnome-cmd-file-props-dialog.cc | 18 ++++--------------
src/utils.cc | 18 ++++++++----------
src/utils.h | 2 +-
3 files changed, 13 insertions(+), 25 deletions(-)
---
diff --git a/src/gnome-cmd-file-props-dialog.cc b/src/gnome-cmd-file-props-dialog.cc
index f3cf6c1..d3b3451 100644
--- a/src/gnome-cmd-file-props-dialog.cc
+++ b/src/gnome-cmd-file-props-dialog.cc
@@ -66,18 +66,6 @@ struct GnomeCmdFilePropsDialogPrivate
};
-inline const gchar *get_size_disp_string (GnomeVFSFileSize size)
-{
- static gchar s[64];
-
- if (gnome_cmd_data.size_disp_mode == GNOME_CMD_SIZE_DISP_MODE_POWERED)
- return create_nice_size_str (size);
-
- snprintf (s, sizeof (s), ngettext("%s byte","%s bytes",size), size2string (size, gnome_cmd_data.size_disp_mode));
- return s;
-}
-
-
static void calc_tree_size_r (GnomeCmdFilePropsDialogPrivate *data, GnomeVFSURI *uri)
{
GList *list = NULL;
@@ -126,7 +114,7 @@ static void calc_tree_size_r (GnomeCmdFilePropsDialogPrivate *data, GnomeVFSURI
g_mutex_lock (data->mutex);
g_free (data->msg);
- data->msg = g_strdup (get_size_disp_string (data->size));
+ data->msg = create_nice_size_str (data->size);
g_mutex_unlock (data->mutex);
}
@@ -509,8 +497,10 @@ inline GtkWidget *create_properties_tab (GnomeCmdFilePropsDialogPrivate *data)
label = create_bold_label (dialog, _("Size:"));
table_add (table, label, 0, y, GTK_FILL);
- label = create_label (dialog, get_size_disp_string (data->f->info->size));
+ gchar *s = create_nice_size_str (data->f->info->size);
+ label = create_label (dialog, s);
table_add (table, label, 1, y++, GTK_FILL);
+ g_free (s);
if (data->f->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
do_calc_tree_size (data);
diff --git a/src/utils.cc b/src/utils.cc
index 6455c0e..1619a70 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -811,21 +811,19 @@ GList *string_history_add (GList *in, const gchar *value, guint maxsize)
}
-const gchar *create_nice_size_str (GnomeVFSFileSize size)
+gchar *create_nice_size_str (GnomeVFSFileSize size)
{
- static gchar str1[64];
- const gchar *s1 = size2string (size, GNOME_CMD_SIZE_DISP_MODE_GROUPED);
- snprintf (str1, sizeof (str1), ngettext("%s byte","%s bytes",size), s1);
+ GString *s = g_string_sized_new (64);
- if (size >= 1000)
+ if (gnome_cmd_data.size_disp_mode==GNOME_CMD_SIZE_DISP_MODE_POWERED && size>=1000)
{
- static gchar str2[128];
- const gchar *s2 = size2string (size, GNOME_CMD_SIZE_DISP_MODE_POWERED);
- snprintf (str2, sizeof (str2), "%s (%s)", s2, str1);
- return str2;
+ g_string_printf (s, "%s ", size2string (size, GNOME_CMD_SIZE_DISP_MODE_POWERED));
+ g_string_append_printf (s, ngettext("(%s byte)","(%s bytes)",size), size2string (size, GNOME_CMD_SIZE_DISP_MODE_GROUPED));
}
+ else
+ g_string_printf (s, ngettext("%s byte","%s bytes",size), size2string (size, GNOME_CMD_SIZE_DISP_MODE_GROUPED));
- return str1;
+ return g_string_free (s, FALSE);
}
diff --git a/src/utils.h b/src/utils.h
index 067a59c..cb26a69 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -178,7 +178,7 @@ inline gboolean state_is_ctrl_alt_shift (gint state)
GList *strings_to_uris (gchar *data);
GnomeVFSFileSize calc_tree_size (const GnomeVFSURI *dir_uri);
-const gchar *create_nice_size_str (GnomeVFSFileSize size);
+gchar *create_nice_size_str (GnomeVFSFileSize size);
inline gchar *quote_if_needed (const gchar *in)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]