From: Dirk-Jan C. Binnema Date: Tue, 23 Jan 2007 07:41:06 +0000 (+0000) Subject: * modest-header-view-render.c, modest-text-utils.[ch]: X-Git-Tag: git_migration_finished~4183 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=1bcaa975bf187f8164245547b94c511f4f19dc25 * modest-header-view-render.c, modest-text-utils.[ch]: - move the size display string stuff to text utils pmo-trunk-r696 --- diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 70641f6..9d09413 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -870,3 +870,29 @@ modest_text_utils_validate_email_address (const gchar *email_address) return (count >= 1) ? TRUE : FALSE; } + + + + +gchar * +modest_text_utils_get_display_size (gint size) +{ + const int KB=1024; + const int MB=1024 * KB; + const int GB=1024 * MB; + const int TB=1024 * GB; + const int PB=1024 * TB; + + if (size < KB) + return g_strdup_printf (_("%0.2f Kb"), (double)size / KB); + else if (size < MB) + return g_strdup_printf (_("%d Kb"), size / KB); + else if (size < GB) + return g_strdup_printf (_("%d Mb"), size / MB); + else if (size < TB) + return g_strdup_printf (_("%d Gb"), size/ GB); + else if (size < PB) + return g_strdup_printf (_("%d Tb"), size/ TB); + else + return g_strdup_printf (_("Very big")); +} diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 7ff32b8..cd693cc 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -200,6 +200,18 @@ const gchar* modest_text_utils_get_display_date (time_t date); /** + * modest_text_utils_get_display_size: + * @size: size in bytes + * + * get a string representation for a size in bytes. + * + * Returns: the newly allocated display string for the + * size in bytes. must be freed. + */ +gchar * modest_text_utils_get_display_size (gint size); + + +/** * modest_text_utils_validate_email_address: * @email_address: a string * diff --git a/src/widgets/modest-header-view-render.c b/src/widgets/modest-header-view-render.c index f507adb..9ac7d1a 100644 --- a/src/widgets/modest-header-view-render.c +++ b/src/widgets/modest-header-view-render.c @@ -84,7 +84,7 @@ get_display_date (time_t date) } } - + void _modest_header_view_msgtype_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer user_data) @@ -250,33 +250,22 @@ _modest_header_view_size_cell_data (GtkTreeViewColumn *column, GtkCellRenderer gpointer user_data) { TnyHeaderFlags flags; - guint size; - gchar *size_str; - const gchar* unit; - - gtk_tree_model_get (tree_model, iter, + guint size; + gchar *size_str; + const gchar* unit; + + gtk_tree_model_get (tree_model, iter, TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN, &flags, TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN, &size, - -1); - - if (size < 1024*1024) { - unit = _("Kb"); - size /= 1024; - } else if (size < 1024*1024*1024) { - unit = _("Mb"); - size /= (1024*1024); - } else { - unit = _("Gb"); - size /= (1024*1024*1024); - } - - size_str = g_strdup_printf ("%d %s", size, unit); - - g_object_set (G_OBJECT(renderer), - "weight", (flags & TNY_HEADER_FLAG_SEEN) ? 400: 800, - "style", (flags & TNY_HEADER_FLAG_DELETED) ? - PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, - "text", size_str, + -1); + + size_str = modest_text_utils_get_display_size (size); + + g_object_set (G_OBJECT(renderer), + "weight", (flags & TNY_HEADER_FLAG_SEEN) ? 400: 800, + "style", (flags & TNY_HEADER_FLAG_DELETED) ? + PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL, + "text", size_str, NULL); g_free (size_str);