~ubuntu-branches/ubuntu/quantal/gbonds/quantal

« back to all changes in this revision

Viewing changes to src/commands.c

  • Committer: Bazaar Package Importer
  • Author(s): Richard Laager
  • Date: 2007-03-14 23:50:34 UTC
  • Revision ID: james.westby@ubuntu.com-20070314235034-997qegw33jx0wb9r
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  (GBONDS) GNOME based Savings Bond Inventory Program
 
3
 *
 
4
 *  commands.c:  gbonds commands module
 
5
 *
 
6
 *  Copyright (C) 2001-2003  Jim Evins <evins@snaught.com>.
 
7
 *
 
8
 *  This program is free software; you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU General Public License as published by
 
10
 *  the Free Software Foundation; either version 2 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program; if not, write to the Free Software
 
20
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
21
 */
 
22
 
 
23
#include <config.h>
 
24
 
 
25
#include <gtk/gtk.h>
 
26
#include <libgnome/libgnome.h>
 
27
#include <libgnomeui/libgnomeui.h>
 
28
 
 
29
#include "commands.h"
 
30
#include "view.h"
 
31
#include "file.h"
 
32
#include "print-dialog.h"
 
33
#include "prefs-dialog.h"
 
34
#include "debug.h"
 
35
 
 
36
#define LOGO_PIXMAP gnome_program_locate_file (NULL,\
 
37
                                         GNOME_FILE_DOMAIN_APP_PIXMAP,\
 
38
                                         "gbonds/gbonds_logo.png",\
 
39
                                         FALSE, NULL)
 
40
 
 
41
 
 
42
/****************************************************************************/
 
43
/* File->New command.                                                       */
 
44
/****************************************************************************/
 
45
void 
 
46
gb_cmd_file_new (BonoboUIComponent *uic,
 
47
                 gpointer           user_data,
 
48
                 const gchar       *verbname)
 
49
{
 
50
        gbWindow *window = GB_WINDOW (user_data);
 
51
 
 
52
        gb_debug (DEBUG_COMMANDS, "");
 
53
        
 
54
        gb_file_new (GTK_WINDOW(window));
 
55
}
 
56
 
 
57
/****************************************************************************/
 
58
/* File->Open command.                                                      */
 
59
/****************************************************************************/
 
60
void 
 
61
gb_cmd_file_open (BonoboUIComponent *uic,
 
62
                  gpointer           user_data,
 
63
                  const gchar       *verbname)
 
64
{
 
65
        gbWindow *window = GB_WINDOW (user_data);
 
66
 
 
67
        gb_debug (DEBUG_COMMANDS, "");
 
68
 
 
69
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
70
 
 
71
        gb_file_open (GTK_WINDOW(window));
 
72
}
 
73
 
 
74
/****************************************************************************/
 
75
/* File->Import command.                                                    */
 
76
/****************************************************************************/
 
77
void 
 
78
gb_cmd_file_import (BonoboUIComponent *uic,
 
79
                    gpointer           user_data,
 
80
                    const gchar       *verbname)
 
81
{
 
82
        gbWindow *window = GB_WINDOW (user_data);
 
83
 
 
84
        gb_debug (DEBUG_COMMANDS, "");
 
85
 
 
86
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
87
 
 
88
        gb_file_import (GTK_WINDOW(window));
 
89
}
 
90
 
 
91
/****************************************************************************/
 
92
/* File->Save command.                                                      */
 
93
/****************************************************************************/
 
94
void 
 
95
gb_cmd_file_save (BonoboUIComponent *uic,
 
96
                  gpointer           user_data,
 
97
                  const gchar       *verbname)
 
98
{
 
99
        gbWindow *window = GB_WINDOW (user_data);
 
100
 
 
101
        gb_debug (DEBUG_COMMANDS, "");
 
102
 
 
103
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
104
 
 
105
        gb_file_save (GB_VIEW(window->view)->doc, GTK_WINDOW(window));
 
106
}
 
107
 
 
108
/****************************************************************************/
 
109
/* File->Save_as command.                                                   */
 
110
/****************************************************************************/
 
111
void 
 
112
gb_cmd_file_save_as (BonoboUIComponent *uic,
 
113
                     gpointer           user_data,
 
114
                     const gchar       *verbname)
 
