1
/* browse.c - web browse plugin.
3
* Copyright (C) 1998 Alex Roberts
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2, or (at your option)
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
* Converted to a gmodule plugin by Jason Leach <leach@wam.umd.edu>
20
* Libgladify and better error recovery Chema Celorio <chema@celorio.com>
27
#include <glade/glade.h>
35
#define GEDIT_PLUGIN_PROGRAM "lynx"
36
/* xgettext translators: !!!!!!!!!!!---------> the name of the plugin only.
37
it is used to display "you can not use the [name] plugin without this program... */
38
#define GEDIT_PLUGIN_NAME _("Browse")
40
static GtkWidget *location_label;
41
static GtkWidget *url_entry;
44
gedit_plugin_destroy (PluginData *pd)
50
gedit_plugin_finish (GtkWidget *widget, gpointer data)
52
gnome_dialog_close (GNOME_DIALOG(widget));
55
/* WE need to make this plugin non-blocking and to improve the error
56
reporting. !! It is very bad !
61
gedit_plugin_execute (GtkWidget *widget, gint button, gpointer data)
73
url = g_strdup (gtk_entry_get_text (GTK_ENTRY (url_entry)));
75
if (!url || strlen (url) == 0)
77
GnomeDialog *error_dialog;
78
error_dialog = GNOME_DIALOG (gnome_error_dialog_parented ("Please provide a valid URL.",
79
gedit_window_active()));
80
gnome_dialog_run_and_close (error_dialog);
81
gdk_window_raise (widget->window);
85
lynx_location = g_strdup (GTK_LABEL(location_label)->label);
87
if (pipe (fdpipe) == -1)
89
g_warning ("Could not open pipe\n");
107
execv (lynx_location, argv);
109
/* don't use asserts not reached ! Chema.
110
why crash gedit when you can display an error
111
and give the user a chance to save it's work ?
112
g_assert_not_reached ();
114
g_warning ("A undetermined PIPE problem occurred");
119
doc = gedit_document_new_with_title (url);
125
buff [ length = read (fdpipe[0], buff, 1024) ] = 0;
128
gedit_document_insert_text (doc, buff, pos, FALSE);
133
gedit_view_set_position (gedit_view_active (), 0);
135
gnome_config_push_prefix ("/Editor_Plugins/Browse/");
136
gnome_config_set_string ("Url", url[0]);
137
gnome_config_pop_prefix ();
138
gnome_config_sync ();
141
g_free (lynx_location);
147
static GnomeHelpMenuEntry help_entry = { "gedit", "plugins.html#browse" };
148
gnome_help_display (NULL, &help_entry);
153
gnome_dialog_close (GNOME_DIALOG(widget));
157
gedit_plugin_change_location (GtkWidget *button, gpointer userdata)
161
gchar * new_location;
163
gedit_debug (DEBUG_PLUGINS, "");
166
new_location = gedit_plugin_program_location_change (GEDIT_PLUGIN_PROGRAM,
169
if ( new_location == NULL)
171
gdk_window_raise (dialog->window);
175
/* We need to update the label */
176
label = gtk_object_get_data (GTK_OBJECT (dialog), "location_label");
177
g_return_if_fail (label!=NULL);
178
gtk_label_set_text (GTK_LABEL (label),
180
g_free (new_location);
182
gdk_window_raise (dialog->window);
187
gedit_plugin_browse_create_dialog (void)
191
GtkWidget *change_button;
192
gchar *browser_location;
194
gedit_debug (DEBUG_PLUGINS, "");
196
/* xgettext translators: !!!!!!!!!!!---------> the name of the plugin only.
197
it is used to display "you can not use the [name] plugin without this program... */
198
browser_location = gedit_plugin_program_location_get (GEDIT_PLUGIN_PROGRAM,
202
g_return_if_fail(browser_location != NULL);
204
gui = glade_xml_new (GEDIT_GLADEDIR "/browse.glade", NULL);
208
g_warning ("Could not find %s", GEDIT_GLADEDIR "/browse.glade");
212
dialog = glade_xml_get_widget (gui, "dialog");
213
url_entry = glade_xml_get_widget (gui, "url_entry");
214
location_label = glade_xml_get_widget (gui, "location_label");
215
change_button = glade_xml_get_widget (gui, "change_button");
217
g_return_if_fail (dialog != NULL);
218
g_return_if_fail (url_entry != NULL);
219
g_return_if_fail (location_label != NULL);
220
g_return_if_fail (change_button != NULL);
222
/* Set the location label */
223
gtk_object_set_data (GTK_OBJECT (dialog), "location_label", location_label);
224
gtk_label_set_text (GTK_LABEL (location_label),
226
g_free (browser_location);
228
/* Connect the signals */
229
gtk_signal_connect (GTK_OBJECT (dialog), "clicked",
230
GTK_SIGNAL_FUNC (gedit_plugin_execute), NULL);
231
gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
232
GTK_SIGNAL_FUNC (gedit_plugin_finish), NULL);
233
gtk_signal_connect (GTK_OBJECT (change_button), "clicked",
234
GTK_SIGNAL_FUNC (gedit_plugin_change_location), dialog);
236
/* Set the dialog parent and modal type */
237
gnome_dialog_set_parent (GNOME_DIALOG (dialog), gedit_window_active());
238
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
239
gnome_dialog_set_default (GNOME_DIALOG (dialog), 0);
240
gnome_dialog_editable_enters (GNOME_DIALOG (dialog), GTK_EDITABLE (url_entry));
242
/* Show everything then free the GladeXML memmory */
243
gtk_widget_show_all (dialog);
244
gtk_object_unref (GTK_OBJECT (gui));
248
init_plugin (PluginData *pd)
250
pd->destroy_plugin = gedit_plugin_destroy;
251
pd->name = _("Browse");
252
pd->desc = _("Web browse plugin");
253
pd->long_desc = _("Web browse plugin");
254
pd->author = "Alex Roberts <bse@error.fsnet.co.uk>";
255
pd->needs_a_document = FALSE;
257
pd->private_data = (gpointer)gedit_plugin_browse_create_dialog;
258
pd->installed_by_default = TRUE;