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
40 #include "dialog.h" /* For do_refresh() */
41 #include "setup.h" /* For profile_bname */
42 #include "profile.h" /* Load/save directories panelize */
44 #include "panel.h" /* Needed for the externs */
47 #include "../vfs/vfs.h"
50 void do_external_panelize (char *command
);
61 #define B_REMOVE B_USER + 1
63 static WListbox
*l_panelize
;
64 static Dlg_head
*panelize_dlg
;
65 static int last_listitem
;
69 int ret_cmd
, flags
, y
, x
;
72 } panelize_but
[BUTTONS
] = {
73 { B_CANCEL
, NORMAL_BUTTON
, 0, 53, N_("&Cancel"), "c"},
74 { B_ADD
, NORMAL_BUTTON
, 0, 28, N_("&Add new"), "a"},
75 { B_REMOVE
, NORMAL_BUTTON
, 0, 16, N_("&Remove"), "r"},
76 { B_ENTER
, DEFPUSH_BUTTON
, 0, 0, N_("Pane&lize"),"l"},
79 static char *panelize_section
= "Panelize";
81 /* Directory panelize */
82 static struct panelize
{
85 struct panelize
*next
;
88 static char* panelize_title
= N_(" External panelize ");
91 panelize_refresh (void)
93 attrset (COLOR_NORMAL
);
94 dlg_erase (panelize_dlg
);
96 draw_box (panelize_dlg
, 1, 2, panelize_dlg
->lines
-2, panelize_dlg
->cols
-4);
97 draw_box (panelize_dlg
, UY
, UX
, panelize_dlg
->lines
-10, panelize_dlg
->cols
-10);
99 attrset (COLOR_HOT_NORMAL
);
100 dlg_move (panelize_dlg
, 1, (panelize_dlg
->cols
- strlen(panelize_title
)) / 2);
101 addstr (panelize_title
);
105 update_command (void)
107 if (l_panelize
->pos
!= last_listitem
) {
108 last_listitem
= l_panelize
->pos
;
110 ((struct panelize
*) l_panelize
->current
->data
)->command
);
112 update_input (pname
, 1);
117 panelize_callback (Dlg_head
* h
, int Par
, int Msg
)
127 attrset (MENU_ENTRY_COLOR
);
134 static int l_call (void *data
)
136 return listbox_nothing
;
139 static void init_panelize (void)
141 int i
, panelize_cols
= COLS
- 6;
142 struct panelize
*current
= panelize
;
145 static int i18n_flag
= 0;
146 static int maxlen
= 0;
150 i
= sizeof(panelize_but
) / sizeof(panelize_but
[0]);
153 panelize_but
[i
].text
= _(panelize_but
[i
].text
);
154 maxlen
+= strlen (panelize_but
[i
].text
) + 5;
157 panelize_title
= _(panelize_title
);
161 panelize_cols
= max(panelize_cols
, maxlen
);
163 panelize_but
[2].x
= panelize_but
[3].x
164 + strlen (panelize_but
[3].text
) + 7;
165 panelize_but
[1].x
= panelize_but
[2].x
166 + strlen (panelize_but
[2].text
) + 5;
167 panelize_but
[0].x
= panelize_cols
168 - strlen (panelize_but
[0].text
) - 8 - BX
;
170 #endif /* ENABLE_NLS */
176 panelize_dlg
= create_dlg (0, 0, 22, panelize_cols
, dialog_colors
,
177 panelize_callback
, "[External panelize]", "panelize",
178 DLG_CENTER
|DLG_GRID
);
179 x_set_dialog_title (panelize_dlg
, _("External panelize"));
181 #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
183 for (i
= 0; i
< BUTTONS
; i
++)
184 add_widget(panelize_dlg
, button_new (XTRACT (i
)));
186 pname
= input_new (UY
+14, UX
, INPUT_COLOR
, panelize_dlg
->cols
-10, "", "in");
187 add_widget (panelize_dlg
, pname
);
189 add_widget (panelize_dlg
, label_new (UY
+13, UX
, _("Command"), "label-command"));
191 /* get new listbox */
192 l_panelize
= listbox_new (UY
+ 1, UX
+ 1, panelize_dlg
->cols
-12, 10, 0, l_call
, "li");
195 listbox_add_item (l_panelize
, 0, 0, current
->label
, current
);
196 current
= current
->next
;
199 /* add listbox to the dialogs */
200 add_widget (panelize_dlg
, l_panelize
);
202 listbox_select_entry (l_panelize
,
203 listbox_search_text (l_panelize
, _("Other command")));
206 static void panelize_done (void)
208 destroy_dlg (panelize_dlg
);
212 static void add2panelize (char *label
, char *command
)
214 struct panelize
*current
, *old
;
218 while (current
&& strcmp (current
->label
, label
) <= 0){
220 current
= current
->next
;
224 panelize
= g_new (struct panelize
, 1);
225 panelize
->label
= label
;
226 panelize
->command
= command
;
227 panelize
->next
= current
;
229 struct panelize
*new;
230 new = g_new (struct panelize
, 1);
232 new->command
= command
;
239 add2panelize_cmd (void)
243 if (pname
->buffer
&& (*pname
->buffer
)) {
244 label
= input_dialog (_(" Add to external panelize "),
245 _(" Enter command label: "),
254 add2panelize (label
, g_strdup (pname
->buffer
));
258 static void remove_from_panelize (struct panelize
*entry
)
260 if (strcmp (entry
->label
, _("Other command")) != 0) {
261 if (entry
== panelize
) {
262 panelize
= panelize
->next
;
264 struct panelize
*current
= panelize
;
265 while (current
&& current
->next
!= entry
)
266 current
= current
->next
;
268 current
->next
= entry
->next
;
272 g_free (entry
->label
);
273 g_free (entry
->command
);
279 external_panelize (void)
283 if (!vfs_current_is_local ()){
284 message (1, _(" Oops... "),
285 _(" I can't run external panelize while logged on a non local directory "));
291 /* display file info */
292 attrset (SELECTED_COLOR
);
294 run_dlg (panelize_dlg
);
296 switch (panelize_dlg
->ret_value
) {
305 remove_from_panelize (l_panelize
->current
->data
);
309 target
= pname
->buffer
;
310 if (target
!= NULL
&& *target
) {
311 char *cmd
= g_strdup (target
);
312 destroy_dlg (panelize_dlg
);
313 do_external_panelize (cmd
);
324 void load_panelize (void)
329 profile_keys
= profile_init_iterator (panelize_section
, profile_name
);
331 add2panelize (g_strdup (_("Other command")), g_strdup (""));
334 add2panelize (g_strdup (_("Find rejects after patching")), g_strdup ("find . -name \\*.rej -print"));
335 add2panelize (g_strdup (_("Find *.orig after patching")), g_strdup ("find . -name \\*.orig -print"));
336 add2panelize (g_strdup (_("Find SUID and SGID programs")), g_strdup ("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
340 while (profile_keys
){
341 profile_keys
= profile_iterator_next (profile_keys
, &key
, &value
);
342 add2panelize (g_strdup (key
), g_strdup (value
));
346 void save_panelize (void)
348 struct panelize
*current
= panelize
;
350 profile_clean_section (panelize_section
, profile_name
);
351 for (;current
; current
= current
->next
){
352 if (strcmp (current
->label
, _("Other command")))
353 WritePrivateProfileString (panelize_section
,
361 void done_panelize (void)
363 struct panelize
*current
= panelize
;
364 struct panelize
*next
;
366 for (; current
; current
= next
){
367 next
= current
->next
;
368 g_free (current
->label
);
369 g_free (current
->command
);
374 void do_external_panelize (char *command
)
376 int status
, link_to_dir
, stalled_link
;
379 dir_list
*list
= &cpanel
->dir
;
380 char line
[MC_MAXPATHLEN
];
385 external
= popen (command
, "r");
387 close_error_pipe (1, _("Cannot invoke command."));
390 /* Clear the counters and the directory list */
391 panel_clean_dir (cpanel
);
395 if (fgets (line
, MC_MAXPATHLEN
, external
) == NULL
) {
396 if (ferror(external
) && errno
== EINTR
)
401 if (line
[strlen(line
)-1] == '\n')
402 line
[strlen(line
)-1] = 0;
403 if (strlen(line
) < 1)
405 if (line
[0] == '.' && line
[1] == PATH_SEP
)
409 status
= handle_path (list
, name
, &buf
, next_free
, &link_to_dir
,
415 list
->list
[next_free
].fnamelen
= strlen (name
);
416 list
->list
[next_free
].fname
= g_strdup (name
);
417 file_mark (cpanel
, next_free
, 0);
418 list
->list
[next_free
].f
.link_to_dir
= link_to_dir
;
419 list
->list
[next_free
].f
.stalled_link
= stalled_link
;
420 list
->list
[next_free
].f
.dir_size_computed
= 0;
421 list
->list
[next_free
].buf
= buf
;
423 if (!(next_free
& 32))
427 cpanel
->is_panelized
= 1;
429 cpanel
->count
= next_free
;
430 if (list
->list
[0].fname
[0] == PATH_SEP
){
431 strcpy (cpanel
->cwd
, PATH_SEP_STR
);
432 chdir (PATH_SEP_STR
);
435 cpanel
->count
= set_zero_dir (list
);
438 if (pclose (external
) < 0)
439 #else /* SCO_FLAVOR */
440 if (WEXITSTATUS(pclose (external
)) < 0)
441 #endif /* SCO_FLAVOR */
442 message (0, _("External panelize"), _("Pipe close failed"));
443 close_error_pipe (0, 0);
444 try_to_select (cpanel
, NULL
);
445 panel_re_sort (cpanel
);
446 paint_panel (cpanel
);