[frogr] Simplified update of account description string
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Simplified update of account description string
- Date: Fri, 22 Apr 2011 07:20:14 +0000 (UTC)
commit 20b19cc469a584942e6e21d2c9565b137571be40
Author: Mario Sanchez Prada <msanchez igalia com>
Date: Fri Apr 22 08:08:59 2011 +0200
Simplified update of account description string
src/frogr-main-view-model.c | 2 +-
src/frogr-main-view-model.h | 2 +-
src/frogr-main-view.c | 50 ++++++++++++++++++++++--------------------
3 files changed, 28 insertions(+), 26 deletions(-)
---
diff --git a/src/frogr-main-view-model.c b/src/frogr-main-view-model.c
index 008cd26..194b6ea 100644
--- a/src/frogr-main-view-model.c
+++ b/src/frogr-main-view-model.c
@@ -453,7 +453,7 @@ frogr_main_view_model_n_tags (FrogrMainViewModel *self)
return priv->n_tags;
}
-gchar *
+const gchar *
frogr_main_view_model_get_account_description (FrogrMainViewModel *self)
{
g_return_val_if_fail (FROGR_IS_MAIN_VIEW_MODEL (self), NULL);
diff --git a/src/frogr-main-view-model.h b/src/frogr-main-view-model.h
index fd6c4a2..b5cede9 100644
--- a/src/frogr-main-view-model.h
+++ b/src/frogr-main-view-model.h
@@ -101,7 +101,7 @@ void frogr_main_view_model_remove_all_tags (FrogrMainViewModel *self);
guint frogr_main_view_model_n_tags (FrogrMainViewModel *self);
-gchar *frogr_main_view_model_get_account_description (FrogrMainViewModel *self);
+const gchar *frogr_main_view_model_get_account_description (FrogrMainViewModel *self);
void frogr_main_view_model_set_account_description (FrogrMainViewModel *self,
const gchar *description);
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 5a52e2c..d9aa955 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -197,6 +197,8 @@ static void _model_picture_removed (FrogrController *controller,
FrogrPicture *picture,
gpointer data);
+static void _update_account_description (FrogrMainView *mainview);
+
static gchar *_craft_account_description (FrogrMainView *mainview);
static gchar *_get_datasize_string (gulong bandwidth);
@@ -1127,20 +1129,10 @@ _controller_active_account_changed (FrogrController *controller,
gpointer data)
{
FrogrMainView *mainview = NULL;
- FrogrMainViewPrivate *priv = NULL;
- gchar *description = NULL;
mainview = FROGR_MAIN_VIEW (data);
- priv = FROGR_MAIN_VIEW_GET_PRIVATE (mainview);
-
- description = _craft_account_description (mainview);
- frogr_main_view_model_set_account_description (priv->model, description);
-
- if (frogr_controller_get_state (priv->controller) != FROGR_STATE_BUSY)
- frogr_main_view_set_status_text (mainview, description);
-
- DEBUG ("Account details changed: %s", description);
- g_free (description);
+ _update_account_description (mainview);
+ _update_ui (mainview);
}
static void
@@ -1175,6 +1167,19 @@ _model_picture_removed (FrogrController *controller,
_remove_picture_from_ui (mainview, picture);
}
+static void _update_account_description (FrogrMainView *mainview)
+{
+ FrogrMainViewPrivate *priv = NULL;
+ gchar *description = NULL;
+
+ priv = FROGR_MAIN_VIEW_GET_PRIVATE (mainview);
+
+ description = _craft_account_description (mainview);
+ frogr_main_view_model_set_account_description (priv->model, description);
+
+ DEBUG ("Account description changed: %s", description);
+ g_free (description);
+}
static gchar *_craft_account_description (FrogrMainView *mainview)
{
@@ -1235,20 +1240,20 @@ static gchar *_craft_account_description (FrogrMainView *mainview)
}
static gchar *
-_get_datasize_string (gulong bandwidth)
+_get_datasize_string (gulong datasize)
{
gchar *result = NULL;
- if (bandwidth != G_MAXULONG)
+ if (datasize != G_MAXULONG)
{
- gfloat bandwidth_float = G_MAXFLOAT;
+ gfloat datasize_float = G_MAXFLOAT;
gchar *unit_str = NULL;
int n_divisions = 0;
- bandwidth_float = bandwidth;
- while (bandwidth_float > 1000.0 && n_divisions < 3)
+ datasize_float = datasize;
+ while (datasize_float > 1000.0 && n_divisions < 3)
{
- bandwidth_float /= 1024;
+ datasize_float /= 1024;
n_divisions++;
}
@@ -1269,7 +1274,7 @@ _get_datasize_string (gulong bandwidth)
if (unit_str)
{
- result = g_strdup_printf ("%.1f %s", bandwidth_float, unit_str);
+ result = g_strdup_printf ("%.1f %s", datasize_float, unit_str);
g_free (unit_str);
}
}
@@ -1281,7 +1286,7 @@ static void
_update_ui (FrogrMainView *self)
{
FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
- gchar *account_description = NULL;
+ const gchar *account_description = NULL;
gboolean has_accounts = FALSE;
gboolean has_pics = FALSE;
@@ -1400,7 +1405,6 @@ frogr_main_view_init (FrogrMainView *self)
GtkWidget *progress_bar;
GtkWidget *progress_label;
GList *icons;
- gchar *account_description;
#ifdef MAC_INTEGRATION
GtkOSXApplication *osx_app;
@@ -1413,9 +1417,7 @@ frogr_main_view_init (FrogrMainView *self)
priv->controller = g_object_ref (frogr_controller_get_instance ());
/* Init main model's account description */
- account_description = _craft_account_description (self);
- frogr_main_view_model_set_account_description (priv->model, account_description);
- g_free (account_description);
+ _update_account_description (self);
/* Provide a default icon list in several sizes */
icons = g_list_prepend (NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]