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 /* Arrange the desktop icons */
124 arrange_desktop_icons (const char *type
, CORBA_Environment
*ev
)
127 GNOME_FileManager_Desktop_ArrangeType arr_type
;
129 if (strcmp (type
, "name") == 0)
130 arr_type
= GNOME_FileManager_Desktop_BY_NAME
;
131 else if (strcmp (type
, "type") == 0)
132 arr_type
= GNOME_FileManager_Desktop_BY_TYPE
;
133 else if (strcmp (type
, "size") == 0)
134 arr_type
= GNOME_FileManager_Desktop_BY_SIZE
;
135 else if (strcmp (type
, "atime") == 0)
136 arr_type
= GNOME_FileManager_Desktop_BY_ATIME
;
137 else if (strcmp (type
, "mtime") == 0)
138 arr_type
= GNOME_FileManager_Desktop_BY_MTIME
;
139 else if (strcmp (type
, "ctime") == 0)
140 arr_type
= GNOME_FileManager_Desktop_BY_CTIME
;
142 fprintf (stderr
, _("Unknown arrange type `%s'\n"), type
);
146 obj
= get_desktop ();
147 if (obj
== CORBA_OBJECT_NIL
)
150 GNOME_FileManager_Desktop_arrange_icons (obj
, arr_type
, ev
);
151 CORBA_Object_release (obj
, ev
);
155 /* Close invalid windows */
157 close_invalid_windows (CORBA_Environment
*ev
)
161 obj
= get_window_factory ();
162 if (obj
== CORBA_OBJECT_NIL
)
165 GNOME_FileManager_WindowFactory_close_invalid_windows (obj
, ev
);
166 CORBA_Object_release (obj
, ev
);
172 /* Option arguments */
176 ARG_RESCAN_DIRECTORY
,
178 ARG_RESCAN_DESKTOP_DEVICES
,
179 ARG_ARRANGE_DESKTOP_ICONS
,
180 ARG_CLOSE_INVALID_WINDOWS
183 static int selected_option
= -1;
184 static char *directory
;
185 static char *arrange_type
;
187 /* Parse an argument */
189 parse_an_arg (poptContext ctx
,
190 enum poptCallbackReason reason
,
191 const struct poptOption
*opt
,
195 if (reason
== POPT_CALLBACK_REASON_OPTION
)
196 selected_option
= opt
->val
;
197 else if (reason
== POPT_CALLBACK_REASON_POST
&& selected_option
== -1) {
198 poptPrintUsage (ctx
, stderr
, 0);
203 static const struct poptOption options
[] = {
204 { NULL
, '\0', POPT_ARG_CALLBACK
| POPT_CBFLAG_POST
, parse_an_arg
, 0, NULL
, NULL
},
205 { "create-window", '\0', POPT_ARG_STRING
, &directory
, ARG_CREATE_WINDOW
,
206 N_("Create window showing the specified directory"), N_("DIRECTORY") },
207 { "rescan-directory", '\0', POPT_ARG_STRING
, &directory
, ARG_RESCAN_DIRECTORY
,
208 N_("Rescan the specified directory"), N_("DIRECTORY") },
209 { "rescan-desktop", '\0', POPT_ARG_NONE
, NULL
, ARG_RESCAN_DESKTOP
,
210 N_("Rescan the desktop icons"), NULL
},
211 { "rescan-desktop-devices", '\0', POPT_ARG_NONE
, NULL
, ARG_RESCAN_DESKTOP_DEVICES
,
212 N_("Rescan the desktop device icons"), NULL
},
213 { "arrange-desktop-icons", '\0', POPT_ARG_STRING
, &arrange_type
, ARG_ARRANGE_DESKTOP_ICONS
,
214 N_("Arrange the desktop icons"),
215 N_("name | type | size | atime | mtime | ctime") },
216 { "close-invalid-windows", '\0', POPT_ARG_NONE
, NULL
, ARG_CLOSE_INVALID_WINDOWS
,
217 N_("Close windows whose directories cannot be reached"), NULL
},
218 { NULL
, '\0', 0, NULL
, 0, NULL
, NULL
}
224 main (int argc
, char **argv
)
227 CORBA_Environment ev
;
231 bindtextdomain ("gmc-client", LOCALEDIR
);
232 textdomain ("gmc-client");
234 CORBA_exception_init (&ev
);
235 orb
= gnome_CORBA_init_with_popt_table ("gmc-client", VERSION
,
236 &argc
, argv
, options
, 0, &ctx
,
239 switch (selected_option
) {
240 case ARG_CREATE_WINDOW
:
241 result
= create_window (directory
, &ev
);
244 case ARG_RESCAN_DIRECTORY
:
245 result
= rescan_directory (directory
, &ev
);
248 case ARG_RESCAN_DESKTOP
:
249 result
= rescan_desktop (&ev
);
252 case ARG_RESCAN_DESKTOP_DEVICES
:
253 result
= rescan_desktop_devices (&ev
);
256 case ARG_ARRANGE_DESKTOP_ICONS
:
257 result
= arrange_desktop_icons (arrange_type
, &ev
);
260 case ARG_CLOSE_INVALID_WINDOWS
:
261 result
= close_invalid_windows (&ev
);
265 g_assert_not_reached ();
268 if (!result
|| ev
._major
!= CORBA_NO_EXCEPTION
) {
269 poptFreeContext (ctx
);
273 CORBA_exception_free (&ev
);
274 poptFreeContext (ctx
);