2
* Copyright (C) 2010 Stefan Walter
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as
6
* published by the Free Software Foundation; either version 2.1 of
7
* the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22
#include "gcr-certificate.h"
23
#include "gcr-certificate-renderer.h"
24
#include "gcr-certificate-widget.h"
25
#include "gcr-renderer.h"
26
#include "gcr-viewer.h"
31
#include <glib/gi18n-lib.h>
34
* SECTION:gcr-certificate-widget
35
* @title: GcrCertificateWidget
36
* @short_description: Certificate widget and renderer
38
* A #GcrCertificateWidget can be used to display a certificate. The widget
39
* is normally in a collapsed state showing only details, but can be expanded
42
* Use gcr_certificate_widget_new() to create a new certificate widget. Only
43
* one certificate can be displayed. A #GcrCertificateWidget contains a
44
* #GcrViewer internally and #GcrCertificateRenderer is used to render the
45
* certificate to the viewer. To show more than one certificate in a view,
46
* create the viewer and add renderers to it.
50
* GcrCertificateWidget:
52
* A widget that displays a certificate.
56
* GcrCertificateWidgetClass:
58
* The class for #GcrCertificateWidget
67
struct _GcrCertificateWidget {
70
GcrCertificateWidgetPrivate *pv;
73
struct _GcrCertificateWidgetClass {
75
GtkAlignmentClass parent_class;
78
struct _GcrCertificateWidgetPrivate {
80
GcrCertificateRenderer *renderer;
83
G_DEFINE_TYPE (GcrCertificateWidget, gcr_certificate_widget, GTK_TYPE_ALIGNMENT);
85
/* -----------------------------------------------------------------------------
90
gcr_certificate_widget_constructor (GType type, guint n_props, GObjectConstructParam *props)
92
GObject *obj = G_OBJECT_CLASS (gcr_certificate_widget_parent_class)->constructor (type, n_props, props);
93
GcrCertificateWidget *self = NULL;
95
g_return_val_if_fail (obj, NULL);
97
self = GCR_CERTIFICATE_WIDGET (obj);
99
self->pv->viewer = gcr_viewer_new_scrolled ();
100
gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->pv->viewer));
101
gtk_widget_show (GTK_WIDGET (self->pv->viewer));
103
gcr_viewer_add_renderer (self->pv->viewer, GCR_RENDERER (self->pv->renderer));
108
gcr_certificate_widget_init (GcrCertificateWidget *self)
110
self->pv = (G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_CERTIFICATE_WIDGET, GcrCertificateWidgetPrivate));
111
self->pv->renderer = gcr_certificate_renderer_new (NULL);
115
gcr_certificate_widget_finalize (GObject *obj)
117
GcrCertificateWidget *self = GCR_CERTIFICATE_WIDGET (obj);
119
g_assert (self->pv->renderer);
120
g_object_unref (self->pv->renderer);
121
self->pv->renderer = NULL;
123
g_assert (self->pv->viewer);
124
self->pv->viewer = NULL;
126
G_OBJECT_CLASS (gcr_certificate_widget_parent_class)->finalize (obj);
130
gcr_certificate_widget_set_property (GObject *obj, guint prop_id, const GValue *value,
133
GcrCertificateWidget *self = GCR_CERTIFICATE_WIDGET (obj);
136
case PROP_CERTIFICATE:
137
gcr_certificate_widget_set_certificate (self, g_value_get_object (value));
139
case PROP_ATTRIBUTES:
140
gcr_certificate_widget_set_attributes (self, g_value_get_boxed (value));
143
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
149
gcr_certificate_widget_get_property (GObject *obj, guint prop_id, GValue *value,
152
GcrCertificateWidget *self = GCR_CERTIFICATE_WIDGET (obj);
155
case PROP_CERTIFICATE:
156
g_value_set_object (value, gcr_certificate_widget_get_certificate (self));
158
case PROP_ATTRIBUTES:
159
g_value_set_boxed (value, gcr_certificate_widget_get_attributes (self));
162
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
168
gcr_certificate_widget_class_init (GcrCertificateWidgetClass *klass)
170
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
172
gcr_certificate_widget_parent_class = g_type_class_peek_parent (klass);
173
g_type_class_add_private (klass, sizeof (GcrCertificateWidgetPrivate));
175
gobject_class->constructor = gcr_certificate_widget_constructor;
176
gobject_class->finalize = gcr_certificate_widget_finalize;
177
gobject_class->set_property = gcr_certificate_widget_set_property;
178
gobject_class->get_property = gcr_certificate_widget_get_property;
180
g_object_class_install_property (gobject_class, PROP_CERTIFICATE,
181
g_param_spec_object("certificate", "Certificate", "Certificate to display.",
182
GCR_TYPE_CERTIFICATE, G_PARAM_READWRITE));
184
g_object_class_install_property (gobject_class, PROP_ATTRIBUTES,
185
g_param_spec_boxed ("attributes", "Attributes", "Attributes which contain the certificate",
186
GCK_TYPE_ATTRIBUTES, G_PARAM_READWRITE));
189
/* -----------------------------------------------------------------------------
194
* gcr_certificate_widget_new:
195
* @certificate: (allow-none): certificate to display, or %NULL
197
* Create a new certificate widget which displays a given certificate.
199
* Returns: (transfer full): a newly allocated #GcrCertificateWidget, which
200
* should be freed with g_object_unref()
202
GcrCertificateWidget *
203
gcr_certificate_widget_new (GcrCertificate *certificate)
205
return g_object_new (GCR_TYPE_CERTIFICATE_WIDGET, "certificate", certificate, NULL);
209
* gcr_certificate_widget_get_certificate:
210
* @self: The certificate widget
212
* Get the certificate displayed in the widget.
214
* Returns: (allow-none) (transfer none): the certificate
217
gcr_certificate_widget_get_certificate (GcrCertificateWidget *self)
219
g_return_val_if_fail (GCR_IS_CERTIFICATE_WIDGET (self), NULL);
220
return gcr_certificate_renderer_get_certificate (self->pv->renderer);
224
* gcr_certificate_widget_set_certificate:
225
* @self: The certificate widget
226
* @certificate: (allow-none): the certificate to display
228
* Set the certificate displayed in the widget
231
gcr_certificate_widget_set_certificate (GcrCertificateWidget *self, GcrCertificate *certificate)
233
g_return_if_fail (GCR_IS_CERTIFICATE_WIDGET (self));
234
gcr_certificate_renderer_set_certificate (self->pv->renderer, certificate);
238
* gcr_certificate_widget_get_attributes:
239
* @self: The certificate widget
241
* Get the attributes displayed in the widget. The attributes should contain
244
* Returns: (allow-none) (transfer none): the attributes, owned by the widget
247
gcr_certificate_widget_get_attributes (GcrCertificateWidget *self)
249
g_return_val_if_fail (GCR_IS_CERTIFICATE_WIDGET (self), NULL);
250
return gcr_certificate_renderer_get_attributes (self->pv->renderer);
254
* gcr_certificate_widget_set_attributes:
255
* @self: The certificate widget
256
* @attrs: (allow-none): the attributes to display
258
* Set the attributes displayed in the widget. The attributes should contain
262
gcr_certificate_widget_set_attributes (GcrCertificateWidget *self, GckAttributes* attrs)
264
g_return_if_fail (GCR_IS_CERTIFICATE_WIDGET (self));
265
gcr_certificate_renderer_set_attributes (self->pv->renderer, attrs);