commit: 2216742794e48bda3898813acbb9e1d68d38b241
parent aa9d7cd7abb1c1bb2afab376194614ef0c5c9b6e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 6 Jul 2019 14:39:30 +0200
Move non-static definitions to badwolf.h, with proper namespacing
Diffstat:
M | badwolf.c | 62 | +++++++++++--------------------------------------------------- |
A | badwolf.h | 44 | ++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 55 insertions(+), 51 deletions(-)
diff --git a/badwolf.c b/badwolf.c
@@ -2,42 +2,18 @@
// Copyright © 2019 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
// SPDX-License-Identifier: BSD-3-Clause
+#include "badwolf.h"
+
#include "config.h"
#include <glib/gi18n.h> /* _() and other internationalization/localization helpers */
#include <glib/gprintf.h> /* g_fprintf() */
-#include <gtk/gtk.h>
-#include <locale.h> /* LC_* */
-#include <stdlib.h> /* realpath(), malloc() */
-#include <webkit2/webkit2.h>
+#include <locale.h> /* LC_* */
+#include <stdlib.h> /* realpath(), malloc() */
const gchar *homepage = "https://hacktivis.me/projects/badwolf";
const gchar *version = "0.3.0";
-struct Window
-{
- GtkWidget *main_window;
- GtkWidget *notebook;
- GtkWidget *new_tab;
-};
-
-struct Client
-{
- GtkWidget *box;
-
- GtkWidget *toolbar;
- GtkWidget *javascript;
- GtkWidget *location;
-
- WebKitWebView *webView;
- struct Window *window;
-
- GtkWidget *statusbar;
- GtkWidget *statuslabel;
- GtkWidget *search;
-};
-
-gchar *ensure_uri_scheme(gchar *text, gboolean 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);
@@ -51,12 +27,10 @@ static gboolean WebViewCb_web_process_terminated(WebKitWebView *webView,
gpointer user_data);
static gboolean
WebViewCb_notify__uri(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data);
-GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser);
static gboolean
WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data);
static gboolean
WebViewCb_notify__is__playing__audio(WebKitWebView *webView, GParamSpec *pspec, gpointer user_data);
-void webView_tab_label_change(struct Client *browser, const gchar *title);
static gboolean WebViewCb_notify__estimated_load_progress(WebKitWebView *webView,
GParamSpec *pspec,
gpointer user_data);
@@ -86,28 +60,13 @@ static gboolean SearchEntryCb_next__match(GtkSearchEntry *search, gpointer user_
static gboolean SearchEntryCb_previous__match(GtkSearchEntry *search, gpointer user_data);
static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer user_data);
static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data);
-struct Client *
-new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view);
-int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser);
static void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data);
static void closeCb_clicked(GtkButton *close, gpointer user_data);
static void
notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data);
-gint get_tab_position(GtkContainer *notebook, GtkWidget *child);
-/* ensure_uri_scheme: tries to add a scheme on a pseudo-URL missing a scheme
- * - gchar text: pseudo-URL missing a scheme
- * - gboolean try_file: when TRUE check try first if it can be a file:// path
- *
- * When `text` isn't exploitable (ie. NULL), returns "about:blank",
- * when the URL seems to be valid, return it,
- * if try_file is TRUE, check if it can be file:// path,
- * some other checks might be added.
- * In the end use the fallback (`http://` for now, might get configuration),
- * might get some safeguard.
- */
gchar *
-ensure_uri_scheme(gchar *text, gboolean try_file)
+badwolf_ensure_uri_scheme(gchar *text, gboolean try_file)
{
if(text == NULL) return "about:blank";
@@ -156,7 +115,8 @@ WebViewCb_close(WebKitWebView *webView, gpointer user_data)
struct Client *browser = (struct Client *)user_data;
GtkNotebook *notebook = GTK_NOTEBOOK(browser->window->notebook);
- gtk_notebook_remove_page(notebook, get_tab_position(GTK_CONTAINER(notebook), browser->box));
+ gtk_notebook_remove_page(notebook,
+ badwolf_get_tab_position(GTK_CONTAINER(notebook), browser->box));
gtk_widget_destroy(browser->box);
@@ -420,7 +380,7 @@ webView_tab_label_change(struct Client *browser, const gchar *title)
gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(notebook), browser->box, title);
// Set the window title if the title change was on the current tab
- if(get_tab_position(GTK_CONTAINER(notebook), browser->box) ==
+ if(badwolf_get_tab_position(GTK_CONTAINER(notebook), browser->box) ==
gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)))
gtk_window_set_title(GTK_WINDOW(browser->window->main_window), title);
}
@@ -600,7 +560,7 @@ locationCb_activate(GtkEntry *location, gpointer user_data)
char *target_url;
struct Client *browser = (struct Client *)user_data;
- target_url = ensure_uri_scheme((char *)gtk_entry_get_text(location), TRUE);
+ target_url = badwolf_ensure_uri_scheme((char *)gtk_entry_get_text(location), TRUE);
if(target_url != NULL) webkit_web_view_load_uri(browser->webView, target_url);
@@ -674,7 +634,7 @@ struct Client *
new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view)
{
struct Client *browser = malloc(sizeof(struct Client));
- target_url = ensure_uri_scheme(target_url, (related_web_view == NULL));
+ target_url = badwolf_ensure_uri_scheme(target_url, (related_web_view == NULL));
char *badwolf_l10n = NULL;
if(browser == NULL) return NULL;
@@ -877,7 +837,7 @@ notebookCb_switch__page(GtkNotebook *notebook, GtkWidget *page, guint page_num,
}
gint
-get_tab_position(GtkContainer *notebook, GtkWidget *child)
+badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child)
{
GValue position = G_VALUE_INIT;
g_value_init(&position, G_TYPE_INT);
diff --git a/badwolf.h b/badwolf.h
@@ -0,0 +1,44 @@
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+
+struct Window
+{
+ GtkWidget *main_window;
+ GtkWidget *notebook;
+ GtkWidget *new_tab;
+};
+
+struct Client
+{
+ GtkWidget *box;
+
+ GtkWidget *toolbar;
+ GtkWidget *javascript;
+ GtkWidget *location;
+
+ WebKitWebView *webView;
+ struct Window *window;
+
+ GtkWidget *statusbar;
+ GtkWidget *statuslabel;
+ GtkWidget *search;
+};
+
+/* badwolf_ensure_uri_scheme: tries to add a scheme on a pseudo-URL missing a scheme
+ * - gchar text: pseudo-URL missing a scheme
+ * - gboolean try_file: when TRUE check try first if it can be a file:// path
+ *
+ * When `text` isn't exploitable (ie. NULL), returns "about:blank",
+ * when the URL seems to be valid, return it,
+ * if try_file is TRUE, check if it can be file:// path,
+ * some other checks might be added.
+ * In the end use the fallback (`http://` for now, might get configuration),
+ * might get some safeguard.
+ */
+gchar *badwolf_ensure_uri_scheme(gchar *text, gboolean try_file);
+GtkWidget *badwolf_new_tab_box(const gchar *title, struct Client *browser);
+void webView_tab_label_change(struct Client *browser, const gchar *title);
+struct Client *
+new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view);
+int badwolf_new_tab(GtkNotebook *notebook, struct Client *browser);
+gint badwolf_get_tab_position(GtkContainer *notebook, GtkWidget *child);