1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* e-corba-shortcuts.c |
---|
3 | * |
---|
4 | * Copyright (C) 2001 Ximian, Inc. |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of version 2 of the GNU General Public |
---|
8 | * License as published by the Free Software Foundation. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | * General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public |
---|
16 | * License along with this program; if not, write to the |
---|
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | * Boston, MA 02111-1307, USA. |
---|
19 | * |
---|
20 | * Author: Ettore Perazzoli <ettore@ximian.com> |
---|
21 | */ |
---|
22 | |
---|
23 | /* FIXME: Doesn't throw exceptions properly. */ |
---|
24 | |
---|
25 | #ifdef HAVE_CONFIG_H |
---|
26 | #include <config.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | #include "e-corba-shortcuts.h" |
---|
30 | |
---|
31 | #include "e-util/e-corba-utils.h" |
---|
32 | |
---|
33 | #include <gal/util/e-util.h> |
---|
34 | |
---|
35 | |
---|
36 | #define PARENT_TYPE bonobo_x_object_get_type () |
---|
37 | static BonoboXObjectClass *parent_class = NULL; |
---|
38 | |
---|
39 | struct _ECorbaShortcutsPrivate { |
---|
40 | EShortcuts *shortcuts; |
---|
41 | }; |
---|
42 | |
---|
43 | |
---|
44 | /* Utility functions. */ |
---|
45 | |
---|
46 | static const char * |
---|
47 | string_from_corba (CORBA_char *corba_string) |
---|
48 | { |
---|
49 | if (corba_string[0] == '\0') |
---|
50 | return NULL; |
---|
51 | |
---|
52 | return corba_string; |
---|
53 | } |
---|
54 | |
---|
55 | static void |
---|
56 | shortcut_list_to_corba (const GSList *shortcut_list, |
---|
57 | GNOME_Evolution_Shortcuts_ShortcutList *shortcut_list_return) |
---|
58 | { |
---|
59 | GNOME_Evolution_Shortcuts_Shortcut *buffer; |
---|
60 | const GSList *p; |
---|
61 | int num_shortcuts; |
---|
62 | int i; |
---|
63 | |
---|
64 | num_shortcuts = g_slist_length ((GSList *) shortcut_list); /* safe cast, GLib sucks */ |
---|
65 | |
---|
66 | shortcut_list_return->_maximum = num_shortcuts; |
---|
67 | shortcut_list_return->_length = num_shortcuts; |
---|
68 | |
---|
69 | buffer = CORBA_sequence_GNOME_Evolution_Shortcuts_Shortcut_allocbuf (num_shortcuts); |
---|
70 | shortcut_list_return->_buffer = buffer; |
---|
71 | |
---|
72 | for (p = shortcut_list, i = 0; p != NULL; p = p->next, i++) { |
---|
73 | const EShortcutItem *item; |
---|
74 | |
---|
75 | item = (const EShortcutItem *) p->data; |
---|
76 | |
---|
77 | buffer[i].uri = CORBA_string_dup (e_safe_corba_string (item->uri)); |
---|
78 | buffer[i].name = CORBA_string_dup (e_safe_corba_string (item->name)); |
---|
79 | buffer[i].type = CORBA_string_dup (e_safe_corba_string (item->type)); |
---|
80 | buffer[i].customIconName = CORBA_string_dup (e_safe_corba_string (item->custom_icon_name)); |
---|
81 | } |
---|
82 | |
---|
83 | CORBA_sequence_set_release (shortcut_list_return, TRUE); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | /* GtkObject methods. */ |
---|
88 | |
---|
89 | static void |
---|
90 | impl_destroy (GtkObject *object) |
---|
91 | { |
---|
92 | ECorbaShortcuts *corba_shortcuts; |
---|
93 | ECorbaShortcutsPrivate *priv; |
---|
94 | |
---|
95 | corba_shortcuts = E_CORBA_SHORTCUTS (object); |
---|
96 | priv = corba_shortcuts->priv; |
---|
97 | |
---|
98 | gtk_object_unref (GTK_OBJECT (priv->shortcuts)); |
---|
99 | |
---|
100 | g_free (priv); |
---|
101 | |
---|
102 | (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | static void |
---|
107 | impl_add (PortableServer_Servant servant, |
---|
108 | const CORBA_short group_num, |
---|
109 | const CORBA_short position, |
---|
110 | const GNOME_Evolution_Shortcuts_Shortcut *shortcut, |
---|
111 | CORBA_Environment *ev) |
---|
112 | { |
---|
113 | ECorbaShortcuts *corba_shortcuts; |
---|
114 | ECorbaShortcutsPrivate *priv; |
---|
115 | |
---|
116 | corba_shortcuts = E_CORBA_SHORTCUTS (bonobo_object_from_servant (servant)); |
---|
117 | priv = corba_shortcuts->priv; |
---|
118 | |
---|
119 | e_shortcuts_add_shortcut (priv->shortcuts, group_num, position, |
---|
120 | string_from_corba (shortcut->uri), |
---|
121 | string_from_corba (shortcut->name), |
---|
122 | 0, |
---|
123 | string_from_corba (shortcut->type), |
---|
124 | string_from_corba (shortcut->customIconName)); |
---|
125 | } |
---|
126 | |
---|
127 | static void |
---|
128 | impl_remove (PortableServer_Servant servant, |
---|
129 | const CORBA_short group_num, |
---|
130 | const CORBA_short item_num, |
---|
131 | CORBA_Environment *ev) |
---|
132 | { |
---|
133 | ECorbaShortcuts *corba_shortcuts; |
---|
134 | ECorbaShortcutsPrivate *priv; |
---|
135 | |
---|
136 | corba_shortcuts = E_CORBA_SHORTCUTS (bonobo_object_from_servant (servant)); |
---|
137 | priv = corba_shortcuts->priv; |
---|
138 | |
---|
139 | e_shortcuts_remove_shortcut (priv->shortcuts, group_num, item_num); |
---|
140 | } |
---|
141 | |
---|
142 | static GNOME_Evolution_Shortcuts_Shortcut * |
---|
143 | impl_get (PortableServer_Servant servant, |
---|
144 | const CORBA_short group_num, |
---|
145 | const CORBA_short item_num, |
---|
146 | CORBA_Environment *ev) |
---|
147 | { |
---|
148 | ECorbaShortcuts *corba_shortcuts; |
---|
149 | ECorbaShortcutsPrivate *priv; |
---|
150 | GNOME_Evolution_Shortcuts_Shortcut *retval; |
---|
151 | const EShortcutItem *item; |
---|
152 | |
---|
153 | corba_shortcuts = E_CORBA_SHORTCUTS (bonobo_object_from_servant (servant)); |
---|
154 | priv = corba_shortcuts->priv; |
---|
155 | |
---|
156 | item = e_shortcuts_get_shortcut (priv->shortcuts, group_num, item_num); |
---|
157 | if (item == NULL) { |
---|
158 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
159 | ex_GNOME_Evolution_Shortcuts_NotFound, NULL); |
---|
160 | return NULL; |
---|
161 | } |
---|
162 | |
---|
163 | retval = GNOME_Evolution_Shortcuts_Shortcut__alloc (); |
---|
164 | retval->uri = CORBA_string_dup (e_safe_corba_string (item->uri)); |
---|
165 | retval->name = CORBA_string_dup (e_safe_corba_string (item->name)); |
---|
166 | retval->type = CORBA_string_dup (e_safe_corba_string (item->type)); |
---|
167 | retval->customIconName = CORBA_string_dup (e_safe_corba_string (item->custom_icon_name)); |
---|
168 | |
---|
169 | return retval; |
---|
170 | } |
---|
171 | |
---|
172 | static void |
---|
173 | impl_addGroup (PortableServer_Servant servant, |
---|
174 | const CORBA_short position, |
---|
175 | const CORBA_char *name, |
---|
176 | CORBA_Environment *ev) |
---|
177 | { |
---|
178 | ECorbaShortcuts *corba_shortcuts; |
---|
179 | ECorbaShortcutsPrivate *priv; |
---|
180 | |
---|
181 | corba_shortcuts = E_CORBA_SHORTCUTS (bonobo_object_from_servant (servant)); |
---|
182 | priv = corba_shortcuts->priv; |
---|
183 | |
---|
184 | if (position == 0) { |
---|
185 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
186 | ex_GNOME_Evolution_Shortcuts_InvalidPosition, NULL); |
---|
187 | return; |
---|
188 | } |
---|
189 | |
---|
190 | e_shortcuts_add_group (priv->shortcuts, position, name); |
---|
191 | } |
---|
192 | |
---|
193 | static void |
---|
194 | impl_removeGroup (PortableServer_Servant servant, |
---|
195 | const CORBA_short group_num, |
---|
196 | CORBA_Environment *ev) |
---|
197 | { |
---|
198 | ECorbaShortcuts *corba_shortcuts; |
---|
199 | ECorbaShortcutsPrivate *priv; |
---|
200 | |
---|
201 | corba_shortcuts = E_CORBA_SHORTCUTS (bonobo_object_from_servant (servant)); |
---|
202 | priv = corba_shortcuts->priv; |
---|
203 | |
---|
204 | if (group_num == 0) { |
---|
205 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
206 | ex_GNOME_Evolution_Shortcuts_CannotRemove, NULL); |
---|
207 | return; |
---|
208 | } |
---|
209 | |
---|
210 | e_shortcuts_remove_group (priv->shortcuts, group_num); |
---|
211 | } |
---|
212 | |
---|
213 | static GNOME_Evolution_Shortcuts_Group * |
---|
214 | impl_getGroup (PortableServer_Servant servant, |
---|
215 | const CORBA_short group_num, |
---|
216 | CORBA_Environment *ev) |
---|
217 | { |
---|
218 | ECorbaShortcuts *corba_shortcuts; |
---|
219 | ECorbaShortcutsPrivate *priv; |
---|
220 | GNOME_Evolution_Shortcuts_Group *group; |
---|
221 | const GSList *list; |
---|
222 | |
---|
223 | corba_shortcuts = E_CORBA_SHORTCUTS (bonobo_object_from_servant (servant)); |
---|
224 | priv = corba_shortcuts->priv; |
---|
225 | |
---|
226 | list = e_shortcuts_get_shortcuts_in_group (priv->shortcuts, group_num); |
---|
227 | |
---|
228 | group = GNOME_Evolution_Shortcuts_Group__alloc (); |
---|
229 | |
---|
230 | group->name = CORBA_string_dup (e_shortcuts_get_group_title (priv->shortcuts, group_num)); |
---|
231 | |
---|
232 | shortcut_list_to_corba (list, & group->shortcuts); |
---|
233 | |
---|
234 | return group; |
---|
235 | } |
---|
236 | |
---|
237 | static CORBA_sequence_GNOME_Evolution_Shortcuts_Group * |
---|
238 | impl__get_groups (PortableServer_Servant servant, |
---|
239 | CORBA_Environment *ev) |
---|
240 | { |
---|
241 | GNOME_Evolution_Shortcuts_GroupList *list; |
---|
242 | ECorbaShortcuts *corba_shortcuts; |
---|
243 | ECorbaShortcutsPrivate *priv; |
---|
244 | GSList *group_titles; |
---|
245 | const GSList *p; |
---|
246 | int i; |
---|
247 | |
---|
248 | corba_shortcuts = E_CORBA_SHORTCUTS (bonobo_object_from_servant (servant)); |
---|
249 | priv = corba_shortcuts->priv; |
---|
250 | |
---|
251 | list = GNOME_Evolution_Shortcuts_GroupList__alloc (); |
---|
252 | list->_length = e_shortcuts_get_num_groups (priv->shortcuts); |
---|
253 | list->_maximum = list->_length; |
---|
254 | list->_buffer = CORBA_sequence_GNOME_Evolution_Shortcuts_Group_allocbuf (list->_maximum); |
---|
255 | |
---|
256 | CORBA_sequence_set_release (list, TRUE); |
---|
257 | |
---|
258 | group_titles = e_shortcuts_get_group_titles (priv->shortcuts); |
---|
259 | for (p = group_titles, i = 0; p != NULL; p = p->next, i ++) { |
---|
260 | char *group_title; |
---|
261 | const GSList *shortcuts; |
---|
262 | |
---|
263 | group_title = (char *) p->data; |
---|
264 | |
---|
265 | shortcuts = e_shortcuts_get_shortcuts_in_group (priv->shortcuts, i); |
---|
266 | |
---|
267 | list->_buffer[i].name = CORBA_string_dup (group_title); |
---|
268 | shortcut_list_to_corba (shortcuts, &list->_buffer[i].shortcuts); |
---|
269 | |
---|
270 | g_free (group_title); |
---|
271 | } |
---|
272 | |
---|
273 | g_slist_free (group_titles); |
---|
274 | |
---|
275 | return list; |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | static void |
---|
280 | class_init (GtkObjectClass *object_class) |
---|
281 | { |
---|
282 | ECorbaShortcutsClass *corba_shortcuts_class; |
---|
283 | POA_GNOME_Evolution_Shortcuts__epv *epv; |
---|
284 | |
---|
285 | parent_class = gtk_type_class (PARENT_TYPE); |
---|
286 | |
---|
287 | object_class->destroy = impl_destroy; |
---|
288 | |
---|
289 | corba_shortcuts_class = E_CORBA_SHORTCUTS_CLASS (object_class); |
---|
290 | |
---|
291 | epv = & corba_shortcuts_class->epv; |
---|
292 | epv->add = impl_add; |
---|
293 | epv->remove = impl_remove; |
---|
294 | epv->get = impl_get; |
---|
295 | epv->addGroup = impl_addGroup; |
---|
296 | epv->removeGroup = impl_removeGroup; |
---|
297 | epv->getGroup = impl_getGroup; |
---|
298 | epv->_get_groups = impl__get_groups; |
---|
299 | } |
---|
300 | |
---|
301 | static void |
---|
302 | init (ECorbaShortcuts *corba_shortcuts) |
---|
303 | { |
---|
304 | ECorbaShortcutsPrivate *priv; |
---|
305 | |
---|
306 | priv = g_new (ECorbaShortcutsPrivate, 1); |
---|
307 | priv->shortcuts = NULL; |
---|
308 | |
---|
309 | corba_shortcuts->priv = priv; |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | ECorbaShortcuts * |
---|
314 | e_corba_shortcuts_new (EShortcuts *shortcuts) |
---|
315 | { |
---|
316 | ECorbaShortcuts *corba_shortcuts; |
---|
317 | |
---|
318 | g_return_val_if_fail (shortcuts != NULL, NULL); |
---|
319 | g_return_val_if_fail (E_IS_SHORTCUTS (shortcuts), NULL); |
---|
320 | |
---|
321 | corba_shortcuts = gtk_type_new (e_corba_shortcuts_get_type ()); |
---|
322 | |
---|
323 | gtk_object_ref (GTK_OBJECT (shortcuts)); |
---|
324 | corba_shortcuts->priv->shortcuts = shortcuts; |
---|
325 | |
---|
326 | return corba_shortcuts; |
---|
327 | } |
---|
328 | |
---|
329 | |
---|
330 | E_MAKE_X_TYPE (e_corba_shortcuts, "ECorbaShortcuts", ECorbaShortcuts, |
---|
331 | class_init, init, PARENT_TYPE, |
---|
332 | POA_GNOME_Evolution_Shortcuts__init, |
---|
333 | GTK_STRUCT_OFFSET (ECorbaShortcutsClass, epv)) |
---|