fix: fix some warts

- stuff to deal with plugin code wasn't actually compiling
  - created a "stand_in" plugin to provide headers and function
definitions
  - when these are not used
  - it is likely there are better approaches here
- hidebar, newtab -> hide_bar, new_tab
This commit is contained in:
NunoSempere 2023-02-07 14:17:10 +01:00
parent 35f968f29b
commit b50d30851b
4 changed files with 79 additions and 18 deletions

View File

@ -2,7 +2,8 @@
CC=clang CC=clang
SRC=rose.c SRC=rose.c
REQS= #./plugins/*/*.c # REQS=./plugins/*/*.c
REQS=./plugins/stand_in/stand_in.c
DEPS='webkit2gtk-4.0' DEPS='webkit2gtk-4.0'
INCS=`pkg-config --cflags ${DEPS}` INCS=`pkg-config --cflags ${DEPS}`
@ -11,5 +12,5 @@ LIBS=`pkg-config --libs ${DEPS}`
# Optional adblocking depends on https://github.com/jun7/wyebadblock # Optional adblocking depends on https://github.com/jun7/wyebadblock
WYEBAB='-L/usr/lib/wyebrowser/adblock.so' WYEBAB='-L/usr/lib/wyebrowser/adblock.so'
cp -f config.def.h config.h # cp -f config.def.h config.h
$CC $INCS $REQS $SRC -o rose $LIBS $WYEBAB $CC $INCS $REQS $SRC -o rose $LIBS $WYEBAB

View File

@ -0,0 +1,27 @@
/* Why this file is needed:
* If the plugins are disabled,
* their conditionals will never resolve
* and their functionality never comes into play
* but the compiler still wants to know their type
*/
int libre_redirect(const char* uri, char* uri_filtered){
return 0;
}
void str_init(char* str, int n){
};
int str_replace_start(const char* string, const char* target,
const char* replacement, char* output){
return 1;
};
void read_readability_js(char* string){
}
void read_style_js(char* string){
}

View File

@ -0,0 +1,23 @@
/* Why this file is needed:
* If the plugins are disabled,
* their conditionals will never resolve
* and their functionality never comes into play
* but the compiler still wants to know their type
*/
#pragma once
#define LIBRE_N 0
#define STYLE_N 0
#define READABILITY_N 0
int libre_redirect(const char* uri, char* uri_filtered);
void str_init(char* str, int n);
int str_replace_start(const char* string, const char* target,
const char* replacement, char* output);
void read_readability_js(char* string);
void read_style_js(char* string);

38
rose.c
View File

@ -6,7 +6,9 @@
* files to modify, copy, merge, publish, distribute and/or * files to modify, copy, merge, publish, distribute and/or
* sublicense copies of this sotware for their own use. * sublicense copies of this sotware for their own use.
* This code does not come with any warranty. * This code does not come with any warranty.
*
*/ */
#include <stdlib.h> // necessary for free, malloc.
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <webkit2/webkit2.h> #include <webkit2/webkit2.h>
@ -17,16 +19,20 @@
// #include "plugins/readability/readability.h" // #include "plugins/readability/readability.h"
// #include "plugins/style/style.h" // #include "plugins/style/style.h"
#include "plugins/stand_in/stand_in.h"
int LIBRE_REDIRECT_ENABLED = false; int LIBRE_REDIRECT_ENABLED = false;
int READABILITY_ENABLED = false; int READABILITY_ENABLED = false;
int CUSTOM_STYLE_ENABLED = false; int CUSTOM_STYLE_ENABLED = false;
// to enable plugins, // to enable plugins,
// 1. uncomment their #include statement // 1. Enable them:
// 2. set their variable to true; // - uncomment their #include statement
// 3. in build.sh, uncomment: // - set their variable to true
// REQS= #./plugins/*/*.c // - in build.sh, uncomment: REQS= #./plugins/*/*.c
// 2. Remove stand_in code;
// - Comment out #include "plugins/stand_in/stand_in.h" line, or edit it together with stand_in.c so as to not include the plugin functions.
// - In build.sh, comment out REQS=./plugins/stand_in/stand_in.c
#define CACHE \ #define CACHE \
"base-cache-directory", CACHE_DIR, \ "base-cache-directory", CACHE_DIR, \
@ -80,12 +86,19 @@ WebKitWebView *webview_new()
"user-content-manager", contentmanager, NULL); "user-content-manager", contentmanager, NULL);
} }
WebKitWebView *notebook_get_webview(GtkNotebook *notebook)
{
return WEBKIT_WEB_VIEW(
gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook)));
}
void load_uri(WebKitWebView *view, const char *uri) void load_uri(WebKitWebView *view, const char *uri)
{ {
if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") || if (g_str_has_prefix(uri, "http://") || g_str_has_prefix(uri, "https://") ||
g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) { g_str_has_prefix(uri, "file://") || g_str_has_prefix(uri, "about:")) {
webkit_web_view_load_uri(view, uri); webkit_web_view_load_uri(view, uri);
} else { } else {
// webkit_web_view_load_uri(view, uri);
char tmp[strlen(uri) + strlen(SEARCH)]; char tmp[strlen(uri) + strlen(SEARCH)];
snprintf(tmp, sizeof(tmp), SEARCH, uri); snprintf(tmp, sizeof(tmp), SEARCH, uri);
webkit_web_view_load_uri(view, tmp); webkit_web_view_load_uri(view, tmp);
@ -196,12 +209,7 @@ void notebook_append(GtkNotebook *notebook, const char *uri)
webkit_web_view_set_background_color(view, &rgba); webkit_web_view_set_background_color(view, &rgba);
load_uri(view, (uri) ? uri : HOME); load_uri(view, (uri) ? uri : HOME);
gtk_notebook_set_current_page(notebook, n); gtk_notebook_set_current_page(notebook, n);
} gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-" );
WebKitWebView *notebook_get_webview(GtkNotebook *notebook)
{
return WEBKIT_WEB_VIEW(
gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook)));
} }
void show_bar(GtkNotebook *notebook) void show_bar(GtkNotebook *notebook)
@ -278,6 +286,7 @@ int handle_key(func id, GtkNotebook *notebook)
gtk_notebook_get_n_pages(notebook) - 1) { gtk_notebook_get_n_pages(notebook) - 1) {
notebook_append(notebook, NULL); notebook_append(notebook, NULL);
gtk_notebook_set_show_tabs(notebook, true); gtk_notebook_set_show_tabs(notebook, true);
webkit_web_view_set_zoom_level(notebook_get_webview(notebook), zoom);
} else { } else {
gtk_notebook_next_page(notebook); gtk_notebook_next_page(notebook);
} }
@ -326,12 +335,14 @@ int handle_key(func id, GtkNotebook *notebook)
webkit_web_view_get_find_controller(notebook_get_webview(notebook))); webkit_web_view_get_find_controller(notebook_get_webview(notebook)));
break; break;
case newtab: case new_tab:
notebook_append(notebook, NULL); notebook_append(notebook, NULL);
gtk_notebook_set_show_tabs(notebook, true); gtk_notebook_set_show_tabs(notebook, true);
entry_mode = _SEARCH;
show_bar(notebook);
break; break;
case hidebar: case hide_bar:
entry_mode = _HIDDEN; entry_mode = _HIDDEN;
show_bar(notebook); show_bar(notebook);
break; break;
@ -412,7 +423,6 @@ void setup(GtkNotebook *notebook, const char *uri)
gtk_window_set_default_size(window, WIDTH, HEIGHT); gtk_window_set_default_size(window, WIDTH, HEIGHT);
window_init(notebook); window_init(notebook);
notebook_init(notebook, uri); notebook_init(notebook, uri);
g_object_set(gtk_settings_get_default(), GTK, NULL); g_object_set(gtk_settings_get_default(), GTK, NULL);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(notebook)); gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(notebook));