Skip to content

Commit 74d7d4b

Browse files
committed
build: Add support for GIRepository-2.0.
Needed for libpeas-based plugins.
1 parent becb779 commit 74d7d4b

5 files changed

Lines changed: 56 additions & 3 deletions

File tree

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Build-Depends: debhelper-compat (= 12),
1212
libexempi-dev (>= 1.99.5),
1313
libexif-dev (>= 0.6.14),
1414
libgdk-pixbuf-xlib-2.0-dev,
15-
libgirepository1.0-dev (>= 0.9.12),
15+
libgirepository1.0-dev (>= 0.9.12) | libgirepository-2.0-dev,
1616
libglib2.0-dev (>= 2.38.0),
1717
libgtk-3-dev,
1818
libjpeg-dev,

meson.build

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,29 @@ gnome = import('gnome')
3434
i18n = import('i18n')
3535
pkgconfig = import('pkgconfig')
3636

37+
cc = meson.get_compiler('c')
38+
3739
# dependencies
3840
gio_unix = dependency('gio-unix-2.0', version: '>= 2.38.0')
3941
glib = dependency('glib-2.0', version: '>= 2.38.0')
4042
gtk = dependency('gtk+-3.0')
4143
libpeas = dependency('libpeas-1.0', version: '>= 0.7.4')
4244
libpeas_gtk = dependency('libpeas-gtk-1.0', version: '>= 0.7.4')
45+
46+
use_gir20 = cc.has_header('girepository/girepository.h', dependencies: libpeas)
47+
if use_gir20
48+
gi = dependency('girepository-2.0')
49+
else
50+
gi = dependency('gobject-introspection-1.0', version: '>= 0.9.2')
51+
endif
52+
xviewer_conf.set10('USE_GIR20', use_gir20)
53+
4354
pixbuf = dependency('gdk-pixbuf-2.0', version: '>= 2.19.1')
4455
X11 = dependency('x11')
4556
zlib = dependency('zlib')
4657
cinnamon_desktop = dependency('cinnamon-desktop', version: '>= 3.2.0')
4758
xapp = dependency('xapp', version: '>= 2.5.0')
4859

49-
cc = meson.get_compiler('c')
50-
5160
# on some systems we need to find the math lib to make sure it builds
5261
math = cc.find_library('m', required: false)
5362

src/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@
2727
#include "config.h"
2828
#endif
2929
#ifdef HAVE_INTROSPECTION
30+
#if USE_GIR20
31+
#include <girepository/girepository.h>
32+
#else
3033
#include <girepository.h>
3134
#endif
35+
#endif
3236

3337
#include "xviewer-application.h"
3438
#include "xviewer-application-internal.h"
@@ -102,7 +106,11 @@ main (int argc, char **argv)
102106
* Using gtk_get_option_group here initializes gtk during parsing */
103107
g_option_context_add_group (ctx, gtk_get_option_group (FALSE));
104108
#ifdef HAVE_INTROSPECTION
109+
#if USE_GIR20
110+
g_option_context_add_group (ctx, gi_repository_get_option_group ());
111+
#else
105112
g_option_context_add_group (ctx, g_irepository_get_option_group ());
113+
#endif
106114
#endif
107115

108116
if (!g_option_context_parse (ctx, &argc, &argv, &error)) {

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ xviewer_resources = gnome.compile_resources(
131131

132132
xviewer_deps = [
133133
config_h,
134+
gi,
134135
gio_unix,
135136
glib,
136137
gtk,

src/xviewer-plugin-engine.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
#include <glib/gi18n.h>
3535
#include <glib.h>
3636
#include <gio/gio.h>
37+
38+
#if USE_GIR20
39+
#include <girepository/girepository.h>
40+
#else
3741
#include <girepository.h>
42+
#endif
3843

3944
#define XVIEWER_PLUGIN_DATA_DIR XVIEWER_DATA_DIR G_DIR_SEPARATOR_S "plugins"
4045

@@ -86,6 +91,35 @@ xviewer_plugin_engine_new (void)
8691
GError *error = NULL;
8792

8893
/* This should be moved to libpeas */
94+
#if USE_GIR20
95+
GIRepository *repo = gi_repository_dup_default ();
96+
97+
if (gi_repository_require (repo, "Peas", "1.0", 0, &error) == NULL)
98+
{
99+
g_warning ("Error loading Peas typelib: %s\n",
100+
error->message);
101+
g_clear_error (&error);
102+
}
103+
104+
if (gi_repository_require (repo, "PeasGtk", "1.0", 0, &error) == NULL)
105+
{
106+
g_warning ("Error loading PeasGtk typelib: %s\n",
107+
error->message);
108+
g_clear_error (&error);
109+
}
110+
111+
typelib_path = g_build_filename (LIBDIR, "xviewer", "girepository-1.0", NULL);
112+
113+
if (gi_repository_require_private (repo, typelib_path,
114+
"Xviewer", "3.0", 0, &error) == NULL)
115+
{
116+
g_warning ("Error loading Xviewer typelib: %s\n",
117+
error->message);
118+
g_clear_error (&error);
119+
}
120+
121+
g_object_unref (repo);
122+
#else
89123
if (g_irepository_require (g_irepository_get_default (),
90124
"Peas", "1.0", 0, &error) == NULL)
91125
{
@@ -112,6 +146,7 @@ xviewer_plugin_engine_new (void)
112146
error->message);
113147
g_clear_error (&error);
114148
}
149+
#endif
115150

116151
engine = XVIEWER_PLUGIN_ENGINE (g_object_new (XVIEWER_TYPE_PLUGIN_ENGINE,
117152
NULL));

0 commit comments

Comments
 (0)