ru.po: Corrections from Evgeny Bulgakov <bgav@netvision.net.il>
[midnight-commander.git] / gnome / gmc-client.c
blobfd32d5153c386c4edd8b955faf69422d2db24a81
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 /* Close invalid windows */
123 static int
124 close_invalid_windows (CORBA_Environment *ev)
126 CORBA_Object obj;
128 obj = get_window_factory ();
129 if (obj == CORBA_OBJECT_NIL)
130 return FALSE;
132 GNOME_FileManager_WindowFactory_close_invalid_windows (obj, ev);
133 CORBA_Object_release (obj, ev);
134 return TRUE;
139 /* Option arguments */
141 enum {
142 ARG_CREATE_WINDOW,
143 ARG_RESCAN_DIRECTORY,
144 ARG_RESCAN_DESKTOP,
145 ARG_RESCAN_DESKTOP_DEVICES,
146 ARG_CLOSE_INVALID_WINDOWS
149 static int selected_option = -1;
150 static char *directory;
152 /* Parse an argument */
153 static void
154 parse_an_arg (poptContext ctx,
155 enum poptCallbackReason reason,
156 const struct poptOption *opt,
157 char *arg,
158 void *data)
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);
164 exit (1);
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)
188 poptContext ctx;
189 CORBA_Environment ev;
190 CORBA_ORB orb;
191 int result;
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,
199 0, &ev);
201 switch (selected_option) {
202 case ARG_CREATE_WINDOW:
203 result = create_window (directory, &ev);
204 break;
206 case ARG_RESCAN_DIRECTORY:
207 result = rescan_directory (directory, &ev);
208 break;
210 case ARG_RESCAN_DESKTOP:
211 result = rescan_desktop (&ev);
212 break;
214 case ARG_RESCAN_DESKTOP_DEVICES:
215 result = rescan_desktop_devices (&ev);
216 break;
218 case ARG_CLOSE_INVALID_WINDOWS:
219 result = close_invalid_windows (&ev);
220 break;
222 default:
223 g_assert_not_reached ();
226 if (!result || ev._major != CORBA_NO_EXCEPTION) {
227 poptFreeContext (ctx);
228 exit (1);
231 CORBA_exception_free (&ev);
232 poptFreeContext (ctx);
233 return 0;