[gupnp-tools] av-cp: Add server device class
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp-tools] av-cp: Add server device class
- Date: Mon, 25 Apr 2016 21:37:11 +0000 (UTC)
commit f18b0dc1f40a80d03f56d8a290a49a8c2e161b4b
Author: Jens Georg <mail jensge org>
Date: Sat Apr 2 16:16:53 2016 +0200
av-cp: Add server device class
Signed-off-by: Jens Georg <mail jensge org>
https://bugzilla.gnome.org/show_bug.cgi?id=730747
src/av-cp/Makefile.am | 4 +-
src/av-cp/main.c | 26 +++++++++
src/av-cp/playlist-treeview.c | 13 ++++-
src/av-cp/server-device.c | 126 +++++++++++++++++++++++++++++++++++++++++
src/av-cp/server-device.h | 69 ++++++++++++++++++++++
5 files changed, 235 insertions(+), 3 deletions(-)
---
diff --git a/src/av-cp/Makefile.am b/src/av-cp/Makefile.am
index 43cb58d..b1f8db6 100644
--- a/src/av-cp/Makefile.am
+++ b/src/av-cp/Makefile.am
@@ -24,7 +24,9 @@ gupnp_av_cp_SOURCES = main.c \
gui.h \
playlist-treeview.h \
renderer-combo.h \
- renderer-controls.h
+ renderer-controls.h \
+ server-device.c \
+ server-device.h
gupnp_av_cp_LDADD = ../common/libutil.a \
$(LIBGSSDP_LIBS) \
diff --git a/src/av-cp/main.c b/src/av-cp/main.c
index 1d92b3c..df10862 100644
--- a/src/av-cp/main.c
+++ b/src/av-cp/main.c
@@ -35,6 +35,7 @@
#include "gui.h"
#include "renderer-combo.h"
#include "playlist-treeview.h"
+#include "server-device.h"
#define MEDIA_RENDERER "urn:schemas-upnp-org:device:MediaRenderer:1"
#define MEDIA_SERVER "urn:schemas-upnp-org:device:MediaServer:1"
@@ -137,11 +138,36 @@ init_upnp (int port)
{
GUPnPWhiteList *white_list;
GtkButton *button;
+ GUPnPResourceFactory *factory;
#if !GLIB_CHECK_VERSION(2, 35, 0)
g_type_init ();
#endif
+ factory = gupnp_resource_factory_get_default ();
+
+ /* Work-around bgo#764498 */
+
+ gupnp_resource_factory_register_resource_proxy_type (
+ factory,
+ "urn:schemas-upnp-org:device:MediaServer:1",
+ AV_CP_TYPE_MEDIA_SERVER);
+
+ gupnp_resource_factory_register_resource_proxy_type (
+ factory,
+ "urn:schemas-upnp-org:device:MediaServer:2",
+ AV_CP_TYPE_MEDIA_SERVER);
+
+ gupnp_resource_factory_register_resource_proxy_type (
+ factory,
+ "urn:schemas-upnp-org:device:MediaServer:3",
+ AV_CP_TYPE_MEDIA_SERVER);
+
+ gupnp_resource_factory_register_resource_proxy_type (
+ factory,
+ "urn:schemas-upnp-org:device:MediaServer:4",
+ AV_CP_TYPE_MEDIA_SERVER);
+
context_manager = gupnp_context_manager_create (port);
g_assert (context_manager != NULL);
diff --git a/src/av-cp/playlist-treeview.c b/src/av-cp/playlist-treeview.c
index 6a78cf1..ad96ba0 100644
--- a/src/av-cp/playlist-treeview.c
+++ b/src/av-cp/playlist-treeview.c
@@ -33,6 +33,7 @@
#include "icons.h"
#include "pretty-print.h"
#include "gui.h"
+#include "server-device.h"
#define CONTENT_DIR "urn:schemas-upnp-org:service:ContentDirectory"
@@ -729,16 +730,21 @@ append_didl_object (GUPnPDIDLLiteObject *object,
static void
on_device_icon_available (GUPnPDeviceInfo *info,
- GdkPixbuf *icon)
+ GParamSpec *spec,
+ gpointer user_data)
{
GtkTreeModel *model;
GtkTreeIter iter;
+ AVCPMediaServer *server;
const char *udn;
+ GdkPixbuf *icon;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
g_assert (model != NULL);
udn = gupnp_device_info_get_udn (info);
+ server = AV_CP_MEDIA_SERVER (info);
+ g_object_get (G_OBJECT (server), "icon", &icon, NULL);
if (find_row (model,
NULL,
@@ -1043,7 +1049,10 @@ append_media_server (GUPnPDeviceProxy *proxy,
child = g_list_delete_link (child, child);
}
- schedule_icon_update (info, on_device_icon_available);
+ g_signal_connect (proxy,
+ "notify::icon",
+ G_CALLBACK (on_device_icon_available),
+ NULL);
browse (content_dir, "0", 0, MAX_BROWSE);
gupnp_service_proxy_add_notify (content_dir,
diff --git a/src/av-cp/server-device.c b/src/av-cp/server-device.c
new file mode 100644
index 0000000..f961054
--- /dev/null
+++ b/src/av-cp/server-device.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2016 Jens Georg <mail jensge org>
+ *
+ * Authors: Jens Georg <mail jensge org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "server-device.h"
+#include "icons.h"
+
+G_DEFINE_TYPE (AVCPMediaServer, av_cp_media_server, GUPNP_TYPE_DEVICE_PROXY)
+
+struct _AVCPMediaServerPrivate {
+ GdkPixbuf *icon;
+};
+
+enum
+{
+ PROP_ICON = 1,
+ N_PROPERTIES
+};
+
+static GParamSpec *av_cp_media_server_properties[N_PROPERTIES] = { NULL, };
+
+/* GObject overrides */
+static void
+av_cp_media_server_constructed (GObject *obj);
+
+static void
+av_cp_media_server_dispose (GObject *object)
+{
+ GObjectClass *parent_class =
+ G_OBJECT_CLASS (av_cp_media_server_parent_class);
+
+ g_clear_object (&self->priv->icon);
+
+ parent_class->dispose (object);
+}
+
+static void
+av_cp_media_server_get_property (GObject *obj,
+ guint property_id,
+ GValue *value,
+ GParamSpec *spec)
+{
+ AVCPMediaServer *self = AV_CP_MEDIA_SERVER (obj);
+
+ switch (property_id) {
+ case PROP_ICON:
+ g_value_set_object (value, self->priv->icon);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, spec);
+ break;
+ }
+}
+
+static void
+av_cp_media_server_on_icon_updated (GUPnPDeviceInfo *info,
+ GdkPixbuf *icon);
+
+static void
+av_cp_media_server_class_init (AVCPMediaServerClass *klass)
+{
+ GObjectClass *obj_class = G_OBJECT_CLASS (klass);
+
+ obj_class->constructed = av_cp_media_server_constructed;
+ obj_class->get_property = av_cp_media_server_get_property;
+ obj_class->dispose = av_cp_media_server_dispose;
+
+ g_type_class_add_private (klass, sizeof (AVCPMediaServerPrivate));
+
+ av_cp_media_server_properties[PROP_ICON] =
+ g_param_spec_object ("icon",
+ "icon",
+ "icon",
+ GDK_TYPE_PIXBUF,
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_READABLE);
+
+ g_object_class_install_properties (obj_class,
+ N_PROPERTIES,
+ av_cp_media_server_properties);
+}
+
+static void
+av_cp_media_server_init (AVCPMediaServer *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ AV_CP_TYPE_MEDIA_SERVER,
+ AVCPMediaServerPrivate);
+}
+
+static void
+av_cp_media_server_constructed (GObject *obj)
+{
+ AVCPMediaServer *self = AV_CP_MEDIA_SERVER (obj);
+
+ G_OBJECT_CLASS (av_cp_media_server_parent_class)->constructed (obj);
+
+ schedule_icon_update (GUPNP_DEVICE_INFO (self),
+ av_cp_media_server_on_icon_updated);
+}
+
+static void
+av_cp_media_server_on_icon_updated (GUPnPDeviceInfo *info,
+ GdkPixbuf *icon)
+{
+ AVCPMediaServer *self = AV_CP_MEDIA_SERVER (info);
+
+ self->priv->icon = icon;
+ g_object_notify (G_OBJECT (info), "icon");
+}
diff --git a/src/av-cp/server-device.h b/src/av-cp/server-device.h
new file mode 100644
index 0000000..69509ef
--- /dev/null
+++ b/src/av-cp/server-device.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 Jens Georg <mail jensge org>
+ *
+ * Authors: Jens Georg <mail jensge org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef MEDIA_SERVER_H
+#define MEDIA_SERVER_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libgupnp/gupnp.h>
+
+G_BEGIN_DECLS
+
+GType
+av_cp_media_server_get_type (void);
+
+#define AV_CP_TYPE_MEDIA_SERVER (av_cp_media_server_get_type ())
+#define AV_CP_MEDIA_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ AV_CP_TYPE_MEDIA_SERVER, \
+ AVCPMediaServer))
+#define AV_CP_MEDIA_SERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), \
+ AV_CP_TYPE_MEDIA_SERVER, \
+ AVCPMediaServerClass))
+#define AV_CP_IS_MEDIA_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ AV_CP_TYPE_MEDIA_SERVER))
+#define AV_CP_IS_MEDIA_SERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), \
+ AV_CP_TYPE_MEDIA_SERVER))
+#define AV_CP_MEDIA_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ AV_CP_TYPE_MEDIA_SERVER, \
+ AVCPMediaServerDeviceClass))
+
+typedef struct _AVCPMediaServer AVCPMediaServer;
+typedef struct _AVCPMediaServerClass AVCPMediaServerClass;
+typedef struct _AVCPMediaServerPrivate AVCPMediaServerPrivate;
+
+struct _AVCPMediaServer {
+ GUPnPDeviceProxy parent;
+
+ AVCPMediaServerPrivate *priv;
+};
+
+struct _AVCPMediaServerClass {
+ GUPnPDeviceProxyClass parent_class;
+};
+
+gboolean
+av_cp_media_server_ready (AVCPMediaServer *self);
+
+G_END_DECLS
+
+#endif /* MEDIA_SERVER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]