Make the web view aware of news feeds
This introduces the logic needed to lookup news feeds and implements a signal news-feed-ready in MidoriWebView, similar to icon-ready. The interface in the browser still needs to be done.
This commit is contained in:
parent
94d7e7dc53
commit
15f4ab98d4
4 changed files with 131 additions and 12 deletions
|
@ -285,6 +285,10 @@ _midori_browser_update_interface (MidoriBrowser* browser)
|
||||||
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
|
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
|
||||||
icon = katze_throbber_get_static_pixbuf (KATZE_THROBBER (
|
icon = katze_throbber_get_static_pixbuf (KATZE_THROBBER (
|
||||||
g_object_get_data (G_OBJECT (widget), "browser-tab-icon")));
|
g_object_get_data (G_OBJECT (widget), "browser-tab-icon")));
|
||||||
|
/* FIXME show news feed icon if feeds are available */
|
||||||
|
/* gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (
|
||||||
|
gtk_bin_get_child (GTK_BIN (browser->location))),
|
||||||
|
GTK_ICON_ENTRY_SECONDARY, NULL); */
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
|
@ -442,6 +446,25 @@ midori_web_view_element_motion_cb (MidoriWebView* web_View,
|
||||||
_midori_browser_set_statusbar_text (browser, link_uri);
|
_midori_browser_set_statusbar_text (browser, link_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_web_view_load_committed_cb (GtkWidget* web_view,
|
||||||
|
WebKitWebFrame* web_frame,
|
||||||
|
MidoriBrowser* browser)
|
||||||
|
{
|
||||||
|
const gchar* uri;
|
||||||
|
|
||||||
|
if (web_view == midori_browser_get_current_web_view (browser))
|
||||||
|
{
|
||||||
|
uri = midori_web_view_get_display_uri (MIDORI_WEB_VIEW (web_view));
|
||||||
|
midori_location_entry_set_text (MIDORI_LOCATION_ENTRY (
|
||||||
|
browser->location), uri);
|
||||||
|
_midori_browser_set_statusbar_text (browser, NULL);
|
||||||
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (
|
||||||
|
gtk_bin_get_child (GTK_BIN (browser->location))),
|
||||||
|
GTK_ICON_ENTRY_SECONDARY, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_web_view_icon_ready_cb (MidoriWebView* web_view,
|
midori_web_view_icon_ready_cb (MidoriWebView* web_view,
|
||||||
GdkPixbuf* icon,
|
GdkPixbuf* icon,
|
||||||
|
@ -464,16 +487,15 @@ midori_web_view_icon_ready_cb (MidoriWebView* web_view,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_web_view_load_committed_cb (GtkWidget* web_view,
|
midori_web_view_news_feed_ready_cb (MidoriWebView* web_view,
|
||||||
WebKitWebFrame* web_frame,
|
const gchar* href,
|
||||||
|
const gchar* type,
|
||||||
|
const gchar* title,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
if (web_view == midori_browser_get_current_web_view (browser))
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (
|
||||||
{
|
gtk_bin_get_child (GTK_BIN (browser->location))),
|
||||||
const gchar* uri = midori_web_view_get_display_uri (MIDORI_WEB_VIEW (web_view));
|
GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_INDEX);
|
||||||
midori_location_entry_set_text (MIDORI_LOCATION_ENTRY (browser->location), uri);
|
|
||||||
_midori_browser_set_statusbar_text (browser, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -919,6 +941,8 @@ _midori_browser_add_tab (MidoriBrowser* browser,
|
||||||
midori_web_view_load_committed_cb, browser,
|
midori_web_view_load_committed_cb, browser,
|
||||||
"signal::icon-ready",
|
"signal::icon-ready",
|
||||||
midori_web_view_icon_ready_cb, browser,
|
midori_web_view_icon_ready_cb, browser,
|
||||||
|
"signal::news-feed-ready",
|
||||||
|
midori_web_view_news_feed_ready_cb, browser,
|
||||||
"signal::progress-started",
|
"signal::progress-started",
|
||||||
midori_web_view_progress_started_cb, browser,
|
midori_web_view_progress_started_cb, browser,
|
||||||
"signal::progress-changed",
|
"signal::progress-changed",
|
||||||
|
@ -3284,6 +3308,13 @@ midori_browser_init (MidoriBrowser* browser)
|
||||||
|
|
||||||
/* Location */
|
/* Location */
|
||||||
browser->location = midori_location_entry_new ();
|
browser->location = midori_location_entry_new ();
|
||||||
|
/* FIXME: Due to a bug in GtkIconEntry we need to set an initial icon */
|
||||||
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (
|
||||||
|
gtk_bin_get_child (GTK_BIN (browser->location))),
|
||||||
|
GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_INDEX);
|
||||||
|
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (
|
||||||
|
gtk_bin_get_child (GTK_BIN (browser->location))),
|
||||||
|
GTK_ICON_ENTRY_SECONDARY, TRUE);
|
||||||
/* FIXME: sokoke_entry_setup_completion (GTK_ENTRY (browser->location)); */
|
/* FIXME: sokoke_entry_setup_completion (GTK_ENTRY (browser->location)); */
|
||||||
g_object_connect (browser->location,
|
g_object_connect (browser->location,
|
||||||
"signal::active-changed",
|
"signal::active-changed",
|
||||||
|
|
|
@ -80,8 +80,6 @@ midori_location_entry_init (MidoriLocationEntry* location_entry)
|
||||||
|
|
||||||
entry = gtk_icon_entry_new ();
|
entry = gtk_icon_entry_new ();
|
||||||
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY, DEFAULT_ICON);
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_PRIMARY, DEFAULT_ICON);
|
||||||
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_SECONDARY, GTK_STOCK_CLEAR);
|
|
||||||
gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (entry), GTK_ICON_ENTRY_SECONDARY, TRUE);
|
|
||||||
g_signal_connect (entry, "icon_released", G_CALLBACK (entry_icon_released), NULL);
|
g_signal_connect (entry, "icon_released", G_CALLBACK (entry_icon_released), NULL);
|
||||||
g_signal_connect (entry, "key-press-event", G_CALLBACK (entry_key_press_event), location_entry);
|
g_signal_connect (entry, "key-press-event", G_CALLBACK (entry_key_press_event), location_entry);
|
||||||
|
|
||||||
|
@ -139,7 +137,7 @@ entry_icon_released (GtkIconEntry* entry,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
|
if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
|
||||||
gtk_entry_set_text (GTK_ENTRY (entry), "");
|
/* FIXME Show available news feeds */;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "midori-webview.h"
|
#include "midori-webview.h"
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "gjs.h"
|
||||||
#include "sokoke.h"
|
#include "sokoke.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
|
|
||||||
|
@ -59,6 +60,7 @@ enum
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ICON_READY,
|
ICON_READY,
|
||||||
|
NEWS_FEED_READY,
|
||||||
PROGRESS_STARTED,
|
PROGRESS_STARTED,
|
||||||
PROGRESS_CHANGED,
|
PROGRESS_CHANGED,
|
||||||
PROGRESS_DONE,
|
PROGRESS_DONE,
|
||||||
|
@ -87,6 +89,44 @@ midori_web_view_get_property (GObject* object,
|
||||||
GValue* value,
|
GValue* value,
|
||||||
GParamSpec* pspec);
|
GParamSpec* pspec);
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_cclosure_marshal_VOID__STRING_STRING_STRING (GClosure* closure,
|
||||||
|
GValue* return_value,
|
||||||
|
guint n_param_values,
|
||||||
|
const GValue* param_values,
|
||||||
|
gpointer invocation_hint,
|
||||||
|
gpointer marshal_data)
|
||||||
|
{
|
||||||
|
typedef void(*GMarshalFunc_VOID__STRING_STRING_STRING) (gpointer data1,
|
||||||
|
const gchar* arg_1,
|
||||||
|
const gchar* arg_2,
|
||||||
|
const gchar* arg_3,
|
||||||
|
gpointer data2);
|
||||||
|
register GMarshalFunc_VOID__STRING_STRING_STRING callback;
|
||||||
|
register GCClosure* cc = (GCClosure*) closure;
|
||||||
|
register gpointer data1, data2;
|
||||||
|
|
||||||
|
g_return_if_fail (n_param_values == 4);
|
||||||
|
|
||||||
|
if (G_CCLOSURE_SWAP_DATA (closure))
|
||||||
|
{
|
||||||
|
data1 = closure->data;
|
||||||
|
data2 = g_value_peek_pointer (param_values + 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data1 = g_value_peek_pointer (param_values + 0);
|
||||||
|
data2 = closure->data;
|
||||||
|
}
|
||||||
|
callback = (GMarshalFunc_VOID__STRING_STRING_STRING) (marshal_data
|
||||||
|
? marshal_data : cc->callback);
|
||||||
|
callback (data1,
|
||||||
|
g_value_get_string (param_values + 1),
|
||||||
|
g_value_get_string (param_values + 2),
|
||||||
|
g_value_get_string (param_values + 3),
|
||||||
|
data2);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_web_view_class_init (MidoriWebViewClass* class)
|
midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
{
|
{
|
||||||
|
@ -101,6 +141,19 @@ midori_web_view_class_init (MidoriWebViewClass* class)
|
||||||
G_TYPE_NONE, 1,
|
G_TYPE_NONE, 1,
|
||||||
GDK_TYPE_PIXBUF);
|
GDK_TYPE_PIXBUF);
|
||||||
|
|
||||||
|
signals[NEWS_FEED_READY] = g_signal_new (
|
||||||
|
"news-feed-ready",
|
||||||
|
G_TYPE_FROM_CLASS (class),
|
||||||
|
(GSignalFlags)(G_SIGNAL_RUN_LAST),
|
||||||
|
G_STRUCT_OFFSET (MidoriWebViewClass, news_feed_ready),
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
midori_cclosure_marshal_VOID__STRING_STRING_STRING,
|
||||||
|
G_TYPE_NONE, 3,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING,
|
||||||
|
G_TYPE_STRING);
|
||||||
|
|
||||||
signals[PROGRESS_STARTED] = g_signal_new (
|
signals[PROGRESS_STARTED] = g_signal_new (
|
||||||
"progress-started",
|
"progress-started",
|
||||||
G_TYPE_FROM_CLASS (class),
|
G_TYPE_FROM_CLASS (class),
|
||||||
|
@ -423,11 +476,43 @@ webkit_web_view_load_finished (MidoriWebView* web_view)
|
||||||
g_signal_emit (web_view, signals[PROGRESS_DONE], 0, web_view->progress);
|
g_signal_emit (web_view, signals[PROGRESS_DONE], 0, web_view->progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gjs_value_links_foreach_cb (GjsValue* link,
|
||||||
|
MidoriWebView* web_view)
|
||||||
|
{
|
||||||
|
const gchar* type;
|
||||||
|
|
||||||
|
if (gjs_value_is_object (link) && gjs_value_has_attribute (link, "type")
|
||||||
|
&& gjs_value_has_attribute (link, "href"))
|
||||||
|
{
|
||||||
|
type = gjs_value_get_attribute_string (link, "type");
|
||||||
|
if (!strcmp (type, "application/rss+xml")
|
||||||
|
|| !strcmp (type, "application/x.atom+xml")
|
||||||
|
|| !strcmp (type, "application/atom+xml"))
|
||||||
|
g_signal_emit (web_view, signals[NEWS_FEED_READY], 0,
|
||||||
|
gjs_value_get_attribute_string (link, "href"), type,
|
||||||
|
gjs_value_has_attribute (link, "title")
|
||||||
|
? gjs_value_get_attribute_string (link, "title") : NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
webkit_web_frame_load_done (WebKitWebFrame* web_frame,
|
webkit_web_frame_load_done (WebKitWebFrame* web_frame,
|
||||||
gboolean success,
|
gboolean success,
|
||||||
MidoriWebView* web_view)
|
MidoriWebView* web_view)
|
||||||
{
|
{
|
||||||
|
GjsValue* value;
|
||||||
|
GjsValue* document;
|
||||||
|
GjsValue* links;
|
||||||
|
|
||||||
|
value = gjs_value_new (webkit_web_frame_get_global_context (web_frame), NULL);
|
||||||
|
document = gjs_value_get_by_name (value, "document");
|
||||||
|
links = gjs_value_get_elements_by_tag_name (document, "link");
|
||||||
|
gjs_value_foreach (links, (GjsCallback)gjs_value_links_foreach_cb, web_view);
|
||||||
|
g_object_unref (links);
|
||||||
|
g_object_unref (document);
|
||||||
|
g_object_unref (value);
|
||||||
|
|
||||||
web_view->is_loading = FALSE;
|
web_view->is_loading = FALSE;
|
||||||
web_view->progress = -1;
|
web_view->progress = -1;
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,11 @@ struct _MidoriWebViewClass
|
||||||
(*icon_ready) (MidoriWebView* web_view,
|
(*icon_ready) (MidoriWebView* web_view,
|
||||||
GdkPixbuf* icon);
|
GdkPixbuf* icon);
|
||||||
void
|
void
|
||||||
|
(*news_feed_ready) (MidoriWebView* web_view,
|
||||||
|
const gchar* href,
|
||||||
|
const gchar* type,
|
||||||
|
const gchar* title);
|
||||||
|
void
|
||||||
(*progress_started) (MidoriWebView* web_view,
|
(*progress_started) (MidoriWebView* web_view,
|
||||||
guint progress);
|
guint progress);
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue