1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /** |
---|
3 | * eog-collection-control.c |
---|
4 | * |
---|
5 | * Authors: |
---|
6 | * Martin Baulig (baulig@suse.de) |
---|
7 | * Jens Finke (jens@gnome.org) |
---|
8 | * |
---|
9 | * Copyright 2000, SuSE GmbH. |
---|
10 | * Copyright 2001, The Free Software Foundation |
---|
11 | */ |
---|
12 | #include <config.h> |
---|
13 | #include <stdio.h> |
---|
14 | #include <gtk/gtksignal.h> |
---|
15 | #include <gtk/gtkmarshal.h> |
---|
16 | #include <gtk/gtktypeutils.h> |
---|
17 | |
---|
18 | #include <bonobo/bonobo-macros.h> |
---|
19 | |
---|
20 | #include "eog-collection-control.h" |
---|
21 | #include "eog-collection-view.h" |
---|
22 | |
---|
23 | struct _EogCollectionControlPrivate{ |
---|
24 | EogCollectionView *view; |
---|
25 | }; |
---|
26 | |
---|
27 | static void eog_collection_control_dispose (GObject *object); |
---|
28 | static void eog_collection_control_finalize (GObject *object); |
---|
29 | static void eog_collection_control_class_init (EogCollectionControlClass *klass); |
---|
30 | static void eog_collection_control_instance_init (EogCollectionControl *object); |
---|
31 | |
---|
32 | BONOBO_CLASS_BOILERPLATE (EogCollectionControl, eog_collection_control, |
---|
33 | BonoboControl, BONOBO_TYPE_CONTROL); |
---|
34 | |
---|
35 | static void |
---|
36 | eog_collection_control_dispose (GObject *object) |
---|
37 | { |
---|
38 | EogCollectionControl *control; |
---|
39 | |
---|
40 | g_return_if_fail (object != NULL); |
---|
41 | g_return_if_fail (EOG_IS_COLLECTION_CONTROL (object)); |
---|
42 | |
---|
43 | control = EOG_COLLECTION_CONTROL (object); |
---|
44 | |
---|
45 | BONOBO_CALL_PARENT (G_OBJECT_CLASS, dispose, (object)); |
---|
46 | } |
---|
47 | |
---|
48 | static void |
---|
49 | eog_collection_control_finalize (GObject *object) |
---|
50 | { |
---|
51 | EogCollectionControl *control; |
---|
52 | |
---|
53 | g_return_if_fail (object != NULL); |
---|
54 | g_return_if_fail (EOG_IS_COLLECTION_CONTROL (object)); |
---|
55 | |
---|
56 | control = EOG_COLLECTION_CONTROL (object); |
---|
57 | |
---|
58 | g_free (control->priv); |
---|
59 | |
---|
60 | BONOBO_CALL_PARENT (G_OBJECT_CLASS, finalize, (object)); |
---|
61 | } |
---|
62 | |
---|
63 | static void |
---|
64 | eog_collection_control_create_ui (EogCollectionControl *control) |
---|
65 | { |
---|
66 | /* Currently we have no additional user interface. */ |
---|
67 | } |
---|
68 | |
---|
69 | static void |
---|
70 | eog_collection_control_set_ui_container (EogCollectionControl *eog_ctrl, |
---|
71 | Bonobo_UIContainer ui_container) |
---|
72 | { |
---|
73 | BonoboUIComponent *uic; |
---|
74 | |
---|
75 | g_return_if_fail (eog_ctrl != NULL); |
---|
76 | g_return_if_fail (EOG_IS_COLLECTION_CONTROL (eog_ctrl)); |
---|
77 | g_return_if_fail (ui_container != CORBA_OBJECT_NIL); |
---|
78 | |
---|
79 | uic = bonobo_control_get_ui_component (BONOBO_CONTROL (eog_ctrl)); |
---|
80 | |
---|
81 | eog_collection_view_set_ui_container (EOG_COLLECTION_VIEW (eog_ctrl->priv->view), |
---|
82 | ui_container); |
---|
83 | |
---|
84 | bonobo_ui_component_set_container (uic, ui_container, NULL); |
---|
85 | eog_collection_control_create_ui (eog_ctrl); |
---|
86 | } |
---|
87 | |
---|
88 | static void |
---|
89 | eog_collection_control_unset_ui_container (EogCollectionControl *eog_ctrl) |
---|
90 | { |
---|
91 | BonoboUIComponent *uic; |
---|
92 | |
---|
93 | g_return_if_fail (eog_ctrl != NULL); |
---|
94 | g_return_if_fail (EOG_IS_COLLECTION_CONTROL (eog_ctrl)); |
---|
95 | |
---|
96 | uic = bonobo_control_get_ui_component (BONOBO_CONTROL (eog_ctrl)); |
---|
97 | |
---|
98 | eog_collection_view_unset_ui_container (EOG_COLLECTION_VIEW (eog_ctrl->priv->view)); |
---|
99 | |
---|
100 | bonobo_ui_component_unset_container (uic, NULL); |
---|
101 | } |
---|
102 | |
---|
103 | static void |
---|
104 | eog_collection_control_activate (BonoboControl *bctrl, gboolean state, gpointer data) |
---|
105 | { |
---|
106 | EogCollectionControl *eog_ctrl; |
---|
107 | |
---|
108 | g_return_if_fail (bctrl != NULL); |
---|
109 | g_return_if_fail (EOG_IS_COLLECTION_CONTROL (bctrl)); |
---|
110 | |
---|
111 | eog_ctrl = EOG_COLLECTION_CONTROL (bctrl); |
---|
112 | |
---|
113 | if (state) { |
---|
114 | Bonobo_UIContainer ui_container; |
---|
115 | |
---|
116 | ui_container = bonobo_control_get_remote_ui_container (BONOBO_CONTROL (bctrl), NULL); |
---|
117 | if (ui_container != CORBA_OBJECT_NIL) { |
---|
118 | eog_collection_control_set_ui_container (eog_ctrl, ui_container); |
---|
119 | bonobo_object_release_unref (ui_container, NULL); |
---|
120 | } |
---|
121 | } else |
---|
122 | eog_collection_control_unset_ui_container (eog_ctrl); |
---|
123 | |
---|
124 | BONOBO_CALL_PARENT (BONOBO_CONTROL_CLASS, activate, (bctrl, state)); |
---|
125 | } |
---|
126 | |
---|
127 | static void |
---|
128 | eog_collection_control_class_init (EogCollectionControlClass *klass) |
---|
129 | { |
---|
130 | GObjectClass *object_class = (GObjectClass *)klass; |
---|
131 | |
---|
132 | object_class->dispose = eog_collection_control_dispose; |
---|
133 | object_class->finalize = eog_collection_control_finalize; |
---|
134 | } |
---|
135 | |
---|
136 | static void |
---|
137 | eog_collection_control_instance_init (EogCollectionControl *control) |
---|
138 | { |
---|
139 | control->priv = g_new0 (EogCollectionControlPrivate, 1); |
---|
140 | } |
---|
141 | |
---|
142 | static void |
---|
143 | handle_open_uri (GObject *obj, gchar *uri, gpointer data) |
---|
144 | { |
---|
145 | EogCollectionControl *eog_ctrl; |
---|
146 | BonoboObject *bctrl; |
---|
147 | CORBA_Environment ev; |
---|
148 | Bonobo_ControlFrame ctrl_frame; |
---|
149 | |
---|
150 | g_return_if_fail (obj != NULL); |
---|
151 | g_return_if_fail (EOG_IS_COLLECTION_CONTROL (data)); |
---|
152 | |
---|
153 | eog_ctrl = EOG_COLLECTION_CONTROL (data); |
---|
154 | CORBA_exception_init (&ev); |
---|
155 | |
---|
156 | bctrl = bonobo_object_query_local_interface (BONOBO_OBJECT (eog_ctrl), |
---|
157 | "IDL:Bonobo/Control:1.0"); |
---|
158 | if (bctrl == NULL) { |
---|
159 | g_error (_("Couldn't get local BonoboControl interface.\n")); |
---|
160 | return; |
---|
161 | } |
---|
162 | |
---|
163 | ctrl_frame = bonobo_control_get_control_frame (BONOBO_CONTROL (bctrl), NULL); |
---|
164 | Bonobo_ControlFrame_activateURI (ctrl_frame, CORBA_string_dup (uri), CORBA_FALSE, &ev); |
---|
165 | |
---|
166 | CORBA_Object_release (ctrl_frame, &ev); |
---|
167 | bonobo_object_unref (BONOBO_OBJECT (bctrl)); |
---|
168 | CORBA_exception_free (&ev); |
---|
169 | } |
---|
170 | |
---|
171 | EogCollectionControl * |
---|
172 | eog_collection_control_construct (EogCollectionControl *eog_ctrl) |
---|
173 | { |
---|
174 | EogCollectionControlPrivate *priv; |
---|
175 | BonoboPropertyBag *property_bag; |
---|
176 | GtkWidget *widget; |
---|
177 | |
---|
178 | g_return_val_if_fail (eog_ctrl != NULL, NULL); |
---|
179 | g_return_val_if_fail (EOG_IS_COLLECTION_CONTROL (eog_ctrl), NULL); |
---|
180 | |
---|
181 | priv = eog_ctrl->priv; |
---|
182 | |
---|
183 | /* construct parent object */ |
---|
184 | priv->view = EOG_COLLECTION_VIEW (eog_collection_view_new ()); |
---|
185 | widget = eog_collection_view_get_widget (priv->view); |
---|
186 | bonobo_control_construct (BONOBO_CONTROL (eog_ctrl), widget); |
---|
187 | |
---|
188 | bonobo_object_add_interface (BONOBO_OBJECT (eog_ctrl), |
---|
189 | BONOBO_OBJECT (priv->view)); |
---|
190 | |
---|
191 | gtk_widget_unref (widget); |
---|
192 | |
---|
193 | g_signal_connect (eog_ctrl, "activate", |
---|
194 | G_CALLBACK (eog_collection_control_activate), NULL); |
---|
195 | |
---|
196 | /* add properties */ |
---|
197 | property_bag = eog_collection_view_get_property_bag (priv->view); |
---|
198 | bonobo_control_set_properties (BONOBO_CONTROL (eog_ctrl), |
---|
199 | bonobo_object_corba_objref (BONOBO_OBJECT (property_bag)), |
---|
200 | NULL); |
---|
201 | bonobo_object_unref (BONOBO_OBJECT (property_bag)); |
---|
202 | |
---|
203 | /* connect collection view signals */ |
---|
204 | g_signal_connect (G_OBJECT (priv->view), |
---|
205 | "open_uri", |
---|
206 | G_CALLBACK (handle_open_uri), eog_ctrl); |
---|
207 | |
---|
208 | return eog_ctrl; |
---|
209 | } |
---|
210 | |
---|
211 | EogCollectionControl * |
---|
212 | eog_collection_control_new (void) |
---|
213 | { |
---|
214 | EogCollectionControl *control; |
---|
215 | |
---|
216 | control = g_object_new (EOG_TYPE_COLLECTION_CONTROL, NULL); |
---|
217 | |
---|
218 | return eog_collection_control_construct (control); |
---|
219 | } |
---|