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
1=== modified file 'midori/midori-browser.c'
2--- midori/midori-browser.c 2013-06-22 16:01:42 +0000
3+++ midori/midori-browser.c 2013-06-25 22:40:32 +0000
4@@ -1204,7 +1204,7 @@
5 {
6 GList* tabs = midori_browser_get_tabs (browser);
7 for (; tabs != NULL; tabs = g_list_next (tabs))
8- if (midori_view_is_blank (tabs->data))
9+ if (!strcmp (midori_tab_get_uri (tabs->data), "about:dial"))
10 midori_view_reload (tabs->data, FALSE);
11 g_list_free (tabs);
12 }
13@@ -1212,16 +1212,10 @@
14 static void
15 midori_browser_add_speed_dial (MidoriBrowser* browser)
16 {
17- GdkPixbuf* img;
18 GtkWidget* view = midori_browser_get_current_tab (browser);
19-
20- if ((img = midori_view_get_snapshot (MIDORI_VIEW (view), 240, 160)))
21- {
22- midori_speed_dial_add (browser->dial,
23- midori_view_get_display_uri (MIDORI_VIEW (view)),
24- midori_view_get_display_title (MIDORI_VIEW (view)), img);
25- g_object_unref (img);
26- }
27+ midori_speed_dial_add (browser->dial,
28+ midori_view_get_display_uri (MIDORI_VIEW (view)),
29+ midori_view_get_display_title (MIDORI_VIEW (view)), NULL);
30 }
31
32 static gboolean
33
34=== modified file 'midori/midori-speeddial.vala'
35--- midori/midori-speeddial.vala 2013-06-20 21:27:24 +0000
36+++ midori/midori-speeddial.vala 2013-06-25 22:40:32 +0000
37@@ -50,6 +50,7 @@
38
39 public SpeedDial (string new_filename, string? fallback = null) {
40 filename = new_filename;
41+ thumb_queue = new GLib.List<Spec> ();
42 keyfile = new GLib.KeyFile ();
43 try {
44 keyfile.load_from_file (filename, GLib.KeyFileFlags.NONE);
45@@ -141,12 +142,18 @@
46 return "Dial %u".printf (slot_count + 1);
47 }
48
49- public void add (string uri, string title, Gdk.Pixbuf img) {
50+ public void add (string uri, string title, Gdk.Pixbuf? img) {
51 string id = get_next_free_slot ();
52- add_with_id (id, uri, title, img);
53+ uint slot = id.substring (5, -1).to_int ();
54+ try {
55+ save_message ("speed_dial-save-add %u %s".printf (slot, uri));
56+ }
57+ catch (Error error) {
58+ critical ("Failed to add speed dial thumbnail: %s", error.message);
59+ }
60 }
61
62- public void add_with_id (string id, string uri, string title, Gdk.Pixbuf img) {
63+ public void add_with_id (string id, string uri, string title, Gdk.Pixbuf? img) {
64 keyfile.set_string (id, "uri", uri);
65 keyfile.set_string (id, "title", title);
66
67@@ -335,50 +342,81 @@
68
69 void load_status (GLib.Object thumb_view_, ParamSpec pspec) {
70 #if !HAVE_WEBKIT2
71- if (thumb_view.load_status != WebKit.LoadStatus.FINISHED)
72+ if (thumb_view.load_status != WebKit.LoadStatus.FINISHED
73+ && thumb_view.load_status != WebKit.LoadStatus.FAILED)
74 return;
75-
76- return_if_fail (spec != null);
77- var img = (thumb_view.parent as Gtk.OffscreenWindow).get_pixbuf ();
78- var pixbuf_scaled = img.scale_simple (240, 160, Gdk.InterpType.TILES);
79- img = pixbuf_scaled;
80- unowned string title = thumb_view.get_title ();
81- add_with_id (spec.dial_id, spec.uri, title ?? spec.uri, img);
82+ thumb_view.notify["load-status"].disconnect (load_status);
83+ /* Schedule an idle to give the offscreen time to draw */
84+ Idle.add (save_thumbnail);
85+#endif
86+ }
87+
88+ bool save_thumbnail () {
89+#if !HAVE_WEBKIT2
90+ return_val_if_fail (spec != null, false);
91+
92+ var offscreen = (thumb_view.parent as Gtk.OffscreenWindow);
93+ var pixbuf = offscreen.get_pixbuf ();
94+ int image_width = pixbuf.get_width (), image_height = pixbuf.get_height ();
95+ int thumb_width = 240, thumb_height = 160;
96+ float image_ratio = image_width / image_height;
97+ float thumb_ratio = thumb_width / thumb_height;
98+ int x_offset, y_offset, computed_width, computed_height;
99+ if (image_ratio > thumb_ratio) {
100+ computed_width = (int)(image_height * thumb_ratio);
101+ computed_height = image_height;
102+ x_offset = (image_width - computed_width) / 2;
103+ y_offset = 0;
104+ }
105+ else {
106+ computed_width = image_width;
107+ computed_height = (int)(image_width / thumb_ratio);
108+ x_offset = 0;
109+ y_offset = 0;
110+ }
111+ var sub = pixbuf;
112+ if (y_offset + computed_height <= image_height)
113+ sub = new Gdk.Pixbuf.subpixbuf (pixbuf, x_offset, y_offset, computed_width, computed_height);
114+ var scaled = sub.scale_simple (thumb_width, thumb_height, Gdk.InterpType.TILES);
115+ add_with_id (spec.dial_id, spec.uri, thumb_view.get_title () ?? spec.uri, scaled);
116
117 thumb_queue.remove (spec);
118- if (thumb_queue != null && thumb_queue.data != null) {
119- spec = thumb_queue.data;
120+ if (thumb_queue.length () > 0) {
121+ spec = thumb_queue.nth_data (0);
122+ thumb_view.notify["load-status"].connect (load_status);
123 thumb_view.load_uri (spec.uri);
124 }
125- else
126- /* disconnect_by_func (thumb_view, load_status) */;
127 #endif
128+ return false;
129 }
130
131 void get_thumb (string dial_id, string uri) {
132 #if !HAVE_WEBKIT2
133 if (thumb_view == null) {
134 thumb_view = new WebKit.WebView ();
135- var settings = new WebKit.WebSettings ();
136- settings. set ("enable-javascript", false,
137- "enable-plugins", false,
138- "auto-load-images", true,
139- "enable-html5-database", false,
140- "enable-html5-local-storage", false);
141- if (settings.get_class ().find_property ("enable-java-applet") != null)
142- settings.set ("enable-java-applet", false);
143- thumb_view.settings = settings;
144+ thumb_view.settings.set (
145+ "enable-scripts", false,
146+ "enable-plugins", false,
147+ "auto-load-images", true,
148+ "enable-html5-database", false,
149+ "enable-html5-local-storage", false,
150+ "enable-java-applet", false);
151 var offscreen = new Gtk.OffscreenWindow ();
152 offscreen.add (thumb_view);
153 thumb_view.set_size_request (800, 600);
154 offscreen.show_all ();
155 }
156
157+ /* Don't load thumbnails already queued */
158+ foreach (var spec_ in thumb_queue)
159+ if (spec_.dial_id == dial_id)
160+ return;
161+
162 thumb_queue.append (new Spec (dial_id, uri));
163- if (thumb_queue.nth_data (1) != null)
164+ if (thumb_queue.length () > 1)
165 return;
166
167- spec = thumb_queue.data;
168+ spec = thumb_queue.nth_data (0);
169 thumb_view.notify["load-status"].connect (load_status);
170 thumb_view.load_uri (spec.uri);
171 #endif
172
173=== modified file 'midori/midori-view.c'
174--- midori/midori-view.c 2013-06-20 21:21:32 +0000
175+++ midori/midori-view.c 2013-06-25 22:40:32 +0000
176@@ -5452,6 +5452,7 @@
177 * Returns: a newly allocated #GdkPixbuf
178 *
179 * Since: 0.2.1
180+ * Deprecated: 0.5.3
181 **/
182 GdkPixbuf*
183 midori_view_get_snapshot (MidoriView* view,
184@@ -5460,76 +5461,7 @@
185 {
186 g_return_val_if_fail (MIDORI_IS_VIEW (view), NULL);
187
188- GdkPixbuf* pixbuf;
189- #ifdef HAVE_WEBKIT2_A
190- webkit_web_view_get_snapshot (WEBKIT_WEB_VIEW (view->web_view),
191- WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE,
192- NULL, midori_view_get_snapshot_cb, view);
193- #else
194- GtkAllocation allocation;
195- gint x, y;
196- GdkRectangle rect;
197- #if !GTK_CHECK_VERSION (3, 0, 0)
198- gint w, h;
199- GdkWindow* window;
200- GdkPixmap* pixmap;
201- GdkEvent event;
202- gboolean result;
203- GdkColormap* colormap;
204- #else
205- cairo_surface_t* surface;
206- cairo_t* cr;
207- #endif
208-
209- gtk_widget_get_allocation (view->web_view, &allocation);
210- x = allocation.x;
211- y = allocation.y;
212-
213- #if GTK_CHECK_VERSION (3, 0, 0)
214- surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
215- allocation.width, allocation.height);
216- cr = cairo_create (surface);
217- cairo_rectangle (cr, x, y, width, height);
218- cairo_clip (cr);
219- gtk_widget_draw (view->web_view, cr);
220- pixbuf = gdk_pixbuf_get_from_surface (surface, x, y, width, height);
221- cairo_surface_destroy (surface);
222- cairo_destroy (cr);
223- #else
224- w = allocation.width;
225- h = allocation.height;
226- rect.x = x;
227- rect.y = y;
228- rect.width = w;
229- rect.height = h;
230-
231- window = gtk_widget_get_window (view->web_view);
232- g_return_val_if_fail (window != NULL, NULL);
233-
234- pixmap = gdk_pixmap_new (window, w, h, gdk_drawable_get_depth (window));
235- event.expose.type = GDK_EXPOSE;
236- event.expose.window = pixmap;
237- event.expose.send_event = FALSE;
238- event.expose.count = 0;
239- event.expose.area.x = 0;
240- event.expose.area.y = 0;
241- gdk_drawable_get_size (GDK_DRAWABLE (window),
242- &event.expose.area.width, &event.expose.area.height);
243- event.expose.region = gdk_region_rectangle (&event.expose.area);
244-
245- g_signal_emit_by_name (view->web_view, "expose-event", &event, &result);
246-
247- colormap = gdk_drawable_get_colormap (pixmap);
248- pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap, 0, 0,
249- 0, 0, rect.width, rect.height);
250- g_object_unref (pixmap);
251- #endif
252- #endif
253-
254- GdkPixbuf* scaled = gdk_pixbuf_scale_simple (pixbuf, width, height,
255- GDK_INTERP_TILES);
256- g_object_unref (pixbuf);
257- return scaled;
258+ return view->icon ? g_object_ref (view->icon) : NULL;
259 }
260
261 /**

Subscribers

People subscribed via source and target branches

to all changes: