[gnome-control-center/T20818: 40/54] info: add link for license attribution document



commit 42640854bf67c0e6660c87491ec88eb00ce337e5
Author: Cosimo Cecchi <cosimo endlessm com>
Date:   Fri Jun 20 18:05:12 2014 -0700

    info: add link for license attribution document
    
    [endlessm/eos-shell#457]

 panels/info/cc-info-overview-panel.c |   71 ++++++++++++++++++++++++++++++++++
 panels/info/info-overview.ui         |   23 +++++++++++
 2 files changed, 94 insertions(+), 0 deletions(-)
---
diff --git a/panels/info/cc-info-overview-panel.c b/panels/info/cc-info-overview-panel.c
index 3af58be..49356ab 100644
--- a/panels/info/cc-info-overview-panel.c
+++ b/panels/info/cc-info-overview-panel.c
@@ -108,6 +108,76 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (CcInfoOverviewPanel, cc_info_overview_panel, CC_TYPE_PANEL)
 
+static gboolean
+on_attribution_label_link (GtkLabel            *label,
+                           gchar               *uri,
+                           CcInfoOverviewPanel *self)
+{
+  g_autoptr(GError) error = NULL;
+  const gchar * const * languages;
+  const gchar * const * data_dirs;
+  const gchar *language;
+  g_autofree gchar *pdf_uri = NULL;
+  g_autofree gchar *path = NULL;
+  gint i, j;
+  gboolean found = FALSE;
+
+  if (g_strcmp0 (uri, "attribution-link") != 0)
+    return FALSE;
+
+  data_dirs = g_get_system_data_dirs ();
+  languages = g_get_language_names ();
+  path = NULL;
+
+  for (i = 0; languages[i] != NULL; i++)
+    {
+      language = languages[i];
+
+      for (j = 0; data_dirs[j] != NULL; j++)
+        {
+          path = g_build_filename (data_dirs[j],
+                                   "eos-license-service",
+                                   "terms",
+                                   language,
+                                   "Endless-Terms-of-Use.pdf",
+                                   NULL);
+
+          if (g_file_test (path, G_FILE_TEST_EXISTS))
+            {
+              found = TRUE;
+              break;
+            }
+
+          g_free (path);
+          path = NULL;
+        }
+
+      if (found)
+        break;
+    }
+
+  if (!found)
+    {
+      g_warning ("Unable to find terms and conditions PDF on the system");
+      return TRUE;
+    }
+
+  pdf_uri = g_filename_to_uri (path, NULL, &error);
+
+  if (error)
+    {
+      g_warning ("Unable to construct terms and conditions PDF uri: %s", error->message);
+      return TRUE;
+    }
+
+  gtk_show_uri (NULL, pdf_uri, gtk_get_current_event_time (), &error);
+
+  if (error)
+    g_warning ("Unable to display terms and conditions PDF: %s", error->message);
+
+  return TRUE;
+}
+
 static void
 version_start_element_handler (GMarkupParseContext      *ctx,
                                const char               *element_name,
@@ -928,6 +998,7 @@ cc_info_overview_panel_class_init (CcInfoOverviewPanelClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, CcInfoOverviewPanel, label8);
   gtk_widget_class_bind_template_child_private (widget_class, CcInfoOverviewPanel, grid1);
   gtk_widget_class_bind_template_child_private (widget_class, CcInfoOverviewPanel, label18);
+  gtk_widget_class_bind_template_callback (widget_class, on_attribution_label_link);
 }
 
 static void
diff --git a/panels/info/info-overview.ui b/panels/info/info-overview.ui
index 219a83c..a0baa29 100644
--- a/panels/info/info-overview.ui
+++ b/panels/info/info-overview.ui
@@ -301,6 +301,29 @@
           </packing>
         </child>
         <child>
+          <object class="GtkLabel" id="attribution_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="use_markup">True</property>
+            <property name="xalign">0</property>
+            <property name="margin_left">22</property>
+            <property name="label" translatable="yes">&lt;a href='attribution-link'&gt;Endless Terms of 
Use&lt;/a&gt;</property>
+            <signal name="activate-link" handler="on_attribution_label_link" object="CcInfoOverviewPanel" 
swapped="no" />
+            <attributes>
+              <attribute name="scale" value="0.83"/>
+            </attributes>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+        <child>
           <object class="GtkButtonBox" id="hbuttonbox1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>


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