Idle fixes
[wmaker-crm.git] / util / wmgenmenu.c
bloba90019364ff12e178429d8a28b22bdefaa05d5f0
1 /* Copyright (C) 2010 Carlos R. Mafra */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <locale.h>
7 #include <libintl.h>
8 #define _(text) gettext(text)
10 #include <WINGs/WUtil.h>
12 #define MAX_NR_APPS 50 /* Maximum number of entries in each apps list */
13 #define MAX_WMS 10 /* Maximum number of other window managers to check */
14 #include "wmgenmenu.h"
16 static void find_and_write(char **list);
17 static inline void workspaces(void);
18 static inline void lock_screen(void);
19 static inline void wmaker_config(void);
20 static inline void run_command(void);
21 static void other_window_managers(char **other_wm);
22 static inline void wm_visual(void);
23 static inline void write_first_line(int count);
25 char *path;
27 int main(int argc, char *argv[])
29 char *locale;
30 extern char *path;
32 path = getenv("PATH");
33 locale = getenv("LANG");
34 setlocale(LC_ALL, "");
36 if (getenv("NLSPATH"))
37 bindtextdomain("wmgenmenu", getenv("NLSPATH"));
38 else
39 bindtextdomain("wmgenmenu", LOCALEDIR);
41 bind_textdomain_codeset("wmgenmenu", "UTF-8");
42 textdomain("wmgenmenu");
44 printf("\(\"Window Maker\",\n");
46 printf(" \(\"");
47 printf(_("Applications"));
48 printf("\",\n");
50 /* This "first" printf is different from the others! */
51 printf(" \(\"");
52 printf(_("Terminals"));
53 printf("\"");
54 find_and_write(terminals);
56 printf("\n ),\n \(\"");
57 printf(_("Internet"));
58 printf("\"");
59 find_and_write(internet);
61 printf("\n ),\n \(\"");
62 printf(_("Email"));
63 printf("\"");
64 find_and_write(email);
66 printf("\n ),\n \(\"");
67 printf(_("Mathematics"));
68 printf("\"");
69 find_and_write(Mathematiks);
71 printf("\n ),\n \(\"");
72 printf(_("File Managers"));
73 printf("\"");
74 find_and_write(file_managers);
76 printf("\n ),\n \(\"");
77 printf(_("Graphics"));
78 printf("\"");
79 find_and_write(Graphics);
81 printf("\n ),\n \(\"");
82 printf(_("Multimedia"));
83 printf("\"");
84 find_and_write(Multimedia);
86 printf("\n ),\n \(\"");
87 printf(_("Editors"));
88 printf("\"");
89 find_and_write(Editors);
91 printf("\n ),\n \(\"");
92 printf(_("Development"));
93 printf("\"");
94 find_and_write(development);
96 printf("\n ),\n \(\"");
97 printf(_("Window Maker"));
98 printf("\"");
99 find_and_write(WindowMaker);
101 printf("\n ),\n \(\"");
102 printf(_("Office"));
103 printf("\"");
104 find_and_write(Office);
106 printf("\n ),\n \(\"");
107 printf(_("Astronomy"));
108 printf("\"");
109 find_and_write(Astronomie);
111 printf("\n ),\n \(\"");
112 printf(_("Sound"));
113 printf("\"");
114 find_and_write(Sound);
116 printf("\n ),\n \(\"");
117 printf(_("Comics"));
118 printf("\"");
119 find_and_write(Comics);
121 printf("\n ),\n \(\"");
122 printf(_("Viewers"));
123 printf("\"");
124 find_and_write(Viewers);
126 printf("\n ),\n \(\"");
127 printf(_("Utilities"));
128 printf("\"");
129 find_and_write(Utilities);
131 printf("\n ),\n \(\"");
132 printf(_("System"));
133 printf("\"");
134 find_and_write(System);
136 printf("\n ),\n \(\"");
137 printf(_("Video"));
138 printf("\"");
139 find_and_write(Video);
141 printf("\n ),\n \(\"");
142 printf(_("Chat and Talk"));
143 printf("\"");
144 find_and_write(Chat);
146 printf("\n ),\n \(\"");
147 printf(_("P2P-Network"));
148 printf("\"");
149 find_and_write(P2P);
151 printf("\n ),\n \(\"");
152 printf(_("Games"));
153 printf("\"");
154 find_and_write(Games);
156 printf("\n ),\n \(\"");
157 printf(_("OpenSUSE"));
158 printf("\"");
159 find_and_write(OpenSUSE);
161 printf("\n ),\n \(\"");
162 printf(_("Mandriva"));
163 printf("\"");
164 find_and_write(Mandriva);
166 /* This must be after the last entry */
167 printf("\n )\n");
168 printf(" ),\n");
170 run_command();
171 wm_visual();
172 workspaces();
173 wmaker_config();
175 printf("(\"");
176 printf(_("Info Panel"));
177 printf("\", INFO_PANEL),\n");
179 printf("(\"");
180 printf(_("Restart"));
181 printf("\", RESTART),\n");
183 other_window_managers(other_wm);
184 lock_screen();
186 printf("(\"");
187 printf(_("Exit..."));
188 printf("\", EXIT)\n");
190 /* Final closing parenthesis */
191 printf(")\n");
193 exit(EXIT_SUCCESS);
196 static void find_and_write(char **list)
198 int i, argc;
199 char *location, **argv;
200 extern char *path;
202 for (i = 0; i <= MAX_NR_APPS; i++) {
203 if (list[i]) {
204 /* Before checking if app exists, split its options */
205 wtokensplit(list[i], &argv, &argc);
206 location = wfindfile(path, argv[0]);
207 if (location) {
208 /* check whether it is to be executed in a terminal */
209 if (strcmp("!", argv[argc - 1]) < 0)
210 printf(",\n \(\"%s\", EXEC, \"%s\")", argv[0], list[i]);
211 else {
212 char comm[50], *ptr[1];
214 strcpy(comm, list[i]);
215 /* ugly hack to delete character ! from list[i] */
216 ptr[0] = strchr(comm,'!');
217 *ptr[0] = ' ';
218 printf(",\n \(\"%s\", EXEC, \"xterm -e %s\")", argv[0], comm);
225 static inline void wmaker_config(void)
227 char *location = wfindfile(path, "WPrefs");
229 if (location) {
230 printf("(\"");
231 printf(_("Config wmaker..."));
232 printf("\", EXEC, \"WPrefs\"),\n");
236 static inline void workspaces(void)
238 printf("(\"");
239 printf(_("Workspaces"));
240 printf("\", WORKSPACE_MENU),\n");
242 printf(" (\"");
243 printf(_("Workspace"));
244 printf("\",\n");
246 printf(" (\"");
247 printf(_("Hide others"));
248 printf("\", HIDE_OTHERS),\n");
250 printf(" (\"");
251 printf(_("Show all"));
252 printf("\", SHOW_ALL),\n");
254 printf(" (\"");
255 printf(_("Arrange Icons"));
256 printf("\", ARRANGE_ICONS),\n");
258 printf(" (\"");
259 printf(_("Refresh"));
260 printf("\", REFRESH),\n");
262 printf(" (\"");
263 printf(_("Save Session"));
264 printf("\", SAVE_SESSION),\n");
266 printf(" (\"");
267 printf(_("Clear Session"));
268 printf("\", CLEAR_SESSION)\n");
270 printf(" ),\n");
273 static inline void lock_screen(void)
275 char *location;
277 location = wfindfile(path, "xlock");
278 if (location) {
279 printf("(\"");
280 printf(_("Lock Screen"));
281 printf("\", EXEC, \"xlock -allowroot -usefirst -mode matrix\"),\n");
285 static void other_window_managers(char **other_wm)
287 int count = 0;
288 char *location;
289 int i;
291 printf("(\"");
292 printf(_("Other Window Managers"));
293 printf("\",\n");
295 for (i = 0; i <= MAX_WMS; i++) {
296 if (other_wm[i]) {
297 location = wfindfile(path, other_wm[i]);
298 if (location) {
299 write_first_line(count);
300 printf(_("Start %s"), other_wm[i]);
301 printf("\", RESTART, \"%s\")", other_wm[i]);
302 count++;
306 printf("\n),\n");
309 static void wm_visual(void)
311 /* TODO: add more pre-defined dirs to Themes etc */
312 printf("(\"");
313 printf(_("Workspace Appearance"));
314 printf("\",\n");
316 printf("(\"");
317 printf(_("Themes"));
318 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/Themes WITH setstyle\"),\n");
320 printf("(\"");
321 printf(_("Styles"));
322 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/Styles WITH setstyle\"),\n");
324 printf("(\"");
325 printf(_("Icons"));
326 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/IconSets WITH seticons\"),\n");
328 printf("(\"");
329 printf(_("Background"));
330 printf("\", OPEN_MENU, \"-noext $HOME/GNUstep/Library/WindowMaker/Backgrounds WITH wmsetbg -u -t\"),\n");
332 printf("(\"");
333 printf(_("Save Theme"));
334 printf("\", SHEXEC, \"getstyle -t $HOME/GNUstep/Library/WindowMaker/Themes/\\\"%%a(Theme name)\\\"\"),\n");
336 printf("(\"");
337 printf(_("Save Icons"));
338 printf("\", SHEXEC, \"geticonset $HOME/GNUstep/Library/WindowMaker/IconSets/\\\"%%a(IconSet name)\\\"\")\n");
339 printf("),\n");
343 static inline void run_command(void)
346 * %A below requires Voinov's "Add dialog history" (which
347 * is included in wmaker-crm), otherwise it should be %a
349 printf("\(\"");
350 printf(_("Run..."));
351 printf("\", SHEXEC, \"%%A(");
352 printf(_("Run, Type command:"));
353 printf(")\"),\n");
356 static inline void write_first_line(int count)
358 /* All lines inside a menu must end with a comma, except for
359 * the last one. To cope with this let's check if there is a
360 * previous entry before writing the "start of the line", and
361 * write the trailing comma if there is.
363 if (count == 0)
364 printf(" (\"");
365 else {
366 printf(",\n (\"");