[epiphany/wip/bookmarks: 4/9] bookmarks: Add custom list box row



commit 444f2789744d91bbb4d2c8fe1ceffd500d534232
Author: Iulian Radu <iulian radu67 gmail com>
Date:   Sat Jul 23 23:25:08 2016 +0300

    bookmarks: Add custom list box row

 src/Makefile.am                   |    2 +
 src/ephy-bookmark-row.c           |  134 +++++++++++++++++++++++++++++++++++++
 src/ephy-bookmark-row.h           |   35 ++++++++++
 src/ephy-bookmark.c               |    2 +-
 src/ephy-bookmark.h               |    4 +-
 src/ephy-bookmarks-popover.c      |   16 ++++-
 src/epiphany.gresource.xml        |    1 +
 src/resources/gtk/bookmark-row.ui |   18 +++++
 8 files changed, 207 insertions(+), 5 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 9dd4021..a684398 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,6 +32,8 @@ libephymain_la_SOURCES = \
        ephy-action-helper.h                    \
        ephy-bookmark.c                         \
        ephy-bookmark.h                         \
+       ephy-bookmark-row.c                     \
+       ephy-bookmark-row.h                     \
        ephy-bookmarks-popover.c                \
        ephy-bookmarks-popover.h                \
        ephy-completion-model.c                 \
