#include <gdk/gdkkeysyms.h>
#include <gio/gio.h>
#include <webkit2/webkit2.h>
+#include <JavaScriptCore/JavaScript.h>
+static gboolean button_tablabel(GtkWidget *, GdkEvent *, gpointer);
static void client_destroy(GtkWidget *, gpointer);
-static gboolean client_destroy_request(WebKitWebView *, gpointer);
static WebKitWebView *client_new(const gchar *, WebKitWebView *, gboolean);
static WebKitWebView *client_new_request(WebKitWebView *, WebKitNavigationAction *,
gpointer);
static void changed_title(GObject *, GParamSpec *, gpointer);
static void changed_uri(GObject *, GParamSpec *, gpointer);
static gboolean crashed_web_view(WebKitWebView *, gpointer);
-static gboolean crashed_web_view_reload(gpointer);
static gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
WebKitPolicyDecisionType, gpointer);
static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
-static void downloadmanager_cancel(GtkToolButton *, gpointer data);
+static void downloadmanager_cancel(GtkToolButton *, gpointer);
+static gboolean downloadmanager_delete(GtkWidget *, gpointer);
static void downloadmanager_setup(void);
static gchar *ensure_uri_scheme(const gchar *);
-static void external_handler_run(GtkAction *, gpointer);
+static void external_handler_run(GSimpleAction *, GVariant *, gpointer);
static void grab_environment_configuration(void);
+static void grab_feeds_finished(GObject *, GAsyncResult *, gpointer);
static void hover_web_view(WebKitWebView *, WebKitHitTestResult *, guint, gpointer);
+static void icon_location(GtkEntry *, GtkEntryIconPosition, GdkEvent *, gpointer);
static gboolean key_common(GtkWidget *, GdkEvent *, gpointer);
static gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
static void keywords_load(void);
static gboolean keywords_try_search(WebKitWebView *, const gchar *);
+static void mainwindow_setup(void);
+static void mainwindow_title(gint);
+static void mainwindow_title_before(GtkNotebook *, GtkWidget *, guint, gpointer);
static gboolean menu_web_view(WebKitWebView *, WebKitContextMenu *, GdkEvent *,
WebKitHitTestResult *, gpointer);
+static gboolean quit_if_nothing_active(void);
static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
+static void run_user_scripts(WebKitWebView *);
static void search(gpointer, gint);
static void show_web_view(WebKitWebView *, gpointer);
-static Window tabbed_launch(void);
static void trust_user_certs(WebKitWebContext *);
{
gchar *external_handler_uri;
gchar *hover_uri;
+ gchar *feed_html;
GtkWidget *location;
+ GtkWidget *tablabel;
GtkWidget *vbox;
GtkWidget *web_view;
- GtkWidget *win;
};
+struct MainWindow
+{
+ GtkWidget *win;
+ GtkWidget *notebook;
+} mw;
+
struct DownloadManager
{
GtkWidget *scroll;
static const gchar *accepted_language[2] = { NULL, NULL };
-static gint clients = 0;
+static gint clients = 0, downloads = 0;
static gboolean cooperative_alone = TRUE;
static gboolean cooperative_instances = TRUE;
static int cooperative_pipe_fp = 0;
-static int crash_autoreload_delay = 2;
static gchar *download_dir = "/var/tmp";
-static Window embed = 0;
+static gboolean enable_console_to_stdout = FALSE;
static gchar *fifo_suffix = "main";
static gdouble global_zoom = 1.0;
+static gchar *history_file = NULL;
static gchar *home_uri = "about:blank";
static gboolean initial_wc_setup_done = FALSE;
static GHashTable *keywords = NULL;
static gchar *search_text = NULL;
-static gboolean tabbed_automagic = TRUE;
static gchar *user_agent = NULL;
+gboolean
+button_tablabel(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ if (event->type == GDK_BUTTON_RELEASE)
+ {
+ switch (((GdkEventButton *)event)->button)
+ {
+ case 2:
+ client_destroy(NULL, data);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
void
-client_destroy(GtkWidget *obj, gpointer data)
+client_destroy(GtkWidget *widget, gpointer data)
{
struct Client *c = (struct Client *)data;
+ gint idx;
g_signal_handlers_disconnect_by_func(G_OBJECT(c->web_view),
changed_load_progress, c);
+ idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox);
+ if (idx == -1)
+ fprintf(stderr, __NAME__": Tab index was -1, bamboozled\n");
+ else
+ gtk_notebook_remove_page(GTK_NOTEBOOK(mw.notebook), idx);
+
free(c);
clients--;
- if (clients == 0)
- gtk_main_quit();
-}
-
-gboolean
-client_destroy_request(WebKitWebView *web_view, gpointer data)
-{
- struct Client *c = (struct Client *)data;
-
- gtk_widget_destroy(c->win);
-
- return TRUE;
+ quit_if_nothing_active();
}
WebKitWebView *
struct Client *c;
WebKitWebContext *wc;
gchar *f;
+ GtkWidget *evbox;
if (uri != NULL && cooperative_instances && !cooperative_alone)
{
- write(cooperative_pipe_fp, uri, strlen(uri));
+ f = ensure_uri_scheme(uri);
+ write(cooperative_pipe_fp, f, strlen(f));
write(cooperative_pipe_fp, "\n", 1);
+ g_free(f);
return NULL;
}
exit(EXIT_FAILURE);
}
- if (embed != 0)
- {
- c->win = gtk_plug_new(embed);
- if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
- {
- fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
- gtk_widget_destroy(c->win);
- c->win = NULL;
- embed = 0;
- }
- }
-
- if (c->win == NULL)
- c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
-
- g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
- gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
-
if (related_wv == NULL)
c->web_view = webkit_web_view_new();
else
g_signal_connect(G_OBJECT(c->web_view), "context-menu",
G_CALLBACK(menu_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "close",
- G_CALLBACK(client_destroy_request), c);
+ G_CALLBACK(client_destroy), c);
g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
G_CALLBACK(decide_policy), NULL);
g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
G_CALLBACK(key_web_view), c);
- g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
+ g_signal_connect(G_OBJECT(c->web_view), "button-release-event",
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
G_CALLBACK(key_web_view), c);
g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
"user-agent", user_agent, NULL);
+ if (enable_console_to_stdout)
+ webkit_settings_set_enable_write_console_messages_to_stdout(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)), TRUE);
+
+ webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view)), TRUE);
+
c->location = gtk_entry_new();
g_signal_connect(G_OBJECT(c->location), "key-press-event",
G_CALLBACK(key_location), c);
+ g_signal_connect(G_OBJECT(c->location), "icon-release",
+ G_CALLBACK(icon_location), c);
+ /* XXX This is a workaround. Setting this to NULL (which is done in
+ * grab_feeds_finished() if no feed has been detected) adds a little
+ * padding left of the text. Not sure why. The point of this call
+ * right here is to have that padding right from the start. This
+ * avoids a graphical artifact. */
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
+ GTK_ENTRY_ICON_PRIMARY,
+ NULL);
c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(c->vbox), c->location, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(c->vbox), c->web_view, TRUE, TRUE, 0);
- gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
+ c->tablabel = gtk_label_new(__NAME__);
+ gtk_label_set_ellipsize(GTK_LABEL(c->tablabel), PANGO_ELLIPSIZE_END);
+ gtk_label_set_width_chars(GTK_LABEL(c->tablabel), 20);
+
+ evbox = gtk_event_box_new();
+ gtk_container_add(GTK_CONTAINER(evbox), c->tablabel);
+ g_signal_connect(G_OBJECT(evbox), "button-release-event",
+ G_CALLBACK(button_tablabel), c);
+
+ /* This only shows the event box and the label inside, nothing else.
+ * Needed because the evbox/label is "internal" to the notebook and
+ * not part of the normal "widget tree" (IIUC). */
+ gtk_widget_show_all(evbox);
+
+ gtk_notebook_append_page(GTK_NOTEBOOK(mw.notebook), c->vbox, evbox);
+ gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(mw.notebook), c->vbox, TRUE);
if (show)
show_web_view(NULL, c);
{
struct Client *c = (struct Client *)data;
gdouble p;
+ gchar *grab_feeds =
+ "a = document.querySelectorAll('"
+ " html > head > link[rel=\"alternate\"][href][type=\"application/atom+xml\"],"
+ " html > head > link[rel=\"alternate\"][href][type=\"application/rss+xml\"]"
+ "');"
+ "if (a.length == 0)"
+ " null;"
+ "else"
+ "{"
+ " out = '';"
+ " for (i = 0; i < a.length; i++)"
+ " {"
+ " url = encodeURIComponent(a[i].href);"
+ " if ('title' in a[i] && a[i].title != '')"
+ " title = encodeURIComponent(a[i].title);"
+ " else"
+ " title = url;"
+ " out += '<li><a href=\"' + url + '\">' + title + '</a></li>';"
+ " }"
+ " out;"
+ "}";
p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
+ if (p == 1)
+ {
+ p = 0;
+
+ /* The page has loaded fully. We now run the short JavaScript
+ * snippet above that operates on the DOM. It tries to grab all
+ * occurences of <link rel="alternate" ...>, i.e. RSS/Atom feed
+ * references. */
+ webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(c->web_view),
+ grab_feeds, NULL,
+ grab_feeds_finished, c);
+
+ run_user_scripts(WEBKIT_WEB_VIEW(c->web_view));
+ }
gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), p);
}
t = t == NULL ? u : t;
t = t[0] == 0 ? u : t;
- gtk_window_set_title(GTK_WINDOW(c->win), t);
+ gtk_label_set_text(GTK_LABEL(c->tablabel), t);
+ mainwindow_title(-1);
}
void
{
const gchar *t;
struct Client *c = (struct Client *)data;
+ FILE *fp;
t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
- gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
-}
-gboolean
-crashed_web_view(WebKitWebView *web_view, gpointer data)
-{
- fprintf(stderr, __NAME__": WebView crashed!\n");
- if (crash_autoreload_delay >= 1)
+ /* When a web process crashes, we get a "notify::uri" signal, but we
+ * can no longer read a meaningful URI. It's just an empty string
+ * now. Not updating the location bar in this scenario is important,
+ * because we would override the "WEB PROCESS CRASHED" message. */
+ if (t != NULL && strlen(t) > 0)
{
- fprintf(stderr, __NAME__": Reloading WebView in %d seconds.\n",
- crash_autoreload_delay);
- g_timeout_add_seconds(crash_autoreload_delay, crashed_web_view_reload,
- web_view);
- }
+ gtk_entry_set_text(GTK_ENTRY(c->location), t);
- return TRUE;
+ if (history_file != NULL)
+ {
+ fp = fopen(history_file, "a");
+ if (fp != NULL)
+ {
+ fprintf(fp, "%s\n", t);
+ fclose(fp);
+ }
+ else
+ perror(__NAME__": Error opening history file");
+ }
+ }
}
gboolean
-crashed_web_view_reload(gpointer data)
+crashed_web_view(WebKitWebView *web_view, gpointer data)
{
- webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(data));
+ gchar *t;
+ struct Client *c = (struct Client *)data;
+
+ t = g_strdup_printf("WEB PROCESS CRASHED: %s",
+ webkit_web_view_get_uri(WEBKIT_WEB_VIEW(web_view)));
+ gtk_entry_set_text(GTK_ENTRY(c->location), t);
+ g_free(t);
- return G_SOURCE_REMOVE;
+ return TRUE;
}
gboolean
return TRUE;
}
+void
+download_handle_finished(WebKitDownload *download, gpointer data)
+{
+ downloads--;
+}
+
void
download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
gpointer data)
g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
G_CALLBACK(changed_download_progress), tb);
+ downloads++;
+ g_signal_connect(G_OBJECT(download), "finished",
+ G_CALLBACK(download_handle_finished), NULL);
+
g_object_ref(download);
g_signal_connect(G_OBJECT(tb), "clicked",
G_CALLBACK(downloadmanager_cancel), download);
gtk_widget_destroy(GTK_WIDGET(tb));
}
+gboolean
+downloadmanager_delete(GtkWidget *obj, gpointer data)
+{
+ if (!quit_if_nothing_active())
+ gtk_widget_hide(dm.win);
+
+ return TRUE;
+}
+
void
downloadmanager_setup(void)
{
gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
g_signal_connect(G_OBJECT(dm.win), "delete-event",
- G_CALLBACK(gtk_widget_hide_on_delete), NULL);
+ G_CALLBACK(downloadmanager_delete), NULL);
g_signal_connect(G_OBJECT(dm.win), "key-press-event",
G_CALLBACK(key_downloadmanager), NULL);
if (!g_str_has_prefix(f, "http:") &&
!g_str_has_prefix(f, "https:") &&
!g_str_has_prefix(f, "file:") &&
- !g_str_has_prefix(f, "about:"))
+ !g_str_has_prefix(f, "about:") &&
+ !g_str_has_prefix(f, "data:"))
{
g_free(f);
fabs = realpath(t, NULL);
}
void
-external_handler_run(GtkAction *action, gpointer data)
+external_handler_run(GSimpleAction *simple, GVariant *param, gpointer data)
{
struct Client *c = (struct Client *)data;
gchar *argv[] = { "lariza-external-handler", "-u", NULL, NULL };
GPid pid;
GError *err = NULL;
- (void)action;
+ (void)simple;
+ (void)param;
argv[2] = c->external_handler_uri;
if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
if (e != NULL)
accepted_language[0] = g_strdup(e);
- e = g_getenv(__NAME_UPPERCASE__"_CRASH_AUTORELOAD_DELAY");
- if (e != NULL)
- crash_autoreload_delay = atoi(e);
-
e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
if (e != NULL)
download_dir = g_strdup(e);
+ e = g_getenv(__NAME_UPPERCASE__"_ENABLE_CONSOLE_TO_STDOUT");
+ if (e != NULL)
+ enable_console_to_stdout = TRUE;
+
e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
if (e != NULL)
fifo_suffix = g_strdup(e);
+ e = g_getenv(__NAME_UPPERCASE__"_HISTORY_FILE");
+ if (e != NULL)
+ history_file = g_strdup(e);
+
e = g_getenv(__NAME_UPPERCASE__"_HOME_URI");
if (e != NULL)
home_uri = g_strdup(e);
global_zoom = atof(e);
}
+void
+grab_feeds_finished(GObject *object, GAsyncResult *result, gpointer data)
+{
+ struct Client *c = (struct Client *)data;
+ WebKitJavascriptResult *js_result;
+ JSCValue *value;
+ JSCException *exception;
+ GError *err = NULL;
+ gchar *str_value;
+
+ g_free(c->feed_html);
+ c->feed_html = NULL;
+
+ /* This was taken almost verbatim from the example in WebKit's
+ * documentation:
+ *
+ * https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-run-javascript-finish */
+
+ js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object),
+ result, &err);
+ if (!js_result)
+ {
+ fprintf(stderr, __NAME__": Error running javascript: %s\n", err->message);
+ g_error_free(err);
+ return;
+ }
+
+ value = webkit_javascript_result_get_js_value(js_result);
+ if (jsc_value_is_string(value))
+ {
+ str_value = jsc_value_to_string(value);
+ exception = jsc_context_get_exception(jsc_value_get_context(value));
+ if (exception != NULL)
+ {
+ fprintf(stderr, __NAME__": Error running javascript: %s\n",
+ jsc_exception_get_message(exception));
+ }
+ else
+ c->feed_html = str_value;
+
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
+ GTK_ENTRY_ICON_PRIMARY,
+ "application-rss+xml-symbolic");
+ gtk_entry_set_icon_activatable(GTK_ENTRY(c->location),
+ GTK_ENTRY_ICON_PRIMARY,
+ TRUE);
+ }
+ else
+ {
+ gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
+ GTK_ENTRY_ICON_PRIMARY,
+ NULL);
+ }
+
+ webkit_javascript_result_unref(js_result);
+}
+
void
hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers,
gpointer data)
}
}
+void
+icon_location(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
+ gpointer data)
+{
+ struct Client *c = (struct Client *)data;
+ gchar *d;
+ gchar *data_template =
+ "data:text/html,"
+ "<!DOCTYPE html>"
+ "<html>"
+ " <head>"
+ " <meta charset=\"UTF-8\">"
+ " <title>Feeds</title>"
+ " </head>"
+ " <body>"
+ " <p>Feeds found on this page:</p>"
+ " <ul>"
+ " %s"
+ " </ul>"
+ " </body>"
+ "</html>";
+
+ if (c->feed_html != NULL)
+ {
+ /* What we're actually trying to do is show a simple HTML page
+ * that lists all the feeds on the current page. The function
+ * webkit_web_view_load_html() looks like the proper way to do
+ * that. Sad thing is, it doesn't create a history entry, but
+ * instead simply replaces the content of the current page. This
+ * is not what we want.
+ *
+ * RFC 2397 [0] defines the data URI scheme [1]. We abuse this
+ * mechanism to show my custom HTML snippet *and* create a
+ * history entry.
+ *
+ * [0]: https://tools.ietf.org/html/rfc2397
+ * [1]: https://en.wikipedia.org/wiki/Data_URI_scheme */
+ d = g_strdup_printf(data_template, c->feed_html);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), d);
+ g_free(d);
+ }
+}
+
gboolean
key_common(GtkWidget *widget, GdkEvent *event, gpointer data)
{
switch (((GdkEventKey *)event)->keyval)
{
case GDK_KEY_q: /* close window (left hand) */
- gtk_widget_destroy(c->win);
+ client_destroy(NULL, c);
return TRUE;
case GDK_KEY_w: /* home (left hand) */
f = ensure_uri_scheme(home_uri);
g_free(c->external_handler_uri);
c->external_handler_uri = g_strdup(
webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
- external_handler_run(NULL, c);
+ external_handler_run(NULL, NULL, c);
return TRUE;
}
}
switch (((GdkEventKey *)event)->keyval)
{
case GDK_KEY_d: /* close window (left hand) */
- gtk_widget_hide(dm.win);
+ case GDK_KEY_q:
+ downloadmanager_delete(dm.win, NULL);
return TRUE;
}
}
{
if (search_text != NULL)
g_free(search_text);
- search_text = g_strdup(t + 2); /* XXX whacky */
+ search_text = g_strdup(t + 2);
search(c, 0);
}
else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
gtk_entry_set_progress_fraction(GTK_ENTRY(c->location), 0);
}
}
- else if (event->type == GDK_BUTTON_PRESS)
+ else if (event->type == GDK_BUTTON_RELEASE)
{
switch (((GdkEventButton *)event)->button)
{
{
gboolean ret = FALSE;
gchar **tokens = NULL;
- gchar *val = NULL, *uri = NULL;
+ gchar *val = NULL, *escaped = NULL, *uri = NULL;
tokens = g_strsplit(t, " ", 2);
if (tokens[0] != NULL && tokens[1] != NULL)
val = g_hash_table_lookup(keywords, tokens[0]);
if (val != NULL)
{
- uri = g_strdup_printf((gchar *)val, tokens[1]);
+ escaped = g_uri_escape_string(tokens[1], NULL, TRUE);
+ uri = g_strdup_printf((gchar *)val, escaped);
webkit_web_view_load_uri(web_view, uri);
g_free(uri);
+ g_free(escaped);
ret = TRUE;
}
}
return ret;
}
+void
+mainwindow_setup(void)
+{
+ mw.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size(GTK_WINDOW(mw.win), 800, 600);
+ g_signal_connect(G_OBJECT(mw.win), "destroy", gtk_main_quit, NULL);
+ gtk_window_set_title(GTK_WINDOW(mw.win), __NAME__);
+
+ mw.notebook = gtk_notebook_new();
+ gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE);
+ gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook);
+ g_signal_connect(G_OBJECT(mw.notebook), "switch-page",
+ G_CALLBACK(mainwindow_title_before), NULL);
+
+ /* XXX Global hotkeys to change tabs are missing */
+}
+
+void
+mainwindow_title_before(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data)
+{
+ mainwindow_title(idx);
+}
+
+void
+mainwindow_title(gint idx)
+{
+ GtkWidget *child, *evbox, *label;
+ const gchar *text;
+
+ if (idx == -1)
+ {
+ idx = gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook));
+ if (idx == -1)
+ return;
+ }
+
+ child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(mw.notebook), idx);
+ if (child == NULL)
+ return;
+
+ evbox = gtk_notebook_get_tab_label(GTK_NOTEBOOK(mw.notebook), child);
+ label = gtk_bin_get_child(GTK_BIN(evbox));
+ text = gtk_label_get_text(GTK_LABEL(label));
+ gtk_window_set_title(GTK_WINDOW(mw.win), text);
+}
+
gboolean
menu_web_view(WebKitWebView *web_view, WebKitContextMenu *menu, GdkEvent *ev,
WebKitHitTestResult *ht, gpointer data)
{
struct Client *c = (struct Client *)data;
- GtkAction *action = NULL;
+ GSimpleAction *action = NULL;
WebKitContextMenuItem *mi = NULL;
const gchar *uri = NULL;
if (c->external_handler_uri != NULL)
g_free(c->external_handler_uri);
c->external_handler_uri = g_strdup(uri);
- action = gtk_action_new("external_handler", "Open with external handler",
- NULL, NULL);
+ action = g_simple_action_new("external_handler", NULL);
g_signal_connect(G_OBJECT(action), "activate",
G_CALLBACK(external_handler_run), data);
- mi = webkit_context_menu_item_new(action);
+ mi = webkit_context_menu_item_new_from_gaction(G_ACTION(action),
+ "Open with external handler",
+ NULL);
webkit_context_menu_append(menu, mi);
+ g_object_unref(action);
}
/* FALSE = Show the menu. (TRUE = Don't ever show it.) */
return FALSE;
}
+gboolean
+quit_if_nothing_active(void)
+{
+ if (clients == 0)
+ {
+ if (downloads == 0)
+ {
+ gtk_main_quit();
+ return TRUE;
+ }
+ else
+ gtk_widget_show_all(dm.win);
+ }
+
+ return FALSE;
+}
+
gboolean
remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
{
return TRUE;
}
+void
+run_user_scripts(WebKitWebView *web_view)
+{
+ gchar *base = NULL, *path = NULL, *contents = NULL;
+ const gchar *entry = NULL;
+ GDir *scriptdir = NULL;
+
+ base = g_build_filename(g_get_user_config_dir(), __NAME__, "user-scripts", NULL);
+ scriptdir = g_dir_open(base, 0, NULL);
+ if (scriptdir != NULL)
+ {
+ while ((entry = g_dir_read_name(scriptdir)) != NULL)
+ {
+ path = g_build_filename(base, entry, NULL);
+ if (g_str_has_suffix(path, ".js"))
+ {
+ if (g_file_get_contents(path, &contents, NULL, NULL))
+ {
+ webkit_web_view_run_javascript(web_view, contents, NULL, NULL, NULL);
+ g_free(contents);
+ }
+ }
+ g_free(path);
+ }
+ g_dir_close(scriptdir);
+ }
+
+ g_free(base);
+}
+
void
search(gpointer data, gint direction)
{
show_web_view(WebKitWebView *web_view, gpointer data)
{
struct Client *c = (struct Client *)data;
+ gint idx;
(void)web_view;
- gtk_widget_grab_focus(c->web_view);
- gtk_widget_show_all(c->win);
-}
+ gtk_widget_show_all(mw.win);
-Window
-tabbed_launch(void)
-{
- gint tabbed_stdout;
- GIOChannel *tabbed_stdout_channel;
- GError *err = NULL;
- gchar *output = NULL;
- char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
- Window plug_into;
+ idx = gtk_notebook_page_num(GTK_NOTEBOOK(mw.notebook), c->vbox);
+ if (idx != -1)
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(mw.notebook), idx);
- if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
- NULL, NULL, NULL, &tabbed_stdout, NULL,
- &err))
- {
- fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
- g_error_free(err);
- return 0;
- }
-
- tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
- if (tabbed_stdout_channel == NULL)
- {
- fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
- return 0;
- }
- g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
- g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
- if (output == NULL)
- {
- fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
- return 0;
- }
- g_strstrip(output);
- plug_into = strtol(output, NULL, 16);
- g_free(output);
- if (plug_into == 0)
- fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
- return plug_into;
+ gtk_widget_grab_focus(c->web_view);
}
void
grab_environment_configuration();
- while ((opt = getopt(argc, argv, "e:CT")) != -1)
+ while ((opt = getopt(argc, argv, "C")) != -1)
{
switch (opt)
{
- case 'e':
- embed = atol(optarg);
- tabbed_automagic = FALSE;
- break;
case 'C':
cooperative_instances = FALSE;
break;
- case 'T':
- tabbed_automagic = FALSE;
- break;
default:
fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
exit(EXIT_FAILURE);
cooperation_setup();
downloadmanager_setup();
- if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
- embed = tabbed_launch();
+ mainwindow_setup();
if (!cooperative_instances || cooperative_alone)
{