diff options
author | Iulian Radu <iulian.radu67@gmail.com> | 2016-07-19 13:55:52 +0300 |
---|---|---|
committer | Iulian Radu <iulian.radu67@gmail.com> | 2016-09-28 16:15:13 +0300 |
commit | 37cbdaa1a641b6364071228da6d9f1858ca92de5 (patch) | |
tree | 67b6d06ad48e48f20588bf70ccb62ece4c836534 /src | |
parent | 1253b96c103bf49db6eba3153ad0e94b1868cbec (diff) | |
download | epiphany-37cbdaa1a641b6364071228da6d9f1858ca92de5.tar.gz |
bookmarks: Add EphyBookmarksManager
Diffstat (limited to 'src')
-rw-r--r-- | src/ephy-bookmarks-manager.c | 84 | ||||
-rw-r--r-- | src/ephy-bookmarks-manager.h | 35 | ||||
-rw-r--r-- | src/ephy-bookmarks-popover.c | 39 | ||||
-rw-r--r-- | src/ephy-shell.c | 20 | ||||
-rw-r--r-- | src/ephy-shell.h | 3 | ||||
-rw-r--r-- | src/ephy-window.c | 2 | ||||
-rw-r--r-- | src/ephy-window.h | 1 |
7 files changed, 180 insertions, 4 deletions
diff --git a/src/ephy-bookmarks-manager.c b/src/ephy-bookmarks-manager.c new file mode 100644 index 000000000..93925476e --- /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 000000000..7a859e2c4 --- /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 a10f95334..8fa2e6ee7 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 eedcf5605..667e6594c 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -55,6 +55,7 @@ struct _EphyShell { GList *windows; GObject *lockdown; EphyBookmarks *bookmarks; + EphyBookmarksManager *bookmarks_manager; GNetworkMonitor *network_monitor; GtkWidget *bme; GtkWidget *history_window; @@ -757,6 +758,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 1bd29d144..25f011777 100644 --- a/src/ephy-shell.h +++ b/src/ephy-shell.h @@ -21,6 +21,7 @@ #pragma once #include "ephy-bookmarks.h" +#include "ephy-bookmarks-manager.h" #include "ephy-embed-shell.h" #include "ephy-embed.h" #include "ephy-session.h" @@ -101,6 +102,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 f449a746f..205fe90a0 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -136,6 +136,7 @@ struct _EphyWindow { GtkApplicationWindow parent_instance; GtkWidget *header_bar; + EphyBookmarksManager *bookmarks_manager; GHashTable *action_labels; GtkNotebook *notebook; EphyEmbed *active_embed; @@ -2601,6 +2602,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 2297093f0..905541ba4 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -18,6 +18,7 @@ #pragma once +#include "ephy-bookmarks-manager.h" #include "ephy-web-view.h" #include <gtk/gtk.h> |