1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2009 Free Software Foundation
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.
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.
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/>. */
18 /* This file is a rubbish bin where stuff gets put when it doesn't seem to
23 #include <glib-object.h>
27 #include "message-dialog.h"
28 #include <data/format.h>
29 #include <data/data-in.h>
30 #include <data/data-out.h>
31 #include <data/dictionary.h>
32 #include <data/casereader-provider.h>
33 #include <libpspp/message.h>
34 #include "psppire-syntax-window.h"
35 #include <gtk/gtkbuilder.h>
36 #include <libpspp/i18n.h>
41 #include <data/settings.h>
43 #include "psppire-data-store.h"
49 /* Formats a value according to FORMAT
50 The returned string must be freed when no longer required */
52 value_to_text (union value v, const PsppireDict *dict, struct fmt_spec format)
56 s = data_out (&v, dict_get_encoding (dict->dict), &format);
65 text_to_value (const gchar *text, union value *v,
66 struct fmt_spec format)
70 if ( format.type != FMT_A)
72 if ( ! text ) return FALSE;
75 const gchar *s = text;
83 if ( !*s) return FALSE;
88 ok = data_in (ss_cstr (text), LEGACY_NATIVE, format.type, 0, 0, 0,
89 v, fmt_var_width (&format));
97 builder_new_real (const gchar *name)
99 GtkBuilder *builder = gtk_builder_new ();
102 if ( ! gtk_builder_add_from_file (builder, name, &err))
104 g_critical ("Couldnt open user interface file %s: %s", name, err->message);
105 g_clear_error (&err);
113 get_object_assert (GtkBuilder *builder, const gchar *name, GType type)
118 o = gtk_builder_get_object (builder, name);
121 g_critical ("Object \"%s\" could not be found\n", name);
123 if ( ! g_type_is_a (G_OBJECT_TYPE (o), type))
125 g_critical ("Object \"%s\" was expected to have type %s, but in fact has type %s",
126 name, g_type_name (type), G_OBJECT_TYPE_NAME (o));
134 get_action_assert (GtkBuilder *builder, const gchar *name)
136 return GTK_ACTION (get_object_assert (builder, name, GTK_TYPE_ACTION));
140 get_widget_assert (GtkBuilder *builder, const gchar *name)
142 return GTK_WIDGET (get_object_assert (builder, name, GTK_TYPE_WIDGET));
145 /* This function must be used whenever a filename generated by glib,
146 (eg, from gtk_file_chooser_get_filename) and passed to the C library,
147 (eg through a pspp syntax string).
150 convert_glib_filename_to_system_filename (const gchar *fname, GError **err)
155 const gchar *target_encoding;
156 gchar *utf8_name = NULL;
158 g_get_charset (&target_encoding);
160 output_name = g_convert (fname, -1, target_encoding,
161 "UTF-8", NULL, NULL, err);
163 output_name = xstrdup (fname);
171 #define _(msgid) gettext (msgid)
172 #define N_(msgid) msgid
180 dialog = gtk_message_dialog_new (NULL,
184 _("Sorry. The help system hasn't yet "
185 "been implemented."));
186 gtk_dialog_run (GTK_DIALOG (dialog));
187 gtk_widget_destroy (dialog);
191 connect_help (GtkBuilder *xml)
193 GSList *helps = gtk_builder_get_objects (xml);
196 for ( i = helps; i ; i = g_slist_next (i))
198 GObject *o = i->data;
199 if ( GTK_IS_WIDGET (o) )
203 g_object_get (o, "name", &name, NULL);
206 strncpy (s, name, 11);
210 if ( 0 == strcmp ("help_button", s))
212 g_signal_connect (o, "clicked", give_help, 0);
217 g_slist_free (helps);
222 reference_manual (GtkMenuItem *menu, gpointer data)
225 gchar *cmd = g_strdup_printf ("yelp file://%s", relocate (DOCDIR "/pspp.xml"));
227 if ( ! g_spawn_command_line_async (cmd, &err) )
229 msg (ME, _("Cannot open reference manual: %s"), err->message);
233 g_clear_error (&err);
237 /* Create a deep copy of SRC */
239 clone_list_store (const GtkListStore *src)
241 GtkTreeIter src_iter;
244 const gint n_cols = gtk_tree_model_get_n_columns (GTK_TREE_MODEL (src));
245 GType *types = g_malloc (sizeof (*types) * n_cols);
250 for (i = 0 ; i < n_cols; ++i )
251 types[i] = gtk_tree_model_get_column_type (GTK_TREE_MODEL (src), i);
253 dest = gtk_list_store_newv (n_cols, types);
255 for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (src),
258 ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (src), &src_iter))
260 GtkTreeIter dest_iter;
261 gtk_list_store_append (dest, &dest_iter);
263 for (i = 0 ; i < n_cols; ++i )
267 gtk_tree_model_get_value (GTK_TREE_MODEL (src), &src_iter, i, &val);
268 gtk_list_store_set_value (dest, &dest_iter, i, &val);
270 g_value_unset (&val);
282 paste_syntax_in_new_window (const gchar *syntax)
284 GtkWidget *se = psppire_syntax_window_new ();
286 gtk_text_buffer_insert_at_cursor (PSPPIRE_SYNTAX_WINDOW (se)->buffer, syntax, -1);
288 gtk_widget_show (se);