[frogr] Make the mainview model keep the original list of pictures as uploaded
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Make the mainview model keep the original list of pictures as uploaded
- Date: Tue, 26 Apr 2011 06:19:00 +0000 (UTC)
commit 8bc59a72eca178b103ef5d756003d8695576b9b8
Author: Mario Sanchez Prada <msanchez igalia com>
Date: Mon Apr 25 23:03:17 2011 -0700
Make the mainview model keep the original list of pictures as uploaded
Very helpful to make sure we can at any moment change the sorting
criteria back to the original one: as loaded.
src/frogr-main-view-model.c | 54 ++++++++++++++++++++++++++----------------
1 files changed, 33 insertions(+), 21 deletions(-)
---
diff --git a/src/frogr-main-view-model.c b/src/frogr-main-view-model.c
index 6934b99..fb51b78 100644
--- a/src/frogr-main-view-model.c
+++ b/src/frogr-main-view-model.c
@@ -38,8 +38,8 @@ typedef struct _FrogrMainViewModelPrivate FrogrMainViewModelPrivate;
struct _FrogrMainViewModelPrivate
{
GSList *pictures_list;
+ GSList *pictures_list_as_loaded;
guint n_pictures;
- gboolean pictures_list_reversed;
GSList *sets_list;
guint n_sets;
@@ -122,6 +122,12 @@ _frogr_main_view_model_dispose (GObject* object)
priv->pictures_list = NULL;
}
+ if (priv->pictures_list)
+ {
+ g_slist_free (priv->pictures_list_as_loaded);
+ priv->pictures_list_as_loaded = NULL;
+ }
+
if (priv->sets_list)
{
g_slist_foreach (priv->sets_list, (GFunc)g_object_unref, NULL);
@@ -204,8 +210,8 @@ frogr_main_view_model_init (FrogrMainViewModel *self)
/* Init private data */
priv->pictures_list = NULL;
+ priv->pictures_list_as_loaded = NULL;
priv->n_pictures = 0;
- priv->pictures_list_reversed = FALSE;
priv->sets_list = NULL;
priv->n_sets = 0;
@@ -240,6 +246,7 @@ frogr_main_view_model_add_picture (FrogrMainViewModel *self,
g_object_ref (picture);
priv->pictures_list = g_slist_append (priv->pictures_list, picture);
+ priv->pictures_list_as_loaded = g_slist_append (priv->pictures_list_as_loaded, picture);
priv->n_pictures++;
g_signal_emit (self, signals[PICTURE_ADDED], 0, picture);
@@ -255,6 +262,7 @@ frogr_main_view_model_remove_picture (FrogrMainViewModel *self,
FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
priv->pictures_list = g_slist_remove (priv->pictures_list, picture);
+ priv->pictures_list_as_loaded = g_slist_remove (priv->pictures_list_as_loaded, picture);
priv->n_pictures--;
g_object_unref (picture);
@@ -291,48 +299,52 @@ frogr_main_view_model_reorder_pictures (FrogrMainViewModel *self,
g_return_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self));
FrogrMainViewModelPrivate *priv = NULL;
- GSList *old_list = NULL;
- GSList *old_item = NULL;
+ GSList *list_as_loaded = NULL;
+ GSList *current_list = NULL;
+ GSList *current_item = NULL;
gint *new_order = 0;
- gint old_pos = 0;
+ gint current_pos = 0;
gint new_pos = 0;
priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
/* Temporarily save the current list, and alloc an array to
represent the new order compared to the old positions */
- old_list = g_slist_copy (priv->pictures_list);
- new_order = g_new0 (gint, g_slist_length (old_list));
+ current_list = g_slist_copy (priv->pictures_list);
+ new_order = g_new0 (gint, g_slist_length (current_list));
- /* If list was reversed, re-reverse it before sorting */
- if (priv->pictures_list_reversed)
- priv->pictures_list = g_slist_reverse (priv->pictures_list);
-
- priv->pictures_list_reversed = reversed;
+ /* Use the original list (as loaded) as reference for sorting */
+ list_as_loaded = g_slist_copy (priv->pictures_list_as_loaded);
+ /* Only sort if we have specified a property name */
if (property_name)
{
- /* Only sort if we have specified a property name */
- priv->pictures_list = g_slist_sort_with_data (priv->pictures_list,
- (GCompareDataFunc) _compare_pictures_by_property,
- (gchar*) property_name);
+ list_as_loaded = g_slist_sort_with_data (list_as_loaded,
+ (GCompareDataFunc) _compare_pictures_by_property,
+ (gchar*) property_name);
}
+ /* Update the list of pictures */
+ if (priv->pictures_list)
+ g_slist_free (priv->pictures_list);
+ priv->pictures_list = g_slist_copy (list_as_loaded);
+
/* If we're reordering in reverse order, reverse the result list */
if (reversed)
priv->pictures_list = g_slist_reverse (priv->pictures_list);
/* Build the new_order array */
- old_pos = 0;
- for (old_item = old_list; old_item; old_item = g_slist_next (old_item))
+ current_pos = 0;
+ for (current_item = current_list; current_item; current_item = g_slist_next (current_item))
{
- new_pos = g_slist_index (priv->pictures_list, old_item->data);
- new_order[new_pos] = old_pos++;
+ new_pos = g_slist_index (priv->pictures_list, current_item->data);
+ new_order[new_pos] = current_pos++;
}
g_signal_emit (self, signals[PICTURES_REORDERED], 0, new_order);
- g_slist_free (old_list);
+ g_slist_free (list_as_loaded);
+ g_slist_free (current_list);
g_free (new_order);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]