summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2022-04-08 16:41:38 +0200
committerBastien Nocera <hadess@hadess.net>2022-07-18 11:25:19 +0200
commit8d55550dbd41a15184eb17eeb80533d5b34c6a97 (patch)
treee5ed35f0e0f39c0ea0badf8ea402b6548a25f010
parent4de39a5d63b07e9d6a7dd8d0fad3da2cadd866a2 (diff)
downloadtotem-8d55550dbd41a15184eb17eeb80533d5b34c6a97.tar.gz
main: Add playlist page to GTK inspector
Before this change, it was possible to visualise the playlist as a widget by recompiling totem while uncommenting a couple of lines of code. Move this functionality to the GTK inspector by creating a module that will get loaded when the GTK inspector is.
-rw-r--r--meson_options.txt1
-rw-r--r--src/meson.build17
-rw-r--r--src/totem-inspector-module.c34
-rw-r--r--src/totem-object.c10
-rw-r--r--src/totem-playlist-inspector-page.c130
-rw-r--r--src/totem-playlist-inspector-page.h14
6 files changed, 196 insertions, 10 deletions
diff --git a/meson_options.txt b/meson_options.txt
index 4611a1376..da23319cb 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -5,3 +5,4 @@ option('libportal', type: 'feature', value: 'auto', description: 'Build plugins
option('with-plugins', type: 'combo', choices: ['all', 'none', 'auto'], value: 'auto', description: 'Which Totem plugins to compile (default: auto; "all", "none" and "auto" are valid)')
option('enable-gtk-doc', type: 'boolean', value: false, description: 'use gtk-doc to build documentation')
option('profile', type: 'combo', choices: ['default', 'development'], value: 'default', description: 'Build profiles')
+option('inspector-page', type:'boolean', value: false, description: 'Whether to build the optional GTK inspector page')
diff --git a/src/meson.build b/src/meson.build
index 6446e603e..3185cea50 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -118,6 +118,7 @@ libtotem_sources = files(
'totem-open-location.c',
'totem-options.c',
'totem-playlist.c',
+ 'totem-playlist-inspector-page.c',
'totem-preferences-dialog.c',
'totem-search-entry.c',
'totem-selection-toolbar.c',
@@ -262,6 +263,22 @@ executable(
c_args: totem_common_cflags
)
+if get_option('inspector-page')
+ module_libdir = totem_libdir / 'gtk-3.0' / 'inspector'
+
+ totem_inspector_sources = [
+ 'totem-inspector-module.c',
+ ]
+
+ shared_module(
+ 'totem-inspector-module',
+ totem_inspector_sources,
+ dependencies: libtotem_player_dep,
+ install: true,
+ install_dir: module_libdir,
+ )
+endif
+
gir_sources = libtotem_sources + libtotem_player_sources + headers
gir_incs = [
diff --git a/src/totem-inspector-module.c b/src/totem-inspector-module.c
new file mode 100644
index 000000000..24869181a
--- /dev/null
+++ b/src/totem-inspector-module.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2022 Red Hat Inc.
+ *
+ * SPDX-License-Identifier: GPL-2-or-later WITH gstreamer-exception
+ *
+ * Author: Bastien Nocera <hadess@hadess.net>
+ */
+
+#include "totem.h"
+#include "totem-playlist-inspector-page.h"
+
+void
+g_io_module_load (GIOModule *module)
+{
+ GApplication *app;
+
+ app = g_application_get_default ();
+ if (!app)
+ return;
+ if (!g_str_has_prefix (g_application_get_application_id (app), "org.gnome.Totem"))
+ return;
+
+ g_type_module_use (G_TYPE_MODULE (module));
+
+ g_io_extension_point_implement ("gtk-inspector-page",
+ TOTEM_TYPE_PLAYLIST_INSPECTOR_PAGE,
+ "totem-playlist",
+ 10);
+}
+
+void
+g_io_module_unload (GIOModule *module)
+{
+}
diff --git a/src/totem-object.c b/src/totem-object.c
index 47b326761..eb35c8b74 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -4088,16 +4088,6 @@ playlist_widget_setup (TotemObject *totem)
totem->playlist = TOTEM_PLAYLIST (totem_playlist_new ());
totem->playlist_signals = g_signal_group_new (TOTEM_TYPE_PLAYLIST);
-#if 0
- {
- GtkWidget *window;
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_default_size (GTK_WINDOW (window), 500, 400);
- gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (totem->playlist));
- gtk_widget_show_all (window);
- }
-#endif
g_signal_group_connect (totem->playlist_signals, "active-name-changed",
G_CALLBACK (on_playlist_change_name), totem);
g_signal_group_connect (totem->playlist_signals, "item-activated",
diff --git a/src/totem-playlist-inspector-page.c b/src/totem-playlist-inspector-page.c
new file mode 100644
index 000000000..57f8323e5
--- /dev/null
+++ b/src/totem-playlist-inspector-page.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2022 Red Hat Inc.
+ *
+ * SPDX-License-Identifier: GPL-2-or-later WITH gstreamer-exception
+ *
+ * Author: Bastien Nocera <hadess@hadess.net>
+ */
+
+#include "totem-playlist-inspector-page.h"
+#include "totem-private.h"
+
+struct _TotemPlaylistInspectorPage {
+ GtkBox parent_instance;
+
+ TotemObject *totem;
+ GObject *object;
+};
+
+G_DEFINE_FINAL_TYPE (TotemPlaylistInspectorPage, totem_playlist_inspector_page, GTK_TYPE_BOX)
+
+enum {
+ PROP_0,
+ PROP_TITLE,
+ PROP_OBJECT,
+ LAST_PROP,
+};
+
+static GParamSpec *props[LAST_PROP];
+
+static gboolean
+insert_playlist_widget (TotemPlaylistInspectorPage *self)
+{
+ GApplication *app;
+ TotemObject *totem;
+
+ if (self->totem)
+ return G_SOURCE_REMOVE;
+ app = g_application_get_default ();
+ if (!app || !TOTEM_IS_OBJECT (app)) {
+ g_warning ("TotemPlaylistInspectorPage instantiated for non-totem app");
+ return G_SOURCE_REMOVE;
+ }
+ totem = TOTEM_OBJECT (app);
+ if (!totem->playlist)
+ return G_SOURCE_CONTINUE;
+ gtk_container_add (GTK_CONTAINER (self),
+ GTK_WIDGET (totem->playlist));
+ gtk_widget_show_all (GTK_WIDGET (self));
+ self->totem = totem;
+ return G_SOURCE_REMOVE;
+}
+
+static void
+totem_playlist_inspector_page_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TotemPlaylistInspectorPage *self = TOTEM_PLAYLIST_INSPECTOR_PAGE (object);
+
+ switch (prop_id) {
+ case PROP_TITLE:
+ g_value_set_string (value, "Playlist");
+ break;
+ case PROP_OBJECT:
+ g_value_set_object (value, self->object);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+totem_playlist_inspector_page_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TotemPlaylistInspectorPage *self = TOTEM_PLAYLIST_INSPECTOR_PAGE (object);
+
+ switch (prop_id) {
+ case PROP_OBJECT:
+ g_set_object (&self->object, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+totem_playlist_inspector_page_dispose (GObject *object)
+{
+ TotemPlaylistInspectorPage *self = TOTEM_PLAYLIST_INSPECTOR_PAGE (object);
+
+ g_clear_object (&self->object);
+
+ G_OBJECT_CLASS (totem_playlist_inspector_page_parent_class)->dispose (object);
+}
+
+static void
+totem_playlist_inspector_page_class_init (TotemPlaylistInspectorPageClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = totem_playlist_inspector_page_get_property;
+ object_class->set_property = totem_playlist_inspector_page_set_property;
+ object_class->dispose = totem_playlist_inspector_page_dispose;
+
+ props[PROP_TITLE] =
+ g_param_spec_string ("title",
+ "Title",
+ "Title",
+ "Playlist",
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ props[PROP_OBJECT] =
+ g_param_spec_object ("object",
+ "Object",
+ "Object",
+ G_TYPE_OBJECT,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, props);
+}
+
+static void
+totem_playlist_inspector_page_init (TotemPlaylistInspectorPage *self)
+{
+ g_idle_add ((GSourceFunc) insert_playlist_widget, self);
+}
diff --git a/src/totem-playlist-inspector-page.h b/src/totem-playlist-inspector-page.h
new file mode 100644
index 000000000..6b5b16671
--- /dev/null
+++ b/src/totem-playlist-inspector-page.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) 2022 Red Hat Inc.
+ *
+ * SPDX-License-Identifier: GPL-2-or-later WITH gstreamer-exception
+ *
+ * Author: Bastien Nocera <hadess@hadess.net>
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#define TOTEM_TYPE_PLAYLIST_INSPECTOR_PAGE (totem_playlist_inspector_page_get_type())
+G_DECLARE_FINAL_TYPE (TotemPlaylistInspectorPage, totem_playlist_inspector_page, TOTEM, PLAYLIST_INSPECTOR_PAGE, GtkBox)