Made make distcheck work
[pspp-builds.git] / src / ui / gui / psppire.c
1 /* 
2     PSPPIRE --- A Graphical User Interface for PSPP
3     Copyright (C) 2004, 2005  Free Software Foundation
4     Written by John Darrington
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19     02110-1301, USA. */
20
21 /*
22  * Initial main.c file generated by Glade. Edit as required.
23  * Glade will not overwrite this file.
24  */
25
26 #include <assert.h>
27 #include <libpspp/version.h>
28 #include <libpspp/copyleft.h>
29 #include <getopt.h>
30 #include <gtk/gtk.h>
31 #include <gtk/gtk.h>
32 #include <glade/glade.h>
33 #include "menu-actions.h"
34 #include "psppire-dict.h"
35 #include "psppire-var-store.h"
36 #include "psppire-data-store.h"
37
38 #include "helper.h"
39 #include "data-sheet.h"
40 #include "var-sheet.h"
41 #include "psppire-case-array.h"
42
43 GladeXML *xml;
44
45
46 PsppireDict *the_dictionary = 0;
47 PsppireCaseArray *the_cases = 0;
48
49
50 PsppireDataStore *data_store = 0;
51
52
53 static bool parse_command_line (int *argc, char ***argv);
54
55
56 int 
57 main(int argc, char *argv[]) 
58 {
59   if ( ! parse_command_line(&argc, &argv) ) 
60     return 0;
61
62   gtk_init(&argc, &argv);
63
64   glade_init();
65
66   the_dictionary = psppire_dict_new();
67
68   /* Create the model for the var_sheet */
69   PsppireVarStore *var_store = psppire_var_store_new(the_dictionary);
70
71   /* Create the model for the data sheet */
72   the_cases = psppire_case_array_new(100, 20);
73
74   data_store = psppire_data_store_new(the_dictionary, the_cases);
75
76
77   /* load the interface */
78   xml = glade_xml_new("psppire.glade", NULL, NULL);
79
80   if ( !xml ) 
81     {
82       g_print("Is psppire.glade in current directory?\n");
83       return 1;
84     }
85
86   GtkWidget *data_editor = get_widget_assert(xml, "data_editor");
87   gtk_window_set_icon_from_file(GTK_WINDOW(data_editor), "psppicon.png",0);
88
89   /* connect the signals in the interface */
90   glade_xml_signal_autoconnect(xml);
91
92   GtkSheet *var_sheet  = GTK_SHEET(get_widget_assert(xml, "variable_sheet"));
93   GtkSheet *data_sheet = GTK_SHEET(get_widget_assert(xml, "data_sheet"));
94
95   gtk_sheet_set_model(var_sheet, G_SHEET_MODEL(var_store));
96   
97   gtk_sheet_set_model(data_sheet, G_SHEET_MODEL(data_store));
98
99
100   gtk_init_add(callbacks_on_init, 0);
101
102   /* start the event loop */
103   gtk_main();
104   return 0;
105 }
106
107
108 /* Parses the command line specified by ARGC and ARGV as received by
109    main().  Returns true if normal execution should proceed,
110    false if the command-line indicates that PSPP should exit. */
111 static bool
112 parse_command_line (int *argc, char ***argv)
113 {
114   static struct option long_options[] =
115   {
116     {"help", no_argument, NULL, 'h'},
117     {"version", no_argument, NULL, 'V'},
118     {0, 0, 0, 0},
119   };
120
121   int c;
122
123   for (;;)
124     {
125       c = getopt_long (*argc, *argv, "hV", long_options, NULL);
126       if (c == -1)
127         break;
128
129       switch (c)
130         {
131         case 'h':
132           puts("Usage: ./psppire\nMust be run from the directory containing psppire.glade");
133           return false;
134         case 'V':
135           puts (version);
136           puts (legal);
137           return false;
138         default:
139           assert (0);
140         }
141     }
142
143   return true;
144 }