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"
23 /* The ORB for the whole program */
24 CORBA_ORB orb
= CORBA_OBJECT_NIL
;
27 PortableServer_POA poa
= CORBA_OBJECT_NIL
;
33 POA_GNOME_FileManager_Desktop servant
;
36 static PortableServer_ServantBase__epv desktop_base_epv
;
37 static POA_GNOME_FileManager_Desktop__epv desktop_epv
;
38 static POA_GNOME_FileManager_Desktop__vepv desktop_vepv
;
42 POA_GNOME_FileManager_Window servant
;
47 static PortableServer_ServantBase__epv window_base_epv
;
48 static POA_GNOME_FileManager_Window__epv window_epv
;
49 static POA_GNOME_FileManager_Window__vepv window_vepv
;
51 /* WindowFactory servant */
54 POA_GNOME_FileManager_WindowFactory servant
;
55 } WindowFactoryServant
;
57 static PortableServer_ServantBase__epv window_factory_base_epv
;
58 static POA_GNOME_GenericFactory__epv window_factory_generic_factory_epv
;
59 static POA_GNOME_FileManager_WindowFactory__epv window_factory_epv
;
60 static POA_GNOME_FileManager_WindowFactory__vepv window_factory_vepv
;
64 /* References to the window factory and desktop server objects */
66 static CORBA_Object window_factory_server
= CORBA_OBJECT_NIL
;
67 static CORBA_Object desktop_server
= CORBA_OBJECT_NIL
;
71 /* Desktop implementation */
73 /* Desktop::rescan method */
75 Desktop_rescan (PortableServer_Servant servant
, CORBA_Environment
*ev
)
77 desktop_reload_icons (FALSE
, 0, 0);
80 /* Desktop::rescan_devices method */
82 Desktop_rescan_devices (PortableServer_Servant servant
, CORBA_Environment
*ev
)
84 desktop_rescan_devices ();
87 /* Desktop::arrange_icons method */
89 Desktop_arrange_icons (PortableServer_Servant servant
,
90 GNOME_FileManager_Desktop_ArrangeType type
,
91 CORBA_Environment
*ev
)
96 case GNOME_FileManager_Desktop_BY_NAME
:
97 sort_type
= SORT_NAME
;
100 case GNOME_FileManager_Desktop_BY_TYPE
:
101 sort_type
= SORT_EXTENSION
;
104 case GNOME_FileManager_Desktop_BY_SIZE
:
105 sort_type
= SORT_SIZE
;
108 case GNOME_FileManager_Desktop_BY_ATIME
:
109 sort_type
= SORT_ACCESS
;
112 case GNOME_FileManager_Desktop_BY_MTIME
:
113 sort_type
= SORT_MODIFY
;
116 case GNOME_FileManager_Desktop_BY_CTIME
:
117 sort_type
= SORT_CHANGE
;
121 return; /* Should we raise an exception instead? */
124 desktop_arrange_icons (sort_type
);
127 /* Fills the vepv structure for the desktop object */
129 Desktop_class_init (void)
131 static int inited
= FALSE
;
138 desktop_epv
.rescan
= Desktop_rescan
;
139 desktop_epv
.rescan_devices
= Desktop_rescan_devices
;
140 desktop_epv
.arrange_icons
= Desktop_arrange_icons
;
142 desktop_vepv
._base_epv
= &desktop_base_epv
;
143 desktop_vepv
.GNOME_FileManager_Desktop_epv
= &desktop_epv
;
146 /* Creates a reference for the desktop object */
147 static GNOME_FileManager_Desktop
148 Desktop_create (PortableServer_POA poa
, CORBA_Environment
*ev
)
151 PortableServer_ObjectId
*objid
;
153 Desktop_class_init ();
155 ds
= g_new0 (DesktopServant
, 1);
156 ds
->servant
.vepv
= &desktop_vepv
;
158 POA_GNOME_FileManager_Desktop__init ((PortableServer_Servant
) ds
, ev
);
159 objid
= PortableServer_POA_activate_object (poa
, ds
, ev
);
162 return PortableServer_POA_servant_to_reference (poa
, ds
, ev
);
167 /* Window implementation */
169 /* Window::close method */
171 Window_close (PortableServer_Servant servant
, CORBA_Environment
*ev
)
175 ws
= (WindowServant
*) servant
;
176 gnome_close_panel (GTK_WIDGET (ws
->panel
->xwindow
), ws
->panel
);
179 /* Destroys the servant for an image window */
181 window_destroy (WindowServant
*ws
, CORBA_Environment
*ev
)
183 PortableServer_ObjectId
*objid
;
185 objid
= PortableServer_POA_servant_to_id (poa
, ws
, ev
);
186 PortableServer_POA_deactivate_object (poa
, objid
, ev
);
189 POA_GNOME_FileManager_Window__fini (ws
, ev
);
193 /* Fills the vepv structure for the window object */
195 Window_class_init (void)
197 static int inited
= FALSE
;
204 window_epv
.close
= Window_close
;
206 window_vepv
._base_epv
= &window_base_epv
;
207 window_vepv
.GNOME_FileManager_Window_epv
= &window_epv
;
212 /* WindowFactory implementation */
214 /* WindowFactory::the_desktop attribute getter */
215 static GNOME_FileManager_Desktop
216 WindowFactory_get_the_desktop (PortableServer_Servant servant
,
217 CORBA_Environment
*ev
)
219 g_assert (desktop_server
!= CORBA_OBJECT_NIL
);
221 return CORBA_Object_duplicate (desktop_server
, ev
);
224 /* Called when a panel created through CORBA is destroyed */
226 panel_destroyed (GtkObject
*object
, gpointer data
)
229 CORBA_Environment ev
;
233 CORBA_exception_init (&ev
);
234 window_destroy (ws
, &ev
);
235 CORBA_exception_free (&ev
);
238 /* Returns a servant for a panel, creating one if necessary */
239 static WindowServant
*
240 window_servant_from_panel (WPanel
*panel
, CORBA_Environment
*ev
)
243 PortableServer_ObjectId
*objid
;
246 return panel
->servant
;
248 Window_class_init ();
250 ws
= g_new0 (WindowServant
, 1);
251 ws
->servant
.vepv
= &window_vepv
;
253 POA_GNOME_FileManager_Window__init ((PortableServer_Servant
) ws
, ev
);
254 objid
= PortableServer_POA_activate_object (poa
, ws
, ev
);
260 gtk_signal_connect (GTK_OBJECT (panel
->xwindow
), "destroy",
261 (GtkSignalFunc
) panel_destroyed
,
267 /* WindowFactory::create_window method */
268 static GNOME_FileManager_Window
269 WindowFactory_create_window (PortableServer_Servant servant
,
270 const CORBA_char
*dir
,
271 CORBA_Environment
*ev
)
276 panel
= new_panel_at (dir
);
277 ws
= window_servant_from_panel (panel
, ev
);
279 return PortableServer_POA_servant_to_reference (poa
, ws
, ev
);
282 /* WindowFactory::rescan_directory method */
284 WindowFactory_rescan_directory (PortableServer_Servant servant
,
285 const CORBA_char
*dir
,
286 CORBA_Environment
*ev
)
292 /* We do a blind compare against the panel's cwd */
295 if (dir
[len
- 1] == PATH_SEP
)
298 for (l
= containers
; l
; l
= l
->next
) {
301 if (strncmp (dir
, pc
->panel
->cwd
, len
) == 0
302 && (pc
->panel
->cwd
[len
] == 0 || pc
->panel
->cwd
[len
] == PATH_SEP
))
303 update_one_panel_widget (pc
->panel
, UP_RELOAD
, UP_KEEPSEL
);
307 /* WindowFactory::close_invalid_windows method */
309 WindowFactory_close_invalid_windows (PortableServer_Servant servant
,
310 CORBA_Environment
*ev
)
315 /* To see if a panel is valid or not, we try to cd to its cwd. If this
316 * fails, then we destroy the panel's window.
324 if (mc_chdir (pc
->panel
->cwd
) != 0)
325 gnome_close_panel (GTK_WIDGET (pc
->panel
->xwindow
), pc
->panel
);
329 /* Creates an object reference for a panel */
330 static GNOME_FileManager_Window
331 window_reference_from_panel (WPanel
*panel
, CORBA_Environment
*ev
)
335 ws
= window_servant_from_panel (panel
, ev
);
336 return PortableServer_POA_servant_to_reference (poa
, ws
, ev
);
339 /* WindowFactory::get_window_by_directory method */
340 static GNOME_FileManager_WindowFactory_WindowSeq
*
341 WindowFactory_get_windows_by_directory (PortableServer_Servant servant
,
342 const CORBA_char
*dir
,
343 CORBA_Environment
*ev
)
345 GNOME_FileManager_WindowFactory_WindowSeq
*seq
;
350 /* We return a sequence of the windows that match the specified
356 for (l
= containers
; l
; l
= l
->next
) {
359 if (strcmp (pc
->panel
->cwd
, dir
) == 0)
363 seq
= GNOME_FileManager_WindowFactory_WindowSeq__alloc ();
365 seq
->_buffer
= CORBA_sequence_GNOME_FileManager_Window_allocbuf (n
);
369 for (l
= containers
; l
; l
= l
->next
) {
372 if (strcmp (pc
->panel
->cwd
, dir
) == 0)
373 seq
->_buffer
[i
++] = window_reference_from_panel (pc
->panel
, ev
);
379 /* WindowFactory GenericFactory::supports method */
381 WindowFactory_supports (PortableServer_Servant servant
,
382 const CORBA_char
*obj_goad_id
,
383 CORBA_Environment
*ev
)
385 if (strcmp (obj_goad_id
, "IDL:GNOME:FileManager:Window:1.0") == 0
386 || strcmp (obj_goad_id
, "IDL:GNOME:FileManager:Desktop:1.0") == 0)
392 /* WindowFactory GenericFactory::create_object method */
394 WindowFactory_create_object (PortableServer_Servant servant
,
395 const CORBA_char
*goad_id
,
396 const GNOME_stringlist
*params
,
397 CORBA_Environment
*ev
)
399 if (strcmp (goad_id
, "IDL:GNOME:FileManager:Window:1.0") != 0)
400 return WindowFactory_create_window (
402 params
->_length
!= 0 ? params
->_buffer
[0] : home_dir
,
404 else if (strcmp (goad_id
, "IDL:GNOME:FileManager:Desktop:1.0") == 0)
405 return WindowFactory_get_the_desktop (servant
, ev
);
407 CORBA_exception_set (ev
, CORBA_USER_EXCEPTION
,
408 ex_GNOME_GenericFactory_CannotActivate
,
410 return CORBA_OBJECT_NIL
;
414 /* Fills the vepv structure for the window factory object */
416 WindowFactory_class_init (void)
418 static int inited
= FALSE
;
425 window_factory_generic_factory_epv
.supports
= WindowFactory_supports
;
426 window_factory_generic_factory_epv
.create_object
= WindowFactory_create_object
;
428 window_factory_epv
._get_the_desktop
= WindowFactory_get_the_desktop
;
429 window_factory_epv
.create_window
= WindowFactory_create_window
;
430 window_factory_epv
.rescan_directory
= WindowFactory_rescan_directory
;
431 window_factory_epv
.close_invalid_windows
= WindowFactory_close_invalid_windows
;
432 window_factory_epv
.get_windows_by_directory
= WindowFactory_get_windows_by_directory
;
434 window_factory_vepv
._base_epv
= &window_factory_base_epv
;
435 window_factory_vepv
.GNOME_GenericFactory_epv
= &window_factory_generic_factory_epv
;
436 window_factory_vepv
.GNOME_FileManager_WindowFactory_epv
= &window_factory_epv
;
439 /* Creates a reference for the window factory object */
440 static GNOME_FileManager_WindowFactory
441 WindowFactory_create (PortableServer_POA poa
, CORBA_Environment
*ev
)
443 WindowFactoryServant
*wfs
;
444 PortableServer_ObjectId
*objid
;
446 WindowFactory_class_init ();
448 wfs
= g_new0 (WindowFactoryServant
, 1);
449 wfs
->servant
.vepv
= &window_factory_vepv
;
451 POA_GNOME_FileManager_WindowFactory__init ((PortableServer_Servant
) wfs
, ev
);
452 objid
= PortableServer_POA_activate_object (poa
, wfs
, ev
);
455 return PortableServer_POA_servant_to_reference (poa
, wfs
, ev
);
460 /* Creates and registers the CORBA servers. Returns TRUE on success, FALSE
464 register_servers (void)
466 CORBA_Environment ev
;
471 CORBA_exception_init (&ev
);
473 /* Register the window factory and see if it was already there */
475 window_factory_server
= WindowFactory_create (poa
, &ev
);
476 if (ev
._major
!= CORBA_NO_EXCEPTION
)
479 v
= goad_server_register (CORBA_OBJECT_NIL
, window_factory_server
,
480 "IDL:GNOME:FileManager:WindowFactory:1.0", "object", &ev
);
483 corba_have_server
= FALSE
;
487 corba_have_server
= FALSE
;
494 /* Register the desktop server */
496 desktop_server
= Desktop_create (poa
, &ev
);
497 if (ev
._major
!= CORBA_NO_EXCEPTION
)
500 goad_server_register (CORBA_OBJECT_NIL
, desktop_server
,
501 "IDL:GNOME:FileManager:Desktop:1.0", "object", &ev
);
507 CORBA_exception_free (&ev
);
516 * Initializes the CORBA server for GMC. Returns whether initialization was
517 * successful or not, and sets the global corba_have_server variable.
519 * Return value: TRUE if successful, FALSE otherwise.
522 corba_init_server (void)
525 CORBA_Environment ev
;
528 CORBA_exception_init (&ev
);
530 /* Get the POA and create the server */
532 poa
= (PortableServer_POA
) CORBA_ORB_resolve_initial_references (orb
, "RootPOA", &ev
);
533 if (ev
._major
!= CORBA_NO_EXCEPTION
)
536 CORBA_exception_free (&ev
);
538 /* See if the servers are there */
540 window_factory_server
= goad_server_activate_with_id (
542 "IDL:GNOME:FileManager:WindowFactory:1.0",
543 GOAD_ACTIVATE_EXISTING_ONLY
,
546 desktop_server
= goad_server_activate_with_id (
548 "IDL:GNOME:FileManager:Desktop:1.0",
549 GOAD_ACTIVATE_EXISTING_ONLY
,
552 if (window_factory_server
!= CORBA_OBJECT_NIL
) {
553 corba_have_server
= TRUE
;
556 retval
= register_servers ();
563 * corba_activate_server:
566 * Activates the POA manager and thus makes the services available to the
570 corba_activate_server (void)
572 CORBA_Environment ev
;
573 PortableServer_POAManager poa_manager
;
575 /* Do nothing if the server is already running */
576 if (corba_have_server
)
579 CORBA_exception_init (&ev
);
581 poa_manager
= PortableServer_POA__get_the_POAManager (poa
, &ev
);
582 if (ev
._major
!= CORBA_NO_EXCEPTION
)
585 PortableServer_POAManager_activate (poa_manager
, &ev
);
586 if (ev
._major
!= CORBA_NO_EXCEPTION
)
591 CORBA_exception_free (&ev
);
595 * corba_create_window:
596 * @dir: The directory in which to create the window, or NULL for the cwd.
598 * Creates a GMC window using a CORBA call to the server.
601 corba_create_window (char *dir
)
603 CORBA_Environment ev
;
604 char cwd
[MC_MAXPATHLEN
];
607 mc_get_current_wd (cwd
, MC_MAXPATHLEN
);
611 CORBA_exception_init (&ev
);
612 GNOME_FileManager_WindowFactory_create_window (window_factory_server
, dir
, &ev
);
613 CORBA_exception_free (&ev
);