Merge lp:~kalikiana/midori/nailpolish into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6229
Merged at revision: 6235
Proposed branch: lp:~kalikiana/midori/nailpolish
Merge into: lp:midori
Diff against target: 261 lines (+70/-106)
3 files modified
midori/midori-browser.c (+4/-10)
midori/midori-speeddial.vala (+64/-26)
midori/midori-view.c (+2/-70)
To merge this branch: bzr merge lp:~kalikiana/midori/nailpolish
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+171428@code.launchpad.net

Commit message

Improve and unify thumbnail generation

Description of the change

Improve and unify thumbnail generation

To post a comment you must log in.
Revision history for this message
Paweł Forysiuk (tuxator) wrote :

Looks and works fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'midori/midori-browser.c'
--- midori/midori-browser.c 2013-06-22 16:01:42 +0000
+++ midori/midori-browser.c 2013-06-25 22:40:32 +0000
@@ -1204,7 +1204,7 @@
1204{1204{
1205 GList* tabs = midori_browser_get_tabs (browser);1205 GList* tabs = midori_browser_get_tabs (browser);
1206 for (; tabs != NULL; tabs = g_list_next (tabs))1206 for (; tabs != NULL; tabs = g_list_next (tabs))
1207 if (midori_view_is_blank (tabs->data))1207 if (!strcmp (midori_tab_get_uri (tabs->data), "about:dial"))
1208 midori_view_reload (tabs->data, FALSE);1208 midori_view_reload (tabs->data, FALSE);
1209 g_list_free (tabs);1209 g_list_free (tabs);
1210}1210}
@@ -1212,16 +1212,10 @@
1212static void1212static void
1213midori_browser_add_speed_dial (MidoriBrowser* browser)1213midori_browser_add_speed_dial (MidoriBrowser* browser)
1214{1214{
1215 GdkPixbuf* img;
1216 GtkWidget* view = midori_browser_get_current_tab (browser);1215 GtkWidget* view = midori_browser_get_current_tab (browser);
12171216 midori_speed_dial_add (browser->dial,
1218 if ((img = midori_view_get_snapshot (MIDORI_VIEW (view), 240, 160)))1217 midori_view_get_display_uri (MIDORI_VIEW (view)),
1219 {1218 midori_view_get_display_title (MIDORI_VIEW (view)), NULL);
1220 midori_speed_dial_add (browser->dial,
1221 midori_view_get_display_uri (MIDORI_VIEW (view)),
1222 midori_view_get_display_title (MIDORI_VIEW (view)), img);
1223 g_object_unref (img);
1224 }
1225}1219}
12261220
1227static gboolean1221static gboolean
12281222
=== modified file 'midori/midori-speeddial.vala'
--- midori/midori-speeddial.vala 2013-06-20 21:27:24 +0000
+++ midori/midori-speeddial.vala 2013-06-25 22:40:32 +0000
@@ -50,6 +50,7 @@
5050
51 public SpeedDial (string new_filename, string? fallback = null) {51 public SpeedDial (string new_filename, string? fallback = null) {
52 filename = new_filename;52 filename = new_filename;
53 thumb_queue = new GLib.List<Spec> ();
53 keyfile = new GLib.KeyFile ();54 keyfile = new GLib.KeyFile ();
54 try {55 try {
55 keyfile.load_from_file (filename, GLib.KeyFileFlags.NONE);56 keyfile.load_from_file (filename, GLib.KeyFileFlags.NONE);
@@ -141,12 +142,18 @@
141 return "Dial %u".printf (slot_count + 1);142 return "Dial %u".printf (slot_count + 1);
142 }143 }
143144
144 public void add (string uri, string title, Gdk.Pixbuf img) {145 public void add (string uri, string title, Gdk.Pixbuf? img) {
145 string id = get_next_free_slot ();146 string id = get_next_free_slot ();
146 add_with_id (id, uri, title, img);147 uint slot = id.substring (5, -1).to_int ();
148 try {
149 save_message ("speed_dial-save-add %u %s".printf (slot, uri));
150 }
151 catch (Error error) {
152 critical ("Failed to add speed dial thumbnail: %s", error.message);
153 }
147 }154 }
148155
149 public void add_with_id (string id, string uri, string title, Gdk.Pixbuf img) {156 public void add_with_id (string id, string uri, string title, Gdk.Pixbuf? img) {
150 keyfile.set_string (id, "uri", uri);157 keyfile.set_string (id, "uri", uri);
151 keyfile.set_string (id, "title", title);158 keyfile.set_string (id, "title", title);
152159
@@ -335,50 +342,81 @@
335342
336 void load_status (GLib.Object thumb_view_, ParamSpec pspec) {343 void load_status (GLib.Object thumb_view_, ParamSpec pspec) {
337#if !HAVE_WEBKIT2344#if !HAVE_WEBKIT2
338 if (thumb_view.load_status != WebKit.LoadStatus.FINISHED)345 if (thumb_view.load_status != WebKit.LoadStatus.FINISHED
346 && thumb_view.load_status != WebKit.LoadStatus.FAILED)
339 return;347 return;
340348 thumb_view.notify["load-status"].disconnect (load_status);
341 return_if_fail (spec != null);349 /* Schedule an idle to give the offscreen time to draw */
342 var img = (thumb_view.parent as Gtk.OffscreenWindow).get_pixbuf ();350 Idle.add (save_thumbnail);
343 var pixbuf_scaled = img.scale_simple (240, 160, Gdk.InterpType.TILES);351#endif
344 img = pixbuf_scaled;352 }
345 unowned string title = thumb_view.get_title ();353
346 add_with_id (spec.dial_id, spec.uri, title ?? spec.uri, img);354 bool save_thumbnail () {
355#if !HAVE_WEBKIT2
356 return_val_if_fail (spec != null, false);
357
358 var offscreen = (thumb_view.parent as Gtk.OffscreenWindow);
359 var pixbuf = offscreen.get_pixbuf ();
360 int image_width = pixbuf.get_width (), image_height = pixbuf.get_height ();
361 int thumb_width = 240, thumb_height = 160;
362 float image_ratio = image_width / image_height;
363 float thumb_ratio = thumb_width / thumb_height;
364 int x_offset, y_offset, computed_width, computed_height;
365 if (image_ratio > thumb_ratio) {
366 computed_width = (int)(image_height * thumb_ratio);
367 computed_height = image_height;
368 x_offset = (image_width - computed_width) / 2;
369 y_offset = 0;
370 }
371 else {
372 computed_width = image_width;
373 computed_height = (int)(image_width / thumb_ratio);
374 x_offset = 0;
375 y_offset = 0;
376 }
377 var sub = pixbuf;
378 if (y_offset + computed_height <= image_height)
379 sub = new Gdk.Pixbuf.subpixbuf (pixbuf, x_offset, y_offset, computed_width, computed_height);
380 var scaled = sub.scale_simple (thumb_width, thumb_height, Gdk.InterpType.TILES);
381 add_with_id (spec.dial_id, spec.uri, thumb_view.get_title () ?? spec.uri, scaled);
347382
348 thumb_queue.remove (spec);383 thumb_queue.remove (spec);
349 if (thumb_queue != null && thumb_queue.data != null) {384 if (thumb_queue.length () > 0) {
350 spec = thumb_queue.data;385 spec = thumb_queue.nth_data (0);
386 thumb_view.notify["load-status"].connect (load_status);
351 thumb_view.load_uri (spec.uri);387 thumb_view.load_uri (spec.uri);
352 }388 }
353 else
354 /* disconnect_by_func (thumb_view, load_status) */;
355#endif389#endif
390 return false;
356 }391 }
357392
358 void get_thumb (string dial_id, string uri) {393 void get_thumb (string dial_id, string uri) {
359#if !HAVE_WEBKIT2394#if !HAVE_WEBKIT2
360 if (thumb_view == null) {395 if (thumb_view == null) {
361 thumb_view = new WebKit.WebView ();396 thumb_view = new WebKit.WebView ();
362 var settings = new WebKit.WebSettings ();397 thumb_view.settings.set (
363 settings. set ("enable-javascript", false,398 "enable-scripts", false,
364 "enable-plugins", false,399 "enable-plugins", false,
365 "auto-load-images", true,400 "auto-load-images", true,
366 "enable-html5-database", false,401 "enable-html5-database", false,
367 "enable-html5-local-storage", false);402 "enable-html5-local-storage", false,
368 if (settings.get_class ().find_property ("enable-java-applet") != null)403 "enable-java-applet", false);
369 settings.set ("enable-java-applet", false);
370 thumb_view.settings = settings;
371 var offscreen = new Gtk.OffscreenWindow ();404 var offscreen = new Gtk.OffscreenWindow ();
372 offscreen.add (thumb_view);405 offscreen.add (thumb_view);
373 thumb_view.set_size_request (800, 600);406 thumb_view.set_size_request (800, 600);
374 offscreen.show_all ();407 offscreen.show_all ();
375 }408 }
376409
410 /* Don't load thumbnails already queued */
411 foreach (var spec_ in thumb_queue)
412 if (spec_.dial_id == dial_id)
413 return;
414
377 thumb_queue.append (new Spec (dial_id, uri));415 thumb_queue.append (new Spec (dial_id, uri));
378 if (thumb_queue.nth_data (1) != null)416 if (thumb_queue.length () > 1)
379 return;417 return;
380418
381 spec = thumb_queue.data;419 spec = thumb_queue.nth_data (0);
382 thumb_view.notify["load-status"].connect (load_status);420 thumb_view.notify["load-status"].connect (load_status);
383 thumb_view.load_uri (spec.uri);421 thumb_view.load_uri (spec.uri);
384#endif422#endif
385423
=== modified file 'midori/midori-view.c'
--- midori/midori-view.c 2013-06-20 21:21:32 +0000
+++ midori/midori-view.c 2013-06-25 22:40:32 +0000
@@ -5452,6 +5452,7 @@
5452 * Returns: a newly allocated #GdkPixbuf5452 * Returns: a newly allocated #GdkPixbuf
5453 *5453 *
5454 * Since: 0.2.15454 * Since: 0.2.1
5455 * Deprecated: 0.5.3
5455 **/5456 **/
5456GdkPixbuf*5457GdkPixbuf*
5457midori_view_get_snapshot (MidoriView* view,5458midori_view_get_snapshot (MidoriView* view,
@@ -5460,76 +5461,7 @@
5460{5461{
5461 g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);5462 g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
54625463
5463 GdkPixbuf* pixbuf;5464 return view->icon ? g_object_ref (view->icon) : NULL;
5464 #ifdef HAVE_WEBKIT2_A
5465 webkit_web_view_get_snapshot (WEBKIT_WEB_VIEW (view->web_view),
5466 WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE,
5467 NULL, midori_view_get_snapshot_cb, view);
5468 #else
5469 GtkAllocation allocation;
5470 gint x, y;
5471 GdkRectangle rect;
5472 #if !GTK_CHECK_VERSION (3, 0, 0)
5473 gint w, h;
5474 GdkWindow* window;
5475 GdkPixmap* pixmap;
5476 GdkEvent event;
5477 gboolean result;
5478 GdkColormap* colormap;
5479 #else
5480 cairo_surface_t* surface;
5481 cairo_t* cr;
5482 #endif
5483
5484 gtk_widget_get_allocation (view->web_view, &allocation);
5485 x = allocation.x;
5486 y = allocation.y;
5487
5488 #if GTK_CHECK_VERSION (3, 0, 0)
5489 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
5490 allocation.width, allocation.height);
5491 cr = cairo_create (surface);
5492 cairo_rectangle (cr, x, y, width, height);
5493 cairo_clip (cr);
5494 gtk_widget_draw (view->web_view, cr);
5495 pixbuf = gdk_pixbuf_get_from_surface (surface, x, y, width, height);
5496 cairo_surface_destroy (surface);
5497 cairo_destroy (cr);
5498 #else
5499 w = allocation.width;
5500 h = allocation.height;
5501 rect.x = x;
5502 rect.y = y;
5503 rect.width = w;
5504 rect.height = h;
5505
5506 window = gtk_widget_get_window (view->web_view);
5507 g_return_val_if_fail (window != NULL, NULL);
5508
5509 pixmap = gdk_pixmap_new (window, w, h, gdk_drawable_get_depth (window));
5510 event.expose.type = GDK_EXPOSE;
5511 event.expose.window = pixmap;
5512 event.expose.send_event = FALSE;
5513 event.expose.count = 0;
5514 event.expose.area.x = 0;
5515 event.expose.area.y = 0;
5516 gdk_drawable_get_size (GDK_DRAWABLE (window),
5517 &event.expose.area.width, &event.expose.area.height);
5518 event.expose.region = gdk_region_rectangle (&event.expose.area);
5519
5520 g_signal_emit_by_name (view->web_view, "expose-event", &event, &result);
5521
5522 colormap = gdk_drawable_get_colormap (pixmap);
5523 pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap, 0, 0,
5524 0, 0, rect.width, rect.height);
5525 g_object_unref (pixmap);
5526 #endif
5527 #endif
5528
5529 GdkPixbuf* scaled = gdk_pixbuf_scale_simple (pixbuf, width, height,
5530 GDK_INTERP_TILES);
5531 g_object_unref (pixbuf);
5532 return scaled;
5533}5465}
55345466
5535/**5467/**

Subscribers

People subscribed via source and target branches

to all changes: