[frogr] Moved _get_datasize_string to frogr-util, so others can use it.
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Moved _get_datasize_string to frogr-util, so others can use it.
- Date: Sun, 14 Aug 2011 15:52:35 +0000 (UTC)
commit 9c17dee85b867ed501ab1b93f808a9052bb5666d
Author: Mario Sanchez Prada <msanchez igalia com>
Date: Sun Aug 14 17:40:57 2011 +0200
Moved _get_datasize_string to frogr-util, so others can use it.
So far, this was used only in the main view, but it could be useful
from now on to use it from other places (e.g. controller), so make it
public as yet another utility function.
src/frogr-main-view.c | 53 +++---------------------------------------------
src/frogr-util.c | 43 +++++++++++++++++++++++++++++++++++++++
src/frogr-util.h | 2 +
3 files changed, 49 insertions(+), 49 deletions(-)
---
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index e420724..e61a08f 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -224,8 +224,6 @@ static void _update_state_description (FrogrMainView *mainview);
static gchar *_craft_state_description (FrogrMainView *mainview);
-static gchar *_get_datasize_string (gulong bandwidth);
-
static void _update_sensitiveness (FrogrMainView *self);
static void _update_ui (FrogrMainView *self);
@@ -661,7 +659,7 @@ _on_icon_view_query_tooltip (GtkWidget *icon_view,
return FALSE;
/* Build the tooltip text with basic info: title, size */
- filesize = _get_datasize_string (frogr_picture_get_filesize (picture));
+ filesize = frogr_util_get_datasize_string (frogr_picture_get_filesize (picture));
datetime = frogr_picture_get_datetime (picture);
if (datetime)
{
@@ -1295,8 +1293,8 @@ _craft_state_description (FrogrMainView *mainview)
remaining_bw = frogr_account_get_remaining_bandwidth (account);
max_bw = frogr_account_get_max_bandwidth (account);
- remaining_bw_str = _get_datasize_string (remaining_bw);
- max_bw_str = _get_datasize_string (max_bw);
+ remaining_bw_str = frogr_util_get_datasize_string (remaining_bw);
+ max_bw_str = frogr_util_get_datasize_string (max_bw);
if (remaining_bw_str && max_bw_str)
{
@@ -1325,7 +1323,7 @@ _craft_state_description (FrogrMainView *mainview)
for (item = pictures; item; item = g_slist_next (item))
total_size += frogr_picture_get_filesize (FROGR_PICTURE (item->data));
- total_size_str = _get_datasize_string (total_size);
+ total_size_str = frogr_util_get_datasize_string (total_size);
/* Will show in the status bar the amount of data (in KB, MB or
GB) that would be uploaded as the sum of the sizes for every
@@ -1348,49 +1346,6 @@ _craft_state_description (FrogrMainView *mainview)
return description;
}
-static gchar *
-_get_datasize_string (gulong datasize)
-{
- gchar *result = NULL;
-
- if (datasize != G_MAXULONG)
- {
- gfloat datasize_float = G_MAXFLOAT;
- gchar *unit_str = NULL;
- int n_divisions = 0;
-
- datasize_float = datasize;
- while (datasize_float > 1000.0 && n_divisions < 3)
- {
- datasize_float /= 1024;
- n_divisions++;
- }
-
- switch (n_divisions)
- {
- case 0:
- unit_str = g_strdup ("KB");
- break;
- case 1:
- unit_str = g_strdup ("MB");
- break;
- case 2:
- unit_str = g_strdup ("GB");
- break;
- default:
- unit_str = NULL;;
- }
-
- if (unit_str)
- {
- result = g_strdup_printf ("%.1f %s", datasize_float, unit_str);
- g_free (unit_str);
- }
- }
-
- return result;
-}
-
static void
_update_sensitiveness (FrogrMainView *self)
{
diff --git a/src/frogr-util.c b/src/frogr-util.c
index e1fac6f..79d11e4 100644
--- a/src/frogr-util.c
+++ b/src/frogr-util.c
@@ -346,3 +346,46 @@ frogr_util_get_corrected_pixbuf (GdkPixbuf *pixbuf, gint max_width, gint max_hei
/* No rotation was applied, return the scaled pixbuf */
return scaled_pixbuf;
}
+
+gchar *
+frogr_util_get_datasize_string (gulong datasize)
+{
+ gchar *result = NULL;
+
+ if (datasize != G_MAXULONG)
+ {
+ gfloat datasize_float = G_MAXFLOAT;
+ gchar *unit_str = NULL;
+ int n_divisions = 0;
+
+ datasize_float = datasize;
+ while (datasize_float > 1000.0 && n_divisions < 3)
+ {
+ datasize_float /= 1024;
+ n_divisions++;
+ }
+
+ switch (n_divisions)
+ {
+ case 0:
+ unit_str = g_strdup ("KB");
+ break;
+ case 1:
+ unit_str = g_strdup ("MB");
+ break;
+ case 2:
+ unit_str = g_strdup ("GB");
+ break;
+ default:
+ unit_str = NULL;;
+ }
+
+ if (unit_str)
+ {
+ result = g_strdup_printf ("%.1f %s", datasize_float, unit_str);
+ g_free (unit_str);
+ }
+ }
+
+ return result;
+}
diff --git a/src/frogr-util.h b/src/frogr-util.h
index 6c13c08..f9bf4be 100644
--- a/src/frogr-util.h
+++ b/src/frogr-util.h
@@ -41,6 +41,8 @@ void frogr_util_show_error_dialog (GtkWindow *parent, const gchar *message);
GdkPixbuf *frogr_util_get_corrected_pixbuf (GdkPixbuf *pixbuf, gint max_width, gint max_height);
+gchar *frogr_util_get_datasize_string (gulong datasize);
+
G_END_DECLS
#endif /* FROGR_UTIL_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]