~sarahstrong/ubuntu/lucid/gedit/mypatch

« back to all changes in this revision

Viewing changes to plugins/convert/convert.c

  • Committer: Bazaar Package Importer
  • Author(s): Joe Drew
  • Date: 2002-01-13 02:13:27 UTC
  • Revision ID: james.westby@ubuntu.com-20020113021327-dukaa4n50oykvrjg
Tags: upstream-0.9.6
ImportĀ upstreamĀ versionĀ 0.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* convert.c - number conversion plugin.
 
2
 *
 
3
 * Copyright (C) 1998 Alex Roberts
 
4
 *
 
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)
 
8
 * any later version.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
/* TODO: 
 
21
 * [X] libglade-ify me
 
22
 */
 
23
 
 
24
#include <config.h>
 
25
#include <gnome.h>
 
26
#include <glade/glade.h>
 
27
 
 
28
#include "plugin.h"
 
29
#include "window.h"
 
30
 
 
31
static GtkWidget *from, *to;
 
32
 
 
33
void convert_plugin (void);
 
34
 
 
35
static void
 
36
destroy_plugin (PluginData *pd)
 
37
{
 
38
        g_free (pd->name);
 
39
}
 
40
 
 
41
static void
 
42
conv_hex (GtkWidget *widget, gpointer data)
 
43
{
 
44
        int start;
 
45
        gchar *value;
 
46
 
 
47
        start = atoi (gtk_entry_get_text (GTK_ENTRY (from)));
 
48
        value = g_strdup_printf ("%X", start);
 
49
        
 
50
        gtk_entry_set_text (GTK_ENTRY(to), value);
 
51
 
 
52
        g_free (value);
 
53
}
 
54
 
 
55
static void
 
56
conv_oct (GtkWidget *widget, gpointer data)
 
57
{
 
58
        int start;
 
59
        gchar *value;
 
60
 
 
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);
 
64
 
 
65
        g_free (value);
 
66
}
 
67
 
 
68
static void
 
69
conv_dec (GtkWidget *widget, gpointer data)
 
70
{
 
71
        long start;
 
72
        gchar *value;
 
73
 
 
74
        start = strtol (gtk_entry_get_text (GTK_ENTRY (from)), NULL, 16);
 
75
 
 
76
        value = g_strdup_printf ("%lu", start);
 
77
        gtk_entry_set_text (GTK_ENTRY(to), value);
 
78
 
 
79
        g_free (value);
 
80
}
 
81
 
 
82
static void
 
83
plugin_finish (GtkWidget *widget, gpointer data)
 
84
{
 
85
        gnome_dialog_close (GNOME_DIALOG (widget));
 
86
}
 
87
 
 
88
static void
 
89
close_button_pressed (GtkWidget *widget, GtkWidget* data)
 
90
{
 
91
        gnome_dialog_close (GNOME_DIALOG (data));
 
92
}
 
93
 
 
94
static void
 
95
help_button_pressed (GtkWidget *widget, gpointer data)
 
96
{
 
97
        /* FIXME: Paolo - change to point to the right help page */
 
98
 
 
99
        static GnomeHelpMenuEntry help_entry = { "gedit", "plugins.html" };
 
100
 
 
101
        gnome_help_display (NULL, &help_entry);
 
102
}
 
103
 
 
104
 
 
105
void
 
106
convert_plugin (void)
 
107
{
 
108
        GladeXML *gui;
 
109
        GtkWidget *dialog;
 
110
        GtkWidget *dectohex;
 
111
        GtkWidget *dectooct;
 
112
        GtkWidget *hextodec;
 
113
        GtkWidget *close_button;
 
114
        GtkWidget *help_button;
 
115
        
 
116
        gui = glade_xml_new (GEDIT_GLADEDIR "/convert.glade", "dialog1");
 
117
 
 
118
        if (!gui)
 
119
        {
 
120
                g_warning ("Could not find convert.glade");
 
121
                return;
 
122
        }
 
123
        
 
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");
 
132
 
 
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);
 
141
 
 
142
        gtk_signal_connect (GTK_OBJECT (dectohex),
 
143
                            "clicked",
 
144
                            GTK_SIGNAL_FUNC (conv_hex),
 
145
                            NULL);
 
146
 
 
147
        gtk_signal_connect (GTK_OBJECT (dectooct),
 
148
                            "clicked",
 
149
                            GTK_SIGNAL_FUNC( conv_oct ),
 
150
                            NULL );
 
151
 
 
152
        gtk_signal_connect (GTK_OBJECT (hextodec),
 
153
                            "clicked",
 
154
                            GTK_SIGNAL_FUNC( conv_dec ),
 
155
                            NULL);
 
156
 
 
157
        gtk_signal_connect (GTK_OBJECT (dialog),
 
158
                            "destroy",
 
159
                            GTK_SIGNAL_FUNC (plugin_finish),
 
160
                            NULL);
 
161
        
 
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);
 
166
        
 
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);
 
170
 
 
171
        gtk_widget_show_all (dialog);
 
172
 
 
173
        gtk_object_unref (GTK_OBJECT (gui));
 
174
}
 
175
 
 
176
gint
 
177
init_plugin (PluginData *pd)
 
178
{
 
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;
 
185
 
 
186
        pd->private_data = (gpointer) convert_plugin;
 
187
 
 
188
        return PLUGIN_OK;
 
189
}