[totem/wip/hadess/playlist-inspector] main: Add playlist page to GTK inspector




commit b7794aca64718e9db11fd9906d9652533cfe2447
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Apr 8 16:41:38 2022 +0200

    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.

 src/meson.build                     |  15 +++++
 src/totem-inspector-module.c        |  26 ++++++++
 src/totem-object.c                  |  10 ---
 src/totem-playlist-inspector-page.c | 129 ++++++++++++++++++++++++++++++++++++
 src/totem-playlist-inspector-page.h |  14 ++++
 5 files changed, 184 insertions(+), 10 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index 6446e603e..c1f9ced5a 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,20 @@ executable(
   c_args: totem_common_cflags
 )
 
+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,
+)
+
 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..b66f73958
--- /dev/null
+++ b/src/totem-inspector-module.c
@@ -0,0 +1,26 @@
+/*
+ * 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)
+{
+  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..ec667f4a0
--- /dev/null
+++ b/src/totem-playlist-inspector-page.c
@@ -0,0 +1,129 @@
+/*
+ * 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_CONTINUE;
+       app = g_application_get_default ();
+       if (!app)
+               return G_SOURCE_CONTINUE;
+       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:
+               //insert_playlist_widget (self);
+               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 (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)


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