diff options
Diffstat (limited to 'browser.c')
-rw-r--r-- | browser.c | 80 |
1 files changed, 59 insertions, 21 deletions
@@ -1,3 +1,4 @@ +#define _XOPEN_SOURCE 700 #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -90,6 +91,7 @@ gboolean cooperative_alone = TRUE; gboolean cooperative_instances = TRUE; int cooperative_pipe_fp = 0; gchar *download_dir = "/var/tmp"; +gchar *search_engine = SEARCH_ENGINE; gboolean enable_console_to_stdout = FALSE; gchar *fifo_suffix = "main"; gdouble global_zoom = 1.0; @@ -129,6 +131,7 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, struct Client *c; gchar *f; GtkWidget *evbox, *tabbox; + WebKitWebContext *wc; if (uri != NULL && cooperative_instances && !cooperative_alone) { @@ -153,6 +156,17 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show, else c->web_view = webkit_web_view_new_with_related_view(related_wv); + /* XXX We have just created a new WebView with either the default + * WebContext (if related_wv == NULL) or a WebView with an inherited + * context. Still, it doesn't use the preferred languages we might + * have set on the default WebContext. This used to work. New bug in + * WebKit or changed API? */ + if (accepted_language[0] != NULL) + { + wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view)); + webkit_web_context_set_preferred_languages(wc, accepted_language); + } + webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom); g_signal_connect(G_OBJECT(c->web_view), "notify::favicon", G_CALLBACK(changed_favicon), c); @@ -524,34 +538,43 @@ download_handle_start(WebKitWebView *web_view, WebKitDownload *download, gboolean download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data) { - gchar *sug_clean, *path, *path2 = NULL, *uri; + gchar *sug_clean, *path = NULL, *uri; GtkToolItem *tb; - int suffix = 1; size_t i; + GtkWidget *dialog; + GtkFileChooser *chooser; + gint res; + + dialog = gtk_file_chooser_dialog_new("Save File", + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + "Cancel", + GTK_RESPONSE_CANCEL, + "Save", + GTK_RESPONSE_ACCEPT, + NULL); sug_clean = g_strdup(suggested_filename); for (i = 0; i < strlen(sug_clean); i++) if (sug_clean[i] == G_DIR_SEPARATOR) sug_clean[i] = '_'; - path = g_build_filename(download_dir, sug_clean, NULL); - path2 = g_strdup(path); - while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000) + chooser = GTK_FILE_CHOOSER(dialog); + gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE); + gtk_file_chooser_set_current_name(chooser, sug_clean); + gtk_file_chooser_set_current_folder(chooser, download_dir); + gtk_widget_show_all(dialog); + res = gtk_dialog_run(GTK_DIALOG(dialog)); + if (res != GTK_RESPONSE_ACCEPT) { - g_free(path2); - - path2 = g_strdup_printf("%s.%d", path, suffix); - suffix++; - } - - if (suffix == 1000) - { - fprintf(stderr, __NAME__": Suffix reached limit for download.\n"); webkit_download_cancel(download); + gtk_widget_destroy(dialog); } else { - uri = g_filename_to_uri(path2, NULL, NULL); + path = gtk_file_chooser_get_filename(chooser); + gtk_widget_destroy(dialog); + uri = g_filename_to_uri(path, NULL, NULL); webkit_download_set_destination(download, uri); g_free(uri); @@ -575,7 +598,6 @@ download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer da g_free(sug_clean); g_free(path); - g_free(path2); /* Propagate -- to whom it may concern. */ return FALSE; @@ -649,7 +671,7 @@ ensure_uri_scheme(const gchar *t) } else { if (g_str_has_prefix(f, "!/")) - f = g_strdup_printf(SEARCH_ENGINE, t + 2); + f = g_strdup_printf(search_engine, t + 2); else f = g_strdup_printf("http://%s", t); } @@ -668,10 +690,28 @@ grab_environment_configuration(void) if (e != NULL) accepted_language[0] = g_strdup(e); + /* + * Accept XDG_DOWNLOAD_DIR as a valid download directory if + * LARIZA_DOWNLOAD_DIR is not specifically set. Since the XDG user directory + * specification is extremely stupid, and depends on a certain xdg-user-dir + * binary, we do two runs for acquiring the XDG_DOWNLOAD_DIR. We look at the + * environment variables (which what this specification should have been), + * and use g_get_user_special_dir() if that fails. + */ e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR"); + if (e == NULL) + e = g_getenv("XDG_DOWNLOAD_DIR"); + if (e == NULL) + e = g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD); + if (e == NULL) + e = g_build_filename(g_get_home_dir(), "Downloads", NULL); if (e != NULL) download_dir = g_strdup(e); + e = g_getenv(__NAME_UPPERCASE__"_SEARCH_ENGINE"); + if (e != NULL) + search_engine = g_strdup(e); + e = g_getenv(__NAME_UPPERCASE__"_ENABLE_CONSOLE_TO_STDOUT"); if (e != NULL) enable_console_to_stdout = TRUE; @@ -861,9 +901,6 @@ init_default_web_context(void) webkit_web_context_set_web_extensions_directory(wc, p); g_free(p); - if (accepted_language[0] != NULL) - webkit_web_context_set_preferred_languages(wc, accepted_language); - g_signal_connect(G_OBJECT(wc), "download-started", G_CALLBACK(download_handle_start), NULL); @@ -918,6 +955,7 @@ key_common(GtkWidget *widget, GdkEvent *event, gpointer data) search(c, 1); return TRUE; case GDK_KEY_3: /* search backward (left hand) */ + case GDK_KEY_N: /* search backward (maybe both hands) */ search(c, -1); return TRUE; case GDK_KEY_o: /* location (BOTH hands) */ @@ -1155,7 +1193,7 @@ permission_request(WebKitWebView *v, WebKitPermissionRequest *r, gpointer data) { struct Client *c = (struct Client *)data; const gchar *h; - char *permission_str; + const gchar *permission_str; h = g_uri_get_host(g_uri_parse( webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)), |