]> www.fi.muni.cz Git - evince.git/blob - shell/ev-properties-license.c
f7c7233a38c3a8fdb9ccf52ade125d1adc5cb078
[evince.git] / shell / ev-properties-license.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /* this file is part of evince, a gnome document viewer
3  *
4  *  Copyright (C) 2009 Juanjo MarĂ­n <juanj.marin@juntadeandalucia.es>
5  *  Copyright (C) 2005 Red Hat, Inc
6  *
7  * Evince is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Evince is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20  */
21
22 #include "config.h"
23
24 #include <string.h>
25
26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h>
28
29 #include "ev-properties-license.h"
30
31 struct _EvPropertiesLicense {
32         GtkVBox base_instance;
33 };
34
35 struct _EvPropertiesLicenseClass {
36         GtkVBoxClass base_class;
37 };
38
39 G_DEFINE_TYPE (EvPropertiesLicense, ev_properties_license, GTK_TYPE_VBOX)
40
41 static void
42 ev_properties_license_class_init (EvPropertiesLicenseClass *properties_license_class)
43 {
44 }
45
46 static GtkWidget *
47 get_license_text_widget (EvDocumentLicense *license)
48 {
49         GtkWidget *swindow, *textview;
50         GtkTextBuffer *buffer;
51
52         textview = gtk_text_view_new ();
53         gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD);
54         gtk_text_view_set_left_margin (GTK_TEXT_VIEW (textview), 8);
55         gtk_text_view_set_right_margin (GTK_TEXT_VIEW (textview), 8);
56
57         buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
58         gtk_text_buffer_set_text (buffer, ev_document_license_get_text (license), -1);
59
60         swindow = gtk_scrolled_window_new (NULL, NULL);
61         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
62                                         GTK_POLICY_AUTOMATIC,
63                                         GTK_POLICY_AUTOMATIC);
64         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
65                                              GTK_SHADOW_IN);
66         gtk_container_add (GTK_CONTAINER (swindow), textview);
67         gtk_widget_show (textview);
68
69         return swindow;
70 }
71
72 static GtkWidget *
73 get_license_uri_widget (const gchar *uri)
74 {
75         GtkWidget *label;
76         gchar     *checked_uri;
77         gchar     *markup;
78
79         label = gtk_label_new (NULL);
80         g_object_set (G_OBJECT (label),
81                       "xalign", 0.0,
82                       "width_chars", 25,
83                       "selectable", TRUE,
84                       "ellipsize", PANGO_ELLIPSIZE_END,
85                       NULL);
86
87 #if GTK_CHECK_VERSION (2, 17, 0)
88         checked_uri = g_uri_parse_scheme (uri);
89         if (checked_uri) {
90                 markup = g_markup_printf_escaped ("<a href=\"%s\">%s</a>", uri, uri);
91                 gtk_label_set_markup (GTK_LABEL (label), markup);
92                 g_free (markup);
93                 g_free (checked_uri);
94         } else
95 #endif
96                 gtk_label_set_text (GTK_LABEL (label), uri);
97
98         return label;
99 }
100
101 static void
102 ev_properties_license_add_section (EvPropertiesLicense *properties,
103                                    const gchar         *title_text,
104                                    GtkWidget           *contents)
105 {
106         GtkWidget *title;
107         GtkWidget *alignment;
108         gchar     *markup;
109
110         title = gtk_label_new (NULL);
111         gtk_misc_set_alignment (GTK_MISC (title), 0.0, 0.5);
112         gtk_label_set_use_markup (GTK_LABEL (title), TRUE);
113         markup = g_strdup_printf ("<b>%s</b>", title_text);
114         gtk_label_set_markup (GTK_LABEL (title), markup);
115         g_free (markup);
116         gtk_box_pack_start (GTK_BOX (properties), title, FALSE, FALSE, 0);
117         gtk_widget_show (title);
118
119         alignment = gtk_alignment_new (0.5, 0.5, 1., 1.);
120         gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
121         gtk_container_add (GTK_CONTAINER (alignment), contents);
122         gtk_widget_show (contents);
123
124         gtk_box_pack_start (GTK_BOX (properties), alignment, FALSE, TRUE, 0);
125         gtk_widget_show (alignment);
126 }
127
128 void
129 ev_properties_license_set_license (EvPropertiesLicense *properties,
130                                    EvDocumentLicense   *license)
131 {
132         const gchar *text = ev_document_license_get_text (license);
133         const gchar *uri = ev_document_license_get_uri (license);
134         const gchar *web_statement = ev_document_license_get_web_statement (license);
135
136         if (text) {
137                 ev_properties_license_add_section (properties,
138                                                    _("Usage terms"),
139                                                    get_license_text_widget (license));
140         }
141
142         if (uri) {
143                 ev_properties_license_add_section (properties,
144                                                    _("Text License"),
145                                                    get_license_uri_widget (uri));
146         }
147
148         if (web_statement) {
149                 ev_properties_license_add_section (properties,
150                                                    _("Further Information"),
151                                                    get_license_uri_widget (web_statement));
152         }
153 }
154
155 static void
156 ev_properties_license_init (EvPropertiesLicense *properties)
157 {
158         gtk_box_set_spacing (GTK_BOX (properties), 12);
159         gtk_container_set_border_width (GTK_CONTAINER (properties), 12);
160 }
161
162 GtkWidget *
163 ev_properties_license_new (void)
164 {
165         EvPropertiesLicense *properties_license;
166
167         properties_license = g_object_new (EV_TYPE_PROPERTIES_LICENSE, NULL);
168
169         return GTK_WIDGET (properties_license);
170 }