GKeyFile *config;
struct Client {
- gchar *external_handler_uri;
- gchar *feed_html;
- gchar *hover_uri;
+ GtkWidget *imgbutton;
+ GtkWidget *jsbutton;
GtkWidget *location;
GtkWidget *tabicon;
GtkWidget *tablabel;
GtkWidget *vbox;
GtkWidget *web_view;
+ WebKitSettings *settings;
gboolean focus_new_tab;
+ gchar *external_handler_uri;
+ gchar *feed_html;
+ gchar *hover_uri;
};
struct Configuration {
gboolean cooperative_alone;
gboolean cooperative_instances;
gboolean enable_console_to_stdout;
+ gboolean images_disabled;
gboolean javascript_disabled;
gboolean private;
gboolean spellcheck_disabled;
+ gchar *default_uri;
gchar *download_dir;
gchar *fifo_suffix;
gchar *history_file;
int cooperative_pipe_fp = 0;
gchar *search_text;
+void
+togglejs(GtkButton *jsbutton, gpointer data) {
+ struct Client *c = (struct Client *)data;
+ webkit_settings_set_enable_javascript(
+ c->settings, !webkit_settings_get_enable_javascript(c->settings));
+ webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view), c->settings);
+}
+
+void
+toggleimg(GtkButton *imgbutton, gpointer data) {
+ struct Client *c = (struct Client *)data;
+ webkit_settings_set_auto_load_images(
+ c->settings, !webkit_settings_get_auto_load_images(c->settings));
+ webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view), c->settings);
+}
+
void
client_destroy(GtkWidget *widget, gpointer data) {
struct Client *c = (struct Client *)data;
quit_if_nothing_active();
}
+void
+set_uri(const char *uri, struct Client *c) {
+ gtk_widget_grab_focus(c->location);
+ const char *goal = (strcmp(cfg.home_uri, uri) == 0) ? cfg.default_uri : uri;
+ gtk_entry_set_text(GTK_ENTRY(c->location), goal);
+ gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
+}
+
WebKitWebView *
client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
gboolean focus_tab) {
else
c->web_view = webkit_web_view_new_with_related_view(related_wv);
+ c->settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view));
+
webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view),
cfg.global_zoom);
- WebKitSettings *settings =
- webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view));
- webkit_settings_set_enable_javascript(settings, !cfg.javascript_disabled);
+ webkit_settings_set_enable_javascript(c->settings,
+ !cfg.javascript_disabled);
+ webkit_settings_set_auto_load_images(c->settings, !cfg.images_disabled);
g_signal_connect(G_OBJECT(c->web_view), "notify::favicon",
G_CALLBACK(changed_favicon), c);
g_signal_connect(G_OBJECT(c->web_view), "notify::title",
G_CALLBACK(crashed_web_view), c);
if (cfg.user_agent != NULL) {
- g_object_set(settings, "user-agent", cfg.user_agent, NULL);
+ g_object_set(c->settings, "user-agent", cfg.user_agent, NULL);
}
if (cfg.enable_console_to_stdout)
- webkit_settings_set_enable_write_console_messages_to_stdout(settings,
+ webkit_settings_set_enable_write_console_messages_to_stdout(c->settings,
TRUE);
- webkit_settings_set_enable_developer_extras(settings, TRUE);
+ webkit_settings_set_enable_developer_extras(c->settings, TRUE);
GtkWidget *locbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
+
+ c->jsbutton = gtk_toggle_button_new_with_label("JS");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->jsbutton),
+ !cfg.javascript_disabled);
+ g_signal_connect(G_OBJECT(c->jsbutton), "toggled", G_CALLBACK(togglejs), c);
+
+ c->imgbutton = gtk_toggle_button_new_with_label("IMG");
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->imgbutton),
+ !cfg.images_disabled);
+ g_signal_connect(G_OBJECT(c->imgbutton), "toggled", G_CALLBACK(toggleimg),
+ c);
+
c->location = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(locbox), c->location, TRUE, TRUE, 5);
+ gtk_box_pack_end(GTK_BOX(locbox), c->jsbutton, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(locbox), c->imgbutton, FALSE, FALSE, 0);
+
if (cfg.private) {
GtkWidget *privindicator = gtk_label_new("Private mode");
gtk_widget_set_tooltip_text(
privindicator, "You are in private mode. No history, caches, or "
"cookies will be saved beyond this session.");
- gtk_box_pack_end(GTK_BOX(locbox), privindicator, FALSE, FALSE, 0);
+ gtk_box_pack_end(GTK_BOX(locbox), privindicator, FALSE, FALSE, 5);
}
g_signal_connect(G_OBJECT(c->location), "key-press-event",
* 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);
+ GTK_ENTRY_ICON_SECONDARY, NULL);
c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start(GTK_BOX(c->vbox), locbox, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(evbox), "scroll-event", G_CALLBACK(key_tablabel),
c);
- /* For easy access, store a reference to our label. */
+ // For easy access, store a reference to our label.
g_object_set_data(G_OBJECT(evbox), "chorizo-tab-label", c->tablabel);
/* This only shows the event box and the label inside, nothing else.
g_free(f);
}
- clients++;
+ set_uri(uri, c);
+ clients++;
return WEBKIT_WEB_VIEW(c->web_view);
}
fprintf(stderr, __NAME__ ": Can't open FIFO at all.\n");
} else {
if (write(cooperative_pipe_fp, "", 0) == -1) {
- /* Could not do an empty write to the FIFO which means
- there's no one listening. */
+ /* Could not do an empty write to the FIFO which means there's no
+ * one listening. */
close(cooperative_pipe_fp);
towatch = g_io_channel_new_file(fifopath, "r+", NULL);
g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
webkit_policy_decision_use(decision);
break;
default:
- /* Use whatever default there is. */
+ // Use whatever default there is.
return FALSE;
}
return TRUE;
cfg.accepted_language[0] = NULL;
cfg.accepted_language[1] = NULL;
cfg.cooperative_alone = TRUE;
- cfg.cooperative_alone = TRUE;
+ cfg.cooperative_instances = TRUE;
cfg.fifo_suffix = "main";
const char *e = g_getenv(__NAME_UPPERCASE__ "_FIFO_SUFFIX");
g_key_file_get_string(config, "browser", "user_agent", NULL);
cfg.javascript_disabled =
g_key_file_get_boolean(config, "browser", "javascript_disabled", NULL);
+ cfg.images_disabled =
+ g_key_file_get_boolean(config, "browser", "images_disabled", NULL);
char *input_cookie_policy =
g_key_file_get_string(config, "browser", "cookie_policy", NULL);
cfg.cookie_policy = WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY;
}
}
+ cfg.default_uri = g_key_file_get_string(config, "ui", "default_uri", NULL);
+ cfg.default_uri = (cfg.default_uri) ? cfg.default_uri : "https://";
cfg.tab_width_chars =
g_key_file_get_integer(config, "ui", "tab_width", NULL);
cfg.tab_width_chars = (cfg.tab_width_chars) ? cfg.tab_width_chars : 20;
}
gtk_entry_set_icon_from_icon_name(GTK_ENTRY(c->location),
- GTK_ENTRY_ICON_PRIMARY,
+ GTK_ENTRY_ICON_SECONDARY,
"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);
+ GTK_ENTRY_ICON_SECONDARY, NULL);
}
webkit_javascript_result_unref(js_result);
if (!cfg.private) {
webkit_web_context_set_favicon_database_directory(wc, NULL);
- gchar *fname = g_build_filename("/", g_get_user_cache_dir(), __NAME__,
+ gchar *fname = g_build_filename("/", g_get_user_data_dir(), __NAME__,
"cookies.db", NULL);
WebKitCookiePersistentStorage type =
WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE;
if (event->type == GDK_KEY_PRESS) {
if (((GdkEventKey *)event)->state & GDK_CONTROL_MASK) {
- WebKitSettings *settings =
- webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view));
- gboolean js = webkit_settings_get_enable_javascript(settings);
+ const char *uri =
+ webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
int key = ((GdkEventKey *)event)->keyval;
if (def_key("download_manager", GDK_KEY_y) == key) {
downloadmanager_show();
webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
return TRUE;
} else if (def_key("location", GDK_KEY_t) == key) {
- gtk_widget_grab_focus(c->location);
- const char *uri =
- webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
- const char *goal = (uri) ? uri : "https://";
- gtk_entry_set_text(GTK_ENTRY(c->location), goal);
- gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
+ set_uri(uri, c);
return TRUE;
} else if (def_key("print", GDK_KEY_Print) == key) {
WebKitPrintOperation *operation =
} else if (def_key("quit", GDK_KEY_g) == key) {
search(c, 2);
gtk_widget_grab_focus(c->web_view);
- const gchar *uri =
- webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
gtk_entry_set_text(GTK_ENTRY(c->location), uri);
gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
webkit_web_view_run_javascript(
gtk_notebook_next_page(GTK_NOTEBOOK(mw.notebook));
return TRUE;
} else if (def_key("toggle_js", GDK_KEY_o) == key) {
- webkit_settings_set_enable_javascript(settings,
- (js) ? FALSE : TRUE);
+ gboolean on =
+ webkit_settings_get_enable_javascript(c->settings);
+ webkit_settings_set_enable_javascript(c->settings, !on);
webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view),
- settings);
- return TRUE;
+ c->settings);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->jsbutton),
+ !on);
+ } else if (def_key("toggle_img", -1) == key) {
+ gboolean on = webkit_settings_get_auto_load_images(c->settings);
+ webkit_settings_set_auto_load_images(c->settings, !on);
+ webkit_web_view_set_settings(WEBKIT_WEB_VIEW(c->web_view),
+ c->settings);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(c->imgbutton),
+ !on);
} else if (def_key("web_search", GDK_KEY_d) == key) {
gtk_widget_grab_focus(c->location);
gtk_entry_set_text(GTK_ENTRY(c->location), "w/");
search_text = g_strdup(t + 2);
search(c, 0);
} else if (t != NULL && t[0] == 'w' && t[1] == '/') {
- const char *engine = cfg.search_engine;
- int len = strlen(engine) + strlen(t) - 2;
- char *f = (char *)malloc(len);
- snprintf(f, len + 1, "%s%s", engine, t + 2);
+ int len = strlen(cfg.search_engine) + strlen(t) - 2;
+ gchar *f = malloc(len + 1);
+ snprintf(f, len + 1, "%s%s", cfg.search_engine, t + 2);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
- free(f);
+ g_free(f);
} else {
f = ensure_uri_scheme(t);
webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
g_signal_connect(G_OBJECT(mw.win), "destroy", gtk_main_quit, NULL);
gchar *priv = (cfg.private) ? "-private" : "";
- gchar *title = malloc(strlen(priv) + strlen(__NAME__));
+ gchar *title = malloc(strlen(priv) + strlen(__NAME__) + 1);
sprintf(title, "%s%s", __NAME__, priv);
gtk_window_set_title(GTK_WINDOW(mw.win), title);