diff options
author | Jens Georg <mail@jensge.org> | 2016-09-04 23:35:30 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2016-12-17 09:47:54 +0100 |
commit | 867b543b045600036ff7511106233587db9289b4 (patch) | |
tree | 9dd98878e1f63672d99fde6a10621d4c2d33e5b2 /src | |
parent | c166b3a1b2ed6e5427ce32e0d8802a8b1244f4a8 (diff) | |
download | gupnp-tools-867b543b045600036ff7511106233587db9289b4.tar.gz |
av-cp: Make DIDL-Lite dialog a template class
Signed-off-by: Jens Georg <mail@jensge.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/av-cp/Makefile.am | 4 | ||||
-rw-r--r-- | src/av-cp/didl-dialog.c | 128 | ||||
-rw-r--r-- | src/av-cp/didl-dialog.h | 58 | ||||
-rw-r--r-- | src/av-cp/playlist-treeview.c | 43 |
4 files changed, 192 insertions, 41 deletions
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; } |