[evince] Add a new tab in properties dialog to show information about document license



commit fbc5a66df0f65fa6f06d2d8496794512033a9ef3
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Sun Oct 25 19:33:24 2009 +0100

    Add a new tab in properties dialog to show information about document license
    
    Based on patch by Juanjo Marín. Fixes bgo#349173.

 shell/Makefile.am             |    2 +
 shell/ev-properties-dialog.c  |   15 ++++
 shell/ev-properties-license.c |  170 +++++++++++++++++++++++++++++++++++++++++
 shell/ev-properties-license.h |   50 ++++++++++++
 4 files changed, 237 insertions(+), 0 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index db878e6..2eff97f 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -70,6 +70,8 @@ evince_SOURCES=				\
 	ev-properties-dialog.h		\
 	ev-properties-fonts.c		\
 	ev-properties-fonts.h		\
+	ev-properties-license.c		\
+	ev-properties-license.h		\
 	ev-open-recent-action.c		\
 	ev-open-recent-action.h		\
 	ev-utils.c			\
diff --git a/shell/ev-properties-dialog.c b/shell/ev-properties-dialog.c
index b19408e..c829b3c 100644
--- a/shell/ev-properties-dialog.c
+++ b/shell/ev-properties-dialog.c
@@ -29,6 +29,7 @@
 #include "ev-properties-dialog.h"
 #include "ev-properties-fonts.h"
 #include "ev-properties-view.h"