115
{
 
116
        gbWindow *window = GB_WINDOW (user_data);
 
117
 
 
118
        gb_debug (DEBUG_COMMANDS, "");
 
119
 
 
120
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
121
 
 
122
        gb_file_save_as (GB_VIEW(window->view)->doc, GTK_WINDOW(window));
 
123
}
 
124
 
 
125
/****************************************************************************/
 
126
/* File->Print command.                                                     */
 
127
/****************************************************************************/
 
128
void
 
129
gb_cmd_file_print (BonoboUIComponent *uic,
 
130
                   gpointer           user_data,
 
131
                   const gchar       *verbname)
 
132
{
 
133
        gbWindow *window = GB_WINDOW (user_data);
 
134
 
 
135
        gb_debug (DEBUG_COMMANDS, "");
 
136
 
 
137
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
138
 
 
139
        gb_print_dialog (GB_VIEW(window->view), BONOBO_WINDOW(window));
 
140
 
 
141
}
 
142
 
 
143
/****************************************************************************/
 
144
/* File->Close command.                                                     */
 
145
/****************************************************************************/
 
146
void 
 
147
gb_cmd_file_close (BonoboUIComponent *uic,
 
148
                   gpointer           user_data,
 
149
                   const gchar       *verbname)
 
150
{
 
151
        gbWindow *window = GB_WINDOW (user_data);
 
152
 
 
153
        gb_debug (DEBUG_COMMANDS, "");
 
154
 
 
155
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
156
 
 
157
        gb_file_close (window);
 
158
}
 
159
 
 
160
/****************************************************************************/
 
161
/* File->Exit command.                                                      */
 
162
/****************************************************************************/
 
163
void 
 
164
gb_cmd_file_exit (BonoboUIComponent *uic,
 
165
                  gpointer           user_data,
 
166
                  const gchar       *verbname)
 
167
{
 
168
        gbWindow *window = GB_WINDOW (user_data);
 
169
 
 
170
        gb_debug (DEBUG_COMMANDS, "");
 
171
 
 
172
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
173
 
 
174
        gb_file_exit ();
 
175
}
 
176
 
 
177
 
 
178
/****************************************************************************/
 
179
/* Edit->Cut command.                                                       */
 
180
/****************************************************************************/
 
181
void 
 
182
gb_cmd_edit_cut (BonoboUIComponent *uic,
 
183
                 gpointer           user_data,
 
184
                 const gchar       *verbname)
 
185
{
 
186
        gbWindow *window = GB_WINDOW (user_data);
 
187
 
 
188
        gb_debug (DEBUG_COMMANDS, "");
 
189
 
 
190
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
191
 
 
192
        gb_view_cut (GB_VIEW(window->view)); 
 
193
}
 
194
 
 
195
/****************************************************************************/
 
196
/* Edit->Copy command.                                                      */
 
197
/****************************************************************************/
 
198
void 
 
199
gb_cmd_edit_copy (BonoboUIComponent *uic,
 
200
                  gpointer           user_data,
 
201
                  const gchar       *verbname)
 
202
{
 
203
        gbWindow *window = GB_WINDOW (user_data);
 
204
 
 
205
        gb_debug (DEBUG_COMMANDS, "");
 
206
 
 
207
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
208
 
 
209
        gb_view_copy (GB_VIEW(window->view)); 
 
210
}
 
211
 
 
212
/****************************************************************************/
 
213
/* Edit->Paste command.                                                     */
 
214
/****************************************************************************/
 
215
void 
 
216
gb_cmd_edit_paste (BonoboUIComponent *uic,
 
217
                   gpointer           user_data,
 
218
                   const gchar       *verbname)
 
219
{
 
220
        gbWindow *window = GB_WINDOW (user_data);
 
221
 
 
222
        gb_debug (DEBUG_COMMANDS, "");
 
223
 
 
224
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
225
 
 
226
        gb_view_paste (GB_VIEW(window->view)); 
 
227
}
 
228
 
 
229
 
 
230
/****************************************************************************/
 
231
/* Edit->Add command.                                                       */
 
232
/****************************************************************************/
 
233
void 
 
234
gb_cmd_edit_add (BonoboUIComponent *uic,
 
235
                 gpointer           user_data,
 
236
                 const gchar       *verbname)
 
237
{
 
238
        gbWindow *window = GB_WINDOW (user_data);
 
239
 
 
240
        gb_debug (DEBUG_COMMANDS, "");
 
241
 
 
242
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
243
 
 
244
        gb_edit_add_bond (GB_VIEW(window->view), BONOBO_WINDOW(window)); 
 
245
}
 
