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, see <http://www.gnu.org/licenses/>.
19  *
20  *  Author:  Dave Camp <dave@ximian.com>
21  *
22  */
23 
24 #include <config.h>
25 #include "nautilus-property-page.h"
26 
27 #include <glib/gi18n-lib.h>
28 
29 enum
30 {
31     PROP_0,
32     PROP_NAME,
33     PROP_LABEL,
34     PROP_PAGE,
35     LAST_PROP
36 };
37 
38 struct _NautilusPropertyPage
39 {
40     GObject parent_instance;
41 
42     char *name;
43     GtkWidget *label;
44     GtkWidget *page;
45 };
46 
G_DEFINE_TYPE(NautilusPropertyPage,nautilus_property_page,G_TYPE_OBJECT)47 G_DEFINE_TYPE (NautilusPropertyPage, nautilus_property_page, G_TYPE_OBJECT)
48 
49 NautilusPropertyPage *
50 nautilus_property_page_new (const char *name,
51                             GtkWidget  *label,
52                             GtkWidget  *page_widget)
53 {
54     NautilusPropertyPage *page;
55 
56     g_return_val_if_fail (name != NULL, NULL);
57     g_return_val_if_fail (GTK_IS_WIDGET (label), NULL);
58     g_return_val_if_fail (GTK_IS_WIDGET (page_widget), NULL);
59 
60     page = g_object_new (NAUTILUS_TYPE_PROPERTY_PAGE,
61                          "name", name,
62                          "label", label,
63                          "page", page_widget,
64                          NULL);
65 
66     return page;
67 }
68 
69 static void
nautilus_property_page_get_property(GObject * object,guint param_id,GValue * value,GParamSpec * pspec)70 nautilus_property_page_get_property (GObject    *object,
71                                      guint       param_id,
72                                      GValue     *value,
73                                      GParamSpec *pspec)
74 {
75     NautilusPropertyPage *page;
76 
77     page = NAUTILUS_PROPERTY_PAGE (object);
78 
79     switch (param_id)
80     {
81         case PROP_NAME:
82         {
83             g_value_set_string (value, page->name);
84         }
85         break;
86 
87         case PROP_LABEL:
88         {
89             g_value_set_object (value, page->label);
90         }
91         break;
92 
93         case PROP_PAGE:
94         {
95             g_value_set_object (value, page->page);
96         }
97         break;
98 
99         default:
100         {
101             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
102         }
103         break;
104     }
105 }
106 
107 static void
nautilus_property_page_set_property(GObject * object,guint param_id,const GValue * value,GParamSpec * pspec)108 nautilus_property_page_set_property (GObject      *object,
109                                      guint         param_id,
110                                      const GValue *value,
111                                      GParamSpec   *pspec)
112 {
113     NautilusPropertyPage *page;
114 
115     page = NAUTILUS_PROPERTY_PAGE (object);
116 
117     switch (param_id)
118     {
119         case PROP_NAME:
120         {
121             g_free (page->name);
122             page->name = g_strdup (g_value_get_string (value));
123             g_object_notify (object, "name");
124         }
125         break;
126 
127         case PROP_LABEL:
128         {
129             if (page->label)
130             {
131                 g_object_unref (page->label);
132             }
133 
134             page->label = g_object_ref (g_value_get_object (value));
135             g_object_notify (object, "label");
136         }
137         break;
138 
139         case PROP_PAGE:
140         {
141             if (page->page)
142             {
143                 g_object_unref (page->page);
144             }
145 
146             page->page = g_object_ref (g_value_get_object (value));
147             g_object_notify (object, "page");
148         }
149         break;
150 
151         default:
152         {
153             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
154         }
155         break;
156     }
157 }
158 
159 static void
nautilus_property_page_dispose(GObject * object)160 nautilus_property_page_dispose (GObject *object)
161 {
162     NautilusPropertyPage *page;
163 
164     page = NAUTILUS_PROPERTY_PAGE (object);
165 
166     if (page->label)
167     {
168         g_object_unref (page->label);
169         page->label = NULL;
170     }
171     if (page->page)
172     {
173         g_object_unref (page->page);
174         page->page = NULL;
175     }
176 }
177 
178 static void
nautilus_property_page_finalize(GObject * object)179 nautilus_property_page_finalize (GObject *object)
180 {
181     NautilusPropertyPage *page;
182 
183     page = NAUTILUS_PROPERTY_PAGE (object);
184 
185     g_free (page->name);
186 
187     G_OBJECT_CLASS (nautilus_property_page_parent_class)->finalize (object);
188 }
189 
190 static void
nautilus_property_page_init(NautilusPropertyPage * page)191 nautilus_property_page_init (NautilusPropertyPage *page)
192 {
193 }
194 
195 static void
nautilus_property_page_class_init(NautilusPropertyPageClass * class)196 nautilus_property_page_class_init (NautilusPropertyPageClass *class)
197 {
198     G_OBJECT_CLASS (class)->finalize = nautilus_property_page_finalize;
199     G_OBJECT_CLASS (class)->dispose = nautilus_property_page_dispose;
200     G_OBJECT_CLASS (class)->get_property = nautilus_property_page_get_property;
201     G_OBJECT_CLASS (class)->set_property = nautilus_property_page_set_property;
202 
203     g_object_class_install_property (G_OBJECT_CLASS (class),
204                                      PROP_NAME,
205                                      g_param_spec_string ("name",
206                                                           "Name",
207                                                           "Name of the page",
208                                                           NULL,
209                                                           G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
210     g_object_class_install_property (G_OBJECT_CLASS (class),
211                                      PROP_LABEL,
212                                      g_param_spec_object ("label",
213                                                           "Label",
214                                                           "Label widget to display in the notebook tab",
215                                                           GTK_TYPE_WIDGET,
216                                                           G_PARAM_READWRITE));
217     g_object_class_install_property (G_OBJECT_CLASS (class),
218                                      PROP_PAGE,
219                                      g_param_spec_object ("page",
220                                                           "Page",
221                                                           "Widget for the property page",
222                                                           GTK_TYPE_WIDGET,
223                                                           G_PARAM_READWRITE));
224 }
225