gui: Redo var sheet, data sheet, text import with PsppSheetView.
[pspp] / src / ui / gui / psppire-var-store.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2006, 2009, 2010, 2011, 2012  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <gettext.h>
21 #define _(msgid) gettext (msgid)
22 #define N_(msgid) msgid
23
24 #include <libpspp/i18n.h>
25
26 #include <gobject/gvaluecollector.h>
27
28 #include "psppire-var-store.h"
29 #include "helper.h"
30
31 #include <data/dictionary.h>
32 #include <data/variable.h>
33 #include <data/format.h>
34 #include <data/missing-values.h>
35
36 #include "val-labs-dialog.h"
37 #include "missing-val-dialog.h"
38 #include <data/value-labels.h>
39
40 #include "var-display.h"
41
42 enum
43   {
44     PROP_0,
45     PSPPIRE_VAR_STORE_DICT
46   };
47
48 static void         psppire_var_store_init            (PsppireVarStore      *var_store);
49 static void         psppire_var_store_class_init      (PsppireVarStoreClass *class);
50 static void         psppire_var_store_finalize        (GObject           *object);
51 static void         psppire_var_store_dispose        (GObject           *object);
52
53
54 static GObjectClass *parent_class = NULL;
55
56 GType
57 psppire_var_store_get_type (void)
58 {
59   static GType var_store_type = 0;
60
61   if (!var_store_type)
62     {
63       static const GTypeInfo var_store_info =
64       {
65         sizeof (PsppireVarStoreClass),
66         NULL,           /* base_init */
67         NULL,           /* base_finalize */
68         (GClassInitFunc) psppire_var_store_class_init,
69         NULL,           /* class_finalize */
70         NULL,           /* class_data */
71         sizeof (PsppireVarStore),
72         0,
73         (GInstanceInitFunc) psppire_var_store_init,
74       };
75
76       var_store_type = g_type_register_static (G_TYPE_OBJECT, "PsppireVarStore", &var_store_info, 0);
77     }
78
79   return var_store_type;
80 }
81
82 static void
83 psppire_var_store_set_property (GObject      *object,
84                                 guint         property_id,
85                                 const GValue *value,
86                                 GParamSpec   *pspec)
87 {
88   PsppireVarStore *self = (PsppireVarStore *) object;
89
90   switch (property_id)
91     {
92     case PSPPIRE_VAR_STORE_DICT:
93       if ( self->dictionary)
94         g_object_unref (self->dictionary);
95       self->dictionary = g_value_dup_object (value);
96       break;
97
98     default:
99       G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
100       break;
101     }
102 }
103
104 static void
105 psppire_var_store_get_property (GObject      *object,
106                         guint         property_id,
107                         GValue       *value,
108                         GParamSpec   *pspec)
109 {
110   PsppireVarStore *self = (PsppireVarStore *) object;
111
112   switch (property_id)
113     {
114     case PSPPIRE_VAR_STORE_DICT:
115       g_value_take_object (value, self->dictionary);
116       break;
117
118     default:
119       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
120       break;
121     }
122 }
123
124
125 static void
126 psppire_var_store_class_init (PsppireVarStoreClass *class)
127 {
128   GObjectClass *object_class;
129   GParamSpec *dict_pspec;
130
131   parent_class = g_type_class_peek_parent (class);
132   object_class = (GObjectClass*) class;
133
134   object_class->finalize = psppire_var_store_finalize;
135   object_class->dispose = psppire_var_store_dispose;
136   object_class->set_property = psppire_var_store_set_property;
137   object_class->get_property = psppire_var_store_get_property;
138
139   dict_pspec = g_param_spec_object ("dictionary",
140                                     "Dictionary",
141                                     "The PsppireDict represented by this var store",
142                                     PSPPIRE_TYPE_DICT,
143                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
144                                     
145   g_object_class_install_property (object_class,
146                                    PSPPIRE_VAR_STORE_DICT,
147                                    dict_pspec);
148 }
149
150 static void
151 psppire_var_store_init (PsppireVarStore *var_store)
152 {
153   var_store->dictionary = NULL;
154 }
155
156 struct variable *
157 psppire_var_store_get_var (PsppireVarStore *store, glong row)
158 {
159   return psppire_dict_get_variable (store->dictionary, row);
160 }
161
162 /**
163  * psppire_var_store_new:
164  * @dict: The dictionary for this var_store.
165  *
166  *
167  * Return value: a new #PsppireVarStore
168  **/
169 PsppireVarStore *
170 psppire_var_store_new (PsppireDict *dict)
171 {
172   PsppireVarStore *retval;
173
174   retval = g_object_new (GTK_TYPE_VAR_STORE, "dictionary", dict, NULL);
175
176   //  psppire_var_store_set_dictionary (retval, dict);
177
178   return retval;
179 }
180
181 static void
182 psppire_var_store_finalize (GObject *object)
183 {
184   /* must chain up */
185   (* parent_class->finalize) (object);
186 }
187
188 static void
189 psppire_var_store_dispose (GObject *object)
190 {
191   PsppireVarStore *self = PSPPIRE_VAR_STORE (object);
192
193   if (self->dictionary)
194     g_object_unref (self->dictionary);
195
196   /* must chain up */
197   (* parent_class->finalize) (object);
198 }
199
200
201 /* Return the number of variables */
202 gint
203 psppire_var_store_get_var_cnt (PsppireVarStore  *store)
204 {
205   return psppire_dict_get_var_cnt (store->dictionary);
206 }