[libgepub/libsoup3] Make gepub-widget configurable



commit 112251fe87162b5e0a1a88dca8affd8c71c8ff71
Author: Daniel GarcĂ­a Moreno <dani danigm net>
Date:   Tue Aug 30 09:57:52 2022 +0200

    Make gepub-widget configurable
    
    This makes the WebKit2 dep optional so the library can be used just to
    read epubs and do not require the whole webkit when it's not needed.

 libgepub/gepub.h     |  5 +++++
 libgepub/meson.build | 12 +++++++++---
 meson.build          | 14 ++++++++++++--
 meson_options.txt    |  1 +
 tests/test-gepub.c   | 29 ++++++++++++++++++++---------
 5 files changed, 47 insertions(+), 14 deletions(-)
---
diff --git a/libgepub/gepub.h b/libgepub/gepub.h
index a8f7fd2..aae56b4 100644
--- a/libgepub/gepub.h
+++ b/libgepub/gepub.h
@@ -1,9 +1,14 @@
 #ifndef _GEPUB__H_
 #define _GEPUB__H_
 
+#include <config.h>
+
 #include "gepub-archive.h"
 #include "gepub-text-chunk.h"
 #include "gepub-doc.h"
+
+#ifdef GEPUB_WIDGET_ENABLED
 #include "gepub-widget.h"
+#endif
 
 #endif
diff --git a/libgepub/meson.build b/libgepub/meson.build
index 65c8463..d8b99ea 100644
--- a/libgepub/meson.build
+++ b/libgepub/meson.build
@@ -2,7 +2,6 @@ headers = files(
   'gepub-archive.h',
   'gepub-doc.h',
   'gepub-text-chunk.h',
-  'gepub-widget.h',
   'gepub.h'
 )
 
@@ -18,9 +17,13 @@ sources = files(
   'gepub-doc.c',
   'gepub-text-chunk.c',
   'gepub-utils.c',
-  'gepub-widget.c'
 )
 
+if get_option('widget')
+  sources += files('gepub-widget.c')
+  headers += files('gepub-widget.h')
+endif
+
 symbol_map = join_paths(meson.current_source_dir(), 'gepub.map')
 
 test_ldflag = '-Wl,--version-script,' + symbol_map
@@ -69,9 +72,12 @@ if get_option('introspection') and get_option('default_library') == 'shared'
   gir_incs = [
     'GObject-2.0',
     'libxml2-2.0',
-    'WebKit2-4.1'
   ]
 
+  if get_option('widget')
+    gir_incs += ['WebKit2-4.1']
+  endif
+
   gir_extra_args = '--warn-all'
 
   gir_dir = join_paths(gepub_datadir, '@0@-@1@'.format('gir', gepub_gir_version))
diff --git a/meson.build b/meson.build
index c868167..406a744 100644
--- a/meson.build
+++ b/meson.build
@@ -31,7 +31,6 @@ libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
 cc = meson.get_compiler('c')
 
 gepub_deps = [
-  dependency('webkit2gtk-4.1'),
   dependency('libsoup-3.0'),
   dependency('glib-2.0'),
   dependency('gobject-2.0'),
@@ -40,6 +39,11 @@ gepub_deps = [
   dependency('libarchive')
 ]
 
+if get_option('widget')
+  webkit2gtk = dependency('webkit2gtk-4.1')
+  gepub_deps += [webkit2gtk]
+endif
+
 gnome = import('gnome')
 pkg = import('pkgconfig')
 
@@ -48,7 +52,13 @@ top_inc = include_directories('.')
 subdir('libgepub')
 subdir('tests')
 
+config_h = configuration_data()
+
+if get_option('widget')
+  config_h.set('GEPUB_WIDGET_ENABLED', 1)
+endif
+
 configure_file(
   output: 'config.h',
-  configuration: configuration_data()
+  configuration: config_h,
 )
diff --git a/meson_options.txt b/meson_options.txt
index d33e9ec..bb85878 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1 +1,2 @@
 option('introspection', type: 'boolean', value: true, description: 'Enable GObject Introspection (depends on 
GObject)')
+option('widget', type: 'boolean', value: true, description: 'Build with GepubWidget based on Webkit')
diff --git a/tests/test-gepub.c b/tests/test-gepub.c
index 15bf481..ccc8b5b 100644
--- a/tests/test-gepub.c
+++ b/tests/test-gepub.c
@@ -21,6 +21,7 @@ GtkWidget *PAGE_LABEL;
 
 #define TEST(f,arg...) PTEST ("\n### TESTING " #f " ###\n\n"); f (arg); PTEST ("\n\n");
 
+#ifdef GEPUB_WIDGET_ENABLED
 static void
 reload_current_chapter (GepubWidget *widget)
 {
@@ -28,6 +29,7 @@ reload_current_chapter (GepubWidget *widget)
     gtk_label_set_text (GTK_LABEL (PAGE_LABEL), txt);
     g_free (txt);
 }
+#endif
 
 static void
 update_text (GepubDoc *doc)
@@ -77,6 +79,7 @@ print_replaced_text (GepubDoc *doc)
 }
 #endif
 
