diff options
author | Matthias Clasen <mclasen@redhat.com> | 2018-03-01 21:46:16 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2018-03-18 21:01:23 +0100 |
commit | e4338c4d422501a459c714a82da76e2ec29b7727 (patch) | |
tree | b7d75adc874c51ce0ba77c1ac0b47d9289d6981d /gtk | |
parent | 29cccf5e84d61f438298e6f857939a1bcdb3d33a (diff) | |
download | gtk+-e4338c4d422501a459c714a82da76e2ec29b7727.tar.gz |
mediafile: Turn into an extension point
This way, we can support external libraries providing implementations of
GtkMediaFile.
We also add a media backend called 'nomedia' that can be enabled to not
compile any support for GtkMediaFile. This is useful when people want to
statically compile GTK into an application that does not use media.
For now, this option is the default.
We also support a new environment variable GTK_MEDIA that allows
selecting the implementation to use.
GTK_MEDIA=help can be used to get info about the available
implementations.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkmain.c | 2 | ||||
-rw-r--r-- | gtk/gtkmediafile.c | 109 | ||||
-rw-r--r-- | gtk/gtkmediafile.h | 2 | ||||
-rw-r--r-- | gtk/gtkmediafileprivate.h | 29 | ||||
-rw-r--r-- | gtk/gtknomediafile.c | 63 | ||||
-rw-r--r-- | gtk/gtknomediafileprivate.h | 33 | ||||
-rw-r--r-- | gtk/meson.build | 1 |
7 files changed, 236 insertions, 3 deletions
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index 336c9363ae..bd0720d5c8 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -119,6 +119,7 @@ #include "gtkdebugupdatesprivate.h" #include "gtkdndprivate.h" #include "gtkmain.h" +#include "gtkmediafileprivate.h" #include "gtkmenu.h" #include "gtkmodulesprivate.h" #include "gtkprivate.h" @@ -632,6 +633,7 @@ default_display_notify_cb (GdkDisplayManager *dm) debug_flags[0].display = gdk_display_get_default (); gtk_print_backends_init (); gtk_im_modules_init (); + gtk_media_file_extension_init (); _gtk_accessibility_init (); } diff --git a/gtk/gtkmediafile.c b/gtk/gtkmediafile.c index edc121fe3e..e3b0e62756 100644 --- a/gtk/gtkmediafile.c +++ b/gtk/gtkmediafile.c @@ -19,9 +19,12 @@ #include "config.h" -#include "gtkmediafile.h" +#include "gtkmediafileprivate.h" +#include "gtkdebug.h" #include "gtkintl.h" +#include "gtkmodulesprivate.h" +#include "gtknomediafileprivate.h" /** * SECTION:gtkmediafile @@ -179,8 +182,64 @@ gtk_media_file_init (GtkMediaFile *self) static GType gtk_media_file_get_impl_type (void) { - g_assert_not_reached (); - return G_TYPE_INVALID; + static GType impl_type = G_TYPE_NONE; + const char *extension_name; + GIOExtension *e; + GIOExtensionPoint *ep; + + if (G_LIKELY (impl_type != G_TYPE_NONE)) + return impl_type; + + GTK_NOTE (MODULES, g_print ("Looking up MediaFile extension\n")); + + ep = g_io_extension_point_lookup (GTK_MEDIA_FILE_EXTENSION_POINT_NAME); + e = NULL; + + extension_name = g_getenv ("GTK_MEDIA"); + if (extension_name) + { + if (g_str_equal (extension_name, "help")) + { + GList *l; + + g_print ("Supported arguments for GTK_MEDIA environment variable:\n"); + + for (l = g_io_extension_point_get_extensions (ep); l; l = l->next) + { + e = l->data; + + g_print ("%10s - %d\n", g_io_extension_get_name (e), g_io_extension_get_priority (e)); + } + + e = NULL; + } + else + { + e = g_io_extension_point_get_extension_by_name (ep, extension_name); + if (e == NULL) + { + g_warning ("Media extension \"%s\" from GTK_MEDIA environment variable not found.", extension_name); + } + } + } + + if (e == NULL) + { + GList *l = g_io_extension_point_get_extensions (ep); + + if (l == NULL) + { + g_error ("GTK was run without any GtkMediaFile extension being present. This must not happen."); + } + + e = l->data; + } + + impl_type = g_io_extension_get_type (e); + + GTK_NOTE (MODULES, g_print ("Using %s from \"%s\" extension\n", g_type_name (impl_type), g_io_extension_get_name (e))); + + return impl_type; } /** @@ -524,3 +583,47 @@ gtk_media_file_get_input_stream (GtkMediaFile *self) return priv->input_stream; } + +void +gtk_media_file_extension_init (void) +{ + GIOExtensionPoint *ep; + GIOModuleScope *scope; + char **paths; + int i; + + GTK_NOTE (MODULES, + g_print ("Registering extension point %s\n", GTK_MEDIA_FILE_EXTENSION_POINT_NAME)); + + ep = g_io_extension_point_register (GTK_MEDIA_FILE_EXTENSION_POINT_NAME); + g_io_extension_point_set_required_type (ep, GTK_TYPE_MEDIA_FILE); + + g_type_ensure (GTK_TYPE_NO_MEDIA_FILE); + + scope = g_io_module_scope_new (G_IO_MODULE_SCOPE_BLOCK_DUPLICATES); + + paths = _gtk_get_module_path ("media"); + for (i = 0; paths[i]; i++) + { + GTK_NOTE (MODULES, + g_print ("Scanning io modules in %s\n", paths[i])); + g_io_modules_scan_all_in_directory_with_scope (paths[i], scope); + } + g_strfreev (paths); + + g_io_module_scope_free (scope); + + if (GTK_DEBUG_CHECK (MODULES)) + { + GList *list, *l; + + list = g_io_extension_point_get_extensions (ep); + for (l = list; l; l = l->next) + { + GIOExtension *ext = l->data; + g_print ("extension: %s: type %s\n", + g_io_extension_get_name (ext), + g_type_name (g_io_extension_get_type (ext))); + } + } +} diff --git a/gtk/gtkmediafile.h b/gtk/gtkmediafile.h index 20f38399a4..daa17d9aa8 100644 --- a/gtk/gtkmediafile.h +++ b/gtk/gtkmediafile.h @@ -28,6 +28,8 @@ G_BEGIN_DECLS +#define GTK_MEDIA_FILE_EXTENSION_POINT_NAME "gtk-media-file" + #define GTK_TYPE_MEDIA_FILE (gtk_media_file_get_type ()) GDK_AVAILABLE_IN_ALL diff --git a/gtk/gtkmediafileprivate.h b/gtk/gtkmediafileprivate.h new file mode 100644 index 0000000000..b328183bef --- /dev/null +++ b/gtk/gtkmediafileprivate.h @@ -0,0 +1,29 @@ +/* + * Copyright © 2018 Benjamin Otte + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: Benjamin Otte <otte@gnome.org> + */ + +#ifndef __GTK_MEDIA_FILE_PRIVATE_H__ +#define __GTK_MEDIA_FILE_PRIVATE_H__ + +#include "gtkmediafile.h" + + +void gtk_media_file_extension_init (void); + + +#endif /* __GTK_MEDIA_FILE_PRIVATE_H__ */ diff --git a/gtk/gtknomediafile.c b/gtk/gtknomediafile.c new file mode 100644 index 0000000000..18ac36b9cb --- /dev/null +++ b/gtk/gtknomediafile.c @@ -0,0 +1,63 @@ +/* + * Copyright © 2018 Benjamin Otte + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: Benjamin Otte <otte@gnome.org> + */ + +#include "config.h" + +#include "gtknomediafileprivate.h" + +#include "gtkintl.h" + +struct _GtkNoMediaFile +{ + GtkMediaFile parent_instance; +}; + +struct _GtkNoMediaFileClass +{ + GtkMediaFileClass parent_class; +}; + +G_DEFINE_TYPE_WITH_CODE (GtkNoMediaFile, gtk_no_media_file, GTK_TYPE_MEDIA_FILE, + g_io_extension_point_implement (GTK_MEDIA_FILE_EXTENSION_POINT_NAME, + g_define_type_id, + "none", + G_MININT);) + +static void +gtk_no_media_file_open (GtkMediaFile *file) +{ + gtk_media_stream_error (GTK_MEDIA_STREAM (file), + G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + _("GTK has been compiled without media support.")); +} + +static void +gtk_no_media_file_class_init (GtkNoMediaFileClass *klass) +{ + GtkMediaFileClass *file_class = GTK_MEDIA_FILE_CLASS (klass); + + file_class->open = gtk_no_media_file_open; +} + +static void +gtk_no_media_file_init (GtkNoMediaFile *video) +{ +} + diff --git a/gtk/gtknomediafileprivate.h b/gtk/gtknomediafileprivate.h new file mode 100644 index 0000000000..0bb6f7375a --- /dev/null +++ b/gtk/gtknomediafileprivate.h @@ -0,0 +1,33 @@ +/* + * Copyright © 2018 Benjamin Otte + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + * Authors: Benjamin Otte <otte@gnome.org> + */ + +#ifndef __GTK_NO_MEDIA_FILE_H__ +#define __GTK_NO_MEDIA_FILE_H__ + +#include <gtk/gtkmediafile.h> + +G_BEGIN_DECLS + +#define GTK_TYPE_NO_MEDIA_FILE (gtk_no_media_file_get_type ()) + +G_DECLARE_FINAL_TYPE (GtkNoMediaFile, gtk_no_media_file, GTK, NO_MEDIA_FILE, GtkMediaFile) + +G_END_DECLS + +#endif /* __GTK_NO_MEDIA_FILE_H__ */ diff --git a/gtk/meson.build b/gtk/meson.build index 6ea234c1b5..f62afe4c3d 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -265,6 +265,7 @@ gtk_public_sources = files([ 'gtkmodules.c', 'gtkmountoperation.c', 'gtknativedialog.c', + 'gtknomediafile.c', 'gtknotebook.c', 'gtkorientable.c', 'gtkoverlay.c', |