+#include "ev-properties-license.h"
 
 struct _EvPropertiesDialog {
 	GtkDialog base_instance;
@@ -37,6 +38,7 @@ struct _EvPropertiesDialog {
 	GtkWidget *notebook;
 	GtkWidget *general_page;
 	GtkWidget *fonts_page;
+	GtkWidget *license_page;
 };
 
 struct _EvPropertiesDialogClass {
@@ -107,6 +109,19 @@ ev_properties_dialog_set_document (EvPropertiesDialog *properties,
 		ev_properties_fonts_set_document
 			(EV_PROPERTIES_FONTS (properties->fonts_page), document);
 	}
+
+	if (info->fields_mask & EV_DOCUMENT_INFO_LICENSE && info->license) {
+		if (properties->license_page == NULL) {
+			label = gtk_label_new (_("Document License"));
+			properties->license_page = ev_properties_license_new ();
+			gtk_notebook_append_page (GTK_NOTEBOOK (properties->notebook),
+						  properties->license_page, label);
+			gtk_widget_show (properties->license_page);
+		}
+
+		ev_properties_license_set_license
+			(EV_PROPERTIES_LICENSE (properties->license_page), info->license);
+	}
 }
 
 GtkWidget *
diff --git a/shell/ev-properties-license.c b/shell/ev-properties-license.c
new file mode 100644
index 0000000..f7c7233
--- /dev/null
+++ b/shell/ev-properties-license.c
@@ -0,0 +1,170 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2009 Juanjo Marín <juanj marin juntadeandalucia es>
+ *  Copyright (C) 2005 Red Hat, Inc
+ *
+ * Evince 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.
+ *
+ * Evince 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "ev-properties-license.h"
+
+struct _EvPropertiesLicense {
+	GtkVBox base_instance;
+};
+
+struct _EvPropertiesLicenseClass {
+	GtkVBoxClass base_class;
+};
+
+G_DEFINE_TYPE (EvPropertiesLicense, ev_properties_license, GTK_TYPE_VBOX)
+
+static void
+ev_properties_license_class_init (EvPropertiesLicenseClass *properties_license_class)
+{
+}
+
+static GtkWidget *
+get_license_text_widget (EvDocumentLicense *license)
+{
+	GtkWidget *swindow, *textview;
+	GtkTextBuffer *buffer;
+
+	textview = gtk_text_view_new ();
+	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD);
+	gtk_text_view_set_left_margin (GTK_TEXT_VIEW (textview), 8);
+	gtk_text_view_set_right_margin (GTK_TEXT_VIEW (textview), 8);
+
+	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
+	gtk_text_buffer_set_text (buffer, ev_document_license_get_text (license), -1);
+
+	swindow = gtk_scrolled_window_new (NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
+					GTK_POLICY_AUTOMATIC,
+					GTK_POLICY_AUTOMATIC);
+	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
+					     GTK_SHADOW_IN);
+	gtk_container_add (GTK_CONTAINER (swindow), textview);
+	gtk_widget_show (textview);
+
+	return swindow;
+}
+
+static GtkWidget *
+get_license_uri_widget (const gchar *uri)
+{
+	GtkWidget *label;
+	gchar     *checked_uri;
+	gchar     *markup;
+
+	label = gtk_label_new (NULL);
+	g_object_set (G_OBJECT (label),
+		      "xalign", 0.0,
+		      "width_chars", 25,
+		      "selectable", TRUE,
+		      "ellipsize", PANGO_ELLIPSIZE_END,
+		      NULL);
+
+#if GTK_CHECK_VERSION (2, 17, 0)
+	checked_uri = g_uri_parse_scheme (uri);
+	if (checked_uri) {
+		markup = g_markup_printf_escaped ("<a href=\"%s\">%s</a>", uri, uri);
+		gtk_label_set_markup (GTK_LABEL (label), markup);
+		g_free (markup);
+		g_free (checked_uri);
+	} else
+#endif
+		gtk_label_set_text (GTK_LABEL (label), uri);
+
+	return label;
+}
+
+static void
+ev_properties_license_add_section (EvPropertiesLicense *properties,
+				   const gchar         *title_text,
+				   GtkWidget           *contents)
+{
+	GtkWidget *title;
+	GtkWidget *alignment;
+	gchar     *markup;
+
+	title = gtk_label_new (NULL);
+	gtk_misc_set_alignment (GTK_MISC (title), 0.0, 0.5);
+	gtk_label_set_use_markup (GTK_LABEL (title), TRUE);
+	markup = g_strdup_printf ("<b>%s</b>", title_text);
+	gtk_label_set_markup (GTK_LABEL (title), markup);
+	g_free (markup);
+	gtk_box_pack_start (GTK_BOX (properties), title, FALSE, FALSE, 0);
+	gtk_widget_show (title);
+
+	alignment = gtk_alignment_new (0.5, 0.5, 1., 1.);
+	gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
+	gtk_container_add (GTK_CONTAINER (alignment), contents);
+	gtk_widget_show (contents);
+
+	gtk_box_pack_start (GTK_BOX (properties), alignment, FALSE, TRUE, 0);
+	gtk_widget_show (alignment);
+}
+
+void
+ev_properties_license_set_license (EvPropertiesLicense *properties,
+				   EvDocumentLicense   *license)
+{
+	const gchar *text = ev_document_license_get_text (license);
+	const gchar *uri = ev_document_license_get_uri (license);
+	const gchar *web_statement = ev_document_license_get_web_statement (license);
+
+	if (text) {
+		ev_properties_license_add_section (properties,
+						   _("Usage terms"),
+						   get_license_text_widget (license));
+	}
+
+	if (uri) {
+		ev_properties_license_add_section (properties,
+						   _("Text License"),
+						   get_license_uri_widget (uri));
+	}
+
+	if (web_statement) {
+		ev_properties_license_add_section (properties,
+						   _("Further Information"),
+						   get_license_uri_widget (web_statement));
+	}
+}
+
+static void
+ev_properties_license_init (EvPropertiesLicense *properties)
+{
+	gtk_box_set_spacing (GTK_BOX (properties), 12);
+	gtk_container_set_border_width (GTK_CONTAINER (properties), 12);
+}
+
+GtkWidget *
+ev_properties_license_new (void)
+{
+	EvPropertiesLicense *properties_license;
+
+	properties_license = g_object_new (EV_TYPE_PROPERTIES_LICENSE, NULL);
+
+	return GTK_WIDGET (properties_license);
+}
diff --git a/shell/ev-properties-license.h b/shell/ev-properties-license.h
new file mode 100644
index 0000000..187850d
--- /dev/null
+++ b/shell/ev-properties-license.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2009 Juanjo Marín <juanj marin juntadeandalucia es>
+ *  Copyright (C) 2005 Red Hat, Inc
+ *
+ * Evince 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.
+ *
+ * Evince 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __EV_PROPERTIES_LICENSE_VIEW_H__
+#define __EV_PROPERTIES_LICENSE_VIEW_H__
+
+#include <gtk/gtk.h>
+
+#include <evince-document.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EvPropertiesLicense        EvPropertiesLicense;
+typedef struct _EvPropertiesLicenseClass   EvPropertiesLicenseClass;
+typedef struct _EvPropertiesLicensePrivate EvPropertiesLicensePrivate;
+
+#define EV_TYPE_PROPERTIES_LICENSE		(ev_properties_license_get_type())
+#define EV_PROPERTIES_LICENSE(object)		(G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PROPERTIES_LICENSE, EvPropertiesLicense))
+#define EV_PROPERTIES_LICENSE_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PROPERTIES_LICENSE, EvPropertiesLicenseClass))
+#define EV_IS_PROPERTIES_LICENSE(object)	(G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PROPERTIES_LICENSE))
+#define EV_IS_PROPERTIES_LICENSE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_PROPERTIES_LICENSE))
+#define EV_PROPERTIES_LICENSE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_PROPERTIES_LICENSE, EvPropertiesLicenseClass))
+
+GType      ev_properties_license_get_type    (void) G_GNUC_CONST;
+
+GtkWidget *ev_properties_license_new         (void);
+void       ev_properties_license_set_license (EvPropertiesLicense *properties_license,
+					      EvDocumentLicense   *license);
+
+G_END_DECLS
+
+#endif /* __EV_PROPERTIES_LICENSE_VIEW_H__ */



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