~ubuntu-branches/ubuntu/hardy/gnome-commander/hardy

« back to all changes in this revision

Viewing changes to libgcmd/gnome-cmd-string-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-06-13 15:39:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060613153948-gvrt3mb2ddk5u62o
Tags: 1.2.0-3
added --disable-scrollkeeper on build

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
    GNOME Commander - A GNOME based file manager 
 
2
    GNOME Commander - A GNOME based file manager
3
3
    Copyright (C) 2001-2006 Marcus Bjurman
4
4
 
5
5
    This program is free software; you can redistribute it and/or modify
15
15
    You should have received a copy of the GNU General Public License
16
16
    along with this program; if not, write to the Free Software
17
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
*/ 
 
18
*/
19
19
#include <config.h>
20
20
#include "libgcmd-deps.h"
21
21
#include "gnome-cmd-dialog.h"
24
24
 
25
25
struct _GnomeCmdStringDialogPrivate
26
26
{
27
 
        GnomeCmdStringDialogCallback ok_cb;
28
 
        GFunc cancel_cb;
29
 
        gpointer data;
30
 
        GtkWidget *dialog;
31
 
        gchar *error_desc;
 
27
    GnomeCmdStringDialogCallback ok_cb;
 
28
    GFunc cancel_cb;
 
29
    gpointer data;
 
30
    GtkWidget *dialog;
 
31
    gchar *error_desc;
32
32
};
33
33
 
34
34
 
38
38
static void
39
39
on_ok (GtkButton *button, GnomeCmdStringDialog *dialog)
40
40
{
41
 
        gboolean valid = TRUE;  
42
 
        
43
 
        if (dialog->priv->ok_cb) {
44
 
                gint i;
45
 
                gchar **values = (gchar**)g_new (gpointer, dialog->rows);
46
 
 
47
 
                for ( i=0 ; i<dialog->rows ; i++ )
48
 
                        values[i] = (gchar*)gtk_entry_get_text (GTK_ENTRY (dialog->entries[i]));
49
 
                                                                  
50
 
                
51
 
                valid = dialog->priv->ok_cb (dialog, (const gchar**)values, dialog->priv->data);
52
 
                if (!valid)
53
 
                        create_error_dialog (dialog->priv->error_desc);
54
 
                g_free (values);
55
 
        }
56
 
 
57
 
        if (valid)
58
 
                gtk_widget_hide (GTK_WIDGET (dialog));
 
41
    gboolean valid = TRUE;
 
42
 
 
43
    if (dialog->priv->ok_cb) {
 
44
        gint i;
 
45
        gchar **values = (gchar**)g_new (gpointer, dialog->rows);
 
46
 
 
47
        for ( i=0 ; i<dialog->rows ; i++ )
 
48
            values[i] = (gchar*)gtk_entry_get_text (GTK_ENTRY (dialog->entries[i]));
 
49
 
 
50
 
 
51
        valid = dialog->priv->ok_cb (dialog, (const gchar**)values, dialog->priv->data);
 
52
        if (!valid)
 
53
            create_error_dialog (dialog->priv->error_desc);
 
54
        g_free (values);
 
55
    }
 
56
 
 
57
    if (valid)
 
58
        gtk_widget_hide (GTK_WIDGET (dialog));
59
59
}
60
60
 
61
61
 
62
62
static void
63
63
on_cancel (GtkButton *button, GnomeCmdStringDialog *dialog)
64
64
{
65
 
        if (dialog->priv->cancel_cb)
66
 
                dialog->priv->cancel_cb (button, dialog->priv->data);
67
 
        
68
 
        gtk_widget_hide (GTK_WIDGET (dialog));
 
65
    if (dialog->priv->cancel_cb)
 
66
        dialog->priv->cancel_cb (button, dialog->priv->data);
 
67
 
 
68
    gtk_widget_hide (GTK_WIDGET (dialog));
69
69
}
70
70
 
71
71
 
79
79
static void
80
80
destroy (GtkObject *object)
81
81
{
82
 
        GnomeCmdStringDialog *dialog = GNOME_CMD_STRING_DIALOG (object);
83
 
        
84
 
        if (GTK_OBJECT_CLASS (parent_class)->destroy)
85
 
                (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
86
 
 
87
 
        g_free (dialog->priv->error_desc);
88
 
        g_free (dialog->priv);
 
82
    GnomeCmdStringDialog *dialog = GNOME_CMD_STRING_DIALOG (object);
 
83
 
 
84
    if (GTK_OBJECT_CLASS (parent_class)->destroy)
 
85
        (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 
86
 
 
87
    g_free (dialog->priv->error_desc);
 
88
    g_free (dialog->priv);
89
89
}
90
90
 
91
91
 
92
92
static void
93
93
map (GtkWidget *widget)
94
94
{
95
 
        if (GTK_WIDGET_CLASS (parent_class)->map != NULL)
96
 
                GTK_WIDGET_CLASS (parent_class)->map (widget);
 
95
    if (GTK_WIDGET_CLASS (parent_class)->map != NULL)
 
96
        GTK_WIDGET_CLASS (parent_class)->map (widget);
97
97
}
98
98
 
99
99
 
100
100
static void
101
101
class_init (GnomeCmdStringDialogClass *class)
102
102
{
103
 
        GtkObjectClass *object_class;
104
 
        GtkWidgetClass *widget_class;
105
 
 
106
 
        object_class = GTK_OBJECT_CLASS (class);
107
 
        widget_class = GTK_WIDGET_CLASS (class);
108
 
 
109
 
        parent_class = gtk_type_class (gnome_cmd_dialog_get_type ());
110
 
        object_class->destroy = destroy;
111
 
        widget_class->map = map;
 
103
    GtkObjectClass *object_class;
 
104
    GtkWidgetClass *widget_class;
 
105
 
 
106
    object_class = GTK_OBJECT_CLASS (class);
 
107
    widget_class = GTK_WIDGET_CLASS (class);
 
108
 
 
109
    parent_class = gtk_type_class (gnome_cmd_dialog_get_type ());
 
110
    object_class->destroy = destroy;
 
111
    widget_class->map = map;
112
112
}
113
113
 
114
114
static void
115
115
init (GnomeCmdStringDialog *string_dialog)
116
116
{
117
 
        string_dialog->priv = g_new0 (GnomeCmdStringDialogPrivate, 1);
118
 
        string_dialog->rows = -1;
 
117
    string_dialog->priv = g_new0 (GnomeCmdStringDialogPrivate, 1);
 
118
    string_dialog->rows = -1;
119
119
}
120
120
 
121
121
 
122
122
static void
123
123
setup_widget (GnomeCmdStringDialog *string_dialog, gint rows)
124
124
{
125
 
        gint i;
126
 
        GtkWidget *dialog = GTK_WIDGET (string_dialog);
127
 
        GtkWidget *table;
128
 
        GtkWidget *btn;
129
 
 
130
 
        string_dialog->rows = rows;
131
 
        string_dialog->labels = (GtkWidget**)g_new (gpointer, rows);
132
 
        string_dialog->entries = (GtkWidget**)g_new (gpointer, rows);
133
 
        string_dialog->priv->error_desc = g_strdup (_("No error description available"));
134
 
 
135
 
        table = create_table (dialog, rows, 2);
136
 
        gnome_cmd_dialog_add_category (GNOME_CMD_DIALOG (dialog), table);
137
 
 
138
 
        for ( i=0 ; i<rows ; i++ ) {
139
 
                string_dialog->labels[i] = create_label (dialog, "");
140
 
                table_add (table, string_dialog->labels[i], 0, i, GTK_FILL);
141
 
                
142
 
                string_dialog->entries[i] = create_entry (dialog, "entry", "");
143
 
                gtk_entry_set_activates_default (GTK_ENTRY (string_dialog->entries[i]), TRUE);
144
 
                table_add (table, string_dialog->entries[i], 1, i, GTK_FILL|GTK_EXPAND);
145
 
        }
146
 
 
147
 
        gnome_cmd_dialog_add_button (
148
 
                GNOME_CMD_DIALOG (dialog),
149
 
                GNOME_STOCK_BUTTON_CANCEL, GTK_SIGNAL_FUNC (on_cancel), string_dialog);
150
 
        btn = gnome_cmd_dialog_add_button (
151
 
                GNOME_CMD_DIALOG (dialog),
152
 
                GNOME_STOCK_BUTTON_OK, GTK_SIGNAL_FUNC (on_ok), string_dialog);
153
 
        
154
 
        gtk_widget_grab_focus (string_dialog->entries[0]);
 
125
    gint i;
 
126
    GtkWidget *dialog = GTK_WIDGET (string_dialog);
 
127
    GtkWidget *table;
 
128
    GtkWidget *btn;
 
129
 
 
130
    string_dialog->rows = rows;
 
131
    string_dialog->labels = (GtkWidget**)g_new (gpointer, rows);
 
132
    string_dialog->entries = (GtkWidget**)g_new (gpointer, rows);
 
133
    string_dialog->priv->error_desc = g_strdup (_("No error description available"));
 
134
 
 
135
    table = create_table (dialog, rows, 2);
 
136
    gnome_cmd_dialog_add_category (GNOME_CMD_DIALOG (dialog), table);
 
137
 
 
138
    for ( i=0 ; i<rows ; i++ ) {
 
139
        string_dialog->labels[i] = create_label (dialog, "");
 
140
        table_add (table, string_dialog->labels[i], 0, i, GTK_FILL);
 
141
 
 
142
        string_dialog->entries[i] = create_entry (dialog, "entry", "");
 
143
        gtk_entry_set_activates_default (GTK_ENTRY (string_dialog->entries[i]), TRUE);
 
144
        table_add (table, string_dialog->entries[i], 1, i, GTK_FILL|GTK_EXPAND);
 
145
    }
 
146
 
 
147
    gnome_cmd_dialog_add_button (
 
148
        GNOME_CMD_DIALOG (dialog),
 
149
        GNOME_STOCK_BUTTON_CANCEL, GTK_SIGNAL_FUNC (on_cancel), string_dialog);
 
150
    btn = gnome_cmd_dialog_add_button (
 
151
        GNOME_CMD_DIALOG (dialog),
 
152
        GNOME_STOCK_BUTTON_OK, GTK_SIGNAL_FUNC (on_ok), string_dialog);
 
153
 
 
154
    gtk_widget_grab_focus (string_dialog->entries[0]);
155
155
    gtk_widget_grab_default (btn);
156
156
}
157
157
 
165
165
GtkType
166
166
gnome_cmd_string_dialog_get_type         (void)
167
167
{
168
 
        static GtkType dlg_type = 0;
169
 
 
170
 
        if (dlg_type == 0)
171
 
        {
172
 
                GtkTypeInfo dlg_info =
173
 
                {
174
 
                        "GnomeCmdStringDialog",
175
 
                        sizeof (GnomeCmdStringDialog),
176
 
                        sizeof (GnomeCmdStringDialogClass),
177
 
                        (GtkClassInitFunc) class_init,
178
 
                        (GtkObjectInitFunc) init,
179
 
                        /* reserved_1 */ NULL,
180
 
                        /* reserved_2 */ NULL,
181
 
                        (GtkClassInitFunc) NULL
182
 
                };
183
 
 
184
 
                dlg_type = gtk_type_unique (gnome_cmd_dialog_get_type (), &dlg_info);
185
 
        }
186
 
        return dlg_type;
 
168
    static GtkType dlg_type = 0;
 
169
 
 
170
    if (dlg_type == 0)
 
171
    {
 
172
        GtkTypeInfo dlg_info =
 
173
        {
 
174
            "GnomeCmdStringDialog",
 
175
            sizeof (GnomeCmdStringDialog),
 
176
            sizeof (GnomeCmdStringDialogClass),
 
177
            (GtkClassInitFunc) class_init,
 
178
            (GtkObjectInitFunc) init,
 
179
            /* reserved_1 */ NULL,
 
180
            /* reserved_2 */ NULL,
 
181
            (GtkClassInitFunc) NULL
 
182
        };
 
183
 
 
184
        dlg_type = gtk_type_unique (gnome_cmd_dialog_get_type (), &dlg_info);
 
185
    }
 
186
    return dlg_type;
187
187
}
188
188
 
189
189
 
190
190
 
191
191
 
192
192
 
193
 
GtkWidget* 
 
193
GtkWidget*
194
194
gnome_cmd_string_dialog_new_with_cancel (const gchar *title,
195
 
                                                                                 const gchar **labels,
196
 
                                                                                 gint rows,
197
 
                                                                                 GnomeCmdStringDialogCallback ok_cb,
198
 
                                                                                 GtkSignalFunc cancel_cb,
199
 
                                                                                 gpointer user_data)
 
195
                                         const gchar **labels,
 
196
                                         gint rows,
 
197
                                         GnomeCmdStringDialogCallback ok_cb,
 
198
                                         GtkSignalFunc cancel_cb,
 
199
                                         gpointer user_data)
200
200
{
201
 
        GnomeCmdStringDialog *dialog = gtk_type_new (gnome_cmd_string_dialog_get_type ());
202
 
 
203
 
        gnome_cmd_string_dialog_setup_with_cancel (
204
 
                dialog, title, labels, rows, 
205
 
                ok_cb, cancel_cb, user_data);
206
 
        
207
 
        return GTK_WIDGET (dialog);
 
201
    GnomeCmdStringDialog *dialog = gtk_type_new (gnome_cmd_string_dialog_get_type ());
 
202
 
 
203
    gnome_cmd_string_dialog_setup_with_cancel (
 
204
        dialog, title, labels, rows,
 
205
        ok_cb, cancel_cb, user_data);
 
206
 
 
207
    return GTK_WIDGET (dialog);
208
208
}
209
209
 
210
210
 
211
 
GtkWidget* 
 
211
GtkWidget*
212
212
gnome_cmd_string_dialog_new (const gchar *title,
213
 
                                                         const gchar **labels,
214
 
                                                         gint rows,
215
 
                                                         GnomeCmdStringDialogCallback ok_cb,
216
 
                                                         gpointer user_data)
 
213
                             const gchar **labels,
 
214
                             gint rows,
 
215
                             GnomeCmdStringDialogCallback ok_cb,
 
216
                             gpointer user_data)
217
217
{
218
 
        return gnome_cmd_string_dialog_new_with_cancel (title, labels, rows,
219
 
                                                                                                        ok_cb, NULL, user_data);
 
218
    return gnome_cmd_string_dialog_new_with_cancel (title, labels, rows,
 
219
                                                    ok_cb, NULL, user_data);
220
220
}
221
221
 
222
222
 
223
223
void
224
224
gnome_cmd_string_dialog_setup_with_cancel (GnomeCmdStringDialog *dialog,
225
 
                                                                                   const gchar *title,
226
 
                                                                                   const gchar **labels,
227
 
                                                                                   gint rows,
228
 
                                                                                   GnomeCmdStringDialogCallback ok_cb,
229
 
                                                                                   GtkSignalFunc cancel_cb,
230
 
                                                                                   gpointer user_data)
 
225
                                           const gchar *title,
 
226
                                           const gchar **labels,
 
227
                                           gint rows,
 
228
                                           GnomeCmdStringDialogCallback ok_cb,
 
229
                                           GtkSignalFunc cancel_cb,
 
230
                                           gpointer user_data)
231
231
{
232
 
        gint i;
233
 
        
234
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
235
 
        g_return_if_fail (title != NULL);
236
 
        g_return_if_fail (labels != NULL);
237
 
        g_return_if_fail (rows > 0);
238
 
        g_return_if_fail (ok_cb != NULL);
239
 
 
240
 
        setup_widget (dialog, rows);
241
 
        gnome_cmd_string_dialog_set_title (dialog, title);
242
 
        gnome_cmd_string_dialog_set_userdata (dialog, user_data);
243
 
        gnome_cmd_string_dialog_set_ok_cb (dialog, ok_cb);
244
 
        gnome_cmd_string_dialog_set_cancel_cb (dialog, cancel_cb);
245
 
 
246
 
        if (labels)
247
 
                for ( i=0 ; i<rows ; i++ )
248
 
                        gnome_cmd_string_dialog_set_label (dialog, i, labels[i]);
 
232
    gint i;
 
233
 
 
234
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
235
    g_return_if_fail (title != NULL);
 
236
    g_return_if_fail (labels != NULL);
 
237
    g_return_if_fail (rows > 0);
 
238
    g_return_if_fail (ok_cb != NULL);
 
239
 
 
240
    setup_widget (dialog, rows);
 
241
    gnome_cmd_string_dialog_set_title (dialog, title);
 
242
    gnome_cmd_string_dialog_set_userdata (dialog, user_data);
 
243
    gnome_cmd_string_dialog_set_ok_cb (dialog, ok_cb);
 
244
    gnome_cmd_string_dialog_set_cancel_cb (dialog, cancel_cb);
 
245
 
 
246
    if (labels)
 
247
        for ( i=0 ; i<rows ; i++ )
 
248
            gnome_cmd_string_dialog_set_label (dialog, i, labels[i]);
249
249
}
250
250
 
251
251
 
252
252
void
253
253
gnome_cmd_string_dialog_setup (GnomeCmdStringDialog *dialog,
254
 
                                                           const gchar *title,
255
 
                                                           const gchar **labels,
256
 
                                                           gint rows,
257
 
                                                           GnomeCmdStringDialogCallback ok_cb,
258
 
                                                           gpointer user_data)
 
254
                               const gchar *title,
 
255
                               const gchar **labels,
 
256
                               gint rows,
 
257
                               GnomeCmdStringDialogCallback ok_cb,
 
258
                               gpointer user_data)
259
259
{
260
 
        gnome_cmd_string_dialog_setup_with_cancel (
261
 
                dialog, title, labels, rows, ok_cb, NULL, user_data);
 
260
    gnome_cmd_string_dialog_setup_with_cancel (
 
261
        dialog, title, labels, rows, ok_cb, NULL, user_data);
262
262
}
263
263
 
264
264
 
265
265
void
266
266
gnome_cmd_string_dialog_set_hidden (GnomeCmdStringDialog *dialog, gint row, gboolean hidden)
267
267
{
268
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
269
 
        g_return_if_fail (row >= 0 && row < dialog->rows);      
 
268
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
269
    g_return_if_fail (row >= 0 && row < dialog->rows);
270
270
 
271
 
        gtk_entry_set_visibility (GTK_ENTRY (dialog->entries[row]), !hidden);   
 
271
    gtk_entry_set_visibility (GTK_ENTRY (dialog->entries[row]), !hidden);
272
272
}
273
273
 