246
 
 
247
/****************************************************************************/
 
248
/* Edit->Delete command.                                                    */
 
249
/****************************************************************************/
 
250
void 
 
251
gb_cmd_edit_delete (BonoboUIComponent *uic,
 
252
                    gpointer           user_data,
 
253
                    const gchar       *verbname)
 
254
{
 
255
        gbWindow *window = GB_WINDOW (user_data);
 
256
 
 
257
        gb_debug (DEBUG_COMMANDS, "");
 
258
 
 
259
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
260
 
 
261
        gb_edit_delete_bonds (GB_VIEW(window->view), BONOBO_WINDOW(window)); 
 
262
}
 
263
 
 
264
/****************************************************************************/
 
265
/* Edit->Title command.                                                     */
 
266
/****************************************************************************/
 
267
void 
 
268
gb_cmd_edit_title (BonoboUIComponent *uic,
 
269
                   gpointer           user_data,
 
270
                   const gchar       *verbname)
 
271
{
 
272
        gbWindow *window = GB_WINDOW (user_data);
 
273
 
 
274
        gb_debug (DEBUG_COMMANDS, "");
 
275
 
 
276
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
277
 
 
278
        gb_edit_title (GB_VIEW(window->view), BONOBO_WINDOW(window)); 
 
279
}
 
280
 
 
281
/****************************************************************************/
 
282
/* Edit->Select_all command.                                                */
 
283
/****************************************************************************/
 
284
void
 
285
gb_cmd_edit_select_all (BonoboUIComponent *uic,
 
286
                        gpointer           user_data,
 
287
                        const gchar       *verbname)
 
288
{
 
289
        gbWindow *window = GB_WINDOW (user_data);
 
290
 
 
291
        gb_debug (DEBUG_COMMANDS, "");
 
292
 
 
293
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
294
 
 
295
        gb_view_select_all (GB_VIEW(window->view)); 
 
296
}
 
297
 
 
298
/****************************************************************************/
 
299
/* Edit->Select_all command.                                                */
 
300
/****************************************************************************/
 
301
void
 
302
gb_cmd_edit_unselect_all (BonoboUIComponent *uic,
 
303
                          gpointer           user_data,
 
304
                          const gchar       *verbname)
 
305
{
 
306
        gbWindow *window = GB_WINDOW (user_data);
 
307
 
 
308
        gb_debug (DEBUG_COMMANDS, "");
 
309
 
 
310
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
311
 
 
312
        gb_view_unselect_all (GB_VIEW(window->view)); 
 
313
}
 
314
 
 
315
/****************************************************************************/
 
316
/* Settings->Preferences command.                                           */
 
317
/****************************************************************************/
 
318
void
 
319
gb_cmd_settings_preferences (BonoboUIComponent *uic,
 
320
                             gpointer           user_data,
 
321
                             const gchar       *verbname)
 
322
{
 
323
        gbWindow *window = GB_WINDOW (user_data);
 
324
        static GtkWidget *dlg = NULL;
 
325
 
 
326
        gb_debug (DEBUG_COMMANDS, "");
 
327
 
 
328
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
329
 
 
330
        if (dlg != NULL)
 
331
        {
 
332
                gtk_window_present (GTK_WINDOW (dlg));
 
333
                gtk_window_set_transient_for (GTK_WINDOW (dlg), 
 
334
                                              GTK_WINDOW(window));
 
335
 
 
336
                return;
 
337
        }
 
338
                
 
339
        dlg = gb_prefs_dialog_new (GTK_WINDOW(window));
 
340
 
 
341
        g_signal_connect (G_OBJECT (dlg), "destroy",
 
342
                          G_CALLBACK (gtk_widget_destroyed), &dlg);
 
343
        
 
344
        gtk_widget_show (dlg);
 
345
}
 
346
 
 
347
/****************************************************************************/
 
348
/* Settings->Update command.                                                */
 
349
/****************************************************************************/
 
350
void
 
351
gb_cmd_settings_update (BonoboUIComponent *uic,
 
352
                        gpointer           user_data,
 
353
                        const gchar       *verbname)
 
