[gnome-keyring] [gcr] Partial implementation of data for tree columns.



commit ddffc3ec8456f100906fb50fad3a548b6d0b7a0a
Author: Stef Walter <stef memberwebs com>
Date:   Sun Oct 17 00:15:02 2010 +0000

    [gcr] Partial implementation of data for tree columns.

 gcr/gcr-certificate-renderer.c |   42 ++++++++++++++++++++--
 gcr/gcr-certificate-renderer.h |    5 +++
 gcr/gcr-collection-model.c     |   24 ++++++++-----
 gcr/gcr-collection-model.h     |   13 ++-----
 gcr/gcr-column.h               |   40 +++++++++++++++++++++
 gcr/gcr-renderer.c             |   21 +++++++++++
 gcr/gcr-renderer.h             |   34 ++++++++---------
 gcr/tests/test-ui-selector.c   |   77 +++++++++++++++++++++++++++++++--------
 8 files changed, 200 insertions(+), 56 deletions(-)
---
diff --git a/gcr/gcr-certificate-renderer.c b/gcr/gcr-certificate-renderer.c
index 592b69b..8b923c0 100644
--- a/gcr/gcr-certificate-renderer.c
+++ b/gcr/gcr-certificate-renderer.c
@@ -45,7 +45,10 @@ enum {
 	PROP_ATTRIBUTES,
 	PROP_DESCRIPTION,
 	PROP_ICON,
-	PROP_MARKUP
+	PROP_MARKUP,
+	PROP_SUBJECT,
+	PROP_ISSUER,
+	PROP_EXPIRY
 };
 
 struct _GcrCertificateRendererPrivate {
@@ -349,6 +352,15 @@ gcr_certificate_renderer_get_property (GObject *obj, guint prop_id, GValue *valu
 	case PROP_MARKUP:
 		g_value_take_string (value, calculate_markup (self));
 		break;
+	case PROP_SUBJECT:
+		g_value_take_string (value, gcr_certificate_get_subject_cn (GCR_CERTIFICATE (self)));
+		break;
+	case PROP_ISSUER:
+		g_value_take_string (value, gcr_certificate_get_issuer_cn (GCR_CERTIFICATE (self)));
+		break;
+	case PROP_EXPIRY:
+		g_value_take_boxed (value, gcr_certificate_get_expiry_date (GCR_CERTIFICATE (self)));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
 		break;
@@ -370,9 +382,21 @@ gcr_certificate_renderer_class_init (GcrCertificateRendererClass *klass)
 	gobject_class->get_property = gcr_certificate_renderer_get_property;
 
 	g_object_class_install_property (gobject_class, PROP_CERTIFICATE,
-	           g_param_spec_object("certificate", "Certificate", "Certificate to display.",
+	           g_param_spec_object ("certificate", "Certificate", "Certificate to display.",
 	                               GCR_TYPE_CERTIFICATE, G_PARAM_READWRITE));
 
+	g_object_class_install_property (gobject_class, PROP_CERTIFICATE,
+	           g_param_spec_string ("subject", "Subject", "Common name of subject",
+	                                "", G_PARAM_READABLE));
+
+	g_object_class_install_property (gobject_class, PROP_CERTIFICATE,
+	           g_param_spec_string ("issuer", "Issuer", "Common name of issuer",
+	                                "", G_PARAM_READABLE));
+
+	g_object_class_install_property (gobject_class, PROP_CERTIFICATE,
+	           g_param_spec_boxed ("expiry", "Expiry", "Certificate expiry",
+	                               G_TYPE_DATE, G_PARAM_READABLE));
+
 	g_object_class_override_property (gobject_class, PROP_LABEL, "label");
 	g_object_class_override_property (gobject_class, PROP_ATTRIBUTES, "attributes");
 	g_object_class_override_property (gobject_class, PROP_DESCRIPTION, "description");
@@ -578,11 +602,23 @@ gcr_certificate_renderer_populate_popup (GcrRenderer *self, GcrViewer *viewer,
 static void
 gcr_renderer_iface_init (GcrRendererIface *iface)
 {
+	static GcrModelColumn columns[] = {
+		{ "expiry", /* Below */ 0, N_("Expires"), 0 },
+		{ "label", G_TYPE_STRING, N_("Name"), 0 },
+		{ "description", G_TYPE_STRING, N_("Type"), 0 },
+		{ "subject", G_TYPE_STRING, N_("Subject"), 0 },
+		{ "issuer", G_TYPE_STRING, N_("Issued By"), 0 },
+		{ NULL }
+	};
+
+	/* Not constant so fill it in here */
+	columns[0].type = G_TYPE_DATE;
+
 	iface->populate_popup = gcr_certificate_renderer_populate_popup;
 	iface->render_view = gcr_certificate_renderer_render;
+	iface->column_info = columns;
 }
 
-
 static gconstpointer
 gcr_certificate_renderer_real_get_der_data (GcrCertificate *cert, gsize *n_data)
 {
diff --git a/gcr/gcr-certificate-renderer.h b/gcr/gcr-certificate-renderer.h
index df84072..ff58ce3 100644
--- a/gcr/gcr-certificate-renderer.h
+++ b/gcr/gcr-certificate-renderer.h
@@ -28,10 +28,13 @@
 #include <gtk/gtk.h>
 
 #include "gcr-certificate.h"
+#include "gcr-renderer.h"
 #include "gcr-types.h"
 
 G_BEGIN_DECLS
 
+#define GCR_TYPE_CERTIFICATE_COLUMNS                (gcr_certificate_renderer_get_columns ())
+
 #define GCR_TYPE_CERTIFICATE_RENDERER               (gcr_certificate_renderer_get_type ())
 #define GCR_CERTIFICATE_RENDERER(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_CERTIFICATE_RENDERER, GcrCertificateRenderer))
 #define GCR_CERTIFICATE_RENDERER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GCR_TYPE_CERTIFICATE_RENDERER, GcrCertificateRendererClass))
@@ -54,6 +57,8 @@ struct _GcrCertificateRendererClass {
 
 GType                     gcr_certificate_renderer_get_type           (void);
 
+const GcrModelColumn*     gcr_certificate_renderer_get_columns        (void);
+
 GcrCertificateRenderer*   gcr_certificate_renderer_new                (GcrCertificate *cert);
 
 GcrCertificateRenderer*   gcr_certificate_renderer_new_for_attributes (const gchar *label,
diff --git a/gcr/gcr-collection-model.c b/gcr/gcr-collection-model.c
index 1eac064..db05bea 100644
--- a/gcr/gcr-collection-model.c
+++ b/gcr/gcr-collection-model.c
@@ -563,45 +563,51 @@ gcr_collection_model_class_init (GcrCollectionModelClass *klass)
 GcrCollectionModel*
 gcr_collection_model_new (GcrCollection *collection, ...)
 {
-	GcrCollectionModelColumn column;
+	GcrModelColumn column;
 	GcrCollectionModel *self;
 	const gchar *arg;
 	GArray *array;
 	va_list va;
 
-	array = g_array_new (TRUE, TRUE, sizeof (GcrCollectionModelColumn));
+	/* With a null terminator */
+	array = g_array_new (TRUE, TRUE, sizeof (GcrModelColumn));
 
 	va_start (va, collection);
 	while ((arg = va_arg (va, const gchar*)) != NULL) {
 		column.property = arg;
 		column.type = va_arg (va, GType);
-		column.data = NULL;
+		column.reserved = NULL;
+		column.label = NULL;
 		g_array_append_val (array, column);
 	}
 	va_end (va);
 
-	self = gcr_collection_model_new_full (collection, (GcrCollectionModelColumn*)array->data, array->len);
+	self = gcr_collection_model_new_full (collection, (GcrModelColumn*)array->data);
 	g_array_free (array, TRUE);
 	return self;
 }
 
 GcrCollectionModel*
-gcr_collection_model_new_full (GcrCollection *collection, const GcrCollectionModelColumn *columns, guint n_columns)
+gcr_collection_model_new_full (GcrCollection *collection, const GcrModelColumn *columns)
 {
 	GcrCollectionModel *self = g_object_new (GCR_TYPE_COLLECTION_MODEL, "collection", collection, NULL);
-	gcr_collection_model_set_columns (self, columns, n_columns);
+	gcr_collection_model_set_columns (self, columns);
 	return self;
 }
 
 gint
-gcr_collection_model_set_columns (GcrCollectionModel *self, const GcrCollectionModelColumn *columns,
-                                  guint n_columns)
+gcr_collection_model_set_columns (GcrCollectionModel *self, const GcrModelColumn *columns)
 {
-	guint i;
+	const GcrModelColumn *col;
+	guint i, n_columns;
 
 	g_return_val_if_fail (GCR_IS_COLLECTION_MODEL (self), -1);
 	g_return_val_if_fail (self->pv->n_columns == 0, -1);
 
+	/* Count the number of columns */
+	for (col = columns, n_columns = 0; col->property; ++col)
+		++n_columns;
+
 	self->pv->column_names = g_new0 (gchar*, n_columns + 1);
 	self->pv->column_types = g_new0 (GType, n_columns + 1);
 	self->pv->n_columns = n_columns;
diff --git a/gcr/gcr-collection-model.h b/gcr/gcr-collection-model.h
index 60a5754..fb750d2 100644
--- a/gcr/gcr-collection-model.h
+++ b/gcr/gcr-collection-model.h
@@ -25,12 +25,7 @@
 #include <gtk/gtk.h>
 
 #include "gcr-collection.h"
-
-typedef struct _GcrCollectionModelColumn {
-	const gchar *property;
-	GType type;
-	gpointer data;
-} GcrCollectionModelColumn;
+#include "gcr-column.h"
 
 #define GCR_TYPE_COLLECTION_MODEL               (gcr_collection_model_get_type ())
 #define GCR_COLLECTION_MODEL(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_COLLECTION_MODEL, GcrCollectionModel))
@@ -59,12 +54,10 @@ GcrCollectionModel*   gcr_collection_model_new                 (GcrCollection *c
                                                                 ...) G_GNUC_NULL_TERMINATED;
 
 GcrCollectionModel*   gcr_collection_model_new_full            (GcrCollection *collection,
-                                                                const GcrCollectionModelColumn *columns,
-                                                                guint n_columns);
+                                                                const GcrModelColumn *columns);
 
 gint                  gcr_collection_model_set_columns         (GcrCollectionModel *self,
-                                                                const GcrCollectionModelColumn *columns,
-                                                                guint n_columns);
+                                                                const GcrModelColumn *columns);
 
 GObject*              gcr_collection_model_object_for_iter     (GcrCollectionModel *self,
                                                                 const GtkTreeIter *iter);
diff --git a/gcr/gcr-column.h b/gcr/gcr-column.h
new file mode 100644
index 0000000..ce26da7
--- /dev/null
+++ b/gcr/gcr-column.h
@@ -0,0 +1,40 @@
+/*
+ * gnome-keyring
+ *
+ * Copyright (C) 2010 Stefan Walter
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef __GCR_COLUMN_H__
+#define __GCR_COLUMN_H__
+
+#include "gcr-types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GcrModelColumn {
+	const gchar *property;
+	GType type;
+	const gchar *label;
+	gpointer reserved;
+} GcrModelColumn;
+
+G_END_DECLS
+
+#endif /* __GCR_COLUMN_H__ */
diff --git a/gcr/gcr-renderer.c b/gcr/gcr-renderer.c
index cbc8bbc..46afac1 100644
--- a/gcr/gcr-renderer.c
+++ b/gcr/gcr-renderer.c
@@ -188,3 +188,24 @@ gcr_renderer_register (GType renderer_type, GckAttributes *attrs)
 	g_array_append_val (registered_renderers, registered);
 	registered_sorted = FALSE;
 }
+
+const GcrModelColumn*
+gcr_renderer_columns (GType renderer_type)
+{
+	const GcrModelColumn *columns;
+	GcrRendererIface *renderer;
+	GTypeClass *klass;
+
+	klass = g_type_class_ref (renderer_type);
+	g_return_val_if_fail (klass, NULL);
+
+	renderer = g_type_interface_peek (klass, GCR_TYPE_RENDERER);
+	g_return_val_if_fail (renderer, NULL);
+
+	columns = renderer->column_info;
+	g_return_val_if_fail (columns, NULL);
+
+	g_type_class_unref (klass);
+
+	return columns;
+}
diff --git a/gcr/gcr-renderer.h b/gcr/gcr-renderer.h
index e2e9234..2676dd2 100644
--- a/gcr/gcr-renderer.h
+++ b/gcr/gcr-renderer.h
@@ -24,6 +24,7 @@
 
 #include <glib-object.h>
 
+#include "gcr-column.h"
 #include "gcr-types.h"
 #include "gcr-viewer.h"
 
@@ -35,24 +36,25 @@ G_BEGIN_DECLS
 #define GCR_RENDERER_GET_INTERFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GCR_TYPE_RENDERER, GcrRendererIface))
 
 typedef struct _GcrRendererIface GcrRendererIface;
-typedef struct _GcrRendererColumn GcrRendererColumn;
 
 struct _GcrRendererIface {
 	GTypeInterface parent;
 
+	/* data */
+	const GcrModelColumn *column_info;
+
 	/* signals */
 	void (*data_changed) (GcrRenderer *self);
 
 	/* virtual */
 	void (*render_view) (GcrRenderer *self, GcrViewer *viewer);
 
-	const GcrRendererColumn* (*get_column_info) (GcrRenderer *self, gint *n_columns);
-
 	const void (*get_column_value) (GcrRenderer *self, GQuark column, GValue *value);
 
 	void (*populate_popup) (GcrRenderer *self, GcrViewer *viewer, GtkMenu *menu);
 
 	gpointer dummy1;
+
 	gpointer dummy2;
 	gpointer dummy3;
 	gpointer dummy4;
@@ -62,33 +64,29 @@ struct _GcrRendererIface {
 
 };
 
-struct _GcrRendererColumn {
-	GQuark column;
-	GType type;
-	const gchar *description;
-};
-
-GType                  gcr_renderer_get_type                      (void) G_GNUC_CONST;
+GType                     gcr_renderer_get_type                   (void) G_GNUC_CONST;
 
-void                   gcr_renderer_render_view                   (GcrRenderer *self,
+void                      gcr_renderer_render_view                (GcrRenderer *self,
                                                                    GcrViewer *viewer);
 
-void                   gcr_renderer_popuplate_popup               (GcrRenderer *self,
+void                      gcr_renderer_popuplate_popup            (GcrRenderer *self,
                                                                    GcrViewer *viewer,
                                                                    GtkMenu *menu);
 
-gchar*                 gcr_renderer_get_markup                    (GcrRenderer *self);
+gchar*                    gcr_renderer_get_markup                 (GcrRenderer *self);
 
-gchar*                 gcr_renderer_get_description               (GcrRenderer *self);
+gchar*                    gcr_renderer_get_description            (GcrRenderer *self);
 
-gchar*                 gcr_renderer_get_stock_icon                (GcrRenderer *self);
+gchar*                    gcr_renderer_get_stock_icon             (GcrRenderer *self);
 
-void                   gcr_renderer_emit_data_changed             (GcrRenderer *self);
+void                      gcr_renderer_emit_data_changed          (GcrRenderer *self);
 
-GcrRenderer*           gcr_renderer_create                        (const gchar *label,
+GcrRenderer*              gcr_renderer_create                     (const gchar *label,
                                                                    GckAttributes *attrs);
 
-void                   gcr_renderer_register                      (GType renderer_type,
+const GcrModelColumn*     gcr_renderer_columns                    (GType renderer_type);
+
+void                      gcr_renderer_register                   (GType renderer_type,
                                                                    GckAttributes *attrs);
 
 G_END_DECLS
diff --git a/gcr/tests/test-ui-selector.c b/gcr/tests/test-ui-selector.c
index d6933d5..a9e717e 100644
--- a/gcr/tests/test-ui-selector.c
+++ b/gcr/tests/test-ui-selector.c
@@ -61,23 +61,14 @@ add_to_selector (GcrParser *parser, const gchar *path)
 	g_free (data);
 }
 
-int
-main (int argc, char *argv[])
+#if 1
+static void
+build_selector (GtkDialog *dialog, GcrCollection *collection)
 {
 	GcrCollectionModel *model;
-	GcrCollection *collection;
-	GtkDialog *dialog;
 	GtkWidget *combo;
 	GtkCellRenderer *cell;
-	GcrParser *parser;
-	int i;
-
-	gtk_init (&argc, &argv);
 
-	dialog = GTK_DIALOG (gtk_dialog_new ());
-	g_object_ref_sink (dialog);
-
-	collection = gcr_simple_collection_new ();
 	model = gcr_collection_model_new (collection,
 	                                  "icon", G_TYPE_ICON,
 	                                  "markup", G_TYPE_STRING,
@@ -96,6 +87,63 @@ main (int argc, char *argv[])
 	gtk_widget_show (GTK_WIDGET (combo));
 	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (dialog)), combo);
 
+	gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 400);
+	gtk_container_set_border_width (GTK_CONTAINER (dialog), 20);
+
+	g_object_unref (model);
+}
+#endif
+
+#if 0
+static void
+build_selector (GtkDialog *dialog, GcrCollection *collection)
+{
+	GcrCollectionModel *model;
+	const GcrModelColumn *columns;
+	GtkWidget *combo;
+	GtkCellRenderer *cell;
+
+	columns = gcr_renderer_columns (GCR_TYPE_CERTIFICATE_RENDERER);
+	model = gcr_collection_model_new_full (collection, columns);
+
+	gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
+
+	combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (model));
+	cell = gtk_cell_renderer_pixbuf_new ();
+	g_object_set (cell, "stock-size", GTK_ICON_SIZE_DND, NULL);
+	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, FALSE);
+	gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cell, "gicon", 0);
+
+	cell = gtk_cell_renderer_text_new ();
+	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
+	gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), cell, "markup", 1);
+
+	gtk_widget_show (GTK_WIDGET (combo));
+	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (dialog)), combo);
+
+	gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 400);
+	gtk_container_set_border_width (GTK_CONTAINER (dialog), 20);
+
+	g_object_unref (model);
+}
+#endif
+
+int
+main (int argc, char *argv[])
+{
+	GcrCollection *collection;
+	GtkDialog *dialog;
+	GcrParser *parser;
+	int i;
+
+	gtk_init (&argc, &argv);
+
+	dialog = GTK_DIALOG (gtk_dialog_new ());
+	g_object_ref_sink (dialog);
+
+	collection = gcr_simple_collection_new ();
+	build_selector (dialog, collection);
+
 #if 0
 	{
 		GtkWidget *widget = gtk_file_chooser_button_new ("Tester", GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
@@ -104,9 +152,6 @@ main (int argc, char *argv[])
 	}
 #endif
 
-	gtk_window_set_default_size (GTK_WINDOW (dialog), 550, 400);
-	gtk_container_set_border_width (GTK_CONTAINER (dialog), 20);
-
 	parser = gcr_parser_new ();
 	g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), collection);
 
@@ -119,10 +164,10 @@ main (int argc, char *argv[])
 	}
 
 	g_object_unref (parser);
+	g_object_unref (collection);
 
 	gtk_dialog_run (dialog);
 	gtk_widget_destroy (GTK_WIDGET (dialog));
-
 	g_object_unref (dialog);
 
 	return 0;



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