1 /* gpastreamop.c - The GpaStreamOperation object.
2 * Copyright (C) 2007 g10 Code GmbH
3 *
4 * This file is part of GPA
5 *
6 * GPA is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * GPA is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 * License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <config.h>
21
22 #include "i18n.h"
23 #include "gtktools.h"
24 #include "gpastreamop.h"
25
26 /* Signals */
27 enum
28 {
29 LAST_SIGNAL
30 };
31
32 /* Properties */
33 enum
34 {
35 PROP_0,
36 PROP_INPUT_STREAM,
37 PROP_OUTPUT_STREAM,
38 PROP_MESSAGE_STREAM
39 };
40
41 static GObjectClass *parent_class;
42 /* static guint signals[LAST_SIGNAL]; */
43
44
45 static void
gpa_stream_operation_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)46 gpa_stream_operation_get_property (GObject *object,
47 guint prop_id,
48 GValue *value,
49 GParamSpec *pspec)
50 {
51 GpaStreamOperation *op = GPA_STREAM_OPERATION (object);
52
53 switch (prop_id)
54 {
55 case PROP_INPUT_STREAM:
56 g_value_set_pointer (value, op->input_stream);
57 break;
58 case PROP_OUTPUT_STREAM:
59 g_value_set_pointer (value, op->output_stream);
60 break;
61 case PROP_MESSAGE_STREAM:
62 g_value_set_pointer (value, op->message_stream);
63 break;
64 default:
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
66 break;
67 }
68 }
69
70
71 static void
gpa_stream_operation_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)72 gpa_stream_operation_set_property (GObject *object,
73 guint prop_id,
74 const GValue *value,
75 GParamSpec *pspec)
76 {
77 GpaStreamOperation *op = GPA_STREAM_OPERATION (object);
78
79 switch (prop_id)
80 {
81 case PROP_INPUT_STREAM:
82 op->input_stream = (gpgme_data_t)g_value_get_pointer (value);
83 break;
84 case PROP_OUTPUT_STREAM:
85 op->output_stream = (gpgme_data_t)g_value_get_pointer (value);
86 break;
87 case PROP_MESSAGE_STREAM:
88 op->message_stream = (gpgme_data_t)g_value_get_pointer (value);
89 break;
90 default:
91 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
92 break;
93 }
94 }
95
96
97 static void
gpa_stream_operation_finalize(GObject * object)98 gpa_stream_operation_finalize (GObject *object)
99 {
100 GpaStreamOperation *op = GPA_STREAM_OPERATION (object);
101
102 gpgme_data_release (op->input_stream);
103 gpgme_data_release (op->output_stream);
104 gpgme_data_release (op->message_stream);
105 gtk_widget_destroy (op->progress_dialog);
106
107 G_OBJECT_CLASS (parent_class)->finalize (object);
108 }
109
110
111 static void
gpa_stream_operation_init(GpaStreamOperation * op)112 gpa_stream_operation_init (GpaStreamOperation *op)
113 {
114 op->input_stream = NULL;
115 op->output_stream = NULL;
116 op->message_stream = NULL;
117
118 op->progress_dialog = NULL;
119 }
120
121
122 static GObject*
gpa_stream_operation_constructor(GType type,guint n_construct_properties,GObjectConstructParam * construct_properties)123 gpa_stream_operation_constructor (GType type,
124 guint n_construct_properties,
125 GObjectConstructParam *construct_properties)
126 {
127 GObject *object;
128 GpaStreamOperation *op;
129
130 object = parent_class->constructor (type,
131 n_construct_properties,
132 construct_properties);
133 op = GPA_STREAM_OPERATION (object);
134
135 op->progress_dialog = gpa_progress_dialog_new (GPA_OPERATION(op)->window,
136 GPA_OPERATION(op)->context);
137
138 return object;
139 }
140
141
142 static void
gpa_stream_operation_class_init(GpaStreamOperationClass * klass)143 gpa_stream_operation_class_init (GpaStreamOperationClass *klass)
144 {
145 GObjectClass *object_class = G_OBJECT_CLASS (klass);
146
147 parent_class = g_type_class_peek_parent (klass);
148
149 object_class->constructor = gpa_stream_operation_constructor;
150 object_class->finalize = gpa_stream_operation_finalize;
151 object_class->set_property = gpa_stream_operation_set_property;
152 object_class->get_property = gpa_stream_operation_get_property;
153
154 /* Signals */
155 /* Properties */
156 g_object_class_install_property (object_class,
157 PROP_INPUT_STREAM,
158 g_param_spec_pointer
159 ("input_stream", "Input Stream",
160 "Data read by gpg/gpgsm",
161 G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
162 g_object_class_install_property (object_class,
163 PROP_OUTPUT_STREAM,
164 g_param_spec_pointer
165 ("output_stream", "Output Stream",
166 "Data written by gpg/gpgsm",
167 G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
168 g_object_class_install_property (object_class,
169 PROP_MESSAGE_STREAM,
170 g_param_spec_pointer
171 ("message_stream", "Message Stream",
172 "Message data read by gpg/gpgsm",
173 G_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
174 }
175
176
177 GType
gpa_stream_operation_get_type(void)178 gpa_stream_operation_get_type (void)
179 {
180 static GType stream_operation_type = 0;
181
182 if (!stream_operation_type)
183 {
184 static const GTypeInfo stream_operation_info =
185 {
186 sizeof (GpaStreamOperationClass),
187 (GBaseInitFunc)NULL,
188 (GBaseFinalizeFunc)NULL,
189 (GClassInitFunc)gpa_stream_operation_class_init,
190 NULL, /* class_finalize */
191 NULL, /* class_data */
192 sizeof (GpaStreamOperation),
193 0, /* n_preallocs */
194 (GInstanceInitFunc)gpa_stream_operation_init,
195 };
196
197 stream_operation_type = g_type_register_static
198 (GPA_OPERATION_TYPE, "GpaStreamOperation",
199 &stream_operation_info, 0);
200 }
201
202 return stream_operation_type;
203 }
204
205
206
207