[evince] Properties: Do not add more license unconditionally



commit 26301e1974d9d2aba4df2e7a960e30190e8183d1
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Mon Jul 9 13:07:00 2018 -0400

    Properties: Do not add more license unconditionally
    
    When the property dialog is open and the document changes,
    check if the license widgets are in place before adding new
    ones.
    
    Fixes #780

 shell/ev-properties-license.c | 83 +++++++++++++++++++++++++++++--------------
 1 file changed, 56 insertions(+), 27 deletions(-)
---
diff --git a/shell/ev-properties-license.c b/shell/ev-properties-license.c
index e681b3df..2c9c754e 100644
--- a/shell/ev-properties-license.c
+++ b/shell/ev-properties-license.c
@@ -30,6 +30,10 @@
 
 struct _EvPropertiesLicense {
        GtkBox base_instance;
+
+       GtkWidget *license;
+       GtkWidget *uri;
+       GtkWidget *web_statement;
 };
 
 struct _EvPropertiesLicenseClass {
@@ -46,7 +50,7 @@ ev_properties_license_class_init (EvPropertiesLicenseClass *properties_license_c
 static GtkWidget *
 get_license_text_widget (EvDocumentLicense *license)
 {
-       GtkWidget *swindow, *textview;
+       GtkWidget     *textview;
        GtkTextBuffer *buffer;
 
        textview = gtk_text_view_new ();
@@ -56,22 +60,33 @@ get_license_text_widget (EvDocumentLicense *license)
 
        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_shadow_type (GTK_SCROLLED_WINDOW (swindow),
-                                            GTK_SHADOW_IN);
-       gtk_container_add (GTK_CONTAINER (swindow), textview);
        gtk_widget_show (textview);
 
-       return swindow;
+       return textview;
+}
+
+static void
+set_uri_to_label (GtkLabel    *label,
+                 const gchar *uri)
+{
+       gchar     *checked_uri;
+       gchar     *markup;
+
+       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 (label, markup);
+               g_free (markup);
+               g_free (checked_uri);
+       } else {
+               gtk_label_set_text (label, uri);
+       }
 }
 
 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),
@@ -81,15 +96,7 @@ get_license_uri_widget (const gchar *uri)
                      "ellipsize", PANGO_ELLIPSIZE_END,
                      NULL);
 
-       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 {
-               gtk_label_set_text (GTK_LABEL (label), uri);
-       }
+       set_uri_to_label (GTK_LABEL (label), uri);
 
        return label;
 }
@@ -128,23 +135,45 @@ ev_properties_license_set_license (EvPropertiesLicense *properties,
        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);
+       GtkTextBuffer *buffer;
+       GtkWidget     *swindow;
 
        if (text) {
-               ev_properties_license_add_section (properties,
-                                                  _("Usage terms"),
-                                                  get_license_text_widget (license));
+               if (!properties->license) {
+                       properties->license = get_license_text_widget (license);
+                       swindow = gtk_scrolled_window_new (NULL, NULL);
+                       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
+                                                            GTK_SHADOW_IN);
+                       gtk_container_add (GTK_CONTAINER (swindow), properties->license);
+                       ev_properties_license_add_section (properties,
+                                                          _("Usage terms"),
+                                                          swindow);
+               } else {
+                       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (properties->license));
+                       gtk_text_buffer_set_text (buffer, text, -1);
+               }
        }
 
        if (uri) {
-               ev_properties_license_add_section (properties,
-                                                  _("Text License"),
-                                                  get_license_uri_widget (uri));
+               if (!properties->uri) {
+                       properties->uri = get_license_uri_widget (uri);
+                       ev_properties_license_add_section (properties,
+                                                          _("Text License"),
+                                                          properties->uri);
+               } else {
+                       set_uri_to_label (GTK_LABEL (properties->uri), uri);
+               }
        }
 
        if (web_statement) {
-               ev_properties_license_add_section (properties,
-                                                  _("Further Information"),
-                                                  get_license_uri_widget (web_statement));
+               if (!properties->web_statement) {
+                       properties->web_statement = get_license_uri_widget (web_statement);
+                       ev_properties_license_add_section (properties,
+                                                          _("Further Information"),
+                                                          properties->web_statement);
+               } else {
+                       set_uri_to_label (GTK_LABEL (properties->web_statement), web_statement);
+               }
        }
 }
 


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