#include "midori-browser.h"
+#include "midori-app.h"
#include "midori-array.h"
#include "midori-view.h"
#include "midori-preferences.h"
webkit_web_view_move_cursor (web_view, GTK_MOVEMENT_VISUAL_POSITIONS, 1);
}
+static void
+_action_readable_activate (GtkAction* action,
+ MidoriBrowser* browser)
+{
+ GtkWidget* view = midori_browser_get_current_tab (browser);
+ gchar* filename;
+ gchar* stylesheet;
+ gint i;
+ gchar* script;
+ gchar* exception;
+
+ if (!view)
+ return;
+
+ filename = midori_app_find_res_filename ("readable.css");
+ stylesheet = NULL;
+ if (!g_file_get_contents (filename, &stylesheet, NULL, NULL))
+ {
+ g_free (filename);
+ g_free (stylesheet);
+ midori_view_add_info_bar (MIDORI_VIEW (view), GTK_MESSAGE_ERROR,
+ "Stylesheet readable.css not found", NULL, view,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
+ return;
+ }
+
+ i = 0;
+ while (stylesheet[i])
+ {
+ /* Replace line breaks with spaces */
+ if (stylesheet[i] == '\n' || stylesheet[i] == '\r')
+ stylesheet[i] = ' ';
+ /* Change all single quotes to double quotes */
+ else if (stylesheet[i] == '\'')
+ stylesheet[i] = '\"';
+ i++;
+ }
+
+ script = g_strdup_printf (
+ "(function () {"
+ "var style = document.createElement ('style');"
+ "style.setAttribute ('type', 'text/css');"
+ "style.appendChild (document.createTextNode ('%s'));"
+ "var head = document.getElementsByTagName ('head')[0];"
+ "if (head) head.appendChild (style);"
+ "else document.documentElement.insertBefore"
+ "(style, document.documentElement.firstChild);"
+ "}) ();", stylesheet);
+ g_free (stylesheet);
+ exception = NULL;
+ if (!midori_view_execute_script (MIDORI_VIEW (view), script, &exception))
+ {
+ midori_view_add_info_bar (MIDORI_VIEW (view), GTK_MESSAGE_ERROR,
+ exception, NULL, view,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
+ g_free (exception);
+ }
+ g_free (script);
+}
+
static gboolean
_action_navigation_activate (GtkAction* action,
MidoriBrowser* browser)
{ "ScrollRight", NULL,
N_("Scroll _Right"), "l",
NULL, G_CALLBACK (_action_scroll_somewhere_activate) },
+ { "Readable", NULL,
+ N_("_Readable"), "<Ctrl><Alt>R",
+ NULL, G_CALLBACK (_action_readable_activate) },
{ "Go", NULL, N_("_Go") },
{ "Back", GTK_STOCK_GO_BACK,
"</menu>"
"<menuitem action='SourceView'/>"
"<menuitem action='Fullscreen'/>"
+ "<menuitem action='Readable'/>"
"</menu>"
"<menu action='Go'>"
"<menuitem action='Back'/>"
{
void (*response_cb) (GtkWidget*, gint, gpointer);
response_cb = g_object_get_data (G_OBJECT (infobar), "midori-infobar-cb");
- response_cb (infobar, response, data_object);
+ if (response_cb != NULL)
+ response_cb (infobar, response, data_object);
gtk_widget_destroy (infobar);
}
#else
gint response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), "midori-infobar-response"));
void (*response_cb) (GtkWidget*, gint, gpointer);
response_cb = g_object_get_data (G_OBJECT (infobar), "midori-infobar-cb");
- response_cb (infobar, response, data_object);
+ if (response_cb != NULL)
+ response_cb (infobar, response, data_object);
gtk_widget_destroy (infobar);
}
#endif
const gchar* button_text;
g_return_val_if_fail (message != NULL, NULL);
- g_return_val_if_fail (response_cb != NULL, NULL);
va_start (args, first_button_text);