354
{
 
355
        gbWindow *window = GB_WINDOW (user_data);
 
356
 
 
357
        gb_debug (DEBUG_COMMANDS, "");
 
358
 
 
359
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
360
 
 
361
        gb_update_druid ();
 
362
 
 
363
}
 
364
 
 
365
/****************************************************************************/
 
366
/* Help->Contents command.                                                  */
 
367
/****************************************************************************/
 
368
void 
 
369
gb_cmd_help_contents (BonoboUIComponent *uic,
 
370
                      gpointer           user_data,
 
371
                      const gchar       *verbname)
 
372
{
 
373
        gbWindow *window = GB_WINDOW (user_data);
 
374
        GError *error = NULL;
 
375
 
 
376
        gb_debug (DEBUG_COMMANDS, "");
 
377
 
 
378
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
379
 
 
380
        gnome_help_display_with_doc_id (NULL, NULL, "gbonds.xml", NULL, &error);
 
381
        
 
382
        if (error != NULL)
 
383
        {
 
384
                g_warning (error->message);
 
385
 
 
386
                g_error_free (error);
 
387
        }
 
388
}
 
389
 
 
390
/****************************************************************************/
 
391
/* Help->About command.                                                     */
 
392
/****************************************************************************/
 
393
void 
 
394
gb_cmd_help_about (BonoboUIComponent *uic,
 
395
                   gpointer           user_data,
 
396
                   const gchar       *verbname)
 
397
{
 
398
        gbWindow *window = GB_WINDOW (user_data);
 
399
        static GtkWidget *about = NULL;
 
400
        GdkPixbuf        *pixbuf = NULL;
 
401
        
 
402
        gchar *copy_text = "Copyright 2001-2003 Jim Evins";
 
403
        gchar *about_text =
 
404
                _("A savings bond inventory program for GNOME.\n"
 
405
                  " \n"
 
406
                  "Gbonds is free software; you can redistribute it and/or modify it "
 
407
                  "under the terms of the GNU General Public License as published by "
 
408
                  "the Free Software Foundation; either version 2 of the License, or "
 
409
                  "(at your option) any later version.\n" " \n"
 
410
                  "This program is distributed in the hope that it will be useful, but "
 
411
                  "WITHOUT ANY WARRANTY; without even the implied warranty of "
 
412
                  "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU "
 
413
                  "General Public License for more details.\n"
 
414
                  " \n"
 
415
                  "DISCLAIMER:  GBonds is not affiliated with or endorsed by the "
 
416
                  "U.S. Treasury or the U.S. Government.");
 
417
 
 
418
        gchar *authors[] = {
 
419
                "Jim Evins <evins@snaught.com>",
 
420
                " ",
 
421
                _("See the file AUTHORS for additional credits,"),
 
422
                _("or visit http://snaught.com/gbonds"),
 
423
                NULL
 
424
        };
 
425
        
 
426
        gchar *documenters[] = {
 
427
                "",
 
428
                NULL
 
429
        };
 
430
 
 
431
        gchar *translator_credits = _("");
 
432
 
 
433
        gb_debug (DEBUG_COMMANDS, "");
 
434
 
 
435
        g_return_if_fail (window && GB_IS_WINDOW(window));
 
436
 
 
437
        if (about != NULL)
 
438
        {
 
439
                gdk_window_show (about->window);
 
440
                gdk_window_raise (about->window);
 
441
                return;
 
442
        }
 
443
        
 
444
        pixbuf = gdk_pixbuf_new_from_file ( LOGO_PIXMAP, NULL);
 
445
 
 
446
        about = gnome_about_new (_("gbonds"), VERSION,
 
447
                                 copy_text,
 
448
                                 about_text,
 
449
                                (const char **)authors,
 
450
                                (const char **)NULL,
 
451
                                (const char *)NULL,
 
452
                                pixbuf);
 
453
 
 
454
        gtk_window_set_transient_for (GTK_WINDOW (about),
 
455
                                      GTK_WINDOW (window));
 
456
 
 
457
        gtk_window_set_destroy_with_parent (GTK_WINDOW (about), TRUE);
 
458
 
 
459
        if (pixbuf != NULL)
 
460
                g_object_unref (pixbuf);
 
461
        
 
462
        g_signal_connect (G_OBJECT (about), "destroy",
 
463
                          G_CALLBACK (gtk_widget_destroyed), &about);
 
464
        
 
465
        gtk_widget_show (about);
 
466
}
 
467
 
 
468