Merge lp:~aauzi/midori/fix-1006629 into lp:midori
- fix-1006629
- Merge into trunk
Proposed by
André Auzi
Status: | Work in progress | ||||||||
---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~aauzi/midori/fix-1006629 | ||||||||
Merge into: | lp:midori | ||||||||
Diff against target: |
4720 lines (+3164/-334) 13 files modified
katze/katze-array.c (+53/-2) katze/katze-arrayaction.c (+270/-2) katze/katze-utils.c (+156/-3) katze/katze-utils.h (+11/-0) midori/midori-array.c (+7/-0) midori/midori-bookmarks-db.c (+106/-15) midori/midori-bookmarks-db.h (+11/-9) midori/midori-browser.c (+390/-31) midori/midori-locationaction.c (+78/-10) midori/midori-locationaction.h (+8/-0) midori/midori-view.c (+110/-1) panels/midori-bookmarks.c (+1963/-260) tests/bookmarks.c (+1/-1) |
||||||||
To merge this branch: | bzr merge lp:~aauzi/midori/fix-1006629 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Midori Devs | Pending | ||
Review via email: mp+203255@code.launchpad.net |
Commit message
Description of the change
Coming after lp:~aauzi/midori/fix-894143, this proposes bookmark creation by Dnd from Location bar into the bookmarkbar and ordering of the bookmarkbar with Dnd.
Preliminary code for Dnd creation from tabs is deactivated. It needs rework to adapt to recent tabby evolutions.
To post a comment you must log in.
lp:~aauzi/midori/fix-1006629
updated
- 6212. By André Auzi
-
merge lp:midori
Unmerged revisions
- 6212. By André Auzi
-
merge lp:midori
- 6211. By André Auzi
-
Merge lp:~aauzi/midori/fix-894143 with pos_bar order
- 6210. By André Auzi
-
Fix bookmarkbar item position updates
- 6209. By André Auzi
-
Put traces in midori_debug ("bookmarks")
- 6208. By André Auzi
-
merge lp:midori, remove tab drag-n-drop due to tabby evolutions
- 6207. By André Auzi
-
merge lp:midori
- 6206. By André Auzi
-
connect menu button press event
- 6205. By André Auzi
-
merge lp:midori
- 6204. By André Auzi
-
fix hilight item width
- 6203. By André Auzi
-
merge lp:midori
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 2013-11-04 20:57:37 +0000 | |||
3 | +++ katze/katze-array.c 2014-01-26 19:44:25 +0000 | |||
4 | @@ -33,6 +33,15 @@ | |||
5 | 33 | GList* items; | 33 | GList* items; |
6 | 34 | }; | 34 | }; |
7 | 35 | 35 | ||
8 | 36 | enum | ||
9 | 37 | { | ||
10 | 38 | PROP_0, | ||
11 | 39 | |||
12 | 40 | PROP_TYPE, | ||
13 | 41 | |||
14 | 42 | N_PROPERTIES | ||
15 | 43 | }; | ||
16 | 44 | |||
17 | 36 | enum { | 45 | enum { |
18 | 37 | ADD_ITEM, | 46 | ADD_ITEM, |
19 | 38 | REMOVE_ITEM, | 47 | REMOVE_ITEM, |
20 | @@ -55,6 +64,17 @@ | |||
21 | 55 | { | 64 | { |
22 | 56 | g_object_set_data (G_OBJECT (array), "last-update", | 65 | g_object_set_data (G_OBJECT (array), "last-update", |
23 | 57 | GINT_TO_POINTER (time (NULL))); | 66 | GINT_TO_POINTER (time (NULL))); |
24 | 67 | /* #define DEBUG_UPDATE */ | ||
25 | 68 | #ifdef DEBUG_UPDATE | ||
26 | 69 | if (KATZE_IS_ITEM (array)) | ||
27 | 70 | { | ||
28 | 71 | const gchar *name = katze_item_get_name (KATZE_ITEM (array)); | ||
29 | 72 | if (name && *name) | ||
30 | 73 | { | ||
31 | 74 | g_print ("_katze_array_update: %s\n", name); | ||
32 | 75 | } | ||
33 | 76 | } | ||
34 | 77 | #endif | ||
35 | 58 | } | 78 | } |
36 | 59 | 79 | ||
37 | 60 | static void | 80 | static void |
38 | @@ -105,6 +125,27 @@ | |||
39 | 105 | } | 125 | } |
40 | 106 | 126 | ||
41 | 107 | static void | 127 | static void |
42 | 128 | _katze_array_set_property (GObject *object, | ||
43 | 129 | guint property_id, | ||
44 | 130 | const GValue *value, | ||
45 | 131 | GParamSpec *pspec) | ||
46 | 132 | { | ||
47 | 133 | KatzeArray *array = KATZE_ARRAY (object); | ||
48 | 134 | |||
49 | 135 | switch (property_id) | ||
50 | 136 | { | ||
51 | 137 | case PROP_TYPE: | ||
52 | 138 | array->priv->type = g_value_get_gtype (value); | ||
53 | 139 | break; | ||
54 | 140 | |||
55 | 141 | default: | ||
56 | 142 | /* We don't have any other property... */ | ||
57 | 143 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | ||
58 | 144 | break; | ||
59 | 145 | } | ||
60 | 146 | } | ||
61 | 147 | |||
62 | 148 | static void | ||
63 | 108 | katze_array_class_init (KatzeArrayClass* class) | 149 | katze_array_class_init (KatzeArrayClass* class) |
64 | 109 | { | 150 | { |
65 | 110 | GObjectClass* gobject_class; | 151 | GObjectClass* gobject_class; |
66 | @@ -187,6 +228,7 @@ | |||
67 | 187 | 228 | ||
68 | 188 | gobject_class = G_OBJECT_CLASS (class); | 229 | gobject_class = G_OBJECT_CLASS (class); |
69 | 189 | gobject_class->finalize = katze_array_finalize; | 230 | gobject_class->finalize = katze_array_finalize; |
70 | 231 | gobject_class->set_property = _katze_array_set_property; | ||
71 | 190 | 232 | ||
72 | 191 | class->add_item = _katze_array_add_item; | 233 | class->add_item = _katze_array_add_item; |
73 | 192 | class->remove_item = _katze_array_remove_item; | 234 | class->remove_item = _katze_array_remove_item; |
74 | @@ -194,6 +236,16 @@ | |||
75 | 194 | class->clear = _katze_array_clear; | 236 | class->clear = _katze_array_clear; |
76 | 195 | class->update = _katze_array_update; | 237 | class->update = _katze_array_update; |
77 | 196 | 238 | ||
78 | 239 | |||
79 | 240 | g_object_class_install_property (gobject_class, | ||
80 | 241 | PROP_TYPE, | ||
81 | 242 | g_param_spec_gtype ( | ||
82 | 243 | "type", | ||
83 | 244 | "Type", | ||
84 | 245 | "The array item type", | ||
85 | 246 | G_TYPE_NONE, | ||
86 | 247 | G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY)); | ||
87 | 248 | |||
88 | 197 | g_type_class_add_private (class, sizeof (KatzeArrayPrivate)); | 249 | g_type_class_add_private (class, sizeof (KatzeArrayPrivate)); |
89 | 198 | } | 250 | } |
90 | 199 | 251 | ||
91 | @@ -238,8 +290,7 @@ | |||
92 | 238 | 290 | ||
93 | 239 | g_return_val_if_fail (g_type_is_a (type, G_TYPE_OBJECT), NULL); | 291 | g_return_val_if_fail (g_type_is_a (type, G_TYPE_OBJECT), NULL); |
94 | 240 | 292 | ||
97 | 241 | array = g_object_new (KATZE_TYPE_ARRAY, NULL); | 293 | array = g_object_new (KATZE_TYPE_ARRAY, "type", type, NULL); |
96 | 242 | array->priv->type = type; | ||
98 | 243 | 294 | ||
99 | 244 | return array; | 295 | return array; |
100 | 245 | } | 296 | } |
101 | 246 | 297 | ||
102 | === modified file 'katze/katze-arrayaction.c' | |||
103 | --- katze/katze-arrayaction.c 2012-12-16 18:40:00 +0000 | |||
104 | +++ katze/katze-arrayaction.c 2014-01-26 19:44:25 +0000 | |||
105 | @@ -29,6 +29,10 @@ | |||
106 | 29 | 29 | ||
107 | 30 | KatzeArray* array; | 30 | KatzeArray* array; |
108 | 31 | gboolean reversed; | 31 | gboolean reversed; |
109 | 32 | |||
110 | 33 | GtkTargetList* dnd_targets; | ||
111 | 34 | GdkEventButton *press_event; | ||
112 | 35 | GdkEventButton stock_press_event; | ||
113 | 32 | }; | 36 | }; |
114 | 33 | 37 | ||
115 | 34 | struct _KatzeArrayActionClass | 38 | struct _KatzeArrayActionClass |
116 | @@ -43,7 +47,8 @@ | |||
117 | 43 | PROP_0, | 47 | PROP_0, |
118 | 44 | 48 | ||
119 | 45 | PROP_ARRAY, | 49 | PROP_ARRAY, |
121 | 46 | PROP_REVERSED | 50 | PROP_REVERSED, |
122 | 51 | PROP_DND_TARGETS | ||
123 | 47 | }; | 52 | }; |
124 | 48 | 53 | ||
125 | 49 | enum | 54 | enum |
126 | @@ -215,6 +220,20 @@ | |||
127 | 215 | "Whether the array should be walked backwards when building menus", | 220 | "Whether the array should be walked backwards when building menus", |
128 | 216 | FALSE, | 221 | FALSE, |
129 | 217 | G_PARAM_READWRITE)); | 222 | G_PARAM_READWRITE)); |
130 | 223 | /** | ||
131 | 224 | * KatzeArrayAction:dnd-targets: | ||
132 | 225 | * | ||
133 | 226 | * GtkTargetList* the array supports. | ||
134 | 227 | * | ||
135 | 228 | * Since: 0.5.2 | ||
136 | 229 | **/ | ||
137 | 230 | g_object_class_install_property (gobject_class, | ||
138 | 231 | PROP_DND_TARGETS, | ||
139 | 232 | g_param_spec_pointer ( | ||
140 | 233 | "dnd-targets", | ||
141 | 234 | "DNDTargets", | ||
142 | 235 | "GtkTargetList* the array supports", | ||
143 | 236 | G_PARAM_READABLE|G_PARAM_WRITABLE)); | ||
144 | 218 | } | 237 | } |
145 | 219 | 238 | ||
146 | 220 | static void | 239 | static void |
147 | @@ -222,6 +241,8 @@ | |||
148 | 222 | { | 241 | { |
149 | 223 | array_action->array = NULL; | 242 | array_action->array = NULL; |
150 | 224 | array_action->reversed = FALSE; | 243 | array_action->reversed = FALSE; |
151 | 244 | array_action->dnd_targets = NULL; | ||
152 | 245 | array_action->press_event = NULL; | ||
153 | 225 | } | 246 | } |
154 | 226 | 247 | ||
155 | 227 | static void | 248 | static void |
156 | @@ -229,6 +250,9 @@ | |||
157 | 229 | { | 250 | { |
158 | 230 | KatzeArrayAction* array_action = KATZE_ARRAY_ACTION (object); | 251 | KatzeArrayAction* array_action = KATZE_ARRAY_ACTION (object); |
159 | 231 | 252 | ||
160 | 253 | if (array_action->dnd_targets) | ||
161 | 254 | gtk_target_list_unref (array_action->dnd_targets); | ||
162 | 255 | |||
163 | 232 | katze_object_assign (array_action->array, NULL); | 256 | katze_object_assign (array_action->array, NULL); |
164 | 233 | 257 | ||
165 | 234 | G_OBJECT_CLASS (katze_array_action_parent_class)->finalize (object); | 258 | G_OBJECT_CLASS (katze_array_action_parent_class)->finalize (object); |
166 | @@ -250,6 +274,9 @@ | |||
167 | 250 | case PROP_REVERSED: | 274 | case PROP_REVERSED: |
168 | 251 | array_action->reversed = g_value_get_boolean (value); | 275 | array_action->reversed = g_value_get_boolean (value); |
169 | 252 | break; | 276 | break; |
170 | 277 | case PROP_DND_TARGETS: | ||
171 | 278 | array_action->dnd_targets = (GtkTargetList*)g_value_get_pointer (value); | ||
172 | 279 | break; | ||
173 | 253 | default: | 280 | default: |
174 | 254 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 281 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
175 | 255 | break; | 282 | break; |
176 | @@ -272,6 +299,9 @@ | |||
177 | 272 | case PROP_REVERSED: | 299 | case PROP_REVERSED: |
178 | 273 | g_value_set_boolean (value, array_action->reversed); | 300 | g_value_set_boolean (value, array_action->reversed); |
179 | 274 | break; | 301 | break; |
180 | 302 | case PROP_DND_TARGETS: | ||
181 | 303 | g_value_set_pointer (value, array_action->dnd_targets); | ||
182 | 304 | break; | ||
183 | 275 | default: | 305 | default: |
184 | 276 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 306 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
185 | 277 | break; | 307 | break; |
186 | @@ -310,8 +340,29 @@ | |||
187 | 310 | GdkEventButton* event, | 340 | GdkEventButton* event, |
188 | 311 | KatzeArrayAction* array_action) | 341 | KatzeArrayAction* array_action) |
189 | 312 | { | 342 | { |
190 | 343 | array_action->stock_press_event = *event; | ||
191 | 344 | array_action->press_event = &array_action->stock_press_event; | ||
192 | 345 | |||
193 | 346 | return FALSE; | ||
194 | 347 | } | ||
195 | 348 | |||
196 | 349 | static gboolean | ||
197 | 350 | katze_array_action_menu_button_release_cb (GtkWidget* proxy, | ||
198 | 351 | GdkEventButton* event, | ||
199 | 352 | KatzeArrayAction* array_action) | ||
200 | 353 | { | ||
201 | 313 | KatzeItem* item = g_object_get_data (G_OBJECT (proxy), "KatzeItem"); | 354 | KatzeItem* item = g_object_get_data (G_OBJECT (proxy), "KatzeItem"); |
202 | 314 | 355 | ||
203 | 356 | if (array_action->press_event) | ||
204 | 357 | { | ||
205 | 358 | gint x = array_action->press_event->x; | ||
206 | 359 | gint y = array_action->press_event->y; | ||
207 | 360 | array_action->press_event = NULL; | ||
208 | 361 | |||
209 | 362 | if (x != event->x || y != event->y) | ||
210 | 363 | return TRUE; | ||
211 | 364 | } | ||
212 | 365 | |||
213 | 315 | katze_array_action_activate_item (array_action, item, event->button); | 366 | katze_array_action_activate_item (array_action, item, event->button); |
214 | 316 | 367 | ||
215 | 317 | /* we need to block the 'activate' handler which would be called | 368 | /* we need to block the 'activate' handler which would be called |
216 | @@ -323,6 +374,120 @@ | |||
217 | 323 | } | 374 | } |
218 | 324 | 375 | ||
219 | 325 | static void | 376 | static void |
220 | 377 | katze_array_action_item_drag_source_drag_data_get ( | ||
221 | 378 | KatzeItem *item, | ||
222 | 379 | GdkDragContext *drag_context, | ||
223 | 380 | GtkSelectionData *data, | ||
224 | 381 | guint info, | ||
225 | 382 | guint time, | ||
226 | 383 | KatzeArrayAction* action) | ||
227 | 384 | { | ||
228 | 385 | g_return_if_fail (KATZE_IS_ITEM (item)); | ||
229 | 386 | |||
230 | 387 | switch (gdk_drag_context_get_selected_action (drag_context)) | ||
231 | 388 | { | ||
232 | 389 | default: | ||
233 | 390 | break; | ||
234 | 391 | case GDK_ACTION_MOVE: | ||
235 | 392 | case GDK_ACTION_COPY: | ||
236 | 393 | if (selection_data_from_katze_item (data, item)) | ||
237 | 394 | break; | ||
238 | 395 | case GDK_ACTION_LINK: | ||
239 | 396 | if (KATZE_ITEM_IS_BOOKMARK (item)) | ||
240 | 397 | { | ||
241 | 398 | const gchar* uri = katze_item_get_uri (item); | ||
242 | 399 | if (uri && *uri) | ||
243 | 400 | { | ||
244 | 401 | gchar* src_uris[2]; | ||
245 | 402 | gchar** uris; | ||
246 | 403 | |||
247 | 404 | src_uris[0] = (gchar*)uri; | ||
248 | 405 | src_uris[1] = NULL; | ||
249 | 406 | |||
250 | 407 | uris = g_strdupv (src_uris); | ||
251 | 408 | |||
252 | 409 | gtk_selection_data_set_uris (data, uris); | ||
253 | 410 | gtk_selection_data_set_text (data, uri, -1); | ||
254 | 411 | |||
255 | 412 | g_strfreev (uris); | ||
256 | 413 | } | ||
257 | 414 | } | ||
258 | 415 | break; | ||
259 | 416 | } | ||
260 | 417 | } | ||
261 | 418 | |||
262 | 419 | static void | ||
263 | 420 | katze_array_action_menu_item_drag_source_drag_data_get_cb ( | ||
264 | 421 | GtkWidget *widget, | ||
265 | 422 | GdkDragContext *drag_context, | ||
266 | 423 | GtkSelectionData *data, | ||
267 | 424 | guint info, | ||
268 | 425 | guint time, | ||
269 | 426 | KatzeArrayAction* action) | ||
270 | 427 | { | ||
271 | 428 | KatzeItem* item = (KatzeItem*)g_object_get_data (G_OBJECT (widget), "KatzeItem"); | ||
272 | 429 | |||
273 | 430 | katze_array_action_item_drag_source_drag_data_get (item, drag_context, data, info, time, action); | ||
274 | 431 | } | ||
275 | 432 | |||
276 | 433 | static void | ||
277 | 434 | katze_array_action_tool_item_child_drag_source_drag_data_get_cb ( | ||
278 | 435 | GtkWidget *widget, | ||
279 | 436 | GdkDragContext *drag_context, | ||
280 | 437 | GtkSelectionData *data, | ||
281 | 438 | guint info, | ||
282 | 439 | guint time, | ||
283 | 440 | KatzeArrayAction *action) | ||
284 | 441 | { | ||
285 | 442 | GtkWidget* proxy = gtk_widget_get_parent (widget); | ||
286 | 443 | KatzeItem* item = (KatzeItem*)g_object_get_data (G_OBJECT (proxy), "KatzeItem"); | ||
287 | 444 | GtkToolbar* toolbar = GTK_TOOLBAR (gtk_widget_get_parent (proxy)); | ||
288 | 445 | gint pos; | ||
289 | 446 | |||
290 | 447 | g_return_if_fail (KATZE_IS_ITEM (item)); | ||
291 | 448 | |||
292 | 449 | pos = gtk_toolbar_get_item_index (toolbar, GTK_TOOL_ITEM (proxy)); | ||
293 | 450 | if (pos != katze_item_get_meta_integer (item, "pos_bar")) | ||
294 | 451 | katze_item_set_meta_integer (item, "pos_bar", pos); | ||
295 | 452 | |||
296 | 453 | katze_array_action_item_drag_source_drag_data_get (item, drag_context, data, info, time, action); | ||
297 | 454 | } | ||
298 | 455 | |||
299 | 456 | extern void midori_bookmarkbar_position_items (GtkWidget *widget); | ||
300 | 457 | |||
301 | 458 | |||
302 | 459 | static void | ||
303 | 460 | katze_array_action_tool_item_child_drag_source_drag_data_delete_cb ( | ||
304 | 461 | GtkWidget *widget, | ||
305 | 462 | GdkDragContext *drag_context, | ||
306 | 463 | KatzeArrayAction* action) | ||
307 | 464 | { | ||
308 | 465 | GtkWidget* proxy = gtk_widget_get_parent (widget); | ||
309 | 466 | KatzeItem* item = (KatzeItem*)g_object_get_data (G_OBJECT (proxy), "KatzeItem"); | ||
310 | 467 | GtkToolbar* toolbar = GTK_TOOLBAR (gtk_widget_get_parent (proxy)); | ||
311 | 468 | |||
312 | 469 | g_return_if_fail (KATZE_IS_ITEM (item)); | ||
313 | 470 | |||
314 | 471 | gtk_container_remove (GTK_CONTAINER (toolbar), proxy); | ||
315 | 472 | |||
316 | 473 | midori_bookmarkbar_position_items (GTK_WIDGET (toolbar)); | ||
317 | 474 | } | ||
318 | 475 | |||
319 | 476 | static void | ||
320 | 477 | katze_array_action_menu_item_drag_source_drag_data_delete_cb ( | ||
321 | 478 | GtkWidget *proxy, | ||
322 | 479 | GdkDragContext *drag_context, | ||
323 | 480 | KatzeArrayAction* action) | ||
324 | 481 | { | ||
325 | 482 | KatzeItem* item = (KatzeItem*)g_object_get_data (G_OBJECT (proxy), "KatzeItem"); | ||
326 | 483 | GtkMenuShell* menu = GTK_MENU_SHELL (gtk_widget_get_parent (proxy)); | ||
327 | 484 | |||
328 | 485 | g_return_if_fail (KATZE_IS_ITEM (item)); | ||
329 | 486 | |||
330 | 487 | gtk_container_remove (GTK_CONTAINER (menu), proxy); | ||
331 | 488 | } | ||
332 | 489 | |||
333 | 490 | static void | ||
334 | 326 | katze_array_action_menu_item_select_cb (GtkWidget* proxy, | 491 | katze_array_action_menu_item_select_cb (GtkWidget* proxy, |
335 | 327 | KatzeArrayAction* array_action); | 492 | KatzeArrayAction* array_action); |
336 | 328 | 493 | ||
337 | @@ -407,6 +572,24 @@ | |||
338 | 407 | G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); | 572 | G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
339 | 408 | g_signal_connect (menuitem, "activate", | 573 | g_signal_connect (menuitem, "activate", |
340 | 409 | G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); | 574 | G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
341 | 575 | #if 0 | ||
342 | 576 | /* TODO: insert menu DND dest code here */ | ||
343 | 577 | if (array_action->dnd_targets) | ||
344 | 578 | { | ||
345 | 579 | gtk_drag_dest_set (submenu, GTK_DEST_DEFAULT_ALL, NULL, 0, | ||
346 | 580 | GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_LINK); | ||
347 | 581 | gtk_drag_dest_set_target_list (submenu, array_action->dnd_targets); | ||
348 | 582 | g_signal_connect (submenu, "drag-motion", | ||
349 | 583 | G_CALLBACK (katze_array_action_menu_drag_dest_drag_motion_cb), | ||
350 | 584 | array_action); | ||
351 | 585 | g_signal_connect (submenu, "drag-leave", | ||
352 | 586 | G_CALLBACK (katze_array_action_menu_drag_dest_drag_leave_cb), | ||
353 | 587 | array_action); | ||
354 | 588 | g_signal_connect (submenu, "drag-data-received", | ||
355 | 589 | G_CALLBACK (katze_array_action_menu_drag_dest_drag_data_received_cb), | ||
356 | 590 | array_action); | ||
357 | 591 | } | ||
358 | 592 | #endif | ||
359 | 410 | } | 593 | } |
360 | 411 | else | 594 | else |
361 | 412 | { | 595 | { |
362 | @@ -416,6 +599,23 @@ | |||
363 | 416 | } | 599 | } |
364 | 417 | g_signal_connect (menuitem, "button-press-event", | 600 | g_signal_connect (menuitem, "button-press-event", |
365 | 418 | G_CALLBACK (katze_array_action_menu_button_press_cb), array_action); | 601 | G_CALLBACK (katze_array_action_menu_button_press_cb), array_action); |
366 | 602 | g_signal_connect (menuitem, "button-release-event", | ||
367 | 603 | G_CALLBACK (katze_array_action_menu_button_release_cb), array_action); | ||
368 | 604 | |||
369 | 605 | |||
370 | 606 | if (array_action->dnd_targets) | ||
371 | 607 | { | ||
372 | 608 | gtk_drag_source_set (menuitem, GDK_BUTTON1_MASK, NULL, 0, | ||
373 | 609 | GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_LINK); | ||
374 | 610 | gtk_drag_source_set_target_list (menuitem, array_action->dnd_targets); | ||
375 | 611 | g_signal_connect (menuitem, "drag-data-get", | ||
376 | 612 | G_CALLBACK (katze_array_action_menu_item_drag_source_drag_data_get_cb), | ||
377 | 613 | array_action); | ||
378 | 614 | g_signal_connect (menuitem, "drag-data-delete", | ||
379 | 615 | G_CALLBACK (katze_array_action_menu_item_drag_source_drag_data_delete_cb), | ||
380 | 616 | array_action); | ||
381 | 617 | } | ||
382 | 618 | |||
383 | 419 | gtk_widget_show (menuitem); | 619 | gtk_widget_show (menuitem); |
384 | 420 | } | 620 | } |
385 | 421 | } | 621 | } |
386 | @@ -622,15 +822,49 @@ | |||
387 | 622 | gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); | 822 | gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); |
388 | 623 | g_signal_connect (menuitem, "select", | 823 | g_signal_connect (menuitem, "select", |
389 | 624 | G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); | 824 | G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); |
390 | 825 | #if 0 | ||
391 | 826 | /* TODO: insert menu DND menu code here */ | ||
392 | 827 | if (array_action->dnd_targets) | ||
393 | 828 | { | ||
394 | 829 | gtk_drag_dest_set (submenu, GTK_DEST_DEFAULT_ALL, NULL, 0, | ||
395 | 830 | GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_LINK); | ||
396 | 831 | gtk_drag_dest_set_target_list (submenu, array_action->dnd_targets); | ||
397 | 832 | g_signal_connect (submenu, "drag-motion", | ||
398 | 833 | G_CALLBACK (katze_array_action_menu_drag_dest_drag_motion_cb), | ||
399 | 834 | array_action); | ||
400 | 835 | g_signal_connect (submenu, "drag-leave", | ||
401 | 836 | G_CALLBACK (katze_array_action_menu_drag_dest_drag_leave_cb), | ||
402 | 837 | array_action); | ||
403 | 838 | g_signal_connect (submenu, "drag-data-received", | ||
404 | 839 | G_CALLBACK (katze_array_action_menu_drag_dest_drag_data_received_cb), | ||
405 | 840 | array_action); | ||
406 | 841 | } | ||
407 | 842 | #endif | ||
408 | 625 | } | 843 | } |
409 | 626 | else | 844 | else |
410 | 627 | { | 845 | { |
411 | 628 | g_signal_connect (menuitem, "button-press-event", | 846 | g_signal_connect (menuitem, "button-press-event", |
412 | 629 | G_CALLBACK (katze_array_action_menu_button_press_cb), array_action); | 847 | G_CALLBACK (katze_array_action_menu_button_press_cb), array_action); |
413 | 848 | g_signal_connect (menuitem, "button-release-event", | ||
414 | 849 | G_CALLBACK (katze_array_action_menu_button_release_cb), array_action); | ||
415 | 630 | /* we need the 'activate' signal as well for keyboard events */ | 850 | /* we need the 'activate' signal as well for keyboard events */ |
416 | 631 | g_signal_connect (menuitem, "activate", | 851 | g_signal_connect (menuitem, "activate", |
417 | 632 | G_CALLBACK (katze_array_action_menu_activate_cb), array_action); | 852 | G_CALLBACK (katze_array_action_menu_activate_cb), array_action); |
418 | 633 | } | 853 | } |
419 | 854 | |||
420 | 855 | if (array_action->dnd_targets) | ||
421 | 856 | { | ||
422 | 857 | gtk_drag_source_set (menuitem, GDK_BUTTON1_MASK, NULL, 0, | ||
423 | 858 | GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_LINK); | ||
424 | 859 | gtk_drag_source_set_target_list (menuitem, array_action->dnd_targets); | ||
425 | 860 | g_signal_connect (menuitem, "drag-data-get", | ||
426 | 861 | G_CALLBACK (katze_array_action_menu_item_drag_source_drag_data_get_cb), | ||
427 | 862 | array_action); | ||
428 | 863 | g_signal_connect (menuitem, "drag-data-delete", | ||
429 | 864 | G_CALLBACK (katze_array_action_menu_item_drag_source_drag_data_delete_cb), | ||
430 | 865 | array_action); | ||
431 | 866 | } | ||
432 | 867 | |||
433 | 634 | gtk_tool_item_set_proxy_menu_item (GTK_TOOL_ITEM (proxy), | 868 | gtk_tool_item_set_proxy_menu_item (GTK_TOOL_ITEM (proxy), |
434 | 635 | "katze-tool-item-menu", menuitem); | 869 | "katze-tool-item-menu", menuitem); |
435 | 636 | return TRUE; | 870 | return TRUE; |
436 | @@ -706,9 +940,33 @@ | |||
437 | 706 | else | 940 | else |
438 | 707 | gtk_tool_item_set_tooltip_text (toolitem, uri); | 941 | gtk_tool_item_set_tooltip_text (toolitem, uri); |
439 | 708 | 942 | ||
441 | 709 | g_object_set_data (G_OBJECT (toolitem), "KatzeArray", item); | 943 | g_object_set_data (G_OBJECT (toolitem), "KatzeItem", item); |
442 | 710 | g_signal_connect (toolitem, "clicked", | 944 | g_signal_connect (toolitem, "clicked", |
443 | 711 | G_CALLBACK (katze_array_action_proxy_clicked_cb), array_action); | 945 | G_CALLBACK (katze_array_action_proxy_clicked_cb), array_action); |
444 | 946 | if (KATZE_IS_ITEM (item)) | ||
445 | 947 | { | ||
446 | 948 | GtkWidget* child = gtk_bin_get_child (GTK_BIN (toolitem)); | ||
447 | 949 | |||
448 | 950 | if (KATZE_ITEM_IS_FOLDER (item) && array_action->dnd_targets) | ||
449 | 951 | { | ||
450 | 952 | #if 0 | ||
451 | 953 | /* TODO: add toggle button DND dest code here */ | ||
452 | 954 | #endif | ||
453 | 955 | } | ||
454 | 956 | |||
455 | 957 | if (array_action->dnd_targets) | ||
456 | 958 | { | ||
457 | 959 | gtk_drag_source_set (child, GDK_BUTTON1_MASK, NULL, 0, | ||
458 | 960 | GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_LINK); | ||
459 | 961 | gtk_drag_source_set_target_list (child, array_action->dnd_targets); | ||
460 | 962 | g_signal_connect (child, "drag-data-get", | ||
461 | 963 | G_CALLBACK (katze_array_action_tool_item_child_drag_source_drag_data_get_cb), | ||
462 | 964 | array_action); | ||
463 | 965 | g_signal_connect (child, "drag-data-delete", | ||
464 | 966 | G_CALLBACK (katze_array_action_tool_item_child_drag_source_drag_data_delete_cb), | ||
465 | 967 | array_action); | ||
466 | 968 | } | ||
467 | 969 | } | ||
468 | 712 | 970 | ||
469 | 713 | g_object_set_data (G_OBJECT (toolitem), "KatzeArrayAction", array_action); | 971 | g_object_set_data (G_OBJECT (toolitem), "KatzeArrayAction", array_action); |
470 | 714 | g_signal_connect (item, "notify", | 972 | g_signal_connect (item, "notify", |
471 | @@ -767,12 +1025,14 @@ | |||
472 | 767 | KatzeArray* array) | 1025 | KatzeArray* array) |
473 | 768 | { | 1026 | { |
474 | 769 | GSList* proxies; | 1027 | GSList* proxies; |
475 | 1028 | KatzeArray *old_array = NULL; | ||
476 | 770 | 1029 | ||
477 | 771 | g_return_if_fail (KATZE_IS_ARRAY_ACTION (array_action)); | 1030 | g_return_if_fail (KATZE_IS_ARRAY_ACTION (array_action)); |
478 | 772 | g_return_if_fail (!array || katze_array_is_a (array, KATZE_TYPE_ITEM)); | 1031 | g_return_if_fail (!array || katze_array_is_a (array, KATZE_TYPE_ITEM)); |
479 | 773 | 1032 | ||
480 | 774 | /* FIXME: Disconnect old array */ | 1033 | /* FIXME: Disconnect old array */ |
481 | 775 | 1034 | ||
482 | 1035 | old_array = array_action->array; | ||
483 | 776 | if (array) | 1036 | if (array) |
484 | 777 | g_object_ref (array); | 1037 | g_object_ref (array); |
485 | 778 | katze_object_assign (array_action->array, array); | 1038 | katze_object_assign (array_action->array, array); |
486 | @@ -793,7 +1053,15 @@ | |||
487 | 793 | 1053 | ||
488 | 794 | do | 1054 | do |
489 | 795 | { | 1055 | { |
490 | 1056 | KatzeArray* item = g_object_get_data (G_OBJECT (proxies->data), "KatzeItem"); | ||
491 | 1057 | |||
492 | 1058 | if (item && (item == old_array)) | ||
493 | 1059 | g_object_set_data (G_OBJECT (proxies->data), "KatzeItem", array); | ||
494 | 1060 | |||
495 | 796 | gtk_widget_set_sensitive (proxies->data, array != NULL); | 1061 | gtk_widget_set_sensitive (proxies->data, array != NULL); |
496 | 797 | } | 1062 | } |
497 | 798 | while ((proxies = g_slist_next (proxies))); | 1063 | while ((proxies = g_slist_next (proxies))); |
498 | 1064 | |||
499 | 1065 | if (array) | ||
500 | 1066 | katze_array_update (KATZE_ARRAY (array)); | ||
501 | 799 | } | 1067 | } |
502 | 800 | 1068 | ||
503 | === modified file 'katze/katze-utils.c' | |||
504 | --- katze/katze-utils.c 2013-11-05 21:51:18 +0000 | |||
505 | +++ katze/katze-utils.c 2014-01-26 19:44:25 +0000 | |||
506 | @@ -29,6 +29,13 @@ | |||
507 | 29 | #include <unistd.h> | 29 | #include <unistd.h> |
508 | 30 | #endif | 30 | #endif |
509 | 31 | 31 | ||
510 | 32 | typedef struct _KatzeArrayData KatzeArrayData; | ||
511 | 33 | |||
512 | 34 | struct _KatzeArrayData | ||
513 | 35 | { | ||
514 | 36 | KatzeItem* items[1]; | ||
515 | 37 | }; | ||
516 | 38 | |||
517 | 32 | #define I_ g_intern_static_string | 39 | #define I_ g_intern_static_string |
518 | 33 | 40 | ||
519 | 34 | static void | 41 | static void |
520 | @@ -1002,12 +1009,99 @@ | |||
521 | 1002 | 1009 | ||
522 | 1003 | g_return_val_if_fail (GTK_IS_TREE_VIEW (treeview), FALSE); | 1010 | g_return_val_if_fail (GTK_IS_TREE_VIEW (treeview), FALSE); |
523 | 1004 | 1011 | ||
527 | 1005 | if ((selection = gtk_tree_view_get_selection (treeview))) | 1012 | selection = gtk_tree_view_get_selection(treeview); |
528 | 1006 | if (gtk_tree_selection_get_selected (selection, model, iter)) | 1013 | |
529 | 1007 | return TRUE; | 1014 | switch (gtk_tree_selection_get_mode (selection)) |
530 | 1015 | { | ||
531 | 1016 | default: | ||
532 | 1017 | break; | ||
533 | 1018 | |||
534 | 1019 | case GTK_SELECTION_SINGLE: | ||
535 | 1020 | case GTK_SELECTION_BROWSE: | ||
536 | 1021 | if (gtk_tree_selection_get_selected (selection, model, iter)) | ||
537 | 1022 | return TRUE; | ||
538 | 1023 | break; | ||
539 | 1024 | |||
540 | 1025 | case GTK_SELECTION_MULTIPLE: | ||
541 | 1026 | if (gtk_tree_selection_count_selected_rows (selection) == 1) | ||
542 | 1027 | { | ||
543 | 1028 | GtkTreeModel *stock_model; | ||
544 | 1029 | GList *list = gtk_tree_selection_get_selected_rows (selection, &stock_model); | ||
545 | 1030 | |||
546 | 1031 | if (model) | ||
547 | 1032 | *model = stock_model; | ||
548 | 1033 | |||
549 | 1034 | if (list) | ||
550 | 1035 | { | ||
551 | 1036 | GtkTreePath *path = (GtkTreePath *)g_list_nth_data (list, 0); | ||
552 | 1037 | |||
553 | 1038 | if (path && (!iter || gtk_tree_model_get_iter (stock_model, iter, path))) | ||
554 | 1039 | { | ||
555 | 1040 | g_list_free_full(list, (GDestroyNotify) gtk_tree_path_free); | ||
556 | 1041 | return TRUE; | ||
557 | 1042 | } | ||
558 | 1043 | |||
559 | 1044 | g_list_free_full(list, (GDestroyNotify) gtk_tree_path_free); | ||
560 | 1045 | } | ||
561 | 1046 | } | ||
562 | 1047 | } | ||
563 | 1048 | |||
564 | 1008 | return FALSE; | 1049 | return FALSE; |
565 | 1009 | } | 1050 | } |
566 | 1010 | 1051 | ||
567 | 1052 | /** | ||
568 | 1053 | * katze_tree_view_get_selected_rows: | ||
569 | 1054 | * @treeview: a #GtkTreeView | ||
570 | 1055 | * @model: a pointer to store the #GtkTreeModel, or %NULL | ||
571 | 1056 | * @rows: a pointer to store the #GList of #GtkTreePath, or %NULL | ||
572 | 1057 | * | ||
573 | 1058 | * Determines whether there is a selection in @treeview | ||
574 | 1059 | * and sets the @rows to the current selection. | ||
575 | 1060 | * | ||
576 | 1061 | * If there is a selection and @model is not %NULL, it is | ||
577 | 1062 | * set to the model. If @model is %NULL, the @rows will be | ||
578 | 1063 | * set to %NULL. | ||
579 | 1064 | * | ||
580 | 1065 | * Either @model or @rows or both can be %NULL in which case | ||
581 | 1066 | * no value will be assigned in any case. | ||
582 | 1067 | * | ||
583 | 1068 | * When @rows is not %NULL it must be freed using: | ||
584 | 1069 | * g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free); | ||
585 | 1070 | * | ||
586 | 1071 | * Return value: the count of selected rows | ||
587 | 1072 | * | ||
588 | 1073 | * Since: 0.4.7.aau.1 | ||
589 | 1074 | **/ | ||
590 | 1075 | |||
591 | 1076 | gint | ||
592 | 1077 | katze_tree_view_get_selected_rows (GtkTreeView* treeview, | ||
593 | 1078 | GtkTreeModel** model, | ||
594 | 1079 | GList** rows) | ||
595 | 1080 | { | ||
596 | 1081 | gint count; | ||
597 | 1082 | GtkTreeSelection* selection; | ||
598 | 1083 | |||
599 | 1084 | if (model) | ||
600 | 1085 | *model = NULL; | ||
601 | 1086 | if (rows) | ||
602 | 1087 | *rows = NULL; | ||
603 | 1088 | |||
604 | 1089 | g_return_val_if_fail (GTK_IS_TREE_VIEW (treeview), 0); | ||
605 | 1090 | |||
606 | 1091 | selection = gtk_tree_view_get_selection(treeview); | ||
607 | 1092 | |||
608 | 1093 | count = gtk_tree_selection_count_selected_rows (selection); | ||
609 | 1094 | if (count > 0) | ||
610 | 1095 | { | ||
611 | 1096 | if (model && rows) | ||
612 | 1097 | { | ||
613 | 1098 | *rows = gtk_tree_selection_get_selected_rows (selection, model); | ||
614 | 1099 | } | ||
615 | 1100 | } | ||
616 | 1101 | |||
617 | 1102 | return count; | ||
618 | 1103 | } | ||
619 | 1104 | |||
620 | 1011 | void | 1105 | void |
621 | 1012 | katze_bookmark_populate_tree_view (KatzeArray* array, | 1106 | katze_bookmark_populate_tree_view (KatzeArray* array, |
622 | 1013 | GtkTreeStore* model, | 1107 | GtkTreeStore* model, |
623 | @@ -1377,3 +1471,62 @@ | |||
624 | 1377 | gtk_widget_set_size_request (GTK_WIDGET (window), 700, 100); | 1471 | gtk_widget_set_size_request (GTK_WIDGET (window), 700, 100); |
625 | 1378 | } | 1472 | } |
626 | 1379 | 1473 | ||
627 | 1474 | gboolean | ||
628 | 1475 | selection_data_from_katze_item (GtkSelectionData* selection_data, KatzeItem* item) | ||
629 | 1476 | { | ||
630 | 1477 | GdkAtom katze_array_atom = gdk_atom_intern_static_string ("KATZE_ARRAY"); | ||
631 | 1478 | KatzeArrayData *kad; | ||
632 | 1479 | |||
633 | 1480 | g_return_val_if_fail (selection_data != NULL, FALSE); | ||
634 | 1481 | g_return_val_if_fail (KATZE_IS_ITEM (item), FALSE); | ||
635 | 1482 | |||
636 | 1483 | if (gtk_selection_data_get_target (selection_data) != katze_array_atom) | ||
637 | 1484 | return FALSE; | ||
638 | 1485 | |||
639 | 1486 | kad = g_malloc (sizeof (KatzeArrayData)); | ||
640 | 1487 | |||
641 | 1488 | kad->items[0] = item; | ||
642 | 1489 | |||
643 | 1490 | gtk_selection_data_set (selection_data, | ||
644 | 1491 | katze_array_atom, | ||
645 | 1492 | 8, /* bytes */ | ||
646 | 1493 | (void*)kad, | ||
647 | 1494 | sizeof (KatzeArrayData)); | ||
648 | 1495 | |||
649 | 1496 | g_free (kad); | ||
650 | 1497 | return TRUE; | ||
651 | 1498 | } | ||
652 | 1499 | |||
653 | 1500 | KatzeArray* | ||
654 | 1501 | katze_array_from_selection_data (GtkSelectionData* selection_data) | ||
655 | 1502 | { | ||
656 | 1503 | GdkAtom katze_array_atom = gdk_atom_intern_static_string ("KATZE_ARRAY"); | ||
657 | 1504 | KatzeArrayData *kad; | ||
658 | 1505 | KatzeArray *array; | ||
659 | 1506 | gint size; | ||
660 | 1507 | gint count; | ||
661 | 1508 | gint i; | ||
662 | 1509 | |||
663 | 1510 | g_return_val_if_fail (selection_data != NULL, FALSE); | ||
664 | 1511 | |||
665 | 1512 | if (gtk_selection_data_get_target (selection_data) != katze_array_atom) | ||
666 | 1513 | return NULL; | ||
667 | 1514 | |||
668 | 1515 | if (gtk_selection_data_get_format (selection_data) != 8) | ||
669 | 1516 | return NULL; | ||
670 | 1517 | |||
671 | 1518 | size = gtk_selection_data_get_length (selection_data); | ||
672 | 1519 | if (size <= 0) | ||
673 | 1520 | return NULL; | ||
674 | 1521 | |||
675 | 1522 | kad = (void*) gtk_selection_data_get_data (selection_data); | ||
676 | 1523 | |||
677 | 1524 | count = (size - G_STRUCT_OFFSET (KatzeArrayData, items))/sizeof(KatzeItem*); | ||
678 | 1525 | |||
679 | 1526 | array = katze_array_new (KATZE_TYPE_ARRAY); | ||
680 | 1527 | |||
681 | 1528 | for ( i = 0; i < count; i++ ) | ||
682 | 1529 | katze_array_add_item (array, kad->items[i]); | ||
683 | 1530 | |||
684 | 1531 | return array; | ||
685 | 1532 | } | ||
686 | 1380 | 1533 | ||
687 | === modified file 'katze/katze-utils.h' | |||
688 | --- katze/katze-utils.h 2013-04-16 22:10:56 +0000 | |||
689 | +++ katze/katze-utils.h 2014-01-26 19:44:25 +0000 | |||
690 | @@ -88,6 +88,11 @@ | |||
691 | 88 | GtkTreeModel** model, | 88 | GtkTreeModel** model, |
692 | 89 | GtkTreeIter* iter); | 89 | GtkTreeIter* iter); |
693 | 90 | 90 | ||
694 | 91 | gint | ||
695 | 92 | katze_tree_view_get_selected_rows (GtkTreeView* treeview, | ||
696 | 93 | GtkTreeModel** model, | ||
697 | 94 | GList** rows); | ||
698 | 95 | |||
699 | 91 | void | 96 | void |
700 | 92 | katze_bookmark_populate_tree_view (KatzeArray* array, | 97 | katze_bookmark_populate_tree_view (KatzeArray* array, |
701 | 93 | GtkTreeStore* model, | 98 | GtkTreeStore* model, |
702 | @@ -138,6 +143,12 @@ | |||
703 | 138 | void | 143 | void |
704 | 139 | katze_window_set_sensible_default_size (GtkWindow* window); | 144 | katze_window_set_sensible_default_size (GtkWindow* window); |
705 | 140 | 145 | ||
706 | 146 | gboolean | ||
707 | 147 | selection_data_from_katze_item (GtkSelectionData* selection_data, KatzeItem* item); | ||
708 | 148 | |||
709 | 149 | KatzeArray* | ||
710 | 150 | katze_array_from_selection_data (GtkSelectionData* selection_data); | ||
711 | 151 | |||
712 | 141 | G_END_DECLS | 152 | G_END_DECLS |
713 | 142 | 153 | ||
714 | 143 | #endif /* __KATZE_UTILS_H__ */ | 154 | #endif /* __KATZE_UTILS_H__ */ |
715 | 144 | 155 | ||
716 | === modified file 'midori/midori-array.c' | |||
717 | --- midori/midori-array.c 2013-08-05 19:52:52 +0000 | |||
718 | +++ midori/midori-array.c 2014-01-26 19:44:25 +0000 | |||
719 | @@ -1031,9 +1031,16 @@ | |||
720 | 1031 | || g_str_equal (name, "last_visit") || g_str_equal (name, "visit_count") | 1031 | || g_str_equal (name, "last_visit") || g_str_equal (name, "visit_count") |
721 | 1032 | || g_str_equal (name, "pos_panel") || g_str_equal (name, "pos_bar")) | 1032 | || g_str_equal (name, "pos_panel") || g_str_equal (name, "pos_bar")) |
722 | 1033 | { | 1033 | { |
723 | 1034 | #if 0 | ||
724 | 1034 | gint value; | 1035 | gint value; |
725 | 1035 | value = sqlite3_column_int64 (stmt, column); | 1036 | value = sqlite3_column_int64 (stmt, column); |
726 | 1036 | katze_item_set_meta_integer (item, name, value); | 1037 | katze_item_set_meta_integer (item, name, value); |
727 | 1038 | #else | ||
728 | 1039 | /* use text to properly handle NULL values */ | ||
729 | 1040 | const unsigned char* text; | ||
730 | 1041 | text = sqlite3_column_text (stmt, column); | ||
731 | 1042 | katze_item_set_meta_string (item, name, (gchar*)text); | ||
732 | 1043 | #endif | ||
733 | 1037 | } | 1044 | } |
734 | 1038 | else if (g_str_equal (name, "desc")) | 1045 | else if (g_str_equal (name, "desc")) |
735 | 1039 | { | 1046 | { |
736 | 1040 | 1047 | ||
737 | === modified file 'midori/midori-bookmarks-db.c' | |||
738 | --- midori/midori-bookmarks-db.c 2014-01-24 23:04:05 +0000 | |||
739 | +++ midori/midori-bookmarks-db.c 2014-01-26 19:44:25 +0000 | |||
740 | @@ -181,14 +181,29 @@ | |||
741 | 181 | midori_bookmarks_db_get_item_parent (MidoriBookmarksDb* bookmarks, | 181 | midori_bookmarks_db_get_item_parent (MidoriBookmarksDb* bookmarks, |
742 | 182 | gpointer item) | 182 | gpointer item) |
743 | 183 | { | 183 | { |
744 | 184 | gint64 parentid = katze_item_get_meta_integer (KATZE_ITEM (item), "parentid"); | ||
745 | 185 | KatzeItem *search = katze_item_new (); | ||
746 | 184 | KatzeArray* parent; | 186 | KatzeArray* parent; |
753 | 185 | gint64 parentid; | 187 | |
754 | 186 | 188 | if (!parentid) | |
755 | 187 | parentid = katze_item_get_meta_integer (KATZE_ITEM (item), "parentid"); | 189 | { |
756 | 188 | 190 | parentid = katze_item_get_meta_integer (KATZE_ITEM (bookmarks), "id"); | |
757 | 189 | if (parentid == 0) | 191 | katze_item_set_meta_integer (KATZE_ITEM (item), "parentid", parentid); |
758 | 190 | { | 192 | } |
759 | 193 | |||
760 | 194 | katze_item_set_meta_integer(search, "id", parentid); | ||
761 | 195 | |||
762 | 196 | parent = KATZE_ARRAY (g_hash_table_lookup (bookmarks->all_items, search)); | ||
763 | 197 | |||
764 | 198 | g_object_unref (search); | ||
765 | 199 | |||
766 | 200 | if (!parent) | ||
767 | 201 | { | ||
768 | 202 | g_warning ("item parent not found\n"); | ||
769 | 203 | |||
770 | 191 | parent = KATZE_ARRAY (bookmarks); | 204 | parent = KATZE_ARRAY (bookmarks); |
771 | 205 | katze_item_set_meta_integer (KATZE_ITEM (item), "parentid", | ||
772 | 206 | katze_item_get_meta_integer (KATZE_ITEM (bookmarks), "id")); | ||
773 | 192 | } | 207 | } |
774 | 193 | else | 208 | else |
775 | 194 | { | 209 | { |
776 | @@ -267,7 +282,10 @@ | |||
777 | 267 | 282 | ||
778 | 268 | g_return_if_fail (parent); | 283 | g_return_if_fail (parent); |
779 | 269 | 284 | ||
781 | 270 | katze_array_update (parent); | 285 | if (IS_MIDORI_BOOKMARKS_DB (parent)) |
782 | 286 | KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->update (parent); | ||
783 | 287 | else | ||
784 | 288 | katze_array_update (parent); | ||
785 | 271 | } | 289 | } |
786 | 272 | 290 | ||
787 | 273 | /** | 291 | /** |
788 | @@ -479,7 +497,7 @@ | |||
789 | 479 | else if (old_parent && katze_item_get_meta_integer (old_parent, "id") > 0) | 497 | else if (old_parent && katze_item_get_meta_integer (old_parent, "id") > 0) |
790 | 480 | new_parentid = g_strdup_printf ("%" G_GINT64_FORMAT, katze_item_get_meta_integer (old_parent, "id")); | 498 | new_parentid = g_strdup_printf ("%" G_GINT64_FORMAT, katze_item_get_meta_integer (old_parent, "id")); |
791 | 481 | else | 499 | else |
793 | 482 | new_parentid = g_strdup_printf ("NULL"); | 500 | new_parentid = g_strdup ("NULL"); |
794 | 483 | 501 | ||
795 | 484 | sqlcmd = sqlite3_mprintf ( | 502 | sqlcmd = sqlite3_mprintf ( |
796 | 485 | "INSERT INTO bookmarks (id, parentid, title, uri, desc, toolbar, app) " | 503 | "INSERT INTO bookmarks (id, parentid, title, uri, desc, toolbar, app) " |
797 | @@ -557,7 +575,8 @@ | |||
798 | 557 | 575 | ||
799 | 558 | sqlcmd = sqlite3_mprintf ( | 576 | sqlcmd = sqlite3_mprintf ( |
800 | 559 | "UPDATE bookmarks SET " | 577 | "UPDATE bookmarks SET " |
802 | 560 | "parentid=%q, title='%q', uri='%q', desc='%q', toolbar=%d, app=%d " | 578 | "parentid=%q, title='%q', uri='%q', desc='%q', toolbar=%d, app=%d, " |
803 | 579 | "pos_bar=%d, pos_panel=%d " | ||
804 | 561 | "WHERE id = %q ;", | 580 | "WHERE id = %q ;", |
805 | 562 | parentid, | 581 | parentid, |
806 | 563 | katze_item_get_name (item), | 582 | katze_item_get_name (item), |
807 | @@ -565,6 +584,8 @@ | |||
808 | 565 | katze_str_non_null (katze_item_get_meta_string (item, "desc")), | 584 | katze_str_non_null (katze_item_get_meta_string (item, "desc")), |
809 | 566 | katze_item_get_meta_boolean (item, "toolbar"), | 585 | katze_item_get_meta_boolean (item, "toolbar"), |
810 | 567 | katze_item_get_meta_boolean (item, "app"), | 586 | katze_item_get_meta_boolean (item, "app"), |
811 | 587 | (gint)katze_item_get_meta_integer (item, "pos_bar"), | ||
812 | 588 | (gint)katze_item_get_meta_integer (item, "pos_panel"), | ||
813 | 568 | id); | 589 | id); |
814 | 569 | 590 | ||
815 | 570 | updated = TRUE; | 591 | updated = TRUE; |
816 | @@ -579,6 +600,14 @@ | |||
817 | 579 | g_free (parentid); | 600 | g_free (parentid); |
818 | 580 | g_free (id); | 601 | g_free (id); |
819 | 581 | 602 | ||
820 | 603 | #ifdef DEBUG_DB_UPDATE | ||
821 | 604 | g_print ("update:%s - parentid: %s, pos_bar:%d, pos_panel:%d\n", | ||
822 | 605 | katze_item_get_name (item), | ||
823 | 606 | parentid, | ||
824 | 607 | (gint)katze_item_get_meta_integer (item, "pos_bar"), | ||
825 | 608 | (gint)katze_item_get_meta_integer (item, "pos_panel")); | ||
826 | 609 | #endif | ||
827 | 610 | |||
828 | 582 | return updated; | 611 | return updated; |
829 | 583 | } | 612 | } |
830 | 584 | 613 | ||
831 | @@ -710,10 +739,10 @@ | |||
832 | 710 | g_return_val_if_fail (errmsg != NULL, NULL); | 739 | g_return_val_if_fail (errmsg != NULL, NULL); |
833 | 711 | 740 | ||
834 | 712 | database = midori_bookmarks_database_new (&error); | 741 | database = midori_bookmarks_database_new (&error); |
836 | 713 | 742 | ||
837 | 714 | if (error != NULL) | 743 | if (error != NULL) |
838 | 715 | { | 744 | { |
840 | 716 | *errmsg = g_strdup (error->message); | 745 | *errmsg = g_strdup (error->message); |
841 | 717 | g_error_free (error); | 746 | g_error_free (error); |
842 | 718 | return NULL; | 747 | return NULL; |
843 | 719 | } | 748 | } |
844 | @@ -724,7 +753,10 @@ | |||
845 | 724 | if (midori_debug ("bookmarks")) | 753 | if (midori_debug ("bookmarks")) |
846 | 725 | sqlite3_trace (db, midori_bookmarks_db_dbtracer, NULL); | 754 | sqlite3_trace (db, midori_bookmarks_db_dbtracer, NULL); |
847 | 726 | 755 | ||
849 | 727 | bookmarks = MIDORI_BOOKMARKS_DB (g_object_new (TYPE_MIDORI_BOOKMARKS_DB, NULL)); | 756 | bookmarks = MIDORI_BOOKMARKS_DB (g_object_new (TYPE_MIDORI_BOOKMARKS_DB, |
850 | 757 | "type", KATZE_TYPE_ITEM, | ||
851 | 758 | NULL)); | ||
852 | 759 | |||
853 | 728 | bookmarks->db = db; | 760 | bookmarks->db = db; |
854 | 729 | 761 | ||
855 | 730 | g_object_set_data (G_OBJECT (bookmarks), "db", db); | 762 | g_object_set_data (G_OBJECT (bookmarks), "db", db); |
856 | @@ -776,6 +808,7 @@ | |||
857 | 776 | katze_item_set_meta_integer (item, "parentid", parentid); | 808 | katze_item_set_meta_integer (item, "parentid", parentid); |
858 | 777 | midori_bookmarks_db_add_item (bookmarks, item); | 809 | midori_bookmarks_db_add_item (bookmarks, item); |
859 | 778 | } | 810 | } |
860 | 811 | |||
861 | 779 | g_list_free (list); | 812 | g_list_free (list); |
862 | 780 | } | 813 | } |
863 | 781 | 814 | ||
864 | @@ -859,7 +892,7 @@ | |||
865 | 859 | * @array: the main bookmark array | 892 | * @array: the main bookmark array |
866 | 860 | * @sqlcmd: the sqlcmd to execute | 893 | * @sqlcmd: the sqlcmd to execute |
867 | 861 | * | 894 | * |
869 | 862 | * Internal function that process the requested @sqlcmd. | 895 | * Internal function that processes the requested @sqlcmd. |
870 | 863 | * | 896 | * |
871 | 864 | * Return value: a #KatzeArray on success, %NULL otherwise | 897 | * Return value: a #KatzeArray on success, %NULL otherwise |
872 | 865 | **/ | 898 | **/ |
873 | @@ -885,6 +918,10 @@ | |||
874 | 885 | * @fields: comma separated list of fields | 918 | * @fields: comma separated list of fields |
875 | 886 | * @condition: condition, like "folder = '%q'" | 919 | * @condition: condition, like "folder = '%q'" |
876 | 887 | * @value: a value to be inserted if @condition contains %q | 920 | * @value: a value to be inserted if @condition contains %q |
877 | 921 | * @order: a value to be inserted in "ORDER BY" | ||
878 | 922 | * default order is : | ||
879 | 923 | * (uri='') ASC, title DESC | ||
880 | 924 | * given @order, when not %NULL, replaces the term: (uri='') ASC | ||
881 | 888 | * @recursive: if %TRUE include children | 925 | * @recursive: if %TRUE include children |
882 | 889 | * | 926 | * |
883 | 890 | * Stores the result in a #KatzeArray. | 927 | * Stores the result in a #KatzeArray. |
884 | @@ -898,6 +935,7 @@ | |||
885 | 898 | const gchar* fields, | 935 | const gchar* fields, |
886 | 899 | const gchar* condition, | 936 | const gchar* condition, |
887 | 900 | const gchar* value, | 937 | const gchar* value, |
888 | 938 | const gchar* order, | ||
889 | 901 | gboolean recursive) | 939 | gboolean recursive) |
890 | 902 | { | 940 | { |
891 | 903 | gchar* sqlcmd; | 941 | gchar* sqlcmd; |
892 | @@ -911,7 +949,8 @@ | |||
893 | 911 | g_return_val_if_fail (condition, NULL); | 949 | g_return_val_if_fail (condition, NULL); |
894 | 912 | 950 | ||
895 | 913 | sqlcmd = g_strdup_printf ("SELECT %s FROM bookmarks WHERE %s " | 951 | sqlcmd = g_strdup_printf ("SELECT %s FROM bookmarks WHERE %s " |
897 | 914 | "ORDER BY (uri='') ASC, title DESC", fields, condition); | 952 | "ORDER BY %s, title DESC", fields, condition, order ? order : "(uri='') ASC"); |
898 | 953 | |||
899 | 915 | if (strstr (condition, "%q")) | 954 | if (strstr (condition, "%q")) |
900 | 916 | { | 955 | { |
901 | 917 | sqlcmd_value = sqlite3_mprintf (sqlcmd, value ? value : ""); | 956 | sqlcmd_value = sqlite3_mprintf (sqlcmd, value ? value : ""); |
902 | @@ -932,7 +971,7 @@ | |||
903 | 932 | gchar* parentid = g_strdup_printf ("%" G_GINT64_FORMAT, | 971 | gchar* parentid = g_strdup_printf ("%" G_GINT64_FORMAT, |
904 | 933 | katze_item_get_meta_integer (item, "id")); | 972 | katze_item_get_meta_integer (item, "id")); |
905 | 934 | KatzeArray* subarray = midori_bookmarks_db_query_recursive (bookmarks, | 973 | KatzeArray* subarray = midori_bookmarks_db_query_recursive (bookmarks, |
907 | 935 | fields, "parentid=%q", parentid, TRUE); | 974 | fields, "parentid=%q", parentid, order, TRUE); |
908 | 936 | KatzeItem* subitem; | 975 | KatzeItem* subitem; |
909 | 937 | GList* sublist; | 976 | GList* sublist; |
910 | 938 | 977 | ||
911 | @@ -1097,3 +1136,55 @@ | |||
912 | 1097 | value, id, | 1136 | value, id, |
913 | 1098 | recursive); | 1137 | recursive); |
914 | 1099 | } | 1138 | } |
915 | 1139 | |||
916 | 1140 | /** | ||
917 | 1141 | * midori_bookmarks_db_populate_folder: | ||
918 | 1142 | **/ | ||
919 | 1143 | |||
920 | 1144 | void | ||
921 | 1145 | midori_bookmarks_db_populate_folder (MidoriBookmarksDb* bookmarks, | ||
922 | 1146 | KatzeArray *folder) | ||
923 | 1147 | { | ||
924 | 1148 | const gchar* id = katze_item_get_meta_string (KATZE_ITEM (folder), "id"); | ||
925 | 1149 | const gchar *condition; | ||
926 | 1150 | KatzeArray* array; | ||
927 | 1151 | KatzeItem* item; | ||
928 | 1152 | GList* list; | ||
929 | 1153 | |||
930 | 1154 | if (id == NULL) | ||
931 | 1155 | { | ||
932 | 1156 | condition = "parentid is NULL"; | ||
933 | 1157 | } | ||
934 | 1158 | else | ||
935 | 1159 | { | ||
936 | 1160 | condition = "parentid = %q"; | ||
937 | 1161 | } | ||
938 | 1162 | |||
939 | 1163 | array = midori_bookmarks_db_query_recursive (bookmarks, | ||
940 | 1164 | "id, title, parentid, uri, app, pos_panel, pos_bar", condition, id, "(uri='') ASC, pos_panel ASC", FALSE); | ||
941 | 1165 | |||
942 | 1166 | if (IS_MIDORI_BOOKMARKS_DB (folder)) | ||
943 | 1167 | { | ||
944 | 1168 | KATZE_ARRAY_FOREACH_ITEM_L (item, folder, list) | ||
945 | 1169 | { | ||
946 | 1170 | KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->remove_item (folder, item); | ||
947 | 1171 | } | ||
948 | 1172 | |||
949 | 1173 | KATZE_ARRAY_FOREACH_ITEM_L (item, array, list) | ||
950 | 1174 | { | ||
951 | 1175 | KATZE_ARRAY_CLASS (midori_bookmarks_db_parent_class)->add_item (folder, item); | ||
952 | 1176 | } | ||
953 | 1177 | } | ||
954 | 1178 | else | ||
955 | 1179 | { | ||
956 | 1180 | katze_array_clear(folder); | ||
957 | 1181 | |||
958 | 1182 | KATZE_ARRAY_FOREACH_ITEM_L (item, array, list) | ||
959 | 1183 | { | ||
960 | 1184 | katze_array_add_item (folder, item); | ||
961 | 1185 | } | ||
962 | 1186 | } | ||
963 | 1187 | |||
964 | 1188 | g_object_unref (array); | ||
965 | 1189 | } | ||
966 | 1190 | |||
967 | 1100 | 1191 | ||
968 | === modified file 'midori/midori-bookmarks-db.h' | |||
969 | --- midori/midori-bookmarks-db.h 2013-09-17 19:34:23 +0000 | |||
970 | +++ midori/midori-bookmarks-db.h 2014-01-26 19:44:25 +0000 | |||
971 | @@ -62,19 +62,21 @@ | |||
972 | 62 | const gchar* fields, | 62 | const gchar* fields, |
973 | 63 | const gchar* condition, | 63 | const gchar* condition, |
974 | 64 | const gchar* value, | 64 | const gchar* value, |
975 | 65 | const gchar* order, | ||
976 | 65 | gboolean recursive); | 66 | gboolean recursive); |
977 | 66 | 67 | ||
978 | 67 | gint64 | 68 | gint64 |
979 | 68 | midori_bookmarks_db_count_recursive (MidoriBookmarksDb* bookmarks, | 69 | midori_bookmarks_db_count_recursive (MidoriBookmarksDb* bookmarks, |
981 | 69 | const gchar* condition, | 70 | const gchar* condition, |
982 | 70 | const gchar* value, | 71 | const gchar* value, |
990 | 71 | KatzeItem* folder, | 72 | KatzeItem* folder, |
991 | 72 | gboolean recursive); | 73 | gboolean recursive); |
992 | 73 | 74 | ||
993 | 74 | gint64 | 75 | void |
994 | 75 | midori_bookmarks_insert_item_db (sqlite3* db, | 76 | midori_bookmarks_db_on_quit (MidoriBookmarksDb* array); |
995 | 76 | KatzeItem* item, | 77 | |
996 | 77 | gint64 parentid); | 78 | void |
997 | 79 | midori_bookmarks_db_populate_folder (MidoriBookmarksDb* bookmarks, | ||
998 | 80 | KatzeArray *folder); | ||
999 | 78 | 81 | ||
1000 | 79 | #endif /* !__MIDORI_BOOKMARKS_DB_H__ */ | 82 | #endif /* !__MIDORI_BOOKMARKS_DB_H__ */ |
1001 | 80 | |||
1002 | 81 | 83 | ||
1003 | === modified file 'midori/midori-browser.c' | |||
1004 | --- midori/midori-browser.c 2014-01-06 23:05:10 +0000 | |||
1005 | +++ midori/midori-browser.c 2014-01-26 19:44:25 +0000 | |||
1006 | @@ -99,9 +99,24 @@ | |||
1007 | 99 | guint maximum_history_age; | 99 | guint maximum_history_age; |
1008 | 100 | guint last_web_search; | 100 | guint last_web_search; |
1009 | 101 | 101 | ||
1010 | 102 | struct _BookmarkbarDNDControl | ||
1011 | 103 | { | ||
1012 | 104 | GtkTargetList* source_targets; | ||
1013 | 105 | GtkTargetList* dest_targets; | ||
1014 | 106 | |||
1015 | 107 | struct _BookmarkbarDragDestControl | ||
1016 | 108 | { | ||
1017 | 109 | GtkToolItem* highligth_item; | ||
1018 | 110 | gboolean hovering; | ||
1019 | 111 | int n; | ||
1020 | 112 | } drag_dest_control; | ||
1021 | 113 | } bookmarkbar_dnd_control; | ||
1022 | 102 | gboolean bookmarkbar_populate; | 114 | gboolean bookmarkbar_populate; |
1023 | 103 | }; | 115 | }; |
1024 | 104 | 116 | ||
1025 | 117 | typedef struct _BookmarkbarDNDControl BookmarkbarDNDControl; | ||
1026 | 118 | typedef struct _BookmarkbarDragDestControl BookmarkbarDragDestControl; | ||
1027 | 119 | |||
1028 | 105 | G_DEFINE_TYPE (MidoriBrowser, midori_browser, GTK_TYPE_WINDOW) | 120 | G_DEFINE_TYPE (MidoriBrowser, midori_browser, GTK_TYPE_WINDOW) |
1029 | 106 | 121 | ||
1030 | 107 | enum | 122 | enum |
1031 | @@ -173,11 +188,22 @@ | |||
1032 | 173 | midori_bookmarkbar_populate (MidoriBrowser* browser); | 188 | midori_bookmarkbar_populate (MidoriBrowser* browser); |
1033 | 174 | static void | 189 | static void |
1034 | 175 | midori_bookmarkbar_populate_idle (MidoriBrowser* browser); | 190 | midori_bookmarkbar_populate_idle (MidoriBrowser* browser); |
1035 | 191 | void | ||
1036 | 192 | midori_bookmarkbar_position_items (GtkWidget* widget); | ||
1037 | 176 | 193 | ||
1038 | 177 | static void | 194 | static void |
1039 | 178 | midori_bookmarkbar_clear (GtkWidget* toolbar); | 195 | midori_bookmarkbar_clear (GtkWidget* toolbar); |
1040 | 179 | 196 | ||
1041 | 180 | static void | 197 | static void |
1042 | 198 | bookmarkbar_dnd_control_init (BookmarkbarDNDControl* control, MidoriBrowser* browser); | ||
1043 | 199 | |||
1044 | 200 | static void | ||
1045 | 201 | bookmarkbar_dnd_control_finalize (BookmarkbarDNDControl* control); | ||
1046 | 202 | |||
1047 | 203 | static void | ||
1048 | 204 | bookmarkbar_dnd_control_install (BookmarkbarDNDControl* control, GtkToolbar* bookmarkbar); | ||
1049 | 205 | |||
1050 | 206 | static void | ||
1051 | 181 | _midori_browser_set_toolbar_style (MidoriBrowser* browser, | 207 | _midori_browser_set_toolbar_style (MidoriBrowser* browser, |
1052 | 182 | MidoriToolbarStyle toolbar_style); | 208 | MidoriToolbarStyle toolbar_style); |
1053 | 183 | 209 | ||
1054 | @@ -716,6 +742,8 @@ | |||
1055 | 716 | const gchar* title) | 742 | const gchar* title) |
1056 | 717 | { | 743 | { |
1057 | 718 | const gchar* custom_title = midori_settings_get_custom_title (MIDORI_SETTINGS (browser->settings)); | 744 | const gchar* custom_title = midori_settings_get_custom_title (MIDORI_SETTINGS (browser->settings)); |
1058 | 745 | GtkAction* action = _action_by_name (browser, "Location"); | ||
1059 | 746 | midori_location_action_set_title (MIDORI_LOCATION_ACTION (action), title); | ||
1060 | 719 | if (custom_title && *custom_title) | 747 | if (custom_title && *custom_title) |
1061 | 720 | gtk_window_set_title (GTK_WINDOW (browser), custom_title); | 748 | gtk_window_set_title (GTK_WINDOW (browser), custom_title); |
1062 | 721 | else if (katze_object_get_boolean (browser->settings, "enable-private-browsing")) | 749 | else if (katze_object_get_boolean (browser->settings, "enable-private-browsing")) |
1063 | @@ -885,14 +913,14 @@ | |||
1064 | 885 | gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo)); | 913 | gtk_cell_layout_clear (GTK_CELL_LAYOUT (combo)); |
1065 | 886 | 914 | ||
1066 | 887 | renderer = gtk_cell_renderer_pixbuf_new (); | 915 | renderer = gtk_cell_renderer_pixbuf_new (); |
1068 | 888 | g_object_set (G_OBJECT (renderer), | 916 | g_object_set (G_OBJECT (renderer), |
1069 | 889 | "stock-id", GTK_STOCK_DIRECTORY, | 917 | "stock-id", GTK_STOCK_DIRECTORY, |
1070 | 890 | "stock-size", GTK_ICON_SIZE_MENU, | 918 | "stock-size", GTK_ICON_SIZE_MENU, |
1071 | 891 | NULL); | 919 | NULL); |
1072 | 892 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE); | 920 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE); |
1073 | 893 | 921 | ||
1074 | 894 | renderer = katze_cell_renderer_combobox_text_new (); | 922 | renderer = katze_cell_renderer_combobox_text_new (); |
1076 | 895 | g_object_set (G_OBJECT (renderer), | 923 | g_object_set (G_OBJECT (renderer), |
1077 | 896 | "width-chars", 40, /* FIXME: figure out a way to define an acceptable string length */ | 924 | "width-chars", 40, /* FIXME: figure out a way to define an acceptable string length */ |
1078 | 897 | "ellipsize", PANGO_ELLIPSIZE_END, | 925 | "ellipsize", PANGO_ELLIPSIZE_END, |
1079 | 898 | "unfolded-text", _("Select [text]"), | 926 | "unfolded-text", _("Select [text]"), |
1080 | @@ -916,7 +944,7 @@ | |||
1081 | 916 | folders = g_list_append (folders, folder); | 944 | folders = g_list_append (folders, folder); |
1082 | 917 | } | 945 | } |
1083 | 918 | 946 | ||
1085 | 919 | sqlite3_clear_bindings (statement); | 947 | sqlite3_clear_bindings (statement); |
1086 | 920 | sqlite3_reset (statement); | 948 | sqlite3_reset (statement); |
1087 | 921 | } | 949 | } |
1088 | 922 | 950 | ||
1089 | @@ -1025,7 +1053,7 @@ | |||
1090 | 1025 | static gint64 | 1053 | static gint64 |
1091 | 1026 | midori_bookmark_folder_button_get_active (GtkWidget* combo) | 1054 | midori_bookmark_folder_button_get_active (GtkWidget* combo) |
1092 | 1027 | { | 1055 | { |
1094 | 1028 | gint64 id = 0; | 1056 | gint64 id = -1; |
1095 | 1029 | GtkTreeIter iter; | 1057 | GtkTreeIter iter; |
1096 | 1030 | 1058 | ||
1097 | 1031 | g_return_val_if_fail (GTK_IS_COMBO_BOX (combo), 0); | 1059 | g_return_val_if_fail (GTK_IS_COMBO_BOX (combo), 0); |
1098 | @@ -1902,6 +1930,8 @@ | |||
1099 | 1902 | KatzeItem* item = midori_view_get_proxy_item (MIDORI_VIEW (view)); | 1930 | KatzeItem* item = midori_view_get_proxy_item (MIDORI_VIEW (view)); |
1100 | 1903 | guint n; | 1931 | guint n; |
1101 | 1904 | 1932 | ||
1102 | 1933 | g_object_set (view, "dnd-targets", browser->bookmarkbar_dnd_control.source_targets, NULL); | ||
1103 | 1934 | |||
1104 | 1905 | midori_browser_connect_tab (browser, view); | 1935 | midori_browser_connect_tab (browser, view); |
1105 | 1906 | 1936 | ||
1106 | 1907 | if (!katze_item_get_meta_boolean (item, "append") && | 1937 | if (!katze_item_get_meta_boolean (item, "append") && |
1107 | @@ -3107,29 +3137,17 @@ | |||
1108 | 3107 | KatzeArray* folder, | 3137 | KatzeArray* folder, |
1109 | 3108 | MidoriBrowser* browser) | 3138 | MidoriBrowser* browser) |
1110 | 3109 | { | 3139 | { |
1111 | 3110 | KatzeArray* bookmarks; | ||
1112 | 3111 | const gchar* id = katze_item_get_meta_string (KATZE_ITEM (folder), "id"); | ||
1113 | 3112 | gchar* condition; | ||
1114 | 3113 | |||
1115 | 3114 | if (browser->bookmarks == NULL) | 3140 | if (browser->bookmarks == NULL) |
1116 | 3115 | return FALSE; | 3141 | return FALSE; |
1117 | 3116 | 3142 | ||
1127 | 3117 | if (id == NULL) | 3143 | midori_bookmarks_db_populate_folder (browser->bookmarks, folder); |
1119 | 3118 | condition = "parentid is NULL"; | ||
1120 | 3119 | else | ||
1121 | 3120 | condition = "parentid = %q"; | ||
1122 | 3121 | |||
1123 | 3122 | bookmarks = midori_bookmarks_db_query_recursive (browser->bookmarks, | ||
1124 | 3123 | "id, title, parentid, uri, app, pos_panel, pos_bar", condition, id, FALSE); | ||
1125 | 3124 | if (!bookmarks) | ||
1126 | 3125 | return FALSE; | ||
1128 | 3126 | 3144 | ||
1129 | 3127 | /* Clear items from dummy array here */ | 3145 | /* Clear items from dummy array here */ |
1130 | 3128 | gtk_container_foreach (GTK_CONTAINER (menu), | 3146 | gtk_container_foreach (GTK_CONTAINER (menu), |
1131 | 3129 | (GtkCallback)(gtk_widget_destroy), NULL); | 3147 | (GtkCallback)(gtk_widget_destroy), NULL); |
1132 | 3130 | 3148 | ||
1133 | 3131 | /* "Import Bookmarks" and "Export Bookmarks" at the top */ | 3149 | /* "Import Bookmarks" and "Export Bookmarks" at the top */ |
1135 | 3132 | if (id == NULL) | 3150 | if (folder == KATZE_ARRAY (browser->bookmarks)) |
1136 | 3133 | { | 3151 | { |
1137 | 3134 | GtkWidget* menuitem; | 3152 | GtkWidget* menuitem; |
1138 | 3135 | menuitem = gtk_action_create_menu_item (_action_by_name (browser, "BookmarksImport")); | 3153 | menuitem = gtk_action_create_menu_item (_action_by_name (browser, "BookmarksImport")); |
1139 | @@ -3143,7 +3161,7 @@ | |||
1140 | 3143 | gtk_widget_show (menuitem); | 3161 | gtk_widget_show (menuitem); |
1141 | 3144 | } | 3162 | } |
1142 | 3145 | 3163 | ||
1144 | 3146 | if (katze_array_is_empty (bookmarks)) | 3164 | if (katze_array_is_empty (folder)) |
1145 | 3147 | { | 3165 | { |
1146 | 3148 | GtkWidget* menuitem = gtk_image_menu_item_new_with_label (_("Empty")); | 3166 | GtkWidget* menuitem = gtk_image_menu_item_new_with_label (_("Empty")); |
1147 | 3149 | gtk_widget_set_sensitive (menuitem, FALSE); | 3167 | gtk_widget_set_sensitive (menuitem, FALSE); |
1148 | @@ -3152,7 +3170,7 @@ | |||
1149 | 3152 | return TRUE; | 3170 | return TRUE; |
1150 | 3153 | } | 3171 | } |
1151 | 3154 | 3172 | ||
1153 | 3155 | katze_array_action_generate_menu (KATZE_ARRAY_ACTION (action), bookmarks, | 3173 | katze_array_action_generate_menu (KATZE_ARRAY_ACTION (action), folder, |
1154 | 3156 | menu, GTK_WIDGET (browser)); | 3174 | menu, GTK_WIDGET (browser)); |
1155 | 3157 | return TRUE; | 3175 | return TRUE; |
1156 | 3158 | } | 3176 | } |
1157 | @@ -4502,7 +4520,7 @@ | |||
1158 | 4502 | 4520 | ||
1159 | 4503 | error = NULL; | 4521 | error = NULL; |
1160 | 4504 | bookmarks = midori_bookmarks_db_query_recursive (browser->bookmarks, | 4522 | bookmarks = midori_bookmarks_db_query_recursive (browser->bookmarks, |
1162 | 4505 | "*", "parentid IS NULL", NULL, TRUE); | 4523 | "*", "parentid IS NULL", NULL, NULL, TRUE); |
1163 | 4506 | if (!midori_array_to_file (bookmarks, path, format, &error)) | 4524 | if (!midori_array_to_file (bookmarks, path, format, &error)) |
1164 | 4507 | { | 4525 | { |
1165 | 4508 | sokoke_message_dialog (GTK_MESSAGE_ERROR, | 4526 | sokoke_message_dialog (GTK_MESSAGE_ERROR, |
1166 | @@ -4903,6 +4921,8 @@ | |||
1167 | 4903 | uri = midori_view_get_display_uri (new_view); | 4921 | uri = midori_view_get_display_uri (new_view); |
1168 | 4904 | midori_browser_set_title (browser, midori_view_get_display_title (new_view)); | 4922 | midori_browser_set_title (browser, midori_view_get_display_title (new_view)); |
1169 | 4905 | action = _action_by_name (browser, "Location"); | 4923 | action = _action_by_name (browser, "Location"); |
1170 | 4924 | midori_location_action_set_icon (MIDORI_LOCATION_ACTION (action), midori_view_get_icon_uri (new_view)); | ||
1171 | 4925 | midori_location_action_set_title (MIDORI_LOCATION_ACTION (action), midori_view_get_display_title (new_view)); | ||
1172 | 4906 | midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri); | 4926 | midori_location_action_set_text (MIDORI_LOCATION_ACTION (action), uri); |
1173 | 4907 | if (midori_paths_get_runtime_mode () == MIDORI_RUNTIME_MODE_APP) | 4927 | if (midori_paths_get_runtime_mode () == MIDORI_RUNTIME_MODE_APP) |
1174 | 4908 | gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (new_view)); | 4928 | gtk_window_set_icon (GTK_WINDOW (browser), midori_view_get_icon (new_view)); |
1175 | @@ -5876,8 +5896,6 @@ | |||
1176 | 5876 | g_object_connect (action, | 5896 | g_object_connect (action, |
1177 | 5877 | "signal::populate-popup", | 5897 | "signal::populate-popup", |
1178 | 5878 | _action_tools_populate_popup, browser, | 5898 | _action_tools_populate_popup, browser, |
1179 | 5879 | "signal::activate-item-alt", | ||
1180 | 5880 | midori_bookmarkbar_activate_item_alt, browser, | ||
1181 | 5881 | NULL); | 5899 | NULL); |
1182 | 5882 | gtk_action_group_add_action (browser->action_group, action); | 5900 | gtk_action_group_add_action (browser->action_group, action); |
1183 | 5883 | g_object_unref (action); | 5901 | g_object_unref (action); |
1184 | @@ -6003,7 +6021,11 @@ | |||
1185 | 6003 | g_signal_connect (browser->bookmarkbar, "popup-context-menu", | 6021 | g_signal_connect (browser->bookmarkbar, "popup-context-menu", |
1186 | 6004 | G_CALLBACK (midori_browser_toolbar_popup_context_menu_cb), browser); | 6022 | G_CALLBACK (midori_browser_toolbar_popup_context_menu_cb), browser); |
1187 | 6005 | 6023 | ||
1189 | 6006 | /* Create the panel */ | 6024 | bookmarkbar_dnd_control_init (&browser->bookmarkbar_dnd_control, browser); |
1190 | 6025 | bookmarkbar_dnd_control_install (&browser->bookmarkbar_dnd_control, | ||
1191 | 6026 | GTK_TOOLBAR (browser->bookmarkbar)); | ||
1192 | 6027 | |||
1193 | 6028 | /* Create the panel */ | ||
1194 | 6007 | hpaned = gtk_hpaned_new (); | 6029 | hpaned = gtk_hpaned_new (); |
1195 | 6008 | g_signal_connect (hpaned, "notify::position", | 6030 | g_signal_connect (hpaned, "notify::position", |
1196 | 6009 | G_CALLBACK (midori_panel_notify_position_cb), | 6031 | G_CALLBACK (midori_panel_notify_position_cb), |
1197 | @@ -6101,6 +6123,8 @@ | |||
1198 | 6101 | { | 6123 | { |
1199 | 6102 | MidoriBrowser* browser = MIDORI_BROWSER (object); | 6124 | MidoriBrowser* browser = MIDORI_BROWSER (object); |
1200 | 6103 | 6125 | ||
1201 | 6126 | bookmarkbar_dnd_control_finalize (&browser->bookmarkbar_dnd_control); | ||
1202 | 6127 | |||
1203 | 6104 | katze_assign (browser->statusbar_text, NULL); | 6128 | katze_assign (browser->statusbar_text, NULL); |
1204 | 6105 | 6129 | ||
1205 | 6106 | katze_object_assign (browser->settings, NULL); | 6130 | katze_object_assign (browser->settings, NULL); |
1206 | @@ -6624,7 +6648,8 @@ | |||
1207 | 6624 | 6648 | ||
1208 | 6625 | static void | 6649 | static void |
1209 | 6626 | midori_bookmarkbar_insert_item (GtkWidget* toolbar, | 6650 | midori_bookmarkbar_insert_item (GtkWidget* toolbar, |
1211 | 6627 | KatzeItem* item) | 6651 | KatzeItem* item, |
1212 | 6652 | gint pos) | ||
1213 | 6628 | { | 6653 | { |
1214 | 6629 | MidoriBrowser* browser = midori_browser_get_for_widget (toolbar); | 6654 | MidoriBrowser* browser = midori_browser_get_for_widget (toolbar); |
1215 | 6630 | GtkAction* action = _action_by_name (browser, "Bookmarks"); | 6655 | GtkAction* action = _action_by_name (browser, "Bookmarks"); |
1216 | @@ -6643,19 +6668,19 @@ | |||
1217 | 6643 | else /* Separator */ | 6668 | else /* Separator */ |
1218 | 6644 | gtk_tool_item_set_use_drag_window (toolitem, TRUE); | 6669 | gtk_tool_item_set_use_drag_window (toolitem, TRUE); |
1219 | 6645 | 6670 | ||
1220 | 6671 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, pos); | ||
1221 | 6646 | gtk_widget_show (GTK_WIDGET (toolitem)); | 6672 | gtk_widget_show (GTK_WIDGET (toolitem)); |
1222 | 6647 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); | ||
1223 | 6648 | } | 6673 | } |
1224 | 6649 | 6674 | ||
1225 | 6650 | static void | 6675 | static void |
1226 | 6651 | midori_bookmarkbar_add_item_cb (KatzeArray* bookmarks, | 6676 | midori_bookmarkbar_add_item_cb (KatzeArray* bookmarks, |
1229 | 6652 | KatzeItem* item, | 6677 | KatzeItem* item, |
1230 | 6653 | MidoriBrowser* browser) | 6678 | MidoriBrowser* browser) |
1231 | 6654 | { | 6679 | { |
1232 | 6655 | if (gtk_widget_get_visible (browser->bookmarkbar)) | 6680 | if (gtk_widget_get_visible (browser->bookmarkbar)) |
1233 | 6656 | midori_bookmarkbar_populate (browser); | 6681 | midori_bookmarkbar_populate (browser); |
1234 | 6657 | else if (katze_item_get_meta_boolean (item, "toolbar")) | 6682 | else if (katze_item_get_meta_boolean (item, "toolbar")) |
1236 | 6658 | _action_set_active (browser, "Bookmarkbar", TRUE); | 6683 | _action_set_active (browser, "Bookmarkbar", TRUE); |
1237 | 6659 | midori_browser_update_history (item, "bookmark", "created"); | 6684 | midori_browser_update_history (item, "bookmark", "created"); |
1238 | 6660 | } | 6685 | } |
1239 | 6661 | 6686 | ||
1240 | @@ -6702,7 +6727,7 @@ | |||
1241 | 6702 | gtk_separator_tool_item_new (), -1); | 6727 | gtk_separator_tool_item_new (), -1); |
1242 | 6703 | 6728 | ||
1243 | 6704 | array = midori_bookmarks_db_query_recursive (browser->bookmarks, | 6729 | array = midori_bookmarks_db_query_recursive (browser->bookmarks, |
1245 | 6705 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "toolbar = 1", NULL, FALSE); | 6730 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "toolbar = 1", NULL, "pos_bar ASC", FALSE); |
1246 | 6706 | if (!array) | 6731 | if (!array) |
1247 | 6707 | { | 6732 | { |
1248 | 6708 | _action_set_sensitive (browser, "BookmarkAdd", FALSE); | 6733 | _action_set_sensitive (browser, "BookmarkAdd", FALSE); |
1249 | @@ -6712,10 +6737,12 @@ | |||
1250 | 6712 | 6737 | ||
1251 | 6713 | KATZE_ARRAY_FOREACH_ITEM (item, array) | 6738 | KATZE_ARRAY_FOREACH_ITEM (item, array) |
1252 | 6714 | { | 6739 | { |
1254 | 6715 | midori_bookmarkbar_insert_item (browser->bookmarkbar, item); | 6740 | midori_bookmarkbar_insert_item (browser->bookmarkbar, item, -1); |
1255 | 6716 | } | 6741 | } |
1256 | 6717 | _action_set_sensitive (browser, "BookmarkAdd", TRUE); | 6742 | _action_set_sensitive (browser, "BookmarkAdd", TRUE); |
1257 | 6718 | _action_set_sensitive (browser, "BookmarkFolderAdd", TRUE); | 6743 | _action_set_sensitive (browser, "BookmarkFolderAdd", TRUE); |
1258 | 6744 | |||
1259 | 6745 | midori_bookmarkbar_position_items (browser->bookmarkbar); | ||
1260 | 6719 | } | 6746 | } |
1261 | 6720 | 6747 | ||
1262 | 6721 | static void | 6748 | static void |
1263 | @@ -6756,6 +6783,10 @@ | |||
1264 | 6756 | midori_bookmarkbar_remove_item_cb, browser); | 6783 | midori_bookmarkbar_remove_item_cb, browser); |
1265 | 6757 | } | 6784 | } |
1266 | 6758 | 6785 | ||
1267 | 6786 | g_object_set (G_OBJECT (_action_by_name (browser, "Bookmarks")), | ||
1268 | 6787 | "array", KATZE_ARRAY (bookmarks), | ||
1269 | 6788 | NULL); | ||
1270 | 6789 | |||
1271 | 6759 | settings = midori_browser_get_settings (browser); | 6790 | settings = midori_browser_get_settings (browser); |
1272 | 6760 | g_signal_handlers_disconnect_by_func (settings, | 6791 | g_signal_handlers_disconnect_by_func (settings, |
1273 | 6761 | midori_browser_show_bookmarkbar_notify_value_cb, browser); | 6792 | midori_browser_show_bookmarkbar_notify_value_cb, browser); |
1274 | @@ -7481,3 +7512,331 @@ | |||
1275 | 7481 | 7512 | ||
1276 | 7482 | g_signal_emit (browser, signals[QUIT], 0); | 7513 | g_signal_emit (browser, signals[QUIT], 0); |
1277 | 7483 | } | 7514 | } |
1278 | 7515 | |||
1279 | 7516 | static void | ||
1280 | 7517 | bookmarkbar_drag_dest_control_init (BookmarkbarDragDestControl* control) | ||
1281 | 7518 | { | ||
1282 | 7519 | control->highligth_item = NULL; | ||
1283 | 7520 | control->hovering = FALSE; | ||
1284 | 7521 | } | ||
1285 | 7522 | |||
1286 | 7523 | static GtkTargetEntry bookmarkbar_dnd_target_entries[]= | ||
1287 | 7524 | { | ||
1288 | 7525 | {"KATZE_ARRAY", GTK_TARGET_SAME_APP, 0}, | ||
1289 | 7526 | }; | ||
1290 | 7527 | |||
1291 | 7528 | #define BOOKMARKBAR_DND_NB_TARGET_ENTRIES \ | ||
1292 | 7529 | G_N_ELEMENTS (bookmarkbar_dnd_target_entries) | ||
1293 | 7530 | |||
1294 | 7531 | static void | ||
1295 | 7532 | bookmarkbar_dnd_control_init (BookmarkbarDNDControl* control, MidoriBrowser* browser) | ||
1296 | 7533 | { | ||
1297 | 7534 | bookmarkbar_drag_dest_control_init (&control->drag_dest_control); | ||
1298 | 7535 | |||
1299 | 7536 | control->source_targets = gtk_target_list_new ( | ||
1300 | 7537 | bookmarkbar_dnd_target_entries, BOOKMARKBAR_DND_NB_TARGET_ENTRIES); | ||
1301 | 7538 | gtk_target_list_add_uri_targets (control->source_targets, 0); | ||
1302 | 7539 | gtk_target_list_add_text_targets (control->source_targets, 0); | ||
1303 | 7540 | |||
1304 | 7541 | control->dest_targets = gtk_target_list_new ( | ||
1305 | 7542 | bookmarkbar_dnd_target_entries, BOOKMARKBAR_DND_NB_TARGET_ENTRIES); | ||
1306 | 7543 | |||
1307 | 7544 | g_object_set (_action_by_name (browser, "Bookmarks"), "dnd-targets", control->source_targets, NULL); | ||
1308 | 7545 | g_object_set (_action_by_name (browser, "Location"), "dnd-targets", control->source_targets, NULL); | ||
1309 | 7546 | } | ||
1310 | 7547 | |||
1311 | 7548 | static void | ||
1312 | 7549 | bookmarkbar_dnd_control_finalize (BookmarkbarDNDControl* control) | ||
1313 | 7550 | { | ||
1314 | 7551 | gtk_target_list_unref (control->source_targets); | ||
1315 | 7552 | gtk_target_list_unref (control->dest_targets); | ||
1316 | 7553 | control->source_targets = NULL; | ||
1317 | 7554 | control->dest_targets = NULL; | ||
1318 | 7555 | } | ||
1319 | 7556 | |||
1320 | 7557 | |||
1321 | 7558 | static GtkToolItem* | ||
1322 | 7559 | bookmarkbar_drag_highlight_item (GdkDragContext *context) | ||
1323 | 7560 | { | ||
1324 | 7561 | |||
1325 | 7562 | GtkToolItem* highlight_item = NULL; | ||
1326 | 7563 | GtkWidget* source = gtk_drag_get_source_widget (context); | ||
1327 | 7564 | |||
1328 | 7565 | if (source) | ||
1329 | 7566 | { | ||
1330 | 7567 | KatzeItem* item = (KatzeItem*)g_object_get_data (G_OBJECT (source), "KatzeItem"); | ||
1331 | 7568 | |||
1332 | 7569 | if (!item && GTK_IS_TOOL_ITEM (gtk_widget_get_parent (source))) | ||
1333 | 7570 | item = (KatzeItem*)g_object_get_data (G_OBJECT (gtk_widget_get_parent (source)), "KatzeItem"); | ||
1334 | 7571 | |||
1335 | 7572 | if (KATZE_ITEM_IS_BOOKMARK (item)) | ||
1336 | 7573 | highlight_item = gtk_tool_button_new (NULL, ""); | ||
1337 | 7574 | else if (KATZE_ITEM_IS_FOLDER (item)) | ||
1338 | 7575 | highlight_item = gtk_toggle_tool_button_new (); | ||
1339 | 7576 | |||
1340 | 7577 | if (highlight_item) | ||
1341 | 7578 | { | ||
1342 | 7579 | GtkToolButton* toolbutton = GTK_TOOL_BUTTON (highlight_item); | ||
1343 | 7580 | GtkWidget* image = katze_item_get_image (item, GTK_WIDGET (highlight_item)); | ||
1344 | 7581 | const gchar* title = katze_item_get_name (item); | ||
1345 | 7582 | GtkWidget* label = gtk_label_new (NULL); | ||
1346 | 7583 | |||
1347 | 7584 | gtk_widget_show (image); | ||
1348 | 7585 | |||
1349 | 7586 | if (!title || !*title) | ||
1350 | 7587 | title = katze_item_get_uri (item); | ||
1351 | 7588 | |||
1352 | 7589 | /* FIXME: Should text direction be respected here? */ | ||
1353 | 7590 | gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); | ||
1354 | 7591 | gtk_label_set_max_width_chars (GTK_LABEL (label), 25); | ||
1355 | 7592 | gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE); | ||
1356 | 7593 | gtk_label_set_text (GTK_LABEL (label), title); | ||
1357 | 7594 | gtk_widget_show (label); | ||
1358 | 7595 | |||
1359 | 7596 | gtk_tool_button_set_icon_widget (toolbutton, image); | ||
1360 | 7597 | gtk_tool_button_set_label_widget (toolbutton, label); | ||
1361 | 7598 | |||
1362 | 7599 | gtk_tool_item_set_visible_horizontal (highlight_item, TRUE); | ||
1363 | 7600 | gtk_tool_item_set_visible_vertical (highlight_item, TRUE); | ||
1364 | 7601 | gtk_tool_item_set_is_important (highlight_item, TRUE); | ||
1365 | 7602 | } | ||
1366 | 7603 | } | ||
1367 | 7604 | |||
1368 | 7605 | if (!highlight_item) | ||
1369 | 7606 | highlight_item = gtk_separator_tool_item_new (); | ||
1370 | 7607 | |||
1371 | 7608 | gtk_widget_show (GTK_WIDGET (highlight_item)); | ||
1372 | 7609 | return highlight_item; | ||
1373 | 7610 | } | ||
1374 | 7611 | |||
1375 | 7612 | static gboolean | ||
1376 | 7613 | bookmarkbar_drag_dest_drag_motion_cb (GtkWidget *widget, | ||
1377 | 7614 | GdkDragContext *context, | ||
1378 | 7615 | gint x, gint y, guint t, | ||
1379 | 7616 | BookmarkbarDragDestControl* control) | ||
1380 | 7617 | { | ||
1381 | 7618 | GtkToolbar* toolbar = GTK_TOOLBAR (widget); | ||
1382 | 7619 | gint n = gtk_toolbar_get_drop_index (toolbar, x, y); | ||
1383 | 7620 | |||
1384 | 7621 | if (!control->highligth_item) | ||
1385 | 7622 | { | ||
1386 | 7623 | GtkToolItem* highlight_item = bookmarkbar_drag_highlight_item (context); | ||
1387 | 7624 | g_object_ref (highlight_item); | ||
1388 | 7625 | |||
1389 | 7626 | gtk_toolbar_set_drop_highlight_item (toolbar, | ||
1390 | 7627 | highlight_item, | ||
1391 | 7628 | n); | ||
1392 | 7629 | control->highligth_item = highlight_item; | ||
1393 | 7630 | control->n = n; | ||
1394 | 7631 | } | ||
1395 | 7632 | else if (n != control->n) | ||
1396 | 7633 | { | ||
1397 | 7634 | gtk_toolbar_set_drop_highlight_item (toolbar, | ||
1398 | 7635 | control->highligth_item, | ||
1399 | 7636 | n); | ||
1400 | 7637 | control->n = n; | ||
1401 | 7638 | } | ||
1402 | 7639 | return FALSE; | ||
1403 | 7640 | } | ||
1404 | 7641 | |||
1405 | 7642 | static void | ||
1406 | 7643 | bookmarkbar_drag_dest_drag_leave_cb (GtkWidget *widget, | ||
1407 | 7644 | GdkDragContext *context, | ||
1408 | 7645 | guint time, | ||
1409 | 7646 | BookmarkbarDragDestControl* control) | ||
1410 | 7647 | { | ||
1411 | 7648 | GtkToolbar* toolbar = GTK_TOOLBAR (widget); | ||
1412 | 7649 | |||
1413 | 7650 | if (control->highligth_item) | ||
1414 | 7651 | { | ||
1415 | 7652 | gtk_toolbar_set_drop_highlight_item (toolbar, NULL, -1); | ||
1416 | 7653 | g_object_unref (control->highligth_item); | ||
1417 | 7654 | control->highligth_item = NULL; | ||
1418 | 7655 | } | ||
1419 | 7656 | } | ||
1420 | 7657 | |||
1421 | 7658 | void | ||
1422 | 7659 | midori_bookmarkbar_position_items (GtkWidget *widget) | ||
1423 | 7660 | { | ||
1424 | 7661 | GtkToolbar* toolbar = GTK_TOOLBAR (widget); | ||
1425 | 7662 | MidoriBrowser* browser = midori_browser_get_for_widget (widget); | ||
1426 | 7663 | gint n = gtk_toolbar_get_n_items (toolbar); | ||
1427 | 7664 | gint i; | ||
1428 | 7665 | gint pos; | ||
1429 | 7666 | |||
1430 | 7667 | pos = 0; | ||
1431 | 7668 | for (i = 0; i < n ; i++ ) | ||
1432 | 7669 | { | ||
1433 | 7670 | GtkWidget* toolitem = GTK_WIDGET (gtk_toolbar_get_nth_item (toolbar, i)); | ||
1434 | 7671 | KatzeItem* local_item = (KatzeItem*)g_object_get_data (G_OBJECT (toolitem), "KatzeItem"); | ||
1435 | 7672 | |||
1436 | 7673 | if (!KATZE_IS_ITEM (local_item)) | ||
1437 | 7674 | continue; | ||
1438 | 7675 | |||
1439 | 7676 | if (pos != katze_item_get_meta_integer (local_item, "pos_bar")) | ||
1440 | 7677 | katze_item_set_meta_integer (local_item, "pos_bar", pos); | ||
1441 | 7678 | |||
1442 | 7679 | midori_bookmarks_db_update_item (browser->bookmarks, local_item); | ||
1443 | 7680 | |||
1444 | 7681 | pos++; | ||
1445 | 7682 | } | ||
1446 | 7683 | } | ||
1447 | 7684 | |||
1448 | 7685 | static void | ||
1449 | 7686 | bookmarkbar_drag_dest_drag_data_received_cb (GtkWidget *widget, | ||
1450 | 7687 | GdkDragContext *drag_context, | ||
1451 | 7688 | gint x, | ||
1452 | 7689 | gint y, | ||
1453 | 7690 | GtkSelectionData *data, | ||
1454 | 7691 | guint info, | ||
1455 | 7692 | guint time, | ||
1456 | 7693 | BookmarkbarDragDestControl* control) | ||
1457 | 7694 | { | ||
1458 | 7695 | GtkToolbar* toolbar = GTK_TOOLBAR (widget); | ||
1459 | 7696 | MidoriBrowser* browser = midori_browser_get_for_widget (widget); | ||
1460 | 7697 | gboolean success = FALSE; | ||
1461 | 7698 | gboolean delete = FALSE; | ||
1462 | 7699 | |||
1463 | 7700 | g_assert (browser); | ||
1464 | 7701 | |||
1465 | 7702 | g_signal_handlers_block_by_func (browser->bookmarks, | ||
1466 | 7703 | midori_bookmarkbar_add_item_cb, browser); | ||
1467 | 7704 | g_signal_handlers_block_by_func (browser->bookmarks, | ||
1468 | 7705 | midori_bookmarkbar_update_item_cb, browser); | ||
1469 | 7706 | g_signal_handlers_block_by_func (browser->bookmarks, | ||
1470 | 7707 | midori_bookmarkbar_remove_item_cb, browser); | ||
1471 | 7708 | |||
1472 | 7709 | if (gtk_selection_data_get_length (data) >= 0) | ||
1473 | 7710 | { | ||
1474 | 7711 | switch (gdk_drag_context_get_selected_action (drag_context)) | ||
1475 | 7712 | { | ||
1476 | 7713 | case GDK_ACTION_MOVE: | ||
1477 | 7714 | delete = TRUE; | ||
1478 | 7715 | case GDK_ACTION_COPY: | ||
1479 | 7716 | if (gtk_selection_data_get_format (data) == 8) | ||
1480 | 7717 | { | ||
1481 | 7718 | KatzeArray *array = katze_array_from_selection_data (data); | ||
1482 | 7719 | |||
1483 | 7720 | if (array) | ||
1484 | 7721 | { | ||
1485 | 7722 | KatzeItem *item; | ||
1486 | 7723 | KATZE_ARRAY_FOREACH_ITEM (item, array) | ||
1487 | 7724 | { | ||
1488 | 7725 | gint old_pos = gtk_toolbar_get_n_items(toolbar); | ||
1489 | 7726 | gint dest_pos = gtk_toolbar_get_drop_index (toolbar, x, y); | ||
1490 | 7727 | gboolean is_bookmark = katze_item_get_meta_string (item, "id") ? TRUE : FALSE ; | ||
1491 | 7728 | gboolean from_toolbar = is_bookmark && katze_item_get_meta_boolean (item, "toolbar"); | ||
1492 | 7729 | |||
1493 | 7730 | if (midori_debug("bookmarks")) | ||
1494 | 7731 | { | ||
1495 | 7732 | g_print ("bookmarkbar received KATZE_ITEM(bookmark:%d, toolbar:%d, title:%s) \n", | ||
1496 | 7733 | is_bookmark, from_toolbar, katze_item_get_name (item)); | ||
1497 | 7734 | } | ||
1498 | 7735 | |||
1499 | 7736 | if (from_toolbar) | ||
1500 | 7737 | { | ||
1501 | 7738 | GtkToolItem* toolitem = NULL; | ||
1502 | 7739 | KatzeItem* local_item = NULL; | ||
1503 | 7740 | |||
1504 | 7741 | old_pos = katze_item_get_meta_integer (item, "pos_bar"); | ||
1505 | 7742 | |||
1506 | 7743 | if ((dest_pos != old_pos) | ||
1507 | 7744 | && (toolitem = gtk_toolbar_get_nth_item (toolbar, | ||
1508 | 7745 | old_pos)) | ||
1509 | 7746 | && (local_item = (KatzeItem*)g_object_get_data ( | ||
1510 | 7747 | G_OBJECT (toolitem), "KatzeItem"))) | ||
1511 | 7748 | { | ||
1512 | 7749 | midori_bookmarkbar_insert_item (widget, | ||
1513 | 7750 | local_item, dest_pos); | ||
1514 | 7751 | |||
1515 | 7752 | if (old_pos < dest_pos) | ||
1516 | 7753 | old_pos++; | ||
1517 | 7754 | |||
1518 | 7755 | /* FIXME: force a move */ | ||
1519 | 7756 | delete = TRUE; | ||
1520 | 7757 | } | ||
1521 | 7758 | else | ||
1522 | 7759 | delete = FALSE; | ||
1523 | 7760 | } | ||
1524 | 7761 | else if (!is_bookmark) | ||
1525 | 7762 | { | ||
1526 | 7763 | item = katze_item_copy (item); | ||
1527 | 7764 | |||
1528 | 7765 | katze_item_set_meta_integer (item, "toolbar", TRUE); | ||
1529 | 7766 | |||
1530 | 7767 | midori_bookmarkbar_insert_item (widget, | ||
1531 | 7768 | item, dest_pos); | ||
1532 | 7769 | |||
1533 | 7770 | midori_bookmarks_db_add_item (browser->bookmarks, item); | ||
1534 | 7771 | |||
1535 | 7772 | if (old_pos > dest_pos) | ||
1536 | 7773 | old_pos++; | ||
1537 | 7774 | |||
1538 | 7775 | delete = FALSE; | ||
1539 | 7776 | } | ||
1540 | 7777 | else | ||
1541 | 7778 | { | ||
1542 | 7779 | katze_item_set_meta_integer (item, "toolbar", TRUE); | ||
1543 | 7780 | |||
1544 | 7781 | midori_bookmarkbar_insert_item (widget, | ||
1545 | 7782 | item, dest_pos); | ||
1546 | 7783 | |||
1547 | 7784 | if (old_pos > dest_pos) | ||
1548 | 7785 | old_pos++; | ||
1549 | 7786 | |||
1550 | 7787 | delete = FALSE; | ||
1551 | 7788 | } | ||
1552 | 7789 | } | ||
1553 | 7790 | |||
1554 | 7791 | g_object_unref (array); | ||
1555 | 7792 | success = TRUE; | ||
1556 | 7793 | break; | ||
1557 | 7794 | } | ||
1558 | 7795 | } | ||
1559 | 7796 | default: | ||
1560 | 7797 | break; | ||
1561 | 7798 | } | ||
1562 | 7799 | } | ||
1563 | 7800 | |||
1564 | 7801 | if (!success) | ||
1565 | 7802 | delete = FALSE; | ||
1566 | 7803 | |||
1567 | 7804 | gtk_drag_finish (drag_context, success, delete, time); | ||
1568 | 7805 | |||
1569 | 7806 | if (success && !delete) | ||
1570 | 7807 | { | ||
1571 | 7808 | midori_bookmarkbar_position_items (GTK_WIDGET (toolbar)); | ||
1572 | 7809 | } | ||
1573 | 7810 | |||
1574 | 7811 | g_signal_handlers_unblock_by_func (browser->bookmarks, | ||
1575 | 7812 | midori_bookmarkbar_add_item_cb, browser); | ||
1576 | 7813 | g_signal_handlers_unblock_by_func (browser->bookmarks, | ||
1577 | 7814 | midori_bookmarkbar_update_item_cb, browser); | ||
1578 | 7815 | g_signal_handlers_unblock_by_func (browser->bookmarks, | ||
1579 | 7816 | midori_bookmarkbar_remove_item_cb, browser); | ||
1580 | 7817 | } | ||
1581 | 7818 | |||
1582 | 7819 | static void | ||
1583 | 7820 | bookmarkbar_drag_dest_control_install (BookmarkbarDNDControl* control, | ||
1584 | 7821 | GtkToolbar* bookmarkbar) | ||
1585 | 7822 | { | ||
1586 | 7823 | GtkWidget* widget = GTK_WIDGET (bookmarkbar); | ||
1587 | 7824 | gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, NULL, 0, | ||
1588 | 7825 | GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_LINK); | ||
1589 | 7826 | gtk_drag_dest_set_target_list (widget, control->dest_targets); | ||
1590 | 7827 | g_signal_connect (bookmarkbar, "drag-motion", | ||
1591 | 7828 | G_CALLBACK (bookmarkbar_drag_dest_drag_motion_cb), | ||
1592 | 7829 | &control->drag_dest_control); | ||
1593 | 7830 | g_signal_connect (bookmarkbar, "drag-leave", | ||
1594 | 7831 | G_CALLBACK (bookmarkbar_drag_dest_drag_leave_cb), | ||
1595 | 7832 | &control->drag_dest_control); | ||
1596 | 7833 | g_signal_connect (bookmarkbar, "drag-data-received", | ||
1597 | 7834 | G_CALLBACK (bookmarkbar_drag_dest_drag_data_received_cb), | ||
1598 | 7835 | &control->drag_dest_control); | ||
1599 | 7836 | } | ||
1600 | 7837 | |||
1601 | 7838 | static void | ||
1602 | 7839 | bookmarkbar_dnd_control_install (BookmarkbarDNDControl* control, GtkToolbar* bookmarkbar) | ||
1603 | 7840 | { | ||
1604 | 7841 | bookmarkbar_drag_dest_control_install (control, bookmarkbar); | ||
1605 | 7842 | } | ||
1606 | 7484 | 7843 | ||
1607 | === modified file 'midori/midori-locationaction.c' | |||
1608 | --- midori/midori-locationaction.c 2013-11-05 14:51:49 +0000 | |||
1609 | +++ midori/midori-locationaction.c 2014-01-26 19:44:25 +0000 | |||
1610 | @@ -43,6 +43,8 @@ | |||
1611 | 43 | gint completion_index; | 43 | gint completion_index; |
1612 | 44 | GtkWidget* entry; | 44 | GtkWidget* entry; |
1613 | 45 | KatzeArray* history; | 45 | KatzeArray* history; |
1614 | 46 | KatzeItem* item; | ||
1615 | 47 | GtkTargetList* dnd_targets; | ||
1616 | 46 | }; | 48 | }; |
1617 | 47 | 49 | ||
1618 | 48 | struct _MidoriLocationActionClass | 50 | struct _MidoriLocationActionClass |
1619 | @@ -58,7 +60,8 @@ | |||
1620 | 58 | 60 | ||
1621 | 59 | PROP_PROGRESS, | 61 | PROP_PROGRESS, |
1622 | 60 | PROP_SECONDARY_ICON, | 62 | PROP_SECONDARY_ICON, |
1624 | 61 | PROP_HISTORY | 63 | PROP_HISTORY, |
1625 | 64 | PROP_DND_TARGETS | ||
1626 | 62 | }; | 65 | }; |
1627 | 63 | 66 | ||
1628 | 64 | enum | 67 | enum |
1629 | @@ -222,6 +225,22 @@ | |||
1630 | 222 | "The list of history items", | 225 | "The list of history items", |
1631 | 223 | KATZE_TYPE_ARRAY, | 226 | KATZE_TYPE_ARRAY, |
1632 | 224 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | 227 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
1633 | 228 | |||
1634 | 229 | /** | ||
1635 | 230 | * MidoriLocationAction:dnd-targets: | ||
1636 | 231 | * | ||
1637 | 232 | * GtkTargetList* the location action supports. | ||
1638 | 233 | * | ||
1639 | 234 | * Since: 0.5.2 | ||
1640 | 235 | **/ | ||
1641 | 236 | g_object_class_install_property (gobject_class, | ||
1642 | 237 | PROP_DND_TARGETS, | ||
1643 | 238 | g_param_spec_pointer ( | ||
1644 | 239 | "dnd-targets", | ||
1645 | 240 | "DNDTargets", | ||
1646 | 241 | "GtkTargetList* the location action supports", | ||
1647 | 242 | G_PARAM_READABLE|G_PARAM_WRITABLE)); | ||
1648 | 243 | |||
1649 | 225 | } | 244 | } |
1650 | 226 | 245 | ||
1651 | 227 | gchar* | 246 | gchar* |
1652 | @@ -813,6 +832,8 @@ | |||
1653 | 813 | { | 832 | { |
1654 | 814 | location_action->progress = 0.0; | 833 | location_action->progress = 0.0; |
1655 | 815 | location_action->completion_index = -1; | 834 | location_action->completion_index = -1; |
1656 | 835 | location_action->item = katze_item_new (); | ||
1657 | 836 | location_action->dnd_targets = NULL; | ||
1658 | 816 | } | 837 | } |
1659 | 817 | 838 | ||
1660 | 818 | static void | 839 | static void |
1661 | @@ -832,6 +853,8 @@ | |||
1662 | 832 | } | 853 | } |
1663 | 833 | katze_object_assign (location_action->history, NULL); | 854 | katze_object_assign (location_action->history, NULL); |
1664 | 834 | 855 | ||
1665 | 856 | g_object_unref (location_action->item); | ||
1666 | 857 | |||
1667 | 835 | G_OBJECT_CLASS (midori_location_action_parent_class)->finalize (object); | 858 | G_OBJECT_CLASS (midori_location_action_parent_class)->finalize (object); |
1668 | 836 | } | 859 | } |
1669 | 837 | 860 | ||
1670 | @@ -858,6 +881,9 @@ | |||
1671 | 858 | katze_assign (location_action->history, g_value_dup_object (value)); | 881 | katze_assign (location_action->history, g_value_dup_object (value)); |
1672 | 859 | break; | 882 | break; |
1673 | 860 | } | 883 | } |
1674 | 884 | case PROP_DND_TARGETS: | ||
1675 | 885 | location_action->dnd_targets = (GtkTargetList*)g_value_get_pointer (value); | ||
1676 | 886 | break; | ||
1677 | 861 | default: | 887 | default: |
1678 | 862 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 888 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1679 | 863 | break; | 889 | break; |
1680 | @@ -883,6 +909,9 @@ | |||
1681 | 883 | case PROP_HISTORY: | 909 | case PROP_HISTORY: |
1682 | 884 | g_value_set_object (value, location_action->history); | 910 | g_value_set_object (value, location_action->history); |
1683 | 885 | break; | 911 | break; |
1684 | 912 | case PROP_DND_TARGETS: | ||
1685 | 913 | g_value_set_pointer (value, location_action->dnd_targets); | ||
1686 | 914 | break; | ||
1687 | 886 | default: | 915 | default: |
1688 | 887 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 916 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1689 | 888 | break; | 917 | break; |
1690 | @@ -917,20 +946,19 @@ | |||
1691 | 917 | GtkSelectionData* data, | 946 | GtkSelectionData* data, |
1692 | 918 | guint info, | 947 | guint info, |
1693 | 919 | guint32 time, | 948 | guint32 time, |
1695 | 920 | GtkAction* action) | 949 | MidoriLocationAction* action) |
1696 | 921 | { | 950 | { |
1697 | 922 | if (gtk_entry_get_current_icon_drag_source (GTK_ENTRY (entry)) == GTK_ENTRY_ICON_PRIMARY) | 951 | if (gtk_entry_get_current_icon_drag_source (GTK_ENTRY (entry)) == GTK_ENTRY_ICON_PRIMARY) |
1698 | 923 | { | 952 | { |
1703 | 924 | const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry)); | 953 | katze_item_set_uri (action->item, gtk_entry_get_text (GTK_ENTRY (entry))); |
1704 | 925 | gchar** uris = g_strsplit (uri, uri, 1); | 954 | selection_data_from_katze_item (data, action->item); |
1701 | 926 | gtk_selection_data_set_uris (data, uris); | ||
1702 | 927 | g_strfreev (uris); | ||
1705 | 928 | } | 955 | } |
1706 | 929 | } | 956 | } |
1707 | 930 | 957 | ||
1708 | 931 | static GtkWidget* | 958 | static GtkWidget* |
1709 | 932 | midori_location_action_create_tool_item (GtkAction* action) | 959 | midori_location_action_create_tool_item (GtkAction* action) |
1710 | 933 | { | 960 | { |
1711 | 961 | MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action); | ||
1712 | 934 | GtkWidget* toolitem; | 962 | GtkWidget* toolitem; |
1713 | 935 | GtkWidget* alignment; | 963 | GtkWidget* alignment; |
1714 | 936 | GtkWidget* entry; | 964 | GtkWidget* entry; |
1715 | @@ -953,10 +981,18 @@ | |||
1716 | 953 | gtk_entry_set_icon_activatable (GTK_ENTRY (entry), | 981 | gtk_entry_set_icon_activatable (GTK_ENTRY (entry), |
1717 | 954 | GTK_ENTRY_ICON_SECONDARY, TRUE); | 982 | GTK_ENTRY_ICON_SECONDARY, TRUE); |
1718 | 955 | 983 | ||
1723 | 956 | targetlist = gtk_target_list_new (NULL, 0); | 984 | g_object_set_data (G_OBJECT (entry), "KatzeItem", MIDORI_LOCATION_ACTION (action)->item); |
1724 | 957 | gtk_target_list_add_uri_targets (targetlist, 0); | 985 | |
1725 | 958 | gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, targetlist, GDK_ACTION_ASK | GDK_ACTION_COPY | GDK_ACTION_LINK); | 986 | if (location_action->dnd_targets) |
1726 | 959 | gtk_target_list_unref (targetlist); | 987 | gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, |
1727 | 988 | location_action->dnd_targets, GDK_ACTION_ASK | GDK_ACTION_COPY | GDK_ACTION_LINK); | ||
1728 | 989 | else | ||
1729 | 990 | { | ||
1730 | 991 | targetlist = gtk_target_list_new (NULL, 0); | ||
1731 | 992 | gtk_target_list_add_uri_targets (targetlist, 0); | ||
1732 | 993 | gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, targetlist, GDK_ACTION_ASK | GDK_ACTION_COPY | GDK_ACTION_LINK); | ||
1733 | 994 | gtk_target_list_unref (targetlist); | ||
1734 | 995 | } | ||
1735 | 960 | g_signal_connect (entry, "drag-data-get", | 996 | g_signal_connect (entry, "drag-data-get", |
1736 | 961 | G_CALLBACK (midori_location_action_entry_drag_data_get_cb), action); | 997 | G_CALLBACK (midori_location_action_entry_drag_data_get_cb), action); |
1737 | 962 | gtk_widget_show (entry); | 998 | gtk_widget_show (entry); |
1738 | @@ -1630,6 +1666,38 @@ | |||
1739 | 1630 | } | 1666 | } |
1740 | 1631 | 1667 | ||
1741 | 1632 | /** | 1668 | /** |
1742 | 1669 | * midori_location_action_set_icon: | ||
1743 | 1670 | * @location_action: a #MidoriLocationAction | ||
1744 | 1671 | * @icon: an icon | ||
1745 | 1672 | * | ||
1746 | 1673 | * Sets the entry icon to @icon. | ||
1747 | 1674 | * | ||
1748 | 1675 | * Since: 0.5.2 | ||
1749 | 1676 | **/ | ||
1750 | 1677 | void | ||
1751 | 1678 | midori_location_action_set_icon (MidoriLocationAction* location_action, | ||
1752 | 1679 | const gchar* icon) | ||
1753 | 1680 | { | ||
1754 | 1681 | katze_item_set_icon (location_action->item, icon); | ||
1755 | 1682 | } | ||
1756 | 1683 | |||
1757 | 1684 | /** | ||
1758 | 1685 | * midori_location_action_set_title: | ||
1759 | 1686 | * @location_action: a #MidoriLocationAction | ||
1760 | 1687 | * @text: a string | ||
1761 | 1688 | * | ||
1762 | 1689 | * Sets the entry name to @text. | ||
1763 | 1690 | * | ||
1764 | 1691 | * Since: 0.5.2 | ||
1765 | 1692 | **/ | ||
1766 | 1693 | void | ||
1767 | 1694 | midori_location_action_set_title (MidoriLocationAction* location_action, | ||
1768 | 1695 | const gchar* title) | ||
1769 | 1696 | { | ||
1770 | 1697 | katze_item_set_name (location_action->item, title); | ||
1771 | 1698 | } | ||
1772 | 1699 | |||
1773 | 1700 | /** | ||
1774 | 1633 | * midori_location_action_set_text: | 1701 | * midori_location_action_set_text: |
1775 | 1634 | * @location_action: a #MidoriLocationAction | 1702 | * @location_action: a #MidoriLocationAction |
1776 | 1635 | * @text: a string | 1703 | * @text: a string |
1777 | 1636 | 1704 | ||
1778 | === modified file 'midori/midori-locationaction.h' | |||
1779 | --- midori/midori-locationaction.h 2013-04-16 23:10:10 +0000 | |||
1780 | +++ midori/midori-locationaction.h 2014-01-26 19:44:25 +0000 | |||
1781 | @@ -40,6 +40,14 @@ | |||
1782 | 40 | midori_location_action_get_text (MidoriLocationAction* location_action); | 40 | midori_location_action_get_text (MidoriLocationAction* location_action); |
1783 | 41 | 41 | ||
1784 | 42 | void | 42 | void |
1785 | 43 | midori_location_action_set_icon (MidoriLocationAction* location_action, | ||
1786 | 44 | const gchar* icon); | ||
1787 | 45 | |||
1788 | 46 | void | ||
1789 | 47 | midori_location_action_set_title (MidoriLocationAction* location_action, | ||
1790 | 48 | const gchar* title); | ||
1791 | 49 | |||
1792 | 50 | void | ||
1793 | 43 | midori_location_action_set_text (MidoriLocationAction* location_action, | 51 | midori_location_action_set_text (MidoriLocationAction* location_action, |
1794 | 44 | const gchar* text); | 52 | const gchar* text); |
1795 | 45 | 53 | ||
1796 | 46 | 54 | ||
1797 | === modified file 'midori/midori-view.c' | |||
1798 | --- midori/midori-view.c 2013-12-09 20:23:03 +0000 | |||
1799 | +++ midori/midori-view.c 2014-01-26 19:44:25 +0000 | |||
1800 | @@ -121,6 +121,8 @@ | |||
1801 | 121 | GtkWidget* overlay_label; | 121 | GtkWidget* overlay_label; |
1802 | 122 | GtkWidget* overlay_find; | 122 | GtkWidget* overlay_find; |
1803 | 123 | #endif | 123 | #endif |
1804 | 124 | |||
1805 | 125 | GtkTargetList* dnd_targets; | ||
1806 | 124 | }; | 126 | }; |
1807 | 125 | 127 | ||
1808 | 126 | struct _MidoriViewClass | 128 | struct _MidoriViewClass |
1809 | @@ -139,7 +141,8 @@ | |||
1810 | 139 | PROP_MINIMIZED, | 141 | PROP_MINIMIZED, |
1811 | 140 | PROP_ZOOM_LEVEL, | 142 | PROP_ZOOM_LEVEL, |
1812 | 141 | PROP_NEWS_FEEDS, | 143 | PROP_NEWS_FEEDS, |
1814 | 142 | PROP_SETTINGS | 144 | PROP_SETTINGS, |
1815 | 145 | PROP_DND_TARGETS | ||
1816 | 143 | }; | 146 | }; |
1817 | 144 | 147 | ||
1818 | 145 | enum { | 148 | enum { |
1819 | @@ -379,6 +382,21 @@ | |||
1820 | 379 | MIDORI_TYPE_WEB_SETTINGS, | 382 | MIDORI_TYPE_WEB_SETTINGS, |
1821 | 380 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); | 383 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
1822 | 381 | 384 | ||
1823 | 385 | /** | ||
1824 | 386 | * MidoriView:dnd-targets: | ||
1825 | 387 | * | ||
1826 | 388 | * GtkTargetList* the view supports. | ||
1827 | 389 | * | ||
1828 | 390 | * Since: 0.5.2 | ||
1829 | 391 | **/ | ||
1830 | 392 | g_object_class_install_property (gobject_class, | ||
1831 | 393 | PROP_DND_TARGETS, | ||
1832 | 394 | g_param_spec_pointer ( | ||
1833 | 395 | "dnd-targets", | ||
1834 | 396 | "DNDTargets", | ||
1835 | 397 | "GtkTargetList* the view supports", | ||
1836 | 398 | G_PARAM_READABLE|G_PARAM_WRITABLE)); | ||
1837 | 399 | |||
1838 | 382 | #ifdef HAVE_WEBKIT2 | 400 | #ifdef HAVE_WEBKIT2 |
1839 | 383 | WebKitWebContext* context = webkit_web_context_get_default (); | 401 | WebKitWebContext* context = webkit_web_context_get_default (); |
1840 | 384 | webkit_web_context_register_uri_scheme (context, | 402 | webkit_web_context_register_uri_scheme (context, |
1841 | @@ -2983,6 +3001,8 @@ | |||
1842 | 2983 | view->news_feeds = NULL; | 3001 | view->news_feeds = NULL; |
1843 | 2984 | view->find_links = -1; | 3002 | view->find_links = -1; |
1844 | 2985 | view->alerts = 0; | 3003 | view->alerts = 0; |
1845 | 3004 | view->dnd_targets = NULL; | ||
1846 | 3005 | |||
1847 | 2986 | 3006 | ||
1848 | 2987 | view->item = katze_item_new (); | 3007 | view->item = katze_item_new (); |
1849 | 2988 | 3008 | ||
1850 | @@ -3056,6 +3076,9 @@ | |||
1851 | 3056 | case PROP_SETTINGS: | 3076 | case PROP_SETTINGS: |
1852 | 3057 | _midori_view_set_settings (view, g_value_get_object (value)); | 3077 | _midori_view_set_settings (view, g_value_get_object (value)); |
1853 | 3058 | break; | 3078 | break; |
1854 | 3079 | case PROP_DND_TARGETS: | ||
1855 | 3080 | view->dnd_targets = (GtkTargetList*)g_value_get_pointer (value); | ||
1856 | 3081 | break; | ||
1857 | 3059 | default: | 3082 | default: |
1858 | 3060 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 3083 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1859 | 3061 | break; | 3084 | break; |
1860 | @@ -3087,6 +3110,9 @@ | |||
1861 | 3087 | case PROP_SETTINGS: | 3110 | case PROP_SETTINGS: |
1862 | 3088 | g_value_set_object (value, view->settings); | 3111 | g_value_set_object (value, view->settings); |
1863 | 3089 | break; | 3112 | break; |
1864 | 3113 | case PROP_DND_TARGETS: | ||
1865 | 3114 | g_value_set_pointer (value, view->dnd_targets); | ||
1866 | 3115 | break; | ||
1867 | 3090 | default: | 3116 | default: |
1868 | 3091 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 3117 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
1869 | 3092 | break; | 3118 | break; |
1870 | @@ -4296,6 +4322,89 @@ | |||
1871 | 4296 | return new_view; | 4322 | return new_view; |
1872 | 4297 | } | 4323 | } |
1873 | 4298 | 4324 | ||
1874 | 4325 | #if 0 | ||
1875 | 4326 | static void | ||
1876 | 4327 | midori_view_tab_label_data_received (GtkWidget* widget, | ||
1877 | 4328 | GdkDragContext* context, | ||
1878 | 4329 | gint x, | ||
1879 | 4330 | gint y, | ||
1880 | 4331 | GtkSelectionData* data, | ||
1881 | 4332 | guint ttype, | ||
1882 | 4333 | guint timestamp, | ||
1883 | 4334 | MidoriView* view) | ||
1884 | 4335 | { | ||
1885 | 4336 | KatzeArray *array; | ||
1886 | 4337 | gchar** uri; | ||
1887 | 4338 | |||
1888 | 4339 | array = katze_array_from_selection_data (data); | ||
1889 | 4340 | if (array) | ||
1890 | 4341 | { | ||
1891 | 4342 | if (katze_array_get_length (array)) | ||
1892 | 4343 | { | ||
1893 | 4344 | KatzeItem* item = katze_array_get_nth_item (array, 0); | ||
1894 | 4345 | if (KATZE_ITEM_IS_BOOKMARK (item)) | ||
1895 | 4346 | { | ||
1896 | 4347 | midori_view_set_title (view, katze_item_get_name (item)); | ||
1897 | 4348 | midori_view_set_uri (view, katze_item_get_uri (item)); | ||
1898 | 4349 | } | ||
1899 | 4350 | } | ||
1900 | 4351 | |||
1901 | 4352 | g_object_unref (array); | ||
1902 | 4353 | return; | ||
1903 | 4354 | } | ||
1904 | 4355 | |||
1905 | 4356 | uri = gtk_selection_data_get_uris (data); | ||
1906 | 4357 | if (uri != NULL) | ||
1907 | 4358 | { | ||
1908 | 4359 | midori_view_set_uri (view, uri[0]); | ||
1909 | 4360 | g_strfreev (uri); | ||
1910 | 4361 | } | ||
1911 | 4362 | else | ||
1912 | 4363 | { | ||
1913 | 4364 | gchar* text = (gchar*) gtk_selection_data_get_text (data); | ||
1914 | 4365 | midori_view_set_uri (view, text); | ||
1915 | 4366 | g_free (text); | ||
1916 | 4367 | } | ||
1917 | 4368 | } | ||
1918 | 4369 | |||
1919 | 4370 | static void | ||
1920 | 4371 | midori_view_tab_label_data_get (GtkWidget *widget, | ||
1921 | 4372 | GdkDragContext *drag_context, | ||
1922 | 4373 | GtkSelectionData *data, | ||
1923 | 4374 | guint info, | ||
1924 | 4375 | guint time, | ||
1925 | 4376 | MidoriView* view) | ||
1926 | 4377 | { | ||
1927 | 4378 | selection_data_from_katze_item (data, view->item); | ||
1928 | 4379 | } | ||
1929 | 4380 | |||
1930 | 4381 | static void | ||
1931 | 4382 | midori_view_install_tab_dnd (MidoriView* view, GtkWidget* widget) | ||
1932 | 4383 | { | ||
1933 | 4384 | g_object_set_data (G_OBJECT (widget), "KatzeItem", view->item) | ||
1934 | 4385 | ; | ||
1935 | 4386 | gtk_drag_dest_set (widget, GTK_DEST_DEFAULT_ALL, NULL, | ||
1936 | 4387 | 0, GDK_ACTION_COPY); | ||
1937 | 4388 | if (view->dnd_targets) | ||
1938 | 4389 | gtk_drag_dest_set_target_list (widget, view->dnd_targets); | ||
1939 | 4390 | gtk_drag_dest_add_text_targets (widget); | ||
1940 | 4391 | gtk_drag_dest_add_uri_targets (widget); | ||
1941 | 4392 | g_signal_connect (widget, "drag-data-received", | ||
1942 | 4393 | G_CALLBACK (midori_view_tab_label_data_received), | ||
1943 | 4394 | view); | ||
1944 | 4395 | if (view->dnd_targets) | ||
1945 | 4396 | { | ||
1946 | 4397 | g_print ("midori_view_get_tab: install source widget\n"); | ||
1947 | 4398 | gtk_drag_source_set (widget, GDK_BUTTON1_MASK, NULL, 0, | ||
1948 | 4399 | GDK_ACTION_COPY|GDK_ACTION_LINK); | ||
1949 | 4400 | gtk_drag_source_set_target_list (widget, view->dnd_targets); | ||
1950 | 4401 | g_signal_connect (widget, "drag-data-get", | ||
1951 | 4402 | G_CALLBACK (midori_view_tab_label_data_get), | ||
1952 | 4403 | view); | ||
1953 | 4404 | } | ||
1954 | 4405 | } | ||
1955 | 4406 | #endif | ||
1956 | 4407 | |||
1957 | 4299 | /** | 4408 | /** |
1958 | 4300 | * midori_view_get_tab_menu: | 4409 | * midori_view_get_tab_menu: |
1959 | 4301 | * @view: a #MidoriView | 4410 | * @view: a #MidoriView |
1960 | 4302 | 4411 | ||
1961 | === modified file 'panels/midori-bookmarks.c' | |||
1962 | --- panels/midori-bookmarks.c 2014-01-24 23:04:05 +0000 | |||
1963 | +++ panels/midori-bookmarks.c 2014-01-26 19:44:25 +0000 | |||
1964 | @@ -26,6 +26,151 @@ | |||
1965 | 26 | 26 | ||
1966 | 27 | #define COMPLETION_DELAY 200 | 27 | #define COMPLETION_DELAY 200 |
1967 | 28 | 28 | ||
1968 | 29 | #define MIDORI_BOOKMARKS_TREE_MODEL_TARGET "GTK_TREE_MODEL_ROW" | ||
1969 | 30 | |||
1970 | 31 | G_BEGIN_DECLS | ||
1971 | 32 | |||
1972 | 33 | #define MIDORI_BOOKMARKS_TREE_STORE_TYPE \ | ||
1973 | 34 | (midori_bookmarks_tree_store_get_type ()) | ||
1974 | 35 | #define MIDORI_BOOKMARKS_TREE_STORE(obj) \ | ||
1975 | 36 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_BOOKMARKS_TREE_STORE_TYPE, MidoriBookmarksTreeStore)) | ||
1976 | 37 | #define MIDORI_BOOKMARKS_TREE_STORE_CLASS(klass) \ | ||
1977 | 38 | (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_BOOKMARKS_TREE_STORE_TYPE, MidoriBookmarksTreeStoreClass)) | ||
1978 | 39 | |||
1979 | 40 | static gboolean | ||
1980 | 41 | midori_bookmarks_tree_store_drag_data_get (GtkTreeDragSource* drag_source, | ||
1981 | 42 | GtkTreePath* source_path, | ||
1982 | 43 | GtkSelectionData* selection_data); | ||
1983 | 44 | static gboolean | ||
1984 | 45 | midori_bookmarks_tree_store_drag_data_delete (GtkTreeDragSource* drag_source, | ||
1985 | 46 | GtkTreePath* source_path); | ||
1986 | 47 | static gboolean | ||
1987 | 48 | midori_bookmarks_tree_store_row_drop_possible (GtkTreeDragDest *drag_dest, | ||
1988 | 49 | GtkTreePath *dest_path, | ||
1989 | 50 | GtkSelectionData *selection_data); | ||
1990 | 51 | static gboolean | ||
1991 | 52 | midori_bookmarks_tree_store_drag_data_received (GtkTreeDragDest *drag_dest, | ||
1992 | 53 | GtkTreePath *dest_path, | ||
1993 | 54 | GtkSelectionData *selection_data); | ||
1994 | 55 | |||
1995 | 56 | typedef struct _MidoriBookmarksTreeStore MidoriBookmarksTreeStore; | ||
1996 | 57 | typedef struct _MidoriBookmarksTreeStoreClass MidoriBookmarksTreeStoreClass; | ||
1997 | 58 | typedef struct _TreeRowData TreeRowData; | ||
1998 | 59 | |||
1999 | 60 | struct _MidoriBookmarksTreeStore | ||
2000 | 61 | { | ||
2001 | 62 | GtkTreeStore parent_instance; | ||
2002 | 63 | |||
2003 | 64 | GList* stock_got_rows; | ||
2004 | 65 | GtkTreeView *_view; | ||
2005 | 66 | }; | ||
2006 | 67 | |||
2007 | 68 | struct _MidoriBookmarksTreeStoreClass | ||
2008 | 69 | { | ||
2009 | 70 | GtkTreeStoreClass parent_class; | ||
2010 | 71 | }; | ||
2011 | 72 | |||
2012 | 73 | struct _TreeRowData | ||
2013 | 74 | { | ||
2014 | 75 | GtkTreeModel *model; | ||
2015 | 76 | gchar path[4]; | ||
2016 | 77 | }; | ||
2017 | 78 | |||
2018 | 79 | static GtkTreeDragSourceIface * | ||
2019 | 80 | gtk_tree_store_gtk_tree_drag_source_iface = NULL; | ||
2020 | 81 | static GtkTreeDragDestIface * | ||
2021 | 82 | gtk_tree_store_gtk_tree_drag_dest_iface = NULL; | ||
2022 | 83 | |||
2023 | 84 | static void | ||
2024 | 85 | midori_bookmarks_tree_store_drag_source_init (GtkTreeDragSourceIface *iface) | ||
2025 | 86 | { | ||
2026 | 87 | gtk_tree_store_gtk_tree_drag_source_iface = g_type_interface_peek_parent (iface); | ||
2027 | 88 | |||
2028 | 89 | iface->drag_data_get = midori_bookmarks_tree_store_drag_data_get; | ||
2029 | 90 | iface->drag_data_delete = midori_bookmarks_tree_store_drag_data_delete; | ||
2030 | 91 | } | ||
2031 | 92 | |||
2032 | 93 | static void | ||
2033 | 94 | midori_bookmarks_tree_store_drag_dest_init (GtkTreeDragDestIface *iface) | ||
2034 | 95 | { | ||
2035 | 96 | gtk_tree_store_gtk_tree_drag_dest_iface = g_type_interface_peek_parent (iface); | ||
2036 | 97 | |||
2037 | 98 | iface->row_drop_possible = midori_bookmarks_tree_store_row_drop_possible; | ||
2038 | 99 | iface->drag_data_received = midori_bookmarks_tree_store_drag_data_received; | ||
2039 | 100 | } | ||
2040 | 101 | |||
2041 | 102 | static void | ||
2042 | 103 | midori_bookmarks_tree_store_init (MidoriBookmarksTreeStore* item) | ||
2043 | 104 | { | ||
2044 | 105 | item->stock_got_rows = NULL; | ||
2045 | 106 | item->_view = NULL; | ||
2046 | 107 | } | ||
2047 | 108 | |||
2048 | 109 | static void | ||
2049 | 110 | midori_bookmarks_tree_store_class_init (MidoriBookmarksTreeStoreClass *class) | ||
2050 | 111 | { | ||
2051 | 112 | } | ||
2052 | 113 | |||
2053 | 114 | G_DEFINE_TYPE_WITH_CODE (MidoriBookmarksTreeStore, | ||
2054 | 115 | midori_bookmarks_tree_store, | ||
2055 | 116 | GTK_TYPE_TREE_STORE, | ||
2056 | 117 | G_IMPLEMENT_INTERFACE ( | ||
2057 | 118 | GTK_TYPE_TREE_DRAG_SOURCE, | ||
2058 | 119 | midori_bookmarks_tree_store_drag_source_init) | ||
2059 | 120 | G_IMPLEMENT_INTERFACE ( | ||
2060 | 121 | GTK_TYPE_TREE_DRAG_DEST, | ||
2061 | 122 | midori_bookmarks_tree_store_drag_dest_init)); | ||
2062 | 123 | |||
2063 | 124 | |||
2064 | 125 | GtkTreeStore* | ||
2065 | 126 | midori_bookmarks_tree_store_new (gint n_columns, ...) | ||
2066 | 127 | { | ||
2067 | 128 | GtkTreeStore* tree_store = GTK_TREE_STORE (g_object_new (MIDORI_BOOKMARKS_TREE_STORE_TYPE, NULL)); | ||
2068 | 129 | va_list ap; | ||
2069 | 130 | GType* types; | ||
2070 | 131 | gint n; | ||
2071 | 132 | |||
2072 | 133 | if (!tree_store) | ||
2073 | 134 | return NULL; | ||
2074 | 135 | |||
2075 | 136 | types = g_new (GType, n_columns); | ||
2076 | 137 | |||
2077 | 138 | if (!types) | ||
2078 | 139 | { | ||
2079 | 140 | g_object_unref(tree_store); | ||
2080 | 141 | return NULL; | ||
2081 | 142 | } | ||
2082 | 143 | |||
2083 | 144 | va_start(ap, n_columns); | ||
2084 | 145 | for (n = 0; n < n_columns; n++) | ||
2085 | 146 | { | ||
2086 | 147 | types[n] = va_arg(ap, GType); | ||
2087 | 148 | } | ||
2088 | 149 | va_end(ap); | ||
2089 | 150 | |||
2090 | 151 | gtk_tree_store_set_column_types (tree_store, | ||
2091 | 152 | n_columns, | ||
2092 | 153 | types); | ||
2093 | 154 | |||
2094 | 155 | g_free (types); | ||
2095 | 156 | return tree_store; | ||
2096 | 157 | } | ||
2097 | 158 | |||
2098 | 159 | GtkTreeStore* | ||
2099 | 160 | midori_bookmarks_tree_store_newv (gint n_columns, GType *types) | ||
2100 | 161 | { | ||
2101 | 162 | GtkTreeStore* tree_store = GTK_TREE_STORE (g_object_new (MIDORI_BOOKMARKS_TREE_STORE_TYPE, NULL)); | ||
2102 | 163 | |||
2103 | 164 | if (!tree_store) | ||
2104 | 165 | return NULL; | ||
2105 | 166 | |||
2106 | 167 | gtk_tree_store_set_column_types (tree_store, | ||
2107 | 168 | n_columns, | ||
2108 | 169 | types); | ||
2109 | 170 | |||
2110 | 171 | return tree_store; | ||
2111 | 172 | } | ||
2112 | 173 | |||
2113 | 29 | gboolean | 174 | gboolean |
2114 | 30 | midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser, | 175 | midori_browser_edit_bookmark_dialog_new (MidoriBrowser* browser, |
2115 | 31 | KatzeItem* bookmark_or_parent, | 176 | KatzeItem* bookmark_or_parent, |
2116 | @@ -37,6 +182,12 @@ | |||
2117 | 37 | midori_browser_open_bookmark (MidoriBrowser* browser, | 182 | midori_browser_open_bookmark (MidoriBrowser* browser, |
2118 | 38 | KatzeItem* item); | 183 | KatzeItem* item); |
2119 | 39 | 184 | ||
2120 | 185 | static void | ||
2121 | 186 | midori_bookmarks_row_changed_cb (GtkTreeModel* model, | ||
2122 | 187 | GtkTreePath* path, | ||
2123 | 188 | GtkTreeIter* iter, | ||
2124 | 189 | MidoriBookmarks* bookmarks); | ||
2125 | 190 | |||
2126 | 40 | struct _MidoriBookmarks | 191 | struct _MidoriBookmarks |
2127 | 41 | { | 192 | { |
2128 | 42 | GtkVBox parent_instance; | 193 | GtkVBox parent_instance; |
2129 | @@ -50,7 +201,19 @@ | |||
2130 | 50 | gint filter_timeout; | 201 | gint filter_timeout; |
2131 | 51 | gchar* filter; | 202 | gchar* filter; |
2132 | 52 | 203 | ||
2133 | 204 | GList* pending_inserts; | ||
2134 | 53 | KatzeItem* hovering_item; | 205 | KatzeItem* hovering_item; |
2135 | 206 | |||
2136 | 207 | struct _stock_pending_event | ||
2137 | 208 | { | ||
2138 | 209 | gint x; | ||
2139 | 210 | gint y; | ||
2140 | 211 | } *pending_event, | ||
2141 | 212 | stock_pending_event; | ||
2142 | 213 | |||
2143 | 214 | GHashTable* updated_items; | ||
2144 | 215 | GList* added_paths; | ||
2145 | 216 | GList* reordered_paths; | ||
2146 | 54 | }; | 217 | }; |
2147 | 55 | 218 | ||
2148 | 56 | struct _MidoriBookmarksClass | 219 | struct _MidoriBookmarksClass |
2149 | @@ -88,36 +251,47 @@ | |||
2150 | 88 | GParamSpec* pspec); | 251 | GParamSpec* pspec); |
2151 | 89 | 252 | ||
2152 | 90 | static void | 253 | static void |
2158 | 91 | midori_bookmarks_row_changed_cb (GtkTreeModel* model, | 254 | midori_bookmarks_update_cb (KatzeArray* array, |
2159 | 92 | GtkTreePath* path, | 255 | MidoriBookmarks* bookmarks); |
2155 | 93 | GtkTreeIter* iter, | ||
2156 | 94 | MidoriBookmarks* bookmarks); | ||
2157 | 95 | |||
2160 | 96 | static void | 256 | static void |
2161 | 97 | midori_bookmarks_add_item_cb (KatzeArray* array, | 257 | midori_bookmarks_add_item_cb (KatzeArray* array, |
2162 | 98 | KatzeItem* item, | 258 | KatzeItem* item, |
2163 | 99 | MidoriBookmarks* bookmarks); | 259 | MidoriBookmarks* bookmarks); |
2164 | 100 | |||
2165 | 101 | static void | 260 | static void |
2166 | 102 | midori_bookmarks_update_item_cb (KatzeArray* array, | 261 | midori_bookmarks_update_item_cb (KatzeArray* array, |
2170 | 103 | KatzeItem* item, | 262 | KatzeItem* item, |
2171 | 104 | MidoriBookmarks* bookmarks); | 263 | MidoriBookmarks* bookmarks); |
2169 | 105 | |||
2172 | 106 | static void | 264 | static void |
2173 | 107 | midori_bookmarks_remove_item_cb (KatzeArray* array, | 265 | midori_bookmarks_remove_item_cb (KatzeArray* array, |
2174 | 108 | KatzeItem* item, | 266 | KatzeItem* item, |
2175 | 109 | MidoriBookmarks* bookmarks); | 267 | MidoriBookmarks* bookmarks); |
2176 | 110 | 268 | ||
2177 | 111 | static void | 269 | static void |
2180 | 112 | midori_bookmarks_update_cb (KatzeArray* array, | 270 | midori_bookmarks_row_inserted_cb (GtkTreeModel* model, |
2181 | 113 | MidoriBookmarks* bookmarks); | 271 | GtkTreePath* path, |
2182 | 272 | GtkTreeIter* iter, | ||
2183 | 273 | MidoriBookmarks* bookmarks); | ||
2184 | 274 | static void | ||
2185 | 275 | midori_bookmarks_row_changed_cb (GtkTreeModel* model, | ||
2186 | 276 | GtkTreePath* path, | ||
2187 | 277 | GtkTreeIter* iter, | ||
2188 | 278 | MidoriBookmarks* bookmarks); | ||
2189 | 279 | static void | ||
2190 | 280 | midori_bookmarks_row_deleted_cb (GtkTreeModel* model, | ||
2191 | 281 | GtkTreePath* path, | ||
2192 | 282 | MidoriBookmarks* bookmarks); | ||
2193 | 283 | |||
2194 | 284 | static void | ||
2195 | 285 | midori_bookmarks_update_item (MidoriBookmarks* bookmarks, KatzeItem *item); | ||
2196 | 114 | 286 | ||
2197 | 115 | static void | 287 | static void |
2198 | 116 | midori_bookmarks_statusbar_update (MidoriBookmarks *bookmarks); | 288 | midori_bookmarks_statusbar_update (MidoriBookmarks *bookmarks); |
2199 | 117 | 289 | ||
2200 | 118 | static void | 290 | static void |
2203 | 119 | midori_bookmarks_add_item (KatzeItem* item, | 291 | midori_bookmarks_idle_remove_item (MidoriBookmarks* bookmarks, KatzeItem *item); |
2204 | 120 | MidoriBookmarks* bookmarks); | 292 | |
2205 | 293 | static gboolean | ||
2206 | 294 | midori_bookmarks_idle_func (gpointer data); | ||
2207 | 121 | 295 | ||
2208 | 122 | static void | 296 | static void |
2209 | 123 | midori_bookmarks_class_init (MidoriBookmarksClass* class) | 297 | midori_bookmarks_class_init (MidoriBookmarksClass* class) |
2210 | @@ -133,13 +307,13 @@ | |||
2211 | 133 | flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; | 307 | flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; |
2212 | 134 | 308 | ||
2213 | 135 | g_object_class_install_property (gobject_class, | 309 | g_object_class_install_property (gobject_class, |
2221 | 136 | PROP_APP, | 310 | PROP_APP, |
2222 | 137 | g_param_spec_object ( | 311 | g_param_spec_object ( |
2223 | 138 | "app", | 312 | "app", |
2224 | 139 | "App", | 313 | "App", |
2225 | 140 | "The app", | 314 | "The app", |
2226 | 141 | MIDORI_TYPE_APP, | 315 | MIDORI_TYPE_APP, |
2227 | 142 | flags)); | 316 | flags)); |
2228 | 143 | } | 317 | } |
2229 | 144 | 318 | ||
2230 | 145 | static const gchar* | 319 | static const gchar* |
2231 | @@ -168,7 +342,7 @@ | |||
2232 | 168 | gchar* parent_id; | 342 | gchar* parent_id; |
2233 | 169 | 343 | ||
2234 | 170 | parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid); | 344 | parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid); |
2236 | 171 | if (!(root_array = midori_bookmarks_db_query_recursive (array, "*", "parentid = %q", parent_id, FALSE))) | 345 | if (!(root_array = midori_bookmarks_db_query_recursive (array, "*", "parentid = %q", parent_id, "(uri='') ASC, pos_panel DESC", FALSE))) |
2237 | 172 | { | 346 | { |
2238 | 173 | g_free (parent_id); | 347 | g_free (parent_id); |
2239 | 174 | return; | 348 | return; |
2240 | @@ -180,7 +354,7 @@ | |||
2241 | 180 | subarray = katze_array_new (KATZE_TYPE_ARRAY); | 354 | subarray = katze_array_new (KATZE_TYPE_ARRAY); |
2242 | 181 | katze_item_set_name (KATZE_ITEM (subarray), katze_item_get_name (item)); | 355 | katze_item_set_name (KATZE_ITEM (subarray), katze_item_get_name (item)); |
2243 | 182 | midori_bookmarks_export_array_db (db, subarray, | 356 | midori_bookmarks_export_array_db (db, subarray, |
2245 | 183 | katze_item_get_meta_integer (item, "parentid")); | 357 | katze_item_get_meta_integer (item, "parentid")); |
2246 | 184 | katze_array_add_item (array, subarray); | 358 | katze_array_add_item (array, subarray); |
2247 | 185 | } | 359 | } |
2248 | 186 | else | 360 | else |
2249 | @@ -201,20 +375,20 @@ | |||
2250 | 201 | 375 | ||
2251 | 202 | if (keyword && *keyword) | 376 | if (keyword && *keyword) |
2252 | 203 | array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db, | 377 | array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db, |
2254 | 204 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "title LIKE '%%%q%%'", keyword, FALSE); | 378 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "title LIKE '%%%q%%'", keyword, NULL, FALSE); |
2255 | 205 | else | 379 | else |
2256 | 206 | { | 380 | { |
2257 | 207 | if (parentid > 0) | 381 | if (parentid > 0) |
2258 | 208 | { | 382 | { |
2259 | 209 | gchar* parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid); | 383 | gchar* parent_id = g_strdup_printf ("%" G_GINT64_FORMAT, parentid); |
2260 | 210 | array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db, | 384 | array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db, |
2262 | 211 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid = %q", parent_id, FALSE); | 385 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid = %q", parent_id, "(uri='') ASC, pos_panel DESC", FALSE); |
2263 | 212 | 386 | ||
2264 | 213 | g_free (parent_id); | 387 | g_free (parent_id); |
2265 | 214 | } | 388 | } |
2266 | 215 | else | 389 | else |
2267 | 216 | array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db, | 390 | array = midori_bookmarks_db_query_recursive (bookmarks->bookmarks_db, |
2269 | 217 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid IS NULL", NULL, FALSE); | 391 | "id, parentid, title, uri, desc, app, toolbar, pos_panel, pos_bar", "parentid IS NULL", NULL, "(uri='') ASC, pos_panel DESC", FALSE); |
2270 | 218 | } | 392 | } |
2271 | 219 | return array ? array : katze_array_new (KATZE_TYPE_ITEM); | 393 | return array ? array : katze_array_new (KATZE_TYPE_ITEM); |
2272 | 220 | } | 394 | } |
2273 | @@ -231,24 +405,52 @@ | |||
2274 | 231 | KatzeItem* item; | 405 | KatzeItem* item; |
2275 | 232 | GtkTreeIter child; | 406 | GtkTreeIter child; |
2276 | 233 | 407 | ||
2277 | 408 | g_signal_handlers_block_by_func (model, | ||
2278 | 409 | midori_bookmarks_row_changed_cb, | ||
2279 | 410 | bookmarks); | ||
2280 | 411 | |||
2281 | 234 | array = midori_bookmarks_read_from_db (bookmarks, parentid, keyword); | 412 | array = midori_bookmarks_read_from_db (bookmarks, parentid, keyword); |
2282 | 235 | katze_bookmark_populate_tree_view (array, model, parent); | 413 | katze_bookmark_populate_tree_view (array, model, parent); |
2283 | 414 | |||
2284 | 415 | g_signal_handlers_unblock_by_func (model, | ||
2285 | 416 | midori_bookmarks_row_changed_cb, | ||
2286 | 417 | bookmarks); | ||
2287 | 418 | |||
2288 | 236 | /* Remove invisible dummy row */ | 419 | /* Remove invisible dummy row */ |
2289 | 237 | last = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), parent); | 420 | last = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), parent); |
2290 | 238 | if (!last) | 421 | if (!last) |
2291 | 239 | return; | 422 | return; |
2292 | 423 | |||
2293 | 424 | g_signal_handlers_block_by_func (model, | ||
2294 | 425 | midori_bookmarks_row_deleted_cb, | ||
2295 | 426 | bookmarks); | ||
2296 | 427 | |||
2297 | 240 | gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (model), &child, parent, last - 1); | 428 | gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (model), &child, parent, last - 1); |
2298 | 241 | gtk_tree_model_get (GTK_TREE_MODEL (model), &child, 0, &item, -1); | 429 | gtk_tree_model_get (GTK_TREE_MODEL (model), &child, 0, &item, -1); |
2299 | 242 | if (KATZE_ITEM_IS_SEPARATOR (item)) | 430 | if (KATZE_ITEM_IS_SEPARATOR (item)) |
2300 | 243 | gtk_tree_store_remove (model, &child); | 431 | gtk_tree_store_remove (model, &child); |
2301 | 244 | else | 432 | else |
2302 | 245 | g_object_unref (item); | 433 | g_object_unref (item); |
2303 | 434 | |||
2304 | 435 | g_signal_handlers_unblock_by_func (model, | ||
2305 | 436 | midori_bookmarks_row_deleted_cb, | ||
2306 | 437 | bookmarks); | ||
2307 | 438 | |||
2308 | 246 | } | 439 | } |
2309 | 247 | 440 | ||
2310 | 441 | static void | ||
2311 | 442 | midori_bookmarks_add_item (KatzeItem* item, | ||
2312 | 443 | MidoriBookmarks* bookmarks); | ||
2313 | 444 | |||
2314 | 445 | static void | ||
2315 | 446 | add_parent_to_reorder (GtkTreeModel* model, | ||
2316 | 447 | GtkTreePath* path, | ||
2317 | 448 | MidoriBookmarks* bookmarks); | ||
2318 | 449 | |||
2319 | 248 | static gboolean | 450 | static gboolean |
2320 | 249 | midori_bookmarks_reach_item_recurse (GtkTreeModel* model, | 451 | midori_bookmarks_reach_item_recurse (GtkTreeModel* model, |
2323 | 250 | GtkTreeIter* iter, | 452 | GtkTreeIter* iter, |
2324 | 251 | gint64 id) | 453 | gint64 id) |
2325 | 252 | { | 454 | { |
2326 | 253 | do | 455 | do |
2327 | 254 | { | 456 | { |
2328 | @@ -258,7 +460,7 @@ | |||
2329 | 258 | 460 | ||
2330 | 259 | gtk_tree_model_get (model, iter, 0, &item, -1); | 461 | gtk_tree_model_get (model, iter, 0, &item, -1); |
2331 | 260 | 462 | ||
2333 | 261 | if (!KATZE_ITEM_IS_SEPARATOR(item)) | 463 | if (item) |
2334 | 262 | { | 464 | { |
2335 | 263 | itemid = katze_item_get_meta_integer (item, "id"); | 465 | itemid = katze_item_get_meta_integer (item, "id"); |
2336 | 264 | g_object_unref (item); | 466 | g_object_unref (item); |
2337 | @@ -267,13 +469,11 @@ | |||
2338 | 267 | if (id == itemid) | 469 | if (id == itemid) |
2339 | 268 | return TRUE; | 470 | return TRUE; |
2340 | 269 | 471 | ||
2342 | 270 | if (gtk_tree_model_iter_children (model, &child, iter)) | 472 | if (gtk_tree_model_iter_children (model, &child, iter) |
2343 | 473 | && midori_bookmarks_reach_item_recurse (model, &child, id)) | ||
2344 | 271 | { | 474 | { |
2350 | 272 | if (midori_bookmarks_reach_item_recurse (model, &child, id)) | 475 | *iter = child; |
2351 | 273 | { | 476 | return TRUE; |
2347 | 274 | *iter = child; | ||
2348 | 275 | return TRUE; | ||
2349 | 276 | } | ||
2352 | 277 | } | 477 | } |
2353 | 278 | } | 478 | } |
2354 | 279 | while (gtk_tree_model_iter_next(model, iter)); | 479 | while (gtk_tree_model_iter_next(model, iter)); |
2355 | @@ -283,8 +483,8 @@ | |||
2356 | 283 | 483 | ||
2357 | 284 | static gboolean | 484 | static gboolean |
2358 | 285 | midori_bookmarks_reach_item (GtkTreeModel* model, | 485 | midori_bookmarks_reach_item (GtkTreeModel* model, |
2361 | 286 | GtkTreeIter* iter, | 486 | GtkTreeIter* iter, |
2362 | 287 | gint64 id) | 487 | gint64 id) |
2363 | 288 | { | 488 | { |
2364 | 289 | if (!gtk_tree_model_get_iter_first(model, iter)) | 489 | if (!gtk_tree_model_get_iter_first(model, iter)) |
2365 | 290 | return FALSE; | 490 | return FALSE; |
2366 | @@ -293,38 +493,73 @@ | |||
2367 | 293 | } | 493 | } |
2368 | 294 | 494 | ||
2369 | 295 | static void | 495 | static void |
2373 | 296 | midori_bookmarks_add_item_to_model(GtkTreeStore* model, | 496 | midori_bookmarks_add_item_to_model(MidoriBookmarks* bookmarks, |
2374 | 297 | GtkTreeIter* parent, | 497 | GtkTreeModel* model, |
2375 | 298 | KatzeItem* item) | 498 | GtkTreeIter* parent, |
2376 | 499 | KatzeItem* item) | ||
2377 | 299 | { | 500 | { |
2378 | 501 | GtkTreeStore* tree_store = GTK_TREE_STORE (model); | ||
2379 | 502 | gint last; | ||
2380 | 503 | GtkTreeIter child; | ||
2381 | 504 | |||
2382 | 300 | if (KATZE_ITEM_IS_BOOKMARK (item)) | 505 | if (KATZE_ITEM_IS_BOOKMARK (item)) |
2383 | 301 | { | 506 | { |
2384 | 507 | gint position = 0; | ||
2385 | 508 | |||
2386 | 509 | /* skip the folders to be consistent with the db query order */ | ||
2387 | 510 | if (gtk_tree_model_iter_children (model, &child, parent)) | ||
2388 | 511 | while (gtk_tree_model_iter_has_child (model, &child)) | ||
2389 | 512 | { | ||
2390 | 513 | position++; | ||
2391 | 514 | if (!gtk_tree_model_iter_next (model, &child)) | ||
2392 | 515 | break; | ||
2393 | 516 | } | ||
2394 | 517 | |||
2395 | 302 | gchar* tooltip = g_markup_escape_text (katze_item_get_uri (item), -1); | 518 | gchar* tooltip = g_markup_escape_text (katze_item_get_uri (item), -1); |
2396 | 303 | 519 | ||
2399 | 304 | gtk_tree_store_insert_with_values (model, NULL, parent, | 520 | gtk_tree_store_insert_with_values (tree_store, NULL, parent, |
2400 | 305 | 0, | 521 | position, |
2401 | 306 | 0, item, 1, tooltip, -1); | 522 | 0, item, 1, tooltip, -1); |
2402 | 307 | g_free (tooltip); | 523 | g_free (tooltip); |
2403 | 308 | } | 524 | } |
2405 | 309 | else | 525 | else if (KATZE_ITEM_IS_FOLDER (item)) |
2406 | 310 | { | 526 | { |
2407 | 311 | GtkTreeIter root_iter; | 527 | GtkTreeIter root_iter; |
2408 | 312 | 528 | ||
2410 | 313 | gtk_tree_store_insert_with_values (model, &root_iter, parent, | 529 | gtk_tree_store_insert_with_values (tree_store, &root_iter, parent, |
2411 | 314 | 0, 0, item, -1); | 530 | 0, 0, item, -1); |
2412 | 315 | 531 | ||
2413 | 316 | /* That's an invisible dummy, so we always have an expander */ | 532 | /* That's an invisible dummy, so we always have an expander */ |
2417 | 317 | gtk_tree_store_insert_with_values (model, NULL, &root_iter, | 533 | gtk_tree_store_insert_with_values (tree_store, NULL, &root_iter, |
2418 | 318 | 0, | 534 | 0, 0, NULL, -1); |
2416 | 319 | 0, NULL, -1); | ||
2419 | 320 | } | 535 | } |
2420 | 536 | |||
2421 | 537 | /* Remove invisible dummy row */ | ||
2422 | 538 | last = gtk_tree_model_iter_n_children (model, parent); | ||
2423 | 539 | if (!last) | ||
2424 | 540 | return; | ||
2425 | 541 | |||
2426 | 542 | g_signal_handlers_block_by_func (model, | ||
2427 | 543 | midori_bookmarks_row_deleted_cb, | ||
2428 | 544 | bookmarks); | ||
2429 | 545 | |||
2430 | 546 | gtk_tree_model_iter_nth_child (model, &child, parent, last - 1); | ||
2431 | 547 | gtk_tree_model_get (model, &child, 0, &item, -1); | ||
2432 | 548 | if (KATZE_ITEM_IS_SEPARATOR (item)) | ||
2433 | 549 | gtk_tree_store_remove (tree_store, &child); | ||
2434 | 550 | else | ||
2435 | 551 | g_object_unref (item); | ||
2436 | 552 | |||
2437 | 553 | g_signal_handlers_unblock_by_func (model, | ||
2438 | 554 | midori_bookmarks_row_deleted_cb, | ||
2439 | 555 | bookmarks); | ||
2440 | 321 | } | 556 | } |
2441 | 322 | 557 | ||
2442 | 323 | static void | 558 | static void |
2443 | 324 | midori_bookmarks_update_item_in_model(MidoriBookmarks* bookmarks, | 559 | midori_bookmarks_update_item_in_model(MidoriBookmarks* bookmarks, |
2447 | 325 | GtkTreeStore* model, | 560 | GtkTreeStore* model, |
2448 | 326 | GtkTreeIter* iter, | 561 | GtkTreeIter* iter, |
2449 | 327 | KatzeItem* item) | 562 | KatzeItem* item) |
2450 | 328 | { | 563 | { |
2451 | 329 | g_signal_handlers_block_by_func (model, | 564 | g_signal_handlers_block_by_func (model, |
2452 | 330 | midori_bookmarks_row_changed_cb, | 565 | midori_bookmarks_row_changed_cb, |
2453 | @@ -350,18 +585,48 @@ | |||
2454 | 350 | bookmarks); | 585 | bookmarks); |
2455 | 351 | } | 586 | } |
2456 | 352 | 587 | ||
2457 | 588 | static gboolean | ||
2458 | 589 | midori_bookmarks_idle_pending (MidoriBookmarks* bookmarks) | ||
2459 | 590 | { | ||
2460 | 591 | if (bookmarks->pending_inserts | ||
2461 | 592 | || bookmarks->added_paths | ||
2462 | 593 | || bookmarks->reordered_paths | ||
2463 | 594 | || g_hash_table_size (bookmarks->updated_items)) | ||
2464 | 595 | return TRUE; | ||
2465 | 596 | return FALSE; | ||
2466 | 597 | } | ||
2467 | 598 | |||
2468 | 599 | /** | ||
2469 | 600 | * midori_bookmarks_idle_start: | ||
2470 | 601 | * @bookmarks: the bookmarks panel | ||
2471 | 602 | * | ||
2472 | 603 | * Internal function that checks whether idle processing is pending, | ||
2473 | 604 | * if not, add a new one. | ||
2474 | 605 | **/ | ||
2475 | 606 | static void | ||
2476 | 607 | midori_bookmarks_idle_start (MidoriBookmarks* bookmarks) | ||
2477 | 608 | { | ||
2478 | 609 | if (midori_bookmarks_idle_pending (bookmarks)) | ||
2479 | 610 | return; | ||
2480 | 611 | |||
2481 | 612 | g_idle_add (midori_bookmarks_idle_func, bookmarks); | ||
2482 | 613 | } | ||
2483 | 614 | |||
2484 | 353 | static void | 615 | static void |
2485 | 354 | midori_bookmarks_add_item (KatzeItem* item, | 616 | midori_bookmarks_add_item (KatzeItem* item, |
2486 | 355 | MidoriBookmarks* bookmarks); | 617 | MidoriBookmarks* bookmarks); |
2487 | 618 | |||
2488 | 356 | static void | 619 | static void |
2489 | 357 | midori_bookmarks_add_item_cb (KatzeArray* array, | 620 | midori_bookmarks_add_item_cb (KatzeArray* array, |
2490 | 358 | KatzeItem* item, | 621 | KatzeItem* item, |
2491 | 359 | MidoriBookmarks* bookmarks) | 622 | MidoriBookmarks* bookmarks) |
2492 | 360 | { | 623 | { |
2494 | 361 | midori_bookmarks_add_item (item, bookmarks); | 624 | midori_bookmarks_idle_start (bookmarks); |
2495 | 625 | |||
2496 | 626 | g_object_ref (item); | ||
2497 | 627 | bookmarks->pending_inserts = g_list_append (bookmarks->pending_inserts, item); | ||
2498 | 362 | } | 628 | } |
2499 | 363 | 629 | ||
2500 | 364 | |||
2501 | 365 | static void | 630 | static void |
2502 | 366 | midori_bookmarks_add_item (KatzeItem* item, | 631 | midori_bookmarks_add_item (KatzeItem* item, |
2503 | 367 | MidoriBookmarks* bookmarks) | 632 | MidoriBookmarks* bookmarks) |
2504 | @@ -370,18 +635,16 @@ | |||
2505 | 370 | GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); | 635 | GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); |
2506 | 371 | GtkTreeIter iter; | 636 | GtkTreeIter iter; |
2507 | 372 | 637 | ||
2512 | 373 | if (!parentid) | 638 | if (parentid == katze_item_get_meta_integer (KATZE_ITEM (bookmarks->bookmarks_db), "id")) |
2513 | 374 | { | 639 | midori_bookmarks_add_item_to_model (bookmarks, model, NULL, item); |
2510 | 375 | midori_bookmarks_add_item_to_model (GTK_TREE_STORE (model), NULL, item); | ||
2511 | 376 | } | ||
2514 | 377 | else if (midori_bookmarks_reach_item (model, &iter, parentid)) | 640 | else if (midori_bookmarks_reach_item (model, &iter, parentid)) |
2515 | 378 | { | 641 | { |
2516 | 379 | GtkTreePath* path = gtk_tree_model_get_path(model, &iter); | 642 | GtkTreePath* path = gtk_tree_model_get_path(model, &iter); |
2517 | 643 | gint n_children = gtk_tree_model_iter_n_children (model, &iter); | ||
2518 | 380 | 644 | ||
2523 | 381 | if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (bookmarks->treeview), path)) | 645 | if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (bookmarks->treeview), path) |
2524 | 382 | { | 646 | || !n_children) |
2525 | 383 | midori_bookmarks_add_item_to_model (GTK_TREE_STORE (model), &iter, item); | 647 | midori_bookmarks_add_item_to_model (bookmarks, model, &iter, item); |
2522 | 384 | } | ||
2526 | 385 | 648 | ||
2527 | 386 | gtk_tree_path_free (path); | 649 | gtk_tree_path_free (path); |
2528 | 387 | } | 650 | } |
2529 | @@ -389,8 +652,8 @@ | |||
2530 | 389 | 652 | ||
2531 | 390 | static void | 653 | static void |
2532 | 391 | midori_bookmarks_update_item_cb (KatzeArray* array, | 654 | midori_bookmarks_update_item_cb (KatzeArray* array, |
2535 | 392 | KatzeItem* item, | 655 | KatzeItem* item, |
2536 | 393 | MidoriBookmarks* bookmarks) | 656 | MidoriBookmarks* bookmarks) |
2537 | 394 | { | 657 | { |
2538 | 395 | gint64 id = katze_item_get_meta_integer (item, "id"); | 658 | gint64 id = katze_item_get_meta_integer (item, "id"); |
2539 | 396 | gint64 parentid = katze_item_get_meta_integer (item, "parentid"); | 659 | gint64 parentid = katze_item_get_meta_integer (item, "parentid"); |
2540 | @@ -433,7 +696,7 @@ | |||
2541 | 433 | midori_bookmarks_add_item (item, bookmarks); | 696 | midori_bookmarks_add_item (item, bookmarks); |
2542 | 434 | } | 697 | } |
2543 | 435 | } | 698 | } |
2545 | 436 | else if (parentid == 0) | 699 | else if (parentid == katze_item_get_meta_integer (KATZE_ITEM (bookmarks->bookmarks_db), "id")) |
2546 | 437 | { | 700 | { |
2547 | 438 | midori_bookmarks_update_item_in_model (bookmarks, GTK_TREE_STORE (model), &iter, item); | 701 | midori_bookmarks_update_item_in_model (bookmarks, GTK_TREE_STORE (model), &iter, item); |
2548 | 439 | } | 702 | } |
2549 | @@ -457,6 +720,10 @@ | |||
2550 | 457 | GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); | 720 | GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); |
2551 | 458 | GtkTreeIter iter; | 721 | GtkTreeIter iter; |
2552 | 459 | 722 | ||
2553 | 723 | g_assert (KATZE_IS_ITEM (item)); | ||
2554 | 724 | |||
2555 | 725 | midori_bookmarks_idle_remove_item (bookmarks, item); | ||
2556 | 726 | |||
2557 | 460 | if (midori_bookmarks_reach_item (model, &iter, id)) | 727 | if (midori_bookmarks_reach_item (model, &iter, id)) |
2558 | 461 | { | 728 | { |
2559 | 462 | GtkTreeIter parent; | 729 | GtkTreeIter parent; |
2560 | @@ -486,12 +753,869 @@ | |||
2561 | 486 | midori_bookmarks_update_cb (KatzeArray* array, | 753 | midori_bookmarks_update_cb (KatzeArray* array, |
2562 | 487 | MidoriBookmarks* bookmarks) | 754 | MidoriBookmarks* bookmarks) |
2563 | 488 | { | 755 | { |
2564 | 756 | #if 1 | ||
2565 | 757 | g_print ("midori_bookmarks_update_cb: ignored ********\n"); | ||
2566 | 758 | #else | ||
2567 | 489 | GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); | 759 | GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); |
2568 | 760 | |||
2569 | 490 | gtk_tree_store_clear (GTK_TREE_STORE (model)); | 761 | gtk_tree_store_clear (GTK_TREE_STORE (model)); |
2570 | 491 | midori_bookmarks_read_from_db_to_model (bookmarks, | 762 | midori_bookmarks_read_from_db_to_model (bookmarks, |
2571 | 492 | GTK_TREE_STORE (model), NULL, 0, bookmarks->filter); | 763 | GTK_TREE_STORE (model), NULL, 0, bookmarks->filter); |
2574 | 493 | } | 764 | #endif |
2575 | 494 | 765 | } | |
2576 | 766 | |||
2577 | 767 | gboolean | ||
2578 | 768 | midori_bookmarks_tree_set_row_drag_data (GtkSelectionData *selection_data, | ||
2579 | 769 | GtkTreeModel *tree_model, | ||
2580 | 770 | GList* rows) | ||
2581 | 771 | { | ||
2582 | 772 | TreeRowData *trd; | ||
2583 | 773 | gint len; | ||
2584 | 774 | gint struct_size; | ||
2585 | 775 | gint length; | ||
2586 | 776 | gint i; | ||
2587 | 777 | GString *data; | ||
2588 | 778 | |||
2589 | 779 | g_return_val_if_fail (selection_data != NULL, FALSE); | ||
2590 | 780 | g_return_val_if_fail (GTK_IS_TREE_MODEL (tree_model), FALSE); | ||
2591 | 781 | g_return_val_if_fail (rows != NULL, FALSE); | ||
2592 | 782 | |||
2593 | 783 | data = g_string_new(""); | ||
2594 | 784 | |||
2595 | 785 | length = g_list_length (rows); | ||
2596 | 786 | for (i = 0; i < length; i++) | ||
2597 | 787 | { | ||
2598 | 788 | GtkTreePath *path = (GtkTreePath *)g_list_nth_data (rows, i); | ||
2599 | 789 | gchar *path_str = gtk_tree_path_to_string (path); | ||
2600 | 790 | |||
2601 | 791 | g_string_append (data, path_str); | ||
2602 | 792 | if (i < length-1) | ||
2603 | 793 | g_string_append_c (data, '\n'); | ||
2604 | 794 | } | ||
2605 | 795 | |||
2606 | 796 | len = data->len; | ||
2607 | 797 | |||
2608 | 798 | /* the old allocate-end-of-struct-to-hold-string trick */ | ||
2609 | 799 | struct_size = sizeof (TreeRowData) + len + 1 - | ||
2610 | 800 | (sizeof (TreeRowData) - G_STRUCT_OFFSET (TreeRowData, path)); | ||
2611 | 801 | |||
2612 | 802 | trd = g_malloc (struct_size); | ||
2613 | 803 | |||
2614 | 804 | strcpy (trd->path, data->str); | ||
2615 | 805 | |||
2616 | 806 | g_string_free (data, TRUE); | ||
2617 | 807 | |||
2618 | 808 | trd->model = tree_model; | ||
2619 | 809 | |||
2620 | 810 | gtk_selection_data_set (selection_data, | ||
2621 | 811 | gdk_atom_intern_static_string (MIDORI_BOOKMARKS_TREE_MODEL_TARGET), | ||
2622 | 812 | 8, /* bytes */ | ||
2623 | 813 | (void*)trd, | ||
2624 | 814 | struct_size); | ||
2625 | 815 | |||
2626 | 816 | g_free (trd); | ||
2627 | 817 | |||
2628 | 818 | return TRUE; | ||
2629 | 819 | } | ||
2630 | 820 | |||
2631 | 821 | static gboolean | ||
2632 | 822 | midori_bookmarks_tree_store_drag_data_get (GtkTreeDragSource* drag_source, | ||
2633 | 823 | GtkTreePath* source_path, | ||
2634 | 824 | GtkSelectionData* selection_data) | ||
2635 | 825 | { | ||
2636 | 826 | MidoriBookmarksTreeStore *tree_store; | ||
2637 | 827 | gboolean status = FALSE; | ||
2638 | 828 | |||
2639 | 829 | g_return_val_if_fail (selection_data != NULL, FALSE); | ||
2640 | 830 | g_return_val_if_fail (GTK_IS_TREE_MODEL (drag_source), FALSE); | ||
2641 | 831 | g_return_val_if_fail (source_path != NULL, FALSE); | ||
2642 | 832 | |||
2643 | 833 | tree_store = MIDORI_BOOKMARKS_TREE_STORE(drag_source); | ||
2644 | 834 | |||
2645 | 835 | if (tree_store->stock_got_rows) | ||
2646 | 836 | { | ||
2647 | 837 | g_list_free_full (tree_store->stock_got_rows, (GDestroyNotify) gtk_tree_path_free); | ||
2648 | 838 | tree_store->stock_got_rows = NULL; | ||
2649 | 839 | } | ||
2650 | 840 | |||
2651 | 841 | if (gtk_selection_data_get_target (selection_data) == | ||
2652 | 842 | gdk_atom_intern_static_string (MIDORI_BOOKMARKS_TREE_MODEL_TARGET)) | ||
2653 | 843 | { | ||
2654 | 844 | GtkTreeModel *model; | ||
2655 | 845 | GList* rows; | ||
2656 | 846 | if (katze_tree_view_get_selected_rows ( | ||
2657 | 847 | tree_store->_view, &model, &rows)) | ||
2658 | 848 | { | ||
2659 | 849 | status = midori_bookmarks_tree_set_row_drag_data (selection_data, model, rows); | ||
2660 | 850 | |||
2661 | 851 | tree_store->stock_got_rows = rows; | ||
2662 | 852 | } | ||
2663 | 853 | } | ||
2664 | 854 | |||
2665 | 855 | return status; | ||
2666 | 856 | } | ||
2667 | 857 | |||
2668 | 858 | static void | ||
2669 | 859 | update_path_list_for_insert (GList * rows, GtkTreePath* path) | ||
2670 | 860 | { | ||
2671 | 861 | gint length = g_list_length (rows); | ||
2672 | 862 | gint i; | ||
2673 | 863 | |||
2674 | 864 | for (i = 0; i < length; i++ ) | ||
2675 | 865 | { | ||
2676 | 866 | GtkTreePath *src_path_r = (GtkTreePath *)g_list_nth_data (rows, i); | ||
2677 | 867 | gint la = gtk_tree_path_get_depth (path); | ||
2678 | 868 | gint lb = gtk_tree_path_get_depth (src_path_r); | ||
2679 | 869 | gint *ia = gtk_tree_path_get_indices (path); | ||
2680 | 870 | gint *ib = gtk_tree_path_get_indices (src_path_r); | ||
2681 | 871 | gint j; | ||
2682 | 872 | |||
2683 | 873 | if (la > lb) /* insert was donne in a deeper branch than source */ | ||
2684 | 874 | continue; | ||
2685 | 875 | |||
2686 | 876 | if (ia[la-1] > ib[la-1]) /* insert was donne after source */ | ||
2687 | 877 | continue; | ||
2688 | 878 | |||
2689 | 879 | for (j = 0; j < la; j++) | ||
2690 | 880 | { | ||
2691 | 881 | if (ia[j] != ib[j]) break; | ||
2692 | 882 | } | ||
2693 | 883 | |||
2694 | 884 | if (j < la-1) /* insert and source are not in the same branch */ | ||
2695 | 885 | continue; | ||
2696 | 886 | |||
2697 | 887 | /* source at depth level of insert must be incremented due to the insert */ | ||
2698 | 888 | ib[la-1] += 1; | ||
2699 | 889 | } | ||
2700 | 890 | } | ||
2701 | 891 | |||
2702 | 892 | static gint | ||
2703 | 893 | midori_tree_path_compare (const GtkTreePath *a, | ||
2704 | 894 | const GtkTreePath *b) | ||
2705 | 895 | { | ||
2706 | 896 | if (!gtk_tree_path_get_depth ((GtkTreePath *)a)) | ||
2707 | 897 | { | ||
2708 | 898 | if (!gtk_tree_path_get_depth ((GtkTreePath *)b)) | ||
2709 | 899 | return 0; | ||
2710 | 900 | |||
2711 | 901 | return -1; | ||
2712 | 902 | } | ||
2713 | 903 | |||
2714 | 904 | if (!gtk_tree_path_get_depth ((GtkTreePath *)b)) | ||
2715 | 905 | return 1; | ||
2716 | 906 | |||
2717 | 907 | return gtk_tree_path_compare (a, b); | ||
2718 | 908 | } | ||
2719 | 909 | |||
2720 | 910 | static GList* | ||
2721 | 911 | update_path_list_for_delete (GList* rows, GtkTreePath* removed_path) | ||
2722 | 912 | { | ||
2723 | 913 | GList* new_rows = rows; | ||
2724 | 914 | |||
2725 | 915 | while (rows) | ||
2726 | 916 | { | ||
2727 | 917 | GtkTreePath *source_path = (GtkTreePath *)rows->data; | ||
2728 | 918 | gint la = gtk_tree_path_get_depth (removed_path); | ||
2729 | 919 | gint lb = gtk_tree_path_get_depth (source_path); | ||
2730 | 920 | gint *ia = gtk_tree_path_get_indices (removed_path); | ||
2731 | 921 | gint *ib = gtk_tree_path_get_indices (source_path); | ||
2732 | 922 | gint cmp = midori_tree_path_compare (removed_path, source_path); | ||
2733 | 923 | gint j; | ||
2734 | 924 | |||
2735 | 925 | if (cmp == 1) /* removal was done after source => kip source as it is */ | ||
2736 | 926 | goto keep_source; | ||
2737 | 927 | |||
2738 | 928 | if (cmp == 0) /* source is removed => remove source */ | ||
2739 | 929 | goto remove_source; | ||
2740 | 930 | |||
2741 | 931 | /* if removal is an ancestor of the source => remove source */ | ||
2742 | 932 | if (gtk_tree_path_is_ancestor (removed_path, source_path)) | ||
2743 | 933 | goto remove_source; | ||
2744 | 934 | |||
2745 | 935 | if (la > lb) /* removal was donne in a deeper branch than source */ | ||
2746 | 936 | goto keep_source; | ||
2747 | 937 | |||
2748 | 938 | for (j = 0; j < la; j++) | ||
2749 | 939 | { | ||
2750 | 940 | if (ia[j] != ib[j]) break; | ||
2751 | 941 | } | ||
2752 | 942 | |||
2753 | 943 | if (j < la-1) /* removal and source are not in the same branch */ | ||
2754 | 944 | goto keep_source; | ||
2755 | 945 | |||
2756 | 946 | /* source at depth level of removal must be decremented due to the removal */ | ||
2757 | 947 | ib[la-1] -= 1; | ||
2758 | 948 | |||
2759 | 949 | if (ib[la-1] >= 0) | ||
2760 | 950 | goto keep_source; | ||
2761 | 951 | |||
2762 | 952 | remove_source: | ||
2763 | 953 | /* remove source entry */ | ||
2764 | 954 | gtk_tree_path_free (source_path); | ||
2765 | 955 | { | ||
2766 | 956 | GList *next_rows = g_list_next (rows); | ||
2767 | 957 | new_rows = g_list_delete_link (new_rows, rows); | ||
2768 | 958 | rows = next_rows; | ||
2769 | 959 | } | ||
2770 | 960 | continue; | ||
2771 | 961 | |||
2772 | 962 | keep_source: | ||
2773 | 963 | rows = g_list_next (rows); | ||
2774 | 964 | } | ||
2775 | 965 | |||
2776 | 966 | return new_rows; | ||
2777 | 967 | } | ||
2778 | 968 | |||
2779 | 969 | static gboolean | ||
2780 | 970 | midori_bookmarks_tree_store_drag_data_delete (GtkTreeDragSource* drag_source, | ||
2781 | 971 | GtkTreePath* source_path) | ||
2782 | 972 | { | ||
2783 | 973 | gboolean status = TRUE; | ||
2784 | 974 | MidoriBookmarksTreeStore *tree_store = MIDORI_BOOKMARKS_TREE_STORE(drag_source); | ||
2785 | 975 | GtkTreeModel* model = GTK_TREE_MODEL(drag_source); | ||
2786 | 976 | |||
2787 | 977 | if (!tree_store->stock_got_rows) | ||
2788 | 978 | return TRUE; | ||
2789 | 979 | |||
2790 | 980 | while (tree_store->stock_got_rows) | ||
2791 | 981 | { | ||
2792 | 982 | GtkTreePath *prev = (GtkTreePath *)tree_store->stock_got_rows->data; | ||
2793 | 983 | GtkTreeIter iter; | ||
2794 | 984 | |||
2795 | 985 | tree_store->stock_got_rows = g_list_delete_link (tree_store->stock_got_rows, | ||
2796 | 986 | tree_store->stock_got_rows); | ||
2797 | 987 | |||
2798 | 988 | if (gtk_tree_model_get_iter (model, &iter, prev)) | ||
2799 | 989 | { | ||
2800 | 990 | /* remove item updating source paths */ | ||
2801 | 991 | gtk_tree_store_remove (GTK_TREE_STORE (drag_source), &iter); | ||
2802 | 992 | |||
2803 | 993 | tree_store->stock_got_rows = update_path_list_for_delete (tree_store->stock_got_rows, prev); | ||
2804 | 994 | } | ||
2805 | 995 | else | ||
2806 | 996 | status = FALSE; | ||
2807 | 997 | |||
2808 | 998 | gtk_tree_path_free (prev); | ||
2809 | 999 | } | ||
2810 | 1000 | |||
2811 | 1001 | return status; | ||
2812 | 1002 | } | ||
2813 | 1003 | |||
2814 | 1004 | static gboolean | ||
2815 | 1005 | midori_bookmarks_tree_store_get_rows_drag_data (GtkSelectionData *selection_data, | ||
2816 | 1006 | GtkTreeModel **tree_model, | ||
2817 | 1007 | GList **rows) | ||
2818 | 1008 | { | ||
2819 | 1009 | TreeRowData *trd; | ||
2820 | 1010 | |||
2821 | 1011 | g_return_val_if_fail (selection_data != NULL, FALSE); | ||
2822 | 1012 | |||
2823 | 1013 | if (tree_model) | ||
2824 | 1014 | *tree_model = NULL; | ||
2825 | 1015 | |||
2826 | 1016 | if (rows) | ||
2827 | 1017 | *rows = NULL; | ||
2828 | 1018 | |||
2829 | 1019 | if (gtk_selection_data_get_target (selection_data) != | ||
2830 | 1020 | gdk_atom_intern_static_string (MIDORI_BOOKMARKS_TREE_MODEL_TARGET)) | ||
2831 | 1021 | return FALSE; | ||
2832 | 1022 | |||
2833 | 1023 | if (gtk_selection_data_get_length (selection_data) < 0) | ||
2834 | 1024 | return FALSE; | ||
2835 | 1025 | |||
2836 | 1026 | trd = (void*) gtk_selection_data_get_data (selection_data); | ||
2837 | 1027 | |||
2838 | 1028 | if (tree_model) | ||
2839 | 1029 | *tree_model = trd->model; | ||
2840 | 1030 | |||
2841 | 1031 | if (rows) | ||
2842 | 1032 | { | ||
2843 | 1033 | GList *list = NULL; | ||
2844 | 1034 | gchar *trd_path = g_strdup (trd->path); | ||
2845 | 1035 | gchar *path_str; | ||
2846 | 1036 | |||
2847 | 1037 | path_str = strtok(trd_path, "\n"); | ||
2848 | 1038 | while (path_str && *path_str) | ||
2849 | 1039 | { | ||
2850 | 1040 | list = g_list_append (list, gtk_tree_path_new_from_string (path_str)); | ||
2851 | 1041 | path_str = strtok (NULL, "\n"); | ||
2852 | 1042 | } | ||
2853 | 1043 | |||
2854 | 1044 | *rows = list; | ||
2855 | 1045 | g_free (trd_path); | ||
2856 | 1046 | } | ||
2857 | 1047 | |||
2858 | 1048 | return TRUE; | ||
2859 | 1049 | } | ||
2860 | 1050 | |||
2861 | 1051 | #if !GTK_CHECK_VERSION (3,0,0) | ||
2862 | 1052 | gboolean | ||
2863 | 1053 | gtk_tree_model_iter_previous (GtkTreeModel *tree_model, | ||
2864 | 1054 | GtkTreeIter *iter) | ||
2865 | 1055 | { | ||
2866 | 1056 | GtkTreePath* path = gtk_tree_model_get_path (tree_model, iter); | ||
2867 | 1057 | gboolean result = gtk_tree_path_prev (path); | ||
2868 | 1058 | |||
2869 | 1059 | if (result) | ||
2870 | 1060 | result = gtk_tree_model_get_iter (tree_model, iter, path); | ||
2871 | 1061 | else | ||
2872 | 1062 | { | ||
2873 | 1063 | GtkTreeIter invalid = {0}; | ||
2874 | 1064 | *iter = invalid; | ||
2875 | 1065 | } | ||
2876 | 1066 | |||
2877 | 1067 | gtk_tree_path_free (path); | ||
2878 | 1068 | return result; | ||
2879 | 1069 | } | ||
2880 | 1070 | #endif | ||
2881 | 1071 | |||
2882 | 1072 | static gboolean | ||
2883 | 1073 | midori_bookmarks_tree_store_row_drop_possible (GtkTreeDragDest* drag_dest, | ||
2884 | 1074 | GtkTreePath* dest_path, | ||
2885 | 1075 | GtkSelectionData* selection_data) | ||
2886 | 1076 | { | ||
2887 | 1077 | GtkTreeModel* dest_model = GTK_TREE_MODEL(drag_dest); | ||
2888 | 1078 | GtkTreePath *parent; | ||
2889 | 1079 | GtkTreeIter dest_parent; | ||
2890 | 1080 | GtkTreeIter *dest_parent_p = NULL; | ||
2891 | 1081 | gboolean row_drop_possible = TRUE; | ||
2892 | 1082 | GtkTreeViewDropPosition drop_position; | ||
2893 | 1083 | |||
2894 | 1084 | gtk_tree_view_get_drag_dest_row (MIDORI_BOOKMARKS_TREE_STORE (dest_model)->_view, | ||
2895 | 1085 | NULL, &drop_position); | ||
2896 | 1086 | |||
2897 | 1087 | parent = gtk_tree_path_copy (dest_path); | ||
2898 | 1088 | if ((gtk_tree_path_get_depth (parent) > 1) | ||
2899 | 1089 | && gtk_tree_path_up (parent) | ||
2900 | 1090 | && gtk_tree_model_get_iter (dest_model, &dest_parent, parent)) | ||
2901 | 1091 | dest_parent_p = &dest_parent; | ||
2902 | 1092 | |||
2903 | 1093 | gtk_tree_path_free (parent); | ||
2904 | 1094 | |||
2905 | 1095 | if (dest_parent_p) | ||
2906 | 1096 | { | ||
2907 | 1097 | KatzeItem* item; | ||
2908 | 1098 | |||
2909 | 1099 | gtk_tree_model_get (dest_model, dest_parent_p, 0, &item, -1); | ||
2910 | 1100 | |||
2911 | 1101 | if (!KATZE_ITEM_IS_FOLDER (item)) | ||
2912 | 1102 | { | ||
2913 | 1103 | #ifdef DEBUG_DROP | ||
2914 | 1104 | gchar *dest_path_str = gtk_tree_path_to_string (dest_path); | ||
2915 | 1105 | |||
2916 | 1106 | g_print ("%s: can only drop into folders\n", dest_path_str); | ||
2917 | 1107 | g_free (dest_path_str); | ||
2918 | 1108 | #endif /* DEBUG_DROP */ | ||
2919 | 1109 | row_drop_possible = FALSE; | ||
2920 | 1110 | } | ||
2921 | 1111 | |||
2922 | 1112 | if (item) | ||
2923 | 1113 | g_object_unref (item); | ||
2924 | 1114 | } | ||
2925 | 1115 | |||
2926 | 1116 | if (row_drop_possible | ||
2927 | 1117 | && (gtk_selection_data_get_target (selection_data) == | ||
2928 | 1118 | gdk_atom_intern_static_string (MIDORI_BOOKMARKS_TREE_MODEL_TARGET))) | ||
2929 | 1119 | { | ||
2930 | 1120 | GtkTreeModel *src_model; | ||
2931 | 1121 | GList* rows; | ||
2932 | 1122 | |||
2933 | 1123 | if (midori_bookmarks_tree_store_get_rows_drag_data (selection_data, | ||
2934 | 1124 | &src_model, &rows)) | ||
2935 | 1125 | { | ||
2936 | 1126 | GtkTreeIter dest_iter; | ||
2937 | 1127 | GList* src_row; | ||
2938 | 1128 | gboolean dest_is_folder = FALSE; | ||
2939 | 1129 | /* gboolean dest_is_bookmark = FALSE; */ | ||
2940 | 1130 | gboolean src_has_folders = FALSE; | ||
2941 | 1131 | gboolean src_has_bookmarks = FALSE; | ||
2942 | 1132 | |||
2943 | 1133 | if (gtk_tree_model_get_iter (dest_model, &dest_iter, dest_path)) | ||
2944 | 1134 | { | ||
2945 | 1135 | if (gtk_tree_model_iter_has_child (dest_model, &dest_iter)) | ||
2946 | 1136 | dest_is_folder = TRUE; | ||
2947 | 1137 | /* | ||
2948 | 1138 | else | ||
2949 | 1139 | { | ||
2950 | 1140 | KatzeItem* item; | ||
2951 | 1141 | gtk_tree_model_get (dest_model, &dest_iter, 0, &item, -1); | ||
2952 | 1142 | if (item) | ||
2953 | 1143 | { | ||
2954 | 1144 | dest_is_bookmark = TRUE; | ||
2955 | 1145 | g_object_unref (item); | ||
2956 | 1146 | } | ||
2957 | 1147 | } | ||
2958 | 1148 | */ | ||
2959 | 1149 | } | ||
2960 | 1150 | |||
2961 | 1151 | for (src_row = rows ; src_row ; src_row = g_list_next (src_row)) | ||
2962 | 1152 | { | ||
2963 | 1153 | GtkTreePath* src_path = (GtkTreePath*)src_row->data; | ||
2964 | 1154 | GtkTreeIter src_iter; | ||
2965 | 1155 | KatzeItem* item; | ||
2966 | 1156 | |||
2967 | 1157 | if (!gtk_tree_model_get_iter (src_model, &src_iter, src_path)) | ||
2968 | 1158 | continue; | ||
2969 | 1159 | |||
2970 | 1160 | gtk_tree_model_get (src_model, &src_iter, 0, &item, -1); | ||
2971 | 1161 | if (item) | ||
2972 | 1162 | { | ||
2973 | 1163 | if (!src_has_folders && KATZE_ITEM_IS_FOLDER (item)) | ||
2974 | 1164 | src_has_folders = TRUE; | ||
2975 | 1165 | else if (!src_has_bookmarks && KATZE_ITEM_IS_BOOKMARK (item)) | ||
2976 | 1166 | src_has_bookmarks = TRUE; | ||
2977 | 1167 | |||
2978 | 1168 | g_object_unref (item); | ||
2979 | 1169 | } | ||
2980 | 1170 | if (src_has_bookmarks && src_has_folders) | ||
2981 | 1171 | break; | ||
2982 | 1172 | } | ||
2983 | 1173 | |||
2984 | 1174 | if (src_has_bookmarks) | ||
2985 | 1175 | { | ||
2986 | 1176 | switch (drop_position) | ||
2987 | 1177 | { | ||
2988 | 1178 | case GTK_TREE_VIEW_DROP_BEFORE: | ||
2989 | 1179 | case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | ||
2990 | 1180 | if (dest_is_folder) | ||
2991 | 1181 | { | ||
2992 | 1182 | #ifdef DEBUG_DROP | ||
2993 | 1183 | gchar *dest_path_str = gtk_tree_path_to_string (dest_path); | ||
2994 | 1184 | |||
2995 | 1185 | g_print ("%s: cannot drop bookmarks in folders group\n", dest_path_str); | ||
2996 | 1186 | g_free (dest_path_str); | ||
2997 | 1187 | #endif /* DEBUG_DROP */ | ||
2998 | 1188 | row_drop_possible = FALSE; | ||
2999 | 1189 | goto done; | ||
3000 | 1190 | } | ||
3001 | 1191 | break; | ||
3002 | 1192 | case GTK_TREE_VIEW_DROP_AFTER: | ||
3003 | 1193 | case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | ||
3004 | 1194 | if (dest_is_folder) | ||
3005 | 1195 | { | ||
3006 | 1196 | gboolean next_dest_is_folder = FALSE; | ||
3007 | 1197 | |||
3008 | 1198 | if (gtk_tree_model_iter_next (dest_model, &dest_iter)) | ||
3009 | 1199 | if (gtk_tree_model_iter_has_child (dest_model, &dest_iter)) | ||
3010 | 1200 | next_dest_is_folder = TRUE; | ||
3011 | 1201 | |||
3012 | 1202 | if (next_dest_is_folder) | ||
3013 | 1203 | { | ||
3014 | 1204 | #ifdef DEBUG_DROP | ||
3015 | 1205 | gchar *dest_path_str = gtk_tree_path_to_string (dest_path); | ||
3016 | 1206 | |||
3017 | 1207 | g_print ("%s: cannot drop bookmarks in folders group\n", dest_path_str); | ||
3018 | 1208 | g_free (dest_path_str); | ||
3019 | 1209 | #endif /* DEBUG_DROP */ | ||
3020 | 1210 | row_drop_possible = FALSE; | ||
3021 | 1211 | goto done; | ||
3022 | 1212 | } | ||
3023 | 1213 | } | ||
3024 | 1214 | break; | ||
3025 | 1215 | default: | ||
3026 | 1216 | break; | ||
3027 | 1217 | } | ||
3028 | 1218 | } | ||
3029 | 1219 | else if (src_has_folders) | ||
3030 | 1220 | { | ||
3031 | 1221 | gboolean prev_dest_is_folder = TRUE; | ||
3032 | 1222 | |||
3033 | 1223 | if (gtk_tree_model_iter_previous (dest_model, &dest_iter)) | ||
3034 | 1224 | if (!gtk_tree_model_iter_has_child (dest_model, &dest_iter)) | ||
3035 | 1225 | prev_dest_is_folder = FALSE; | ||
3036 | 1226 | |||
3037 | 1227 | if (!prev_dest_is_folder) | ||
3038 | 1228 | { | ||
3039 | 1229 | #ifdef DEBUG_DROP | ||
3040 | 1230 | gchar *dest_path_str = gtk_tree_path_to_string (dest_path); | ||
3041 | 1231 | |||
3042 | 1232 | g_print ("%s: cannot drop folders in bookmarks group\n", dest_path_str); | ||
3043 | 1233 | g_free (dest_path_str); | ||
3044 | 1234 | #endif /* DEBUG_DROP */ | ||
3045 | 1235 | row_drop_possible = FALSE; | ||
3046 | 1236 | goto done; | ||
3047 | 1237 | } | ||
3048 | 1238 | } | ||
3049 | 1239 | |||
3050 | 1240 | if (src_model == dest_model) | ||
3051 | 1241 | { | ||
3052 | 1242 | for (src_row = rows ; src_row ; src_row = g_list_next (src_row)) | ||
3053 | 1243 | { | ||
3054 | 1244 | GtkTreePath* src_path = (GtkTreePath*)src_row->data; | ||
3055 | 1245 | |||
3056 | 1246 | /* Can't drop into ourself. */ | ||
3057 | 1247 | if (gtk_tree_path_is_ancestor (src_path, dest_path)) | ||
3058 | 1248 | { | ||
3059 | 1249 | #ifdef DEBUG_DROP | ||
3060 | 1250 | g_print ("cannot drop into source folders\n"); | ||
3061 | 1251 | #endif /* DEBUG_DROP */ | ||
3062 | 1252 | row_drop_possible = FALSE; | ||
3063 | 1253 | goto done; | ||
3064 | 1254 | } | ||
3065 | 1255 | update_path_list_for_insert (rows, dest_path); | ||
3066 | 1256 | } | ||
3067 | 1257 | } | ||
3068 | 1258 | done: | ||
3069 | 1259 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
3070 | 1260 | } | ||
3071 | 1261 | else | ||
3072 | 1262 | row_drop_possible = FALSE; | ||
3073 | 1263 | } | ||
3074 | 1264 | else | ||
3075 | 1265 | row_drop_possible = FALSE; | ||
3076 | 1266 | |||
3077 | 1267 | #ifdef DEBUG_DROP | ||
3078 | 1268 | if (row_drop_possible) | ||
3079 | 1269 | { | ||
3080 | 1270 | gchar *dest_path_str = gtk_tree_path_to_string (dest_path); | ||
3081 | 1271 | gchar *drop_position_str = "unknown"; | ||
3082 | 1272 | switch (drop_position) | ||
3083 | 1273 | { | ||
3084 | 1274 | case GTK_TREE_VIEW_DROP_BEFORE: | ||
3085 | 1275 | drop_position_str = "before"; | ||
3086 | 1276 | break; | ||
3087 | 1277 | case GTK_TREE_VIEW_DROP_AFTER: | ||
3088 | 1278 | drop_position_str = "after"; | ||
3089 | 1279 | break; | ||
3090 | 1280 | case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | ||
3091 | 1281 | drop_position_str = "into or before"; | ||
3092 | 1282 | break; | ||
3093 | 1283 | case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | ||
3094 | 1284 | drop_position_str = "into or after"; | ||
3095 | 1285 | break; | ||
3096 | 1286 | } | ||
3097 | 1287 | |||
3098 | 1288 | g_print ("%s: row drop possible (%s)\n", dest_path_str, drop_position_str); | ||
3099 | 1289 | g_free (dest_path_str); | ||
3100 | 1290 | } | ||
3101 | 1291 | #endif /* DEBUG_DROP */ | ||
3102 | 1292 | |||
3103 | 1293 | return row_drop_possible; | ||
3104 | 1294 | } | ||
3105 | 1295 | |||
3106 | 1296 | static void | ||
3107 | 1297 | copy_node_data (GtkTreeStore *src_store, | ||
3108 | 1298 | GtkTreeIter *src_iter, | ||
3109 | 1299 | GtkTreeStore *dest_store, | ||
3110 | 1300 | GtkTreeIter *dest_iter) | ||
3111 | 1301 | { | ||
3112 | 1302 | gint i; | ||
3113 | 1303 | gint n_columns; | ||
3114 | 1304 | GtkTreeModel* src_model = GTK_TREE_MODEL (src_store); | ||
3115 | 1305 | |||
3116 | 1306 | n_columns = gtk_tree_model_get_n_columns (src_model); | ||
3117 | 1307 | |||
3118 | 1308 | for (i = 0; i < n_columns; i++) | ||
3119 | 1309 | { | ||
3120 | 1310 | void *item; | ||
3121 | 1311 | |||
3122 | 1312 | gtk_tree_model_get (src_model, src_iter, i, &item, -1); | ||
3123 | 1313 | gtk_tree_store_set (dest_store, dest_iter, i, item, -1); | ||
3124 | 1314 | } | ||
3125 | 1315 | } | ||
3126 | 1316 | |||
3127 | 1317 | static void | ||
3128 | 1318 | recursive_node_copy (GtkTreeStore *src_store, | ||
3129 | 1319 | GtkTreeIter *src_iter, | ||
3130 | 1320 | GtkTreeStore *dest_store, | ||
3131 | 1321 | GtkTreeIter *dest_iter) | ||
3132 | 1322 | { | ||
3133 | 1323 | GtkTreeIter child; | ||
3134 | 1324 | GtkTreeModel *src_model = GTK_TREE_MODEL (src_store); | ||
3135 | 1325 | |||
3136 | 1326 | copy_node_data (src_store, src_iter, dest_store, dest_iter); | ||
3137 | 1327 | |||
3138 | 1328 | if (gtk_tree_model_iter_children (src_model, &child, src_iter)) | ||
3139 | 1329 | { | ||
3140 | 1330 | /* Need to create children and recurse. Note our | ||
3141 | 1331 | * dependence on persistent iterators here. | ||
3142 | 1332 | */ | ||
3143 | 1333 | do | ||
3144 | 1334 | { | ||
3145 | 1335 | GtkTreeIter copy; | ||
3146 | 1336 | |||
3147 | 1337 | /* Gee, a really slow algorithm... ;-) FIXME */ | ||
3148 | 1338 | gtk_tree_store_append (dest_store, | ||
3149 | 1339 | ©, | ||
3150 | 1340 | dest_iter); | ||
3151 | 1341 | |||
3152 | 1342 | recursive_node_copy (src_store, &child, dest_store, ©); | ||
3153 | 1343 | } | ||
3154 | 1344 | while (gtk_tree_model_iter_next (src_model, &child)); | ||
3155 | 1345 | } | ||
3156 | 1346 | } | ||
3157 | 1347 | |||
3158 | 1348 | static gboolean | ||
3159 | 1349 | midori_bookmarks_tree_store_drag_data_received (GtkTreeDragDest *drag_dest, | ||
3160 | 1350 | GtkTreePath *dest_path, | ||
3161 | 1351 | GtkSelectionData *selection_data) | ||
3162 | 1352 | { | ||
3163 | 1353 | gboolean status = TRUE; | ||
3164 | 1354 | |||
3165 | 1355 | g_return_val_if_fail (selection_data != NULL, FALSE); | ||
3166 | 1356 | g_return_val_if_fail (GTK_IS_TREE_MODEL (drag_dest), FALSE); | ||
3167 | 1357 | g_return_val_if_fail (dest_path != NULL, FALSE); | ||
3168 | 1358 | |||
3169 | 1359 | if (gtk_selection_data_get_target (selection_data) == | ||
3170 | 1360 | gdk_atom_intern_static_string (MIDORI_BOOKMARKS_TREE_MODEL_TARGET)) | ||
3171 | 1361 | { | ||
3172 | 1362 | GtkTreeStore *dest_store = GTK_TREE_STORE (drag_dest); | ||
3173 | 1363 | GtkTreeModel *dest_model = GTK_TREE_MODEL (drag_dest); | ||
3174 | 1364 | GtkTreeModel *src_model; | ||
3175 | 1365 | GList* rows; | ||
3176 | 1366 | |||
3177 | 1367 | if (midori_bookmarks_tree_store_get_rows_drag_data (selection_data, | ||
3178 | 1368 | &src_model, &rows)) | ||
3179 | 1369 | { | ||
3180 | 1370 | GtkTreeStore *src_store = GTK_TREE_STORE (src_model); | ||
3181 | 1371 | GtkTreePath *prev = gtk_tree_path_copy (dest_path); | ||
3182 | 1372 | |||
3183 | 1373 | gint count = 0; | ||
3184 | 1374 | gint length = g_list_length (rows); | ||
3185 | 1375 | gint i; | ||
3186 | 1376 | |||
3187 | 1377 | for (i = 0; i < length; i++) | ||
3188 | 1378 | { | ||
3189 | 1379 | GtkTreeIter dest_iter; | ||
3190 | 1380 | GtkTreeIter src_iter; | ||
3191 | 1381 | GtkTreePath *src_path = (GtkTreePath *)g_list_nth_data (rows, i); | ||
3192 | 1382 | |||
3193 | 1383 | if (!gtk_tree_model_get_iter (src_model, &src_iter, src_path)) | ||
3194 | 1384 | continue; | ||
3195 | 1385 | |||
3196 | 1386 | /* Get the path to insert _after_ (dest is the path to insert _before_) */ | ||
3197 | 1387 | if (i == 0) | ||
3198 | 1388 | { | ||
3199 | 1389 | if (!gtk_tree_path_prev (prev)) | ||
3200 | 1390 | { /* Get the parent, NULL if parent is the root */ | ||
3201 | 1391 | GtkTreeIter dest_parent; | ||
3202 | 1392 | GtkTreePath *parent = gtk_tree_path_copy (dest_path); | ||
3203 | 1393 | GtkTreeIter *dest_parent_p = NULL; | ||
3204 | 1394 | |||
3205 | 1395 | if (gtk_tree_path_up (parent) && | ||
3206 | 1396 | gtk_tree_path_get_depth (parent) > 0) | ||
3207 | 1397 | { | ||
3208 | 1398 | gtk_tree_model_get_iter (dest_model, | ||
3209 | 1399 | &dest_parent, parent); | ||
3210 | 1400 | dest_parent_p = &dest_parent; | ||
3211 | 1401 | } | ||
3212 | 1402 | gtk_tree_path_free (parent); | ||
3213 | 1403 | |||
3214 | 1404 | gtk_tree_store_prepend (dest_store, &dest_iter, dest_parent_p); | ||
3215 | 1405 | } | ||
3216 | 1406 | else if (gtk_tree_model_get_iter (dest_model, &dest_iter, prev)) | ||
3217 | 1407 | { | ||
3218 | 1408 | GtkTreeIter tmp_iter = dest_iter; | ||
3219 | 1409 | |||
3220 | 1410 | gtk_tree_store_insert_after (dest_store, &dest_iter, NULL, | ||
3221 | 1411 | &tmp_iter); | ||
3222 | 1412 | } | ||
3223 | 1413 | } | ||
3224 | 1414 | else if (gtk_tree_model_get_iter (dest_model, &dest_iter, prev)) | ||
3225 | 1415 | { | ||
3226 | 1416 | GtkTreeIter tmp_iter = dest_iter; | ||
3227 | 1417 | |||
3228 | 1418 | gtk_tree_store_insert_after (dest_store, &dest_iter, NULL, | ||
3229 | 1419 | &tmp_iter); | ||
3230 | 1420 | } | ||
3231 | 1421 | |||
3232 | 1422 | gtk_tree_path_free (prev); | ||
3233 | 1423 | |||
3234 | 1424 | recursive_node_copy (src_store, &src_iter, dest_store, &dest_iter); | ||
3235 | 1425 | count++; | ||
3236 | 1426 | |||
3237 | 1427 | prev = gtk_tree_model_get_path (dest_model, &dest_iter); | ||
3238 | 1428 | |||
3239 | 1429 | if (src_store != dest_store) | ||
3240 | 1430 | continue; | ||
3241 | 1431 | |||
3242 | 1432 | update_path_list_for_insert (rows, prev); | ||
3243 | 1433 | } | ||
3244 | 1434 | |||
3245 | 1435 | gtk_tree_path_free (prev); | ||
3246 | 1436 | |||
3247 | 1437 | g_assert (count == length); | ||
3248 | 1438 | |||
3249 | 1439 | if (src_store == dest_store) | ||
3250 | 1440 | { | ||
3251 | 1441 | MidoriBookmarksTreeStore *tree_store = MIDORI_BOOKMARKS_TREE_STORE(src_store); | ||
3252 | 1442 | |||
3253 | 1443 | g_list_free_full (tree_store->stock_got_rows, (GDestroyNotify) gtk_tree_path_free); | ||
3254 | 1444 | tree_store->stock_got_rows = rows; | ||
3255 | 1445 | } | ||
3256 | 1446 | else | ||
3257 | 1447 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
3258 | 1448 | } | ||
3259 | 1449 | } | ||
3260 | 1450 | |||
3261 | 1451 | return status; | ||
3262 | 1452 | } | ||
3263 | 1453 | |||
3264 | 1454 | static void | ||
3265 | 1455 | midori_bookmarks_set_item_positon (GtkTreeModel* model, | ||
3266 | 1456 | GtkTreeIter* iter, | ||
3267 | 1457 | gint64 parentid, | ||
3268 | 1458 | MidoriBookmarks* bookmarks) | ||
3269 | 1459 | { | ||
3270 | 1460 | KatzeItem* item; | ||
3271 | 1461 | gint position = 0; | ||
3272 | 1462 | GtkTreeIter next = *iter; | ||
3273 | 1463 | |||
3274 | 1464 | do { | ||
3275 | 1465 | gboolean update = FALSE; | ||
3276 | 1466 | gtk_tree_model_get (model, &next, 0, &item, -1); | ||
3277 | 1467 | |||
3278 | 1468 | if (!KATZE_IS_ITEM (item)) | ||
3279 | 1469 | continue; | ||
3280 | 1470 | |||
3281 | 1471 | if (position != katze_item_get_meta_integer (item, "pos_panel")) | ||
3282 | 1472 | { | ||
3283 | 1473 | katze_item_set_meta_integer (item, "pos_panel", position); | ||
3284 | 1474 | update = TRUE; | ||
3285 | 1475 | } | ||
3286 | 1476 | if (parentid != katze_item_get_meta_integer (item, "parentid")) | ||
3287 | 1477 | { | ||
3288 | 1478 | katze_item_set_meta_integer (item, "parentid", parentid); | ||
3289 | 1479 | update = TRUE; | ||
3290 | 1480 | } | ||
3291 | 1481 | |||
3292 | 1482 | if (update) | ||
3293 | 1483 | midori_bookmarks_update_item (bookmarks, item); | ||
3294 | 1484 | |||
3295 | 1485 | position++; | ||
3296 | 1486 | |||
3297 | 1487 | g_object_unref (item); | ||
3298 | 1488 | } | ||
3299 | 1489 | while (gtk_tree_model_iter_next (model, &next)); | ||
3300 | 1490 | } | ||
3301 | 1491 | |||
3302 | 1492 | static void | ||
3303 | 1493 | assert_reorder_are_folders (GtkTreeModel* model, | ||
3304 | 1494 | MidoriBookmarks* bookmarks) | ||
3305 | 1495 | { | ||
3306 | 1496 | GList* iter; | ||
3307 | 1497 | for (iter = bookmarks->reordered_paths; iter ; iter = g_list_next (iter)) | ||
3308 | 1498 | { | ||
3309 | 1499 | GtkTreePath* path = (GtkTreePath*)iter->data; | ||
3310 | 1500 | GtkTreeIter tree_iter; | ||
3311 | 1501 | |||
3312 | 1502 | if (!gtk_tree_path_get_depth (path)) | ||
3313 | 1503 | continue; | ||
3314 | 1504 | |||
3315 | 1505 | if (gtk_tree_model_get_iter (model, &tree_iter, path)) | ||
3316 | 1506 | { | ||
3317 | 1507 | KatzeItem *item; | ||
3318 | 1508 | |||
3319 | 1509 | gtk_tree_model_get (model, &tree_iter, 0, &item, -1); | ||
3320 | 1510 | |||
3321 | 1511 | g_assert (KATZE_ITEM_IS_FOLDER (item)); | ||
3322 | 1512 | } | ||
3323 | 1513 | } | ||
3324 | 1514 | } | ||
3325 | 1515 | |||
3326 | 1516 | static void | ||
3327 | 1517 | add_parent_to_reorder (GtkTreeModel* model, | ||
3328 | 1518 | GtkTreePath* path, | ||
3329 | 1519 | MidoriBookmarks* bookmarks) | ||
3330 | 1520 | { | ||
3331 | 1521 | GtkTreePath* path_copy = gtk_tree_path_copy (path); | ||
3332 | 1522 | GList* found; | ||
3333 | 1523 | |||
3334 | 1524 | midori_bookmarks_idle_start (bookmarks); | ||
3335 | 1525 | |||
3336 | 1526 | if (gtk_tree_path_get_depth (path_copy) > 1 | ||
3337 | 1527 | && gtk_tree_path_up (path_copy)) | ||
3338 | 1528 | { | ||
3339 | 1529 | GtkTreeIter iter; | ||
3340 | 1530 | if (gtk_tree_model_get_iter (model, &iter, path_copy)) | ||
3341 | 1531 | { | ||
3342 | 1532 | KatzeItem* item; | ||
3343 | 1533 | gtk_tree_model_get (model, &iter, 0, &item, -1); | ||
3344 | 1534 | if (item) | ||
3345 | 1535 | { | ||
3346 | 1536 | g_assert (KATZE_ITEM_IS_FOLDER (item)); | ||
3347 | 1537 | g_object_unref (item); | ||
3348 | 1538 | } | ||
3349 | 1539 | else | ||
3350 | 1540 | g_assert_not_reached (); | ||
3351 | 1541 | } | ||
3352 | 1542 | else | ||
3353 | 1543 | g_assert_not_reached (); | ||
3354 | 1544 | } | ||
3355 | 1545 | else | ||
3356 | 1546 | { | ||
3357 | 1547 | gtk_tree_path_free (path_copy); | ||
3358 | 1548 | path_copy = gtk_tree_path_new (); | ||
3359 | 1549 | } | ||
3360 | 1550 | |||
3361 | 1551 | if ((found = g_list_find_custom (bookmarks->reordered_paths, | ||
3362 | 1552 | path_copy, (GCompareFunc)midori_tree_path_compare)) != NULL) | ||
3363 | 1553 | { | ||
3364 | 1554 | gtk_tree_path_free (path_copy); | ||
3365 | 1555 | return; | ||
3366 | 1556 | } | ||
3367 | 1557 | |||
3368 | 1558 | bookmarks->reordered_paths = g_list_append (bookmarks->reordered_paths, path_copy); | ||
3369 | 1559 | } | ||
3370 | 1560 | |||
3371 | 1561 | static void | ||
3372 | 1562 | midori_bookmarks_row_inserted_cb (GtkTreeModel* model, | ||
3373 | 1563 | GtkTreePath* path, | ||
3374 | 1564 | GtkTreeIter* iter, | ||
3375 | 1565 | MidoriBookmarks* bookmarks) | ||
3376 | 1566 | { | ||
3377 | 1567 | midori_bookmarks_idle_start (bookmarks); | ||
3378 | 1568 | |||
3379 | 1569 | update_path_list_for_insert (bookmarks->added_paths, path); | ||
3380 | 1570 | update_path_list_for_insert (bookmarks->reordered_paths, path); | ||
3381 | 1571 | assert_reorder_are_folders (model, bookmarks); | ||
3382 | 1572 | |||
3383 | 1573 | if (g_list_find_custom (bookmarks->added_paths, | ||
3384 | 1574 | path, (GCompareFunc)midori_tree_path_compare)) | ||
3385 | 1575 | return; | ||
3386 | 1576 | |||
3387 | 1577 | bookmarks->added_paths = g_list_append (bookmarks->added_paths, gtk_tree_path_copy (path)); | ||
3388 | 1578 | } | ||
3389 | 1579 | |||
3390 | 1580 | #ifdef DEBUG_LIST | ||
3391 | 1581 | static void | ||
3392 | 1582 | print_path_list (GList* iter) | ||
3393 | 1583 | { | ||
3394 | 1584 | for ( ; iter ; iter = g_list_next (iter)) | ||
3395 | 1585 | { | ||
3396 | 1586 | gchar* str = gtk_tree_path_to_string ((GtkTreePath*)iter->data); | ||
3397 | 1587 | g_print ("%s ", str); | ||
3398 | 1588 | g_free (str); | ||
3399 | 1589 | } | ||
3400 | 1590 | g_print ("\n"); | ||
3401 | 1591 | } | ||
3402 | 1592 | #endif /* DEBUG_LIST */ | ||
3403 | 1593 | |||
3404 | 1594 | static void | ||
3405 | 1595 | midori_bookmarks_row_deleted_cb (GtkTreeModel* model, | ||
3406 | 1596 | GtkTreePath* path, | ||
3407 | 1597 | MidoriBookmarks* bookmarks) | ||
3408 | 1598 | { | ||
3409 | 1599 | #ifdef DEBUG_LIST | ||
3410 | 1600 | gchar* str = gtk_tree_path_to_string (path); | ||
3411 | 1601 | g_print ("midori_bookmarks_row_deleted_cb: path: %s\n", str); | ||
3412 | 1602 | g_free (str); | ||
3413 | 1603 | #endif /* DEBUG_LIST */ | ||
3414 | 1604 | |||
3415 | 1605 | midori_bookmarks_idle_start (bookmarks); | ||
3416 | 1606 | |||
3417 | 1607 | bookmarks->added_paths = update_path_list_for_delete (bookmarks->added_paths, path); | ||
3418 | 1608 | #ifdef DEBUG_LIST | ||
3419 | 1609 | print_path_list (bookmarks->reordered_paths); | ||
3420 | 1610 | #endif /* DEBUG_LIST */ | ||
3421 | 1611 | bookmarks->reordered_paths = update_path_list_for_delete (bookmarks->reordered_paths, path); | ||
3422 | 1612 | #ifdef DEBUG_LIST | ||
3423 | 1613 | print_path_list (bookmarks->reordered_paths); | ||
3424 | 1614 | #endif /* DEBUG_LIST */ | ||
3425 | 1615 | assert_reorder_are_folders (model, bookmarks); | ||
3426 | 1616 | add_parent_to_reorder (model, path, bookmarks); | ||
3427 | 1617 | assert_reorder_are_folders (model, bookmarks); | ||
3428 | 1618 | } | ||
3429 | 495 | 1619 | ||
3430 | 496 | static void | 1620 | static void |
3431 | 497 | midori_bookmarks_row_changed_cb (GtkTreeModel* model, | 1621 | midori_bookmarks_row_changed_cb (GtkTreeModel* model, |
3432 | @@ -499,41 +1623,8 @@ | |||
3433 | 499 | GtkTreeIter* iter, | 1623 | GtkTreeIter* iter, |
3434 | 500 | MidoriBookmarks* bookmarks) | 1624 | MidoriBookmarks* bookmarks) |
3435 | 501 | { | 1625 | { |
3471 | 502 | KatzeItem* item; | 1626 | add_parent_to_reorder (model, path, bookmarks); |
3472 | 503 | GtkTreeIter parent; | 1627 | assert_reorder_are_folders (model, bookmarks); |
3438 | 504 | KatzeItem* new_parent = NULL; | ||
3439 | 505 | gint64 parentid; | ||
3440 | 506 | |||
3441 | 507 | gtk_tree_model_get (model, iter, 0, &item, -1); | ||
3442 | 508 | |||
3443 | 509 | if (gtk_tree_model_iter_parent (model, &parent, iter)) | ||
3444 | 510 | { | ||
3445 | 511 | gtk_tree_model_get (model, &parent, 0, &new_parent, -1); | ||
3446 | 512 | |||
3447 | 513 | /* Bookmarks must not be moved into non-folder items */ | ||
3448 | 514 | if (!KATZE_ITEM_IS_FOLDER (new_parent)) | ||
3449 | 515 | parentid = 0; | ||
3450 | 516 | else | ||
3451 | 517 | parentid = katze_item_get_meta_integer (new_parent, "id"); | ||
3452 | 518 | } | ||
3453 | 519 | else | ||
3454 | 520 | parentid = 0; | ||
3455 | 521 | |||
3456 | 522 | katze_item_set_meta_integer (item, "parentid", parentid); | ||
3457 | 523 | |||
3458 | 524 | g_signal_handlers_block_by_func (bookmarks->bookmarks_db, | ||
3459 | 525 | midori_bookmarks_update_item_cb, | ||
3460 | 526 | bookmarks); | ||
3461 | 527 | |||
3462 | 528 | midori_bookmarks_db_update_item (bookmarks->bookmarks_db, item); | ||
3463 | 529 | |||
3464 | 530 | g_signal_handlers_unblock_by_func (bookmarks->bookmarks_db, | ||
3465 | 531 | midori_bookmarks_update_item_cb, | ||
3466 | 532 | bookmarks); | ||
3467 | 533 | |||
3468 | 534 | g_object_unref (item); | ||
3469 | 535 | if (new_parent) | ||
3470 | 536 | g_object_unref (new_parent); | ||
3473 | 537 | } | 1628 | } |
3474 | 538 | 1629 | ||
3475 | 539 | static void | 1630 | static void |
3476 | @@ -596,7 +1687,7 @@ | |||
3477 | 596 | GtkTreeIter iter; | 1687 | GtkTreeIter iter; |
3478 | 597 | 1688 | ||
3479 | 598 | if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (bookmarks->treeview), | 1689 | if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (bookmarks->treeview), |
3481 | 599 | &model, &iter)) | 1690 | &model, &iter)) |
3482 | 600 | { | 1691 | { |
3483 | 601 | KatzeItem* item; | 1692 | KatzeItem* item; |
3484 | 602 | MidoriBrowser* browser; | 1693 | MidoriBrowser* browser; |
3485 | @@ -616,15 +1707,17 @@ | |||
3486 | 616 | static void | 1707 | static void |
3487 | 617 | midori_bookmarks_toolbar_update (MidoriBookmarks *bookmarks) | 1708 | midori_bookmarks_toolbar_update (MidoriBookmarks *bookmarks) |
3488 | 618 | { | 1709 | { |
3490 | 619 | gboolean selected; | 1710 | gint selected; |
3491 | 620 | 1711 | ||
3493 | 621 | selected = katze_tree_view_get_selected_iter ( | 1712 | selected = katze_tree_view_get_selected_rows ( |
3494 | 622 | GTK_TREE_VIEW (bookmarks->treeview), NULL, NULL); | 1713 | GTK_TREE_VIEW (bookmarks->treeview), NULL, NULL); |
3497 | 623 | gtk_widget_set_sensitive (GTK_WIDGET (bookmarks->delete), selected); | 1714 | gtk_widget_set_sensitive ( |
3498 | 624 | gtk_widget_set_sensitive (GTK_WIDGET (bookmarks->edit), selected); | 1715 | GTK_WIDGET (bookmarks->delete), (selected > 0 ? TRUE : FALSE)); |
3499 | 1716 | gtk_widget_set_sensitive ( | ||
3500 | 1717 | GTK_WIDGET (bookmarks->edit), (selected == 1 ? TRUE : FALSE)); | ||
3501 | 625 | } | 1718 | } |
3502 | 626 | 1719 | ||
3504 | 627 | static gchar* | 1720 | static gchar* |
3505 | 628 | midori_bookmarks_statusbar_bookmarks_str (gint count) | 1721 | midori_bookmarks_statusbar_bookmarks_str (gint count) |
3506 | 629 | { | 1722 | { |
3507 | 630 | if (!count) | 1723 | if (!count) |
3508 | @@ -634,7 +1727,7 @@ | |||
3509 | 634 | return g_strdup_printf (ngettext ("%d bookmark", "%d bookmarks", count), count); | 1727 | return g_strdup_printf (ngettext ("%d bookmark", "%d bookmarks", count), count); |
3510 | 635 | } | 1728 | } |
3511 | 636 | 1729 | ||
3513 | 637 | static gchar* | 1730 | static gchar* |
3514 | 638 | midori_bookmarks_statusbar_subfolders_str (gint count) | 1731 | midori_bookmarks_statusbar_subfolders_str (gint count) |
3515 | 639 | { | 1732 | { |
3516 | 640 | if (!count) | 1733 | if (!count) |
3517 | @@ -648,78 +1741,141 @@ | |||
3518 | 648 | midori_bookmarks_statusbar_update (MidoriBookmarks *bookmarks) | 1741 | midori_bookmarks_statusbar_update (MidoriBookmarks *bookmarks) |
3519 | 649 | { | 1742 | { |
3520 | 650 | gchar* text = NULL; | 1743 | gchar* text = NULL; |
3529 | 651 | 1744 | GtkTreeModel* model; | |
3530 | 652 | if (bookmarks->hovering_item) | 1745 | GList *rows; |
3531 | 653 | { | 1746 | gint selected; |
3532 | 654 | KatzeItem* item = bookmarks->hovering_item; | 1747 | |
3533 | 655 | 1748 | selected = katze_tree_view_get_selected_rows ( | |
3534 | 656 | g_assert (!KATZE_ITEM_IS_SEPARATOR (item)); | 1749 | GTK_TREE_VIEW (bookmarks->treeview), &model, &rows); |
3535 | 657 | 1750 | ||
3536 | 658 | if (KATZE_ITEM_IS_FOLDER (item)) | 1751 | if (selected > 1) |
3537 | 1752 | { | ||
3538 | 1753 | gint i; | ||
3539 | 1754 | gint selected_folders_count = 0; | ||
3540 | 1755 | gint selected_bookmarks_count = 0; | ||
3541 | 1756 | gchar* selected_folders_str = midori_bookmarks_statusbar_subfolders_str (selected_folders_count); | ||
3542 | 1757 | gchar* selected_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (selected_bookmarks_count); | ||
3543 | 1758 | |||
3544 | 1759 | for (i = 0 ; i < selected ; i++) | ||
3545 | 1760 | { | ||
3546 | 1761 | GtkTreeIter iter; | ||
3547 | 1762 | KatzeItem* item; | ||
3548 | 1763 | |||
3549 | 1764 | if (!gtk_tree_model_get_iter ( | ||
3550 | 1765 | model, &iter, (GtkTreePath *)g_list_nth_data (rows, i))) | ||
3551 | 1766 | continue; | ||
3552 | 1767 | |||
3553 | 1768 | gtk_tree_model_get (model, &iter, 0, &item, -1); | ||
3554 | 1769 | |||
3555 | 1770 | g_assert (!KATZE_ITEM_IS_SEPARATOR (item)); | ||
3556 | 1771 | |||
3557 | 1772 | if (KATZE_ITEM_IS_FOLDER (item)) | ||
3558 | 1773 | { | ||
3559 | 1774 | selected_folders_count++; | ||
3560 | 1775 | } | ||
3561 | 1776 | else | ||
3562 | 1777 | { | ||
3563 | 1778 | selected_bookmarks_count++; | ||
3564 | 1779 | } | ||
3565 | 1780 | } | ||
3566 | 1781 | |||
3567 | 1782 | selected_folders_str = midori_bookmarks_statusbar_subfolders_str (selected_folders_count); | ||
3568 | 1783 | selected_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (selected_bookmarks_count); | ||
3569 | 1784 | |||
3570 | 1785 | if (!selected_bookmarks_count && !selected_folders_count) | ||
3571 | 1786 | g_assert_not_reached (); | ||
3572 | 1787 | else if (!selected_bookmarks_count && (selected_folders_count >= 1)) | ||
3573 | 1788 | /* i18n: Selection containing [[n] folder(s)] and no bookmark */ | ||
3574 | 1789 | text = g_strdup_printf (_("Selection containing %s and no bookmark"), | ||
3575 | 1790 | selected_folders_str); | ||
3576 | 1791 | else if ((selected_bookmarks_count >= 1) && !selected_folders_count) | ||
3577 | 1792 | /* i18n: Selection containing [[n] bookmark(s)] */ | ||
3578 | 1793 | text = g_strdup_printf (_("Selection containing %s"), selected_bookmarks_str); | ||
3579 | 1794 | else if ((selected_bookmarks_count >= 1) && (selected_folders_count >= 1)) | ||
3580 | 1795 | /* i18n: Selection containing [[n] bookmark(s)] and [[n] folder(s)] */ | ||
3581 | 1796 | text = g_strdup_printf (_("Selection containing %s and %s"), | ||
3582 | 1797 | selected_bookmarks_str, selected_folders_str); | ||
3583 | 1798 | |||
3584 | 1799 | g_free (selected_folders_str); | ||
3585 | 1800 | g_free (selected_bookmarks_str); | ||
3586 | 1801 | |||
3587 | 1802 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
3588 | 1803 | } | ||
3589 | 1804 | else | ||
3590 | 1805 | { | ||
3591 | 1806 | if (selected) | ||
3592 | 1807 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
3593 | 1808 | |||
3594 | 1809 | if (bookmarks->hovering_item) | ||
3595 | 1810 | { | ||
3596 | 1811 | KatzeItem* item = bookmarks->hovering_item; | ||
3597 | 1812 | |||
3598 | 1813 | if (KATZE_ITEM_IS_FOLDER (item)) | ||
3599 | 1814 | { | ||
3600 | 1815 | gint child_folders_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, | ||
3601 | 1816 | "uri = ''", NULL, item, FALSE); | ||
3602 | 1817 | gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, | ||
3603 | 1818 | "uri <> ''", NULL, item, FALSE); | ||
3604 | 1819 | gchar* child_folders_str = midori_bookmarks_statusbar_subfolders_str (child_folders_count); | ||
3605 | 1820 | gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count); | ||
3606 | 1821 | |||
3607 | 1822 | if (!child_bookmarks_count && !child_folders_count) | ||
3608 | 1823 | /* i18n: Empty folder */ | ||
3609 | 1824 | text = g_strdup_printf (_("Empty folder")); | ||
3610 | 1825 | else if (!child_bookmarks_count && (child_folders_count >= 1)) | ||
3611 | 1826 | /* i18n: Folder containing [[n] folder(s)] and no bookmark */ | ||
3612 | 1827 | text = g_strdup_printf (_("Folder containing %s and no bookmark"), | ||
3613 | 1828 | child_folders_str); | ||
3614 | 1829 | else if ((child_bookmarks_count >= 1) && !child_folders_count) | ||
3615 | 1830 | /* i18n: Folder containing [[n] bookmark(s)] */ | ||
3616 | 1831 | text = g_strdup_printf (_("Folder containing %s"), child_bookmarks_str); | ||
3617 | 1832 | else if ((child_bookmarks_count >= 1) && (child_folders_count >= 1)) | ||
3618 | 1833 | /* i18n: Folder containing [[n] bookmark(s)] and [[n] folder(s)] */ | ||
3619 | 1834 | text = g_strdup_printf (_("Folder containing %s and %s"), | ||
3620 | 1835 | child_bookmarks_str, child_folders_str); | ||
3621 | 1836 | |||
3622 | 1837 | g_free (child_folders_str); | ||
3623 | 1838 | g_free (child_bookmarks_str); | ||
3624 | 1839 | } | ||
3625 | 1840 | else if (KATZE_ITEM_IS_BOOKMARK (item)) | ||
3626 | 1841 | { | ||
3627 | 1842 | const gchar* uri = katze_item_get_uri (item); | ||
3628 | 1843 | |||
3629 | 1844 | /* i18n: Bookmark leading to: [bookmark uri] */ | ||
3630 | 1845 | text = g_strdup_printf (_("Bookmark leading to: %s"), uri); | ||
3631 | 1846 | } | ||
3632 | 1847 | } | ||
3633 | 1848 | else | ||
3634 | 659 | { | 1849 | { |
3635 | 660 | gint child_folders_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, | 1850 | gint child_folders_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, |
3637 | 661 | "uri = ''", NULL, item, FALSE); | 1851 | "uri = ''", NULL, NULL, FALSE); |
3638 | 662 | gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, | 1852 | gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, |
3640 | 663 | "uri <> ''", NULL, item, FALSE); | 1853 | "uri <> ''", NULL, NULL, FALSE); |
3641 | 664 | gchar* child_folders_str = midori_bookmarks_statusbar_subfolders_str (child_folders_count); | 1854 | gchar* child_folders_str = midori_bookmarks_statusbar_subfolders_str (child_folders_count); |
3642 | 665 | gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count); | 1855 | gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count); |
3643 | 666 | 1856 | ||
3650 | 667 | if (!child_bookmarks_count && !child_folders_count) | 1857 | if (!child_bookmarks_count && (child_folders_count >= 1)) |
3651 | 668 | /* i18n: Empty folder */ | 1858 | /* i18n: [[n] folder(s)] and no bookmark */ |
3652 | 669 | text = g_strdup_printf (_("Empty folder")); | 1859 | text = g_strdup_printf (_("%s and no bookmark"), |
3647 | 670 | else if (!child_bookmarks_count && (child_folders_count >= 1)) | ||
3648 | 671 | /* i18n: Folder containing [[n] folder(s)] and no bookmark */ | ||
3649 | 672 | text = g_strdup_printf (_("Folder containing %s and no bookmark"), | ||
3653 | 673 | child_folders_str); | 1860 | child_folders_str); |
3654 | 674 | else if ((child_bookmarks_count >= 1) && !child_folders_count) | 1861 | else if ((child_bookmarks_count >= 1) && !child_folders_count) |
3657 | 675 | /* i18n: Folder containing [[n] bookmark(s)] */ | 1862 | text = g_strdup (child_bookmarks_str); |
3656 | 676 | text = g_strdup_printf (_("Folder containing %s"), child_bookmarks_str); | ||
3658 | 677 | else if ((child_bookmarks_count >= 1) && (child_folders_count >= 1)) | 1863 | else if ((child_bookmarks_count >= 1) && (child_folders_count >= 1)) |
3661 | 678 | /* i18n: Folder containing [[n] bookmark(s)] and [[n] folder(s)] */ | 1864 | /* i18n: [[n] bookmark(s)] and [[n] folder(s)] */ |
3662 | 679 | text = g_strdup_printf (_("Folder containing %s and %s"), | 1865 | text = g_strdup_printf (_("%s and %s"), |
3663 | 680 | child_bookmarks_str, child_folders_str); | 1866 | child_bookmarks_str, child_folders_str); |
3664 | 681 | 1867 | ||
3665 | 682 | g_free (child_folders_str); | 1868 | g_free (child_folders_str); |
3666 | 683 | g_free (child_bookmarks_str); | 1869 | g_free (child_bookmarks_str); |
3667 | 684 | } | 1870 | } |
3668 | 685 | else if (KATZE_ITEM_IS_BOOKMARK (item)) | ||
3669 | 686 | { | ||
3670 | 687 | const gchar* uri = katze_item_get_uri (item); | ||
3671 | 688 | |||
3672 | 689 | /* i18n: Bookmark leading to: [bookmark uri] */ | ||
3673 | 690 | text = g_strdup_printf (_("Bookmark leading to: %s"), uri); | ||
3674 | 691 | } | ||
3675 | 692 | } | ||
3676 | 693 | else | ||
3677 | 694 | { | ||
3678 | 695 | gint child_folders_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, | ||
3679 | 696 | "uri = ''", NULL, NULL, FALSE); | ||
3680 | 697 | gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, | ||
3681 | 698 | "uri <> ''", NULL, NULL, FALSE); | ||
3682 | 699 | gchar* child_folders_str = midori_bookmarks_statusbar_subfolders_str (child_folders_count); | ||
3683 | 700 | gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count); | ||
3684 | 701 | |||
3685 | 702 | if (!child_bookmarks_count && (child_folders_count >= 1)) | ||
3686 | 703 | /* i18n: [[n] folder(s)] and no bookmark */ | ||
3687 | 704 | text = g_strdup_printf (_("%s and no bookmark"), | ||
3688 | 705 | child_folders_str); | ||
3689 | 706 | else if ((child_bookmarks_count >= 1) && !child_folders_count) | ||
3690 | 707 | text = g_strdup (child_bookmarks_str); | ||
3691 | 708 | else if ((child_bookmarks_count >= 1) && (child_folders_count >= 1)) | ||
3692 | 709 | /* i18n: [[n] bookmark(s)] and [[n] folder(s)] */ | ||
3693 | 710 | text = g_strdup_printf (_("%s and %s"), | ||
3694 | 711 | child_bookmarks_str, child_folders_str); | ||
3695 | 712 | |||
3696 | 713 | g_free (child_folders_str); | ||
3697 | 714 | g_free (child_bookmarks_str); | ||
3698 | 715 | } | 1871 | } |
3699 | 716 | 1872 | ||
3700 | 717 | if (text) | 1873 | if (text) |
3701 | 718 | { | 1874 | { |
3702 | 719 | MidoriBrowser* browser = midori_browser_get_for_widget (bookmarks->treeview); | 1875 | MidoriBrowser* browser = midori_browser_get_for_widget (bookmarks->treeview); |
3704 | 720 | 1876 | ||
3705 | 721 | g_object_set (browser, "statusbar-text", text, NULL); | 1877 | g_object_set (browser, "statusbar-text", text, NULL); |
3707 | 722 | 1878 | ||
3708 | 723 | g_free(text); | 1879 | g_free(text); |
3709 | 724 | } | 1880 | } |
3710 | 725 | } | 1881 | } |
3711 | @@ -729,19 +1885,33 @@ | |||
3712 | 729 | MidoriBookmarks* bookmarks) | 1885 | MidoriBookmarks* bookmarks) |
3713 | 730 | { | 1886 | { |
3714 | 731 | GtkTreeModel* model; | 1887 | GtkTreeModel* model; |
3719 | 732 | GtkTreeIter iter; | 1888 | GList* rows; |
3720 | 733 | 1889 | GList* iter_row; | |
3721 | 734 | if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (bookmarks->treeview), | 1890 | |
3722 | 735 | &model, &iter)) | 1891 | if (!katze_tree_view_get_selected_rows(GTK_TREE_VIEW (bookmarks->treeview), |
3723 | 1892 | &model, &rows)) | ||
3724 | 1893 | return; | ||
3725 | 1894 | |||
3726 | 1895 | for (iter_row = rows ; iter_row ; iter_row = g_list_next (iter_row)) | ||
3727 | 736 | { | 1896 | { |
3735 | 737 | KatzeItem* item; | 1897 | GtkTreeIter iter; |
3736 | 738 | 1898 | ||
3737 | 739 | gtk_tree_model_get (model, &iter, 0, &item, -1); | 1899 | if (gtk_tree_model_get_iter (model, &iter, (GtkTreePath *)iter_row->data)) |
3738 | 740 | 1900 | { | |
3739 | 741 | midori_bookmarks_db_remove_item (bookmarks->bookmarks_db, item); | 1901 | KatzeItem* item; |
3740 | 742 | 1902 | ||
3741 | 743 | g_object_unref (item); | 1903 | gtk_tree_model_get (model, &iter, 0, &item, -1); |
3742 | 1904 | |||
3743 | 1905 | if (item) | ||
3744 | 1906 | { | ||
3745 | 1907 | midori_bookmarks_db_remove_item (bookmarks->bookmarks_db, item); | ||
3746 | 1908 | |||
3747 | 1909 | g_object_unref (item); | ||
3748 | 1910 | } | ||
3749 | 1911 | } | ||
3750 | 744 | } | 1912 | } |
3751 | 1913 | |||
3752 | 1914 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
3753 | 745 | } | 1915 | } |
3754 | 746 | 1916 | ||
3755 | 747 | static GtkWidget* | 1917 | static GtkWidget* |
3756 | @@ -759,7 +1929,7 @@ | |||
3757 | 759 | toolitem = gtk_tool_button_new_from_stock (STOCK_BOOKMARK_ADD); | 1929 | toolitem = gtk_tool_button_new_from_stock (STOCK_BOOKMARK_ADD); |
3758 | 760 | gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkAdd"); | 1930 | gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkAdd"); |
3759 | 761 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), | 1931 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), |
3761 | 762 | _("Add a new bookmark")); | 1932 | _("Add a new bookmark")); |
3762 | 763 | gtk_tool_item_set_is_important (toolitem, TRUE); | 1933 | gtk_tool_item_set_is_important (toolitem, TRUE); |
3763 | 764 | g_signal_connect (toolitem, "clicked", | 1934 | g_signal_connect (toolitem, "clicked", |
3764 | 765 | G_CALLBACK (midori_bookmarks_add_clicked_cb), bookmarks); | 1935 | G_CALLBACK (midori_bookmarks_add_clicked_cb), bookmarks); |
3765 | @@ -767,7 +1937,7 @@ | |||
3766 | 767 | gtk_widget_show (GTK_WIDGET (toolitem)); | 1937 | gtk_widget_show (GTK_WIDGET (toolitem)); |
3767 | 768 | toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_EDIT); | 1938 | toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_EDIT); |
3768 | 769 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), | 1939 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), |
3770 | 770 | _("Edit the selected bookmark")); | 1940 | _("Edit the selected bookmark")); |
3771 | 771 | g_signal_connect (toolitem, "clicked", | 1941 | g_signal_connect (toolitem, "clicked", |
3772 | 772 | G_CALLBACK (midori_bookmarks_edit_clicked_cb), bookmarks); | 1942 | G_CALLBACK (midori_bookmarks_edit_clicked_cb), bookmarks); |
3773 | 773 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); | 1943 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); |
3774 | @@ -775,7 +1945,7 @@ | |||
3775 | 775 | bookmarks->edit = GTK_WIDGET (toolitem); | 1945 | bookmarks->edit = GTK_WIDGET (toolitem); |
3776 | 776 | toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE); | 1946 | toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_DELETE); |
3777 | 777 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), | 1947 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), |
3779 | 778 | _("Delete the selected bookmark")); | 1948 | _("Delete the selected bookmark")); |
3780 | 779 | g_signal_connect (toolitem, "clicked", | 1949 | g_signal_connect (toolitem, "clicked", |
3781 | 780 | G_CALLBACK (midori_bookmarks_delete_clicked_cb), bookmarks); | 1950 | G_CALLBACK (midori_bookmarks_delete_clicked_cb), bookmarks); |
3782 | 781 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); | 1951 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); |
3783 | @@ -791,7 +1961,7 @@ | |||
3784 | 791 | toolitem = gtk_tool_button_new_from_stock (STOCK_FOLDER_NEW); | 1961 | toolitem = gtk_tool_button_new_from_stock (STOCK_FOLDER_NEW); |
3785 | 792 | gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkFolderAdd"); | 1962 | gtk_widget_set_name (GTK_WIDGET (toolitem), "BookmarkFolderAdd"); |
3786 | 793 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), | 1963 | gtk_widget_set_tooltip_text (GTK_WIDGET (toolitem), |
3788 | 794 | _("Add a new folder")); | 1964 | _("Add a new folder")); |
3789 | 795 | g_signal_connect (toolitem, "clicked", | 1965 | g_signal_connect (toolitem, "clicked", |
3790 | 796 | G_CALLBACK (midori_bookmarks_add_clicked_cb), bookmarks); | 1966 | G_CALLBACK (midori_bookmarks_add_clicked_cb), bookmarks); |
3791 | 797 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); | 1967 | gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1); |
3792 | @@ -841,6 +2011,12 @@ | |||
3793 | 841 | G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks); | 2011 | G_CALLBACK (midori_bookmarks_remove_item_cb), bookmarks); |
3794 | 842 | g_signal_connect (bookmarks->bookmarks_db, "update", | 2012 | g_signal_connect (bookmarks->bookmarks_db, "update", |
3795 | 843 | G_CALLBACK (midori_bookmarks_update_cb), bookmarks); | 2013 | G_CALLBACK (midori_bookmarks_update_cb), bookmarks); |
3796 | 2014 | g_signal_connect_after (model, "row-inserted", | ||
3797 | 2015 | G_CALLBACK (midori_bookmarks_row_inserted_cb), | ||
3798 | 2016 | bookmarks); | ||
3799 | 2017 | g_signal_connect_after (model, "row-deleted", | ||
3800 | 2018 | G_CALLBACK (midori_bookmarks_row_deleted_cb), | ||
3801 | 2019 | bookmarks); | ||
3802 | 844 | g_signal_connect_after (model, "row-changed", | 2020 | g_signal_connect_after (model, "row-changed", |
3803 | 845 | G_CALLBACK (midori_bookmarks_row_changed_cb), | 2021 | G_CALLBACK (midori_bookmarks_row_changed_cb), |
3804 | 846 | bookmarks); | 2022 | bookmarks); |
3805 | @@ -856,12 +2032,12 @@ | |||
3806 | 856 | 2032 | ||
3807 | 857 | switch (prop_id) | 2033 | switch (prop_id) |
3808 | 858 | { | 2034 | { |
3815 | 859 | case PROP_APP: | 2035 | case PROP_APP: |
3816 | 860 | midori_bookmarks_set_app (bookmarks, g_value_get_object (value)); | 2036 | midori_bookmarks_set_app (bookmarks, g_value_get_object (value)); |
3817 | 861 | break; | 2037 | break; |
3818 | 862 | default: | 2038 | default: |
3819 | 863 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 2039 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
3820 | 864 | break; | 2040 | break; |
3821 | 865 | } | 2041 | } |
3822 | 866 | } | 2042 | } |
3823 | 867 | 2043 | ||
3824 | @@ -875,12 +2051,12 @@ | |||
3825 | 875 | 2051 | ||
3826 | 876 | switch (prop_id) | 2052 | switch (prop_id) |
3827 | 877 | { | 2053 | { |
3834 | 878 | case PROP_APP: | 2054 | case PROP_APP: |
3835 | 879 | g_value_set_object (value, bookmarks->app); | 2055 | g_value_set_object (value, bookmarks->app); |
3836 | 880 | break; | 2056 | break; |
3837 | 881 | default: | 2057 | default: |
3838 | 882 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 2058 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
3839 | 883 | break; | 2059 | break; |
3840 | 884 | } | 2060 | } |
3841 | 885 | } | 2061 | } |
3842 | 886 | 2062 | ||
3843 | @@ -918,8 +2094,8 @@ | |||
3844 | 918 | if (item && katze_item_get_name (item)) | 2094 | if (item && katze_item_get_name (item)) |
3845 | 919 | { | 2095 | { |
3846 | 920 | g_object_set (renderer, "markup", NULL, | 2096 | g_object_set (renderer, "markup", NULL, |
3849 | 921 | "ellipsize", PANGO_ELLIPSIZE_END, | 2097 | "ellipsize", PANGO_ELLIPSIZE_END, |
3850 | 922 | "text", katze_item_get_name (item), NULL); | 2098 | "text", katze_item_get_name (item), NULL); |
3851 | 923 | } | 2099 | } |
3852 | 924 | else | 2100 | else |
3853 | 925 | g_object_set (renderer, "markup", _("<i>Separator</i>"), NULL); | 2101 | g_object_set (renderer, "markup", _("<i>Separator</i>"), NULL); |
3854 | @@ -976,7 +2152,7 @@ | |||
3855 | 976 | menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL); | 2152 | menuitem = gtk_image_menu_item_new_from_stock (stock_id, NULL); |
3856 | 977 | if (label) | 2153 | if (label) |
3857 | 978 | gtk_label_set_text_with_mnemonic (GTK_LABEL (gtk_bin_get_child ( | 2154 | gtk_label_set_text_with_mnemonic (GTK_LABEL (gtk_bin_get_child ( |
3859 | 979 | GTK_BIN (menuitem))), label); | 2155 | GTK_BIN (menuitem))), label); |
3860 | 980 | if (!strcmp (stock_id, GTK_STOCK_EDIT)) | 2156 | if (!strcmp (stock_id, GTK_STOCK_EDIT)) |
3861 | 981 | gtk_widget_set_sensitive (menuitem, | 2157 | gtk_widget_set_sensitive (menuitem, |
3862 | 982 | !KATZE_ITEM_IS_SEPARATOR (item)); | 2158 | !KATZE_ITEM_IS_SEPARATOR (item)); |
3863 | @@ -1007,39 +2183,103 @@ | |||
3864 | 1007 | } | 2183 | } |
3865 | 1008 | } | 2184 | } |
3866 | 1009 | 2185 | ||
3876 | 1010 | static void | 2186 | static GtkWidget* |
3877 | 1011 | midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem, | 2187 | midori_bookmarks_open_bookmark_in_tab (KatzeItem *item, |
3878 | 1012 | MidoriBookmarks* bookmarks) | 2188 | MidoriBrowser* browser) |
3879 | 1013 | { | 2189 | { |
3880 | 1014 | KatzeItem* item; | 2190 | const gchar* uri = katze_item_get_uri (item); |
3881 | 1015 | const gchar* uri; | 2191 | |
3882 | 1016 | 2192 | if (!uri || !*uri) | |
3883 | 1017 | item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem"); | 2193 | return NULL; |
3884 | 1018 | if (KATZE_ITEM_IS_FOLDER (item)) | 2194 | |
3885 | 2195 | return midori_browser_add_item (browser, item); | ||
3886 | 2196 | } | ||
3887 | 2197 | |||
3888 | 2198 | static GtkWidget* | ||
3889 | 2199 | midori_bookmarks_open_folder_in_tab (gint64 parentid, | ||
3890 | 2200 | MidoriBookmarks* bookmarks, | ||
3891 | 2201 | MidoriBrowser* browser) | ||
3892 | 2202 | { | ||
3893 | 2203 | GtkWidget* last_view = NULL; | ||
3894 | 2204 | KatzeArray* array; | ||
3895 | 2205 | |||
3896 | 2206 | array = midori_bookmarks_read_from_db (bookmarks, parentid, NULL); | ||
3897 | 2207 | |||
3898 | 2208 | if (KATZE_IS_ARRAY (array)) | ||
3899 | 1019 | { | 2209 | { |
3900 | 1020 | KatzeItem* child; | 2210 | KatzeItem* child; |
3907 | 1021 | KatzeArray* array; | 2211 | |
3902 | 1022 | |||
3903 | 1023 | array = midori_bookmarks_read_from_db (bookmarks, | ||
3904 | 1024 | katze_item_get_meta_integer (item, "parentid"), NULL); | ||
3905 | 1025 | |||
3906 | 1026 | g_return_if_fail (KATZE_IS_ARRAY (array)); | ||
3908 | 1027 | KATZE_ARRAY_FOREACH_ITEM (child, array) | 2212 | KATZE_ARRAY_FOREACH_ITEM (child, array) |
3909 | 1028 | { | 2213 | { |
3911 | 1029 | if ((uri = katze_item_get_uri (child)) && *uri) | 2214 | GtkWidget* view = midori_bookmarks_open_bookmark_in_tab (child, browser); |
3912 | 2215 | if (view) | ||
3913 | 2216 | last_view = view; | ||
3914 | 2217 | } | ||
3915 | 2218 | } | ||
3916 | 2219 | |||
3917 | 2220 | return last_view; | ||
3918 | 2221 | } | ||
3919 | 2222 | |||
3920 | 2223 | static void | ||
3921 | 2224 | midori_bookmarks_open_in_tab_activate_cb (GtkWidget* menuitem, | ||
3922 | 2225 | MidoriBookmarks* bookmarks) | ||
3923 | 2226 | { | ||
3924 | 2227 | GtkWidget* last_view = NULL; | ||
3925 | 2228 | MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks)); | ||
3926 | 2229 | GtkTreeModel* model; | ||
3927 | 2230 | GList* rows; | ||
3928 | 2231 | gint length; | ||
3929 | 2232 | |||
3930 | 2233 | length = katze_tree_view_get_selected_rows (GTK_TREE_VIEW (bookmarks->treeview), | ||
3931 | 2234 | &model, &rows); | ||
3932 | 2235 | |||
3933 | 2236 | if (!length) | ||
3934 | 2237 | { | ||
3935 | 2238 | KatzeItem* root = KATZE_ITEM (bookmarks->bookmarks_db); | ||
3936 | 2239 | KatzeItem* item = KATZE_ITEM (g_object_get_data (G_OBJECT (menuitem), "KatzeItem")); | ||
3937 | 2240 | |||
3938 | 2241 | if (item != root) | ||
3939 | 2242 | return; | ||
3940 | 2243 | |||
3941 | 2244 | last_view = midori_bookmarks_open_folder_in_tab (0, bookmarks, browser); | ||
3942 | 2245 | } | ||
3943 | 2246 | else | ||
3944 | 2247 | { | ||
3945 | 2248 | gint i; | ||
3946 | 2249 | |||
3947 | 2250 | for (i = 0 ; i < length; i++) | ||
3948 | 2251 | { | ||
3949 | 2252 | GtkTreeIter iter; | ||
3950 | 2253 | |||
3951 | 2254 | if (gtk_tree_model_get_iter ( | ||
3952 | 2255 | model, &iter, (GtkTreePath *)g_list_nth_data (rows, i))) | ||
3953 | 1030 | { | 2256 | { |
3957 | 1031 | MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks)); | 2257 | GtkWidget* view = NULL; |
3958 | 1032 | GtkWidget* view = midori_browser_add_item (browser, child); | 2258 | KatzeItem* item; |
3959 | 1033 | midori_browser_set_current_tab_smartly (browser, view); | 2259 | |
3960 | 2260 | gtk_tree_model_get (model, &iter, 0, &item, -1); | ||
3961 | 2261 | |||
3962 | 2262 | if (KATZE_ITEM_IS_SEPARATOR(item)) | ||
3963 | 2263 | continue; | ||
3964 | 2264 | |||
3965 | 2265 | if (KATZE_ITEM_IS_FOLDER (item)) | ||
3966 | 2266 | view = midori_bookmarks_open_folder_in_tab ( | ||
3967 | 2267 | katze_item_get_meta_integer (item, "id"), bookmarks, browser); | ||
3968 | 2268 | else | ||
3969 | 2269 | view = midori_bookmarks_open_bookmark_in_tab (item, browser); | ||
3970 | 2270 | |||
3971 | 2271 | g_object_unref (item); | ||
3972 | 2272 | |||
3973 | 2273 | if (view) | ||
3974 | 2274 | last_view = view; | ||
3975 | 1034 | } | 2275 | } |
3976 | 1035 | } | 2276 | } |
3984 | 1036 | } | 2277 | |
3985 | 1037 | else if ((uri = katze_item_get_uri (item)) && *uri) | 2278 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); |
3986 | 1038 | { | 2279 | } |
3987 | 1039 | MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (bookmarks)); | 2280 | |
3988 | 1040 | GtkWidget* view = midori_browser_add_item (browser, item); | 2281 | if (last_view) |
3989 | 1041 | midori_browser_set_current_tab_smartly (browser, view); | 2282 | midori_browser_set_current_tab_smartly (browser, last_view); |
3983 | 1042 | } | ||
3990 | 1043 | } | 2283 | } |
3991 | 1044 | 2284 | ||
3992 | 1045 | static void | 2285 | static void |
3993 | @@ -1067,18 +2307,20 @@ | |||
3994 | 1067 | KatzeItem* item, | 2307 | KatzeItem* item, |
3995 | 1068 | MidoriBookmarks* bookmarks) | 2308 | MidoriBookmarks* bookmarks) |
3996 | 1069 | { | 2309 | { |
3997 | 2310 | KatzeItem* root = KATZE_ITEM (bookmarks->bookmarks_db); | ||
3998 | 1070 | GtkWidget* menu; | 2311 | GtkWidget* menu; |
3999 | 1071 | GtkWidget* menuitem; | 2312 | GtkWidget* menuitem; |
4000 | 1072 | 2313 | ||
4001 | 1073 | menu = gtk_menu_new (); | 2314 | menu = gtk_menu_new (); |
4003 | 1074 | if (KATZE_ITEM_IS_FOLDER (item)) | 2315 | if ((item == root) |
4004 | 2316 | || KATZE_ITEM_IS_FOLDER (item)) | ||
4005 | 1075 | { | 2317 | { |
4006 | 1076 | gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, | 2318 | gint child_bookmarks_count = midori_bookmarks_db_count_recursive (bookmarks->bookmarks_db, |
4007 | 1077 | "uri <> ''", NULL, item, FALSE); | 2319 | "uri <> ''", NULL, item, FALSE); |
4008 | 1078 | 2320 | ||
4009 | 1079 | midori_bookmarks_popup_item (menu, | 2321 | midori_bookmarks_popup_item (menu, |
4012 | 1080 | STOCK_TAB_NEW, _("Open all in _Tabs"), item, | 2322 | STOCK_TAB_NEW, _("Open all in _Tabs"), item, |
4013 | 1081 | (!child_bookmarks_count ? NULL : midori_bookmarks_open_in_tab_activate_cb), | 2323 | (!child_bookmarks_count ? NULL : midori_bookmarks_open_in_tab_activate_cb), |
4014 | 1082 | bookmarks); | 2324 | bookmarks); |
4015 | 1083 | } | 2325 | } |
4016 | 1084 | else | 2326 | else |
4017 | @@ -1094,11 +2336,59 @@ | |||
4018 | 1094 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); | 2336 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); |
4019 | 1095 | gtk_widget_show (menuitem); | 2337 | gtk_widget_show (menuitem); |
4020 | 1096 | midori_bookmarks_popup_item (menu, GTK_STOCK_EDIT, NULL, | 2338 | midori_bookmarks_popup_item (menu, GTK_STOCK_EDIT, NULL, |
4026 | 1097 | item, midori_bookmarks_edit_clicked_cb, bookmarks); | 2339 | item, (item == root) ? NULL : midori_bookmarks_edit_clicked_cb, bookmarks); |
4027 | 1098 | midori_bookmarks_popup_item (menu, GTK_STOCK_DELETE, NULL, | 2340 | midori_bookmarks_popup_item (menu, GTK_STOCK_DELETE, NULL, |
4028 | 1099 | item, midori_bookmarks_delete_clicked_cb, bookmarks); | 2341 | item, (item == root) ? NULL : midori_bookmarks_delete_clicked_cb, bookmarks); |
4029 | 1100 | 2342 | ||
4030 | 1101 | katze_widget_popup (widget, GTK_MENU (menu), event, KATZE_MENU_POSITION_CURSOR); | 2343 | katze_widget_popup (widget, GTK_MENU (menu), event, KATZE_MENU_POSITION_CURSOR); |
4031 | 2344 | } | ||
4032 | 2345 | |||
4033 | 2346 | static void | ||
4034 | 2347 | midori_bookmarks_multi_popup (GtkWidget* widget, | ||
4035 | 2348 | GdkEventButton* event, | ||
4036 | 2349 | MidoriBookmarks* bookmarks, | ||
4037 | 2350 | GtkTreeModel* model, | ||
4038 | 2351 | gint count, | ||
4039 | 2352 | GList* rows) | ||
4040 | 2353 | { | ||
4041 | 2354 | GtkWidget* menu; | ||
4042 | 2355 | GtkWidget* menuitem; | ||
4043 | 2356 | |||
4044 | 2357 | menu = gtk_menu_new (); | ||
4045 | 2358 | |||
4046 | 2359 | midori_bookmarks_popup_item (menu, | ||
4047 | 2360 | STOCK_TAB_NEW, _("Open all in _Tabs"), | ||
4048 | 2361 | KATZE_ITEM(bookmarks->bookmarks_db), midori_bookmarks_open_in_tab_activate_cb, bookmarks); | ||
4049 | 2362 | menuitem = gtk_separator_menu_item_new (); | ||
4050 | 2363 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); | ||
4051 | 2364 | gtk_widget_show (menuitem); | ||
4052 | 2365 | |||
4053 | 2366 | midori_bookmarks_popup_item (menu, GTK_STOCK_EDIT, NULL, | ||
4054 | 2367 | NULL, NULL, bookmarks); | ||
4055 | 2368 | midori_bookmarks_popup_item (menu, GTK_STOCK_DELETE, NULL, | ||
4056 | 2369 | KATZE_ITEM(bookmarks->bookmarks_db), midori_bookmarks_delete_clicked_cb, bookmarks); | ||
4057 | 2370 | |||
4058 | 2371 | katze_widget_popup (widget, GTK_MENU (menu), event, KATZE_MENU_POSITION_CURSOR); | ||
4059 | 2372 | } | ||
4060 | 2373 | |||
4061 | 2374 | static gboolean | ||
4062 | 2375 | midori_bookmarks_do_block_selection (GtkTreeSelection *selection, | ||
4063 | 2376 | GtkTreeModel *model, | ||
4064 | 2377 | GtkTreePath *path, | ||
4065 | 2378 | gboolean path_currently_selected, | ||
4066 | 2379 | gpointer data) | ||
4067 | 2380 | { | ||
4068 | 2381 | return FALSE; | ||
4069 | 2382 | } | ||
4070 | 2383 | |||
4071 | 2384 | static gboolean | ||
4072 | 2385 | midori_bookmarks_do_not_block_selection (GtkTreeSelection *selection, | ||
4073 | 2386 | GtkTreeModel *model, | ||
4074 | 2387 | GtkTreePath *path, | ||
4075 | 2388 | gboolean path_currently_selected, | ||
4076 | 2389 | gpointer data) | ||
4077 | 2390 | { | ||
4078 | 2391 | return TRUE; | ||
4079 | 1102 | } | 2392 | } |
4080 | 1103 | 2393 | ||
4081 | 1104 | static gboolean | 2394 | static gboolean |
4082 | @@ -1109,32 +2399,194 @@ | |||
4083 | 1109 | GtkTreeModel* model; | 2399 | GtkTreeModel* model; |
4084 | 1110 | GtkTreeIter iter; | 2400 | GtkTreeIter iter; |
4085 | 1111 | 2401 | ||
4087 | 1112 | if (event->button != 2 && event->button != 3) | 2402 | if (bookmarks->pending_event) |
4088 | 2403 | { | ||
4089 | 2404 | GtkTreeView* treeview = GTK_TREE_VIEW(widget); | ||
4090 | 2405 | GtkTreeSelection* selection = gtk_tree_view_get_selection (treeview); | ||
4091 | 2406 | gint x = bookmarks->stock_pending_event.x; | ||
4092 | 2407 | gint y = bookmarks->stock_pending_event.y; | ||
4093 | 2408 | |||
4094 | 2409 | bookmarks->pending_event = NULL; | ||
4095 | 2410 | gtk_tree_selection_set_select_function ( | ||
4096 | 2411 | selection, midori_bookmarks_do_not_block_selection, NULL, NULL); | ||
4097 | 2412 | |||
4098 | 2413 | if (x != event->x || y != event->y) | ||
4099 | 2414 | return FALSE; | ||
4100 | 2415 | } | ||
4101 | 2416 | |||
4102 | 2417 | if (event->button == 3) | ||
4103 | 2418 | return TRUE; | ||
4104 | 2419 | |||
4105 | 2420 | if (event->button != 2) | ||
4106 | 1113 | return FALSE; | 2421 | return FALSE; |
4107 | 1114 | 2422 | ||
4108 | 1115 | if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter)) | 2423 | if (katze_tree_view_get_selected_iter (GTK_TREE_VIEW (widget), &model, &iter)) |
4109 | 1116 | { | 2424 | { |
4110 | 2425 | gboolean done = FALSE; | ||
4111 | 1117 | KatzeItem* item; | 2426 | KatzeItem* item; |
4112 | 1118 | 2427 | ||
4113 | 1119 | gtk_tree_model_get (model, &iter, 0, &item, -1); | 2428 | gtk_tree_model_get (model, &iter, 0, &item, -1); |
4114 | 1120 | 2429 | ||
4116 | 1121 | if (event->button == 2) | 2430 | if (KATZE_ITEM_IS_BOOKMARK (item)) |
4117 | 1122 | { | 2431 | { |
4120 | 1123 | const gchar* uri; | 2432 | MidoriBrowser* browser = midori_browser_get_for_widget (widget); |
4121 | 1124 | if (KATZE_ITEM_IS_BOOKMARK (item) && (uri = katze_item_get_uri (item)) && *uri) | 2433 | GtkWidget* view = midori_bookmarks_open_bookmark_in_tab ( |
4122 | 2434 | item, browser); | ||
4123 | 2435 | |||
4124 | 2436 | if (widget) | ||
4125 | 1125 | { | 2437 | { |
4129 | 1126 | MidoriBrowser* browser = midori_browser_get_for_widget (widget); | 2438 | midori_browser_set_current_tab_smartly (browser, view); |
4130 | 1127 | GtkWidget* view = midori_browser_add_uri (browser, uri); | 2439 | done = TRUE; |
4128 | 1128 | midori_browser_set_current_tab (browser, view); | ||
4131 | 1129 | } | 2440 | } |
4132 | 1130 | } | 2441 | } |
4140 | 1131 | else | 2442 | |
4141 | 1132 | midori_bookmarks_popup (widget, event, item, bookmarks); | 2443 | g_object_unref (item); |
4142 | 1133 | 2444 | ||
4143 | 1134 | if (item != NULL) | 2445 | return done; |
4144 | 1135 | g_object_unref (item); | 2446 | } |
4145 | 1136 | return TRUE; | 2447 | |
4146 | 1137 | } | 2448 | return FALSE; |
4147 | 2449 | } | ||
4148 | 2450 | |||
4149 | 2451 | static gboolean | ||
4150 | 2452 | midori_bookmarks_block_selection(GtkWidget* widget, | ||
4151 | 2453 | GdkEventButton* event, | ||
4152 | 2454 | MidoriBookmarks* bookmarks) | ||
4153 | 2455 | { | ||
4154 | 2456 | GtkTreeView* treeview = GTK_TREE_VIEW(widget); | ||
4155 | 2457 | GtkTreePath* path; | ||
4156 | 2458 | GtkTreeSelection* selection; | ||
4157 | 2459 | gint cell_x; | ||
4158 | 2460 | gint cell_y; | ||
4159 | 2461 | |||
4160 | 2462 | if (!gtk_tree_view_get_path_at_pos ( | ||
4161 | 2463 | treeview, event->x, event->y, | ||
4162 | 2464 | &path, NULL, &cell_x, &cell_y)) | ||
4163 | 2465 | return FALSE; | ||
4164 | 2466 | |||
4165 | 2467 | gtk_widget_grab_focus (widget); | ||
4166 | 2468 | |||
4167 | 2469 | selection = gtk_tree_view_get_selection (treeview); | ||
4168 | 2470 | |||
4169 | 2471 | if (gtk_tree_selection_path_is_selected (selection, path) | ||
4170 | 2472 | && !(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK))) | ||
4171 | 2473 | { | ||
4172 | 2474 | bookmarks->pending_event = &bookmarks->stock_pending_event; | ||
4173 | 2475 | bookmarks->stock_pending_event.x = event->x; | ||
4174 | 2476 | bookmarks->stock_pending_event.y = event->y; | ||
4175 | 2477 | gtk_tree_selection_set_select_function ( | ||
4176 | 2478 | selection, midori_bookmarks_do_block_selection, NULL, NULL); | ||
4177 | 2479 | } | ||
4178 | 2480 | else | ||
4179 | 2481 | { | ||
4180 | 2482 | bookmarks->pending_event = NULL; | ||
4181 | 2483 | gtk_tree_selection_set_select_function ( | ||
4182 | 2484 | selection, midori_bookmarks_do_not_block_selection, NULL, NULL); | ||
4183 | 2485 | } | ||
4184 | 2486 | |||
4185 | 2487 | return FALSE; | ||
4186 | 2488 | } | ||
4187 | 2489 | |||
4188 | 2490 | static gboolean | ||
4189 | 2491 | midori_bookmarks_button_press_event_cb (GtkWidget* widget, | ||
4190 | 2492 | GdkEventButton* event, | ||
4191 | 2493 | MidoriBookmarks* bookmarks) | ||
4192 | 2494 | { | ||
4193 | 2495 | GtkTreeView* treeview = GTK_TREE_VIEW(widget); | ||
4194 | 2496 | GtkTreePath* path; | ||
4195 | 2497 | GtkTreeSelection* selection; | ||
4196 | 2498 | GtkTreeModel* model; | ||
4197 | 2499 | gint selected; | ||
4198 | 2500 | GList* rows; | ||
4199 | 2501 | gint cell_x; | ||
4200 | 2502 | gint cell_y; | ||
4201 | 2503 | |||
4202 | 2504 | if (event->button == 1) | ||
4203 | 2505 | return midori_bookmarks_block_selection (widget, event, bookmarks); | ||
4204 | 2506 | |||
4205 | 2507 | if (event->button != 3) | ||
4206 | 2508 | return FALSE; | ||
4207 | 2509 | |||
4208 | 2510 | selection = gtk_tree_view_get_selection (treeview); | ||
4209 | 2511 | |||
4210 | 2512 | if (!gtk_tree_view_get_path_at_pos ( | ||
4211 | 2513 | treeview, event->x, event->y, | ||
4212 | 2514 | &path, NULL, &cell_x, &cell_y)) | ||
4213 | 2515 | { | ||
4214 | 2516 | /* FIXME: popup opening below treeview | ||
4215 | 2517 | * Rationale: the user is actually in ROOT folder | ||
4216 | 2518 | * we may need to have a non editable, non deletable, ROOT folder popup | ||
4217 | 2519 | * Open all in Tabs | ||
4218 | 2520 | * Separator | ||
4219 | 2521 | * Edit [inactive] | ||
4220 | 2522 | * Delete [inactive] | ||
4221 | 2523 | * Here we just mimic the Files behaviour: | ||
4222 | 2524 | * 1- unselect all | ||
4223 | 2525 | * 2- let popup based on selection process | ||
4224 | 2526 | */ | ||
4225 | 2527 | |||
4226 | 2528 | gtk_tree_selection_unselect_all (selection); | ||
4227 | 2529 | } | ||
4228 | 2530 | else if (!gtk_tree_selection_path_is_selected (selection, path)) | ||
4229 | 2531 | { | ||
4230 | 2532 | /* Use case: popup opening on item not in selection | ||
4231 | 2533 | * Rationale: the user is addressing a single item not in selection | ||
4232 | 2534 | * we may need a single item popup with callbacks working on the item, | ||
4233 | 2535 | * not the selection. | ||
4234 | 2536 | * Here we just mimic the Files behaviour: | ||
4235 | 2537 | * 1- change the selection to the item the popup is opened on | ||
4236 | 2538 | * 2- let popup based on selection process | ||
4237 | 2539 | */ | ||
4238 | 2540 | |||
4239 | 2541 | gtk_tree_selection_unselect_all (selection); | ||
4240 | 2542 | gtk_tree_selection_select_path (selection, path); | ||
4241 | 2543 | } | ||
4242 | 2544 | |||
4243 | 2545 | selected = katze_tree_view_get_selected_rows(GTK_TREE_VIEW (widget), &model, &rows); | ||
4244 | 2546 | |||
4245 | 2547 | if (!selected) | ||
4246 | 2548 | { | ||
4247 | 2549 | KatzeItem* root = KATZE_ITEM (bookmarks->bookmarks_db); | ||
4248 | 2550 | |||
4249 | 2551 | midori_bookmarks_popup (widget, event, root, bookmarks); | ||
4250 | 2552 | |||
4251 | 2553 | return TRUE; | ||
4252 | 2554 | } | ||
4253 | 2555 | |||
4254 | 2556 | if (selected == 1) | ||
4255 | 2557 | { | ||
4256 | 2558 | GtkTreeIter iter; | ||
4257 | 2559 | KatzeItem* item; | ||
4258 | 2560 | |||
4259 | 2561 | if (!gtk_tree_model_get_iter ( | ||
4260 | 2562 | model, &iter, (GtkTreePath *)g_list_nth_data (rows, 0))) | ||
4261 | 2563 | { | ||
4262 | 2564 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
4263 | 2565 | |||
4264 | 2566 | return FALSE; | ||
4265 | 2567 | } | ||
4266 | 2568 | |||
4267 | 2569 | gtk_tree_model_get (model, &iter, 0, &item, -1); | ||
4268 | 2570 | |||
4269 | 2571 | midori_bookmarks_popup (widget, event, item, bookmarks); | ||
4270 | 2572 | |||
4271 | 2573 | g_object_unref (item); | ||
4272 | 2574 | |||
4273 | 2575 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
4274 | 2576 | |||
4275 | 2577 | return TRUE; | ||
4276 | 2578 | } | ||
4277 | 2579 | |||
4278 | 2580 | if (selected > 1) | ||
4279 | 2581 | { | ||
4280 | 2582 | midori_bookmarks_multi_popup (widget, event, bookmarks, | ||
4281 | 2583 | model, selected, rows); | ||
4282 | 2584 | |||
4283 | 2585 | g_list_free_full (rows, (GDestroyNotify) gtk_tree_path_free); | ||
4284 | 2586 | |||
4285 | 2587 | return TRUE; | ||
4286 | 2588 | } | ||
4287 | 2589 | |||
4288 | 1138 | return FALSE; | 2590 | return FALSE; |
4289 | 1139 | } | 2591 | } |
4290 | 1140 | 2592 | ||
4291 | @@ -1165,39 +2617,74 @@ | |||
4292 | 1165 | } | 2617 | } |
4293 | 1166 | } | 2618 | } |
4294 | 1167 | 2619 | ||
4300 | 1168 | static void | 2620 | static gboolean |
4301 | 1169 | midori_bookmarks_row_expanded_cb (GtkTreeView* treeview, | 2621 | midori_bookmarks_test_expand_row_cb (GtkTreeView* treeview, |
4302 | 1170 | GtkTreeIter* iter, | 2622 | GtkTreeIter* iter, |
4303 | 1171 | GtkTreePath* path, | 2623 | GtkTreePath* path, |
4304 | 1172 | MidoriBookmarks* bookmarks) | 2624 | MidoriBookmarks* bookmarks) |
4305 | 1173 | { | 2625 | { |
4306 | 1174 | GtkTreeModel* model; | 2626 | GtkTreeModel* model; |
4307 | 2627 | GtkTreeIter child; | ||
4308 | 1175 | KatzeItem* item; | 2628 | KatzeItem* item; |
4309 | 2629 | gint64 id; | ||
4310 | 1176 | 2630 | ||
4311 | 1177 | model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); | 2631 | model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); |
4312 | 2632 | |||
4313 | 1178 | gtk_tree_model_get (model, iter, 0, &item, -1); | 2633 | gtk_tree_model_get (model, iter, 0, &item, -1); |
4314 | 2634 | |||
4315 | 2635 | g_return_val_if_fail (KATZE_IS_ITEM(item), TRUE); | ||
4316 | 2636 | |||
4317 | 2637 | g_signal_handlers_block_by_func (model, | ||
4318 | 2638 | midori_bookmarks_row_deleted_cb, | ||
4319 | 2639 | bookmarks); | ||
4320 | 2640 | |||
4321 | 2641 | id = katze_item_get_meta_integer (item, "id"); | ||
4322 | 2642 | |||
4323 | 2643 | g_object_unref (item); | ||
4324 | 2644 | |||
4325 | 2645 | while (gtk_tree_model_iter_children (model, &child, iter)) | ||
4326 | 2646 | gtk_tree_store_remove (GTK_TREE_STORE (model), &child); | ||
4327 | 2647 | /* That's an invisible dummy, so we always have an expander */ | ||
4328 | 2648 | gtk_tree_store_insert_with_values (GTK_TREE_STORE (model), &child, iter, | ||
4329 | 2649 | 0, 0, NULL, -1); | ||
4330 | 2650 | |||
4331 | 2651 | g_signal_handlers_unblock_by_func (model, | ||
4332 | 2652 | midori_bookmarks_row_deleted_cb, | ||
4333 | 2653 | bookmarks); | ||
4334 | 2654 | |||
4335 | 1179 | midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), | 2655 | midori_bookmarks_read_from_db_to_model (bookmarks, GTK_TREE_STORE (model), |
4338 | 1180 | iter, katze_item_get_meta_integer (item, "id"), NULL); | 2656 | iter, id, NULL); |
4339 | 1181 | g_object_unref (item); | 2657 | |
4340 | 2658 | return FALSE; | ||
4341 | 1182 | } | 2659 | } |
4342 | 1183 | 2660 | ||
4343 | 1184 | static void | 2661 | static void |
4344 | 1185 | midori_bookmarks_row_collapsed_cb (GtkTreeView *treeview, | 2662 | midori_bookmarks_row_collapsed_cb (GtkTreeView *treeview, |
4345 | 1186 | GtkTreeIter *parent, | 2663 | GtkTreeIter *parent, |
4346 | 1187 | GtkTreePath *path, | 2664 | GtkTreePath *path, |
4348 | 1188 | gpointer user_data) | 2665 | MidoriBookmarks* bookmarks) |
4349 | 1189 | { | 2666 | { |
4350 | 1190 | GtkTreeModel* model; | 2667 | GtkTreeModel* model; |
4351 | 1191 | GtkTreeStore* treestore; | 2668 | GtkTreeStore* treestore; |
4352 | 1192 | GtkTreeIter child; | 2669 | GtkTreeIter child; |
4353 | 1193 | 2670 | ||
4354 | 1194 | model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); | 2671 | model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)); |
4355 | 2672 | |||
4356 | 2673 | g_signal_handlers_block_by_func (model, | ||
4357 | 2674 | midori_bookmarks_row_deleted_cb, | ||
4358 | 2675 | bookmarks); | ||
4359 | 2676 | |||
4360 | 1195 | treestore = GTK_TREE_STORE (model); | 2677 | treestore = GTK_TREE_STORE (model); |
4361 | 1196 | while (gtk_tree_model_iter_nth_child (model, &child, parent, 0)) | 2678 | while (gtk_tree_model_iter_nth_child (model, &child, parent, 0)) |
4362 | 1197 | gtk_tree_store_remove (treestore, &child); | 2679 | gtk_tree_store_remove (treestore, &child); |
4363 | 1198 | /* That's an invisible dummy, so we always have an expander */ | 2680 | /* That's an invisible dummy, so we always have an expander */ |
4364 | 1199 | gtk_tree_store_insert_with_values (treestore, &child, parent, | 2681 | gtk_tree_store_insert_with_values (treestore, &child, parent, |
4365 | 1200 | 0, 0, NULL, -1); | 2682 | 0, 0, NULL, -1); |
4366 | 2683 | |||
4367 | 2684 | g_signal_handlers_block_by_func (model, | ||
4368 | 2685 | midori_bookmarks_row_deleted_cb, | ||
4369 | 2686 | bookmarks); | ||
4370 | 2687 | |||
4371 | 1201 | } | 2688 | } |
4372 | 1202 | 2689 | ||
4373 | 1203 | static void | 2690 | static void |
4374 | @@ -1205,26 +2692,27 @@ | |||
4375 | 1205 | MidoriBookmarks *bookmarks) | 2692 | MidoriBookmarks *bookmarks) |
4376 | 1206 | { | 2693 | { |
4377 | 1207 | midori_bookmarks_toolbar_update (bookmarks); | 2694 | midori_bookmarks_toolbar_update (bookmarks); |
4378 | 2695 | midori_bookmarks_statusbar_update (bookmarks); | ||
4379 | 1208 | } | 2696 | } |
4380 | 1209 | 2697 | ||
4381 | 1210 | static KatzeItem* | 2698 | static KatzeItem* |
4382 | 1211 | midori_bookmarks_get_item_at_pos (GtkTreeView *treeview, | 2699 | midori_bookmarks_get_item_at_pos (GtkTreeView *treeview, |
4383 | 1212 | gint x, gint y) | 2700 | gint x, gint y) |
4385 | 1213 | { | 2701 | { |
4386 | 1214 | GtkTreeModel* model = gtk_tree_view_get_model (treeview); | 2702 | GtkTreeModel* model = gtk_tree_view_get_model (treeview); |
4387 | 1215 | GtkTreePath* path; | 2703 | GtkTreePath* path; |
4388 | 1216 | GtkTreeIter iter; | 2704 | GtkTreeIter iter; |
4389 | 1217 | KatzeItem* item = NULL; | 2705 | KatzeItem* item = NULL; |
4390 | 1218 | 2706 | ||
4391 | 1219 | gtk_tree_view_get_path_at_pos (treeview, x, y, | 2707 | gtk_tree_view_get_path_at_pos (treeview, x, y, |
4394 | 1220 | &path, NULL, NULL, NULL); | 2708 | &path, NULL, NULL, NULL); |
4395 | 1221 | 2709 | ||
4396 | 1222 | if (!path) | 2710 | if (!path) |
4397 | 1223 | return NULL; | 2711 | return NULL; |
4399 | 1224 | 2712 | ||
4400 | 1225 | if (gtk_tree_model_get_iter (model, &iter, path)) | 2713 | if (gtk_tree_model_get_iter (model, &iter, path)) |
4401 | 1226 | gtk_tree_model_get (model, &iter, 0, &item, -1); | 2714 | gtk_tree_model_get (model, &iter, 0, &item, -1); |
4403 | 1227 | 2715 | ||
4404 | 1228 | gtk_tree_path_free (path); | 2716 | gtk_tree_path_free (path); |
4405 | 1229 | 2717 | ||
4406 | 1230 | return item; | 2718 | return item; |
4407 | @@ -1296,7 +2784,7 @@ | |||
4408 | 1296 | 2784 | ||
4409 | 1297 | if (bookmarks->hovering_item) | 2785 | if (bookmarks->hovering_item) |
4410 | 1298 | g_object_unref (bookmarks->hovering_item); | 2786 | g_object_unref (bookmarks->hovering_item); |
4412 | 1299 | 2787 | ||
4413 | 1300 | bookmarks->hovering_item = NULL; | 2788 | bookmarks->hovering_item = NULL; |
4414 | 1301 | 2789 | ||
4415 | 1302 | g_object_set (browser, "statusbar-text", "", NULL); | 2790 | g_object_set (browser, "statusbar-text", "", NULL); |
4416 | @@ -1337,6 +2825,186 @@ | |||
4417 | 1337 | midori_bookmarks_filter_timeout_cb, bookmarks, NULL); | 2825 | midori_bookmarks_filter_timeout_cb, bookmarks, NULL); |
4418 | 1338 | } | 2826 | } |
4419 | 1339 | 2827 | ||
4420 | 2828 | static GtkTargetEntry midori_bookmarks_dnd_target_entries[]= | ||
4421 | 2829 | { | ||
4422 | 2830 | {MIDORI_BOOKMARKS_TREE_MODEL_TARGET, GTK_TARGET_SAME_WIDGET, 0}, | ||
4423 | 2831 | }; | ||
4424 | 2832 | |||
4425 | 2833 | #define MIDORI_BOOKMARKS_DND_NB_TARGET_ENTRIES \ | ||
4426 | 2834 | G_N_ELEMENTS (midori_bookmarks_dnd_target_entries) | ||
4427 | 2835 | |||
4428 | 2836 | static guint | ||
4429 | 2837 | item_hash (gconstpointer item) | ||
4430 | 2838 | { | ||
4431 | 2839 | gint64 id = katze_item_get_meta_integer (KATZE_ITEM (item), "id"); | ||
4432 | 2840 | return g_int64_hash (&id); | ||
4433 | 2841 | } | ||
4434 | 2842 | |||
4435 | 2843 | static gboolean | ||
4436 | 2844 | item_equal (gconstpointer item_a, gconstpointer item_b) | ||
4437 | 2845 | { | ||
4438 | 2846 | gint64 id_a = katze_item_get_meta_integer (KATZE_ITEM (item_a), "id"); | ||
4439 | 2847 | gint64 id_b = katze_item_get_meta_integer (KATZE_ITEM (item_b), "id"); | ||
4440 | 2848 | return (id_a == id_b)? TRUE : FALSE; | ||
4441 | 2849 | } | ||
4442 | 2850 | |||
4443 | 2851 | static gboolean | ||
4444 | 2852 | midori_bookmarks_idle_func (gpointer data) | ||
4445 | 2853 | { | ||
4446 | 2854 | MidoriBookmarks* bookmarks = MIDORI_BOOKMARKS (data); | ||
4447 | 2855 | GtkTreeModel* model = gtk_tree_view_get_model (GTK_TREE_VIEW (bookmarks->treeview)); | ||
4448 | 2856 | GHashTableIter hash_iter; | ||
4449 | 2857 | gpointer key, value; | ||
4450 | 2858 | GList* list_iter; | ||
4451 | 2859 | |||
4452 | 2860 | /* update remaining additions */ | ||
4453 | 2861 | assert_reorder_are_folders (model, bookmarks); | ||
4454 | 2862 | for (list_iter = bookmarks->added_paths; list_iter ; list_iter = g_list_next (list_iter)) | ||
4455 | 2863 | { | ||
4456 | 2864 | GtkTreePath* path = (GtkTreePath*)list_iter->data; | ||
4457 | 2865 | |||
4458 | 2866 | add_parent_to_reorder (model, path, bookmarks); | ||
4459 | 2867 | assert_reorder_are_folders (model, bookmarks); | ||
4460 | 2868 | } | ||
4461 | 2869 | |||
4462 | 2870 | g_list_free_full (bookmarks->added_paths, (GDestroyNotify) gtk_tree_path_free); | ||
4463 | 2871 | bookmarks->added_paths = NULL; | ||
4464 | 2872 | |||
4465 | 2873 | /* do actual reordering */ | ||
4466 | 2874 | for (list_iter = bookmarks->reordered_paths; list_iter ; list_iter = g_list_next (list_iter)) | ||
4467 | 2875 | { | ||
4468 | 2876 | GtkTreeIter local_iter; | ||
4469 | 2877 | GtkTreePath* path = (GtkTreePath*)list_iter->data; | ||
4470 | 2878 | |||
4471 | 2879 | if (gtk_tree_path_get_depth (path)) | ||
4472 | 2880 | { | ||
4473 | 2881 | GtkTreeIter parent; | ||
4474 | 2882 | |||
4475 | 2883 | if (gtk_tree_model_get_iter (model, &parent, path)) | ||
4476 | 2884 | { | ||
4477 | 2885 | KatzeItem *item; | ||
4478 | 2886 | gint64 id; | ||
4479 | 2887 | |||
4480 | 2888 | gtk_tree_model_get (model, &parent, 0, &item, -1); | ||
4481 | 2889 | |||
4482 | 2890 | g_assert (KATZE_ITEM_IS_FOLDER (item)); | ||
4483 | 2891 | |||
4484 | 2892 | id = katze_item_get_meta_integer (item, "id"); | ||
4485 | 2893 | |||
4486 | 2894 | if (gtk_tree_model_iter_children (model, &local_iter, &parent)) | ||
4487 | 2895 | midori_bookmarks_set_item_positon(model, &local_iter, id, bookmarks); | ||
4488 | 2896 | |||
4489 | 2897 | /* update folder array for menu update */ | ||
4490 | 2898 | katze_array_update (KATZE_ARRAY (item)); | ||
4491 | 2899 | |||
4492 | 2900 | g_object_unref (item); | ||
4493 | 2901 | } | ||
4494 | 2902 | } | ||
4495 | 2903 | else | ||
4496 | 2904 | { | ||
4497 | 2905 | if (gtk_tree_model_get_iter_first (model, &local_iter)) | ||
4498 | 2906 | midori_bookmarks_set_item_positon(model, &local_iter, | ||
4499 | 2907 | katze_item_get_meta_integer (KATZE_ITEM (bookmarks->bookmarks_db), "id"), | ||
4500 | 2908 | bookmarks); | ||
4501 | 2909 | |||
4502 | 2910 | g_signal_handlers_block_by_func (bookmarks->bookmarks_db, | ||
4503 | 2911 | midori_bookmarks_update_cb, | ||
4504 | 2912 | bookmarks); | ||
4505 | 2913 | |||
4506 | 2914 | /* update folder array for menu update */ | ||
4507 | 2915 | katze_array_update (KATZE_ARRAY (bookmarks->bookmarks_db)); | ||
4508 | 2916 | |||
4509 | 2917 | g_signal_handlers_unblock_by_func (bookmarks->bookmarks_db, | ||
4510 | 2918 | midori_bookmarks_update_cb, | ||
4511 | 2919 | bookmarks); | ||
4512 | 2920 | } | ||
4513 | 2921 | } | ||
4514 | 2922 | |||
4515 | 2923 | g_list_free_full (bookmarks->reordered_paths, (GDestroyNotify) gtk_tree_path_free); | ||
4516 | 2924 | bookmarks->reordered_paths = NULL; | ||
4517 | 2925 | |||
4518 | 2926 | /* then finalize updates */ | ||
4519 | 2927 | g_signal_handlers_block_by_func (bookmarks->bookmarks_db, | ||
4520 | 2928 | midori_bookmarks_update_item_cb, | ||
4521 | 2929 | bookmarks); | ||
4522 | 2930 | |||
4523 | 2931 | g_hash_table_iter_init (&hash_iter, bookmarks->updated_items); | ||
4524 | 2932 | |||
4525 | 2933 | while (g_hash_table_iter_next (&hash_iter, &key, &value)) | ||
4526 | 2934 | { | ||
4527 | 2935 | midori_bookmarks_db_update_item (bookmarks->bookmarks_db, KATZE_ITEM (value)); | ||
4528 | 2936 | g_object_unref (value); | ||
4529 | 2937 | } | ||
4530 | 2938 | |||
4531 | 2939 | g_signal_handlers_unblock_by_func (bookmarks->bookmarks_db, | ||
4532 | 2940 | midori_bookmarks_update_item_cb, | ||
4533 | 2941 | bookmarks); | ||
4534 | 2942 | |||
4535 | 2943 | g_hash_table_remove_all (bookmarks->updated_items); | ||
4536 | 2944 | |||
4537 | 2945 | /* process pending additions of inserted bookmarks */ | ||
4538 | 2946 | for (list_iter = bookmarks->pending_inserts; list_iter; list_iter = g_list_next (list_iter)) | ||
4539 | 2947 | { | ||
4540 | 2948 | KatzeItem *item = KATZE_ITEM (list_iter->data); | ||
4541 | 2949 | gint64 id = katze_item_get_meta_integer (item, "id"); | ||
4542 | 2950 | GtkTreeIter iter; | ||
4543 | 2951 | |||
4544 | 2952 | if (!midori_bookmarks_reach_item (model, &iter, id)) | ||
4545 | 2953 | midori_bookmarks_add_item (item, bookmarks); | ||
4546 | 2954 | |||
4547 | 2955 | g_object_unref (item); | ||
4548 | 2956 | } | ||
4549 | 2957 | |||
4550 | 2958 | g_list_free (bookmarks->pending_inserts); | ||
4551 | 2959 | bookmarks->pending_inserts = NULL; | ||
4552 | 2960 | return midori_bookmarks_idle_pending (bookmarks); | ||
4553 | 2961 | } | ||
4554 | 2962 | |||
4555 | 2963 | static void | ||
4556 | 2964 | midori_bookmarks_update_item (MidoriBookmarks* bookmarks, KatzeItem *item) | ||
4557 | 2965 | { | ||
4558 | 2966 | midori_bookmarks_idle_start (bookmarks); | ||
4559 | 2967 | |||
4560 | 2968 | if (g_hash_table_lookup (bookmarks->updated_items, item)) | ||
4561 | 2969 | return; | ||
4562 | 2970 | |||
4563 | 2971 | g_object_ref (item); | ||
4564 | 2972 | g_hash_table_insert (bookmarks->updated_items, item, item); | ||
4565 | 2973 | } | ||
4566 | 2974 | |||
4567 | 2975 | static void | ||
4568 | 2976 | midori_bookmarks_idle_remove_item (MidoriBookmarks* bookmarks, KatzeItem *item) | ||
4569 | 2977 | { | ||
4570 | 2978 | gpointer found; | ||
4571 | 2979 | |||
4572 | 2980 | if (KATZE_ITEM_IS_FOLDER (item)) | ||
4573 | 2981 | { | ||
4574 | 2982 | gint64 id = katze_item_get_meta_integer (item, "id"); | ||
4575 | 2983 | GHashTableIter iter; | ||
4576 | 2984 | gpointer key, value; | ||
4577 | 2985 | |||
4578 | 2986 | g_hash_table_iter_init (&iter, bookmarks->updated_items); | ||
4579 | 2987 | |||
4580 | 2988 | while (g_hash_table_iter_next (&iter, &key, &value)) | ||
4581 | 2989 | { | ||
4582 | 2990 | KatzeItem *hash_item = KATZE_ITEM(key); | ||
4583 | 2991 | |||
4584 | 2992 | gint64 parentid = katze_item_get_meta_integer (hash_item, "parentid"); | ||
4585 | 2993 | if (parentid == id) | ||
4586 | 2994 | { | ||
4587 | 2995 | g_hash_table_iter_remove (&iter); | ||
4588 | 2996 | g_object_unref (hash_item); | ||
4589 | 2997 | } | ||
4590 | 2998 | } | ||
4591 | 2999 | } | ||
4592 | 3000 | |||
4593 | 3001 | if ((found = g_hash_table_lookup (bookmarks->updated_items, item)) != NULL) | ||
4594 | 3002 | { | ||
4595 | 3003 | g_hash_table_remove (bookmarks->updated_items, found); | ||
4596 | 3004 | g_object_unref (found); | ||
4597 | 3005 | } | ||
4598 | 3006 | } | ||
4599 | 3007 | |||
4600 | 1340 | static void | 3008 | static void |
4601 | 1341 | midori_bookmarks_init (MidoriBookmarks* bookmarks) | 3009 | midori_bookmarks_init (MidoriBookmarks* bookmarks) |
4602 | 1342 | { | 3010 | { |
4603 | @@ -1349,6 +3017,8 @@ | |||
4604 | 1349 | GtkCellRenderer* renderer_text; | 3017 | GtkCellRenderer* renderer_text; |
4605 | 1350 | GtkTreeSelection* selection; | 3018 | GtkTreeSelection* selection; |
4606 | 1351 | 3019 | ||
4607 | 3020 | bookmarks->pending_event = NULL; | ||
4608 | 3021 | |||
4609 | 1352 | /* Create the filter entry */ | 3022 | /* Create the filter entry */ |
4610 | 1353 | entry = sokoke_search_entry_new (_("Search Bookmarks")); | 3023 | entry = sokoke_search_entry_new (_("Search Bookmarks")); |
4611 | 1354 | g_signal_connect_after (entry, "changed", | 3024 | g_signal_connect_after (entry, "changed", |
4612 | @@ -1359,7 +3029,7 @@ | |||
4613 | 1359 | gtk_box_pack_start (GTK_BOX (bookmarks), box, FALSE, FALSE, 5); | 3029 | gtk_box_pack_start (GTK_BOX (bookmarks), box, FALSE, FALSE, 5); |
4614 | 1360 | 3030 | ||
4615 | 1361 | /* Create the treeview */ | 3031 | /* Create the treeview */ |
4617 | 1362 | model = gtk_tree_store_new (2, KATZE_TYPE_ITEM, G_TYPE_STRING); | 3032 | model = midori_bookmarks_tree_store_new (2, KATZE_TYPE_ITEM, G_TYPE_STRING); |
4618 | 1363 | treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); | 3033 | treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); |
4619 | 1364 | gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); | 3034 | gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); |
4620 | 1365 | gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), 1); | 3035 | gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), 1); |
4621 | @@ -1376,19 +3046,32 @@ | |||
4622 | 1376 | (GtkTreeCellDataFunc)midori_bookmarks_treeview_render_text_cb, | 3046 | (GtkTreeCellDataFunc)midori_bookmarks_treeview_render_text_cb, |
4623 | 1377 | treeview, NULL); | 3047 | treeview, NULL); |
4624 | 1378 | gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); | 3048 | gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); |
4626 | 1379 | gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE); | 3049 | gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), FALSE); |
4627 | 3050 | gtk_tree_view_enable_model_drag_source ( | ||
4628 | 3051 | GTK_TREE_VIEW (treeview), | ||
4629 | 3052 | GDK_BUTTON1_MASK, | ||
4630 | 3053 | midori_bookmarks_dnd_target_entries, | ||
4631 | 3054 | MIDORI_BOOKMARKS_DND_NB_TARGET_ENTRIES, | ||
4632 | 3055 | GDK_ACTION_MOVE|GDK_ACTION_LINK); | ||
4633 | 3056 | gtk_tree_view_enable_model_drag_dest ( | ||
4634 | 3057 | GTK_TREE_VIEW (treeview), | ||
4635 | 3058 | midori_bookmarks_dnd_target_entries, | ||
4636 | 3059 | MIDORI_BOOKMARKS_DND_NB_TARGET_ENTRIES, | ||
4637 | 3060 | GDK_ACTION_MOVE|GDK_ACTION_LINK); | ||
4638 | 1380 | g_object_unref (model); | 3061 | g_object_unref (model); |
4639 | 1381 | g_object_connect (treeview, | 3062 | g_object_connect (treeview, |
4640 | 1382 | "signal::row-activated", | 3063 | "signal::row-activated", |
4641 | 1383 | midori_bookmarks_row_activated_cb, bookmarks, | 3064 | midori_bookmarks_row_activated_cb, bookmarks, |
4642 | 3065 | "signal::button-press-event", | ||
4643 | 3066 | midori_bookmarks_button_press_event_cb, bookmarks, | ||
4644 | 1384 | "signal::button-release-event", | 3067 | "signal::button-release-event", |
4645 | 1385 | midori_bookmarks_button_release_event_cb, bookmarks, | 3068 | midori_bookmarks_button_release_event_cb, bookmarks, |
4646 | 1386 | "signal::key-release-event", | 3069 | "signal::key-release-event", |
4647 | 1387 | midori_bookmarks_key_release_event_cb, bookmarks, | 3070 | midori_bookmarks_key_release_event_cb, bookmarks, |
4648 | 1388 | "signal::popup-menu", | 3071 | "signal::popup-menu", |
4649 | 1389 | midori_bookmarks_popup_menu_cb, bookmarks, | 3072 | midori_bookmarks_popup_menu_cb, bookmarks, |
4652 | 1390 | "signal::row-expanded", | 3073 | "signal::test-expand-row", |
4653 | 1391 | midori_bookmarks_row_expanded_cb, bookmarks, | 3074 | midori_bookmarks_test_expand_row_cb, bookmarks, |
4654 | 1392 | "signal::row-collapsed", | 3075 | "signal::row-collapsed", |
4655 | 1393 | midori_bookmarks_row_collapsed_cb, bookmarks, | 3076 | midori_bookmarks_row_collapsed_cb, bookmarks, |
4656 | 1394 | "signal::enter-notify-event", | 3077 | "signal::enter-notify-event", |
4657 | @@ -1398,18 +3081,27 @@ | |||
4658 | 1398 | "signal::leave-notify-event", | 3081 | "signal::leave-notify-event", |
4659 | 1399 | midori_bookmarks_leave_notify_event_cb, bookmarks, | 3082 | midori_bookmarks_leave_notify_event_cb, bookmarks, |
4660 | 1400 | NULL); | 3083 | NULL); |
4664 | 1401 | gtk_widget_add_events (GTK_WIDGET (treeview), | 3084 | |
4665 | 1402 | GDK_POINTER_MOTION_MASK | 3085 | MIDORI_BOOKMARKS_TREE_STORE (model)->_view = GTK_TREE_VIEW (treeview); |
4666 | 1403 | | GDK_POINTER_MOTION_HINT_MASK); | 3086 | |
4667 | 3087 | gtk_widget_add_events (GTK_WIDGET (treeview), | ||
4668 | 3088 | GDK_POINTER_MOTION_MASK | ||
4669 | 3089 | | GDK_POINTER_MOTION_HINT_MASK); | ||
4670 | 1404 | 3090 | ||
4671 | 1405 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); | 3091 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); |
4672 | 3092 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); | ||
4673 | 1406 | g_signal_connect_after (selection, "changed", | 3093 | g_signal_connect_after (selection, "changed", |
4676 | 1407 | G_CALLBACK (midori_bookmarks_selection_changed_cb), | 3094 | G_CALLBACK (midori_bookmarks_selection_changed_cb), |
4677 | 1408 | bookmarks); | 3095 | bookmarks); |
4678 | 1409 | gtk_widget_show (treeview); | 3096 | gtk_widget_show (treeview); |
4679 | 1410 | gtk_box_pack_start (GTK_BOX (bookmarks), treeview, TRUE, TRUE, 0); | 3097 | gtk_box_pack_start (GTK_BOX (bookmarks), treeview, TRUE, TRUE, 0); |
4680 | 1411 | bookmarks->treeview = treeview; | 3098 | bookmarks->treeview = treeview; |
4681 | 3099 | bookmarks->pending_inserts = NULL; | ||
4682 | 1412 | bookmarks->hovering_item = NULL; | 3100 | bookmarks->hovering_item = NULL; |
4683 | 3101 | bookmarks->pending_inserts = NULL; | ||
4684 | 3102 | bookmarks->updated_items = g_hash_table_new (item_hash, item_equal); | ||
4685 | 3103 | bookmarks->added_paths = NULL; | ||
4686 | 3104 | bookmarks->reordered_paths = NULL; | ||
4687 | 1413 | } | 3105 | } |
4688 | 1414 | 3106 | ||
4689 | 1415 | static void | 3107 | static void |
4690 | @@ -1420,5 +3112,16 @@ | |||
4691 | 1420 | if (bookmarks->app) | 3112 | if (bookmarks->app) |
4692 | 1421 | g_object_unref (bookmarks->app); | 3113 | g_object_unref (bookmarks->app); |
4693 | 1422 | if (bookmarks->hovering_item) | 3114 | if (bookmarks->hovering_item) |
4695 | 1423 | g_object_unref (bookmarks->hovering_item); | 3115 | g_object_unref (bookmarks->hovering_item); |
4696 | 3116 | |||
4697 | 3117 | if (g_idle_remove_by_data (bookmarks)) | ||
4698 | 3118 | { | ||
4699 | 3119 | g_list_free_full (bookmarks->pending_inserts, (GDestroyNotify) g_object_unref); | ||
4700 | 3120 | bookmarks->pending_inserts = NULL; | ||
4701 | 3121 | g_hash_table_unref (bookmarks->updated_items); | ||
4702 | 3122 | g_list_free_full (bookmarks->added_paths, (GDestroyNotify) gtk_tree_path_free); | ||
4703 | 3123 | bookmarks->added_paths = NULL; | ||
4704 | 3124 | g_list_free_full (bookmarks->reordered_paths, (GDestroyNotify) gtk_tree_path_free); | ||
4705 | 3125 | bookmarks->reordered_paths = NULL; | ||
4706 | 3126 | } | ||
4707 | 1424 | } | 3127 | } |
4708 | 1425 | 3128 | ||
4709 | === modified file 'tests/bookmarks.c' | |||
4710 | --- tests/bookmarks.c 2013-08-05 19:52:52 +0000 | |||
4711 | +++ tests/bookmarks.c 2014-01-26 19:44:25 +0000 | |||
4712 | @@ -128,7 +128,7 @@ | |||
4713 | 128 | } | 128 | } |
4714 | 129 | 129 | ||
4715 | 130 | db_items = midori_bookmarks_db_query_recursive (db_bookmarks, | 130 | db_items = midori_bookmarks_db_query_recursive (db_bookmarks, |
4717 | 131 | "*", "title='%q'", katze_item_get_name (test_item), FALSE); | 131 | "*", "title='%q'", katze_item_get_name (test_item), NULL, FALSE); |
4718 | 132 | 132 | ||
4719 | 133 | /* FIXME g_assert_cmpint (katze_array_get_length (db_items), ==, 1); */ | 133 | /* FIXME g_assert_cmpint (katze_array_get_length (db_items), ==, 1); */ |
4720 | 134 | db_item = katze_array_get_nth_item (db_items, 0); | 134 | db_item = katze_array_get_nth_item (db_items, 0); |