[epiphany/wip/bookmarks: 11/76] bookmarks-popover: Populate Tags stack
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/bookmarks: 11/76] bookmarks-popover: Populate Tags stack
- Date: Wed, 28 Sep 2016 13:17:43 +0000 (UTC)
commit ed73547278dedef8db5b4b8503e497f5228092cf
Author: Iulian Radu <iulian radu67 gmail com>
Date: Fri Jul 22 15:07:38 2016 +0300
bookmarks-popover: Populate Tags stack
src/ephy-bookmark.c | 11 +++++++++--
src/ephy-bookmark.h | 2 ++
src/ephy-bookmarks-manager.c | 27 +++++++++++++++++++++++++++
src/ephy-bookmarks-manager.h | 2 ++
src/ephy-bookmarks-popover.c | 34 ++++++++++++++++++++++++++++++++++
5 files changed, 74 insertions(+), 2 deletions(-)
---
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index 18f1caf..38ccaa4 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -133,8 +133,7 @@ ephy_bookmark_new (char *url, char *title)
}
const char *
-ephy_bookmark_get_url (EphyBookmark *self)
-{
+ephy_bookmark_get_url (EphyBookmark *self) {
g_return_val_if_fail (EPHY_IS_BOOKMARK (self), NULL);
return self->url;
@@ -147,3 +146,11 @@ ephy_bookmark_set_tags (EphyBookmark *self, GList *tags)
self->tags = tags;
}
+
+GList *
+ephy_bookmark_get_tags (EphyBookmark *self)
+{
+ g_return_val_if_fail (EPHY_IS_BOOKMARK (self), NULL);
+
+ return self->tags;
+}
diff --git a/src/ephy-bookmark.h b/src/ephy-bookmark.h
index a45cc00..9d5d279 100644
--- a/src/ephy-bookmark.h
+++ b/src/ephy-bookmark.h
@@ -29,9 +29,11 @@ G_DECLARE_FINAL_TYPE (EphyBookmark, ephy_bookmark, EPHY, BOOKMARK, GObject)
EphyBookmark *ephy_bookmark_new (char *url,
char *title);
+
const char *ephy_bookmark_get_url (EphyBookmark *self);
void ephy_bookmark_set_tags (EphyBookmark *self,
GList *tags);
+GList *ephy_bookmark_get_tags (EphyBookmark *self);
G_END_DECLS
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c
index 60d5998..9c3735c 100644
--- a/src/ephy-bookmarks-manager.c
+++ b/src/ephy-bookmarks-manager.c
@@ -82,3 +82,30 @@ ephy_bookmarks_manager_get_bookmarks (EphyBookmarksManager *self)
return self->bookmarks;
}
+
+GList *
+ephy_bookmarks_manager_get_tags (EphyBookmarksManager *self)
+{
+ GHashTable *tags_set;
+ GList *l;
+ GList *tags;
+
+ g_return_val_if_fail (EPHY_IS_BOOKMARKS_MANAGER (self), NULL);
+
+ tags_set = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ for (l = self->bookmarks; l != NULL; l = l->next) {
+ EphyBookmark *bookmark = EPHY_BOOKMARK (l->data);
+ GList *ll;
+
+ for (ll = ephy_bookmark_get_tags (bookmark); ll != NULL; ll = ll->next)
+ g_hash_table_add (tags_set, g_strdup (ll->data));
+ }
+
+ tags = g_list_copy_deep (g_hash_table_get_values (tags_set),
+ (GCopyFunc)g_strdup,
+ NULL);
+ g_hash_table_destroy (tags_set);
+
+ return tags;
+}
diff --git a/src/ephy-bookmarks-manager.h b/src/ephy-bookmarks-manager.h
index 7a859e2..55c90ff 100644
--- a/src/ephy-bookmarks-manager.h
+++ b/src/ephy-bookmarks-manager.h
@@ -28,7 +28,9 @@ G_DECLARE_FINAL_TYPE (EphyBookmarksManager, ephy_bookmarks_manager, EPHY, BOOKMA
void ephy_bookmarks_manager_add_bookmark (EphyBookmarksManager *self,
EphyBookmark *bookmark);
+
GList *ephy_bookmarks_manager_get_bookmarks (EphyBookmarksManager *self);
+GList *ephy_bookmarks_manager_get_tags (EphyBookmarksManager *manager);
G_END_DECLS
diff --git a/src/ephy-bookmarks-popover.c b/src/ephy-bookmarks-popover.c
index 86e53ac..e8862ac 100644
--- a/src/ephy-bookmarks-popover.c
+++ b/src/ephy-bookmarks-popover.c
@@ -30,6 +30,7 @@ struct _EphyBookmarksPopover {
GtkPopover parent_instance;
GtkWidget *bookmarks_list_box;
+ GtkWidget *tags_list_box;
EphyWindow *window;
};
@@ -82,6 +83,29 @@ bookmarks_list_box_row_activated_cb (EphyBookmarksPopover *self,
g_action_activate (action, g_variant_new_string (url));
}
+static GtkWidget *
+build_tag_box (const gchar *tag)
+{
+ GtkWidget *box;
+ GtkWidget *image;
+ GtkWidget *label;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_widget_set_halign (box, GTK_ALIGN_START);
+
+ image = gtk_image_new_from_icon_name ("user-bookmarks-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 6);
+ gtk_widget_show (image);
+
+ label = gtk_label_new (tag);
+ gtk_box_pack_start (GTK_BOX (box),label, TRUE, FALSE, 6);
+ gtk_widget_show (label);
+
+ gtk_widget_show (box);
+
+ return box;
+}
+
static void
ephy_bookmarks_popover_set_property (GObject *object,
guint prop_id,
@@ -131,6 +155,7 @@ ephy_bookmarks_popover_class_init (EphyBookmarksPopoverClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/epiphany/gtk/bookmarks-popover.ui");
gtk_widget_class_bind_template_child (widget_class, EphyBookmarksPopover, bookmarks_list_box);
+ gtk_widget_class_bind_template_child (widget_class, EphyBookmarksPopover, tags_list_box);
}
static void
@@ -162,6 +187,15 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
gtk_list_box_prepend (GTK_LIST_BOX (self->bookmarks_list_box), bookmark_row);
}
+ tags = ephy_bookmarks_manager_get_tags (manager);
+ for (l = tags; l != NULL; l = g_list_next (l)) {
+ GtkWidget *tag_box;
+ gchar *tag = (gchar *)l->data;
+
+ tag_box = build_tag_box (tag);
+ gtk_list_box_prepend (GTK_LIST_BOX (self->tags_list_box), tag_box);
+ }
+
g_signal_connect_object (manager, "bookmark-added",
G_CALLBACK (bookmark_added_cb),
self, G_CONNECT_SWAPPED);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]