[epiphany/wip/bookmarks: 7/9] bookmarks-popover: Open bookmark on row click
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/bookmarks: 7/9] bookmarks-popover: Open bookmark on row click
- Date: Sat, 23 Jul 2016 21:30:34 +0000 (UTC)
commit d1b5e907a2047485ef2fd6acf34a32f698d78162
Author: Iulian Radu <iulian radu67 gmail com>
Date: Thu Jul 21 23:06:28 2016 +0300
bookmarks-popover: Open bookmark on row click
src/ephy-bookmark-row.c | 10 ++++-
src/ephy-bookmark-row.h | 2 +
src/ephy-bookmark.c | 38 ++++++++++------
src/ephy-bookmark.h | 2 +
src/ephy-bookmarks-manager.c | 6 +-
src/ephy-bookmarks-popover.c | 100 +++++++++++++++++++++++++++++++++++++++---
src/ephy-bookmarks-popover.h | 5 ++-
src/ephy-toolbar.c | 2 +-
8 files changed, 137 insertions(+), 28 deletions(-)
---
diff --git a/src/ephy-bookmark-row.c b/src/ephy-bookmark-row.c
index d30b7fb..a5b0fde 100644
--- a/src/ephy-bookmark-row.c
+++ b/src/ephy-bookmark-row.c
@@ -66,7 +66,7 @@ ephy_bookmark_row_get_property (GObject *object,
switch (prop_id)
{
case PROP_BOOKMARK:
- g_value_set_object (value, self->bookmark);
+ g_value_set_object (value, ephy_bookmark_row_get_bookmark (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -132,3 +132,11 @@ ephy_bookmark_row_new (EphyBookmark *bookmark)
"bookmark", bookmark,
NULL);
}
+
+EphyBookmark *
+ephy_bookmark_row_get_bookmark (EphyBookmarkRow *self)
+{
+ g_return_val_if_fail (EPHY_IS_BOOKMARK_ROW (self), NULL);
+
+ return self->bookmark;
+}
diff --git a/src/ephy-bookmark-row.h b/src/ephy-bookmark-row.h
index 7f16b7e..7201b04 100644
--- a/src/ephy-bookmark-row.h
+++ b/src/ephy-bookmark-row.h
@@ -30,6 +30,8 @@ G_DECLARE_FINAL_TYPE (EphyBookmarkRow, ephy_bookmark_row, EPHY, BOOKMARK_ROW, Gt
GtkWidget *ephy_bookmark_row_new (EphyBookmark *bookmark);
+EphyBookmark *ephy_bookmark_row_get_bookmark (EphyBookmarkRow *self);
+
G_END_DECLS
#endif /* _EPHY_BOOKMARK_ROW_H */
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index ec09336..43b9028 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -20,10 +20,10 @@
#include "ephy-bookmark.h"
struct _EphyBookmark {
- GObject parent_instance;
+ GObject parent_instance;
- char *url;
- char *title;
+ char *url;
+ char *title;
};
G_DEFINE_TYPE (EphyBookmark, ephy_bookmark, G_TYPE_OBJECT)
@@ -38,17 +38,6 @@ enum {
static GParamSpec *obj_properties[LAST_PROP];
static void
-ephy_bookmark_finalize (GObject *object)
-{
- EphyBookmark *self = EPHY_BOOKMARK (object);
-
- g_clear_pointer (&self->url, g_free);
- g_clear_pointer (&self->title, g_free);
-
- G_OBJECT_CLASS (ephy_bookmark_parent_class)->finalize (object);
-}
-
-static void
ephy_bookmark_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -81,7 +70,7 @@ ephy_bookmark_get_property (GObject *object,
g_value_set_string (value, self->title);
break;
case PROP_URL:
- g_value_set_string (value, self->url);
+ g_value_set_string (value, ephy_bookmark_get_url (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -89,6 +78,17 @@ ephy_bookmark_get_property (GObject *object,
}
static void
+ephy_bookmark_finalize (GObject *object)
+{
+ EphyBookmark *self = EPHY_BOOKMARK (object);
+
+ g_clear_pointer (&self->url, g_free);
+ g_clear_pointer (&self->title, g_free);
+
+ G_OBJECT_CLASS (ephy_bookmark_parent_class)->finalize (object);
+}
+
+static void
ephy_bookmark_class_init (EphyBookmarkClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -127,3 +127,11 @@ ephy_bookmark_new (char *url, char *title)
"title", title,
NULL);
}
+
+const char *
+ephy_bookmark_get_url (EphyBookmark *self)
+{
+ g_return_val_if_fail (EPHY_IS_BOOKMARK (self), NULL);
+
+ return self->url;
+}
\ No newline at end of file
diff --git a/src/ephy-bookmark.h b/src/ephy-bookmark.h
index 61233f6..f72a994 100644
--- a/src/ephy-bookmark.h
+++ b/src/ephy-bookmark.h
@@ -29,6 +29,8 @@ 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);
+
G_END_DECLS
#endif /* _EPHY_BOOKMARK_H */
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c
index 9392547..60d5998 100644
--- a/src/ephy-bookmarks-manager.c
+++ b/src/ephy-bookmarks-manager.c
@@ -64,7 +64,7 @@ void
ephy_bookmarks_manager_add_bookmark (EphyBookmarksManager *self,
EphyBookmark *bookmark)
{
- g_return_if_fail (EPHY_IS_BOOKMARKS_MANAGER (manager));
+ g_return_if_fail (EPHY_IS_BOOKMARKS_MANAGER (self));
g_return_if_fail (EPHY_IS_BOOKMARK (bookmark));
if (g_list_find (self->bookmarks, bookmark))
@@ -72,13 +72,13 @@ ephy_bookmarks_manager_add_bookmark (EphyBookmarksManager *self,
self->bookmarks = g_list_prepend (self->bookmarks, bookmark);
- g_signal_emit (manager, signals[BOOKMARK_ADDED], 0, bookmark);
+ g_signal_emit (self, signals[BOOKMARK_ADDED], 0, bookmark);
}
GList *
ephy_bookmarks_manager_get_bookmarks (EphyBookmarksManager *self)
{
- g_return_val_if_fail (EPHY_IS_BOOKMARKS_MANAGER (manager), NULL);
+ g_return_val_if_fail (EPHY_IS_BOOKMARKS_MANAGER (self), NULL);
return self->bookmarks;
}
diff --git a/src/ephy-bookmarks-popover.c b/src/ephy-bookmarks-popover.c
index 8fa2e6e..c5f3d91 100644
--- a/src/ephy-bookmarks-popover.c
+++ b/src/ephy-bookmarks-popover.c
@@ -15,10 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
+
+#include "ephy-bookmarks-popover.h"
+
#include "ephy-bookmark.h"
#include "ephy-bookmark-row.h"
#include "ephy-bookmarks-manager.h"
-#include "ephy-bookmarks-popover.h"
+#include "ephy-shell.h"
#include <glib/gi18n.h>
@@ -26,27 +30,105 @@ struct _EphyBookmarksPopover {
GtkPopover parent_instance;
GtkWidget *bookmarks_list_box;
+
+ EphyWindow *window;
};
G_DEFINE_TYPE (EphyBookmarksPopover, ephy_bookmarks_popover, GTK_TYPE_POPOVER)
+enum {
+ PROP_0,
+ PROP_WINDOW,
+ LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
static void
-bookmark_added_cb (EphyBookmarksPopover *popover,
+bookmark_added_cb (EphyBookmarksPopover *self,
EphyBookmark *bookmark)
{
GtkWidget *bookmark_row;
+ g_assert (EPHY_IS_BOOKMARKS_POPOVER (self));
+ g_assert (EPHY_IS_BOOKMARK (bookmark));
+
bookmark_row = ephy_bookmark_row_new (bookmark);
- gtk_list_box_prepend (GTK_LIST_BOX (popover->bookmarks_list_box), bookmark_row);
+ gtk_list_box_prepend (GTK_LIST_BOX (self->bookmarks_list_box), bookmark_row);
+}
+
+static void
+bookmarks_list_box_row_activated_cb (EphyBookmarksPopover *self,
+ EphyBookmarkRow *row,
+ GtkListBox *box)
+{
+ EphyBookmark *bookmark;
+ GActionGroup *action_group;
+ GAction *action;
+ const gchar *url;
+
+ g_assert (EPHY_IS_BOOKMARKS_POPOVER (self));
+ g_assert (EPHY_IS_BOOKMARK_ROW (row));
+ g_assert (GTK_IS_LIST_BOX (box));
+
+
+ action_group = gtk_widget_get_action_group (GTK_WIDGET (self->window), "win");
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "open-bookmark");
+
+ bookmark = ephy_bookmark_row_get_bookmark (row);
+ url = ephy_bookmark_get_url (bookmark);
+
+ g_action_activate (action, g_variant_new_string (url));
+}
+
+static void
+ephy_bookmarks_popover_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyBookmarksPopover *self = EPHY_BOOKMARKS_POPOVER (object);
+
+ switch (prop_id) {
+ case PROP_WINDOW:
+ self->window = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_bookmarks_popover_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
ephy_bookmarks_popover_class_init (EphyBookmarksPopoverClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ object_class->set_property = ephy_bookmarks_popover_set_property;
+ object_class->get_property = ephy_bookmarks_popover_get_property;
+
+ obj_properties[PROP_WINDOW] =
+ g_param_spec_object ("window",
+ "An EphyWindow object",
+ "The popover's parent EphyWindow",
+ EPHY_TYPE_WINDOW,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+
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);
}
@@ -58,7 +140,6 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
GList *bookmarks;
GList *l;
EphyBookmark *dummy_bookmark;
- GtkWidget *row;
gtk_widget_init_template (GTK_WIDGET (self));
@@ -74,17 +155,22 @@ ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
GtkWidget *bookmark_row;
bookmark_row = ephy_bookmark_row_new (bookmark);
- gtk_list_box_prepend (GTK_LIST_BOX (popover->bookmarks_list_box), bookmark_row);
+ gtk_list_box_prepend (GTK_LIST_BOX (self->bookmarks_list_box), bookmark_row);
}
g_signal_connect_object (manager, "bookmark-added",
G_CALLBACK (bookmark_added_cb),
- popover, G_CONNECT_SWAPPED);
+ self, G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (self->bookmarks_list_box, "row-activated",
+ G_CALLBACK (bookmarks_list_box_row_activated_cb),
+ self, G_CONNECT_SWAPPED);
}
EphyBookmarksPopover *
-ephy_bookmarks_popover_new (void)
+ephy_bookmarks_popover_new (EphyWindow *window)
{
return g_object_new (EPHY_TYPE_BOOKMARKS_POPOVER,
+ "window", window,
NULL);
}
diff --git a/src/ephy-bookmarks-popover.h b/src/ephy-bookmarks-popover.h
index f7be1c4..3cd2dd8 100644
--- a/src/ephy-bookmarks-popover.h
+++ b/src/ephy-bookmarks-popover.h
@@ -18,6 +18,8 @@
#ifndef EPHY_BOOKMARKS_POPOVER_H
#define EPHY_BOOKMARKS_POPOVER_H
+#include "ephy-window.h"
+
#include <gtk/gtk.h>
G_BEGIN_DECLS
@@ -26,7 +28,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EphyBookmarksPopover, ephy_bookmarks_popover, EPHY, BOOKMARKS_POPOVER, GtkPopover)
-EphyBookmarksPopover* ephy_bookmarks_popover_new (void);
+EphyBookmarksPopover* ephy_bookmarks_popover_new (EphyWindow *window);
+
G_END_DECLS
diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c
index cf59d09..e76a371 100644
--- a/src/ephy-toolbar.c
+++ b/src/ephy-toolbar.c
@@ -673,7 +673,7 @@ ephy_toolbar_constructed (GObject *object)
gtk_button_set_image (GTK_BUTTON (button),
gtk_image_new_from_icon_name ("user-bookmarks-symbolic", GTK_ICON_SIZE_BUTTON));
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
- gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), GTK_WIDGET (ephy_bookmarks_popover_new ()));
+ gtk_menu_button_set_popover (GTK_MENU_BUTTON (button), GTK_WIDGET (ephy_bookmarks_popover_new
(toolbar->window)));
gtk_header_bar_pack_end (GTK_HEADER_BAR (toolbar), button);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]