[epiphany] add-bookmark-popover: Save bookmark when popover is closed, not shown



commit bc07c2f3411854bcfafde8e8a9a4c189eaea071c
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Thu Mar 23 19:13:49 2017 +0200

    add-bookmark-popover: Save bookmark when popover is closed, not shown
    
    Fix bug 780443

 src/bookmarks/ephy-add-bookmark-popover.c |   51 +++++++++++++++++++++-------
 1 files changed, 38 insertions(+), 13 deletions(-)
---
diff --git a/src/bookmarks/ephy-add-bookmark-popover.c b/src/bookmarks/ephy-add-bookmark-popover.c
index 4ba209b..5042934 100644
--- a/src/bookmarks/ephy-add-bookmark-popover.c
+++ b/src/bookmarks/ephy-add-bookmark-popover.c
@@ -32,6 +32,8 @@ struct _EphyAddBookmarkPopover {
   GtkPopover     parent_instance;
 
   char          *address;
+  EphyBookmark  *bookmark;
+  gboolean       is_new_bookmark;
 
   GtkWidget     *grid;
   EphyHeaderBar *header_bar;
@@ -109,8 +111,37 @@ ephy_add_bookmark_popover_class_init (EphyAddBookmarkPopoverClass *klass)
 }
 
 static void
+ephy_add_bookmark_popover_closed_cb (GtkPopover *popover,
+                                     gpointer    user_data)
+{
+  EphyAddBookmarkPopover *self;
+  EphyBookmarksManager *manager;
+  GtkWidget *location_entry;
+
+  g_assert (EPHY_IS_ADD_BOOKMARK_POPOVER (popover));
+
+  self = EPHY_ADD_BOOKMARK_POPOVER (popover);
+  manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
+
+  if (self->is_new_bookmark) {
+    location_entry = GTK_WIDGET (ephy_header_bar_get_title_widget (self->header_bar));
+    ephy_bookmarks_manager_add_bookmark (manager, self->bookmark);
+    ephy_location_entry_set_bookmark_icon_state (EPHY_LOCATION_ENTRY (location_entry),
+                                                 EPHY_LOCATION_ENTRY_BOOKMARK_ICON_BOOKMARKED);
+    self->is_new_bookmark = FALSE;
+  } else {
+    ephy_bookmarks_manager_save_to_file_async (manager, NULL,
+                                               ephy_bookmarks_manager_save_to_file_warn_on_error_cb,
+                                               NULL);
+  }
+}
+
+static void
 ephy_add_bookmark_popover_init (EphyAddBookmarkPopover *self)
 {
+  g_signal_connect (self, "closed",
+                    G_CALLBACK (ephy_add_bookmark_popover_closed_cb),
+                    NULL);
 }
 
 GtkWidget *
@@ -172,28 +203,22 @@ void
 ephy_add_bookmark_popover_show (EphyAddBookmarkPopover *self)
 {
   EphyBookmarksManager *manager;
-  GtkWidget *location_entry;
   EphyWindow *window;
   EphyEmbed *embed;
-  EphyBookmark *bookmark;
   const char *address;
 
   manager = ephy_shell_get_bookmarks_manager (ephy_shell_get_default ());
-  location_entry = GTK_WIDGET (ephy_header_bar_get_title_widget (self->header_bar));
   window = ephy_header_bar_get_window (self->header_bar);
   embed = ephy_embed_container_get_active_child (EPHY_EMBED_CONTAINER (window));
 
   address = ephy_web_view_get_address (ephy_embed_get_web_view (embed));
 
-  bookmark = ephy_bookmarks_manager_get_bookmark_by_url (manager, address);
-  if (!bookmark) {
-    bookmark = ephy_bookmark_new (address,
-                                  ephy_embed_get_title (embed),
-                                  g_sequence_new (g_free));
-
-    ephy_bookmarks_manager_add_bookmark (manager, bookmark);
-    ephy_location_entry_set_bookmark_icon_state (EPHY_LOCATION_ENTRY (location_entry),
-                                                 EPHY_LOCATION_ENTRY_BOOKMARK_ICON_BOOKMARKED);
+  self->bookmark = ephy_bookmarks_manager_get_bookmark_by_url (manager, address);
+  if (!self->bookmark) {
+    self->bookmark = ephy_bookmark_new (address,
+                                        ephy_embed_get_title (embed),
+                                        g_sequence_new (g_free));
+    self->is_new_bookmark = TRUE;
   }
 
   g_signal_connect_object (manager, "bookmark-removed",
@@ -203,7 +228,7 @@ ephy_add_bookmark_popover_show (EphyAddBookmarkPopover *self)
 
   if (self->grid)
     gtk_widget_destroy (self->grid);
-  self->grid = ephy_bookmark_properties_grid_new (bookmark,
+  self->grid = ephy_bookmark_properties_grid_new (self->bookmark,
                                                   EPHY_BOOKMARK_PROPERTIES_GRID_TYPE_POPOVER,
                                                   GTK_WIDGET (self));
   gtk_container_add (GTK_CONTAINER (self), self->grid);


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