Translate the names of aggretation functions. Fixes bug #31035
[pspp] / src / ui / gui / dict-display.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2007  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
18 #include <config.h>
19 #include <gettext.h>
20 #include <gtk/gtk.h>
21
22 #include "psppire-conf.h"
23 #include "dict-display.h"
24
25 #include "psppire-dict.h"
26 #include "psppire-var-view.h"
27 #include <libpspp/i18n.h>
28 #include "helper.h"
29 #include <data/variable.h>
30 #include <data/format.h>
31
32 #define _(msgid) gettext (msgid)
33 #define N_(msgid) msgid
34
35 static void
36 get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter,
37                 GtkTreeModel **model, GtkTreeIter *iter
38                 )
39 {
40   *model = top_model;
41   *iter = *top_iter;
42   while (GTK_IS_TREE_MODEL_FILTER (*model))
43     {
44       GtkTreeIter parent_iter = *iter;
45       GtkTreeModelFilter *parent_model = GTK_TREE_MODEL_FILTER (*model);
46
47       *model = gtk_tree_model_filter_get_model (parent_model);
48
49       gtk_tree_model_filter_convert_iter_to_child_iter (parent_model,
50                                                         iter,
51                                                         &parent_iter);
52     }
53
54   g_assert (PSPPIRE_IS_DICT (*model));
55 }
56
57
58 void
59 insert_source_row_into_entry (GtkTreeIter iter,
60                               GtkWidget *dest,
61                               GtkTreeModel *model,
62                               gpointer data
63                               )
64 {
65   GtkTreePath *path;
66   GtkTreeModel *dict;
67   gint *idx;
68   struct variable *var;
69   GtkTreeIter dict_iter;
70
71   g_return_if_fail (GTK_IS_ENTRY(dest));
72
73   get_base_model (model, &iter, &dict, &dict_iter);
74
75   path = gtk_tree_model_get_path (GTK_TREE_MODEL (dict), &dict_iter);
76
77   idx = gtk_tree_path_get_indices (path);
78
79   var =  psppire_dict_get_variable (PSPPIRE_DICT (dict), *idx);
80
81   gtk_tree_path_free (path);
82
83   gtk_entry_set_text (GTK_ENTRY (dest),  var_get_name (var));
84 }
85
86
87 void
88 insert_source_row_into_tree_view (GtkTreeIter iter,
89                                   GtkWidget *dest,
90                                   GtkTreeModel *model,
91                                   gpointer data
92                                   )
93 {
94   GtkTreePath *path;
95   GtkTreeIter dest_iter;
96   GtkTreeIter dict_iter;
97   gint *row ;
98   GtkTreeModel *destmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
99
100   const struct variable *var;
101   GtkTreeModel *dict;
102
103   get_base_model (model, &iter, &dict, &dict_iter);
104
105   path = gtk_tree_model_get_path (dict, &dict_iter);
106
107   row = gtk_tree_path_get_indices (path);
108
109   var = psppire_dict_get_variable (PSPPIRE_DICT (dict), *row);
110
111   gtk_list_store_append (GTK_LIST_STORE (destmodel),  &dest_iter);
112
113   gtk_list_store_set (GTK_LIST_STORE (destmodel), &dest_iter, 0, var, -1);
114
115   gtk_tree_path_free (path);
116 }
117
118
119
120 gboolean
121 is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter,
122                        PsppireSelector *selector)
123 {
124   gboolean result;
125   GtkTreeIter dict_iter;
126   GtkTreeModel *dict;
127   struct variable *var;
128   gint dict_index;
129   gint *indeces;
130   GtkTreePath *path;
131   GtkWidget *entry = NULL;
132   const gchar *text = NULL;
133
134   g_object_get (selector, "dest-widget", &entry, NULL);
135
136   text = gtk_entry_get_text (GTK_ENTRY (entry));
137
138   get_base_model (model, iter, &dict, &dict_iter);
139
140   path = gtk_tree_model_get_path (dict, &dict_iter);
141
142   indeces = gtk_tree_path_get_indices (path);
143
144   dict_index = indeces [0];
145
146   var = psppire_dict_get_variable (PSPPIRE_DICT (dict), dict_index);
147
148   gtk_tree_path_free (path);
149
150   result = ( 0 == strcmp (text, var_get_name (var) ));
151
152   return result;
153 }
154