1
/* convert.c - number conversion 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.
26
#include <glade/glade.h>
31
static GtkWidget *from, *to;
33
void convert_plugin (void);
36
destroy_plugin (PluginData *pd)
42
conv_hex (GtkWidget *widget, gpointer data)
47
start = atoi (gtk_entry_get_text (GTK_ENTRY (from)));
48
value = g_strdup_printf ("%X", start);
50
gtk_entry_set_text (GTK_ENTRY(to), value);
56
conv_oct (GtkWidget *widget, gpointer data)
61
start = atoi (gtk_entry_get_text( GTK_ENTRY( from ) ));
62
value = g_strdup_printf ("%o", start);
63
gtk_entry_set_text(GTK_ENTRY(to), value);
69
conv_dec (GtkWidget *widget, gpointer data)
74
start = strtol (gtk_entry_get_text (GTK_ENTRY (from)), NULL, 16);
76
value = g_strdup_printf ("%lu", start);
77
gtk_entry_set_text (GTK_ENTRY(to), value);
83
plugin_finish (GtkWidget *widget, gpointer data)
85
gnome_dialog_close (GNOME_DIALOG (widget));
89
close_button_pressed (GtkWidget *widget, GtkWidget* data)
91
gnome_dialog_close (GNOME_DIALOG (data));
95
help_button_pressed (GtkWidget *widget, gpointer data)
97
/* FIXME: Paolo - change to point to the right help page */
99
static GnomeHelpMenuEntry help_entry = { "gedit", "plugins.html" };
101
gnome_help_display (NULL, &help_entry);
106
convert_plugin (void)
113
GtkWidget *close_button;
114
GtkWidget *help_button;
116
gui = glade_xml_new (GEDIT_GLADEDIR "/convert.glade", "dialog1");
120
g_warning ("Could not find convert.glade");
124
dialog = glade_xml_get_widget (gui, "dialog1");
125
to = glade_xml_get_widget (gui, "to");
126
from = glade_xml_get_widget (gui, "from");
127
dectohex = glade_xml_get_widget (gui, "dectohex");
128
dectooct = glade_xml_get_widget (gui, "dectooct");
129
hextodec = glade_xml_get_widget (gui, "hextodec");
130
close_button = glade_xml_get_widget (gui, "close_button");
131
help_button = glade_xml_get_widget (gui, "help_button");
133
g_return_if_fail (dialog != NULL);
134
g_return_if_fail (to != NULL);
135
g_return_if_fail (from != NULL);
136
g_return_if_fail (dectohex != NULL);
137
g_return_if_fail (dectooct != NULL);
138
g_return_if_fail (hextodec != NULL);
139
g_return_if_fail (close_button != NULL);
140
g_return_if_fail (help_button != NULL);
142
gtk_signal_connect (GTK_OBJECT (dectohex),
144
GTK_SIGNAL_FUNC (conv_hex),
147
gtk_signal_connect (GTK_OBJECT (dectooct),
149
GTK_SIGNAL_FUNC( conv_oct ),
152
gtk_signal_connect (GTK_OBJECT (hextodec),
154
GTK_SIGNAL_FUNC( conv_dec ),
157
gtk_signal_connect (GTK_OBJECT (dialog),
159
GTK_SIGNAL_FUNC (plugin_finish),
162
gtk_signal_connect (GTK_OBJECT (close_button), "clicked",
163
GTK_SIGNAL_FUNC (close_button_pressed), dialog);
164
gtk_signal_connect (GTK_OBJECT (help_button), "clicked",
165
GTK_SIGNAL_FUNC (help_button_pressed), NULL);
167
/* Set the dialog parent and modal type */
168
gnome_dialog_set_parent (GNOME_DIALOG (dialog), gedit_window_active());
169
gnome_dialog_set_default (GNOME_DIALOG (dialog), 0);
171
gtk_widget_show_all (dialog);
173
gtk_object_unref (GTK_OBJECT (gui));
177
init_plugin (PluginData *pd)
179
pd->destroy_plugin = destroy_plugin;
180
pd->name = _("Convert");
181
pd->desc = _("Number Converter");
182
pd->long_desc = _("Number Converter");
183
pd->author = "Alex Roberts <bse@error.fsnet.co.uk>";
184
pd->needs_a_document = FALSE;
186
pd->private_data = (gpointer) convert_plugin;