Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit54f1da0929d5c412aaec8032f277140e7c739726 (patch)
Author
 Haelwenn Monnier <contact@hacktivis.me>
2019-05-12 03:45:50 +0000
Committer
 Haelwenn Monnier <contact@hacktivis.me>
2019-05-12 03:45:50 +0000
Filesde37e55e0b6d32f8df4b8a03d29e3d232b02945b
goodwolf-54f1da0929d5c412aaec8032f277140e7c739726.tar
goodwolf-54f1da0929d5c412aaec8032f277140e7c739726.tar.gz
goodwolf-54f1da0929d5c412aaec8032f277140e7c739726.zip
Parente440a33e371d5741a3f49bc44727665adabbe023 (diff)
Parent47be92a843fe469256ec136dd13f5b2ee69c7d27 (diff)
Merge branch 'features/ensure_url' into 'develop'
Add a simple way to fix the URL See merge request lanodan/badWolf!5
3 files changed, 33 insertions, 5 deletions
-rw-r--r--Makefile2
-rw-r--r--badwolf.12
-rw-r--r--badwolf.c34
diff --git a/Makefile b/Makefile
index 74ddedd..7bd30db 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ TRANS = fr.mo
CC = cc
CFLAGS = -g -Wall -Wextra
-CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\"
+CDEPS = `pkg-config --cflags $(DEPS)` -DDATADIR=\"$(DATADIR)\" -DPACKAGE=\"$(PACKAGE)\" -D_DEFAULT_SOURCE
LIBS = `pkg-config --libs $(DEPS)`
all: $(OBJS) $(TRANS)
diff --git a/badwolf.1 b/badwolf.1
index f039518..0d0d75a 100644
--- a/badwolf.1
+++ b/badwolf.1
@@ -9,7 +9,7 @@
.Sh SYNOPSIS
.Nm
.Op Ar webkit/gtk options
-.Op Ar url
+.Op Ar url or path
.Sh DESCRIPTION
.Nm
is a minimalist browser that care about privacy, it is based on WebKitGTK and thus also accepts WebKitGTK (and depdendencies) flags and environment variables, unfortunately there doesn't seems to be manpages for theses.
diff --git a/badwolf.c b/badwolf.c
index 1cdaab6..246ad76 100644
--- a/badwolf.c
+++ b/badwolf.c
@@ -8,6 +8,7 @@
#include <glib/gprintf.h> /* g_fprintf() */
#include <gtk/gtk.h>
#include <locale.h> /* LC_* */
+#include <stdlib.h> /* realpath() */
#include <webkit2/webkit2.h>
const gchar *homepage = "https://hacktivis.me/projects/badwolf";
@@ -36,6 +37,7 @@ struct Client
GtkWidget *search;
};
+gchar *ensure_uri_scheme(gchar *text, gbool try_file);
static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data);
static gboolean
commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser);
@@ -80,6 +82,32 @@ static void
notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data);
gint get_tab_position(GtkContainer *notebook, GtkWidget *child);
+gchar *
+ensure_uri_scheme(gchar *text, gbool try_file)
+{
+ if(text == NULL) return "about:blank";
+
+ char *scheme = g_uri_parse_scheme(text);
+
+ if(scheme != NULL) return text;
+
+ if(try_file)
+ {
+ gchar *f;
+ char *path;
+ path = realpath(text, NULL);
+
+ if(path != NULL)
+ {
+ f = g_strdup_printf("file://%s", path);
+ free(path);
+ return f;
+ }
+ }
+
+ return g_strdup_printf("http://%s", text);
+}
+
static void
badwolf_about_dialog(GtkWindow *main_window)
{
@@ -425,10 +453,10 @@ WebViewCb_create(WebKitWebView *related_web_view,
static gboolean
locationCb_activate(GtkEntry *location, gpointer user_data)
{
- const char *target_url;
+ char *target_url;
struct Client *browser = (struct Client *)user_data;
- target_url = gtk_entry_get_text(location);
+ target_url = ensure_uri_scheme((char *)gtk_entry_get_text(location), FALSE);
if(target_url != NULL) webkit_web_view_load_uri(browser->webView, target_url);
@@ -502,7 +530,7 @@ struct Client *
new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view)
{
struct Client *browser = g_malloc(sizeof(struct Client));
- if(target_url == NULL) target_url = "about:blank";
+ target_url = ensure_uri_scheme(target_url, (related_web_view != NULL));
browser->window = window;
browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);