diff --git a/src/ephy-bookmark-row.c b/src/ephy-bookmark-row.c
new file mode 100644
index 0000000..d30b7fb
--- /dev/null
+++ b/src/ephy-bookmark-row.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2016 Iulian-Gabriel Radu <iulian radu67 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "ephy-bookmark-row.h"
+
+struct _EphyBookmarkRow {
+  GtkListBoxRow    parent_instance;
+
+  EphyBookmark    *bookmark;
+
+  GtkWidget       *title_label;
+};
+
+G_DEFINE_TYPE (EphyBookmarkRow, ephy_bookmark_row, GTK_TYPE_LIST_BOX_ROW)
+
+enum {
+  PROP_0,
+  PROP_BOOKMARK,
+  LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
+static void
+ephy_bookmark_row_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  EphyBookmarkRow *self = EPHY_BOOKMARK_ROW (object);
+
+  switch (prop_id)
+    {
+    case PROP_BOOKMARK:
+      self->bookmark = g_value_dup_object (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ephy_bookmark_row_get_property (GObject      *object,
+                                guint         prop_id,
+                                GValue       *value,
+                                GParamSpec   *pspec)
+{
+  EphyBookmarkRow *self = EPHY_BOOKMARK_ROW (object);
+
+  switch (prop_id)
+    {
+    case PROP_BOOKMARK:
+      g_value_set_object (value, self->bookmark);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+ephy_bookmark_row_dispose (GObject *object)
+{
+  EphyBookmarkRow *self = EPHY_BOOKMARK_ROW (object);
+
+  g_clear_object (&self->bookmark);
+
+  G_OBJECT_CLASS (ephy_bookmark_row_parent_class)->dispose (object);
+}
+
+static void
+ephy_bookmark_row_constructed (GObject *object)
+{
+  EphyBookmarkRow *self = EPHY_BOOKMARK_ROW (object);
+
+  g_object_bind_property (self->bookmark, "title",
+                          self->title_label, "label",
+                          G_BINDING_SYNC_CREATE);
+
+  G_OBJECT_CLASS (ephy_bookmark_row_parent_class)->constructed (object);
+}
+
+static void
+ephy_bookmark_row_class_init (EphyBookmarkRowClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->set_property = ephy_bookmark_row_set_property;
+  object_class->get_property = ephy_bookmark_row_get_property;
+  object_class->dispose = ephy_bookmark_row_dispose;
+  object_class->constructed = ephy_bookmark_row_constructed;
+
+  obj_properties[PROP_BOOKMARK] =
+    g_param_spec_object ("bookmark",
+                         "An EphyBookmark object",
+                         "The EphyBookmark shown by this widget",
+                         EPHY_TYPE_BOOKMARK,
+                         G_PARAM_READWRITE | 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/bookmark-row.ui");
+  gtk_widget_class_bind_template_child (widget_class, EphyBookmarkRow, title_label);
+}
+
+static void
+ephy_bookmark_row_init (EphyBookmarkRow *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+GtkWidget *
+ephy_bookmark_row_new (EphyBookmark *bookmark)
+{
+  return g_object_new (EPHY_TYPE_BOOKMARK_ROW,
+                       "bookmark", bookmark,
+                       NULL);
+}
diff --git a/src/ephy-bookmark-row.h b/src/ephy-bookmark-row.h
new file mode 100644
index 0000000..7f16b7e
--- /dev/null
+++ b/src/ephy-bookmark-row.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 Iulian-Gabriel Radu <iulian radu67 gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _EPHY_BOOKMARK_ROW_H
+#define _EPHY_BOOKMARK_ROW_H
+
+#include "ephy-bookmark.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_BOOKMARK_ROW (ephy_bookmark_row_get_type ())
+
+G_DECLARE_FINAL_TYPE (EphyBookmarkRow, ephy_bookmark_row, EPHY, BOOKMARK_ROW, GtkListBoxRow)
+
+GtkWidget           *ephy_bookmark_row_new            (EphyBookmark *bookmark);
+
+G_END_DECLS
+
+#endif /* _EPHY_BOOKMARK_ROW_H */
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index 3bebcd6..ec09336 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -120,7 +120,7 @@ ephy_bookmark_init (EphyBookmark *self)
 }
 
 EphyBookmark *
-ephy_bookmark_new (const char *url, const char *title)
+ephy_bookmark_new (char *url, char *title)
 {
   return g_object_new (EPHY_TYPE_BOOKMARK,
                        "url", url,
diff --git a/src/ephy-bookmark.h b/src/ephy-bookmark.h
index 2a6dbdf..61233f6 100644
--- a/src/ephy-bookmark.h
+++ b/src/ephy-bookmark.h
@@ -26,8 +26,8 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyBookmark, ephy_bookmark, EPHY, BOOKMARK, GObject)
 
-EphyBookmark        *ephy_bookmark_new          (const char *url,
-                                                 const char *title);
+EphyBookmark        *ephy_bookmark_new          (char *url,
+                                                 char *title);
 
 G_END_DECLS
 
diff --git a/src/ephy-bookmarks-popover.c b/src/ephy-bookmarks-popover.c
index a38e047..a10f953 100644
--- a/src/ephy-bookmarks-popover.c
+++ b/src/ephy-bookmarks-popover.c
@@ -15,12 +15,16 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <glib/gi18n.h>
-
+#include "ephy-bookmark.h"
+#include "ephy-bookmark-row.h"
 #include "ephy-bookmarks-popover.h"
 
+#include <glib/gi18n.h>
+
 struct _EphyBookmarksPopover {
   GtkPopover      parent_instance;
+
+  GtkWidget      *bookmarks_list_box;
 };
 
 G_DEFINE_TYPE (EphyBookmarksPopover, ephy_bookmarks_popover, GTK_TYPE_POPOVER)
@@ -31,12 +35,20 @@ ephy_bookmarks_popover_class_init (EphyBookmarksPopoverClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (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);
 }
 
 static void
 ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
 {
+  EphyBookmark *bookmark;
+  GtkWidget *row;
+
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  bookmark = ephy_bookmark_new (g_strdup ("https://duckduckgo.com";), g_strdup ("Test title"));
+  row = ephy_bookmark_row_new (bookmark);
+  gtk_list_box_insert (GTK_LIST_BOX (self->bookmarks_list_box), row, -1);
 }
 
 EphyBookmarksPopover *
diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml
index 5b5c32a..d913534 100644
--- a/src/epiphany.gresource.xml
+++ b/src/epiphany.gresource.xml
@@ -12,6 +12,7 @@
     <file preprocess="xml-stripblanks" compressed="true">history-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">passwords-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">shortcuts-dialog.ui</file>
+    <file preprocess="xml-stripblanks" compressed="true">gtk/bookmark-row.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">gtk/bookmarks-popover.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">gtk/menus.ui</file>
     <file preprocess="xml-stripblanks">epiphany-application-menu.ui</file>
diff --git a/src/resources/gtk/bookmark-row.ui b/src/resources/gtk/bookmark-row.ui
new file mode 100644
index 0000000..689924c
--- /dev/null
+++ b/src/resources/gtk/bookmark-row.ui
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.18 -->
+  <template class="EphyBookmarkRow" parent="GtkListBoxRow">
+    <property name="visible">true</property>
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">horizontal</property>
+        <property name="visible">true</property>
+        <child>
+          <object class="GtkLabel" id="title_label">
+            <property name="visible">true</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]