2 Copyright (C) 1995 The Free Software Foundation
4 Written by: 1995 Janne Kukonlehto
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include <sys/types.h>
32 /* Needed for the extern declarations of integer parameters */
33 #define DIR_H_INCLUDE_HANDLE_DIRENT
35 #include "tty.h" /* attrset() */
40 #include "dialog.h" /* For do_refresh() */
41 #include "wtools.h" /* For common_dialog_repaint() */
42 #include "setup.h" /* For profile_bname */
43 #include "profile.h" /* Load/save directories panelize */
45 #include "panel.h" /* cpanel */
46 #include "main.h" /* repaint_screen */
58 #define B_REMOVE B_USER + 1
60 static WListbox
*l_panelize
;
61 static Dlg_head
*panelize_dlg
;
62 static int last_listitem
;
66 int ret_cmd
, flags
, y
, x
;
69 } panelize_but
[BUTTONS
] = {
70 { B_CANCEL
, NORMAL_BUTTON
, 0, 53, N_("&Cancel"), "c"},
71 { B_ADD
, NORMAL_BUTTON
, 0, 28, N_("&Add new"), "a"},
72 { B_REMOVE
, NORMAL_BUTTON
, 0, 16, N_("&Remove"), "r"},
73 { B_ENTER
, DEFPUSH_BUTTON
, 0, 0, N_("Pane&lize"),"l"},
76 static char *panelize_section
= "Panelize";
78 /* Directory panelize */
79 static struct panelize
{
82 struct panelize
*next
;
88 if (l_panelize
->pos
!= last_listitem
) {
89 last_listitem
= l_panelize
->pos
;
91 ((struct panelize
*) l_panelize
->current
->data
)->command
);
93 update_input (pname
, 1);
98 panelize_callback (Dlg_head
* h
, int Par
, int Msg
)
102 common_dialog_repaint (h
);
103 attrset (COLOR_NORMAL
);
104 draw_box (h
, UY
, UX
, h
->lines
- 10, h
->cols
- 10);
110 attrset (MENU_ENTRY_COLOR
);
117 static int l_call (void *data
)
119 return listbox_nothing
;
122 static void init_panelize (void)
124 int i
, panelize_cols
= COLS
- 6;
125 struct panelize
*current
= panelize
;
128 static int i18n_flag
= 0;
129 static int maxlen
= 0;
133 i
= sizeof(panelize_but
) / sizeof(panelize_but
[0]);
136 panelize_but
[i
].text
= _(panelize_but
[i
].text
);
137 maxlen
+= strlen (panelize_but
[i
].text
) + 5;
143 panelize_cols
= max(panelize_cols
, maxlen
);
145 panelize_but
[2].x
= panelize_but
[3].x
146 + strlen (panelize_but
[3].text
) + 7;
147 panelize_but
[1].x
= panelize_but
[2].x
148 + strlen (panelize_but
[2].text
) + 5;
149 panelize_but
[0].x
= panelize_cols
150 - strlen (panelize_but
[0].text
) - 8 - BX
;
152 #endif /* ENABLE_NLS */
158 panelize_dlg
= create_dlg (0, 0, 22, panelize_cols
, dialog_colors
,
159 panelize_callback
, "[External panelize]",
160 _("External panelize"), DLG_CENTER
);
162 #define XTRACT(i) BY+panelize_but[i].y, BX+panelize_but[i].x, panelize_but[i].ret_cmd, panelize_but[i].flags, panelize_but[i].text, 0, 0, panelize_but[i].tkname
164 for (i
= 0; i
< BUTTONS
; i
++)
165 add_widget(panelize_dlg
, button_new (XTRACT (i
)));
167 pname
= input_new (UY
+14, UX
, INPUT_COLOR
, panelize_dlg
->cols
-10, "", "in");
168 add_widget (panelize_dlg
, pname
);
170 add_widget (panelize_dlg
, label_new (UY
+13, UX
, _("Command"), "label-command"));
172 /* get new listbox */
173 l_panelize
= listbox_new (UY
+ 1, UX
+ 1, panelize_dlg
->cols
-12, 10, 0, l_call
, "li");
176 listbox_add_item (l_panelize
, 0, 0, current
->label
, current
);
177 current
= current
->next
;
180 /* add listbox to the dialogs */
181 add_widget (panelize_dlg
, l_panelize
);
183 listbox_select_entry (l_panelize
,
184 listbox_search_text (l_panelize
, _("Other command")));
187 static void panelize_done (void)
189 destroy_dlg (panelize_dlg
);
193 static void add2panelize (char *label
, char *command
)
195 struct panelize
*current
, *old
;
199 while (current
&& strcmp (current
->label
, label
) <= 0){
201 current
= current
->next
;
205 panelize
= g_new (struct panelize
, 1);
206 panelize
->label
= label
;
207 panelize
->command
= command
;
208 panelize
->next
= current
;
210 struct panelize
*new;
211 new = g_new (struct panelize
, 1);
213 new->command
= command
;
220 add2panelize_cmd (void)
224 if (pname
->buffer
&& (*pname
->buffer
)) {
225 label
= input_dialog (_(" Add to external panelize "),
226 _(" Enter command label: "),
235 add2panelize (label
, g_strdup (pname
->buffer
));
239 static void remove_from_panelize (struct panelize
*entry
)
241 if (strcmp (entry
->label
, _("Other command")) != 0) {
242 if (entry
== panelize
) {
243 panelize
= panelize
->next
;
245 struct panelize
*current
= panelize
;
246 while (current
&& current
->next
!= entry
)
247 current
= current
->next
;
249 current
->next
= entry
->next
;
253 g_free (entry
->label
);
254 g_free (entry
->command
);
260 external_panelize (void)
264 if (!vfs_current_is_local ()){
265 message (1, MSG_ERROR
,
266 _(" Cannot run external panelize in a non-local directory "));
272 /* display file info */
273 attrset (SELECTED_COLOR
);
275 run_dlg (panelize_dlg
);
277 switch (panelize_dlg
->ret_value
) {
286 remove_from_panelize (l_panelize
->current
->data
);
290 target
= pname
->buffer
;
291 if (target
!= NULL
&& *target
) {
292 char *cmd
= g_strdup (target
);
293 destroy_dlg (panelize_dlg
);
294 do_external_panelize (cmd
);
305 void load_panelize (void)
310 profile_keys
= profile_init_iterator (panelize_section
, profile_name
);
312 add2panelize (g_strdup (_("Other command")), g_strdup (""));
315 add2panelize (g_strdup (_("Find rejects after patching")), g_strdup ("find . -name \\*.rej -print"));
316 add2panelize (g_strdup (_("Find *.orig after patching")), g_strdup ("find . -name \\*.orig -print"));
317 add2panelize (g_strdup (_("Find SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
321 while (profile_keys
){
322 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
323 add2panelize (g_strdup (key
), g_strdup (value
));
327 void save_panelize (void)
329 struct panelize
*current
= panelize
;
331 profile_clean_section (panelize_section
, profile_name
);
332 for (;current
; current
= current
->next
){
333 if (strcmp (current
->label
, _("Other command")))
334 WritePrivateProfileString (panelize_section
,
342 void done_panelize (void)
344 struct panelize
*current
= panelize
;
345 struct panelize
*next
;
347 for (; current
; current
= next
){
348 next
= current
->next
;
349 g_free (current
->label
);
350 g_free (current
->command
);
355 void do_external_panelize (char *command
)
357 int status
, link_to_dir
, stale_link
;
360 dir_list
*list
= &cpanel
->dir
;
361 char line
[MC_MAXPATHLEN
];
366 external
= popen (command
, "r");
368 close_error_pipe (1, _("Cannot invoke command."));
371 /* Clear the counters and the directory list */
372 panel_clean_dir (cpanel
);
376 if (fgets (line
, MC_MAXPATHLEN
, external
) == NULL
) {
377 if (ferror(external
) && errno
== EINTR
)
382 if (line
[strlen(line
)-1] == '\n')
383 line
[strlen(line
)-1] = 0;
384 if (strlen(line
) < 1)
386 if (line
[0] == '.' && line
[1] == PATH_SEP
)
390 status
= handle_path (list
, name
, &buf
, next_free
, &link_to_dir
,
396 list
->list
[next_free
].fnamelen
= strlen (name
);
397 list
->list
[next_free
].fname
= g_strdup (name
);
398 file_mark (cpanel
, next_free
, 0);
399 list
->list
[next_free
].f
.link_to_dir
= link_to_dir
;
400 list
->list
[next_free
].f
.stale_link
= stale_link
;
401 list
->list
[next_free
].f
.dir_size_computed
= 0;
402 list
->list
[next_free
].buf
= buf
;
404 if (!(next_free
& 32))
408 cpanel
->is_panelized
= 1;
410 cpanel
->count
= next_free
;
411 if (list
->list
[0].fname
[0] == PATH_SEP
){
412 strcpy (cpanel
->cwd
, PATH_SEP_STR
);
413 chdir (PATH_SEP_STR
);
416 cpanel
->count
= set_zero_dir (list
);
419 if (pclose (external
) < 0)
420 #else /* SCO_FLAVOR */
421 if (WEXITSTATUS(pclose (external
)) < 0)
422 #endif /* SCO_FLAVOR */
423 message (0, _("External panelize"), _("Pipe close failed"));
424 close_error_pipe (0, 0);
425 try_to_select (cpanel
, NULL
);
426 panel_re_sort (cpanel
);
427 paint_panel (cpanel
);