1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/*
* e-signature-preview.c
*
* 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 of the License, or (at your option) version 3.
*
* 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 the program; if not, see <http://www.gnu.org/licenses/>
*
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "e-signature-preview.h"
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <glib/gstdio.h>
#include <libemail-utils/e-signature-utils.h>
enum {
PROP_0,
PROP_DISABLE_COMMAND_LINE,
PROP_SIGNATURE
};
enum {
REFRESH,
LAST_SIGNAL
};
struct _ESignaturePreviewPrivate {
ESignature *signature;
guint disable_command_line : 1;
};
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE (
ESignaturePreview,
e_signature_preview,
E_TYPE_WEB_VIEW)
static void
signature_preview_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_DISABLE_COMMAND_LINE:
e_signature_preview_set_disable_command_line (
E_SIGNATURE_PREVIEW (object),
g_value_get_boolean (value));
return;
case PROP_SIGNATURE:
e_signature_preview_set_signature (
E_SIGNATURE_PREVIEW (object),
g_value_get_object (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
signature_preview_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_DISABLE_COMMAND_LINE:
g_value_set_boolean (
value,
e_signature_preview_get_disable_command_line (
E_SIGNATURE_PREVIEW (object)));
return;
case PROP_SIGNATURE:
g_value_set_object (
value,
e_signature_preview_get_signature (
E_SIGNATURE_PREVIEW (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
signature_preview_dispose (GObject *object)
{
ESignaturePreviewPrivate *priv;
priv = E_SIGNATURE_PREVIEW (object)->priv;
if (priv->signature != NULL) {
g_object_unref (priv->signature);
priv->signature = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_signature_preview_parent_class)->dispose (object);
}
static void
signature_preview_constructed (GObject *object)
{
#ifndef G_OS_WIN32
GSettings *settings;
settings = g_settings_new ("org.gnome.desktop.lockdown");
g_settings_bind (
settings, "disable-command-line",
object, "disable-command-line",
G_SETTINGS_BIND_GET);
g_object_unref (settings);
#endif
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_signature_preview_parent_class)->constructed (object);
}
static void
signature_preview_refresh (ESignaturePreview *preview)
{
EWebView *web_view;
ESignature *signature;
const gchar *filename;
gboolean is_script;
gchar *content = NULL;
/* XXX We should show error messages in the preview. */
web_view = E_WEB_VIEW (preview);
signature = e_signature_preview_get_signature (preview);
if (signature == NULL)
goto clear;
filename = e_signature_get_filename (signature);
is_script = e_signature_get_is_script (signature);
if (is_script && preview->priv->disable_command_line)
goto clear;
if (is_script)
content = e_run_signature_script (filename);
else
content = e_read_signature_file (signature, FALSE, NULL);
if (content == NULL || *content == '\0')
goto clear;
if (e_signature_get_is_html (signature))
e_web_view_load_string (web_view, content);
else {
gchar *string;
string = g_strdup_printf ("<PRE>%s</PRE>", content);
e_web_view_load_string (web_view, string);
g_free (string);
}
g_free (content);
return;
clear:
e_web_view_clear (web_view);
g_free (content);
}
static void
e_signature_preview_class_init (ESignaturePreviewClass *class)
{
GObjectClass *object_class;
g_type_class_add_private (class, sizeof (ESignaturePreviewPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = signature_preview_set_property;
object_class->get_property = signature_preview_get_property;
object_class->dispose = signature_preview_dispose;
object_class->constructed = signature_preview_constructed;
class->refresh = signature_preview_refresh;
g_object_class_install_property (
object_class,
PROP_DISABLE_COMMAND_LINE,
g_param_spec_boolean (
"disable-command-line",
"Disable Command Line",
NULL,
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (
object_class,
PROP_SIGNATURE,
g_param_spec_object (
"signature",
"Signature",
NULL,
E_TYPE_SIGNATURE,
G_PARAM_READWRITE));
signals[REFRESH] = g_signal_new (
"refresh",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (ESignaturePreviewClass, refresh),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
static void
e_signature_preview_init (ESignaturePreview *preview)
{
preview->priv = G_TYPE_INSTANCE_GET_PRIVATE (
preview, E_TYPE_SIGNATURE_PREVIEW, ESignaturePreviewPrivate);
}
GtkWidget *
e_signature_preview_new (void)
{
return g_object_new (E_TYPE_SIGNATURE_PREVIEW, NULL);
}
void
e_signature_preview_refresh (ESignaturePreview *preview)
{
g_return_if_fail (E_IS_SIGNATURE_PREVIEW (preview));
g_signal_emit (preview, signals[REFRESH], 0);
}
gboolean
e_signature_preview_get_disable_command_line (ESignaturePreview *preview)
{
g_return_val_if_fail (E_IS_SIGNATURE_PREVIEW (preview), FALSE);
return preview->priv->disable_command_line;
}
void
e_signature_preview_set_disable_command_line (ESignaturePreview *preview,
gboolean disable_command_line)
{
g_return_if_fail (E_IS_SIGNATURE_PREVIEW (preview));
preview->priv->disable_command_line = disable_command_line;
g_object_notify (G_OBJECT (preview), "disable-command-line");
}
ESignature *
e_signature_preview_get_signature (ESignaturePreview *preview)
{
g_return_val_if_fail (E_IS_SIGNATURE_PREVIEW (preview), NULL);
return preview->priv->signature;
}
void
e_signature_preview_set_signature (ESignaturePreview *preview,
ESignature *signature)
{
g_return_if_fail (E_IS_SIGNATURE_PREVIEW (preview));
if (signature != NULL) {
g_return_if_fail (E_IS_SIGNATURE (signature));
g_object_ref (signature);
}
if (preview->priv->signature != NULL)
g_object_unref (preview->priv->signature);
preview->priv->signature = signature;
g_object_notify (G_OBJECT (preview), "signature");
e_signature_preview_refresh (preview);
}
|