~ubuntu-branches/ubuntu/trusty/gcr/trusty-proposed

« back to all changes in this revision

Viewing changes to gcr/gcr-certificate-widget.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-03 10:18:39 UTC
  • Revision ID: package-import@ubuntu.com-20120503101839-wuvloldm7gmdsnij
Tags: upstream-3.4.1
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Stefan Walter
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 * 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
 
 
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"
 
27
 
 
28
#include "gck/gck.h"
 
29
 
 
30
#include <gdk/gdk.h>
 
31
#include <glib/gi18n-lib.h>
 
32
 
 
33
/**
 
34
 * SECTION:gcr-certificate-widget
 
35
 * @title: GcrCertificateWidget
 
36
 * @short_description: Certificate widget and renderer
 
37
 *
 
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
 
40
 * by the user.
 
41
 *
 
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.
 
47
 */
 
48
 
 
49
/**
 
50
 * GcrCertificateWidget:
 
51
 *
 
52
 * A widget that displays a certificate.
 
53
 */
 
54
 
 
55
/**
 
56
 * GcrCertificateWidgetClass:
 
57
 *
 
58
 * The class for #GcrCertificateWidget
 
59
 */
 
60
 
 
61
enum {
 
62
        PROP_0,
 
63
        PROP_CERTIFICATE,
 
64
        PROP_ATTRIBUTES
 
65
};
 
66
 
 
67
struct _GcrCertificateWidget {
 
68
        /*< private >*/
 
69
        GtkAlignment parent;
 
70
        GcrCertificateWidgetPrivate *pv;
 
71
};
 
72
 
 
73
struct _GcrCertificateWidgetClass {
 
74
        /*< private >*/
 
75
        GtkAlignmentClass parent_class;
 
76
};
 
77
 
 
78
struct _GcrCertificateWidgetPrivate {
 
79
        GcrViewer *viewer;
 
80
        GcrCertificateRenderer *renderer;
 
81
};
 
82
 
 
83
G_DEFINE_TYPE (GcrCertificateWidget, gcr_certificate_widget, GTK_TYPE_ALIGNMENT);
 
84
 
 
85
/* -----------------------------------------------------------------------------
 
86
 * OBJECT
 
87
 */
 
88
 
 
89
static GObject*
 
90
gcr_certificate_widget_constructor (GType type, guint n_props, GObjectConstructParam *props)
 
91
{
 
92
        GObject *obj = G_OBJECT_CLASS (gcr_certificate_widget_parent_class)->constructor (type, n_props, props);
 
93
        GcrCertificateWidget *self = NULL;
 
94
 
 
95
        g_return_val_if_fail (obj, NULL);
 
96
 
 
97
        self = GCR_CERTIFICATE_WIDGET (obj);
 
98
 
 
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));
 
102
 
 
103
        gcr_viewer_add_renderer (self->pv->viewer, GCR_RENDERER (self->pv->renderer));
 
104
        return obj;
 
105
}
 
106
 
 
107
static void
 
108
gcr_certificate_widget_init (GcrCertificateWidget *self)
 
109
{
 
110
        self->pv = (G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_CERTIFICATE_WIDGET, GcrCertificateWidgetPrivate));
 
111
        self->pv->renderer = gcr_certificate_renderer_new (NULL);
 
112
}
 
113
 
 
114
static void
 
115
gcr_certificate_widget_finalize (GObject *obj)
 
116
{
 
117
        GcrCertificateWidget *self = GCR_CERTIFICATE_WIDGET (obj);
 
118
 
 
119
        g_assert (self->pv->renderer);
 
120
        g_object_unref (self->pv->renderer);
 
121
        self->pv->renderer = NULL;
 
122
 
 
123
        g_assert (self->pv->viewer);
 
124
        self->pv->viewer = NULL;
 
125
 
 
126
        G_OBJECT_CLASS (gcr_certificate_widget_parent_class)->finalize (obj);
 
127
}
 
128
 
 
129
static void
 
130
gcr_certificate_widget_set_property (GObject *obj, guint prop_id, const GValue *value,
 
131
                                     GParamSpec *pspec)
 
132
{
 
133
        GcrCertificateWidget *self = GCR_CERTIFICATE_WIDGET (obj);
 
134
 
 
135
        switch (prop_id) {
 
136
        case PROP_CERTIFICATE:
 
137
                gcr_certificate_widget_set_certificate (self, g_value_get_object (value));
 
138
                break;
 
139
        case PROP_ATTRIBUTES:
 
140
                gcr_certificate_widget_set_attributes (self, g_value_get_boxed (value));
 
141
                break;
 
142
        default:
 
143
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
 
144
                break;
 
145
        }
 
146
}
 
