[epiphany/wip/bookmarks: 6/9] bookmarks: Add EphyBookmarksManager
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/bookmarks: 6/9] bookmarks: Add EphyBookmarksManager
- Date: Sat, 23 Jul 2016 21:30:29 +0000 (UTC)
commit 809654e736878ad4b61fd79637ae6167f06f538f
Author: Iulian Radu <iulian radu67 gmail com>
Date: Tue Jul 19 13:55:52 2016 +0300
bookmarks: Add EphyBookmarksManager
src/Makefile.am | 8 ++++
src/ephy-bookmarks-manager.c | 84 ++++++++++++++++++++++++++++++++++++++++++
src/ephy-bookmarks-manager.h | 35 +++++++++++++++++
src/ephy-bookmarks-popover.c | 39 +++++++++++++++++--
src/ephy-shell.c | 20 ++++++++++
src/ephy-shell.h | 3 +
src/ephy-window.c | 2 +
src/ephy-window.h | 1 +
8 files changed, 188 insertions(+), 4 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 621223d..47f28a0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,6 +24,14 @@ TYPES_H_FILES = \
$(NULL)
libephymain_la_SOURCES = \
+ ephy-bookmark.c \
+ ephy-bookmark.h \
+ ephy-bookmark-row.c \
+ ephy-bookmark-row.h \
+ ephy-bookmarks-manager.c \
+ ephy-bookmarks-manager.h \
+ ephy-bookmarks-popover.c \
+ ephy-bookmarks-popover.h \
clear-data-dialog.c \
clear-data-dialog.h \
cookies-dialog.c \
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c
new file mode 100644
index 0000000..9392547
--- /dev/null
+++ b/src/ephy-bookmarks-manager.c
@@ -0,0 +1,84 @@
+/*
+ * 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-bookmarks-manager.h"
+
+#include "ephy-file-helpers.h"
+
+#define EPHY_BOOKMARKS_FILE "bookmarks.gvdb"
+
+struct _EphyBookmarksManager {
+ GObject parent_instance;
+
+ GList *bookmarks;
+
+ gchar *gvdb_file;
+};
+
+G_DEFINE_TYPE (EphyBookmarksManager, ephy_bookmarks_manager, G_TYPE_OBJECT)
+
+enum {
+ BOOKMARK_ADDED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+static void
+ephy_bookmarks_manager_class_init (EphyBookmarksManagerClass *klass)
+{
+ signals[BOOKMARK_ADDED] =
+ g_signal_new ("bookmark-added",
+ EPHY_TYPE_BOOKMARKS_MANAGER,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 1,
+ EPHY_TYPE_BOOKMARK);
+}
+
+static void
+ephy_bookmarks_manager_init (EphyBookmarksManager *self)
+{
+ self->gvdb_file = g_build_filename (ephy_dot_dir (),
+ EPHY_BOOKMARKS_FILE,
+ NULL);
+}
+
+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_BOOKMARK (bookmark));
+
+ if (g_list_find (self->bookmarks, bookmark))
+ return;
+
+ self->bookmarks = g_list_prepend (self->bookmarks, bookmark);
+
+ g_signal_emit (manager, signals[BOOKMARK_ADDED], 0, bookmark);
+}
+
+GList *
+ephy_bookmarks_manager_get_bookmarks (EphyBookmarksManager *self)
+{
+ g_return_val_if_fail (EPHY_IS_BOOKMARKS_MANAGER (manager), NULL);
+
+ return self->bookmarks;
+}
diff --git a/src/ephy-bookmarks-manager.h b/src/ephy-bookmarks-manager.h
new file mode 100644
index 0000000..7a859e2
--- /dev/null
+++ b/src/ephy-bookmarks-manager.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_BOOKMARKS_MANAGER_H
+#define EPHY_BOOKMARKS_MANAGER_H
+
+#include "ephy-bookmark.h"
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_BOOKMARKS_MANAGER (ephy_bookmarks_manager_get_type ())
+
+G_DECLARE_FINAL_TYPE (EphyBookmarksManager, ephy_bookmarks_manager, EPHY, BOOKMARKS_MANAGER, GObject)
+
+void ephy_bookmarks_manager_add_bookmark (EphyBookmarksManager *self,
+ EphyBookmark *bookmark);
+GList *ephy_bookmarks_manager_get_bookmarks (EphyBookmarksManager *self);
+
+G_END_DECLS
+
+#endif /* EPHY_BOOKMARKS_MANAGER_H */
diff --git a/src/ephy-bookmarks-popover.c b/src/ephy-bookmarks-popover.c
index a10f953..8fa2e6e 100644
--- a/src/ephy-bookmarks-popover.c
+++ b/src/ephy-bookmarks-popover.c
@@ -17,6 +17,7 @@
#include "ephy-bookmark.h"
#include "ephy-bookmark-row.h"
+#include "ephy-bookmarks-manager.h"
#include "ephy-bookmarks-popover.h"
#include <glib/gi18n.h>
@@ -29,6 +30,18 @@ struct _EphyBookmarksPopover {
G_DEFINE_TYPE (EphyBookmarksPopover, ephy_bookmarks_popover, GTK_TYPE_POPOVER)
+
+static void
+bookmark_added_cb (EphyBookmarksPopover *popover,
+ EphyBookmark *bookmark)
+{
+ GtkWidget *bookmark_row;
+
+ bookmark_row = ephy_bookmark_row_new (bookmark);
+
+ gtk_list_box_prepend (GTK_LIST_BOX (popover->bookmarks_list_box), bookmark_row);
+}
+
static void
ephy_bookmarks_popover_class_init (EphyBookmarksPopoverClass *klass)
{
@@ -41,14 +54,32 @@ ephy_bookmarks_popover_class_init (EphyBookmarksPopoverClass *klass)
static void
ephy_bookmarks_popover_init (EphyBookmarksPopover *self)
{
- EphyBookmark *bookmark;
+ EphyBookmarksManager *manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
+ GList *bookmarks;
+ GList *l;
+ EphyBookmark *dummy_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);
+ dummy_bookmark = ephy_bookmark_new (g_strdup ("https://duckduckgo.com"), g_strdup ("Test title"));
+ ephy_bookmarks_manager_add_bookmark (manager, dummy_bookmark);
+
+ dummy_bookmark = ephy_bookmark_new (g_strdup ("https://wikipedia.com"), g_strdup ("wikipedia"));
+ ephy_bookmarks_manager_add_bookmark (manager, dummy_bookmark);
+
+ bookmarks = ephy_bookmarks_manager_get_bookmarks (manager);
+ for (l = bookmarks; l != NULL; l = g_list_next (l)) {
+ EphyBookmark *bookmark = (EphyBookmark *)l->data;
+ GtkWidget *bookmark_row;
+
+ bookmark_row = ephy_bookmark_row_new (bookmark);
+ gtk_list_box_prepend (GTK_LIST_BOX (popover->bookmarks_list_box), bookmark_row);
+ }
+
+ g_signal_connect_object (manager, "bookmark-added",
+ G_CALLBACK (bookmark_added_cb),
+ popover, G_CONNECT_SWAPPED);
}
EphyBookmarksPopover *
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 7a5ff1e..7c51744 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -52,6 +52,7 @@ struct _EphyShell {
GList *windows;
GObject *lockdown;
EphyBookmarks *bookmarks;
+ EphyBookmarksManager *bookmarks_manager;
GNetworkMonitor *network_monitor;
GtkWidget *bme;
GtkWidget *history_window;
@@ -744,6 +745,25 @@ ephy_shell_get_bookmarks (EphyShell *shell)
}
/**
+ * ephy_shell_get_bookmarks_manager:
+ * @shell: the #EphyShell
+ *
+ * Returns bookmarks manager.
+ *
+ * Return value: (transfer none): An #EphyBookmarksManager.
+ */
+EphyBookmarksManager *
+ephy_shell_get_bookmarks_manager (EphyShell *shell)
+{
+ g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL);
+
+ if (shell->bookmarks_manager == NULL)
+ shell->bookmarks_manager = EPHY_BOOKMARKS_MANAGER (g_object_new (EPHY_TYPE_BOOKMARKS_MANAGER, NULL));
+
+ return shell->bookmarks_manager;
+}
+
+/**
* ephy_shell_get_net_monitor:
*
* Return value: (transfer none):
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index f06bbdc..9ce4487 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -22,6 +22,7 @@
#define EPHY_SHELL_H
#include "ephy-bookmarks.h"
+#include "ephy-bookmarks-manager.h"
#include "ephy-embed-shell.h"
#include "ephy-embed.h"
#include "ephy-session.h"
@@ -102,6 +103,8 @@ EphyBookmarks *ephy_shell_get_bookmarks (EphyShell *shell);
GtkWidget *ephy_shell_get_bookmarks_editor (EphyShell *shell);
+EphyBookmarksManager *ephy_shell_get_bookmarks_manager (EphyShell *shell);
+
GtkWidget *ephy_shell_get_history_window (EphyShell *shell);
GObject *ephy_shell_get_prefs_dialog (EphyShell *shell);
diff --git a/src/ephy-window.c b/src/ephy-window.c
index b01644e..4621be3 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -139,6 +139,7 @@ struct _EphyWindow {
GtkWidget *toolbar;
GtkUIManager *manager;
+ EphyBookmarksManager *bookmarks_manager;
GHashTable *action_labels;
GtkNotebook *notebook;
EphyEmbed *active_embed;
@@ -2620,6 +2621,7 @@ ephy_window_dispose (GObject *object)
_ephy_window_set_context_event (window, NULL);
+ g_clear_object (&window->bookmarks_manager);
g_clear_object (&window->hit_test_result);
g_hash_table_unref (window->action_labels);
diff --git a/src/ephy-window.h b/src/ephy-window.h
index f2a3199..c934215 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -18,6 +18,7 @@
#ifndef EPHY_WINDOW_H
#define EPHY_WINDOW_H
+#include "ephy-bookmarks-manager.h"
#include "ephy-web-view.h"
#include <gtk/gtk.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]