De-fuzzyed some msgs...
[midnight-commander.git] / gnome / gmc-client.c
blob75c9dcc53d6b529c2197d40694371fb052d3d8ef
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>
6 */
8 #include <config.h>
9 #include <libgnorba/gnorba.h>
10 #include "FileManager.h"
14 /* Tries to contact the window factory */
15 static CORBA_Object
16 get_window_factory (void)
18 CORBA_Object obj;
20 obj = goad_server_activate_with_id (
21 NULL,
22 "IDL:GNOME:FileManager:WindowFactory:1.0",
23 GOAD_ACTIVATE_EXISTING_ONLY,
24 NULL);
25 if (obj == CORBA_OBJECT_NIL)
26 fprintf (stderr, _("Could not contact the file manager\n"));
28 return obj;
31 static CORBA_Object
32 get_desktop (void)
34 CORBA_Environment ev;
35 CORBA_Object wf;
36 CORBA_Object obj;
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);
51 return obj;
54 /* Creates a new window in the specified directory */
55 static int
56 create_window (char *dir, CORBA_Environment *ev)
58 CORBA_Object obj;
60 obj = get_window_factory ();
61 if (obj == CORBA_OBJECT_NIL)
62 return FALSE;
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);
70 return TRUE;
73 /* Rescan the specified directory */
74 static int
75 rescan_directory (char *dir, CORBA_Environment *ev)
77 CORBA_Object obj;
79 obj = get_window_factory ();
80 if (obj == CORBA_OBJECT_NIL)
81 return FALSE;
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);
89 return TRUE;
92 /* Rescan the desktop icons */
93 static int
94 rescan_desktop (CORBA_Environment *ev)
96 CORBA_Object obj;
98 obj = get_desktop ();
99 if (obj == CORBA_OBJECT_NIL)
100 return FALSE;
102 GNOME_FileManager_Desktop_rescan (obj, ev);
103 CORBA_Object_release (obj, ev);
104 return TRUE;
107 /* Rescan the desktop device icons */
108 static int
109 rescan_desktop_devices (CORBA_Environment *ev)
111 CORBA_Object obj;
113 obj = get_desktop ();
114 if (obj == CORBA_OBJECT_NIL)
115 return FALSE;
117 GNOME_FileManager_Desktop_rescan_devices (obj, ev);
118 CORBA_Object_release (obj, ev);
119 return TRUE;
122 /* Arrange the desktop icons */
123 static int
124 arrange_desktop_icons (const char *type, CORBA_Environment *ev)
126 CORBA_Object obj;
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;
141 else {
142 fprintf (stderr, _("Unknown arrange type `%s'\n"), type);
143 return FALSE;
146 obj = get_desktop ();
147 if (obj == CORBA_OBJECT_NIL)
148 return FALSE;
150 GNOME_FileManager_Desktop_arrange_icons (obj, arr_type, ev);
151 CORBA_Object_release (obj, ev);
152 return TRUE;
155 /* Close invalid windows */
156 static int
157 close_invalid_windows (CORBA_Environment *ev)
159 CORBA_Object obj;
161 obj = get_window_factory ();
162 if (obj == CORBA_OBJECT_NIL)
163 return FALSE;
165 GNOME_FileManager_WindowFactory_close_invalid_windows (obj, ev);
166 CORBA_Object_release (obj, ev);
167 return TRUE;
172 /* Option arguments */
174 enum {
175 ARG_CREATE_WINDOW,
176 ARG_RESCAN_DIRECTORY,
177 ARG_RESCAN_DESKTOP,
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 */
188 static void
189 parse_an_arg (poptContext ctx,
190 enum poptCallbackReason reason,
191 const struct poptOption *opt,
192 char *arg,
193 void *data)
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);
199 exit (1);
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)
226 poptContext ctx;
227 CORBA_Environment ev;
228 CORBA_ORB orb;
229 int result = FALSE;
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,
237 0, &ev);
239 switch (selected_option) {
240 case ARG_CREATE_WINDOW:
241 result = create_window (directory, &ev);
242 break;
244 case ARG_RESCAN_DIRECTORY:
245 result = rescan_directory (directory, &ev);
246 break;
248 case ARG_RESCAN_DESKTOP:
249 result = rescan_desktop (&ev);
250 break;
252 case ARG_RESCAN_DESKTOP_DEVICES:
253 result = rescan_desktop_devices (&ev);
254 break;
256 case ARG_ARRANGE_DESKTOP_ICONS:
257 result = arrange_desktop_icons (arrange_type, &ev);
258 break;
260 case ARG_CLOSE_INVALID_WINDOWS:
261 result = close_invalid_windows (&ev);
262 break;
264 default:
265 g_assert_not_reached ();
268 if (!result || ev._major != CORBA_NO_EXCEPTION) {
269 poptFreeContext (ctx);
270 exit (1);
273 CORBA_exception_free (&ev);
274 poptFreeContext (ctx);
275 return 0;