Merge lp:~aauzi/midori/fix-1179624 into lp:midori

Proposed by André Auzi
Status: Superseded
Proposed branch: lp:~aauzi/midori/fix-1179624
Merge into: lp:midori
Diff against target: 624 lines (+454/-19)
5 files modified
katze/katze-item.c (+9/-3)
midori/midori-array.c (+150/-0)
midori/midori-array.h (+7/-0)
midori/midori-browser.c (+35/-7)
panels/midori-bookmarks.c (+253/-9)
To merge this branch: bzr merge lp:~aauzi/midori/fix-1179624
Reviewer Review Type Date Requested Status
Paweł Forysiuk Needs Fixing
Cris Dywan Needs Fixing
Review via email: mp+166606@code.launchpad.net

This proposal supersedes a proposal from 2013-05-21.

This proposal has been superseded by a proposal from 2013-05-31.

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

385 + else if (!child_bookmarks_count && child_folders_count)
386 + text = g_strdup_printf(
387 + _("%s : folder, %d subfolders and no bookmark"),
388 + name, child_folders_count);

This should be done using ngettext, leaving gettext to figure out plural forms (there may be a dual form or other grammatical implications the code can't handle).

Is it necessary to implement midori_array_count_recursive using midori_array_query_recursive rather than asking SQlite to count rows? This seems a bit wasteful.

review: Needs Fixing
Revision history for this message
André Auzi (aauzi) wrote : Posted in a previous version of this proposal

> 385 + else if (!child_bookmarks_count && child_folders_count)
> 386 + text = g_strdup_printf(
> 387 + _("%s : folder, %d subfolders and no bookmark"),
> 388 + name, child_folders_count);
>
> This should be done using ngettext, leaving gettext to figure out plural forms
> (there may be a dual form or other grammatical implications the code can't
> handle).

Interesting. I was not aware of ngettext existence. I will give it a try.

> Is it necessary to implement midori_array_count_recursive using
> midori_array_query_recursive rather than asking SQlite to count rows? This
> seems a bit wasteful.

Well, the count within a folder is done using a COUNT(*) sql statement but SQLite does not implement recursive queries therefore I had to implement recursion within the code.

I nevertheless agree, midori_array_query_recursive was the easy path and this has to be changed.
Especially if we consider the fact that I not only retrieve the sub folder id but also its *uri* (!!!goof!!!)

This being noticed I still have doubts about the feature, initially I thought we could need to implement fancy stuff like giving the counts for the whole tree depth if the user press the 'alt' or 'ctrl' modifiers but the feedback I get with one child level actually suits my needs, I wonder if the need of such feature would come up one day.

If nobody needs it, it's the whole idea of recursion that's wasteful and we could just get rid of it and stick to one child level count which is achieved with a single SQL statement.

I wonder if it was the meaning of the remark?

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

Thanks a lot for the updates! I think personally it's fine to do the counting this way, as usual I'd like Paweł's opinion on any bookmark UI changes.

Meanwhile "Open as Web A_pplication" was dropped as a pseudo-bookmark feature, please drop it here as well. Generel agreement is to leave this functionality to the web app extension.

There's also a merge conflict, you'll want to 'bzr merge lp:midori' to resolve it (see also the wiki).

Btw you can use "--fixes=lp:1179624" as an argument to "bzr commit" instead of in the message which makes a clickable link in the log and ensures closing of the bug once it's merged.

review: Needs Fixing
Revision history for this message
Paweł Forysiuk (tuxator) wrote :

Looks promising.

Please resolve conflicts and drop webapp code, it should slim the patch a bit
making it easier to read.

47 + text = g_strdup_printf(
448 + _("%s : folder, %s and %s"),
449 + name,
450 + child_bookmarks_str,
451 + child_folders_str);

Can you maybe "pack" such statements? I don't think this style is used in midori code and it
balloons the patch as well. I see it a couple of places.

+ text = g_strdup_printf(_("%s : folder, %s and %s"),
+ name, child_bookmarks_str, child_folders_str);

Something like this is still readable i think.

As for translatable strings it would be wise to add comments for translators there
/* i18n: some explanation */ Should help those reading the code as well.
Otherwise code looks good. Let's see again after update.

review: Needs Fixing
lp:~aauzi/midori/fix-1179624 updated
6172. By André Auzi

Take into account review remarks

6173. By André Auzi

Merge with lp:midori.

1 conflict solved:
 * remove of Open link as web application in link popup context menu

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

Thanks for the remarks.

Concerning the "web application" removal it was not clear to me if the status bar text and GTK_STOCK_EXECUTE icon use was to be removed as well. I just left them in the proposal so far.

In my opinion they should stay because it's the only remaining visual hint of the special behaviour of a click on such bookmarks.

Nevertheless it's your design decision, just let me know if I have to cleanup this part as well.

If not, a nice improvement, that's unfortunately not yet in my skills abilities, would be to use a combined icon made of the site's favicon and a "web application marker" (maybe a star or something like that...)

lp:~aauzi/midori/fix-1179624 updated
6174. By André Auzi

Fix potential memory leak in:

489 +static KatzeItem*
490 +midori_bookmarks_get_item_at_pos (GtkTreeView *treeview,
491 + gint x, gint y)
492 +{
493 + GtkTreeModel* model = gtk_tree_view_get_model (treeview);
494 + GtkTreePath* path;
495 + GtkTreeIter iter;
496 + KatzeItem* item;
497 +
498 + gtk_tree_view_get_path_at_pos (treeview, x, y,
499 + &path, NULL, NULL, NULL);
500 +
501 + if (!path)
502 + return NULL;
503 +
504 + if (!gtk_tree_model_get_iter (model, &iter, path))
505 + return NULL;
506 +
507 + gtk_tree_model_get (model, &iter, 0, &item, -1);
508 +
509 + gtk_tree_path_free (path); <= can leak if gtk_tree_model_get_iter returned FALSE
510 +
511 + return item;
512 +}

6175. By André Auzi

Complete remove of "app" related code

Take pfor's comments into account: texts simplifications and redundancy
reduced

6176. By André Auzi

Merge lp:midori

6177. By André Auzi

Remove change in midori_browser_bookmark_open_activate_cb

6178. By André Auzi

Change code style

6179. By André Auzi

merge lp:midori

6180. By André Auzi

Take into account review comments + merge lp:midori

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'katze/katze-item.c'
--- katze/katze-item.c 2013-02-21 21:36:30 +0000
+++ katze/katze-item.c 2013-05-31 18:42:28 +0000
@@ -445,8 +445,13 @@
445445
446 g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);446 g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
447447
448 if (widget && KATZE_ITEM_IS_FOLDER (item))448 if (widget)
449 return gtk_widget_render_icon (widget, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);449 {
450 if (KATZE_ITEM_IS_FOLDER (item))
451 return gtk_widget_render_icon (widget, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
452 if (KATZE_ITEM_IS_BOOKMARK (item) && katze_item_get_meta_boolean (item, "app"))
453 return gtk_widget_render_icon (widget, GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU, NULL);
454 }
450 if ((pixbuf = midori_paths_get_icon (katze_item_get_icon (item), NULL)))455 if ((pixbuf = midori_paths_get_icon (katze_item_get_icon (item), NULL)))
451 return pixbuf;456 return pixbuf;
452 if ((pixbuf = midori_paths_get_icon (item->uri, widget)))457 if ((pixbuf = midori_paths_get_icon (item->uri, widget)))
@@ -526,7 +531,8 @@
526 gtk_widget_show (image);531 gtk_widget_show (image);
527 if (pixbuf != NULL)532 if (pixbuf != NULL)
528 g_object_unref (pixbuf);533 g_object_unref (pixbuf);
529 if (KATZE_ITEM_IS_FOLDER (item))534 if (KATZE_ITEM_IS_FOLDER (item)
535 || (KATZE_ITEM_IS_BOOKMARK (item) && katze_item_get_meta_boolean (item, "app")))
530 return image;536 return image;
531 g_object_set_data (G_OBJECT (image), "KatzeItem", g_object_ref (item));537 g_object_set_data (G_OBJECT (image), "KatzeItem", g_object_ref (item));
532 g_signal_connect (image, "destroy",538 g_signal_connect (image, "destroy",
533539
=== modified file 'midori/midori-array.c'
--- midori/midori-array.c 2013-04-16 23:16:24 +0000
+++ midori/midori-array.c 2013-05-31 18:42:28 +0000
@@ -1194,3 +1194,153 @@
1194 return midori_array_query_recursive (bookmarks, fields, condition, value, FALSE);1194 return midori_array_query_recursive (bookmarks, fields, condition, value, FALSE);
1195}1195}
11961196
1197static gint64
1198count_from_sqlite (sqlite3* db,
1199 const gchar* sqlcmd)
1200{
1201 gint64 count = -1;
1202 sqlite3_stmt* stmt;
1203 gint result;
1204
1205 result = sqlite3_prepare_v2 (db, sqlcmd, -1, &stmt, NULL);
1206 if (result != SQLITE_OK)
1207 return -1;
1208
1209 g_assert (sqlite3_column_count (stmt) == 1);
1210
1211 if ((result = sqlite3_step (stmt)) == SQLITE_ROW)
1212 count = sqlite3_column_int64(stmt, 0);
1213
1214 sqlite3_clear_bindings (stmt);
1215 sqlite3_reset (stmt);
1216
1217 return count;
1218}
1219
1220static gint64
1221midori_array_count_recursive_by_id (KatzeArray* bookmarks,
1222 const gchar* condition,
1223 const gchar* value,
1224 gint64 id,
1225 gboolean recursive)
1226{
1227 gint64 count = -1;
1228 sqlite3* db;
1229 gchar* sqlcmd;
1230 char* sqlcmd_value;
1231 sqlite3_stmt* stmt;
1232 gint result;
1233 GList* ids;
1234 GList* iter_ids;
1235
1236 g_return_val_if_fail (condition, -1);
1237 g_return_val_if_fail (KATZE_IS_ARRAY (bookmarks), -1);
1238 db = g_object_get_data (G_OBJECT (bookmarks), "db");
1239 g_return_val_if_fail (db != NULL, -1);
1240
1241 g_assert(!strstr("parentid", condition));
1242
1243 if (id > 0)
1244 sqlcmd = g_strdup_printf ("SELECT COUNT(*) FROM bookmarks "
1245 "WHERE parentid = %" G_GINT64_FORMAT " AND %s",
1246 id,
1247 condition);
1248 else
1249 sqlcmd = g_strdup_printf ("SELECT COUNT(*) FROM bookmarks "
1250 "WHERE parentid IS NULL AND %s ",
1251 condition);
1252
1253 if (strstr (condition, "%q"))
1254 {
1255 sqlcmd_value = sqlite3_mprintf (sqlcmd, value ? value : "");
1256 count = count_from_sqlite (db, sqlcmd_value);
1257 sqlite3_free (sqlcmd_value);
1258 }
1259 else
1260 count = count_from_sqlite (db, sqlcmd);
1261
1262 g_free (sqlcmd);
1263
1264 if (!recursive || (count < 0))
1265 return count;
1266
1267 ids = NULL;
1268
1269 if (id > 0)
1270 sqlcmd_value = sqlite3_mprintf (
1271 "SELECT id FROM bookmarks "
1272 "WHERE parentid = %" G_GINT64_FORMAT " AND uri = ''", id);
1273 else
1274 sqlcmd_value = sqlite3_mprintf (
1275 "SELECT id FROM bookmarks "
1276 "WHERE parentid IS NULL AND uri = ''");
1277
1278 if (sqlite3_prepare_v2 (db, sqlcmd_value, -1, &stmt, NULL) == SQLITE_OK)
1279 {
1280 g_assert (sqlite3_column_count (stmt) == 1);
1281
1282 if ((result = sqlite3_step (stmt)) == SQLITE_ROW)
1283 {
1284 gint64* pid = g_new (gint64, 1);
1285
1286 *pid = sqlite3_column_int64(stmt, 0);
1287 ids = g_list_append (ids, pid);
1288 }
1289
1290 sqlite3_clear_bindings (stmt);
1291 sqlite3_reset (stmt);
1292 }
1293
1294 sqlite3_free (sqlcmd_value);
1295
1296 iter_ids = ids;
1297 while (iter_ids)
1298 {
1299 gint64 sub_count = midori_array_count_recursive_by_id (bookmarks,
1300 condition,
1301 value,
1302 *(gint64*)(iter_ids->data),
1303 recursive);
1304
1305 if (sub_count < 0)
1306 {
1307 g_list_free_full (ids, g_free);
1308 return -1;
1309 }
1310
1311 count += sub_count;
1312 iter_ids = g_list_next (iter_ids);
1313 }
1314
1315 g_list_free_full (ids, g_free);
1316 return count;
1317}
1318
1319/**
1320 * midori_array_count_recursive:
1321 * @array: the main bookmark array
1322 * @condition: condition, like "folder = '%q'"
1323 * @value: a value to be inserted if @condition contains %q
1324 * @recursive: if %TRUE include children
1325 *
1326 * Return value: the number of elements on success, -1 otherwise
1327 *
1328 * Since: 0.5.2
1329 **/
1330gint64
1331midori_array_count_recursive (KatzeArray* bookmarks,
1332 const gchar* condition,
1333 const gchar* value,
1334 KatzeItem* folder,
1335 gboolean recursive)
1336{
1337 gint64 id = -1;
1338
1339 g_return_val_if_fail (!folder || KATZE_ITEM_IS_FOLDER (folder), -1);
1340
1341 id = folder ? katze_item_get_meta_integer (folder, "id") : 0;
1342
1343 return midori_array_count_recursive_by_id (bookmarks, condition,
1344 value, id,
1345 recursive);
1346}
11971347
=== modified file 'midori/midori-array.h'
--- midori/midori-array.h 2012-01-03 20:15:19 +0000
+++ midori/midori-array.h 2013-05-31 18:42:28 +0000
@@ -47,4 +47,11 @@
47katze_array_from_sqlite (sqlite3* db,47katze_array_from_sqlite (sqlite3* db,
48 const gchar* sqlcmd);48 const gchar* sqlcmd);
4949
50gint64
51midori_array_count_recursive (KatzeArray* bookmarks,
52 const gchar* condition,
53 const gchar* value,
54 KatzeItem* folder,
55 gboolean recursive);
56
50#endif /* !__MIDORI_ARRAY_H__ */57#endif /* !__MIDORI_ARRAY_H__ */
5158
=== modified file 'midori/midori-browser.c'
--- midori/midori-browser.c 2013-05-31 03:40:27 +0000
+++ midori/midori-browser.c 2013-05-31 18:42:28 +0000
@@ -4147,7 +4147,10 @@
4147 else if (!KATZE_IS_ARRAY (item) && strcmp (stock_id, GTK_STOCK_DELETE))4147 else if (!KATZE_IS_ARRAY (item) && strcmp (stock_id, GTK_STOCK_DELETE))
4148 gtk_widget_set_sensitive (menuitem, uri != NULL);4148 gtk_widget_set_sensitive (menuitem, uri != NULL);
4149 g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);4149 g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
4150 g_signal_connect (menuitem, "activate", G_CALLBACK (callback), userdata);4150 if (callback)
4151 g_signal_connect (menuitem, "activate", G_CALLBACK (callback), userdata);
4152 else
4153 gtk_widget_set_sensitive (menuitem, FALSE);
4151 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);4154 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
4152 gtk_widget_show (menuitem);4155 gtk_widget_show (menuitem);
4153}4156}
@@ -4156,8 +4159,22 @@
4156midori_browser_bookmark_open_activate_cb (GtkWidget* menuitem,4159midori_browser_bookmark_open_activate_cb (GtkWidget* menuitem,
4157 MidoriBrowser* browser)4160 MidoriBrowser* browser)
4158{4161{
4159 KatzeItem* item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");4162 KatzeItem* item;
4160 midori_browser_open_bookmark (browser, item);4163 const gchar* uri;
4164
4165 item = (KatzeItem*)g_object_get_data (G_OBJECT (menuitem), "KatzeItem");
4166
4167 if ((uri = katze_item_get_uri (item)) && *uri)
4168 {
4169 gchar* uri_fixed = sokoke_magic_uri (uri, TRUE, FALSE);
4170 if (!uri_fixed)
4171 uri_fixed = g_strdup (uri);
4172
4173 midori_browser_set_current_uri (browser, uri_fixed);
4174 gtk_widget_grab_focus (midori_browser_get_current_tab (browser));
4175
4176 g_free (uri_fixed);
4177 }
4161}4178}
41624179
4163static void4180static void
@@ -4237,10 +4254,19 @@
4237 GtkWidget* menuitem;4254 GtkWidget* menuitem;
42384255
4239 menu = gtk_menu_new ();4256 menu = gtk_menu_new ();
4240 if (!katze_item_get_uri (item))4257 if (KATZE_ITEM_IS_FOLDER (item))
4241 midori_browser_bookmark_popup_item (menu,4258 {
4242 STOCK_TAB_NEW, _("Open all in _Tabs"),4259 gint child_bookmarks_count = midori_array_count_recursive (browser->bookmarks,
4243 item, midori_browser_bookmark_open_in_tab_activate_cb, browser);4260 "uri <> ''", NULL, item, FALSE);
4261
4262 if (!child_bookmarks_count)
4263 midori_browser_bookmark_popup_item (menu,
4264 STOCK_TAB_NEW, _("Open all in _Tabs"), item, NULL, browser);
4265 else
4266 midori_browser_bookmark_popup_item (menu,
4267 STOCK_TAB_NEW, _("Open all in _Tabs"),
4268 item, midori_browser_bookmark_open_in_tab_activate_cb, browser);
4269 }
4244 else4270 else
4245 {4271 {
4246 midori_browser_bookmark_popup_item (menu, GTK_STOCK_OPEN, NULL,4272 midori_browser_bookmark_popup_item (menu, GTK_STOCK_OPEN, NULL,
@@ -4252,9 +4278,11 @@
4252 STOCK_WINDOW_NEW, _("Open in New _Window"),4278 STOCK_WINDOW_NEW, _("Open in New _Window"),
4253 item, midori_browser_bookmark_open_in_window_activate_cb, browser);4279 item, midori_browser_bookmark_open_in_window_activate_cb, browser);
4254 }4280 }
4281
4255 menuitem = gtk_separator_menu_item_new ();4282 menuitem = gtk_separator_menu_item_new ();
4256 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);4283 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
4257 gtk_widget_show (menuitem);4284 gtk_widget_show (menuitem);
4285
4258 midori_browser_bookmark_popup_item (menu, GTK_STOCK_EDIT, NULL,4286 midori_browser_bookmark_popup_item (menu, GTK_STOCK_EDIT, NULL,
4259 item, midori_browser_bookmark_edit_activate_cb, widget);4287 item, midori_browser_bookmark_edit_activate_cb, widget);
4260 midori_browser_bookmark_popup_item (menu, GTK_STOCK_DELETE, NULL,4288 midori_browser_bookmark_popup_item (menu, GTK_STOCK_DELETE, NULL,
42614289
=== modified file 'panels/midori-bookmarks.c'
--- panels/midori-bookmarks.c 2013-02-11 21:49:41 +0000
+++ panels/midori-bookmarks.c 2013-05-31 18:42:28 +0000
@@ -39,7 +39,6 @@
39struct _MidoriBookmarks39struct _MidoriBookmarks
40{40{
41 GtkVBox parent_instance;41 GtkVBox parent_instance;
42
43 GtkWidget* toolbar;42 GtkWidget* toolbar;
44 GtkWidget* edit;43 GtkWidget* edit;
45 GtkWidget* delete;44 GtkWidget* delete;
@@ -49,6 +48,8 @@
4948
50 gint filter_timeout;49 gint filter_timeout;
51 gchar* filter;50 gchar* filter;
51
52 KatzeItem* hovering_item;
52};53};
5354
54struct _MidoriBookmarksClass55struct _MidoriBookmarksClass
@@ -86,6 +87,9 @@
86 GParamSpec* pspec);87 GParamSpec* pspec);
8788
88static void89static void
90midori_bookmarks_statusbar_update (MidoriBookmarks *bookmarks);
91
92static void
89midori_bookmarks_class_init (MidoriBookmarksClass* class)93midori_bookmarks_class_init (MidoriBookmarksClass* class)
90{94{
91 GObjectClass* gobject_class;95 GObjectClass* gobject_class;
@@ -441,6 +445,121 @@
441 gtk_widget_set_sensitive (GTK_WIDGET (bookmarks->edit), selected);445 gtk_widget_set_sensitive (GTK_WIDGET (bookmarks->edit), selected);
442}446}
443447
448static gchar*
449midori_bookmarks_statusbar_bookmarks_str (gint count)
450{
451 if (!count)
452 return NULL;
453
454 /* i18n: [n] bookmark(s) */
455 return g_strdup_printf (ngettext ("%d bookmark", "%d bookmarks", count), count);
456}
457
458static gchar*
459midori_bookmarks_statusbar_subfolder_str (gint count)
460{
461 if (!count)
462 return NULL;
463
464 /* i18n: [n] subfolder(s) */
465 return g_strdup_printf (ngettext ("%d subfolder", "%d subfolders", count), count);
466}
467
468static void
469midori_bookmarks_statusbar_update (MidoriBookmarks *bookmarks)
470{
471 gchar* text = NULL;
472 GtkTreeModel* model;
473 GtkTreeIter iter;
474 gboolean selected;
475
476 if (bookmarks->hovering_item)
477 {
478 KatzeItem* item = bookmarks->hovering_item;
479 const gchar* name;
480
481 g_assert (!KATZE_ITEM_IS_SEPARATOR (item));
482
483 name = katze_item_get_name (item);
484
485 if (KATZE_ITEM_IS_FOLDER (item))
486 {
487 gint child_folders_count = midori_array_count_recursive (bookmarks->array,
488 "uri = ''", NULL, item, FALSE);
489 gint child_bookmarks_count = midori_array_count_recursive (bookmarks->array,
490 "uri <> ''", NULL, item, FALSE);
491 gchar* child_folders_str = midori_bookmarks_statusbar_subfolder_str (child_folders_count);
492 gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count);
493
494 if (!child_bookmarks_count && !child_folders_count)
495 /* i18n: [folder name] : empty folder */
496 text = g_strdup_printf(_("%s : empty folder"), name);
497 else if (!child_bookmarks_count && (child_folders_count >= 1))
498 /* i18n: [folder name] : folder, [[n] folder(s)] and no bookmark */
499 text = g_strdup_printf(_("%s : folder, %s and no bookmark"),
500 name, child_folders_str);
501 else if ((child_bookmarks_count >= 1) && !child_folders_count)
502 /* i18n: [folder name] : folder, [[n] bookmark(s)] */
503 text = g_strdup_printf(_("%s : folder, %s"),
504 name, child_bookmarks_str);
505 else if ((child_bookmarks_count >= 1) && (child_folders_count >= 1))
506 /* i18n: [folder name] : folder, [[n] bookmark(s)] and [[n] folder(s)] */
507 text = g_strdup_printf(_("%s : folder, %s and %s"),
508 name, child_bookmarks_str, child_folders_str);
509
510 g_free (child_folders_str);
511 g_free (child_bookmarks_str);
512 }
513 else if (KATZE_ITEM_IS_BOOKMARK (item))
514 {
515 const gchar* uri = katze_item_get_uri (item);
516
517 if (katze_item_get_meta_boolean (item, "app"))
518 /* i18n: [bookmark name] : web application bookmark to : [bookmark uri] */
519 text = g_strdup_printf (_("%s : web application bookmark to : %s"), name, uri);
520 else
521 /* i18n: [bookmark name] : bookmark to : [bookmark uri] */
522 text = g_strdup_printf (_("%s : bookmark to : %s"), name, uri);
523 }
524 }
525 else
526 {
527 gint child_folders_count = midori_array_count_recursive (bookmarks->array,
528 "uri = ''", NULL, NULL, FALSE);
529 gint child_bookmarks_count = midori_array_count_recursive (bookmarks->array,
530 "uri <> ''", NULL, NULL, FALSE);
531 gchar* child_folders_str = midori_bookmarks_statusbar_subfolder_str (child_folders_count);
532 gchar* child_bookmarks_str = midori_bookmarks_statusbar_bookmarks_str (child_bookmarks_count);
533
534 if (!child_bookmarks_count && !child_folders_count)
535 text = g_strdup_printf(_("Bookmarks : empty"));
536 else if (!child_bookmarks_count && (child_folders_count >= 1))
537 /* i18n: Bookmarks : [[n] folder(s)] and no bookmark */
538 text = g_strdup_printf(_("Bookmarks : %s and no bookmark"),
539 child_folders_str);
540 else if ((child_bookmarks_count >= 1) && !child_folders_count)
541 /* i18n: Bookmarks : [[n] bookmark(s)] */
542 text = g_strdup_printf(_("Bookmarks : %s"),
543 child_bookmarks_str);
544 else if ((child_bookmarks_count >= 1) && (child_folders_count >= 1))
545 /* i18n: Bookmarks : [[n] bookmark(s)] and [[n] folder(s)] */
546 text = g_strdup_printf(_("Bookmarks : %s and %s"),
547 child_bookmarks_str, child_folders_str);
548
549 g_free (child_folders_str);
550 g_free (child_bookmarks_str);
551 }
552
553 if (text)
554 {
555 MidoriBrowser* browser = midori_browser_get_for_widget (bookmarks->treeview);
556
557 g_object_set (browser, "statusbar-text", text, NULL);
558
559 g_free(text);
560 }
561}
562
444gboolean563gboolean
445midori_bookmarks_update_item_db (sqlite3* db,564midori_bookmarks_update_item_db (sqlite3* db,
446 KatzeItem* item)565 KatzeItem* item)
@@ -547,6 +666,7 @@
547 gtk_widget_show (GTK_WIDGET (toolitem));666 gtk_widget_show (GTK_WIDGET (toolitem));
548 bookmarks->delete = GTK_WIDGET (toolitem);667 bookmarks->delete = GTK_WIDGET (toolitem);
549 midori_bookmarks_toolbar_update (bookmarks);668 midori_bookmarks_toolbar_update (bookmarks);
669 midori_bookmarks_statusbar_update (bookmarks);
550 toolitem = gtk_separator_tool_item_new ();670 toolitem = gtk_separator_tool_item_new ();
551 gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (toolitem), FALSE);671 gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (toolitem), FALSE);
552 gtk_tool_item_set_expand (toolitem, TRUE);672 gtk_tool_item_set_expand (toolitem, TRUE);
@@ -745,7 +865,10 @@
745 else if (!KATZE_ITEM_IS_FOLDER (item) && strcmp (stock_id, GTK_STOCK_DELETE))865 else if (!KATZE_ITEM_IS_FOLDER (item) && strcmp (stock_id, GTK_STOCK_DELETE))
746 gtk_widget_set_sensitive (menuitem, uri != NULL);866 gtk_widget_set_sensitive (menuitem, uri != NULL);
747 g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);867 g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
748 g_signal_connect (menuitem, "activate", G_CALLBACK (callback), bookmarks);868 if (callback)
869 g_signal_connect (menuitem, "activate", G_CALLBACK (callback), bookmarks);
870 else
871 gtk_widget_set_sensitive (menuitem, FALSE);
749 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);872 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
750 gtk_widget_show (menuitem);873 gtk_widget_show (menuitem);
751}874}
@@ -831,14 +954,24 @@
831954
832 menu = gtk_menu_new ();955 menu = gtk_menu_new ();
833 if (KATZE_ITEM_IS_FOLDER (item))956 if (KATZE_ITEM_IS_FOLDER (item))
834 midori_bookmarks_popup_item (menu,957 {
835 STOCK_TAB_NEW, _("Open all in _Tabs"),958 gint child_bookmarks_count = midori_array_count_recursive (bookmarks->array,
836 item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);959 "uri <> ''", NULL, item, FALSE);
960
961 if (!child_bookmarks_count)
962 midori_bookmarks_popup_item (menu,
963 STOCK_TAB_NEW, _("Open all in _Tabs"),
964 item, NULL, bookmarks);
965 else
966 midori_bookmarks_popup_item (menu,
967 STOCK_TAB_NEW, _("Open all in _Tabs"),
968 item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);
969 }
837 else970 else
838 {971 {
839 midori_bookmarks_popup_item (menu, GTK_STOCK_OPEN, NULL,972 midori_bookmarks_popup_item (menu, GTK_STOCK_OPEN, NULL,
840 item, midori_bookmarks_open_activate_cb, bookmarks);973 item, midori_bookmarks_open_activate_cb, bookmarks);
841 midori_bookmarks_popup_item (menu, STOCK_TAB_NEW, _("Open in New _Tab"),974 midori_bookmarks_popup_item (menu, STOCK_TAB_NEW, _("Open in New _Tab"),
842 item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);975 item, midori_bookmarks_open_in_tab_activate_cb, bookmarks);
843 midori_bookmarks_popup_item (menu, STOCK_WINDOW_NEW, _("Open in New _Window"),976 midori_bookmarks_popup_item (menu, STOCK_WINDOW_NEW, _("Open in New _Window"),
844 item, midori_bookmarks_open_in_window_activate_cb, bookmarks);977 item, midori_bookmarks_open_in_window_activate_cb, bookmarks);
@@ -960,6 +1093,105 @@
960 midori_bookmarks_toolbar_update (bookmarks);1093 midori_bookmarks_toolbar_update (bookmarks);
961}1094}
9621095
1096static KatzeItem*
1097midori_bookmarks_get_item_at_pos (GtkTreeView *treeview,
1098 gint x, gint y)
1099{
1100 GtkTreeModel* model = gtk_tree_view_get_model (treeview);
1101 GtkTreePath* path;
1102 GtkTreeIter iter;
1103 KatzeItem* item;
1104
1105 gtk_tree_view_get_path_at_pos (treeview, x, y,
1106 &path, NULL, NULL, NULL);
1107
1108 if (!path)
1109 return NULL;
1110
1111 if (!gtk_tree_model_get_iter (model, &iter, path))
1112 return NULL;
1113
1114 gtk_tree_model_get (model, &iter, 0, &item, -1);
1115
1116 gtk_tree_path_free (path);
1117
1118 return item;
1119}
1120
1121static gboolean
1122midori_bookmarks_enter_notify_event_cb (GtkTreeView *treeview,
1123 GdkEventCrossing *event,
1124 MidoriBookmarks *bookmarks)
1125{
1126 KatzeItem* item = midori_bookmarks_get_item_at_pos (treeview, event->x, event->y);
1127
1128 if (bookmarks->hovering_item)
1129 g_object_unref (bookmarks->hovering_item);
1130
1131 bookmarks->hovering_item = item;
1132
1133 midori_bookmarks_statusbar_update (bookmarks);
1134
1135 return FALSE;
1136}
1137
1138static gboolean
1139midori_bookmarks_motion_notify_event_cb (GtkTreeView *treeview,
1140 GdkEventMotion *event,
1141 MidoriBookmarks *bookmarks)
1142{
1143 gboolean item_changed;
1144 KatzeItem* item;
1145 gint x;
1146 gint y;
1147
1148 if (event->is_hint)
1149 gtk_widget_get_pointer (GTK_WIDGET (treeview), &x, &y);
1150 else
1151 {
1152 x = event->x;
1153 y = event->y;
1154 }
1155
1156 item = midori_bookmarks_get_item_at_pos (treeview, x, y);
1157
1158 item_changed = (bookmarks->hovering_item != item) ? TRUE : FALSE;
1159
1160 if (!item_changed)
1161 {
1162 if (item)
1163 g_object_unref (item);
1164 }
1165 else
1166 {
1167 if (bookmarks->hovering_item)
1168 g_object_unref (bookmarks->hovering_item);
1169
1170 bookmarks->hovering_item = item;
1171
1172 midori_bookmarks_statusbar_update (bookmarks);
1173 }
1174
1175 return FALSE;
1176}
1177
1178static gboolean
1179midori_bookmarks_leave_notify_event_cb (GtkTreeView *treeview,
1180 GdkEventCrossing *event,
1181 MidoriBookmarks *bookmarks)
1182{
1183 MidoriBrowser* browser = midori_browser_get_for_widget (bookmarks->treeview);
1184
1185 if (bookmarks->hovering_item)
1186 g_object_unref (bookmarks->hovering_item);
1187
1188 bookmarks->hovering_item = NULL;
1189
1190 g_object_set (browser, "statusbar-text", "", NULL);
1191
1192 return FALSE;
1193}
1194
963static gboolean1195static gboolean
964midori_bookmarks_filter_timeout_cb (gpointer data)1196midori_bookmarks_filter_timeout_cb (gpointer data)
965{1197{
@@ -1047,7 +1279,17 @@
1047 midori_bookmarks_row_expanded_cb, bookmarks,1279 midori_bookmarks_row_expanded_cb, bookmarks,
1048 "signal::row-collapsed",1280 "signal::row-collapsed",
1049 midori_bookmarks_row_collapsed_cb, bookmarks,1281 midori_bookmarks_row_collapsed_cb, bookmarks,
1282 "signal::enter-notify-event",
1283 midori_bookmarks_enter_notify_event_cb, bookmarks,
1284 "signal::motion-notify-event",
1285 midori_bookmarks_motion_notify_event_cb, bookmarks,
1286 "signal::leave-notify-event",
1287 midori_bookmarks_leave_notify_event_cb, bookmarks,
1050 NULL);1288 NULL);
1289 gtk_widget_add_events (GTK_WIDGET (treeview),
1290 GDK_POINTER_MOTION_MASK
1291 | GDK_POINTER_MOTION_HINT_MASK);
1292
1051 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));1293 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
1052 g_signal_connect_after (selection, "changed",1294 g_signal_connect_after (selection, "changed",
1053 G_CALLBACK (midori_bookmarks_selection_changed_cb),1295 G_CALLBACK (midori_bookmarks_selection_changed_cb),
@@ -1055,6 +1297,7 @@
1055 gtk_widget_show (treeview);1297 gtk_widget_show (treeview);
1056 gtk_box_pack_start (GTK_BOX (bookmarks), treeview, TRUE, TRUE, 0);1298 gtk_box_pack_start (GTK_BOX (bookmarks), treeview, TRUE, TRUE, 0);
1057 bookmarks->treeview = treeview;1299 bookmarks->treeview = treeview;
1300 bookmarks->hovering_item = NULL;
1058}1301}
10591302
1060static void1303static void
@@ -1064,5 +1307,6 @@
10641307
1065 if (bookmarks->app)1308 if (bookmarks->app)
1066 g_object_unref (bookmarks->app);1309 g_object_unref (bookmarks->app);
1310 if (bookmarks->hovering_item)
1311 g_object_unref (bookmarks->hovering_item);
1067}1312}
1068

Subscribers

People subscribed via source and target branches

to all changes: