summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2016-09-04 23:35:30 +0200
committerJens Georg <mail@jensge.org>2016-12-17 09:47:54 +0100
commit867b543b045600036ff7511106233587db9289b4 (patch)
tree9dd98878e1f63672d99fde6a10621d4c2d33e5b2
parentc166b3a1b2ed6e5427ce32e0d8802a8b1244f4a8 (diff)
downloadgupnp-tools-867b543b045600036ff7511106233587db9289b4.tar.gz
av-cp: Make DIDL-Lite dialog a template class
Signed-off-by: Jens Georg <mail@jensge.org>
-rw-r--r--data/didl-lite-dialog.ui73
-rw-r--r--data/org.gupnp.Tools.AV-CP.gresource.xml3
-rw-r--r--src/av-cp/Makefile.am4
-rw-r--r--src/av-cp/didl-dialog.c128
-rw-r--r--src/av-cp/didl-dialog.h58
-rw-r--r--src/av-cp/playlist-treeview.c43
6 files changed, 267 insertions, 42 deletions
diff --git a/data/didl-lite-dialog.ui b/data/didl-lite-dialog.ui
new file mode 100644
index 0000000..3b50007
--- /dev/null
+++ b/data/didl-lite-dialog.ui
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+ <requires lib="gtk+" version="3.20"/>
+ <requires lib="gtksourceview" version="3.0"/>
+ <template class="AVCPDidlDialog" parent="GtkDialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">GUPnP AV CP - Metadata View</property>
+ <property name="default_width">640</property>
+ <property name="default_height">480</property>
+ <property name="type_hint">dialog</property>
+ <signal name="delete-event" handler="gtk_widget_hide_on_delete" swapped="no"/>
+ <child internal-child="vbox">
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="didl-close-button">
+ <property name="label">_Close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked" handler="gtk_widget_hide" object="AVCPDidlDialog" swapped="yes"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="didl-scrolledwindow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <child>
+ <object class="GtkSourceView" id="didl_textview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
+ <property name="wrap_mode">char</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">didl-close-button</action-widget>
+ </action-widgets>
+ </template>
+</interface>
diff --git a/data/org.gupnp.Tools.AV-CP.gresource.xml b/data/org.gupnp.Tools.AV-CP.gresource.xml
index abe7151..8db8120 100644
--- a/data/org.gupnp.Tools.AV-CP.gresource.xml
+++ b/data/org.gupnp.Tools.AV-CP.gresource.xml
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix='/org/gupnp/Tools/AV-CP'>
<file preprocess='xml-stripblanks'>search-dialog.ui</file>
+ <file preprocess='xml-stripblanks'>didl-lite-dialog.ui</file>
<file preprocess='xml-stripblanks'>gupnp-av-cp.ui</file>
- </gresource>
+ </gresource>
</gresources>
diff --git a/src/av-cp/Makefile.am b/src/av-cp/Makefile.am
index c32d849..2982b5a 100644
--- a/src/av-cp/Makefile.am
+++ b/src/av-cp/Makefile.am
@@ -42,7 +42,9 @@ gupnp_av_cp_SOURCES = main.c \
server-device.c \
server-device.h \
search-dialog.c \
- search-dialog.h
+ search-dialog.h \
+ didl-dialog.h \
+ didl-dialog.c
gupnp_av_cp_LDADD = ../common/libutil.a \
$(LIBGSSDP_LIBS) \
diff --git a/src/av-cp/didl-dialog.c b/src/av-cp/didl-dialog.c
new file mode 100644
index 0000000..62ac9f1
--- /dev/null
+++ b/src/av-cp/didl-dialog.c
@@ -0,0 +1,128 @@
+/*
+ * 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 "didl-dialog.h"
+#include "pretty-print.h"
+
+#include <gtk/gtk.h>
+
+#ifdef HAVE_GTK_SOURCEVIEW
+#include <gtksourceview/gtksource.h>
+#endif
+
+#define DIALOG_RESOURCE_PATH "/org/gupnp/Tools/AV-CP/didl-lite-dialog.ui"
+
+struct _AVCPDidlDialog {
+ GtkDialog parent;
+};
+
+struct _AVCPDidlDialogClass {
+ GtkDialogClass parent_class;
+};
+
+struct _AVCPDidlDialogPrivate {
+ GtkWidget *didl_textview;
+};
+typedef struct _AVCPDidlDialogPrivate AVCPDidlDialogPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (AVCPDidlDialog, av_cp_didl_dialog, GTK_TYPE_DIALOG)
+
+/* GObject overrides */
+static void av_cp_didl_dialog_constructed (GObject *object);
+
+static void
+av_cp_didl_dialog_class_init (AVCPDidlDialogClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ gtk_widget_class_set_template_from_resource (widget_class,
+ DIALOG_RESOURCE_PATH);
+
+ gtk_widget_class_bind_template_child_private (widget_class,
+ AVCPDidlDialog,
+ didl_textview);
+
+ object_class->constructed = av_cp_didl_dialog_constructed;
+}
+
+static void
+av_cp_didl_dialog_init (AVCPDidlDialog *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+av_cp_didl_dialog_constructed (GObject *object)
+{
+ AVCPDidlDialog *self = AV_CP_DIDL_DIALOG (object);
+ AVCPDidlDialogPrivate *priv;
+ GObjectClass *parent_class = NULL;
+
+ parent_class = G_OBJECT_CLASS (av_cp_didl_dialog_parent_class);
+ if (parent_class->constructed != NULL) {
+ parent_class->constructed (object);
+ }
+
+ priv = av_cp_didl_dialog_get_instance_private (self);
+
+ g_signal_connect (object, "delete-event",
+ G_CALLBACK (gtk_widget_hide_on_delete), NULL);
+
+#ifdef HAVE_GTK_SOURCEVIEW
+ {
+ GtkSourceLanguageManager *manager =
+ gtk_source_language_manager_get_default ();
+ GtkSourceLanguage *language =
+ gtk_source_language_manager_guess_language (manager,
+ NULL,
+ "text/xml");
+
+ GtkSourceBuffer *buffer = gtk_source_buffer_new_with_language (language);
+ gtk_source_buffer_set_highlight_syntax (buffer, TRUE);
+ gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (priv->didl_textview),
+ TRUE);
+
+ gtk_text_view_set_buffer (GTK_TEXT_VIEW (priv->didl_textview),
+ GTK_TEXT_BUFFER (buffer));
+ }
+#endif
+}
+
+AVCPDidlDialog *
+av_cp_didl_dialog_new (void)
+{
+ return g_object_new (AV_CP_TYPE_DIDL_DIALOG, NULL);
+}
+
+void
+av_cp_didl_dialog_set_xml (AVCPDidlDialog *self, const char *xml)
+{
+ GtkTextBuffer *buffer;
+ char *formatted;
+ AVCPDidlDialogPrivate *priv;
+
+ priv = av_cp_didl_dialog_get_instance_private (self);
+
+ formatted = pretty_print_xml (xml);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->didl_textview));
+ gtk_text_buffer_set_text (buffer, formatted, -1);
+ g_free (formatted);
+}
diff --git a/src/av-cp/didl-dialog.h b/src/av-cp/didl-dialog.h
new file mode 100644
index 0000000..3834cd0
--- /dev/null
+++ b/src/av-cp/didl-dialog.h
@@ -0,0 +1,58 @@
+/*
+ * 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 DIDL_DIALOG_H
+#define DIDL_DIALOG_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <libgupnp/gupnp.h>
+
+G_BEGIN_DECLS
+
+GType
+av_cp_didl_dialog_get_type (void);
+
+#define AV_CP_TYPE_DIDL_DIALOG (av_cp_didl_dialog_get_type ())
+#define AV_CP_DIDL_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ AV_CP_TYPE_DIDL_DIALOG, \
+ AVCPDidlDialog))
+#define AV_CP_DIDL_DIALOG_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), \
+ AV_CP_TYPE_DIDL_DIALOG, \
+ AVCPDidlDialogClass))
+#define AV_CP_IS_DIDL_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ AV_CP_TYPE_DIDL_DIALOG))
+#define AV_CP_IS_DIDL_DIALOG_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), \
+ AV_CP_TYPE_DIDL_DIALOG))
+#define AV_CP_DIDL_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ AV_CP_TYPE_DIDL_DIALOG, \
+ AVCPDidlDialogDeviceClass))
+
+typedef struct _AVCPDidlDialog AVCPDidlDialog;
+typedef struct _AVCPDidlDialogClass AVCPDidlDialogClass;
+
+AVCPDidlDialog *av_cp_didl_dialog_new (void);
+void av_cp_didl_dialog_set_xml (AVCPDidlDialog *self, const char *xml);
+
+G_END_DECLS
+
+#endif /* DIDL_DIALOG_H */
diff --git a/src/av-cp/playlist-treeview.c b/src/av-cp/playlist-treeview.c
index 119365f..431cab1 100644
--- a/src/av-cp/playlist-treeview.c
+++ b/src/av-cp/playlist-treeview.c
@@ -23,10 +23,6 @@
#include <config.h>
#include <gmodule.h>
-#ifdef HAVE_GTK_SOURCEVIEW
-#include <gtksourceview/gtksource.h>
-#endif
-
#include "playlist-treeview.h"
#include "renderer-combo.h"
#include "renderer-controls.h"
@@ -35,6 +31,7 @@
#include "gui.h"
#include "server-device.h"
#include "search-dialog.h"
+#include "didl-dialog.h"
#define CONTENT_DIR "urn:schemas-upnp-org:service:ContentDirectory"
@@ -52,7 +49,6 @@ typedef gboolean (* RowCompareFunc) (GtkTreeModel *model,
static GtkWidget *treeview;
static GtkWidget *popup;
static GtkWidget *didl_dialog;
-static GtkWidget *didl_textview;
static gboolean expanded;
static GHashTable *initial_notify;
static GtkDialog *search_dialog;
@@ -309,18 +305,9 @@ on_playlist_row_collapsed (GtkTreeView *tree_view,
static void display_metadata (const char *metadata,
gpointer user_data)
{
- GtkTextBuffer *buffer;
- char *formatted;
-
- formatted = pretty_print_xml (metadata);
-
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (didl_textview));
- gtk_text_buffer_set_text (buffer, formatted, -1);
- gtk_widget_show (GTK_WIDGET (didl_textview));
+ av_cp_didl_dialog_set_xml (AV_CP_DIDL_DIALOG (didl_dialog), metadata);
gtk_dialog_run (GTK_DIALOG (didl_dialog));
-
- g_free (formatted);
}
G_MODULE_EXPORT
@@ -384,31 +371,7 @@ setup_playlist_treeview (GtkBuilder *builder)
popup = GTK_WIDGET (gtk_builder_get_object (builder, "playlist-popup"));
g_assert (popup != NULL);
- didl_dialog = GTK_WIDGET (gtk_builder_get_object (builder,
- "didl-dialog"));
- g_signal_connect (didl_dialog, "delete-event",
- G_CALLBACK (gtk_widget_hide_on_delete), NULL);
-
- didl_textview = GTK_WIDGET (gtk_builder_get_object (builder,
- "didl-textview"));
-#ifdef HAVE_GTK_SOURCEVIEW
- {
- GtkSourceLanguageManager *manager =
- gtk_source_language_manager_get_default ();
- GtkSourceLanguage *language =
- gtk_source_language_manager_guess_language (manager,
- NULL,
- "text/xml");
-
- GtkSourceBuffer *buffer = gtk_source_buffer_new_with_language (language);
- gtk_source_buffer_set_highlight_syntax (buffer, TRUE);
- gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (didl_textview),
- TRUE);
-
- gtk_text_view_set_buffer (GTK_TEXT_VIEW (didl_textview),
- GTK_TEXT_BUFFER (buffer));
- }
-#endif
+ didl_dialog = GTK_WIDGET (av_cp_didl_dialog_new ());
expanded = FALSE;
}