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

Proposed by André Auzi
Status: Work in progress
Proposed branch: lp:~aauzi/midori/fix-1179200-9
Merge into: lp:midori
Diff against target: 270 lines (+183/-15)
1 file modified
panels/midori-bookmarks.c (+183/-15)
To merge this branch: bzr merge lp:~aauzi/midori/fix-1179200-9
Reviewer Review Type Date Requested Status
Cris Dywan code-review Approve
Midori Devs Pending
Review via email: mp+186421@code.launchpad.net

Commit message

Delaye bookmark inserts to handle move operations

Description of the change

This is the last step of fix-1179200

It introduces a first derivation of GtkTreeStore for DND drop destination control.

Inserts are delayed to handle move operations where move is actually an insert at destination, followed by a delete at the source and finally a row change callback.

Be aware that everything's not solved, basically both bookmark bar and bookmark panel interract well, one being updated when operations are done on the other.

From my testing, I've seen there's still an update issue of folders in the bookmark menu.

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.

This step comes after step 8 (branch lp:~aauzi/midori/fix-1179200-8) but remains independent of step 7 which adds database transactions.

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

Maybe it's a little overkill too pass column types to the bookmarks store as opposed to hard-coding the right types; no strong opinion whilst the code is already there.

Note: I'm giving primarily technical review not real life stress testing, somebody else *must* try this, I'm not eager to get more regressions in.

review: Approve (code-review)
Revision history for this message
RabbitBot (rabbitbot-a) wrote :

Attempt to merge into lp:midori failed due to conflicts:

text conflict in panels/midori-bookmarks.c

Unmerged revisions

6334. By André Auzi

merge lp:midori after merge of fix-1179200-8

6333. By André Auzi

merge fix-1179200-8

6332. By André Auzi

merge lp:midori

6331. By André Auzi

Derivation of GtkTreeStore for DND drop destination control.

