summaryrefslogtreecommitdiff
path: root/libnautilus-private/nautilus-preferences-group.c
blob: b96163ec24ee8142c7fa9e7401b3af23af8be5ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-prefs-group-radio.c - Radio button prefs group implementation.

   Copyright (C) 1999, 2000 Eazel, Inc.

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: Ramiro Estrugo <ramiro@eazel.com>
*/

#include <config.h>
#include "nautilus-preferences-group.h"

#include <gnome.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtksignal.h>
#include "nautilus-gtk-macros.h"

/* Signals */
typedef enum
{
	CHANGED,
	LAST_SIGNAL
} RadioGroupSignals;

typedef struct
{
	GtkWidget	*radio_button;
} ButtonInfo;

struct _NautilusPreferencesGroupDetails
{
	GtkWidget	*main_box;
	GtkWidget	*content_box;
	GtkWidget	*description_label;
	gboolean	show_description;
};

static const gint PREFERENCES_GROUP_NOT_FOUND = -1;

/* NautilusPreferencesGroupClass methods */
static void        nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *klass);
static void        nautilus_preferences_group_initialize       (NautilusPreferencesGroup      *preferences_group);


/* GtkObjectClass methods */
static void        nautilus_preferences_group_destroy          (GtkObject                    *object);


/* Private stuff */
static void        preferences_group_construct                 (NautilusPreferencesGroup *prefs_group,
								const gchar * title);

NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesGroup,
				   nautilus_preferences_group,
				   GTK_TYPE_FRAME);

/*
 * NautilusPreferencesGroupClass methods
 */
static void
nautilus_preferences_group_initialize_class (NautilusPreferencesGroupClass *preferences_group_class)
{
	GtkObjectClass *object_class;
	GtkWidgetClass *widget_class;
	
	object_class = GTK_OBJECT_CLASS (preferences_group_class);
	widget_class = GTK_WIDGET_CLASS (preferences_group_class);

 	parent_class = gtk_type_class (gtk_frame_get_type ());
	
	/* GtkObjectClass */
	object_class->destroy = nautilus_preferences_group_destroy;
}

static void
nautilus_preferences_group_initialize (NautilusPreferencesGroup *group)
{
	group->details = g_new (NautilusPreferencesGroupDetails, 1);

	group->details->main_box = NULL;
	group->details->content_box = NULL;
	group->details->description_label = NULL;
	group->details->show_description = FALSE;
}

/*
 * GtkObjectClass methods
 */
static void
nautilus_preferences_group_destroy(GtkObject* object)
{
	NautilusPreferencesGroup *group;
	
	g_return_if_fail (object != NULL);
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (object));
	
	group = NAUTILUS_PREFERENCES_GROUP (object);

	g_free (group->details);
	
	/* Chain */
	if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
		(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}

/*
 * Private stuff
 */
static void
preferences_group_construct (NautilusPreferencesGroup *group,
			     const gchar * title)
{
	g_assert (group != NULL);
	g_assert (title != NULL);

	g_assert (group->details->content_box == NULL);
	g_assert (group->details->main_box == NULL);
	g_assert (group->details->description_label == NULL);

	/* Ourselves */
	gtk_frame_set_shadow_type (GTK_FRAME (group),
				   GTK_SHADOW_ETCHED_IN);

	gtk_frame_set_label (GTK_FRAME (group), title);

	/* Main box */
	group->details->main_box = gtk_vbox_new (FALSE, 0);

	gtk_container_add (GTK_CONTAINER (group),
			   group->details->main_box);

	/* Description label */
	group->details->description_label = gtk_label_new ("Blurb");

	gtk_label_set_justify (GTK_LABEL (group->details->description_label),
			       GTK_JUSTIFY_LEFT);

	gtk_box_pack_start (GTK_BOX (group->details->main_box),
			    group->details->description_label,
			    FALSE,
			    FALSE,
			    0);

	if (group->details->show_description)
	{
		gtk_widget_show (group->details->description_label);
	}

	/* Content box */
	group->details->content_box = 
		gtk_vbox_new (FALSE, 0);

	gtk_box_pack_start (GTK_BOX (group->details->main_box),
			    group->details->content_box,
			    FALSE,
			    FALSE,
			    0);

	gtk_container_set_border_width (GTK_CONTAINER (group->details->content_box),
					4);

	gtk_widget_show (group->details->content_box);
	gtk_widget_show (group->details->main_box);
}

/*
 * NautilusPreferencesGroup public methods
 */
GtkWidget *
nautilus_preferences_group_new (const gchar *title)
{
	NautilusPreferencesGroup *group;

	g_return_val_if_fail (title != NULL, NULL);

	group = NAUTILUS_PREFERENCES_GROUP
		(gtk_widget_new (nautilus_preferences_group_get_type (), NULL));

	preferences_group_construct (group, title);
	
	return GTK_WIDGET (group);
}

GtkWidget *
nautilus_preferences_group_add_item (NautilusPreferencesGroup		*group,
				     const char				*preference_name,
				     NautilusPreferencesItemType	item_type)
{
	GtkWidget			*item;
	NautilusPreference		*preference;

	g_return_val_if_fail (group != NULL, NULL);
	g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_GROUP (group), NULL);

	g_return_val_if_fail (preference_name != NULL, NULL);

	preference = nautilus_preference_find_by_name (preference_name);

	g_assert (preference != NULL);

	gtk_object_unref (GTK_OBJECT (preference));

	preference = NULL;

	item = nautilus_preferences_item_new (preference_name, item_type);
	
	gtk_box_pack_start (GTK_BOX (group->details->content_box),
			    item,
			    TRUE,
			    TRUE,
			    0);

	gtk_widget_show (item);

	return item;
}