[frogr] Add new tags added locally to the auto-completion feature (#658120)
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Add new tags added locally to the auto-completion feature (#658120)
- Date: Sun, 8 Apr 2012 01:02:35 +0000 (UTC)
commit 3285b31c74835ed3030c6373d98088bb5f07aea6
Author: Mario Sanchez Prada <msanchez igalia com>
Date: Sun Apr 8 02:58:58 2012 +0200
Add new tags added locally to the auto-completion feature (#658120)
From now on, if you add a new tag (that is, not existing in pictures
in flickr already) to a picture in frogr, this tag will be suggested
for the other pictures whose details are being edited.
https://bugzilla.gnome.org/show_bug.cgi?id=658120
src/frogr-add-tags-dialog.c | 14 +++-
src/frogr-controller.c | 6 +-
src/frogr-details-dialog.c | 13 +++
src/frogr-main-view-model.c | 192 ++++++++++++++++++++++++++++++++++++++-----
src/frogr-main-view-model.h | 21 ++++-
src/frogr-picture.c | 6 +-
6 files changed, 218 insertions(+), 34 deletions(-)
---
diff --git a/src/frogr-add-tags-dialog.c b/src/frogr-add-tags-dialog.c
index bd29ae6..25117b8 100644
--- a/src/frogr-add-tags-dialog.c
+++ b/src/frogr-add-tags-dialog.c
@@ -21,8 +21,11 @@
#include "frogr-add-tags-dialog.h"
#include "frogr-config.h"
+#include "frogr-controller.h"
#include "frogr-global-defs.h"
#include "frogr-live-entry.h"
+#include "frogr-main-view.h"
+#include "frogr-main-view-model.h"
#include "frogr-picture.h"
#include <config.h>
@@ -72,8 +75,10 @@ _dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
/* Check if there's something to add */
if (tags && !g_str_equal (tags, ""))
{
- FrogrPicture *picture;
- GSList *item;
+ FrogrMainView *mainview = NULL;
+ FrogrMainViewModel *model = NULL;
+ FrogrPicture *picture = NULL;
+ GSList *item = NULL;
DEBUG ("Adding tags to picture(s): %s", tags);
@@ -83,6 +88,11 @@ _dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
picture = FROGR_PICTURE (item->data);
frogr_picture_add_tags (picture, tags);
}
+
+ /* Add tags to the model */
+ mainview = frogr_controller_get_main_view (frogr_controller_get_instance ());
+ model = frogr_main_view_get_model (mainview);
+ frogr_main_view_model_add_local_tags_from_string (model, tags);
}
/* Free */
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index 2e28e60..f066195 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -1742,7 +1742,7 @@ _fetch_tags_cb (GObject *object, GAsyncResult *res, gpointer data)
/* Update main view's model */
mainview_model = frogr_main_view_get_model (priv->mainview);
- frogr_main_view_model_set_tags_list (mainview_model, tags_list);
+ frogr_main_view_model_set_remote_tags (mainview_model, tags_list);
priv->fetching_tags = FALSE;
}
@@ -1829,7 +1829,7 @@ _show_details_dialog_on_idle (GSList *pictures)
frogr_main_view_hide_progress (mainview);
mainview_model = frogr_main_view_get_model (priv->mainview);
- tags_list = frogr_main_view_model_get_tags_list (mainview_model);
+ tags_list = frogr_main_view_model_get_all_tags (mainview_model);
/* Sets already pre-fetched: show the dialog */
window = frogr_main_view_get_window (priv->mainview);
@@ -1859,7 +1859,7 @@ _show_add_tags_dialog_on_idle (GSList *pictures)
frogr_main_view_hide_progress (mainview);
mainview_model = frogr_main_view_get_model (priv->mainview);
- tags_list = frogr_main_view_model_get_tags_list (mainview_model);
+ tags_list = frogr_main_view_model_get_all_tags (mainview_model);
/* Sets already pre-fetched: show the dialog */
window = frogr_main_view_get_window (priv->mainview);
diff --git a/src/frogr-details-dialog.c b/src/frogr-details-dialog.c
index d7a9c84..1d472a7 100644
--- a/src/frogr-details-dialog.c
+++ b/src/frogr-details-dialog.c
@@ -25,6 +25,8 @@
#include "frogr-global-defs.h"
#include "frogr-gtk-compat.h"
#include "frogr-live-entry.h"
+#include "frogr-main-view.h"
+#include "frogr-main-view-model.h"
#include "frogr-picture.h"
#include "frogr-util.h"
@@ -987,6 +989,17 @@ _save_data (FrogrDetailsDialog *self)
/* Everything went fine */
result = TRUE;
}
+
+ /* Add tags to the model */
+ if (!g_str_equal (tags, ""))
+ {
+ FrogrMainView *mainview = NULL;
+ FrogrMainViewModel *model = NULL;
+
+ mainview = frogr_controller_get_main_view (frogr_controller_get_instance ());
+ model = frogr_main_view_get_model (mainview);
+ frogr_main_view_model_add_local_tags_from_string (model, tags);
+ }
}
else
{
diff --git a/src/frogr-main-view-model.c b/src/frogr-main-view-model.c
index 90ca404..b700b7e 100644
--- a/src/frogr-main-view-model.c
+++ b/src/frogr-main-view-model.c
@@ -45,8 +45,13 @@ struct _FrogrMainViewModelPrivate
GSList *groups_list;
guint n_groups;
- GSList *tags_list;
- guint n_tags;
+ GSList *remote_tags;
+ guint n_remote_tags;
+
+ GSList *local_tags;
+ guint n_local_tags;
+
+ GSList *all_tags;
};
/* Signals */
@@ -122,6 +127,40 @@ _compare_pictures_by_property (FrogrPicture *p1, FrogrPicture *p2,
return result;
}
+static GSList *
+_get_tags_list_from_string (const gchar *tags_string)
+{
+ GSList *tags_list = NULL;
+ gchar *stripped_tags = NULL;
+
+ if (!tags_string)
+ return NULL;
+
+ stripped_tags = g_strstrip (g_strdup (tags_string));
+ if (!g_str_equal (stripped_tags, ""))
+ {
+ gchar **tags_array = NULL;
+ gchar *tag;
+ gint i;
+
+ /* Now iterate over every token, adding it to the list */
+ tags_array = g_strsplit (stripped_tags, TAGS_DELIMITER, -1);
+ for (i = 0; tags_array[i]; i++)
+ {
+ /* add stripped tag if not already set*/
+ tag = g_strstrip(g_strdup (tags_array[i]));
+ if (!g_str_equal (tag, ""))
+ tags_list = g_slist_append (tags_list, tag);
+ }
+
+ /* Free */
+ g_strfreev (tags_array);
+ }
+ g_free (stripped_tags);
+
+ return tags_list;
+}
+
static void
_frogr_main_view_model_dispose (GObject* object)
{
@@ -155,11 +194,24 @@ _frogr_main_view_model_dispose (GObject* object)
priv->groups_list = NULL;
}
- if (priv->tags_list)
+ if (priv->remote_tags)
{
- g_slist_foreach (priv->tags_list, (GFunc)g_free, NULL);
- g_slist_free (priv->tags_list);
- priv->tags_list = NULL;
+ g_slist_foreach (priv->remote_tags, (GFunc)g_free, NULL);
+ g_slist_free (priv->remote_tags);
+ priv->remote_tags = NULL;
+ }
+
+ if (priv->local_tags)
+ {
+ g_slist_foreach (priv->local_tags, (GFunc)g_free, NULL);
+ g_slist_free (priv->local_tags);
+ priv->local_tags = NULL;
+ }
+
+ if (priv->all_tags)
+ {
+ g_slist_free (priv->all_tags);
+ priv->all_tags = NULL;
}
G_OBJECT_CLASS (frogr_main_view_model_parent_class)->dispose (object);
@@ -215,8 +267,13 @@ frogr_main_view_model_init (FrogrMainViewModel *self)
priv->groups_list = NULL;
priv->n_groups = 0;
- priv->tags_list = NULL;
- priv->n_tags = 0;
+ priv->remote_tags = NULL;
+ priv->n_remote_tags = 0;
+
+ priv->local_tags = NULL;
+ priv->n_local_tags = 0;
+
+ priv->all_tags = NULL;
}
/* Public API */
@@ -537,53 +594,146 @@ frogr_main_view_model_set_groups (FrogrMainViewModel *self,
}
GSList *
-frogr_main_view_model_get_tags_list (FrogrMainViewModel *self)
+frogr_main_view_model_get_remote_tags (FrogrMainViewModel *self)
{
FrogrMainViewModelPrivate *priv = NULL;
g_return_val_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self), NULL);
priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
- return priv->tags_list;
+ return priv->remote_tags;
}
void
-frogr_main_view_model_set_tags_list (FrogrMainViewModel *self, GSList *tags_list)
+frogr_main_view_model_set_remote_tags (FrogrMainViewModel *self, GSList *tags_list)
{
FrogrMainViewModelPrivate *priv = NULL;
g_return_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self));
- frogr_main_view_model_remove_all_tags (self);
+ frogr_main_view_model_remove_remote_tags (self);
+
+ priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
+ priv->remote_tags = tags_list;
+ priv->n_remote_tags = g_slist_length (tags_list);
+}
+
+void
+frogr_main_view_model_remove_remote_tags (FrogrMainViewModel *self)
+{
+ FrogrMainViewModelPrivate *priv = NULL;
+
+ g_return_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self));
+
+ priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
+
+ g_slist_foreach (priv->remote_tags, (GFunc)g_free, NULL);
+ g_slist_free (priv->remote_tags);
+
+ priv->remote_tags = NULL;
+ priv->n_remote_tags = 0;
+}
+
+guint
+frogr_main_view_model_n_remote_tags (FrogrMainViewModel *self)
+{
+ FrogrMainViewModelPrivate *priv = NULL;
+
+ g_return_val_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self), 0);
+
+ priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
+ return priv->n_remote_tags;
+}
+
+GSList *
+frogr_main_view_model_get_local_tags_list (FrogrMainViewModel *self)
+{
+ FrogrMainViewModelPrivate *priv = NULL;
+
+ g_return_val_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self), NULL);
priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
- priv->tags_list = tags_list;
- priv->n_tags = g_slist_length (tags_list);
+ return priv->local_tags;
}
void
-frogr_main_view_model_remove_all_tags (FrogrMainViewModel *self)
+frogr_main_view_model_add_local_tags_from_string (FrogrMainViewModel *self,
+ const gchar *tags_str)
{
FrogrMainViewModelPrivate *priv = NULL;
+ GSList *tags_list = NULL;
+ GSList *current = NULL;
g_return_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self));
priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
- g_slist_foreach (priv->tags_list, (GFunc)g_free, NULL);
- g_slist_free (priv->tags_list);
+ tags_list = _get_tags_list_from_string (tags_str);
+ for (current = tags_list; current; current = g_slist_next (current))
+ {
+ if (!g_slist_find_custom (priv->local_tags, current->data, (GCompareFunc)g_strcmp0))
+ {
+ priv->local_tags = g_slist_prepend (priv->local_tags, g_strdup ((const gchar *)current->data));
+ priv->n_local_tags++;
+ }
+ }
+ priv->local_tags = g_slist_sort (priv->local_tags, (GCompareFunc)g_strcmp0);
- priv->tags_list = NULL;
- priv->n_tags = 0;
+ g_slist_foreach (tags_list, (GFunc)g_free, NULL);
+ g_slist_free (tags_list);
+}
+
+void
+frogr_main_view_model_remove_local_tags (FrogrMainViewModel *self)
+{
+ FrogrMainViewModelPrivate *priv = NULL;
+
+ g_return_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self));
+
+ priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
+
+ g_slist_foreach (priv->local_tags, (GFunc)g_free, NULL);
+ g_slist_free (priv->local_tags);
+
+ priv->local_tags = NULL;
+ priv->n_local_tags = 0;
}
guint
-frogr_main_view_model_n_tags (FrogrMainViewModel *self)
+frogr_main_view_model_n_local_tags (FrogrMainViewModel *self)
+{
+ FrogrMainViewModelPrivate *priv = NULL;
+
+ g_return_val_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self), 0);
+
+ priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
+ return priv->n_local_tags;
+}
+
+GSList *
+frogr_main_view_model_get_all_tags (FrogrMainViewModel *self)
{
FrogrMainViewModelPrivate *priv = NULL;
+ GSList *list = NULL;
+ GSList *current = NULL;
g_return_val_if_fail(FROGR_IS_MAIN_VIEW_MODEL (self), 0);
priv = FROGR_MAIN_VIEW_MODEL_GET_PRIVATE (self);
- return priv->n_tags;
+
+ /* Copy the list of remote tags and add those locally added */
+ list = g_slist_copy (priv->remote_tags);
+ for (current = priv->local_tags; current; current = g_slist_next (current))
+ {
+ if (!g_slist_find_custom (list, current->data, (GCompareFunc)g_strcmp0))
+ list = g_slist_prepend (list, current->data);
+ }
+ list = g_slist_sort (list, (GCompareFunc)g_strcmp0);
+
+ /* Update internal pointers to the result list */
+ if (priv->all_tags)
+ g_slist_free (priv->all_tags);
+ priv->all_tags = list;
+
+ return priv->all_tags;
}
diff --git a/src/frogr-main-view-model.h b/src/frogr-main-view-model.h
index 1a29d19..4b982ea 100644
--- a/src/frogr-main-view-model.h
+++ b/src/frogr-main-view-model.h
@@ -94,14 +94,25 @@ GSList *frogr_main_view_model_get_groups (FrogrMainViewModel *self);
void frogr_main_view_model_set_groups (FrogrMainViewModel *self,
GSList *groups_list);
-GSList *frogr_main_view_model_get_tags_list (FrogrMainViewModel *self);
+GSList *frogr_main_view_model_get_remote_tags (FrogrMainViewModel *self);
-void frogr_main_view_model_set_tags_list (FrogrMainViewModel *self,
- GSList *tags_list);
+void frogr_main_view_model_set_remote_tags (FrogrMainViewModel *self,
+ GSList *tags_list);
-void frogr_main_view_model_remove_all_tags (FrogrMainViewModel *self);
+void frogr_main_view_model_remove_remote_tags (FrogrMainViewModel *self);
-guint frogr_main_view_model_n_tags (FrogrMainViewModel *self);
+guint frogr_main_view_model_n_remote_tags (FrogrMainViewModel *self);
+
+GSList *frogr_main_view_model_get_local_tags_list (FrogrMainViewModel *self);
+
+void frogr_main_view_model_add_local_tags_from_string (FrogrMainViewModel *self,
+ const gchar *tags_str);
+
+void frogr_main_view_model_remove_local_tags (FrogrMainViewModel *self);
+
+guint frogr_main_view_model_n_local_tags (FrogrMainViewModel *self);
+
+GSList *frogr_main_view_model_get_all_tags (FrogrMainViewModel *self);
G_END_DECLS
diff --git a/src/frogr-picture.c b/src/frogr-picture.c
index 32496b4..e9d12c1 100644
--- a/src/frogr-picture.c
+++ b/src/frogr-picture.c
@@ -86,7 +86,7 @@ enum {
/* Prototypes */
-static gboolean _tag_is_photoset (FrogrPicture *self, const gchar *tag);
+static gboolean _tag_is_set (FrogrPicture *self, const gchar *tag);
static void _add_tags_to_tags_list (FrogrPicture *self,
const gchar *tags_string);
static void _update_tags_string (FrogrPicture *self);
@@ -94,7 +94,7 @@ static void _update_tags_string (FrogrPicture *self);
/* Private API */
static gboolean
-_tag_is_photoset (FrogrPicture *self, const gchar *tag)
+_tag_is_set (FrogrPicture *self, const gchar *tag)
{
FrogrPicturePrivate *priv = FROGR_PICTURE_GET_PRIVATE (self);
GSList *item;
@@ -134,7 +134,7 @@ _add_tags_to_tags_list (FrogrPicture *self,
{
/* add stripped tag if not already set*/
tag = g_strstrip(g_strdup (tags_array[i]));
- if (!g_str_equal (tag, "") && !_tag_is_photoset (self, tag))
+ if (!g_str_equal (tag, "") && !_tag_is_set (self, tag))
priv->tags_list = g_slist_append (priv->tags_list, tag);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]