147
 
 
148
static void
 
149
gcr_certificate_widget_get_property (GObject *obj, guint prop_id, GValue *value,
 
150
                                     GParamSpec *pspec)
 
151
{
 
152
        GcrCertificateWidget *self = GCR_CERTIFICATE_WIDGET (obj);
 
153
 
 
154
        switch (prop_id) {
 
155
        case PROP_CERTIFICATE:
 
156
                g_value_set_object (value, gcr_certificate_widget_get_certificate (self));
 
157
                break;
 
158
        case PROP_ATTRIBUTES:
 
159
                g_value_set_boxed (value, gcr_certificate_widget_get_attributes (self));
 
160
                break;
 
161
        default:
 
162
                G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
 
163
                break;
 
164
        }
 
165
}
 
166
 
 
167
static void
 
168
gcr_certificate_widget_class_init (GcrCertificateWidgetClass *klass)
 
169
{
 
170
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
171
 
 
172
        gcr_certificate_widget_parent_class = g_type_class_peek_parent (klass);
 
173
        g_type_class_add_private (klass, sizeof (GcrCertificateWidgetPrivate));
 
174
 
 
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;
 
179
 
 
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));
 
183
 
 
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));
 
187
}
 
188
 
 
189
/* -----------------------------------------------------------------------------
 
190
 * PUBLIC
 
191
 */
 
192
 
 
193
/**
 
194
 * gcr_certificate_widget_new:
 
195
 * @certificate: (allow-none): certificate to display, or %NULL
 
196
 *
 
197
 * Create a new certificate widget which displays a given certificate.
 
198
 *
 
199
 * Returns: (transfer full): a newly allocated #GcrCertificateWidget, which
 
200
 *          should be freed with g_object_unref()
 
201
 */
 
202
GcrCertificateWidget *
 
203
gcr_certificate_widget_new (GcrCertificate *certificate)
 
204
{
 
205
        return g_object_new (GCR_TYPE_CERTIFICATE_WIDGET, "certificate", certificate, NULL);
 
206
}
 
207
 
 
208
/**
 
209
 * gcr_certificate_widget_get_certificate:
 
210
 * @self: The certificate widget
 
211
 *
 
212
 * Get the certificate displayed in the widget.
 
213
 *
 
214
 * Returns: (allow-none) (transfer none): the certificate
 
215
 */
 
216
GcrCertificate *
 
217
gcr_certificate_widget_get_certificate (GcrCertificateWidget *self)
 
218
{
 
219
        g_return_val_if_fail (GCR_IS_CERTIFICATE_WIDGET (self), NULL);
 
220
        return gcr_certificate_renderer_get_certificate (self->pv->renderer);
 
221
}
 
222
 
 
223
/**
 
224
 * gcr_certificate_widget_set_certificate:
 
225
 * @self: The certificate widget
 
226
 * @certificate: (allow-none): the certificate to display
 
227
 *
 
228
 * Set the certificate displayed in the widget
 
229
 */
 
230
void
 
231
gcr_certificate_widget_set_certificate (GcrCertificateWidget *self, GcrCertificate *certificate)
 
232
{
 
233
        g_return_if_fail (GCR_IS_CERTIFICATE_WIDGET (self));
 
234
        gcr_certificate_renderer_set_certificate (self->pv->renderer, certificate);
 
235
}
 
236
 
 
237
/**
 
238
 * gcr_certificate_widget_get_attributes:
 
239
 * @self: The certificate widget
 
240
 *
 
241
 * Get the attributes displayed in the widget. The attributes should contain
 
242
 * a certificate.
 
243
 *
 
244
 * Returns: (allow-none) (transfer none): the attributes, owned by the widget
 
245
 */
 
246
GckAttributes *
 
247
gcr_certificate_widget_get_attributes (GcrCertificateWidget *self)
 
248
{
 
249
        g_return_val_if_fail (GCR_IS_CERTIFICATE_WIDGET (self), NULL);
 
250
        return gcr_certificate_renderer_get_attributes (self->pv->renderer);
 
251
}
 
252
 
 
253
/**
 
254
 * gcr_certificate_widget_set_attributes:
 
255
 * @self: The certificate widget
 
256
 * @attrs: (allow-none): the attributes to display
 
257
 *
 
258
 * Set the attributes displayed in the widget. The attributes should contain
 
259
 * a certificate.
 
260
 */
 
261
void
 
262
gcr_certificate_widget_set_attributes (GcrCertificateWidget *self, GckAttributes* attrs)
 
263
{
 
264
        g_return_if_fail (GCR_IS_CERTIFICATE_WIDGET (self));
 
265
        gcr_certificate_renderer_set_attributes (self->pv->renderer, attrs);
 
266
}