Move thumbnail generation into SpeedDial class
This commit is contained in:
parent
f2960a910d
commit
6210c59e31
5 changed files with 98 additions and 166 deletions
|
@ -1227,15 +1227,10 @@ midori_browser_add_speed_dial (MidoriBrowser* browser)
|
||||||
|
|
||||||
if ((img = midori_view_get_snapshot (MIDORI_VIEW (view), 240, 160)))
|
if ((img = midori_view_get_snapshot (MIDORI_VIEW (view), 240, 160)))
|
||||||
{
|
{
|
||||||
gchar* slot_id = midori_speed_dial_get_next_free_slot (browser->dial);
|
midori_speed_dial_add (browser->dial,
|
||||||
gchar* dial_id = g_strdup_printf ("Dial %s", slot_id + 1);
|
|
||||||
midori_speed_dial_add (browser->dial, dial_id,
|
|
||||||
midori_view_get_display_uri (MIDORI_VIEW (view)),
|
midori_view_get_display_uri (MIDORI_VIEW (view)),
|
||||||
midori_view_get_display_title (MIDORI_VIEW (view)), img);
|
midori_view_get_display_title (MIDORI_VIEW (view)), img);
|
||||||
g_free (dial_id);
|
|
||||||
midori_view_save_speed_dial_config (MIDORI_VIEW (view));
|
|
||||||
g_object_unref (img);
|
g_object_unref (img);
|
||||||
g_free (slot_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,18 @@ namespace Midori {
|
||||||
string filename;
|
string filename;
|
||||||
public GLib.KeyFile keyfile;
|
public GLib.KeyFile keyfile;
|
||||||
string? html = null;
|
string? html = null;
|
||||||
|
List<Spec> thumb_queue = null;
|
||||||
|
WebKit.WebView thumb_view = null;
|
||||||
|
Spec? spec = null;
|
||||||
|
|
||||||
|
public class Spec {
|
||||||
|
public string dial_id;
|
||||||
|
public string uri;
|
||||||
|
public Spec (string dial_id, string uri) {
|
||||||
|
this.dial_id = dial_id;
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public SpeedDial (string new_filename, string? fallback = null) {
|
public SpeedDial (string new_filename, string? fallback = null) {
|
||||||
filename = new_filename;
|
filename = new_filename;
|
||||||
|
@ -114,7 +126,12 @@ namespace Midori {
|
||||||
return "s%u".printf (slot_count + 1);
|
return "s%u".printf (slot_count + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add (string id, string uri, string title, Gdk.Pixbuf img) {
|
public void add (string uri, string title, Gdk.Pixbuf img) {
|
||||||
|
string id = "Dial " + get_next_free_slot ();
|
||||||
|
add_with_id (id, uri, title, img);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add_with_id (string id, string uri, string title, Gdk.Pixbuf img) {
|
||||||
keyfile.set_string (id, "uri", uri);
|
keyfile.set_string (id, "uri", uri);
|
||||||
keyfile.set_string (id, "title", title);
|
keyfile.set_string (id, "title", title);
|
||||||
|
|
||||||
|
@ -127,6 +144,7 @@ namespace Midori {
|
||||||
catch (Error error) {
|
catch (Error error) {
|
||||||
critical ("Failed to save speed dial thumbnail: %s", error.message);
|
critical ("Failed to save speed dial thumbnail: %s", error.message);
|
||||||
}
|
}
|
||||||
|
save ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public unowned string get_html (bool close_buttons_left, GLib.Object view) throws Error {
|
public unowned string get_html (bool close_buttons_left, GLib.Object view) throws Error {
|
||||||
|
@ -204,8 +222,7 @@ namespace Midori {
|
||||||
catch (FileError error) {
|
catch (FileError error) {
|
||||||
encoded = null;
|
encoded = null;
|
||||||
if (load_missing)
|
if (load_missing)
|
||||||
/* FIXME: midori_view_speed_dial_get_thumb (view, tile, uri); */
|
get_thumb (tile, uri);
|
||||||
critical ("FIXME midori_view_speed_dial_get_thumb");
|
|
||||||
}
|
}
|
||||||
markup.append_printf ("""
|
markup.append_printf ("""
|
||||||
<div class="shortcut" id="s%u"><div class="preview">
|
<div class="shortcut" id="s%u"><div class="preview">
|
||||||
|
@ -254,7 +271,7 @@ namespace Midori {
|
||||||
}
|
}
|
||||||
else if (action == "add") {
|
else if (action == "add") {
|
||||||
keyfile.set_string (dial_id, "uri", parts[2]);
|
keyfile.set_string (dial_id, "uri", parts[2]);
|
||||||
/* FIXME midori_view_speed_dial_get_thumb (view, dial_id, parts[2]); */
|
get_thumb (dial_id, parts[2]);
|
||||||
}
|
}
|
||||||
else if (action == "rename") {
|
else if (action == "rename") {
|
||||||
uint offset = parts[0].length + parts[1].length + 2;
|
uint offset = parts[0].length + parts[1].length + 2;
|
||||||
|
@ -276,14 +293,84 @@ namespace Midori {
|
||||||
keyfile.set_string (dial2_id, "title", title);
|
keyfile.set_string (dial2_id, "title", title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
save ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save () throws Error {
|
void save () {
|
||||||
html = null;
|
html = null;
|
||||||
|
|
||||||
|
try {
|
||||||
FileUtils.set_contents (filename, keyfile.to_data ());
|
FileUtils.set_contents (filename, keyfile.to_data ());
|
||||||
}
|
}
|
||||||
|
catch (Error error) {
|
||||||
|
critical ("Failed to update speed dial: %s", error.message);
|
||||||
|
}
|
||||||
|
/* FIXME Refresh all open views */
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_status (GLib.Object thumb_view_, ParamSpec pspec) {
|
||||||
|
if (thumb_view.load_status != WebKit.LoadStatus.FINISHED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
return_if_fail (spec != null);
|
||||||
|
#if HAVE_OFFSCREEN
|
||||||
|
var img = (thumb_view.parent as Gtk.OffscreenWindow).get_pixbuf ();
|
||||||
|
var pixbuf_scaled = img.scale_simple (240, 160, Gdk.InterpType.TILES);
|
||||||
|
img = pixbuf_scaled;
|
||||||
|
#else
|
||||||
|
thumb_view.realize ();
|
||||||
|
var img = midori_view_web_view_get_snapshot (thumb_view, 240, 160);
|
||||||
|
#endif
|
||||||
|
unowned string title = thumb_view.get_title ();
|
||||||
|
add_with_id (spec.dial_id, spec.uri, title ?? spec.uri, img);
|
||||||
|
|
||||||
|
thumb_queue.remove (spec);
|
||||||
|
if (thumb_queue != null && thumb_queue.data != null) {
|
||||||
|
spec = thumb_queue.data;
|
||||||
|
thumb_view.load_uri (spec.uri);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* disconnect_by_func (thumb_view, load_status) */;
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_thumb (string dial_id, string uri) {
|
||||||
|
if (thumb_view == null) {
|
||||||
|
thumb_view = new WebKit.WebView ();
|
||||||
|
var settings = new WebKit.WebSettings ();
|
||||||
|
settings. set ("enable-scripts", false,
|
||||||
|
"enable-plugins", false,
|
||||||
|
"auto-load-images", true,
|
||||||
|
"enable-html5-database", false,
|
||||||
|
"enable-html5-local-storage", false);
|
||||||
|
if (settings.get_class ().find_property ("enable-java-applet") != null)
|
||||||
|
settings.set ("enable-java-applet", false);
|
||||||
|
thumb_view.settings = settings;
|
||||||
|
#if HAVE_OFFSCREEN
|
||||||
|
var offscreen = new Gtk.OffscreenWindow ();
|
||||||
|
offscreen.add (thumb_view);
|
||||||
|
thumb_view.set_size_request (800, 600);
|
||||||
|
offscreen.show_all ();
|
||||||
|
#else
|
||||||
|
/* What we are doing here is a bit of a hack. In order to render a
|
||||||
|
thumbnail we need a new view and load the url in it. But it has
|
||||||
|
to be visible and packed in a container. So we secretly pack it
|
||||||
|
into the notebook of the parent browser. */
|
||||||
|
notebook.add (thumb_view);
|
||||||
|
thumb_view.destroy.connect (Gtk.widget_destroyed);
|
||||||
|
/* We use an empty label. It's not invisible but hard to spot. */
|
||||||
|
notebook.set_tab_label (thumb_view, new Gtk.EventBox ());
|
||||||
|
thumb_view.show ();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
thumb_queue.append (new Spec (dial_id, uri));
|
||||||
|
if (thumb_queue.nth_data (1) != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
spec = thumb_queue.data;
|
||||||
|
thumb_view.notify["load-status"].connect (load_status);
|
||||||
|
thumb_view.load_uri (spec.uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,11 +77,6 @@ midori_view_web_view_get_snapshot (GtkWidget* web_view,
|
||||||
gint width,
|
gint width,
|
||||||
gint height);
|
gint height);
|
||||||
|
|
||||||
static void
|
|
||||||
midori_view_speed_dial_get_thumb (MidoriView* view,
|
|
||||||
gchar* dial_id,
|
|
||||||
gchar* url);
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
midori_view_display_error (MidoriView* view,
|
midori_view_display_error (MidoriView* view,
|
||||||
const gchar* uri,
|
const gchar* uri,
|
||||||
|
@ -225,9 +220,6 @@ enum {
|
||||||
|
|
||||||
static guint signals[LAST_SIGNAL];
|
static guint signals[LAST_SIGNAL];
|
||||||
|
|
||||||
static GtkWidget* thumb_view = NULL;
|
|
||||||
static GList* thumb_queue = NULL;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_view_finalize (GObject* object);
|
midori_view_finalize (GObject* object);
|
||||||
|
|
||||||
|
@ -3310,9 +3302,7 @@ webkit_web_view_console_message_cb (GtkWidget* web_view,
|
||||||
{
|
{
|
||||||
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
||||||
MidoriSpeedDial* dial = katze_object_get_object (browser, "speed-dial");
|
MidoriSpeedDial* dial = katze_object_get_object (browser, "speed-dial");
|
||||||
|
|
||||||
midori_speed_dial_save_message (dial, message, NULL);
|
midori_speed_dial_save_message (dial, message, NULL);
|
||||||
midori_view_save_speed_dial_config (view);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_signal_emit (view, signals[CONSOLE_MESSAGE], 0, message, line, source_id);
|
g_signal_emit (view, signals[CONSOLE_MESSAGE], 0, message, line, source_id);
|
||||||
|
@ -6168,143 +6158,3 @@ midori_view_get_security (MidoriView* view)
|
||||||
return view->security;
|
return view->security;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
thumb_view_load_status_cb (WebKitWebView* thumb_view_,
|
|
||||||
GParamSpec* pspec,
|
|
||||||
MidoriView* view)
|
|
||||||
{
|
|
||||||
GdkPixbuf* img;
|
|
||||||
#if HAVE_OFFSCREEN
|
|
||||||
GdkPixbuf* pixbuf_scaled;
|
|
||||||
#endif
|
|
||||||
gchar* spec;
|
|
||||||
gchar* url;
|
|
||||||
gchar* dial_id;
|
|
||||||
MidoriBrowser* browser;
|
|
||||||
MidoriSpeedDial* dial;
|
|
||||||
const gchar* title;
|
|
||||||
|
|
||||||
if (webkit_web_view_get_load_status (thumb_view_) != WEBKIT_LOAD_FINISHED)
|
|
||||||
return;
|
|
||||||
|
|
||||||
browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
|
||||||
dial = katze_object_get_object (browser, "speed-dial");
|
|
||||||
|
|
||||||
spec = g_object_get_data (G_OBJECT (thumb_view), "spec");
|
|
||||||
url = strstr (spec, "|") + 1;
|
|
||||||
dial_id = g_strndup (spec, url - spec - 1);
|
|
||||||
|
|
||||||
#if HAVE_OFFSCREEN
|
|
||||||
img = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (
|
|
||||||
gtk_widget_get_parent (GTK_WIDGET (thumb_view))));
|
|
||||||
pixbuf_scaled = gdk_pixbuf_scale_simple (img, 240, 160, GDK_INTERP_TILES);
|
|
||||||
katze_object_assign (img, pixbuf_scaled);
|
|
||||||
#else
|
|
||||||
gtk_widget_realize (thumb_view);
|
|
||||||
img = midori_view_web_view_get_snapshot (thumb_view, 240, 160);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
title = webkit_web_view_get_title (WEBKIT_WEB_VIEW (thumb_view));
|
|
||||||
midori_speed_dial_add (dial, dial_id, url, title ? title : url, img);
|
|
||||||
g_object_unref (img);
|
|
||||||
midori_view_save_speed_dial_config (view);
|
|
||||||
|
|
||||||
thumb_queue = g_list_remove (thumb_queue, spec);
|
|
||||||
if (thumb_queue != NULL)
|
|
||||||
{
|
|
||||||
g_object_set_data_full (G_OBJECT (thumb_view), "spec",
|
|
||||||
thumb_queue->data, (GDestroyNotify)g_free);
|
|
||||||
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (thumb_view),
|
|
||||||
strstr (thumb_queue->data, "|") + 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
g_signal_handlers_disconnect_by_func (
|
|
||||||
thumb_view, thumb_view_load_status_cb, view);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* midori_view_speed_dial_get_thumb
|
|
||||||
* @view: a #MidoriView
|
|
||||||
* @dom_id: Id of the shortcut on speed_dial page in wich to inject content
|
|
||||||
* @url: url of the shortcut
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
midori_view_speed_dial_get_thumb (MidoriView* view,
|
|
||||||
gchar* dial_id,
|
|
||||||
gchar* url)
|
|
||||||
{
|
|
||||||
WebKitWebSettings* settings;
|
|
||||||
GtkWidget* browser;
|
|
||||||
#if !HAVE_OFFSCREEN
|
|
||||||
GtkWidget* notebook;
|
|
||||||
GtkWidget* label;
|
|
||||||
|
|
||||||
browser = gtk_widget_get_toplevel (GTK_WIDGET (view));
|
|
||||||
if (!GTK_IS_WINDOW (browser))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* What we are doing here is a bit of a hack. In order to render a
|
|
||||||
thumbnail we need a new view and load the url in it. But it has
|
|
||||||
to be visible and packed in a container. So we secretly pack it
|
|
||||||
into the notebook of the parent browser. */
|
|
||||||
notebook = katze_object_get_object (browser, "notebook");
|
|
||||||
if (!notebook)
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!thumb_view)
|
|
||||||
{
|
|
||||||
thumb_view = webkit_web_view_new ();
|
|
||||||
settings = g_object_new (WEBKIT_TYPE_WEB_SETTINGS,
|
|
||||||
"enable-scripts", FALSE,
|
|
||||||
"enable-plugins", FALSE, "auto-load-images", TRUE,
|
|
||||||
"enable-html5-database", FALSE, "enable-html5-local-storage", FALSE,
|
|
||||||
#if WEBKIT_CHECK_VERSION (1, 1, 22)
|
|
||||||
"enable-java-applet", FALSE,
|
|
||||||
#endif
|
|
||||||
NULL);
|
|
||||||
webkit_web_view_set_settings (WEBKIT_WEB_VIEW (thumb_view), settings);
|
|
||||||
#if HAVE_OFFSCREEN
|
|
||||||
browser = gtk_offscreen_window_new ();
|
|
||||||
gtk_container_add (GTK_CONTAINER (browser), thumb_view);
|
|
||||||
gtk_widget_set_size_request (thumb_view, 800, 600);
|
|
||||||
gtk_widget_show_all (browser);
|
|
||||||
#else
|
|
||||||
gtk_container_add (GTK_CONTAINER (notebook), thumb_view);
|
|
||||||
g_signal_connect (thumb_view, "destroy",
|
|
||||||
G_CALLBACK (gtk_widget_destroyed),
|
|
||||||
&thumb_view);
|
|
||||||
/* We use an empty label. It's not invisible but at least hard to spot. */
|
|
||||||
label = gtk_event_box_new ();
|
|
||||||
gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), thumb_view, label);
|
|
||||||
gtk_widget_show (thumb_view);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if !HAVE_OFFSCREEN
|
|
||||||
g_object_unref (notebook);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
thumb_queue = g_list_append (thumb_queue, g_strconcat (dial_id, "|", url, NULL));
|
|
||||||
if (g_list_nth_data (thumb_queue, 1) != NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_object_set_data_full (G_OBJECT (thumb_view), "spec",
|
|
||||||
thumb_queue->data, (GDestroyNotify)g_free);
|
|
||||||
g_signal_connect (thumb_view, "notify::load-status",
|
|
||||||
G_CALLBACK (thumb_view_load_status_cb), view);
|
|
||||||
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (thumb_view), url);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
midori_view_save_speed_dial_config (MidoriView* view)
|
|
||||||
{
|
|
||||||
guint i = 0;
|
|
||||||
MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (view));
|
|
||||||
MidoriSpeedDial* dial = katze_object_get_object (browser, "speed-dial");
|
|
||||||
GtkWidget* tab;
|
|
||||||
|
|
||||||
midori_speed_dial_save (dial, NULL);
|
|
||||||
while ((tab = midori_browser_get_nth_tab (browser, i++)))
|
|
||||||
if (midori_view_is_blank (MIDORI_VIEW (tab)))
|
|
||||||
midori_view_reload (MIDORI_VIEW (tab), FALSE);
|
|
||||||
}
|
|
||||||
|
|
|
@ -290,9 +290,6 @@ midori_view_add_info_bar (MidoriView* view,
|
||||||
const gchar* first_button_text,
|
const gchar* first_button_text,
|
||||||
...);
|
...);
|
||||||
|
|
||||||
void
|
|
||||||
midori_view_save_speed_dial_config (MidoriView* view);
|
|
||||||
|
|
||||||
const gchar*
|
const gchar*
|
||||||
midori_view_fallback_extension (MidoriView* view,
|
midori_view_fallback_extension (MidoriView* view,
|
||||||
const gchar* extension);
|
const gchar* extension);
|
||||||
|
|
3
wscript
3
wscript
|
@ -262,11 +262,14 @@ def configure (conf):
|
||||||
if check_version (conf.check_cfg (modversion='webkitgtk-3.0'), 1, 5, 1):
|
if check_version (conf.check_cfg (modversion='webkitgtk-3.0'), 1, 5, 1):
|
||||||
check_pkg ('javascriptcoregtk-3.0', '1.5.1', args=args)
|
check_pkg ('javascriptcoregtk-3.0', '1.5.1', args=args)
|
||||||
conf.env.append_value ('VALAFLAGS', '-D HAVE_GTK3')
|
conf.env.append_value ('VALAFLAGS', '-D HAVE_GTK3')
|
||||||
|
conf.env.append_value ('VALAFLAGS', '-D HAVE_OFFSCREEN')
|
||||||
else:
|
else:
|
||||||
check_pkg ('gtk+-2.0', '2.16.0', var='GTK')
|
check_pkg ('gtk+-2.0', '2.16.0', var='GTK')
|
||||||
check_pkg ('webkit-1.0', '1.1.17', args=args)
|
check_pkg ('webkit-1.0', '1.1.17', args=args)
|
||||||
if check_version (conf.check_cfg (modversion='webkit-1.0'), 1, 5, 1):
|
if check_version (conf.check_cfg (modversion='webkit-1.0'), 1, 5, 1):
|
||||||
check_pkg ('javascriptcoregtk-1.0', '1.5.1', args=args)
|
check_pkg ('javascriptcoregtk-1.0', '1.5.1', args=args)
|
||||||
|
if check_version ('gtk+-2.0', '2.20.0'):
|
||||||
|
conf.env.append_value ('VALAFLAGS', '-D HAVE_OFFSCREEN')
|
||||||
conf.env['HAVE_GTK3'] = option_enabled ('gtk3')
|
conf.env['HAVE_GTK3'] = option_enabled ('gtk3')
|
||||||
check_pkg ('libsoup-2.4', '2.27.90')
|
check_pkg ('libsoup-2.4', '2.27.90')
|
||||||
conf.define ('LIBSOUP_VERSION', conf.check_cfg (modversion='libsoup-2.4'))
|
conf.define ('LIBSOUP_VERSION', conf.check_cfg (modversion='libsoup-2.4'))
|
||||||
|
|
Loading…
Reference in a new issue