274
274
 
275
275
void
276
276
gnome_cmd_string_dialog_set_title (GnomeCmdStringDialog *dialog, const gchar *title)
277
277
{
278
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
279
 
        
280
 
        gtk_window_set_title (GTK_WINDOW (dialog), title);
 
278
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
279
 
 
280
    gtk_window_set_title (GTK_WINDOW (dialog), title);
281
281
}
282
282
 
283
283
 
284
284
void
285
285
gnome_cmd_string_dialog_set_label (GnomeCmdStringDialog *dialog, gint row, const gchar *label)
286
286
{
287
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
288
 
        g_return_if_fail (row >= 0 && row < dialog->rows);
289
 
        g_return_if_fail (label != NULL);
290
 
        
291
 
        gtk_label_set_text (GTK_LABEL (dialog->labels[row]), label);
 
287
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
288
    g_return_if_fail (row >= 0 && row < dialog->rows);
 
289
    g_return_if_fail (label != NULL);
 
290
 
 
291
    gtk_label_set_text (GTK_LABEL (dialog->labels[row]), label);
292
292
}
293
293
 
294
294
 
295
295
void
296
296
gnome_cmd_string_dialog_set_userdata (GnomeCmdStringDialog *dialog, gpointer user_data)
297
297
{
298
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
299
 
        
300
 
        dialog->priv->data = user_data;
 
298
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
299
 
 
300
    dialog->priv->data = user_data;
301
301
}
302
302
 
303
303
 
304
304
void
305
305
gnome_cmd_string_dialog_set_ok_cb (GnomeCmdStringDialog *dialog, GnomeCmdStringDialogCallback ok_cb)
306
306
{
307
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
308
 
        g_return_if_fail (ok_cb != NULL);
309
 
        
310
 
        dialog->priv->ok_cb = ok_cb;
 
307
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
308
    g_return_if_fail (ok_cb != NULL);
 
309
 
 
310
    dialog->priv->ok_cb = ok_cb;
311
311
}
312
312
 
313
313
 
314
314
void
315
315
gnome_cmd_string_dialog_set_cancel_cb (GnomeCmdStringDialog *dialog, GtkSignalFunc cancel_cb)
316
316
{
317
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
318
 
        
319
 
        dialog->priv->cancel_cb = (GFunc)cancel_cb;
 
317
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
318
 
 
319
    dialog->priv->cancel_cb = (GFunc)cancel_cb;
320
320
}
321
321
 
322
322
 
323
323
void
324
324
gnome_cmd_string_dialog_set_value (GnomeCmdStringDialog *dialog, gint row, const gchar *value)
325
325
{
326
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
327
 
        g_return_if_fail (row >= 0 && row < dialog->rows);
328
 
        
329
 
        gtk_entry_set_text (GTK_ENTRY (dialog->entries[row]), value?value:"");
 
326
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
327
    g_return_if_fail (row >= 0 && row < dialog->rows);
 
328
 
 
329
    gtk_entry_set_text (GTK_ENTRY (dialog->entries[row]), value?value:"");
330
330
}
331
331
 
332
332
 
333
333
void
334
334
gnome_cmd_string_dialog_set_error_desc (GnomeCmdStringDialog *dialog, gchar *msg)
335
335
{
336
 
        g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
337
 
        g_return_if_fail (msg != NULL);
338
 
        
339
 
        if (dialog->priv->error_desc)
340
 
                g_free (dialog->priv->error_desc);
341
 
 
342
 
        dialog->priv->error_desc = g_strdup (msg);
 
336
    g_return_if_fail (GNOME_CMD_IS_STRING_DIALOG (dialog));
 
337
    g_return_if_fail (msg != NULL);
 
338
 
 
339
    if (dialog->priv->error_desc)
 
340
        g_free (dialog->priv->error_desc);
 
341
 
 
342
    dialog->priv->error_desc = g_strdup (msg);
343
343
}