Inserts are delayed to handle move operations where move is actually an insert at destination, followed by a delete at the source and finally a row change callback.

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 2014-01-24 23:04:05 +0000
3+++ panels/midori-bookmarks.c 2014-01-30 21:02:51 +0000
4@@ -26,6 +26,111 @@
5
6 #define COMPLETION_DELAY 200
7
8+G_BEGIN_DECLS
9+
10+#define MIDORI_BOOKMARKS_TREE_STORE_TYPE \
11+ (midori_bookmarks_tree_store_get_type ())
12+#define MIDORI_BOOKMARKS_TREE_STORE(obj) \
13+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_BOOKMARKS_TREE_STORE_TYPE, MidoriBookmarksTreeStore))
14+#define MIDORI_BOOKMARKS_TREE_STORE_CLASS(klass) \
15+ (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_BOOKMARKS_TREE_STORE_TYPE, MidoriBookmarksTreeStoreClass))
16+
17+static gboolean
18+midori_bookmarks_tree_store_row_drop_possible (GtkTreeDragDest *drag_dest,
19+ GtkTreePath *dest_path,
20+ GtkSelectionData *selection_data);
21+
22+typedef struct _MidoriBookmarksTreeStore MidoriBookmarksTreeStore;
23+typedef struct _MidoriBookmarksTreeStoreClass MidoriBookmarksTreeStoreClass;
24+
25+struct _MidoriBookmarksTreeStore
26+{
27+ GtkTreeStore parent_instance;
28+};
29+
30+struct _MidoriBookmarksTreeStoreClass
31+{
32+ GtkTreeStoreClass parent_class;
33+};
34+
35+static GtkTreeDragDestIface *
36+gtk_tree_store_gtk_tree_drag_dest_iface = NULL;
37+
38+static void
39+midori_bookmarks_tree_store_drag_dest_init (GtkTreeDragDestIface *iface)
40+{
41+ gtk_tree_store_gtk_tree_drag_dest_iface = g_type_interface_peek_parent (iface);
42+
43+ iface->row_drop_possible = midori_bookmarks_tree_store_row_drop_possible;
44+}
45+
46+static void
47+midori_bookmarks_tree_store_init (MidoriBookmarksTreeStore* item)
48+{
49+}
50+
51+static void
52+midori_bookmarks_tree_store_class_init (MidoriBookmarksTreeStoreClass *class)
53+{
54+}
55+
56+G_DEFINE_TYPE_WITH_CODE (MidoriBookmarksTreeStore,
57+ midori_bookmarks_tree_store,
58+ GTK_TYPE_TREE_STORE,
59+ G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_DEST,
60+ midori_bookmarks_tree_store_drag_dest_init));
61+
62+
63+GtkTreeStore*
64+midori_bookmarks_tree_store_new (gint n_columns, ...)
65+{
66+ GtkTreeStore* tree_store = GTK_TREE_STORE (g_object_new (MIDORI_BOOKMARKS_TREE_STORE_TYPE, NULL));
67+ va_list ap;
68+ GType* types;
69+ gint n;
70+
71+ if (!tree_store)
72+ return NULL;
73+
74+ types = g_new (GType, n_columns);
75+
76+ if (!types)
77+ {
78+ g_object_unref(tree_store);
79+ return NULL;
80+ }
81+
82+ va_start(ap, n_columns);
83+ for (n = 0; n < n_columns; n++)
84+ {
85+ types[n] = va_arg(ap, GType);
86+ }
87+ va_end(ap);
88+
89+ gtk_tree_store_set_column_types (tree_store,
90+ n_columns,
91+ types);
92+
93+ g_free (types);
94+ return tree_store;
95+}
96+
97+
98+GtkTreeStore*
99+midori_bookmarks_tree_store_newv (gint n_columns, GType *types)
100+{
101+ GtkTreeStore* tree_store = GTK_TREE_STORE (g_object_new (MIDORI_BOOKMARKS_TREE_STORE_TYPE, NULL));
102+
103+ if (!tree_store)
104+ return NULL;
105+
106+ gtk_tree_store_set_column_types (tree_store,
107+ n_columns,
108+ types);
109+
110+ return tree_store;
111+}
112+
113 gboolean
114 midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser,
115 KatzeItem* bookmark_or_parent,
116@@ -50,6 +155,7 @@
117 gint filter_timeout;
118 gchar* filter;
119
120+ GList* pending_inserts;
121 KatzeItem* hovering_item;
122 };
123
124@@ -353,15 +459,39 @@
125 static void
126 midori_bookmarks_add_item (KatzeItem* item,
127 MidoriBookmarks* bookmarks);
128+
129+static gboolean
130+midori_bookmarks_idle (MidoriBookmarks* bookmarks)
131+{
132+ GList* list_iter;
133+
134+ for (list_iter = bookmarks->pending_inserts; list_iter; list_iter = g_list_next (list_iter))
135+ {
136+ KatzeItem *item = KATZE_ITEM (list_iter->data);
137+
138+ midori_bookmarks_add_item (item, bookmarks);
139+
140+ g_object_unref (item);
141+ }
142+
143+ g_list_free (bookmarks->pending_inserts);
144+ bookmarks->pending_inserts = NULL;
145+
146+ return FALSE;
147+}
148+
149 static void
150 midori_bookmarks_add_item_cb (KatzeArray* array,
151 KatzeItem* item,
152 MidoriBookmarks* bookmarks)
153 {
154- midori_bookmarks_add_item (item, bookmarks);
155+ if (!bookmarks->pending_inserts)
156+ g_idle_add ((GSourceFunc)midori_bookmarks_idle, bookmarks);
157+
158+ g_object_ref (item);
159+ bookmarks->pending_inserts = g_list_append (bookmarks->pending_inserts, item);
160 }
161
162-
163 static void
164 midori_bookmarks_add_item (KatzeItem* item,
165 MidoriBookmarks* bookmarks)
166@@ -493,6 +623,42 @@
167 }
168
169
170+static gboolean
171+midori_bookmarks_tree_store_row_drop_possible (GtkTreeDragDest* drag_dest,
172+ GtkTreePath* dest_path,
173+ GtkSelectionData* selection_data)
174+{
175+ gboolean row_drop_possible =
176+ gtk_tree_store_gtk_tree_drag_dest_iface->row_drop_possible (drag_dest,
177+ dest_path,
178+ selection_data);
179+
180+ if (!row_drop_possible)
181+ return FALSE;
182+
183+ if ((!gtk_tree_path_get_depth(dest_path) > 1)
184+ && gtk_tree_path_up(dest_path))
185+ {
186+ GtkTreeModel* model = GTK_TREE_MODEL(drag_dest);
187+ GtkTreeIter iter;
188+
189+ if (gtk_tree_model_get_iter (model, &iter, dest_path))
190+ {
191+ KatzeItem* item;
192+
193+ gtk_tree_model_get (model, &iter, 0, &item, -1);
194+
195+ if (!KATZE_ITEM_IS_FOLDER(item))
196+ row_drop_possible = FALSE;
197+
198+ if (item)
199+ g_object_unref (item);
200+ }
201+ }
202+
203+ return row_drop_possible;
204+}
205+
206 static void
207 midori_bookmarks_row_changed_cb (GtkTreeModel* model,
208 GtkTreePath* path,
209@@ -501,23 +667,26 @@
210 {
211 KatzeItem* item;
212 GtkTreeIter parent;
213- KatzeItem* new_parent = NULL;
214- gint64 parentid;
215-
216+ gint64 parentid = 0;
217+
218 gtk_tree_model_get (model, iter, 0, &item, -1);
219
220+ if (!KATZE_IS_ITEM (item))
221+ return;
222+
223 if (gtk_tree_model_iter_parent (model, &parent, iter))
224 {
225+ KatzeItem* new_parent;
226+
227 gtk_tree_model_get (model, &parent, 0, &new_parent, -1);
228
229- /* Bookmarks must not be moved into non-folder items */
230- if (!KATZE_ITEM_IS_FOLDER (new_parent))
231- parentid = 0;
232- else
233- parentid = katze_item_get_meta_integer (new_parent, "id");
234+ /* Bookmarks cannot be moved into non-folder items */
235+ g_assert (KATZE_ITEM_IS_FOLDER (new_parent));
236+
237+ parentid = katze_item_get_meta_integer (new_parent, "id");
238+
239+ g_object_unref (new_parent);
240 }
241- else
242- parentid = 0;
243
244 katze_item_set_meta_integer (item, "parentid", parentid);
245
246@@ -532,8 +701,6 @@
247 bookmarks);
248
249 g_object_unref (item);
250- if (new_parent)
251- g_object_unref (new_parent);
252 }
253
254 static void
255@@ -1359,7 +1526,7 @@
256 gtk_box_pack_start (GTK_BOX (bookmarks), box, FALSE, FALSE, 5);
257
258 /* Create the treeview */
259- model = gtk_tree_store_new (2, KATZE_TYPE_ITEM, G_TYPE_STRING);
260+ model = midori_bookmarks_tree_store_new (2, KATZE_TYPE_ITEM, G_TYPE_STRING);
261 treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
262 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
263 gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), 1);
264@@ -1409,6 +1576,7 @@
265 gtk_widget_show (treeview);
266 gtk_box_pack_start (GTK_BOX (bookmarks), treeview, TRUE, TRUE, 0);
267 bookmarks->treeview = treeview;
268+ bookmarks->pending_inserts = NULL;
269 bookmarks->hovering_item = NULL;
270 }
271

Subscribers

People subscribed via source and target branches

to all changes: