8 #define WANT_WIDGETS /* bleah */
12 #include "layout.h" /* get_panel_widget */
13 #include "ext.h" /* regex_command */
14 #include "cmd.h" /* copy_cmd, ren_cmd, delete_cmd, ... */
21 #include "../vfs/vfs.h"
22 #include "gnome-open-dialog.h"
25 gmc_unable_to_execute_dlg (gchar
*fname
, const gchar
*command
, gchar
*action
, const gchar
*mime
)
27 GtkWidget
*msg_dialog
= NULL
;
28 GtkWidget
*hack_widget
;
31 if (!strcmp (action
, "x-gnome-app-info")) {
32 msg
= g_strdup_printf (
33 _("Unable to execute\n\"%s\".\n\n"
34 "Please check it to see if it points to a valid command."),
39 fix
= g_strdup_printf (
40 _("\".\n\nTo fix this, bring up the mime-properties editor "
41 "in the GNOME Control Center, and edit the default %s"
42 "-action for \"%s\"."),
45 fix
= g_strdup_printf (
46 _("\".\n\nTo fix this error, bring up this file's properties "
47 "and change the default %s-action."),
50 msg
= g_strdup_printf (
51 _("Unable to %s\n\"%s\"\nwith the command:\n\"%s\"%s"),
52 action
, fname
, command
, fix
);
56 msg_dialog
= gnome_message_box_new (msg
,
57 GNOME_MESSAGE_BOX_ERROR
,
58 GNOME_STOCK_BUTTON_OK
,
60 /* Kids, don't try this at home */
61 /* this is pretty evil... <-: */
62 hack_widget
= GNOME_DIALOG (msg_dialog
)->vbox
;
63 hack_widget
= ((GtkBoxChild
*) GTK_BOX (hack_widget
)->children
->data
)->widget
;
64 hack_widget
= ((GtkBoxChild
*) GTK_BOX (hack_widget
)->children
->next
->data
)->widget
;
65 gtk_label_set_line_wrap (GTK_LABEL (hack_widget
), TRUE
);
67 gnome_dialog_run_and_close (GNOME_DIALOG (msg_dialog
));
72 gmc_execute (const char *fname
, const char *buf
, int needs_terminal
)
74 exec_extension (fname
, buf
, NULL
, NULL
, 0, needs_terminal
);
78 gmc_check_exec_string (const char *buf
)
85 gnome_config_make_vector (buf
, &argc
, &argv
);
89 prog
= gnome_is_program_in_path (argv
[0]);
95 /* check to see if it's a GMC directive. */
96 if ((strlen (argv
[0]) > 1) && (argv
[0][0] == '%') && (argv
[0][1] != '%'))
98 for (i
= 0; i
< argc
; i
++)
105 gmc_open_filename (char *fname
, GList
*args
)
107 /* fname is a full name */
109 const char *mime_type
;
113 int needs_terminal
= 0;
116 mime_type
= gnome_mime_type_or_default_of_file (fname
, NULL
);
118 mime_type
= gnome_mime_type_or_default (fname
, NULL
);
121 * We accept needs_terminal as -1, which means our caller
122 * did not want to do the work
124 if (gnome_metadata_get (fname
, "flags", &size
, &buf
) == 0){
125 needs_terminal
= (strstr (buf
, "needsterminal") != 0);
128 } else if (mime_type
)
129 needs_terminal
= gnome_mime_needsterminal (mime_type
, "open.flags");
131 if (gnome_metadata_get (fname
, "fm-open", &size
, &buf
) != 0)
132 gnome_metadata_get (fname
, "open", &size
, &buf
);
135 if (gmc_check_exec_string (buf
))
136 gmc_execute (fname
, buf
, needs_terminal
);
138 gmc_unable_to_execute_dlg (fname
, buf
, _("open"), NULL
);
146 cmd
= gnome_mime_get_value (mime_type
, "fm-open");
148 cmd
= gnome_mime_get_value (mime_type
, "open");
152 if (gmc_check_exec_string (cmd
))
153 gmc_execute (fname
, cmd
, needs_terminal
);
155 gmc_unable_to_execute_dlg (fname
, cmd
, _("open"), mime_type
);
159 if ((strcmp (mime_type
, "application/x-gnome-app-info") == 0) ||
160 (strcmp (mime_type
, "application/x-kde-app-info") == 0)){
161 GnomeDesktopEntry
*entry
;
163 entry
= gnome_desktop_entry_load (fname
);
166 gnome_desktop_entry_launch (entry
);
167 gnome_desktop_entry_free (entry
);
170 gmc_unable_to_execute_dlg (fname
, NULL
, "x-gnome-app-info", NULL
);
175 /* We just struck out. Prompt the user. */
180 gmc_edit (char *fname
)
182 /* fname is a full path */
184 const char *mime_type
;
191 if (gnome_metadata_get (fname
, "edit", &size
, &buf
) == 0){
192 if (gmc_check_exec_string (buf
))
193 gmc_execute (fname
, buf
, 0);
195 gmc_unable_to_execute_dlg (fname
, buf
, _("edit"), NULL
);
201 mime_type
= gnome_mime_type_or_default_of_file (fname
, NULL
);
203 mime_type
= gnome_mime_type_or_default (fname
, NULL
);
206 cmd
= gnome_mime_get_value (mime_type
, "edit");
209 if (gmc_check_exec_string (cmd
))
210 gmc_execute (fname
, cmd
, 0);
212 gmc_unable_to_execute_dlg (fname
, cmd
, _("edit"), mime_type
);
217 gnome_config_push_prefix( "/editor/Editor/");
218 type
= gnome_config_get_string ("EDITOR_TYPE=executable");
220 if (strcmp (type
, "mc-internal") == 0){
227 editor
= gnome_config_get_string ("EDITOR=emacs");
228 on_terminal
= gnome_config_get_bool ("NEEDS_TERM=false");
231 char *quoted
= name_quote (fname
, 0);
232 char *editor_cmd
= g_strconcat (editor
, " ", quoted
, NULL
);
234 gnome_open_terminal_with_cmd (editor_cmd
);
238 char *cmd
= g_strconcat (editor
, " %s", NULL
);
240 gmc_execute (fname
, cmd
, 0);
249 gmc_open (file_entry
*fe
)
253 fullname
= g_concat_dir_and_file (cpanel
->cwd
, fe
->fname
);
254 retval
= gmc_open_filename (fullname
, NULL
);
260 gmc_open_with (gchar
*filename
)
263 gchar
*command
= NULL
;
265 WPanel
*panel
= cpanel
;
267 dialog
= gnome_open_dialog_new (filename
);
268 if (!is_a_desktop_panel (panel
))
269 gnome_dialog_set_parent (GNOME_DIALOG (dialog
), GTK_WINDOW (panel
->xwindow
));
271 switch (gnome_dialog_run (GNOME_DIALOG (dialog
))) {
273 command
= gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (
274 GNOME_FILE_ENTRY (GNOME_OPEN_DIALOG (dialog
)->entry
)->gentry
))));
275 /* Assume COMMAND %f */
277 /* FIXME: these need the needs_terminal argument to be set correctly */
278 if (strchr (command
, '%'))
279 exec_extension (filename
, command
, NULL
, NULL
, 0, FALSE
);
281 /* This prolly isn't perfect, but it will do. */
282 real_command
= g_strconcat (command
, " %f", NULL
);
283 exec_extension (filename
, real_command
, NULL
, NULL
, 0, FALSE
);
284 g_free (real_command
);
288 gtk_widget_destroy (dialog
);
291 gtk_widget_destroy (dialog
);
294 gtk_widget_destroy (dialog
);
301 gmc_run_view (const char *filename
, const char *buf
)
303 exec_extension (filename
, buf
, NULL
, NULL
, 0, 0);
307 gmc_view_command (gchar
*filename
)
309 const char *mime_type
, *cmd
;
313 if (gnome_metadata_get (filename
, "fm-view", &size
, &buf
) == 0)
316 if (gnome_metadata_get (filename
, "view", &size
, &buf
) == 0)
320 mime_type
= gnome_mime_type_or_default_of_file (filename
, NULL
);
322 mime_type
= gnome_mime_type_or_default (filename
, NULL
);
328 cmd
= gnome_mime_get_value (mime_type
, "fm-view");
331 return g_strdup (cmd
);
333 cmd
= gnome_mime_get_value (mime_type
, "view");
335 return g_strdup (cmd
);
341 gmc_view (char *filename
, int start_line
)
344 const gchar
*mime_type
;
346 mime_type
= gnome_mime_type_or_default_of_file (filename
, NULL
);
348 mime_type
= gnome_mime_type_or_default (filename
, NULL
);
349 cmd
= gmc_view_command (filename
);
351 if (gmc_check_exec_string (cmd
))
352 gmc_run_view (filename
, cmd
);
354 gmc_unable_to_execute_dlg (filename
, cmd
, _("view"), mime_type
);
358 view (NULL
, filename
, 0, 0);