1 /* Simple command-line client for the GNOME edition of the Midnight Commander
3 * Copyright (C) 1999 The Free Software Foundation
5 * Author: Federico Mena <federico@nuclecu.unam.mx>
9 #include <libgnorba/gnorba.h>
10 #include "FileManager.h"
14 /* Tries to contact the window factory */
16 get_window_factory (void)
20 obj
= goad_server_activate_with_id (
22 "IDL:GNOME:FileManager:WindowFactory:1.0",
23 GOAD_ACTIVATE_EXISTING_ONLY
,
25 if (obj
== CORBA_OBJECT_NIL
)
26 fprintf (stderr
, _("Could not contact the file manager\n"));
38 wf
= get_window_factory ();
39 if (wf
== CORBA_OBJECT_NIL
)
40 return CORBA_OBJECT_NIL
;
42 CORBA_exception_init (&ev
);
43 obj
= GNOME_FileManager_WindowFactory__get_the_desktop (wf
, &ev
);
44 if (ev
._major
!= CORBA_NO_EXCEPTION
) {
45 fprintf (stderr
, _("Could not get the desktop\n"));
46 CORBA_exception_free (&ev
);
47 return CORBA_OBJECT_NIL
;
50 CORBA_exception_free (&ev
);
54 /* Creates a new window in the specified directory */
56 create_window (char *dir
, CORBA_Environment
*ev
)
60 obj
= get_window_factory ();
61 if (obj
== CORBA_OBJECT_NIL
)
64 g_assert (dir
!= NULL
);
66 /* FIXME: need to canonicalize non-absolute pathnames */
68 GNOME_FileManager_WindowFactory_create_window (obj
, dir
, ev
);
69 CORBA_Object_release (obj
, ev
);
73 /* Rescan the specified directory */
75 rescan_directory (char *dir
, CORBA_Environment
*ev
)
79 obj
= get_window_factory ();
80 if (obj
== CORBA_OBJECT_NIL
)
83 g_assert (dir
!= NULL
);
85 /* FIXME: need to canonicalize non-absolute pathnames */
87 GNOME_FileManager_WindowFactory_rescan_directory (obj
, dir
, ev
);
88 CORBA_Object_release (obj
, ev
);
92 /* Rescan the desktop icons */
94 rescan_desktop (CORBA_Environment
*ev
)
99 if (obj
== CORBA_OBJECT_NIL
)
102 GNOME_FileManager_Desktop_rescan (obj
, ev
);
103 CORBA_Object_release (obj
, ev
);
107 /* Rescan the desktop device icons */
109 rescan_desktop_devices (CORBA_Environment
*ev
)
113 obj
= get_desktop ();
114 if (obj
== CORBA_OBJECT_NIL
)
117 GNOME_FileManager_Desktop_rescan_devices (obj
, ev
);
118 CORBA_Object_release (obj
, ev
);
122 /* Close invalid windows */
124 close_invalid_windows (CORBA_Environment
*ev
)
128 obj
= get_window_factory ();
129 if (obj
== CORBA_OBJECT_NIL
)
132 GNOME_FileManager_WindowFactory_close_invalid_windows (obj
, ev
);
133 CORBA_Object_release (obj
, ev
);
139 /* Option arguments */
143 ARG_RESCAN_DIRECTORY
,
145 ARG_RESCAN_DESKTOP_DEVICES
,
146 ARG_CLOSE_INVALID_WINDOWS
149 static int selected_option
= -1;
150 static char *directory
;
152 /* Parse an argument */
154 parse_an_arg (poptContext ctx
,
155 enum poptCallbackReason reason
,
156 const struct poptOption
*opt
,
160 if (reason
== POPT_CALLBACK_REASON_OPTION
)
161 selected_option
= opt
->val
;
162 else if (reason
== POPT_CALLBACK_REASON_POST
&& selected_option
== -1) {
163 poptPrintUsage (ctx
, stderr
, 0);
168 static const struct poptOption options
[] = {
169 { NULL
, '\0', POPT_ARG_CALLBACK
| POPT_CBFLAG_POST
, parse_an_arg
, 0, NULL
, NULL
},
170 { "create-window", '\0', POPT_ARG_STRING
, &directory
, ARG_CREATE_WINDOW
,
171 N_("Create window showing the specified directory"), N_("DIRECTORY") },
172 { "rescan-directory", '\0', POPT_ARG_STRING
, &directory
, ARG_RESCAN_DIRECTORY
,
173 N_("Rescan the specified directory"), N_("DIRECTORY") },
174 { "rescan-desktop", '\0', POPT_ARG_NONE
, NULL
, ARG_RESCAN_DESKTOP
,
175 N_("Rescan the desktop icons"), NULL
},
176 { "rescan-desktop-devices", '\0', POPT_ARG_NONE
, NULL
, ARG_RESCAN_DESKTOP_DEVICES
,
177 N_("Rescan the desktop device icons"), NULL
},
178 { "close-invalid-windows", '\0', POPT_ARG_NONE
, NULL
, ARG_CLOSE_INVALID_WINDOWS
,
179 N_("Close windows whose directories cannot be reached"), NULL
},
180 { NULL
, '\0', 0, NULL
, 0, NULL
, NULL
}
186 main (int argc
, char **argv
)
189 CORBA_Environment ev
;
193 bindtextdomain ("gmc-client", LOCALEDIR
);
194 textdomain ("gmc-client");
196 CORBA_exception_init (&ev
);
197 orb
= gnome_CORBA_init_with_popt_table ("gmc-client", VERSION
,
198 &argc
, argv
, options
, 0, &ctx
,
201 switch (selected_option
) {
202 case ARG_CREATE_WINDOW
:
203 result
= create_window (directory
, &ev
);
206 case ARG_RESCAN_DIRECTORY
:
207 result
= rescan_directory (directory
, &ev
);
210 case ARG_RESCAN_DESKTOP
:
211 result
= rescan_desktop (&ev
);
214 case ARG_RESCAN_DESKTOP_DEVICES
:
215 result
= rescan_desktop_devices (&ev
);
218 case ARG_CLOSE_INVALID_WINDOWS
:
219 result
= close_invalid_windows (&ev
);
223 g_assert_not_reached ();
226 if (!result
|| ev
._major
!= CORBA_NO_EXCEPTION
) {
227 poptFreeContext (ctx
);
231 CORBA_exception_free (&ev
);
232 poptFreeContext (ctx
);