Merge lp:~aauzi/midori/fix-1179200-8 into lp:midori

Proposed by André Auzi
Status: Merged
Approved by: Cris Dywan
Approved revision: 6332
Merged at revision: 6546
Proposed branch: lp:~aauzi/midori/fix-1179200-8
Merge into: lp:midori
Diff against target: 373 lines (+262/-27)
2 files modified
panels/midori-bookmarks.c (+262/-23)
panels/midori-bookmarks.h (+0/-4)
To merge this branch: bzr merge lp:~aauzi/midori/fix-1179200-8
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Review via email: mp+186413@code.launchpad.net

Commit message

Add helper callbacks to modify bookmark's tree store with unneded access to bookmarks db

Description of the change

Eigth step for merge of fix-1179200

We're almost done.

This step already avoids the problem reported in fix-1179200.

It implements add-item, update-item and remove-item callbacks that browse the tree store in order to add, move or remove the item without accesses to the database.

Read of the database is basically reserved to initial update and tree branch expansion.

To post a comment you must log in.
Revision history for this message
André Auzi (aauzi) wrote :

Updated to stay in sync with lp:midori.

Additionnally, this step becomes independent of step 7 which adds database transactions.

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

Nice!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'panels/midori-bookmarks.c'
2--- panels/midori-bookmarks.c 2013-10-25 21:49:56 +0000
3+++ panels/midori-bookmarks.c 2014-01-24 23:43:21 +0000
4@@ -88,9 +88,38 @@
5 GParamSpec* pspec);
6
7 static void
8+midori_bookmarks_row_changed_cb (GtkTreeModel* model,
9+ GtkTreePath* path,
10+ GtkTreeIter* iter,
11+ MidoriBookmarks* bookmarks);
12+
13+static void
14+midori_bookmarks_add_item_cb (KatzeArray* array,
15+ KatzeItem* item,
16+ MidoriBookmarks* bookmarks);
17+
18+static void
19+midori_bookmarks_update_item_cb (KatzeArray* array,
20+ KatzeItem* item,
21+ MidoriBookmarks* bookmarks);
22+
23+static void
24+midori_bookmarks_remove_item_cb (KatzeArray* array,
25+ KatzeItem* item,
26+ MidoriBookmarks* bookmarks);
27+
28+static void
29+midori_bookmarks_update_cb (KatzeArray* array,
30+ MidoriBookmarks* bookmarks);
31+
32+static void
33 midori_bookmarks_statusbar_update (MidoriBookmarks *bookmarks);
34
35 static void
36+midori_bookmarks_add_item (KatzeItem* item,
37+ MidoriBookmarks* bookmarks);
38+
39+static void
40 midori_bookmarks_class_init (MidoriBookmarksClass* class)
41 {
42 GObjectClass* gobject_class;
43@@ -216,16 +245,207 @@
44 g_object_unref (item);
45 }
46
47+static gboolean
48+midori_bookmarks_reach_item_recurse (GtkTreeModel* model,
49+ GtkTreeIter* iter,
50+ gint64 id)
51+{
52+ do
53+ {
54+ GtkTreeIter child;
55+ KatzeItem *item;
56+ gint64 itemid = -1;
57+
58+ gtk_tree_model_get (model, iter, 0, &item, -1);
59+
60+ if (!KATZE_ITEM_IS_SEPARATOR(item))
61+ {
62+ itemid = katze_item_get_meta_integer (item, "id");
63+ g_object_unref (item);
64+ }
65+
66+ if (id == itemid)
67+ return TRUE;
68+
69+ if (gtk_tree_model_iter_children (model, &child, iter))
70+ {
71+ if (midori_bookmarks_reach_item_recurse (model, &child, id))
72+ {
73+ *iter = child;
74+ return TRUE;
75+ }
76+ }
77+ }
78+ while (gtk_tree_model_iter_next(model, iter));
79+
80+ return FALSE;
81+}
82+
83+static gboolean
84+midori_bookmarks_reach_item (GtkTreeModel* model,
85+ GtkTreeIter* iter,
86+ gint64 id)
87+{
88+ if (!gtk_tree_model_get_iter_first(model, iter))
89+ return FALSE;
90+
91+ return midori_bookmarks_reach_item_recurse (model, iter, id);
92+}
93+
94+static void
95+midori_bookmarks_add_item_to_model(GtkTreeStore* model,
96+ GtkTreeIter* parent,
97+ KatzeItem* item)
98+{
99+ if (KATZE_ITEM_IS_BOOKMARK (item))
100+ {
101+ gchar* tooltip = g_markup_escape_text (katze_item_get_uri (item), -1);
102+
103+ gtk_tree_store_insert_with_values (model, NULL, parent,
104+ 0,
105+ 0, item, 1, tooltip, -1);
106+ g_free (tooltip);
107+ }
108+ else
109+ {
110+ GtkTreeIter root_iter;
111+
112+ gtk_tree_store_insert_with_values (model, &root_iter, parent,
113+ 0, 0, item, -1);
114+
115+ /* That's an invisible dummy, so we always have an expander */
116+ gtk_tree_store_insert_with_values (model, NULL, &root_iter,
117+ 0,
118+ 0, NULL, -1);
119+ }
120+}
121+
122+static void
123+midori_bookmarks_update_item_in_model(MidoriBookmarks* bookmarks,
124+ GtkTreeStore* model,
125+ GtkTreeIter* iter,
126+ KatzeItem* item)
127+{
128+ g_signal_handlers_block_by_func (model,
129+ midori_bookmarks_row_changed_cb,
130+ bookmarks);
131+
132+ if (KATZE_ITEM_IS_BOOKMARK (item))
133+ {
134+ gchar* tooltip = g_markup_escape_text (katze_item_get_uri (item), -1);
135+
136+ gtk_tree_store_set(model, iter,
137+ 0, item, 1, tooltip, -1);
138+
139+ g_free (tooltip);
140+ }
141+ else
142+ {
143+ gtk_tree_store_set(model, iter,
144+ 0, item, -1);
145+ }
146+
147+ g_signal_handlers_unblock_by_func (model,
148+ midori_bookmarks_row_changed_cb,
149+ bookmarks);
150+}
151+
152+static void
153+midori_bookmarks_add_item (KatzeItem* item,
154+ MidoriBookmarks* bookmarks);
155 static void
156 midori_bookmarks_add_item_cb (KatzeArray* array,
157 KatzeItem* item,
158 MidoriBookmarks* bookmarks)
159 {
160- GtkTreeModel* model;
161- model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
162- gtk_tree_store_clear (GTK_TREE_STORE (model));
163- midori_bookmarks_read_from_db_to_model (bookmarks,
164- GTK_TREE_STORE (model), NULL, 0, bookmarks->filter);
165+ midori_bookmarks_add_item (item, bookmarks);
166+}
167+
168+
169+static void
170+midori_bookmarks_add_item (KatzeItem* item,
171+ MidoriBookmarks* bookmarks)
172+{
173+ gint64 parentid = katze_item_get_meta_integer (item, "parentid");
174+ GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
175+ GtkTreeIter iter;
176+
177+ if (!parentid)
178+ {
179+ midori_bookmarks_add_item_to_model (GTK_TREE_STORE (model), NULL, item);
180+ }
181+ else if (midori_bookmarks_reach_item (model, &iter, parentid))
182+ {
183+ GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
184+
185+ if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (bookmarks->treeview), path))
186+ {
187+ midori_bookmarks_add_item_to_model (GTK_TREE_STORE (model), &iter, item);
188+ }
189+
190+ gtk_tree_path_free (path);
191+ }
192+}
193+
194+static void
195+midori_bookmarks_update_item_cb (KatzeArray* array,
196+ KatzeItem* item,
197+ MidoriBookmarks* bookmarks)
198+{
199+ gint64 id = katze_item_get_meta_integer (item, "id");
200+ gint64 parentid = katze_item_get_meta_integer (item, "parentid");
201+ GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
202+ GtkTreeIter iter;
203+
204+ if (midori_bookmarks_reach_item (model, &iter, id))
205+ {
206+ gint64 old_parentid = 0;
207+ GtkTreeIter parent;
208+
209+ if (gtk_tree_model_iter_parent (model, &parent, &iter))
210+ {
211+ KatzeItem* old_parent;
212+
213+ gtk_tree_model_get (model, &parent, 0, &old_parent, -1);
214+
215+ old_parentid = katze_item_get_meta_integer (old_parent, "id");
216+
217+ g_object_unref (old_parent);
218+
219+ if (parentid == old_parentid)
220+ {
221+ midori_bookmarks_update_item_in_model (bookmarks, GTK_TREE_STORE (model), &iter, item);
222+ }
223+ else
224+ {
225+ gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
226+
227+ if (!gtk_tree_model_iter_has_child (model, &parent))
228+ {
229+ GtkTreePath* path = gtk_tree_model_get_path(model, &parent);
230+
231+ if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (bookmarks->treeview), path))
232+ gtk_tree_view_collapse_row (GTK_TREE_VIEW (bookmarks->treeview), path);
233+
234+ gtk_tree_path_free (path);
235+ }
236+
237+ midori_bookmarks_add_item (item, bookmarks);
238+ }
239+ }
240+ else if (parentid == 0)
241+ {
242+ midori_bookmarks_update_item_in_model (bookmarks, GTK_TREE_STORE (model), &iter, item);
243+ }
244+ else
245+ {
246+ gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
247+
248+ midori_bookmarks_add_item (item, bookmarks);
249+ }
250+ }
251+ else
252+ midori_bookmarks_add_item (item, bookmarks);
253 }
254
255 static void
256@@ -233,10 +453,33 @@
257 KatzeItem* item,
258 MidoriBookmarks* bookmarks)
259 {
260+ gint64 id = katze_item_get_meta_integer (item, "id");
261 GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview));
262- gtk_tree_store_clear (GTK_TREE_STORE (model));
263- midori_bookmarks_read_from_db_to_model (bookmarks,
264- GTK_TREE_STORE (model), NULL, 0, bookmarks->filter);
265+ GtkTreeIter iter;
266+
267+ if (midori_bookmarks_reach_item (model, &iter, id))
268+ {
269+ GtkTreeIter parent;
270+
271+ if (gtk_tree_model_iter_parent (model, &parent, &iter))
272+ {
273+ gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
274+
275+ if (!gtk_tree_model_iter_has_child (model, &parent))
276+ {
277+ GtkTreePath* path = gtk_tree_model_get_path(model, &parent);
278+
279+ if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (bookmarks->treeview), path))
280+ gtk_tree_view_collapse_row (GTK_TREE_VIEW (bookmarks->treeview), path);
281+
282+ gtk_tree_path_free (path);
283+ }
284+ }
285+ else
286+ {
287+ gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
288+ }
289+ }
290 }
291
292 static void
293@@ -278,8 +521,16 @@
294
295 katze_item_set_meta_integer (item, "parentid", parentid);
296
297+ g_signal_handlers_block_by_func (bookmarks->bookmarks_db,
298+ midori_bookmarks_update_item_cb,
299+ bookmarks);
300+
301 midori_bookmarks_db_update_item (bookmarks->bookmarks_db, item);
302
303+ g_signal_handlers_unblock_by_func (bookmarks->bookmarks_db,
304+ midori_bookmarks_update_item_cb,
305+ bookmarks);
306+
307 g_object_unref (item);
308 if (new_parent)
309 g_object_unref (new_parent);
310@@ -349,24 +600,15 @@
311 {
312 KatzeItem* item;
313 MidoriBrowser* browser;
314- gint64 parentid;
315
316 gtk_tree_model_get (model, &iter, 0, &item, -1);
317
318 g_assert (!KATZE_ITEM_IS_SEPARATOR (item));
319
320 browser = midori_browser_get_for_widget (bookmarks->treeview);
321- parentid = katze_item_get_meta_integer (item, "parentid");
322 midori_browser_edit_bookmark_dialog_new (
323 browser, item, FALSE, KATZE_ITEM_IS_FOLDER (item), NULL);
324
325- if (katze_item_get_meta_integer (item, "parentid") != parentid)
326- {
327- gtk_tree_store_clear (GTK_TREE_STORE (model));
328- midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model),
329- NULL, 0, NULL);
330- }
331-
332 g_object_unref (item);
333 }
334 }
335@@ -496,13 +738,8 @@
336
337 gtk_tree_model_get (model, &iter, 0, &item, -1);
338
339- /* Manually remove the iter and block clearing the treeview */
340- gtk_tree_store_remove (GTK_TREE_STORE (model), &iter);
341- g_signal_handlers_block_by_func (bookmarks->bookmarks_db,
342- midori_bookmarks_remove_item_cb, bookmarks);
343 midori_bookmarks_db_remove_item (bookmarks->bookmarks_db, item);
344- g_signal_handlers_unblock_by_func (bookmarks->bookmarks_db,
345- midori_bookmarks_remove_item_cb, bookmarks);
346+
347 g_object_unref (item);
348 }
349 }
350@@ -598,6 +835,8 @@
351 midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), NULL, 0, NULL);
352 g_signal_connect_after (bookmarks->bookmarks_db, "add-item",
353 G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks);
354+ g_signal_connect_after (bookmarks->bookmarks_db, "update-item",
355+ G_CALLBACK (midori_bookmarks_update_item_cb), bookmarks);
356 g_signal_connect (bookmarks->bookmarks_db, "remove-item",
357 G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks);
358 g_signal_connect (bookmarks->bookmarks_db, "update",
359
360=== modified file 'panels/midori-bookmarks.h'
361--- panels/midori-bookmarks.h 2013-10-31 14:21:54 +0000
362+++ panels/midori-bookmarks.h 2014-01-24 23:43:21 +0000
363@@ -37,10 +37,6 @@
364 GType
365 midori_bookmarks_get_type (void);
366
367-gboolean
368-midori_bookmarks_update_item_db (sqlite3* db,
369- KatzeItem* item);
370-
371 G_END_DECLS
372
373 #endif /* __MIDORI_BOOKMARKS_PANEL_H__ */

Subscribers

People subscribed via source and target branches

to all changes: