From 98abdb39c4c043fa5175f0dc6e532ec794a5dc18 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 17 Dec 2022 20:54:27 +0100 Subject: feat: integrate libre_redirect code into rose.c --- rose.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/rose.c b/rose.c index 78bdd3b..c71a1b8 100644 --- a/rose.c +++ b/rose.c @@ -9,10 +9,12 @@ * * @author: fenze */ +#include +#include +#include #include "config.h" - -#include +#include "plugins/libre_redirect/libre_redirect.h" #define CACHE \ "base-cache-directory", CACHE_DIR, \ @@ -78,15 +80,43 @@ void load_uri(WebKitWebView *view, const char *uri) } } +void redirect_if_annoying(WebKitWebView *view, const char *uri){ + int l = LIBRE_N + strlen(uri) + 1; + char uri_filtered[l]; + str_init(uri_filtered, l); + + int check = libre_redirect(uri, uri_filtered); + if(check == 2){ + webkit_web_view_load_uri(view, uri_filtered); + } + +} + void load_changed(WebKitWebView *self, WebKitLoadEvent load_event, GtkNotebook *notebook) { - if (load_event == WEBKIT_LOAD_FINISHED) { - gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self), - webkit_web_view_get_title(self)); - gtk_widget_hide(GTK_WIDGET(bar)); - } + switch (load_event) { + /* see */ + case WEBKIT_LOAD_STARTED: + redirect_if_annoying(self, webkit_web_view_get_uri(self)); + break; + case WEBKIT_LOAD_REDIRECTED: + redirect_if_annoying(self, webkit_web_view_get_uri(self)); + break; + case WEBKIT_LOAD_COMMITTED: + redirect_if_annoying(self, webkit_web_view_get_uri(self)); + break; + case WEBKIT_LOAD_FINISHED: + { + const char* title = webkit_web_view_get_title(self); + gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(self), + title == NULL ? "—" : title ); + // gtk_widget_hide(GTK_WIDGET(bar)); + break; + } + } } + void notebook_append(GtkNotebook *notebook, const char *uri) { GdkScreen *screen = gtk_window_get_screen(GTK_WINDOW(window)); -- cgit v1.2.3