1 /*
2 
3 Copyright (c) 2001-2007 Michael Terry
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program 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
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 
19 */
20 
21 #include <string.h>
22 #include "xpad-settings.h"
23 #include "fio.h"
24 
25 G_DEFINE_TYPE(XpadSettings, xpad_settings, G_TYPE_OBJECT)
26 #define XPAD_SETTINGS_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), XPAD_TYPE_SETTINGS, XpadSettingsPrivate))
27 
28 #define DEFAULTS_FILENAME	"default-style"
29 
30 struct XpadSettingsPrivate
31 {
32 	guint width;
33 	guint height;
34 	gboolean has_decorations;
35 	gboolean confirm_destroy;
36 	gboolean edit_lock;
37 	gboolean sticky;
38 	gboolean has_toolbar;
39 	gboolean autohide_toolbar;
40 	gboolean has_scrollbar;
41 	GdkColor *back;
42 	GdkColor *text;
43 	gchar *fontname;
44 	GSList *toolbar_buttons;
45 };
46 
47 enum
48 {
49 	CHANGE_BUTTONS,
50 	LAST_SIGNAL
51 };
52 
53 enum
54 {
55   PROP_0,
56   PROP_WIDTH,
57   PROP_HEIGHT,
58   PROP_HAS_DECORATIONS,
59   PROP_CONFIRM_DESTROY,
60   PROP_STICKY,
61   PROP_EDIT_LOCK,
62   PROP_HAS_TOOLBAR,
63   PROP_AUTOHIDE_TOOLBAR,
64   PROP_HAS_SCROLLBAR,
65   PROP_BACK_COLOR,
66   PROP_TEXT_COLOR,
67   PROP_FONTNAME,
68   LAST_PROP
69 };
70 
71 static void load_from_file (XpadSettings *settings, const gchar *filename);
72 static void save_to_file (XpadSettings *settings, const gchar *filename);
73 static void xpad_settings_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
74 static void xpad_settings_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
75 static void xpad_settings_finalize (GObject *object);
76 
77 static XpadSettings *_xpad_settings = NULL;
78 static guint signals[LAST_SIGNAL] = { 0 };
79 
80 XpadSettings *
xpad_settings(void)81 xpad_settings (void)
82 {
83 	/* Singleton class */
84 	if (!_xpad_settings)
85 		_xpad_settings = XPAD_SETTINGS (g_object_new (XPAD_TYPE_SETTINGS, NULL));
86 
87 	return _xpad_settings;
88 }
89 
90 static void
xpad_settings_class_init(XpadSettingsClass * klass)91 xpad_settings_class_init (XpadSettingsClass *klass)
92 {
93 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
94 
95 	gobject_class->finalize = xpad_settings_finalize;
96 	gobject_class->set_property = xpad_settings_set_property;
97 	gobject_class->get_property = xpad_settings_get_property;
98 
99 	/* Properties */
100 
101 	g_object_class_install_property (gobject_class,
102 	                                 PROP_WIDTH,
103 	                                 g_param_spec_uint ("width",
104 	                                                    "Default Width of Pads",
105 	                                                    "Window width of pads on creation",
106 	                                                    0,
107 	                                                    G_MAXUINT,
108 	                                                    200,
109 	                                                    G_PARAM_READWRITE));
110 
111 	g_object_class_install_property (gobject_class,
112 	                                 PROP_HEIGHT,
113 	                                 g_param_spec_uint ("height",
114 	                                                    "Default Height of Pads",
115 	                                                    "Window height of pads on creation",
116 	                                                    0,
117 	                                                    G_MAXUINT,
118 	                                                    200,
119 	                                                    G_PARAM_READWRITE));
120 
121 	g_object_class_install_property (gobject_class,
122 	                                 PROP_HAS_DECORATIONS,
123 	                                 g_param_spec_boolean ("has_decorations",
124 	                                                       "Has Decorations",
125 	                                                       "Whether pads have window decorations",
126 	                                                       TRUE,
127 	                                                       G_PARAM_READWRITE));
128 
129 	g_object_class_install_property (gobject_class,
130 	                                 PROP_CONFIRM_DESTROY,
131 	                                 g_param_spec_boolean ("confirm_destroy",
132 	                                                       "Confirm Destroy",
133 	                                                       "Whether destroying a pad requires user confirmation",
134 	                                                       TRUE,
135 	                                                       G_PARAM_READWRITE));
136 
137 	g_object_class_install_property (gobject_class,
138 	                                 PROP_STICKY,
139 	                                 g_param_spec_boolean ("sticky",
140 	                                                       "Default Stickiness",
141 	                                                       "Whether pads are sticky on creation",
142 	                                                       FALSE,
143 	                                                       G_PARAM_READWRITE));
144 
145 	g_object_class_install_property (gobject_class,
146 	                                 PROP_EDIT_LOCK,
147 	                                 g_param_spec_boolean ("edit_lock",
148 	                                                       "Edit Lock",
149 	                                                       "Whether edit lock mode is enabled",
150 	                                                       FALSE,
151 	                                                       G_PARAM_READWRITE));
152 
153 	g_object_class_install_property (gobject_class,
154 	                                 PROP_HAS_TOOLBAR,
155 	                                 g_param_spec_boolean ("has_toolbar",
156 	                                                       "Has Toolbar",
157 	                                                       "Whether pads have toolbars",
158 	                                                       TRUE,
159 	                                                       G_PARAM_READWRITE));
160 
161 	g_object_class_install_property (gobject_class,
162 	                                 PROP_AUTOHIDE_TOOLBAR,
163 	                                 g_param_spec_boolean ("autohide_toolbar",
164 	                                                       "Autohide Toolbar",
165 	                                                       "Whether toolbars hide when not used",
166 	                                                       TRUE,
167 	                                                       G_PARAM_READWRITE));
168 
169 	g_object_class_install_property (gobject_class,
170 	                                 PROP_HAS_SCROLLBAR,
171 	                                 g_param_spec_boolean ("has_scrollbar",
172 	                                                       "Has Scrollbar",
173 	                                                       "Whether pads have scrollbars",
174 	                                                       FALSE,
175 	                                                       G_PARAM_READWRITE));
176 
177 	g_object_class_install_property (gobject_class,
178 	                                 PROP_FONTNAME,
179 	                                 g_param_spec_string ("fontname",
180 	                                                      "Font Name",
181 	                                                      "Default name of pad font",
182 	                                                      NULL,
183 	                                                      G_PARAM_READWRITE));
184 
185 	g_object_class_install_property (gobject_class,
186 	                                 PROP_TEXT_COLOR,
187 	                                 g_param_spec_boxed ("text_color",
188 	                                                     "Text Color",
189 	                                                     "Default color of pad text",
190 	                                                     GDK_TYPE_COLOR,
191 	                                                     G_PARAM_READWRITE));
192 
193 	g_object_class_install_property (gobject_class,
194 	                                 PROP_BACK_COLOR,
195 	                                 g_param_spec_boxed ("back_color",
196 	                                                     "Back Color",
197 	                                                     "Default color of pad background",
198 	                                                     GDK_TYPE_COLOR,
199 	                                                     G_PARAM_READWRITE));
200 
201 	/* Signals */
202 
203 	signals[CHANGE_BUTTONS] =
204 		g_signal_new ("change_buttons",
205 		              G_OBJECT_CLASS_TYPE (gobject_class),
206 		              G_SIGNAL_RUN_LAST,
207 		              G_STRUCT_OFFSET (XpadSettingsClass, change_buttons),
208 		              NULL, NULL,
209 		              g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
210 
211 	g_type_class_add_private (gobject_class, sizeof (XpadSettingsPrivate));
212 }
213 
214 static void
xpad_settings_init(XpadSettings * settings)215 xpad_settings_init (XpadSettings *settings)
216 {
217 	GdkColor back, text;
218 
219 	settings->priv = XPAD_SETTINGS_GET_PRIVATE (settings);
220 
221 	/* A pleasant light yellow color, similar to
222 	   commercial sticky notes. */
223 	back.pixel = 0;
224 	back.red = 65535;
225 	back.green = 61166;
226 	back.blue = 39321;
227 	settings->priv->back = gdk_color_copy (&back);
228 
229 	/* Black */
230 	text.pixel = 0;
231 	text.red = 0;
232 	text.green = 0;
233 	text.blue = 0;
234 	settings->priv->text = gdk_color_copy (&text);
235 
236 	settings->priv->width = 200;
237 	settings->priv->height = 200;
238 	settings->priv->has_decorations = TRUE;
239 	settings->priv->confirm_destroy = TRUE;
240 	settings->priv->sticky = FALSE;
241 	settings->priv->edit_lock = FALSE;
242 	settings->priv->fontname = NULL;
243 	settings->priv->has_toolbar = TRUE;
244 	settings->priv->autohide_toolbar = TRUE;
245 	settings->priv->has_scrollbar = TRUE;
246 
247 	settings->priv->toolbar_buttons = NULL;
248 	settings->priv->toolbar_buttons = g_slist_append (settings->priv->toolbar_buttons, g_strdup ("New"));
249 	settings->priv->toolbar_buttons = g_slist_append (settings->priv->toolbar_buttons, g_strdup ("Delete"));
250 	settings->priv->toolbar_buttons = g_slist_append (settings->priv->toolbar_buttons, g_strdup ("Close"));
251 
252 	load_from_file (settings, DEFAULTS_FILENAME);
253 }
254 
255 static void
xpad_settings_finalize(GObject * object)256 xpad_settings_finalize (GObject *object)
257 {
258 	XpadSettings *settings = XPAD_SETTINGS (object);
259 
260 	g_slist_free (settings->priv->toolbar_buttons);
261 	gdk_color_free (settings->priv->text);
262 	gdk_color_free (settings->priv->back);
263 	g_free (settings->priv->fontname);
264 
265 	G_OBJECT_CLASS (xpad_settings_parent_class)->finalize (object);
266 }
267 
xpad_settings_set_width(XpadSettings * settings,guint width)268 void xpad_settings_set_width (XpadSettings *settings, guint width)
269 {
270 	if (settings->priv->width == width)
271 		return;
272 
273 	settings->priv->width = width;
274 
275 	save_to_file (settings, DEFAULTS_FILENAME);
276 
277 	g_object_notify (G_OBJECT (settings), "width");
278 }
279 
xpad_settings_get_width(XpadSettings * settings)280 guint xpad_settings_get_width (XpadSettings *settings)
281 {
282 	return settings->priv->width;
283 }
284 
xpad_settings_set_height(XpadSettings * settings,guint height)285 void xpad_settings_set_height (XpadSettings *settings, guint height)
286 {
287 	if (settings->priv->height == height)
288 		return;
289 
290 	settings->priv->height = height;
291 
292 	save_to_file (settings, DEFAULTS_FILENAME);
293 
294 	g_object_notify (G_OBJECT (settings), "height");
295 }
296 
xpad_settings_get_height(XpadSettings * settings)297 guint xpad_settings_get_height (XpadSettings *settings)
298 {
299 	return settings->priv->height;
300 }
301 
xpad_settings_set_has_decorations(XpadSettings * settings,gboolean decorations)302 void xpad_settings_set_has_decorations (XpadSettings *settings, gboolean decorations)
303 {
304 	if (settings->priv->has_decorations == decorations)
305 		return;
306 
307 	settings->priv->has_decorations = decorations;
308 
309 	save_to_file (settings, DEFAULTS_FILENAME);
310 
311 	g_object_notify (G_OBJECT (settings), "has_decorations");
312 }
313 
xpad_settings_get_has_decorations(XpadSettings * settings)314 gboolean xpad_settings_get_has_decorations (XpadSettings *settings)
315 {
316 	return settings->priv->has_decorations;
317 }
318 
xpad_settings_set_confirm_destroy(XpadSettings * settings,gboolean confirm)319 void xpad_settings_set_confirm_destroy (XpadSettings *settings, gboolean confirm)
320 {
321 	if (settings->priv->confirm_destroy == confirm)
322 		return;
323 
324 	settings->priv->confirm_destroy = confirm;
325 
326 	save_to_file (settings, DEFAULTS_FILENAME);
327 
328 	g_object_notify (G_OBJECT (settings), "confirm_destroy");
329 }
330 
xpad_settings_get_confirm_destroy(XpadSettings * settings)331 gboolean xpad_settings_get_confirm_destroy (XpadSettings *settings)
332 {
333 	return settings->priv->confirm_destroy;
334 }
335 
xpad_settings_set_edit_lock(XpadSettings * settings,gboolean lock)336 void xpad_settings_set_edit_lock (XpadSettings *settings, gboolean lock)
337 {
338 	if (settings->priv->edit_lock == lock)
339 		return;
340 
341 	settings->priv->edit_lock = lock;
342 
343 	save_to_file (settings, DEFAULTS_FILENAME);
344 
345 	g_object_notify (G_OBJECT (settings), "edit_lock");
346 }
347 
xpad_settings_get_edit_lock(XpadSettings * settings)348 gboolean xpad_settings_get_edit_lock (XpadSettings *settings)
349 {
350 	return settings->priv->edit_lock;
351 }
352 
xpad_settings_set_has_toolbar(XpadSettings * settings,gboolean toolbar)353 void xpad_settings_set_has_toolbar (XpadSettings *settings, gboolean toolbar)
354 {
355 	if (settings->priv->has_toolbar == toolbar)
356 		return;
357 
358 	settings->priv->has_toolbar = toolbar;
359 
360 	save_to_file (settings, DEFAULTS_FILENAME);
361 
362 	g_object_notify (G_OBJECT (settings), "has_toolbar");
363 }
364 
xpad_settings_get_has_toolbar(XpadSettings * settings)365 gboolean xpad_settings_get_has_toolbar (XpadSettings *settings)
366 {
367 	return settings->priv->has_toolbar;
368 }
369 
xpad_settings_set_sticky(XpadSettings * settings,gboolean sticky)370 void xpad_settings_set_sticky (XpadSettings *settings, gboolean sticky)
371 {
372 	if (settings->priv->sticky == sticky)
373 		return;
374 
375 	settings->priv->sticky = sticky;
376 
377 	save_to_file (settings, DEFAULTS_FILENAME);
378 
379 	g_object_notify (G_OBJECT (settings), "sticky");
380 }
381 
xpad_settings_get_sticky(XpadSettings * settings)382 gboolean xpad_settings_get_sticky (XpadSettings *settings)
383 {
384 	return settings->priv->sticky;
385 }
386 
xpad_settings_set_autohide_toolbar(XpadSettings * settings,gboolean hide)387 void xpad_settings_set_autohide_toolbar (XpadSettings *settings, gboolean hide)
388 {
389 	if (settings->priv->autohide_toolbar == hide)
390 		return;
391 
392 	settings->priv->autohide_toolbar = hide;
393 
394 	save_to_file (settings, DEFAULTS_FILENAME);
395 
396 	g_object_notify (G_OBJECT (settings), "autohide_toolbar");
397 }
398 
xpad_settings_get_autohide_toolbar(XpadSettings * settings)399 gboolean xpad_settings_get_autohide_toolbar (XpadSettings *settings)
400 {
401 	return settings->priv->autohide_toolbar;
402 }
403 
xpad_settings_set_has_scrollbar(XpadSettings * settings,gboolean scrollbar)404 void xpad_settings_set_has_scrollbar (XpadSettings *settings, gboolean scrollbar)
405 {
406 	if (settings->priv->has_scrollbar == scrollbar)
407 		return;
408 
409 	settings->priv->has_scrollbar = scrollbar;
410 
411 	save_to_file (settings, DEFAULTS_FILENAME);
412 
413 	g_object_notify (G_OBJECT (settings), "has_scrollbar");
414 }
415 
xpad_settings_get_has_scrollbar(XpadSettings * settings)416 gboolean xpad_settings_get_has_scrollbar (XpadSettings *settings)
417 {
418 	return settings->priv->has_scrollbar;
419 }
420 
xpad_settings_add_toolbar_button(XpadSettings * settings,const gchar * button)421 void xpad_settings_add_toolbar_button (XpadSettings *settings, const gchar *button)
422 {
423 	settings->priv->toolbar_buttons = g_slist_append (settings->priv->toolbar_buttons, g_strdup (button));
424 
425 	save_to_file (settings, DEFAULTS_FILENAME);
426 
427 	g_signal_emit (settings, signals[CHANGE_BUTTONS], 0);
428 }
429 
xpad_settings_move_toolbar_button(XpadSettings * settings,gint button,gint new)430 gboolean xpad_settings_move_toolbar_button (XpadSettings *settings, gint button, gint new)
431 {
432 	GSList *element;
433 	gpointer data;
434 
435 	if (button == new)
436 		return FALSE;
437 
438 	if (new >= g_slist_length (settings->priv->toolbar_buttons) || 0 > new )
439 		return FALSE;
440 
441 	element = g_slist_nth (settings->priv->toolbar_buttons, button);
442 	if (!element)
443 		return FALSE;
444 
445 	data = element->data;
446 	settings->priv->toolbar_buttons = g_slist_delete_link (settings->priv->toolbar_buttons, element);
447 	settings->priv->toolbar_buttons = g_slist_insert (settings->priv->toolbar_buttons, data, new);
448 
449 	save_to_file (settings, DEFAULTS_FILENAME);
450 
451 	g_signal_emit (settings, signals[CHANGE_BUTTONS], 0);
452 
453 	return TRUE;
454 }
455 
xpad_settings_remove_toolbar_button(XpadSettings * settings,gint button)456 gboolean xpad_settings_remove_toolbar_button (XpadSettings *settings, gint button)
457 {
458 	GSList *element;
459 
460 	element = g_slist_nth (settings->priv->toolbar_buttons, button);
461 
462 	if (!element)
463 		return FALSE;
464 
465 	g_free (element->data);
466 	settings->priv->toolbar_buttons = g_slist_delete_link (settings->priv->toolbar_buttons, element);
467 
468 	save_to_file (settings, DEFAULTS_FILENAME);
469 
470 	g_signal_emit (settings, signals[CHANGE_BUTTONS], 0);
471 
472 	return TRUE;
473 }
474 
xpad_settings_get_toolbar_buttons(XpadSettings * settings)475 G_CONST_RETURN GSList *xpad_settings_get_toolbar_buttons (XpadSettings *settings)
476 {
477 	return settings->priv->toolbar_buttons;
478 }
479 
xpad_settings_set_back_color(XpadSettings * settings,const GdkColor * back)480 void xpad_settings_set_back_color (XpadSettings *settings, const GdkColor *back)
481 {
482 	if (settings->priv->back)
483 		gdk_color_free (settings->priv->back);
484 
485 	if (back)
486 		settings->priv->back = gdk_color_copy (back);
487 	else
488 		settings->priv->back = NULL;
489 
490 	save_to_file (settings, DEFAULTS_FILENAME);
491 
492 	g_object_notify (G_OBJECT (settings), "back_color");
493 }
494 
xpad_settings_get_back_color(XpadSettings * settings)495 G_CONST_RETURN GdkColor *xpad_settings_get_back_color (XpadSettings *settings)
496 {
497 	return settings->priv->back;
498 }
499 
xpad_settings_set_text_color(XpadSettings * settings,const GdkColor * text)500 void xpad_settings_set_text_color (XpadSettings *settings, const GdkColor *text)
501 {
502 	if (settings->priv->text)
503 		gdk_color_free (settings->priv->text);
504 
505 	if (text)
506 		settings->priv->text = gdk_color_copy (text);
507 	else
508 		settings->priv->text = NULL;
509 
510 	save_to_file (settings, DEFAULTS_FILENAME);
511 
512 	g_object_notify (G_OBJECT (settings), "text_color");
513 }
514 
xpad_settings_get_text_color(XpadSettings * settings)515 G_CONST_RETURN GdkColor *xpad_settings_get_text_color (XpadSettings *settings)
516 {
517 	return settings->priv->text;
518 }
519 
xpad_settings_set_fontname(XpadSettings * settings,const gchar * fontname)520 void xpad_settings_set_fontname (XpadSettings *settings, const gchar *fontname)
521 {
522 	g_free (settings->priv->fontname);
523 	settings->priv->fontname = g_strdup (fontname);
524 
525 	save_to_file (settings, DEFAULTS_FILENAME);
526 
527 	g_object_notify (G_OBJECT (settings), "fontname");
528 }
529 
xpad_settings_get_fontname(XpadSettings * settings)530 G_CONST_RETURN gchar *xpad_settings_get_fontname (XpadSettings *settings)
531 {
532 	return settings->priv->fontname;
533 }
534 
535 static void
xpad_settings_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)536 xpad_settings_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
537 {
538 	XpadSettings *settings;
539 
540 	settings = XPAD_SETTINGS (object);
541 
542 	switch (prop_id)
543 	{
544 	case PROP_HEIGHT:
545 		xpad_settings_set_height (settings, g_value_get_uint (value));
546 		break;
547 
548 	case PROP_WIDTH:
549 		xpad_settings_set_width (settings, g_value_get_uint (value));
550 		break;
551 
552 	case PROP_HAS_DECORATIONS:
553 		xpad_settings_set_has_decorations (settings, g_value_get_boolean (value));
554 		break;
555 
556 	case PROP_CONFIRM_DESTROY:
557 		xpad_settings_set_confirm_destroy (settings, g_value_get_boolean (value));
558 		break;
559 
560 	case PROP_STICKY:
561 		xpad_settings_set_sticky (settings, g_value_get_boolean (value));
562 		break;
563 
564 	case PROP_EDIT_LOCK:
565 		xpad_settings_set_edit_lock (settings, g_value_get_boolean (value));
566 		break;
567 
568 	case PROP_HAS_TOOLBAR:
569 		xpad_settings_set_has_toolbar (settings, g_value_get_boolean (value));
570 		break;
571 
572 	case PROP_AUTOHIDE_TOOLBAR:
573 		xpad_settings_set_autohide_toolbar (settings, g_value_get_boolean (value));
574 		break;
575 
576 	case PROP_HAS_SCROLLBAR:
577 		xpad_settings_set_has_scrollbar (settings, g_value_get_boolean (value));
578 		break;
579 
580 	case PROP_BACK_COLOR:
581 		xpad_settings_set_back_color (settings, g_value_get_boxed (value));
582 		break;
583 
584 	case PROP_TEXT_COLOR:
585 		xpad_settings_set_text_color (settings, g_value_get_boxed (value));
586 		break;
587 
588 	case PROP_FONTNAME:
589 		xpad_settings_set_fontname (settings, g_value_get_string (value));
590 		break;
591 
592 	default:
593 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
594 		break;
595 	}
596 }
597 
598 static void
xpad_settings_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)599 xpad_settings_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
600 {
601 	XpadSettings *settings;
602 
603 	settings = XPAD_SETTINGS (object);
604 
605 	switch (prop_id)
606 	{
607 	case PROP_HEIGHT:
608 		g_value_set_uint (value, xpad_settings_get_height (settings));
609 		break;
610 
611 	case PROP_WIDTH:
612 		g_value_set_uint (value, xpad_settings_get_width (settings));
613 		break;
614 
615 	case PROP_HAS_DECORATIONS:
616 		g_value_set_boolean (value, xpad_settings_get_has_decorations (settings));
617 		break;
618 
619 	case PROP_CONFIRM_DESTROY:
620 		g_value_set_boolean (value, xpad_settings_get_confirm_destroy (settings));
621 		break;
622 
623 	case PROP_STICKY:
624 		g_value_set_boolean (value, xpad_settings_get_sticky (settings));
625 		break;
626 
627 	case PROP_EDIT_LOCK:
628 		g_value_set_boolean (value, xpad_settings_get_edit_lock (settings));
629 		break;
630 
631 	case PROP_HAS_TOOLBAR:
632 		g_value_set_boolean (value, xpad_settings_get_has_toolbar (settings));
633 		break;
634 
635 	case PROP_AUTOHIDE_TOOLBAR:
636 		g_value_set_boolean (value, xpad_settings_get_autohide_toolbar (settings));
637 		break;
638 
639 	case PROP_HAS_SCROLLBAR:
640 		g_value_set_boolean (value, xpad_settings_get_has_scrollbar (settings));
641 		break;
642 
643 	case PROP_BACK_COLOR:
644 		g_value_set_static_boxed (value, xpad_settings_get_back_color (settings));
645 		break;
646 
647 	case PROP_TEXT_COLOR:
648 		g_value_set_static_boxed (value, xpad_settings_get_text_color (settings));
649 		break;
650 
651 	case PROP_FONTNAME:
652 		g_value_set_string (value, xpad_settings_get_fontname (settings));
653 		break;
654 
655 	default:
656 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
657 		break;
658 	}
659 }
660 
661 static void
load_from_file(XpadSettings * settings,const gchar * filename)662 load_from_file (XpadSettings *settings, const gchar *filename)
663 {
664 	/**
665 	 * We need to set up int values for all these to take the value from the file.
666 	 * These will be assigned back to the appropriate values after load.
667 	 */
668 	gchar *buttons = NULL;
669 	GdkColor text = {0}, back = {0};
670 	gboolean use_text, use_back;
671 
672 	use_text = settings->priv->text ? TRUE : FALSE;
673 	if (settings->priv->text)
674 		text = *settings->priv->text;
675 
676 	use_back = settings->priv->back ? TRUE : FALSE;
677 	if (settings->priv->back)
678 		back = *settings->priv->back;
679 
680 	if (fio_get_values_from_file (filename,
681 		"b|decorations", &settings->priv->has_decorations,
682 		"u|height", &settings->priv->height,
683 		"u|width", &settings->priv->width,
684 		"b|confirm_destroy", &settings->priv->confirm_destroy,
685 		"b|edit_lock", &settings->priv->edit_lock,
686 		"b|sticky_on_start", &settings->priv->sticky,
687 		"h|back_red", &back.red,
688 		"h|back_green", &back.green,
689 		"h|back_blue", &back.blue,
690 		"b|use_back", &use_back,
691 		"h|text_red", &text.red,
692 		"h|text_green", &text.green,
693 		"h|text_blue", &text.blue,
694 		"b|use_text", &use_text,
695 		"s|fontname", &settings->priv->fontname,
696 		"b|toolbar", &settings->priv->has_toolbar,
697 		"b|auto_hide_toolbar", &settings->priv->autohide_toolbar,
698 		"b|scrollbar", &settings->priv->has_scrollbar,
699 		"s|buttons", &buttons,
700 		NULL))
701 		return;
702 
703 	if (use_text)
704 	{
705 		gdk_color_free (settings->priv->text);
706 		settings->priv->text = gdk_color_copy (&text);
707 	}
708 
709 	if (use_back)
710 	{
711 		gdk_color_free (settings->priv->back);
712 		settings->priv->back = gdk_color_copy (&back);
713 	}
714 
715 	if (settings->priv->fontname &&
716 	    strcmp (settings->priv->fontname, "NULL") == 0)
717 	{
718 		g_free (settings->priv->fontname);
719 		settings->priv->fontname = NULL;
720 	}
721 
722 	if (buttons)
723 	{
724 		gint i;
725 		gchar **button_names;
726 
727 		button_names = g_strsplit (buttons, ",", 0);
728 
729 		while (settings->priv->toolbar_buttons)
730 		{
731 			g_free (settings->priv->toolbar_buttons->data);
732 			settings->priv->toolbar_buttons =
733 				g_slist_delete_link (settings->priv->toolbar_buttons,
734 				settings->priv->toolbar_buttons);
735 		}
736 
737 		for (i = 0; button_names[i]; ++i)
738 		{
739 			settings->priv->toolbar_buttons =
740 				g_slist_append (settings->priv->toolbar_buttons,
741 				g_strstrip (button_names[i])); /* takes ownership of string */
742 		}
743 
744 		g_free (button_names);
745 		g_free (buttons);
746 	}
747 }
748 
749 
750 static void
save_to_file(XpadSettings * settings,const gchar * filename)751 save_to_file (XpadSettings *settings, const gchar *filename)
752 {
753 	gchar *buttons = g_strdup ("");
754 	GSList *tmp;
755 
756 	tmp = settings->priv->toolbar_buttons;
757 
758 	while (tmp)
759 	{
760 		gchar *tmpstr = buttons;
761 
762 		if (tmp->next)
763 			buttons = g_strconcat (buttons, tmp->data, ", ", NULL);
764 		else
765 			buttons = g_strconcat (buttons, tmp->data, NULL);
766 
767 		g_free (tmpstr);
768 		tmp = tmp->next;
769 	}
770 
771 	fio_set_values_to_file (filename,
772 		"b|decorations", settings->priv->has_decorations,
773 		"u|height", settings->priv->height,
774 		"u|width", settings->priv->width,
775 		"b|confirm_destroy", settings->priv->confirm_destroy,
776 		"b|edit_lock", settings->priv->edit_lock,
777 		"b|sticky_on_start", settings->priv->sticky,
778 		"h|back_red", settings->priv->back ? settings->priv->back->red : 0,
779 		"h|back_green", settings->priv->back ? settings->priv->back->green : 0,
780 		"h|back_blue", settings->priv->back ? settings->priv->back->blue : 0,
781 		"b|use_back", settings->priv->back ? TRUE : FALSE,
782 		"h|text_red", settings->priv->text ? settings->priv->text->red : 0,
783 		"h|text_green", settings->priv->text ? settings->priv->text->green : 0,
784 		"h|text_blue", settings->priv->text ? settings->priv->text->blue : 0,
785 		"b|use_text", settings->priv->text ? TRUE : FALSE,
786 		"s|fontname", settings->priv->fontname ? settings->priv->fontname : "NULL",
787 		"b|toolbar", settings->priv->has_toolbar,
788 		"b|auto_hide_toolbar", settings->priv->autohide_toolbar,
789 		"b|scrollbar", settings->priv->has_scrollbar,
790 		"s|buttons", buttons,
791 		NULL);
792 
793 	g_free (buttons);
794 }
795