1 /* vi:set et ai sw=2 sts=2 ts=2: */
2 /*-
3 * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <thunar-apr/thunar-apr-abstract-page.h>
26 #include <thunar-apr/thunar-apr-private.h>
27
28
29
30 /* Property identifiers */
31 enum
32 {
33 PROP_0,
34 PROP_FILE,
35 };
36
37 /* Signal identifiers */
38 enum
39 {
40 FILE_CHANGED,
41 LAST_SIGNAL,
42 };
43
44
45
46 static void thunar_apr_abstract_page_dispose (GObject *object);
47 static void thunar_apr_abstract_page_get_property (GObject *object,
48 guint prop_id,
49 GValue *value,
50 GParamSpec *pspec);
51 static void thunar_apr_abstract_page_set_property (GObject *object,
52 guint prop_id,
53 const GValue *value,
54 GParamSpec *pspec);
55 static void thunar_apr_abstract_page_file_changed (ThunarAprAbstractPage *abstract_page,
56 ThunarxFileInfo *file);
57
58
59
60 static guint abstract_page_signals[LAST_SIGNAL];
61
62
63
64 THUNARX_DEFINE_ABSTRACT_TYPE (ThunarAprAbstractPage,
65 thunar_apr_abstract_page,
66 THUNARX_TYPE_PROPERTY_PAGE);
67
68
69
70 static void
thunar_apr_abstract_page_class_init(ThunarAprAbstractPageClass * klass)71 thunar_apr_abstract_page_class_init (ThunarAprAbstractPageClass *klass)
72 {
73 GObjectClass *gobject_class;
74
75 gobject_class = G_OBJECT_CLASS (klass);
76 gobject_class->dispose = thunar_apr_abstract_page_dispose;
77 gobject_class->get_property = thunar_apr_abstract_page_get_property;
78 gobject_class->set_property = thunar_apr_abstract_page_set_property;
79
80 /**
81 * ThunarAprAbstractPage:file:
82 *
83 * The #ThunarxFileInfo for the file being displayed by
84 * this property page.
85 **/
86 g_object_class_install_property (gobject_class,
87 PROP_FILE,
88 g_param_spec_object ("file", "file", "file",
89 THUNARX_TYPE_FILE_INFO,
90 G_PARAM_READWRITE));
91
92 /**
93 * ThunarAprAbstractPage::file-changed:
94 * @abstract_page : a #ThunarAprAbstractPage.
95 * @file : a #ThunarxFileInfo.
96 *
97 * Emitted by @abstract_page whenever the associated
98 * @file changes.
99 **/
100 abstract_page_signals[FILE_CHANGED] =
101 g_signal_new ("file-changed",
102 G_TYPE_FROM_CLASS (klass),
103 G_SIGNAL_RUN_LAST,
104 G_STRUCT_OFFSET (ThunarAprAbstractPageClass, file_changed),
105 NULL, NULL,
106 g_cclosure_marshal_VOID__OBJECT,
107 G_TYPE_NONE, 1,
108 THUNARX_TYPE_FILE_INFO);
109 }
110
111
112
113 static void
thunar_apr_abstract_page_init(ThunarAprAbstractPage * abstract_page)114 thunar_apr_abstract_page_init (ThunarAprAbstractPage *abstract_page)
115 {
116 /* be sure to setup the i18n support for the thunar-apr plugin */
117 thunar_apr_i18n_init ();
118 }
119
120
121
122 static void
thunar_apr_abstract_page_dispose(GObject * object)123 thunar_apr_abstract_page_dispose (GObject *object)
124 {
125 ThunarAprAbstractPage *abstract_page = THUNAR_APR_ABSTRACT_PAGE (object);
126
127 /* disconnect from the file */
128 thunar_apr_abstract_page_set_file (abstract_page, NULL);
129
130 (*G_OBJECT_CLASS (thunar_apr_abstract_page_parent_class)->dispose) (object);
131 }
132
133
134
135 static void
thunar_apr_abstract_page_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)136 thunar_apr_abstract_page_get_property (GObject *object,
137 guint prop_id,
138 GValue *value,
139 GParamSpec *pspec)
140 {
141 ThunarAprAbstractPage *abstract_page = THUNAR_APR_ABSTRACT_PAGE (object);
142
143 switch (prop_id)
144 {
145 case PROP_FILE:
146 g_value_set_object (value, thunar_apr_abstract_page_get_file (abstract_page));
147 break;
148
149 default:
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
151 break;
152 }
153 }
154
155
156
157 static void
thunar_apr_abstract_page_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)158 thunar_apr_abstract_page_set_property (GObject *object,
159 guint prop_id,
160 const GValue *value,
161 GParamSpec *pspec)
162 {
163 ThunarAprAbstractPage *abstract_page = THUNAR_APR_ABSTRACT_PAGE (object);
164
165 switch (prop_id)
166 {
167 case PROP_FILE:
168 thunar_apr_abstract_page_set_file (abstract_page, g_value_get_object (value));
169 break;
170
171 default:
172 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
173 break;
174 }
175 }
176
177
178
179 static void
thunar_apr_abstract_page_file_changed(ThunarAprAbstractPage * abstract_page,ThunarxFileInfo * file)180 thunar_apr_abstract_page_file_changed (ThunarAprAbstractPage *abstract_page,
181 ThunarxFileInfo *file)
182 {
183 /* emit the "file-changed" signal */
184 g_signal_emit (G_OBJECT (abstract_page), abstract_page_signals[FILE_CHANGED], 0, file);
185 }
186
187
188
189 /**
190 * thunar_apr_abstract_page_get_file:
191 * @abstract_page : a #ThunarAprAbstractPage.
192 *
193 * Returns the #ThunarxFileInfo for the file being
194 * displayed by the @abstract_page.
195 *
196 * Return value: the file for @abstract_page.
197 **/
198 ThunarxFileInfo*
thunar_apr_abstract_page_get_file(ThunarAprAbstractPage * abstract_page)199 thunar_apr_abstract_page_get_file (ThunarAprAbstractPage *abstract_page)
200 {
201 g_return_val_if_fail (THUNAR_APR_IS_ABSTRACT_PAGE (abstract_page), NULL);
202 return abstract_page->file;
203 }
204
205
206
207 /**
208 * thunar_apr_abstract_page_set_file:
209 * @abstract_page : a #ThunarAprAbstractPage.
210 * @file : a #ThunarxFileInfo or %NULL.
211 *
212 * Sets the #ThunarxFileInfo being displayed by the
213 * @abstract_page to @file. If @file is %NULL, the
214 * property will be reset.
215 **/
216 void
thunar_apr_abstract_page_set_file(ThunarAprAbstractPage * abstract_page,ThunarxFileInfo * file)217 thunar_apr_abstract_page_set_file (ThunarAprAbstractPage *abstract_page,
218 ThunarxFileInfo *file)
219 {
220 g_return_if_fail (THUNAR_APR_IS_ABSTRACT_PAGE (abstract_page));
221 g_return_if_fail (file == NULL || THUNARX_IS_FILE_INFO (file));
222
223 /* verify that we don't already display that file */
224 if (G_UNLIKELY (abstract_page->file == file))
225 return;
226
227 /* disconnect from the previous file */
228 if (G_UNLIKELY (abstract_page->file != NULL))
229 {
230 g_signal_handlers_disconnect_by_func (G_OBJECT (abstract_page->file), thunar_apr_abstract_page_file_changed, abstract_page);
231 g_object_unref (G_OBJECT (abstract_page->file));
232 }
233
234 /* activate the new file */
235 abstract_page->file = file;
236
237 /* connect to the new file */
238 if (G_LIKELY (file != NULL))
239 {
240 /* connect "changed" signal and take a reference */
241 g_signal_connect_swapped (G_OBJECT (file), "changed", G_CALLBACK (thunar_apr_abstract_page_file_changed), abstract_page);
242 g_object_ref (G_OBJECT (file));
243
244 /* update the initial state */
245 thunar_apr_abstract_page_file_changed (abstract_page, file);
246 }
247
248 /* notify listeners */
249 g_object_notify (G_OBJECT (abstract_page), "file");
250 }
251
252
253
254
255
256