No issues found
1 /*
2 * nautilus-property-page.h - Property pages exported by
3 * NautilusPropertyProvider objects.
4 *
5 * Copyright (C) 2003 Novell, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * Author: Dave Camp <dave@ximian.com>
22 *
23 */
24
25 #include <config.h>
26 #include "nautilus-property-page.h"
27
28 #include "nautilus-extension-i18n.h"
29
30 enum {
31 PROP_0,
32 PROP_NAME,
33 PROP_LABEL,
34 PROP_PAGE,
35 LAST_PROP
36 };
37
38 struct _NautilusPropertyPageDetails {
39 char *name;
40 GtkWidget *label;
41 GtkWidget *page;
42 };
43
44 static GObjectClass *parent_class = NULL;
45
46 /**
47 * nautilus_property_page_new:
48 * @name: the identifier for the property page
49 * @label: the user-visible label of the property page
50 * @page: the property page to display
51 *
52 * Creates a new #NautilusPropertyPage from page_widget.
53 *
54 * Returns: a newly created #NautilusPropertyPage
55 */
56 NautilusPropertyPage *
57 nautilus_property_page_new (const char *name,
58 GtkWidget *label,
59 GtkWidget *page_widget)
60 {
61 NautilusPropertyPage *page;
62
63 g_return_val_if_fail (name != NULL, NULL);
64 g_return_val_if_fail (label != NULL && GTK_IS_WIDGET (label), NULL);
65 g_return_val_if_fail (page_widget != NULL && GTK_IS_WIDGET (page_widget),
66 NULL);
67
68 page = g_object_new (NAUTILUS_TYPE_PROPERTY_PAGE,
69 "name", name,
70 "label", label,
71 "page", page_widget,
72 NULL);
73
74 return page;
75 }
76
77 static void
78 nautilus_property_page_get_property (GObject *object,
79 guint param_id,
80 GValue *value,
81 GParamSpec *pspec)
82 {
83 NautilusPropertyPage *page;
84
85 page = NAUTILUS_PROPERTY_PAGE (object);
86
87 switch (param_id) {
88 case PROP_NAME :
89 g_value_set_string (value, page->details->name);
90 break;
91 case PROP_LABEL :
92 g_value_set_object (value, page->details->label);
93 break;
94 case PROP_PAGE :
95 g_value_set_object (value, page->details->page);
96 break;
97 default :
98 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
99 break;
100 }
101 }
102
103 static void
104 nautilus_property_page_set_property (GObject *object,
105 guint param_id,
106 const GValue *value,
107 GParamSpec *pspec)
108 {
109 NautilusPropertyPage *page;
110
111 page = NAUTILUS_PROPERTY_PAGE (object);
112
113 switch (param_id) {
114 case PROP_NAME :
115 g_free (page->details->name);
116 page->details->name = g_strdup (g_value_get_string (value));
117 g_object_notify (object, "name");
118 break;
119 case PROP_LABEL :
120 if (page->details->label) {
121 g_object_unref (page->details->label);
122 }
123
124 page->details->label = g_object_ref (g_value_get_object (value));
125 g_object_notify (object, "label");
126 break;
127 case PROP_PAGE :
128 if (page->details->page) {
129 g_object_unref (page->details->page);
130 }
131
132 page->details->page = g_object_ref (g_value_get_object (value));
133 g_object_notify (object, "page");
134 break;
135 default :
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
137 break;
138 }
139 }
140
141 static void
142 nautilus_property_page_dispose (GObject *object)
143 {
144 NautilusPropertyPage *page;
145
146 page = NAUTILUS_PROPERTY_PAGE (object);
147
148 if (page->details->label) {
149 g_object_unref (page->details->label);
150 page->details->label = NULL;
151 }
152 if (page->details->page) {
153 g_object_unref (page->details->page);
154 page->details->page = NULL;
155 }
156 }
157
158 static void
159 nautilus_property_page_finalize (GObject *object)
160 {
161 NautilusPropertyPage *page;
162
163 page = NAUTILUS_PROPERTY_PAGE (object);
164
165 g_free (page->details->name);
166
167 g_free (page->details);
168
169 G_OBJECT_CLASS (parent_class)->finalize (object);
170 }
171
172 static void
173 nautilus_property_page_instance_init (NautilusPropertyPage *page)
174 {
175 page->details = g_new0 (NautilusPropertyPageDetails, 1);
176 }
177
178 static void
179 nautilus_property_page_class_init (NautilusPropertyPageClass *class)
180 {
181 parent_class = g_type_class_peek_parent (class);
182
183 G_OBJECT_CLASS (class)->finalize = nautilus_property_page_finalize;
184 G_OBJECT_CLASS (class)->dispose = nautilus_property_page_dispose;
185 G_OBJECT_CLASS (class)->get_property = nautilus_property_page_get_property;
186 G_OBJECT_CLASS (class)->set_property = nautilus_property_page_set_property;
187
188 g_object_class_install_property (G_OBJECT_CLASS (class),
189 PROP_NAME,
190 g_param_spec_string ("name",
191 "Name",
192 "Name of the page",
193 NULL,
194 G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
195 g_object_class_install_property (G_OBJECT_CLASS (class),
196 PROP_LABEL,
197 g_param_spec_object ("label",
198 "Label",
199 "Label widget to display in the notebook tab",
200 GTK_TYPE_WIDGET,
201 G_PARAM_READWRITE));
202 g_object_class_install_property (G_OBJECT_CLASS (class),
203 PROP_PAGE,
204 g_param_spec_object ("page",
205 "Page",
206 "Widget for the property page",
207 GTK_TYPE_WIDGET,
208 G_PARAM_READWRITE));
209 }
210
211 GType
212 nautilus_property_page_get_type (void)
213 {
214 static GType type = 0;
215
216 if (!type) {
217 const GTypeInfo info = {
218 sizeof (NautilusPropertyPageClass),
219 NULL,
220 NULL,
221 (GClassInitFunc)nautilus_property_page_class_init,
222 NULL,
223 NULL,
224 sizeof (NautilusPropertyPage),
225 0,
226 (GInstanceInitFunc)nautilus_property_page_instance_init
227 };
228
229 type = g_type_register_static
230 (G_TYPE_OBJECT,
231 "NautilusPropertyPage",
232 &info, 0);
233 }
234
235 return type;
236 }