1 /* CORBA support for the Midnight Commander
3 * Copyright (C) 1999 The Free Sofware Foundation
5 * Authors: Miguel de Icaza <miguel@nuclecu.unam.mx>
6 * Federico Mena <federico@nuclecu.unam.mx>
7 * Elliot Lee <sopwith@cuc.edu>
12 #include "../vfs/vfs.h"
13 #include <libgnorba/gnorba.h>
14 #include "FileManager.h"
24 /* The ORB for the whole program */
25 CORBA_ORB orb
= CORBA_OBJECT_NIL
;
28 PortableServer_POA poa
= CORBA_OBJECT_NIL
;
34 POA_GNOME_FileManager_Desktop servant
;
37 static PortableServer_ServantBase__epv desktop_base_epv
;
38 static POA_GNOME_FileManager_Desktop__epv desktop_epv
;
39 static POA_GNOME_FileManager_Desktop__vepv desktop_vepv
;
43 POA_GNOME_FileManager_Window servant
;
48 static PortableServer_ServantBase__epv window_base_epv
;
49 static POA_GNOME_FileManager_Window__epv window_epv
;
50 static POA_GNOME_FileManager_Window__vepv window_vepv
;
52 /* WindowFactory servant */
55 POA_GNOME_FileManager_WindowFactory servant
;
56 } WindowFactoryServant
;
58 static PortableServer_ServantBase__epv window_factory_base_epv
;
59 static POA_GNOME_GenericFactory__epv window_factory_generic_factory_epv
;
60 static POA_GNOME_FileManager_WindowFactory__epv window_factory_epv
;
61 static POA_GNOME_FileManager_WindowFactory__vepv window_factory_vepv
;
65 /* References to the window factory and desktop server objects */
67 static CORBA_Object window_factory_server
= CORBA_OBJECT_NIL
;
68 static CORBA_Object desktop_server
= CORBA_OBJECT_NIL
;
72 /* Desktop implementation */
74 /* Desktop::rescan method */
76 Desktop_rescan (PortableServer_Servant servant
, CORBA_Environment
*ev
)
78 desktop_reload_icons (FALSE
, 0, 0);
81 /* Desktop::rescan_devices method */
83 Desktop_rescan_devices (PortableServer_Servant servant
, CORBA_Environment
*ev
)
85 desktop_rescan_devices ();
88 /* Fills the vepv structure for the desktop object */
90 Desktop_class_init (void)
92 static int inited
= FALSE
;
99 desktop_epv
.rescan
= Desktop_rescan
;
100 desktop_epv
.rescan_devices
= Desktop_rescan_devices
;
102 desktop_vepv
._base_epv
= &desktop_base_epv
;
103 desktop_vepv
.GNOME_FileManager_Desktop_epv
= &desktop_epv
;
106 /* Creates a reference for the desktop object */
107 static GNOME_FileManager_Desktop
108 Desktop_create (PortableServer_POA poa
, CORBA_Environment
*ev
)
111 PortableServer_ObjectId
*objid
;
113 Desktop_class_init ();
115 ds
= g_new0 (DesktopServant
, 1);
116 ds
->servant
.vepv
= &desktop_vepv
;
118 POA_GNOME_FileManager_Desktop__init ((PortableServer_Servant
) ds
, ev
);
119 objid
= PortableServer_POA_activate_object (poa
, ds
, ev
);
122 return PortableServer_POA_servant_to_reference (poa
, ds
, ev
);
127 /* Window implementation */
129 /* Window::close method */
131 Window_close (PortableServer_Servant servant
, CORBA_Environment
*ev
)
135 ws
= (WindowServant
*) servant
;
136 gnome_close_panel (GTK_WIDGET (ws
->panel
->xwindow
), ws
->panel
);
139 /* Destroys the servant for an image window */
141 window_destroy (WindowServant
*ws
, CORBA_Environment
*ev
)
143 PortableServer_ObjectId
*objid
;
145 objid
= PortableServer_POA_servant_to_id (poa
, ws
, ev
);
146 PortableServer_POA_deactivate_object (poa
, objid
, ev
);
149 POA_GNOME_FileManager_Window__fini (ws
, ev
);
153 /* Fills the vepv structure for the window object */
155 Window_class_init (void)
157 static int inited
= FALSE
;
164 window_epv
.close
= Window_close
;
166 window_vepv
._base_epv
= &window_base_epv
;
167 window_vepv
.GNOME_FileManager_Window_epv
= &window_epv
;
172 /* WindowFactory implementation */
174 /* WindowFactory::the_desktop attribute getter */
175 static GNOME_FileManager_Desktop
176 WindowFactory_get_the_desktop (PortableServer_Servant servant
,
177 CORBA_Environment
*ev
)
179 g_assert (desktop_server
!= CORBA_OBJECT_NIL
);
181 return CORBA_Object_duplicate (desktop_server
, ev
);
184 /* Called when a panel created through CORBA is destroyed */
186 panel_destroyed (GtkObject
*object
, gpointer data
)
189 CORBA_Environment ev
;
193 CORBA_exception_init (&ev
);
194 window_destroy (ws
, &ev
);
195 CORBA_exception_free (&ev
);
198 /* Returns a servant for a panel, creating one if necessary */
199 static WindowServant
*
200 window_servant_from_panel (WPanel
*panel
, CORBA_Environment
*ev
)
203 PortableServer_ObjectId
*objid
;
206 return panel
->servant
;
208 Window_class_init ();
210 ws
= g_new0 (WindowServant
, 1);
211 ws
->servant
.vepv
= &window_vepv
;
213 POA_GNOME_FileManager_Window__init ((PortableServer_Servant
) ws
, ev
);
214 objid
= PortableServer_POA_activate_object (poa
, ws
, ev
);
220 gtk_signal_connect (GTK_OBJECT (panel
->xwindow
), "destroy",
221 (GtkSignalFunc
) panel_destroyed
,
227 /* WindowFactory::create_window method */
228 static GNOME_FileManager_Window
229 WindowFactory_create_window (PortableServer_Servant servant
,
231 CORBA_Environment
*ev
)
236 panel
= new_panel_at (dir
);
237 ws
= window_servant_from_panel (panel
, ev
);
239 return PortableServer_POA_servant_to_reference (poa
, ws
, ev
);
242 /* WindowFactory::rescan_directory method */
244 WindowFactory_rescan_directory (PortableServer_Servant servant
,
246 CORBA_Environment
*ev
)
252 /* We do a blind compare against the panel's cwd */
255 if (dir
[len
- 1] == PATH_SEP
)
258 for (l
= containers
; l
; l
= l
->next
) {
261 if (strncmp (dir
, pc
->panel
->cwd
, len
) == 0
262 && (pc
->panel
->cwd
[len
] == 0 || pc
->panel
->cwd
[len
] == PATH_SEP
))
263 update_one_panel_widget (pc
->panel
, UP_RELOAD
, UP_KEEPSEL
);
267 /* WindowFactory::close_invalid_windows method */
269 WindowFactory_close_invalid_windows (PortableServer_Servant servant
,
270 CORBA_Environment
*ev
)
275 /* To see if a panel is valid or not, we try to cd to its cwd. If this
276 * fails, then we destroy the panel's window.
284 if (mc_chdir (pc
->panel
->cwd
) != 0)
285 gnome_close_panel (GTK_WIDGET (pc
->panel
->xwindow
), pc
->panel
);
289 /* Creates an object reference for a panel */
290 static GNOME_FileManager_Window
291 window_reference_from_panel (WPanel
*panel
, CORBA_Environment
*ev
)
295 ws
= window_servant_from_panel (panel
, ev
);
296 return PortableServer_POA_servant_to_reference (poa
, ws
, ev
);
299 /* WindowFactory::get_window_by_directory method */
300 static GNOME_FileManager_WindowFactory_WindowSeq
*
301 WindowFactory_get_windows_by_directory (PortableServer_Servant servant
,
303 CORBA_Environment
*ev
)
305 GNOME_FileManager_WindowFactory_WindowSeq
*seq
;
310 /* We return a sequence of the windows that match the specified
316 for (l
= containers
; l
; l
= l
->next
) {
319 if (strcmp (pc
->panel
->cwd
, dir
) == 0)
323 seq
= GNOME_FileManager_WindowFactory_WindowSeq__alloc ();
325 seq
->_buffer
= CORBA_sequence_GNOME_FileManager_Window_allocbuf (n
);
329 for (l
= containers
; l
; l
= l
->next
) {
332 if (strcmp (pc
->panel
->cwd
, dir
) == 0)
333 seq
->_buffer
[i
++] = window_reference_from_panel (pc
->panel
, ev
);
339 /* WindowFactory GenericFactory::supports method */
341 WindowFactory_supports (PortableServer_Servant servant
,
342 CORBA_char
*obj_goad_id
,
343 CORBA_Environment
*ev
)
345 if (strcmp (obj_goad_id
, "IDL:GNOME:FileManager:Window:1.0") == 0
346 || strcmp (obj_goad_id
, "IDL:GNOME:FileManager:Desktop:1.0") == 0)
352 /* WindowFactory GenericFactory::create_object method */
354 WindowFactory_create_object (PortableServer_Servant servant
,
356 GNOME_stringlist
*params
,
357 CORBA_Environment
*ev
)
359 if (strcmp (goad_id
, "IDL:GNOME:FileManager:Window:1.0") != 0)
360 return WindowFactory_create_window (
362 params
->_length
!= 0 ? params
->_buffer
[0] : home_dir
,
364 else if (strcmp (goad_id
, "IDL:GNOME:FileManager:Desktop:1.0") == 0)
365 return WindowFactory_get_the_desktop (servant
, ev
);
367 CORBA_exception_set (ev
, CORBA_USER_EXCEPTION
,
368 ex_GNOME_GenericFactory_CannotActivate
,
370 return CORBA_OBJECT_NIL
;
374 /* Fills the vepv structure for the window factory object */
376 WindowFactory_class_init (void)
378 static int inited
= FALSE
;
385 window_factory_generic_factory_epv
.supports
= WindowFactory_supports
;
386 window_factory_generic_factory_epv
.create_object
= WindowFactory_create_object
;
388 window_factory_epv
._get_the_desktop
= WindowFactory_get_the_desktop
;
389 window_factory_epv
.create_window
= WindowFactory_create_window
;
390 window_factory_epv
.rescan_directory
= WindowFactory_rescan_directory
;
391 window_factory_epv
.close_invalid_windows
= WindowFactory_close_invalid_windows
;
392 window_factory_epv
.get_windows_by_directory
= WindowFactory_get_windows_by_directory
;
394 window_factory_vepv
._base_epv
= &window_factory_base_epv
;
395 window_factory_vepv
.GNOME_GenericFactory_epv
= &window_factory_generic_factory_epv
;
396 window_factory_vepv
.GNOME_FileManager_WindowFactory_epv
= &window_factory_epv
;
399 /* Creates a reference for the window factory object */
400 static GNOME_FileManager_WindowFactory
401 WindowFactory_create (PortableServer_POA poa
, CORBA_Environment
*ev
)
403 WindowFactoryServant
*wfs
;
404 PortableServer_ObjectId
*objid
;
406 WindowFactory_class_init ();
408 wfs
= g_new0 (WindowFactoryServant
, 1);
409 wfs
->servant
.vepv
= &window_factory_vepv
;
411 POA_GNOME_FileManager_WindowFactory__init ((PortableServer_Servant
) wfs
, ev
);
412 objid
= PortableServer_POA_activate_object (poa
, wfs
, ev
);
415 return PortableServer_POA_servant_to_reference (poa
, wfs
, ev
);
420 /* Creates and registers the CORBA servers. Returns TRUE on success, FALSE
424 register_servers (void)
426 CORBA_Environment ev
;
431 CORBA_exception_init (&ev
);
433 /* Register the window factory and see if it was already there */
435 window_factory_server
= WindowFactory_create (poa
, &ev
);
436 if (ev
._major
!= CORBA_NO_EXCEPTION
)
439 v
= goad_server_register (CORBA_OBJECT_NIL
, window_factory_server
,
440 "IDL:GNOME:FileManager:WindowFactory:1.0", "object", &ev
);
443 corba_have_server
= FALSE
;
447 corba_have_server
= FALSE
;
454 /* Register the desktop server */
456 desktop_server
= Desktop_create (poa
, &ev
);
457 if (ev
._major
!= CORBA_NO_EXCEPTION
)
460 goad_server_register (CORBA_OBJECT_NIL
, desktop_server
,
461 "IDL:GNOME:FileManager:Desktop:1.0", "object", &ev
);
467 CORBA_exception_free (&ev
);
476 * Initializes the CORBA server for GMC. Returns whether initialization was
477 * successful or not, and sets the global corba_have_server variable.
479 * Return value: TRUE if successful, FALSE otherwise.
482 corba_init_server (void)
485 CORBA_Environment ev
;
488 CORBA_exception_init (&ev
);
490 /* Get the POA and create the server */
492 poa
= (PortableServer_POA
) CORBA_ORB_resolve_initial_references (orb
, "RootPOA", &ev
);
493 if (ev
._major
!= CORBA_NO_EXCEPTION
)
496 CORBA_exception_free (&ev
);
498 /* See if the servers are there */
500 window_factory_server
= goad_server_activate_with_id (
502 "IDL:GNOME:FileManager:WindowFactory:1.0",
503 GOAD_ACTIVATE_EXISTING_ONLY
,
506 desktop_server
= goad_server_activate_with_id (
508 "IDL:GNOME:FileManager:Desktop:1.0",
509 GOAD_ACTIVATE_EXISTING_ONLY
,
512 if (window_factory_server
!= CORBA_OBJECT_NIL
) {
513 corba_have_server
= TRUE
;
516 retval
= register_servers ();
523 * corba_activate_server:
526 * Activates the POA manager and thus makes the services available to the
530 corba_activate_server (void)
532 CORBA_Environment ev
;
533 PortableServer_POAManager poa_manager
;
535 /* Do nothing if the server is already running */
536 if (corba_have_server
)
539 CORBA_exception_init (&ev
);
541 poa_manager
= PortableServer_POA__get_the_POAManager (poa
, &ev
);
542 if (ev
._major
!= CORBA_NO_EXCEPTION
)
545 PortableServer_POAManager_activate (poa_manager
, &ev
);
546 if (ev
._major
!= CORBA_NO_EXCEPTION
)
551 CORBA_exception_free (&ev
);
555 * corba_create_window:
556 * @dir: The directory in which to create the window, or NULL for the cwd.
558 * Creates a GMC window using a CORBA call to the server.
561 corba_create_window (char *dir
)
563 CORBA_Environment ev
;
564 char cwd
[MC_MAXPATHLEN
];
567 mc_get_current_wd (cwd
, MC_MAXPATHLEN
);
571 CORBA_exception_init (&ev
);
572 GNOME_FileManager_WindowFactory_create_window (window_factory_server
, dir
, &ev
);
573 CORBA_exception_free (&ev
);