Merge lp:~aauzi/midori/fix-bookmarks-menu-update-regression into lp:midori

Proposed by André Auzi
Status: Merged
Approved by: Danielle Foré
Approved revision: 6577
Merged at revision: 6759
Proposed branch: lp:~aauzi/midori/fix-bookmarks-menu-update-regression
Merge into: lp:midori
Diff against target: 434 lines (+168/-43)
7 files modified
katze/katze-array.c (+53/-2)
katze/katze-arrayaction.c (+10/-0)
midori/midori-array.c (+4/-3)
midori/midori-bookmarks-db.c (+85/-13)
midori/midori-bookmarks-db.h (+3/-4)
midori/midori-browser.c (+12/-20)
panels/midori-bookmarks.c (+1/-1)
To merge this branch: bzr merge lp:~aauzi/midori/fix-bookmarks-menu-update-regression
Reviewer Review Type Date Requested Status
gue5t gue5t Approve
Cris Dywan Abstain
Review via email: mp+208491@code.launchpad.net

Commit message

bookmarks-db singleton was not completely connected to the application, as a result changes done in the panel were not properly propagated to the menu.

Additionnally import was not done in the database cache parent item, as a result the update of the root item, the dookmarks-db singleton, was not done.

Fix that.

Description of the change

The regression was already present in 0.5.7.

bookmarks-db singleton was not completely connected to the application, as a result changes done in the panel were not properly propagated to the menu.

Additionnally import was not done in the database cache parent item, as a result the update of the root item, the dookmarks-db singleton, was not done.

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

Please replace DEBUG_UPDATE with midori_debug("bookmarks") or a check for "bookmarks" being in MIDORI_DEBUG if the code cannot use the function (will need to move the API to a lower level some day), build-time debugging is not easily accessible to most users.

I'm a little bit surprised that midori_bookmarks_db_populate_folder is completely new here, surely there already was a way to enlist the items. Is there code that is too specialized?

review: Needs Fixing
Revision history for this message
André Auzi (aauzi) wrote :

> Please replace DEBUG_UPDATE with midori_debug("bookmarks") or a check for
> "bookmarks" being in MIDORI_DEBUG if the code cannot use the function (will
> need to move the API to a lower level some day), build-time debugging is not
> easily accessible to most users.

OK, I will change that

> I'm a little bit surprised that midori_bookmarks_db_populate_folder is
> completely new here, surely there already was a way to enlist the items.

As far as I can remember there was not.

Unless I missed something in the reverse engineering process, former midori_array_query_items_recursive was returning a freshly created array which wich was recursively populated, only when requested, with it's subfolders.

The recursion was the only point were the arrays were filled.

UI wigets were filled "on demand" without recursion and held the tree structure of the bookmarks database

The point was to avoid the creation of distinct arrays and I missed the fact that query_items_recursive did not fill the root array.

> Is there code that is too specialized?

Or maybe not specialized enough. I realize that midori_bookmarks_query_items_recursive maintains the lookup table of the cached item, it may as well insure that folder items are kept in sync.

In fact there are two use cases for bookmarks items.

1- The UI entries, where queries are done to fill UI widgets "on demand". They must be in cache to insure events propagation between widgets but the tree structure is in the widgets

2- The entries used for import and exports operations for which the tree structure is important.

So far midori_bookmarks_query_items_recursive serves the two purposes but we can imagine future distinction.

The fact is that UI items should be obsolescent when they're in a closed folder, this is not the case yet.

The import/export items may not be collected in the cache.

Revision history for this message
Eric Le Lay (neric27) wrote :

There is bug when exporting bookmarks twice: folder contents will get duplicated.
Duplication happens at "midori-bookmarks-db.c":959.
This renders the recursive use of midori_bookmarks_query_items_recursive unusable.

Revision history for this message
André Auzi (aauzi) wrote :

> There is bug when exporting bookmarks twice: folder contents will get
> duplicated.
> Duplication happens at "midori-bookmarks-db.c":959.
> This renders the recursive use of midori_bookmarks_query_items_recursive
> unusable.
Correct.
If I apply the same design pattern as I used for the folder import, the recursive import misses a
katze_array_clear (item)
before line 959

Thanks, Eric