+#ifdef GEPUB_WIDGET_ENABLED
 static void
 button_pressed (GtkButton *button, GepubWidget *widget)
 {
@@ -120,6 +123,7 @@ button_pressed (GtkButton *button, GepubWidget *widget)
     update_text (doc);
     //print_replaced_text (doc);
 }
+#endif
 
 static void
 test_open (const char *path)
@@ -295,6 +299,7 @@ test_doc_toc (const char *path)
     g_object_unref (G_OBJECT (doc));
 }
 
+#ifdef GEPUB_WIDGET_ENABLED
 static void
 destroy_cb (GtkWidget *window,
             GtkWidget *view)
@@ -304,6 +309,7 @@ destroy_cb (GtkWidget *window,
                                           view);
     gtk_main_quit ();
 }
+#endif
 
 int
 main (int argc, char **argv)
@@ -342,18 +348,12 @@ main (int argc, char **argv)
 
     gtk_init (&argc, &argv);
 
-    widget = gepub_widget_new ();
-
-    webkit_settings_set_enable_developer_extras (
-        webkit_web_view_get_settings (WEBKIT_WEB_VIEW (widget)), TRUE);
-
     if (argc < 2) {
         printf ("you should provide an .epub file\n");
         return 1;
     }
 
     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-    g_signal_connect (window, "destroy", G_CALLBACK(destroy_cb), widget);
     gtk_widget_set_size_request (GTK_WIDGET (window), 1200, 800);
     vpaned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
     gtk_container_add (GTK_CONTAINER (window), vpaned);
@@ -365,7 +365,15 @@ main (int argc, char **argv)
         return -1;
     }
 
+    #ifdef GEPUB_WIDGET_ENABLED
+    widget = gepub_widget_new ();
+
+    webkit_settings_set_enable_developer_extras (
+        webkit_web_view_get_settings (WEBKIT_WEB_VIEW (widget)), TRUE);
+
     gepub_widget_set_doc (GEPUB_WIDGET (widget), doc);
+    g_signal_connect (window, "destroy", G_CALLBACK(destroy_cb), widget);
+    #endif
 
     scrolled = gtk_scrolled_window_new (NULL, NULL);
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, 
GTK_POLICY_AUTOMATIC);
@@ -382,6 +390,8 @@ main (int argc, char **argv)
     vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
     hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
     hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
+
+    #ifdef GEPUB_WIDGET_ENABLED
     b_prev = gtk_button_new_with_label ("< chapter");
     g_signal_connect (b_prev, "clicked", (GCallback)button_pressed, GEPUB_WIDGET (widget));
     b_next = gtk_button_new_with_label ("chapter >");
@@ -407,13 +417,12 @@ main (int argc, char **argv)
     lh2 = gtk_button_new_with_label ("line height -");
     g_signal_connect (lh2, "clicked", (GCallback)button_pressed, GEPUB_WIDGET (widget));
 
-    PAGE_LABEL = gtk_label_new ("0");
-
     g_signal_connect_swapped (widget, "notify",
                               G_CALLBACK (reload_current_chapter), widget);
 
     paginate = gtk_check_button_new_with_label ("paginated");
     g_signal_connect (paginate, "clicked", (GCallback)button_pressed, GEPUB_WIDGET (widget));
+    gtk_paned_add2 (GTK_PANED (vpaned), widget);
 
     gtk_container_add (GTK_CONTAINER (hbox), b_prev);
     gtk_container_add (GTK_CONTAINER (hbox), b_next);
@@ -432,11 +441,14 @@ main (int argc, char **argv)
 
     gtk_container_add (GTK_CONTAINER (hbox2), lh1);
     gtk_container_add (GTK_CONTAINER (hbox2), lh2);
+    #endif
 
     gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 5);
     gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 5);
     gtk_box_pack_start (GTK_BOX (vbox), scrolled, TRUE, TRUE, 5);
 
+    PAGE_LABEL = gtk_label_new ("0");
+
     textview = gtk_text_view_new ();
     scrolled = gtk_scrolled_window_new (NULL, NULL);
     gtk_container_add (GTK_CONTAINER (scrolled), textview);
@@ -445,7 +457,6 @@ main (int argc, char **argv)
 
     gtk_widget_set_size_request (GTK_WIDGET (vbox), 600, 500);
     gtk_paned_add1 (GTK_PANED (vpaned), vbox);
-    gtk_paned_add2 (GTK_PANED (vpaned), widget);
 
     gtk_widget_show_all (window);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]