[gnome-control-center] color: Show the user a warning if they try to add a broken profile



commit 3b3b95a8a04d5d5a688648bac8b86c9a201b322c
Author: Richard Hughes <richard hughsie com>
Date:   Tue Nov 20 16:09:26 2012 +0000

    color: Show the user a warning if they try to add a broken profile
    
    Broken profiles are very common when the user imports canned profiles from vendors.

 panels/color/cc-color-panel.c |  130 ++++++++++++++++++++++++++++++++++------
 panels/color/color.ui         |   58 +++++++++++++++----
 2 files changed, 157 insertions(+), 31 deletions(-)
---
diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c
index 563fa47..fc8a659 100644
--- a/panels/color/cc-color-panel.c
+++ b/panels/color/cc-color-panel.c
@@ -67,6 +67,7 @@ enum {
   GCM_PREFS_COMBO_COLUMN_TEXT,
   GCM_PREFS_COMBO_COLUMN_PROFILE,
   GCM_PREFS_COMBO_COLUMN_TYPE,
+  GCM_PREFS_COMBO_COLUMN_WARNING_FILENAME,
   GCM_PREFS_COMBO_COLUMN_NUM_COLUMNS
 };
 
@@ -90,6 +91,10 @@ gcm_prefs_combobox_add_profile (CcColorPanel *prefs,
   GtkListStore *list_store;
   gchar *escaped = NULL;
   guint kind = 0;
+  const gchar *warning = NULL;
+#if CD_CHECK_VERSION(0,1,25)
+  gchar **warnings;
+#endif
 
   /* iter is optional */
   if (iter == NULL)
@@ -125,6 +130,13 @@ gcm_prefs_combobox_add_profile (CcColorPanel *prefs,
     }
 #endif
 
+  /* is the profile faulty */
+#if CD_CHECK_VERSION(0,1,25)
+  warnings = cd_profile_get_warnings (profile);
+  if (warnings != NULL && warnings[0] != NULL)
+    warning = "dialog-warning-symbolic";
+#endif
+
   escaped = g_markup_escape_text (string->str, -1);
   list_store = GTK_LIST_STORE(gtk_builder_get_object (prefs->priv->builder,
                                                       "liststore_assign"));
@@ -133,6 +145,7 @@ gcm_prefs_combobox_add_profile (CcColorPanel *prefs,
                       GCM_PREFS_COMBO_COLUMN_TEXT, escaped,
                       GCM_PREFS_COMBO_COLUMN_PROFILE, profile,
                       GCM_PREFS_COMBO_COLUMN_TYPE, kind,
+                      GCM_PREFS_COMBO_COLUMN_WARNING_FILENAME, warning,
                       -1);
 
   g_string_free (string, TRUE);
@@ -596,31 +609,14 @@ out:
 }
 
 static void
-gcm_prefs_profile_view_cb (GtkWidget *widget, CcColorPanel *prefs)
+gcm_prefs_profile_view (CcColorPanel *prefs, CdProfile *profile)
 {
-  CdProfile *profile = NULL;
-  GtkTreeIter iter;
-  GtkTreeModel *model;
-  GtkTreeSelection *selection;
-  gchar *options = NULL;
   GPtrArray *argv = NULL;
   guint xid;
   gboolean ret;
   GError *error = NULL;
   CcColorPanelPrivate *priv = prefs->priv;
 
-  /* get the selected row */
-  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
-                                               "treeview_devices"));
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
-  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
-    g_assert_not_reached ();
-
-  /* get currentlt selected item */
-  gtk_tree_model_get (model, &iter,
-                      GCM_PREFS_COLUMN_PROFILE, &profile,
-                      -1);
-
   /* get xid */
   xid = gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (priv->main_window)));
 
@@ -641,12 +637,70 @@ gcm_prefs_profile_view_cb (GtkWidget *widget, CcColorPanel *prefs)
     }
 
   g_ptr_array_unref (argv);
-  g_free (options);
+}
+
+static void
+gcm_prefs_profile_assign_link_activate_cb (GtkLabel *label,
+                                           const gchar *uri,
+                                           CcColorPanel *prefs)
+{
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  CdProfile *profile = NULL;
+  GtkTreeSelection *selection;
+  CcColorPanelPrivate *priv = prefs->priv;
+  GtkWidget *widget;
+
+  /* get the selected profile */
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "treeview_assign"));
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    goto out;
+  gtk_tree_model_get (model, &iter,
+                      GCM_PREFS_COMBO_COLUMN_PROFILE, &profile,
+                      -1);
+  if (profile == NULL)
+    {
+        g_warning ("failed to get the active profile");
+        goto out;
+    }
+
+  /* show it in the viewer */
+  gcm_prefs_profile_view (prefs, profile);
+out:
   if (profile != NULL)
     g_object_unref (profile);
 }
 
 static void
+gcm_prefs_profile_view_cb (GtkWidget *widget, CcColorPanel *prefs)
+{
+  CdProfile *profile = NULL;
+  GtkTreeIter iter;
+  GtkTreeModel *model;
+  GtkTreeSelection *selection;
+  CcColorPanelPrivate *priv = prefs->priv;
+
+  /* get the selected row */
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "treeview_devices"));
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
+    g_assert_not_reached ();
+
+  /* get currentlt selected item */
+  gtk_tree_model_get (model, &iter,
+                      GCM_PREFS_COLUMN_PROFILE, &profile,
+                      -1);
+
+  /* open up gcm-viewer as a info pane */
+  gcm_prefs_profile_view (prefs, profile);
+
+  g_object_unref (profile);
+}
+
+static void
 gcm_prefs_button_assign_cancel_cb (GtkWidget *widget, CcColorPanel *prefs)
 {
   CcColorPanelPrivate *priv = prefs->priv;
@@ -840,6 +894,15 @@ gcm_prefs_add_profiles_columns (CcColorPanel *prefs,
                                       "markup", GCM_PREFS_COMBO_COLUMN_TEXT);
   gtk_tree_view_column_set_expand (column, TRUE);
   gtk_tree_view_append_column (treeview, column);
+
+  /* image */
+  column = gtk_tree_view_column_new ();
+  renderer = gtk_cell_renderer_pixbuf_new ();
+  g_object_set (renderer, "stock-size", GTK_ICON_SIZE_MENU, NULL);
+  gtk_tree_view_column_pack_start (column, renderer, FALSE);
+  gtk_tree_view_column_add_attribute (column, renderer,
+                                      "icon-name", GCM_PREFS_COMBO_COLUMN_WARNING_FILENAME);
+  gtk_tree_view_append_column (treeview, column);
 }
 
 static void
@@ -1004,15 +1067,36 @@ gcm_prefs_profiles_treeview_clicked_cb (GtkTreeSelection *selection,
                                         CcColorPanel *prefs)
 {
   GtkWidget *widget;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  CdProfile *profile = NULL;
+#if CD_CHECK_VERSION(0,1,25)
+  gchar **warnings;
+#endif
 
   /* get selection */
-  if (!gtk_tree_selection_get_selected (selection, NULL, NULL))
+  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
     return;
+  gtk_tree_model_get (model, &iter,
+                      GCM_PREFS_COMBO_COLUMN_PROFILE, &profile,
+                      -1);
+
 
   /* as soon as anything is selected, make the Add button sensitive */
   widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
                                                "button_assign_ok"));
   gtk_widget_set_sensitive (widget, TRUE);
+
+  /* is the profile faulty */
+  widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder,
+                                               "label_assign_warning"));
+#if CD_CHECK_VERSION(0,1,25)
+  warnings = cd_profile_get_warnings (profile);
+  gtk_widget_set_visible (widget, warnings != NULL && warnings[0] != NULL);
+#else
+  gtk_widget_set_visible (widget, FALSE);
+#endif
+  g_object_unref (profile);
 }
 
 static void
@@ -2359,6 +2443,12 @@ cc_color_panel_init (CcColorPanel *prefs)
   g_signal_connect (widget, "clicked",
                     G_CALLBACK (gcm_prefs_profile_view_cb), prefs);
 
+  /* href */
+  widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                               "label_assign_warning"));
+  g_signal_connect (widget, "activate-link",
+                    G_CALLBACK (gcm_prefs_profile_assign_link_activate_cb), prefs);
+
   /* create device tree view */
   widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
                                                "treeview_devices"));
diff --git a/panels/color/color.ui b/panels/color/color.ui
index 7b90a41..b1f07ee 100644
--- a/panels/color/color.ui
+++ b/panels/color/color.ui
@@ -324,24 +324,52 @@
           </packing>
         </child>
         <child>
-          <object class="GtkScrolledWindow" id="scrolledwindow_assign">
+          <object class="GtkBox" id="box1">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
+            <property name="can_focus">False</property>
             <property name="border_width">5</property>
-            <property name="hscrollbar_policy">never</property>
-            <property name="shadow_type">in</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
             <child>
-              <object class="GtkTreeView" id="treeview_assign">
+              <object class="GtkScrolledWindow" id="scrolledwindow_assign">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="model">liststore_assign</property>
-                <property name="headers_visible">False</property>
-                <property name="enable_search">False</property>
-                <property name="search_column">0</property>
-                <child internal-child="selection">
-                  <object class="GtkTreeSelection" id="treeview-selection2"/>
+                <property name="hscrollbar_policy">never</property>
+                <property name="shadow_type">in</property>
+                <child>
+                  <object class="GtkTreeView" id="treeview_assign">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="model">liststore_assign</property>
+                    <property name="headers_visible">False</property>
+                    <property name="enable_search">False</property>
+                    <property name="search_column">0</property>
+                    <child internal-child="selection">
+                      <object class="GtkTreeSelection" id="treeview-selection2"/>
+                    </child>
+                  </object>
                 </child>
               </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label_assign_warning">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Problems detected. The profile may not work correctly. &lt;a href=""&gt;Show details.&lt;/a&gt;</property>
+                <property name="use_markup">True</property>
+                <property name="wrap">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
             </child>
           </object>
           <packing>
@@ -616,8 +644,16 @@
       <column type="GObject"/>
       <!-- column-name kind -->
       <column type="guint"/>
+      <!-- column-name warningfn -->
+      <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkSizeGroup" id="sizegroup_assign">
+    <widgets>
+      <widget name="label_assign_warning"/>
+      <widget name="scrolledwindow_assign"/>
+    </widgets>
+  </object>
   <object class="GtkSizeGroup" id="sizegroup_buttons"/>
   <object class="GtkSizeGroup" id="sizegroup_combos"/>
   <object class="GtkSizeGroup" id="sizegroup_defaults"/>



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