1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 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/>. */
19 #include <gtk/gtksignal.h>
20 #include <gtk/gtkwindow.h>
25 #define _(msgid) gettext (msgid)
26 #define N_(msgid) msgid
28 #include "psppire-window.h"
31 static void psppire_window_base_finalize (PsppireWindowClass *, gpointer);
32 static void psppire_window_base_init (PsppireWindowClass *class);
33 static void psppire_window_class_init (PsppireWindowClass *class);
34 static void psppire_window_init (PsppireWindow *window);
39 psppire_window_get_type (void)
41 static GType psppire_window_type = 0;
43 if (!psppire_window_type)
45 static const GTypeInfo psppire_window_info =
47 sizeof (PsppireWindowClass),
48 (GBaseInitFunc) psppire_window_base_init,
49 (GBaseFinalizeFunc) psppire_window_base_finalize,
50 (GClassInitFunc)psppire_window_class_init,
51 (GClassFinalizeFunc) NULL,
53 sizeof (PsppireWindow),
55 (GInstanceInitFunc) psppire_window_init,
59 g_type_register_static (GTK_TYPE_WINDOW, "PsppireWindow",
60 &psppire_window_info, 0);
63 return psppire_window_type;
76 uniquify (const gchar *str, int *x)
78 return g_strdup_printf ("%s%d", str, (*x)++);
82 psppire_window_set_property (GObject *object,
87 PsppireWindow *window = PSPPIRE_WINDOW (object);
89 PsppireWindowClass *class = PSPPIRE_WINDOW_CLASS (G_OBJECT_GET_CLASS (object));
95 gchar mdash[6] = {0,0,0,0,0,0};
96 gchar *basename, *title;
97 const gchar *name = g_value_get_string (value);
98 gchar *candidate_name = strdup (name);
101 while ( g_hash_table_lookup (class->name_table, candidate_name))
103 free (candidate_name);
104 candidate_name = uniquify (name, &x);
107 basename = g_path_get_basename (candidate_name);
108 g_unichar_to_utf8 (0x2014, mdash);
110 title = g_strdup_printf ( _("%s %s PSPPIRE Syntax Editor"), basename, mdash);
112 gtk_window_set_title (GTK_WINDOW (window), title);
115 window->name = candidate_name;
118 g_hash_table_insert (class->name_table, window->name, window);
125 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
132 psppire_window_get_property (GObject *object,
137 PsppireWindow *window = PSPPIRE_WINDOW (object);
142 g_value_set_string (value, window->name);
145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
153 psppire_window_finalize (GObject *object)
155 PsppireWindow *window = PSPPIRE_WINDOW (object);
156 PsppireWindowClass *class = PSPPIRE_WINDOW_CLASS (G_OBJECT_GET_CLASS (object));
158 GtkWindowClass *parent_class = g_type_class_peek_parent (class);
160 if ( window->finalized )
163 window->finalized = TRUE;
165 g_debug ("%s %p", __FUNCTION__, object);
167 g_hash_table_remove (class->name_table, window->name);
170 if (G_OBJECT_CLASS (parent_class)->finalize)
171 (*G_OBJECT_CLASS (parent_class)->finalize) (object);
176 psppire_window_class_init (PsppireWindowClass *class)
178 GObjectClass *object_class = G_OBJECT_CLASS (class);
180 GParamSpec *filename_spec =
181 g_param_spec_string ("filename",
183 "The name of the file associated with this window, if any",
185 G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT
189 object_class->set_property = psppire_window_set_property;
190 object_class->get_property = psppire_window_get_property;
192 g_object_class_install_property (object_class,
198 class->name_table = g_hash_table_new (g_str_hash, g_str_equal);
200 g_hash_table_insert (class->name_table, "Untitled", NULL);
205 psppire_window_base_init (PsppireWindowClass *class)
207 GObjectClass *object_class = G_OBJECT_CLASS (class);
209 object_class->finalize = psppire_window_finalize;
216 psppire_window_base_finalize (PsppireWindowClass *class,
219 g_hash_table_destroy (class->name_table);
225 psppire_window_init (PsppireWindow *window)
228 window->finalized = FALSE;
233 psppire_window_new (void)
235 return GTK_WIDGET (g_object_new (psppire_window_get_type (), "type", GTK_WINDOW_TOPLEVEL, NULL));
240 psppire_window_get_filename (PsppireWindow *w)
242 const gchar *name = NULL;
243 g_object_get (w, "filename", name, NULL);
249 psppire_window_set_filename (PsppireWindow *w, const gchar *filename)
251 g_object_set (w, "filename", filename, NULL);