6574. By André Auzi

merge lp:midori

6575. By André Auzi

merge lp:midori

6576. By André Auzi

fix duplication of entries in midori_bookmarks_db_query_recursive

6577. By André Auzi

use midori_debug("bookmarks") instead of DEBUG_UPDATE macro

Revision history for this message
Cris Dywan (kalikiana) wrote :

Thanks for the improvements. As usual, my review is a bit on the theoretical side. Maybe we can get another pair of eyes on it?

review: Abstain
Revision history for this message
gue5t gue5t (gue5t) wrote :

This does seem to get the bookmarks menu updating properly, and the code looks reasonable overally, though I'm not intimately familiar with the files changed. And it's probably better to have work on bookmarks landing than leaving branches out to bitrot.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'katze/katze-array.c'
2--- katze/katze-array.c 2014-03-02 20:05:17 +0000
3+++ katze/katze-array.c 2014-04-25 18:25:46 +0000
4@@ -33,6 +33,15 @@
5 GList* items;
6 };
7
8+enum
9+{
10+ PROP_0,
11+
12+ PROP_TYPE,
13+
14+ N_PROPERTIES
15+};
16+
17 enum {
18 ADD_ITEM,
19 REMOVE_ITEM,
20@@ -53,8 +62,19 @@
21 static void
22 _katze_array_update (KatzeArray* array)
23 {
24+/* FIXME: remove this declaration when midory_debug is made accessible */
25+ extern gboolean midori_debug (const gchar* token);
26+
27 g_object_set_data (G_OBJECT (array), "last-update",
28 GINT_TO_POINTER (time (NULL)));
29+ if (midori_debug ("bookmarks") && KATZE_IS_ITEM (array))
30+ {
31+ const gchar *name = katze_item_get_name (KATZE_ITEM (array));
32+ if (name && *name)
33+ {
34+ g_print ("_katze_array_update: %s\n", name);
35+ }
36+ }
37 }
38
39 static void
40@@ -105,6 +125,27 @@
41 }
42
43 static void
44+_katze_array_set_property (GObject *object,
45+ guint property_id,
46+ const GValue *value,
47+ GParamSpec *pspec)
48+{
49+ KatzeArray *array = KATZE_ARRAY (object);
50+
51+ switch (property_id)
52+ {
53+ case PROP_TYPE:
54+ array->priv->type = g_value_get_gtype (value);
55+ break;
56+
57+ default:
58+ /* We don't have any other property... */
59+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
60+ break;
61+ }
62+}
63+
64+static void
65 katze_array_class_init (KatzeArrayClass* class)
66 {
67 GObjectClass* gobject_class;
68@@ -187,6 +228,7 @@
69
70 gobject_class = G_OBJECT_CLASS (class);
71 gobject_class->finalize = katze_array_finalize;
72+ gobject_class->set_property = _katze_array_set_property;
73
74 class->add_item = _katze_array_add_item;
75 class->remove_item = _katze_array_remove_item;
76@@ -194,6 +236,16 @@
77 class->clear = _katze_array_clear;
78 class->update = _katze_array_update;
79
80+
81+ g_object_class_install_property (gobject_class,
82+ PROP_TYPE,
83+ g_param_spec_gtype (
84+ "type",
85+ "Type",
86+ "The array item type",
87+ G_TYPE_NONE,
88+ G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
89+
90 g_type_class_add_private (class, sizeof (KatzeArrayPrivate));
91 }
92
93@@ -238,8 +290,7 @@
94
95 g_return_val_if_fail (g_type_is_a (type, G_TYPE_OBJECT), NULL);
96
97- array = g_object_new (KATZE_TYPE_ARRAY, NULL);
98- array->priv->type = type;
99+ array = g_object_new (KATZE_TYPE_ARRAY, "type", type, NULL);
100
101 return array;
102 }
103
104=== modified file 'katze/katze-arrayaction.c'
105--- katze/katze-arrayaction.c 2013-12-26 17:41:17 +0000
106+++ katze/katze-arrayaction.c 2014-04-25 18:25:46 +0000
107@@ -815,12 +815,14 @@
108 KatzeArray* array)
109 {
110 GSList* proxies;
111+ KatzeArray *old_array = NULL;
112
113 g_return_if_fail (KATZE_IS_ARRAY_ACTION (array_action));
114 g_return_if_fail (!array || katze_array_is_a (array, KATZE_TYPE_ITEM));
115
116 /* FIXME: Disconnect old array */
117
118+ old_array = array_action->array;
119 if (array)
120 g_object_ref (array);
121 katze_object_assign (array_action->array, array);
122@@ -841,7 +843,15 @@
123
124 do
125 {
126+ KatzeArray* item = g_object_get_data (G_OBJECT (proxies->data), "KatzeItem");
127+
128+ if (item && (item == old_array))
129+ g_object_set_data (G_OBJECT (proxies->data), "KatzeItem", array);
130+
131 gtk_widget_set_sensitive (proxies->data, array != NULL);
132 }
133 while ((proxies = g_slist_next (proxies)));
134+
135+ if (array)
136+ katze_array_update (KATZE_ARRAY (array));
137 }
138
139=== modified file 'midori/midori-array.c'
140--- midori/midori-array.c 2013-08-05 19:52:52 +0000
141+++ midori/midori-array.c 2014-04-25 18:25:46 +0000
142@@ -1031,9 +1031,10 @@
143 || g_str_equal (name, "last_visit") || g_str_equal (name, "visit_count")
144 || g_str_equal (name, "pos_panel") || g_str_equal (name, "pos_bar"))
145 {
146- gint value;
147- value = sqlite3_column_int64 (stmt, column);
148- katze_item_set_meta_integer (item, name, value);
149+ /* use text to properly handle NULL values */
150+ const unsigned char* text;
151+ text = sqlite3_column_text (stmt, column);
152+ katze_item_set_meta_string (item, name, (gchar*)text);
153 }
154 else if (g_str_equal (name, "desc"))
155 {
156
157=== modified file 'midori/midori-bookmarks-db.c'
158--- midori/midori-bookmarks-db.c 2014-03-16 20:25:59 +0000
159+++ midori/midori-bookmarks-db.c 2014-04-25 18:25:46 +0000
160@@ -181,14 +181,27 @@
161 midori_bookmarks_db_get_item_parent (MidoriBookmarksDb* bookmarks,
162 gpointer item)
163 {
164+ gint64 parentid = katze_item_get_meta_integer (KATZE_ITEM (item), "parentid");
165+ KatzeItem *search = katze_item_new ();
166 KatzeArray* parent;
167- gint64 parentid;
168-
169- parentid = katze_item_get_meta_integer (KATZE_ITEM (item), "parentid");
170-
171- if (parentid == 0)
172+
173+ if (!parentid)
174+ {
175+ parentid = katze_item_get_meta_integer (KATZE_ITEM (bookmarks), "id");
176+ katze_item_set_meta_integer (KATZE_ITEM (item), "parentid", parentid);
177+ }
178+
179+ katze_item_set_meta_integer(search, "id", parentid);
180+
181+ parent = KATZE_ARRAY (g_hash_table_lookup (bookmarks->all_items, search));
182+
183+ g_object_unref (search);
184+
185+ if (!parent)
186 {
187 parent = KATZE_ARRAY (bookmarks);
188+ katze_item_set_meta_integer (KATZE_ITEM (item), "parentid",
189+ katze_item_get_meta_integer (KATZE_ITEM (bookmarks), "id"));
190 }
191 else
192 {
193@@ -238,12 +251,12 @@
194 return;
195 }
196
197- if (IS_MIDORI_BOOKMARKS_DB (parent))
198- KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->add_item (parent, item);
199- else if (KATZE_IS_ARRAY (parent))
200- katze_array_add_item (parent, item);
201+ if (IS_MIDORI_BOOKMARKS_DB (db_parent))
202+ KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->add_item (db_parent, item);
203+ else if (KATZE_IS_ARRAY (db_parent))
204+ katze_array_add_item (db_parent, item);
205
206- g_assert (parent == katze_item_get_parent (KATZE_ITEM (item)));
207+ g_assert (db_parent == katze_item_get_parent (KATZE_ITEM (item)));
208 }
209
210 /**
211@@ -267,7 +280,10 @@
212
213 g_return_if_fail (parent);
214
215- katze_array_update (parent);
216+ if (IS_MIDORI_BOOKMARKS_DB (parent))
217+ KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->update (parent);
218+ else
219+ katze_array_update (parent);
220 }
221
222 /**
223@@ -703,7 +719,7 @@
224 g_return_val_if_fail (errmsg != NULL, NULL);
225
226 database = midori_bookmarks_database_new (&error);
227-
228+
229 if (error != NULL)
230 {
231 *errmsg = g_strdup (error->message);
232@@ -714,7 +730,10 @@
233 db = midori_database_get_db (MIDORI_DATABASE (database));
234 g_return_val_if_fail (db != NULL, NULL);
235
236- bookmarks = MIDORI_BOOKMARKS_DB (g_object_new (TYPE_MIDORI_BOOKMARKS_DB, NULL));
237+ bookmarks = MIDORI_BOOKMARKS_DB (g_object_new (TYPE_MIDORI_BOOKMARKS_DB,
238+ "type", KATZE_TYPE_ITEM,
239+ NULL));
240+
241 bookmarks->db = db;
242
243 g_object_set_data (G_OBJECT (bookmarks), "db", db);
244@@ -926,6 +945,8 @@
245 KatzeItem* subitem;
246 GList* sublist;
247
248+ katze_array_clear (KATZE_ARRAY (item));
249+
250 KATZE_ARRAY_FOREACH_ITEM_L (subitem, subarray, sublist)
251 {
252 katze_array_add_item (KATZE_ARRAY (item), subitem);
253@@ -1087,3 +1108,54 @@
254 value, id,
255 recursive);
256 }
257+
258+/**
259+ * midori_bookmarks_db_populate_folder:
260+ **/
261+
262+void
263+midori_bookmarks_db_populate_folder (MidoriBookmarksDb* bookmarks,
264+ KatzeArray *folder)
265+{
266+ const gchar* id = katze_item_get_meta_string (KATZE_ITEM (folder), "id");
267+ const gchar *condition;
268+ KatzeArray* array;
269+ KatzeItem* item;
270+ GList* list;
271+
272+ if (id == NULL)
273+ {
274+ condition = "parentid is NULL";
275+ }
276+ else
277+ {
278+ condition = "parentid = %q";
279+ }
280+
281+ array = midori_bookmarks_db_query_recursive (bookmarks,
282+ "id, title, parentid, uri, app, pos_panel, pos_bar", condition, id, FALSE);
283+
284+ if (IS_MIDORI_BOOKMARKS_DB (folder))
285+ {
286+ KATZE_ARRAY_FOREACH_ITEM_L (item, folder, list)
287+ {
288+ KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->remove_item (folder, item);
289+ }
290+
291+ KATZE_ARRAY_FOREACH_ITEM_L (item, array, list)
292+ {
293+ KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->add_item (folder, item);
294+ }
295+ }
296+ else
297+ {
298+ katze_array_clear(folder);
299+
300+ KATZE_ARRAY_FOREACH_ITEM_L (item, array, list)
301+ {
302+ katze_array_add_item (folder, item);
303+ }
304+ }
305+
306+ g_object_unref (array);
307+}
308
309=== modified file 'midori/midori-bookmarks-db.h'
310--- midori/midori-bookmarks-db.h 2013-09-17 19:34:23 +0000
311+++ midori/midori-bookmarks-db.h 2014-04-25 18:25:46 +0000
312@@ -71,10 +71,9 @@
313 KatzeItem* folder,
314 gboolean recursive);
315
316-gint64
317-midori_bookmarks_insert_item_db (sqlite3* db,
318- KatzeItem* item,
319- gint64 parentid);
320+void
321+midori_bookmarks_db_populate_folder (MidoriBookmarksDb* bookmarks,
322+ KatzeArray *folder);
323
324 #endif /* !__MIDORI_BOOKMARKS_DB_H__ */
325
326
327=== modified file 'midori/midori-browser.c'
328--- midori/midori-browser.c 2014-04-16 21:00:49 +0000
329+++ midori/midori-browser.c 2014-04-25 18:25:46 +0000
330@@ -935,10 +935,10 @@
331 /* FIXME: here we should have the root bookmark array's name and id, not hard encoded values */
332
333 gtk_tree_store_insert_with_values (model, &tree_iter, NULL, G_MAXINT,
334- 0, _("Bookmarks"), 1, (gint64)0, -1);
335+ 0, _("Bookmarks"), 1, (gint64)-1, -1);
336 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &tree_iter);
337
338- current_parentid = 0;
339+ current_parentid = -1;
340 parent_iter = NULL;
341 n = 1;
342 while (g_list_first (folders))
343@@ -959,7 +959,7 @@
344 {
345 /* folder's parent is the stree store root */
346
347- current_parentid = 0;
348+ current_parentid = -1;
349 parent_iter = NULL;
350 }
351 else if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &tree_iter))
352@@ -1036,7 +1036,7 @@
353 static gint64
354 midori_bookmark_folder_button_get_active (GtkWidget* combo)
355 {
356- gint64 id = 0;
357+ gint64 id = -1;
358 GtkTreeIter iter;
359
360 g_return_val_if_fail (GTK_IS_COMBO_BOX (combo), 0);
361@@ -3178,29 +3178,17 @@
362 KatzeArray* folder,
363 MidoriBrowser* browser)
364 {
365- KatzeArray* bookmarks;
366- const gchar* id = katze_item_get_meta_string (KATZE_ITEM (folder), "id");
367- gchar* condition;
368-
369 if (browser->bookmarks == NULL)
370 return FALSE;
371
372- if (id == NULL)
373- condition = "parentid is NULL";
374- else
375- condition = "parentid = %q";
376-
377- bookmarks = midori_bookmarks_db_query_recursive (browser->bookmarks,
378- "id, title, parentid, uri, app, pos_panel, pos_bar", condition, id, FALSE);
379- if (!bookmarks)
380- return FALSE;
381+ midori_bookmarks_db_populate_folder (browser->bookmarks, folder);
382
383 /* Clear items from dummy array here */
384 gtk_container_foreach (GTK_CONTAINER (menu),
385 (GtkCallback)(gtk_widget_destroy), NULL);
386
387 /* "Import Bookmarks" and "Export Bookmarks" at the top */
388- if (id == NULL)
389+ if (folder == KATZE_ARRAY (browser->bookmarks))
390 {
391 GtkWidget* menuitem;
392 menuitem = gtk_action_create_menu_item (_action_by_name (browser, "BookmarksImport"));
393@@ -3214,7 +3202,7 @@
394 gtk_widget_show (menuitem);
395 }
396
397- if (katze_array_is_empty (bookmarks))
398+ if (katze_array_is_empty (folder))
399 {
400 GtkWidget* menuitem = gtk_image_menu_item_new_with_label (_("Empty"));
401 gtk_widget_set_sensitive (menuitem, FALSE);
402@@ -3223,7 +3211,7 @@
403 return TRUE;
404 }
405
406- katze_array_action_generate_menu (KATZE_ARRAY_ACTION (action), bookmarks,
407+ katze_array_action_generate_menu (KATZE_ARRAY_ACTION (action), folder,
408 menu, GTK_WIDGET (browser));
409 return TRUE;
410 }
411@@ -6820,6 +6808,10 @@
412 midori_bookmarkbar_remove_item_cb, browser);
413 }
414
415+ g_object_set (G_OBJECT (_action_by_name (browser, "Bookmarks")),
416+ "array", KATZE_ARRAY (bookmarks),
417+ NULL);
418+
419 settings = midori_browser_get_settings (browser);
420 g_signal_handlers_disconnect_by_func (settings,
421 midori_browser_show_bookmarkbar_notify_value_cb, browser);
422
423=== modified file 'panels/midori-bookmarks.c'
424--- panels/midori-bookmarks.c 2014-01-24 23:04:05 +0000
425+++ panels/midori-bookmarks.c 2014-04-25 18:25:46 +0000
426@@ -370,7 +370,7 @@
427 GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
428 GtkTreeIter iter;
429
430- if (!parentid)
431+ if (parentid == -1)
432 {
433 midori_bookmarks_add_item_to_model (GTK_TREE_STORE (model), NULL, item);
434 }

Subscribers

People subscribed via source and target branches

to all changes: