[gnome-color-manager] Add a metadata tab to gcm-viewer to display all the color geek information



commit 86c89d45b968bd4aad96c35969c36e09465e840e
Author: Richard Hughes <richard hughsie com>
Date:   Tue May 3 14:55:57 2011 +0100

    Add a metadata tab to gcm-viewer to display all the color geek information

 data/gcm-viewer.ui |   60 +++++++++++++++++++++++++++++-
 src/gcm-viewer.c   |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 164 insertions(+), 2 deletions(-)
---
diff --git a/data/gcm-viewer.ui b/data/gcm-viewer.ui
index 4cc5945..efa45c3 100644
--- a/data/gcm-viewer.ui
+++ b/data/gcm-viewer.ui
@@ -1389,8 +1389,10 @@
                               <object class="GtkTreeView" id="treeview_named_colors">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="model">liststore_named_colors</property>
                                 <property name="headers_visible">False</property>
+                                <child internal-child="selection">
+                                  <object class="GtkTreeSelection" id="treeview-selection2"/>
+                                </child>
                               </object>
                             </child>
                           </object>
@@ -1447,6 +1449,62 @@
                     <property name="tab_fill">False</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkVBox" id="vbox_metadata">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="border_width">9</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkScrolledWindow" id="scrolledwindow_metadata">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="shadow_type">in</property>
+                        <child>
+                          <object class="GtkTreeView" id="treeview_metadata">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="headers_visible">False</property>
+                            <child internal-child="selection">
+                              <object class="GtkTreeSelection" id="treeview-selection4"/>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label23">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Metadata is additional information stored in the profile for programs to use.</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">8</property>
+                  </packing>
+                </child>
+                <child type="tab">
+                  <object class="GtkLabel" id="label22">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Metadata</property>
+                  </object>
+                  <packing>
+                    <property name="position">8</property>
+                    <property name="tab_fill">False</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">True</property>
diff --git a/src/gcm-viewer.c b/src/gcm-viewer.c
index fa1645a..980141c 100644
--- a/src/gcm-viewer.c
+++ b/src/gcm-viewer.c
@@ -64,6 +64,7 @@ typedef struct {
 	gchar		*profile_id;
 	guint		 xid;
 	GtkListStore	*liststore_nc;
+	GtkListStore	*liststore_metadata;
 } GcmViewerPrivate;
 
 typedef enum {
@@ -83,6 +84,12 @@ enum {
 };
 
 enum {
+	GCM_METADATA_COLUMN_KEY,
+	GCM_METADATA_COLUMN_VALUE,
+	GCM_METADATA_COLUMN_LAST
+};
+
+enum {
 	GCM_PROFILES_COLUMN_ID,
 	GCM_PROFILES_COLUMN_SORT,
 	GCM_PROFILES_COLUMN_ICON,
@@ -675,6 +682,58 @@ out:
 	return ret;
 }
 
+
+/**
+ * gcm_viewer_add_metadata:
+ **/
+static gboolean
+gcm_viewer_add_metadata (GcmViewerPrivate *viewer,
+			 CdProfile *profile)
+{
+	gboolean ret = FALSE;
+	GError *error = NULL;
+	GHashTable *metadata = NULL;
+	GList *keys = NULL;
+	GList *l;
+	GtkTreeIter iter;
+	const gchar *value;
+
+	/* clear existing */
+	gtk_list_store_clear (viewer->liststore_metadata);
+
+	/* get all the metadata entries */
+	metadata = cd_profile_get_metadata (profile);
+	if (metadata == NULL) {
+		g_warning ("failed to get metadata");
+		g_error_free (error);
+		goto out;
+	}
+
+	/* add items */
+	keys = g_hash_table_get_keys (metadata);
+	if (keys == NULL)
+		goto out;
+	for (l = keys; l != NULL; l = l->next) {
+		value = g_hash_table_lookup (metadata, l->data);
+		g_debug ("Adding '%s', '%s'",
+			 (const gchar *) l->data, value);
+		gtk_list_store_append (viewer->liststore_metadata, &iter);
+		gtk_list_store_set (viewer->liststore_metadata,
+				    &iter,
+				    GCM_METADATA_COLUMN_KEY, l->data,
+				    GCM_METADATA_COLUMN_VALUE, value,
+				    -1);
+	}
+
+	/* success */
+	ret = TRUE;
+out:
+	g_list_free (keys);
+	if (metadata != NULL)
+		g_hash_table_unref (metadata);
+	return ret;
+}
+
 /**
  * gcm_viewer_set_profile:
  **/
@@ -919,6 +978,11 @@ gcm_viewer_set_profile (GcmViewerPrivate *viewer, CdProfile *profile)
 	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_named_colors"));
 	gtk_widget_set_visible (widget, ret);
 
+	/* setup metadata tab */
+	ret = gcm_viewer_add_metadata (viewer, profile);
+	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_metadata"));
+	gtk_widget_set_visible (widget, ret);
+
 	/* set delete sensitivity */
 	ret = gcm_profile_get_can_delete (gcm_profile);
 	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "toolbutton_profile_delete"));
@@ -1058,7 +1122,8 @@ gcm_viewer_activate_cb (GApplication *application, GcmViewerPrivate *viewer)
 }
 
 static void
-gcm_viewer_add_named_colors_columns (GcmViewerPrivate *viewer, GtkTreeView *treeview)
+gcm_viewer_add_named_colors_columns (GcmViewerPrivate *viewer,
+				     GtkTreeView *treeview)
 {
 	GtkCellRenderer *renderer;
 	GtkTreeViewColumn *column;
@@ -1088,6 +1153,35 @@ gcm_viewer_add_named_colors_columns (GcmViewerPrivate *viewer, GtkTreeView *tree
 	gtk_tree_view_column_set_expand (column, FALSE);
 }
 
+static void
+gcm_viewer_add_metadata_columns (GcmViewerPrivate *viewer,
+				 GtkTreeView *treeview)
+{
+	GtkCellRenderer *renderer;
+	GtkTreeViewColumn *column;
+
+	/* column for text */
+	renderer = gtk_cell_renderer_text_new ();
+	g_object_set (renderer,
+		      "wrap-mode", PANGO_WRAP_WORD,
+		      NULL);
+	column = gtk_tree_view_column_new_with_attributes ("", renderer,
+							   "text", GCM_METADATA_COLUMN_KEY,
+							   NULL);
+	gtk_tree_view_column_set_sort_column_id (column, GCM_METADATA_COLUMN_KEY);
+	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (viewer->liststore_metadata),
+					      GCM_METADATA_COLUMN_KEY,
+					      GTK_SORT_ASCENDING);
+	gtk_tree_view_append_column (treeview, column);
+	gtk_tree_view_column_set_expand (column, FALSE);
+
+	column = gtk_tree_view_column_new_with_attributes ("", renderer,
+							   "text", GCM_METADATA_COLUMN_VALUE,
+							   NULL);
+	gtk_tree_view_append_column (treeview, column);
+	gtk_tree_view_column_set_expand (column, TRUE);
+}
+
 /**
  * gcm_viewer_named_color_treeview_clicked:
  **/
@@ -1218,6 +1312,16 @@ gcm_viewer_startup_cb (GApplication *application, GcmViewerPrivate *viewer)
 	g_signal_connect (selection, "changed",
 			  G_CALLBACK (gcm_viewer_named_color_treeview_clicked), viewer);
 
+	/* use metadata */
+	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder,
+						     "treeview_metadata"));
+	viewer->liststore_metadata = gtk_list_store_new (GCM_METADATA_COLUMN_LAST,
+							 G_TYPE_STRING,
+							 G_TYPE_STRING);
+	gtk_tree_view_set_model (GTK_TREE_VIEW (widget),
+				 GTK_TREE_MODEL (viewer->liststore_metadata));
+	gcm_viewer_add_metadata_columns (viewer, GTK_TREE_VIEW (widget));
+
 	/* use cie widget */
 	viewer->cie_widget = gcm_cie_widget_new ();
 	widget = GTK_WIDGET (gtk_builder_get_object (viewer->builder, "vbox_cie_widget"));



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