1 /* note.c generated by valac 0.48.6, the Vala compiler
2 * generated from note.vala, do not modify */
3
4 /*
5 * Notes - panel plugin for Xfce Desktop Environment
6 * Copyright (c) 2009-2010 Mike Massonnet <mmassonnet@xfce.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include <gtk/gtk.h>
24 #include <glib-object.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <glib.h>
28
29 #define XNP_TYPE_NOTE (xnp_note_get_type ())
30 #define XNP_NOTE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XNP_TYPE_NOTE, XnpNote))
31 #define XNP_NOTE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XNP_TYPE_NOTE, XnpNoteClass))
32 #define XNP_IS_NOTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XNP_TYPE_NOTE))
33 #define XNP_IS_NOTE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XNP_TYPE_NOTE))
34 #define XNP_NOTE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XNP_TYPE_NOTE, XnpNoteClass))
35
36 typedef struct _XnpNote XnpNote;
37 typedef struct _XnpNoteClass XnpNoteClass;
38 typedef struct _XnpNotePrivate XnpNotePrivate;
39
40 #define XNP_TYPE_HYPERTEXT_VIEW (xnp_hypertext_view_get_type ())
41 #define XNP_HYPERTEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XNP_TYPE_HYPERTEXT_VIEW, XnpHypertextView))
42 #define XNP_HYPERTEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XNP_TYPE_HYPERTEXT_VIEW, XnpHypertextViewClass))
43 #define XNP_IS_HYPERTEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XNP_TYPE_HYPERTEXT_VIEW))
44 #define XNP_IS_HYPERTEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XNP_TYPE_HYPERTEXT_VIEW))
45 #define XNP_HYPERTEXT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XNP_TYPE_HYPERTEXT_VIEW, XnpHypertextViewClass))
46
47 typedef struct _XnpHypertextView XnpHypertextView;
48 typedef struct _XnpHypertextViewClass XnpHypertextViewClass;
49 enum {
50 XNP_NOTE_0_PROPERTY,
51 XNP_NOTE_NAME_PROPERTY,
52 XNP_NOTE_DIRTY_PROPERTY,
53 XNP_NOTE_NUM_PROPERTIES
54 };
55 static GParamSpec* xnp_note_properties[XNP_NOTE_NUM_PROPERTIES];
56 #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
57 #define _g_free0(var) (var = (g_free (var), NULL))
58 enum {
59 XNP_NOTE_SAVE_DATA_SIGNAL,
60 XNP_NOTE_NUM_SIGNALS
61 };
62 static guint xnp_note_signals[XNP_NOTE_NUM_SIGNALS] = {0};
63
64 struct _XnpNote {
65 GtkScrolledWindow parent_instance;
66 XnpNotePrivate * priv;
67 XnpHypertextView* text_view;
68 };
69
70 struct _XnpNoteClass {
71 GtkScrolledWindowClass parent_class;
72 };
73
74 struct _XnpNotePrivate {
75 gchar* _name;
76 guint save_timeout;
77 gboolean _dirty;
78 };
79
80 static gint XnpNote_private_offset;
81 static gpointer xnp_note_parent_class = NULL;
82
83 GType xnp_note_get_type (void) G_GNUC_CONST;
84 G_DEFINE_AUTOPTR_CLEANUP_FUNC (XnpNote, g_object_unref)
85 GType xnp_hypertext_view_get_type (void) G_GNUC_CONST;
86 G_DEFINE_AUTOPTR_CLEANUP_FUNC (XnpHypertextView, g_object_unref)
87 void xnp_note_set_dirty (XnpNote* self,
88 gboolean value);
89 XnpNote* xnp_note_new (const gchar* name);
90 XnpNote* xnp_note_construct (GType object_type,
91 const gchar* name);
92 void xnp_note_set_name (XnpNote* self,
93 const gchar* value);
94 XnpHypertextView* xnp_hypertext_view_new (void);
95 XnpHypertextView* xnp_hypertext_view_construct (GType object_type);
96 static void xnp_note_buffer_changed_cb (XnpNote* self);
97 static void _xnp_note_buffer_changed_cb_gtk_text_buffer_changed (GtkTextBuffer* _sender,
98 gpointer self);
99 static gboolean xnp_note_save_cb (XnpNote* self);
100 const gchar* xnp_note_get_name (XnpNote* self);
101 gboolean xnp_note_get_dirty (XnpNote* self);
102 static gboolean _xnp_note_save_cb_gsource_func (gpointer self);
103 static void xnp_note_finalize (GObject * obj);
104 static GType xnp_note_get_type_once (void);
105 static void _vala_xnp_note_get_property (GObject * object,
106 guint property_id,
107 GValue * value,
108 GParamSpec * pspec);
109 static void _vala_xnp_note_set_property (GObject * object,
110 guint property_id,
111 const GValue * value,
112 GParamSpec * pspec);
113
114 static inline gpointer
xnp_note_get_instance_private(XnpNote * self)115 xnp_note_get_instance_private (XnpNote* self)
116 {
117 return G_STRUCT_MEMBER_P (self, XnpNote_private_offset);
118 }
119
120 static gpointer
_g_object_ref0(gpointer self)121 _g_object_ref0 (gpointer self)
122 {
123 return self ? g_object_ref (self) : NULL;
124 }
125
126 static void
_xnp_note_buffer_changed_cb_gtk_text_buffer_changed(GtkTextBuffer * _sender,gpointer self)127 _xnp_note_buffer_changed_cb_gtk_text_buffer_changed (GtkTextBuffer* _sender,
128 gpointer self)
129 {
130 xnp_note_buffer_changed_cb ((XnpNote*) self);
131 }
132
133 XnpNote*
xnp_note_construct(GType object_type,const gchar * name)134 xnp_note_construct (GType object_type,
135 const gchar* name)
136 {
137 XnpNote * self = NULL;
138 XnpHypertextView* _tmp0_;
139 XnpHypertextView* _tmp1_;
140 XnpHypertextView* _tmp2_;
141 XnpHypertextView* _tmp3_;
142 XnpHypertextView* _tmp4_;
143 XnpHypertextView* _tmp5_;
144 XnpHypertextView* _tmp6_;
145 XnpHypertextView* _tmp7_;
146 GtkTextBuffer* buffer = NULL;
147 XnpHypertextView* _tmp8_;
148 GtkTextBuffer* _tmp9_;
149 GtkTextBuffer* _tmp10_;
150 g_return_val_if_fail (name != NULL, NULL);
151 self = (XnpNote*) g_object_new (object_type, NULL);
152 xnp_note_set_name (self, name);
153 gtk_scrolled_window_set_policy ((GtkScrolledWindow*) self, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
154 _tmp0_ = xnp_hypertext_view_new ();
155 g_object_ref_sink (_tmp0_);
156 _g_object_unref0 (self->text_view);
157 self->text_view = _tmp0_;
158 _tmp1_ = self->text_view;
159 gtk_widget_show ((GtkWidget*) _tmp1_);
160 _tmp2_ = self->text_view;
161 gtk_text_view_set_wrap_mode ((GtkTextView*) _tmp2_, GTK_WRAP_WORD);
162 _tmp3_ = self->text_view;
163 gtk_text_view_set_left_margin ((GtkTextView*) _tmp3_, 2);
164 _tmp4_ = self->text_view;
165 gtk_text_view_set_right_margin ((GtkTextView*) _tmp4_, 2);
166 _tmp5_ = self->text_view;
167 gtk_text_view_set_pixels_above_lines ((GtkTextView*) _tmp5_, 1);
168 _tmp6_ = self->text_view;
169 gtk_text_view_set_pixels_below_lines ((GtkTextView*) _tmp6_, 1);
170 _tmp7_ = self->text_view;
171 gtk_container_add ((GtkContainer*) self, (GtkWidget*) _tmp7_);
172 _tmp8_ = self->text_view;
173 _tmp9_ = gtk_text_view_get_buffer ((GtkTextView*) _tmp8_);
174 _tmp10_ = _g_object_ref0 (_tmp9_);
175 buffer = _tmp10_;
176 g_signal_connect_object (buffer, "changed", (GCallback) _xnp_note_buffer_changed_cb_gtk_text_buffer_changed, self, 0);
177 _g_object_unref0 (buffer);
178 return self;
179 }
180
181 XnpNote*
xnp_note_new(const gchar * name)182 xnp_note_new (const gchar* name)
183 {
184 return xnp_note_construct (XNP_TYPE_NOTE, name);
185 }
186
187 /**
188 * buffer_changed_cb:
189 *
190 * Reset the save_timeout as long as the buffer is under constant
191 * changes and send the save-data signal.
192 */
193 static void
xnp_note_buffer_changed_cb(XnpNote * self)194 xnp_note_buffer_changed_cb (XnpNote* self)
195 {
196 g_return_if_fail (self != NULL);
197 xnp_note_set_dirty (self, TRUE);
198 }
199
200 /**
201 * save_cb:
202 *
203 * Send save-data signal.
204 */
205 static gboolean
xnp_note_save_cb(XnpNote * self)206 xnp_note_save_cb (XnpNote* self)
207 {
208 gboolean result = FALSE;
209 g_return_val_if_fail (self != NULL, FALSE);
210 g_signal_emit (self, xnp_note_signals[XNP_NOTE_SAVE_DATA_SIGNAL], 0);
211 self->priv->save_timeout = (guint) 0;
212 self->priv->_dirty = FALSE;
213 result = FALSE;
214 return result;
215 }
216
217 const gchar*
xnp_note_get_name(XnpNote * self)218 xnp_note_get_name (XnpNote* self)
219 {
220 const gchar* result;
221 const gchar* _tmp0_;
222 g_return_val_if_fail (self != NULL, NULL);
223 _tmp0_ = self->priv->_name;
224 result = _tmp0_;
225 return result;
226 }
227
228 void
xnp_note_set_name(XnpNote * self,const gchar * value)229 xnp_note_set_name (XnpNote* self,
230 const gchar* value)
231 {
232 g_return_if_fail (self != NULL);
233 if (g_strcmp0 (value, xnp_note_get_name (self)) != 0) {
234 gchar* _tmp0_;
235 _tmp0_ = g_strdup (value);
236 _g_free0 (self->priv->_name);
237 self->priv->_name = _tmp0_;
238 g_object_notify_by_pspec ((GObject *) self, xnp_note_properties[XNP_NOTE_NAME_PROPERTY]);
239 }
240 }
241
242 gboolean
xnp_note_get_dirty(XnpNote * self)243 xnp_note_get_dirty (XnpNote* self)
244 {
245 gboolean result;
246 g_return_val_if_fail (self != NULL, FALSE);
247 result = self->priv->_dirty;
248 return result;
249 }
250
251 static gboolean
_xnp_note_save_cb_gsource_func(gpointer self)252 _xnp_note_save_cb_gsource_func (gpointer self)
253 {
254 gboolean result;
255 result = xnp_note_save_cb ((XnpNote*) self);
256 return result;
257 }
258
259 void
xnp_note_set_dirty(XnpNote * self,gboolean value)260 xnp_note_set_dirty (XnpNote* self,
261 gboolean value)
262 {
263 g_return_if_fail (self != NULL);
264 self->priv->_dirty = value;
265 if (self->priv->save_timeout > ((guint) 0)) {
266 g_source_remove (self->priv->save_timeout);
267 }
268 if (value == FALSE) {
269 self->priv->save_timeout = (guint) 0;
270 } else {
271 self->priv->save_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, (guint) 60, _xnp_note_save_cb_gsource_func, g_object_ref (self), g_object_unref);
272 }
273 g_object_notify_by_pspec ((GObject *) self, xnp_note_properties[XNP_NOTE_DIRTY_PROPERTY]);
274 }
275
276 static void
xnp_note_class_init(XnpNoteClass * klass,gpointer klass_data)277 xnp_note_class_init (XnpNoteClass * klass,
278 gpointer klass_data)
279 {
280 xnp_note_parent_class = g_type_class_peek_parent (klass);
281 g_type_class_adjust_private_offset (klass, &XnpNote_private_offset);
282 G_OBJECT_CLASS (klass)->get_property = _vala_xnp_note_get_property;
283 G_OBJECT_CLASS (klass)->set_property = _vala_xnp_note_set_property;
284 G_OBJECT_CLASS (klass)->finalize = xnp_note_finalize;
285 g_object_class_install_property (G_OBJECT_CLASS (klass), XNP_NOTE_NAME_PROPERTY, xnp_note_properties[XNP_NOTE_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
286 g_object_class_install_property (G_OBJECT_CLASS (klass), XNP_NOTE_DIRTY_PROPERTY, xnp_note_properties[XNP_NOTE_DIRTY_PROPERTY] = g_param_spec_boolean ("dirty", "dirty", "dirty", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
287 xnp_note_signals[XNP_NOTE_SAVE_DATA_SIGNAL] = g_signal_new ("save-data", XNP_TYPE_NOTE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
288 }
289
290 static void
xnp_note_instance_init(XnpNote * self,gpointer klass)291 xnp_note_instance_init (XnpNote * self,
292 gpointer klass)
293 {
294 self->priv = xnp_note_get_instance_private (self);
295 self->priv->_dirty = FALSE;
296 }
297
298 static void
xnp_note_finalize(GObject * obj)299 xnp_note_finalize (GObject * obj)
300 {
301 XnpNote * self;
302 self = G_TYPE_CHECK_INSTANCE_CAST (obj, XNP_TYPE_NOTE, XnpNote);
303 xnp_note_set_dirty (self, FALSE);
304 _g_object_unref0 (self->text_view);
305 _g_free0 (self->priv->_name);
306 G_OBJECT_CLASS (xnp_note_parent_class)->finalize (obj);
307 }
308
309 static GType
xnp_note_get_type_once(void)310 xnp_note_get_type_once (void)
311 {
312 static const GTypeInfo g_define_type_info = { sizeof (XnpNoteClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xnp_note_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XnpNote), 0, (GInstanceInitFunc) xnp_note_instance_init, NULL };
313 GType xnp_note_type_id;
314 xnp_note_type_id = g_type_register_static (gtk_scrolled_window_get_type (), "XnpNote", &g_define_type_info, 0);
315 XnpNote_private_offset = g_type_add_instance_private (xnp_note_type_id, sizeof (XnpNotePrivate));
316 return xnp_note_type_id;
317 }
318
319 GType
xnp_note_get_type(void)320 xnp_note_get_type (void)
321 {
322 static volatile gsize xnp_note_type_id__volatile = 0;
323 if (g_once_init_enter (&xnp_note_type_id__volatile)) {
324 GType xnp_note_type_id;
325 xnp_note_type_id = xnp_note_get_type_once ();
326 g_once_init_leave (&xnp_note_type_id__volatile, xnp_note_type_id);
327 }
328 return xnp_note_type_id__volatile;
329 }
330
331 static void
_vala_xnp_note_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)332 _vala_xnp_note_get_property (GObject * object,
333 guint property_id,
334 GValue * value,
335 GParamSpec * pspec)
336 {
337 XnpNote * self;
338 self = G_TYPE_CHECK_INSTANCE_CAST (object, XNP_TYPE_NOTE, XnpNote);
339 switch (property_id) {
340 case XNP_NOTE_NAME_PROPERTY:
341 g_value_set_string (value, xnp_note_get_name (self));
342 break;
343 case XNP_NOTE_DIRTY_PROPERTY:
344 g_value_set_boolean (value, xnp_note_get_dirty (self));
345 break;
346 default:
347 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
348 break;
349 }
350 }
351
352 static void
_vala_xnp_note_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)353 _vala_xnp_note_set_property (GObject * object,
354 guint property_id,
355 const GValue * value,
356 GParamSpec * pspec)
357 {
358 XnpNote * self;
359 self = G_TYPE_CHECK_INSTANCE_CAST (object, XNP_TYPE_NOTE, XnpNote);
360 switch (property_id) {
361 case XNP_NOTE_NAME_PROPERTY:
362 xnp_note_set_name (self, g_value_get_string (value));
363 break;
364 case XNP_NOTE_DIRTY_PROPERTY:
365 xnp_note_set_dirty (self, g_value_get_boolean (value));
366 break;
367 default:
368 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
369 break;
370 }
371 }
372
373