1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2000 - 2003 Naba Kumar <naba@gnome.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * SECTION:anjuta-preferences
23 * @short_description: Anjuta Prefereces system.
24 * @see_also: #AnjutaPreferencesDialog
25 * @stability: Unstable
26 * @include: libanjuta/anjuta-preferences.h
28 * #AnjutaPreferences is a way to let plugins register their preferences. There
29 * are mainly two ways a plugin could register its preferences in Anjuta.
31 * First is to not use #AnjutaPreferences at all. Simply register a
32 * preferences page in #AnjutaPreferencesDialog using the function
33 * anjuta_preferences_dialog_add_page(). The plugin should take
34 * care of loading, saving and widgets synchronization of the
35 * preferences values. It is particularly useful if the plugin
36 * uses gconf system for its preferences. Also no "changed"
37 * signal will be emitted from it.
39 * Second is to use anjuta_preferences_add_page(), which will
40 * automatically register the preferences keys and values from
41 * a glade xml file. The glade xml file contains a preferences
42 * page of the plugin. The widget names in the page are
43 * given in a particular way (see anjuta_preferences_add_page()) to
44 * let it know property key details. Loading, saving and
45 * widget synchronization are automatically done. "changed" signal is
46 * emitted when a preference is changed.
48 * anjuta_preferences_register_all_properties_from_glade_xml() only registers
49 * the preferences propery keys for automatic loading, saving and widget
50 * syncrhronization, but does not add the page in preferences dialog. It
51 * is useful if the plugin wants to show the preferences page somewhere else.
53 * anjuta_preferences_register_property_from_string() is similar to
54 * anjuta_preferences_register_all_properties_from_glade_xml(), but it only
55 * registers one property, the detail of which is given in its arguments.
56 * anjuta_preferences_register_property_custom() is used to register a
57 * property that uses a widget which is not supported by #AnjutaPreferences.
68 #include <glade/glade-parser.h>
69 #include <gconf/gconf-client.h>
70 #include <libgnomevfs/gnome-vfs.h>
72 #include <libanjuta/anjuta-preferences.h>
73 #include <libanjuta/anjuta-utils.h>
74 #include <libanjuta/resources.h>
75 #include <libanjuta/anjuta-debug.h>
76 #include <libanjuta/interfaces/ianjuta-preferences.h>
78 struct _AnjutaProperty
87 /* Set true if custom set/get to be used */
90 /* For inbuilt generic objects */
91 AnjutaPropertyObjectType object_type
;
92 AnjutaPropertyDataType data_type
;
94 /* For custom objects */
95 void (*set_property
) (AnjutaProperty
*prop
, const gchar
*value
);
96 gchar
* (*get_property
) (AnjutaProperty
*prop
);
100 struct _AnjutaPreferencesPriv
102 GConfClient
*gclient
;
103 GHashTable
*properties
;
104 GtkWidget
*prefs_dialog
;
105 AnjutaPluginManager
*plugin_manager
;
109 /* Internal structure for anjuta_preferences_foreach */
110 struct _AnjutaPreferencesForeachData
112 AnjutaPreferences
*pr
;
113 AnjutaPreferencesFilterType filter
;
114 AnjutaPreferencesCallback callback
;
115 gpointer callback_data
;
118 #define PREFERENCE_PROPERTY_PREFIX "preferences_"
119 #define GCONF_KEY_PREFIX "/apps/anjuta/preferences"
122 build_key (const gchar
*key
)
124 static gchar buffer
[1024];
125 snprintf (buffer
, 1024, "%s/%s", GCONF_KEY_PREFIX
, key
);
130 * anjuta_preferences_get:
131 * @pr: A #AnjutaPreferences object
134 * Gets the value of @key as string. Returned string should be g_freed() when not
137 * Return value: Key value as string or NULL if the key is not defined.
143 anjuta_preferences_get (AnjutaPreferences
*pr
, const gchar
*key
)
145 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), NULL
);
146 g_return_val_if_fail (key
!= NULL
, NULL
);
148 return gconf_client_get_string (pr
->priv
->gclient
, build_key (key
), NULL
);
152 * anjuta_preferences_get_list:
153 * @pr: A #AnjutaPreferences object
155 * @list_type: Type of each list element
157 * Gets the list of @key.
159 * Return value: Key list or NULL if the key is not defined.
165 anjuta_preferences_get_list (AnjutaPreferences
*pr
, const gchar
*key
,
166 GConfValueType list_type
)
168 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), NULL
);
169 g_return_val_if_fail (key
!= NULL
, NULL
);
171 return gconf_client_get_list(pr
->priv
->gclient
, build_key (key
), list_type
, NULL
);
175 * anjuta_preferences_get_pair:
176 * @pr: A #AnjutaPreferences object
178 * @car_type: Desired type of the pair's first field (car).
179 * @cdr_type: Desired type of the pair's second field (cdr).
180 * @car_retloc: Address of a return location for the car.
181 * @cdr_retloc: Address of a return location for the cdr.
183 * Gets the pair of @key.
185 * Return value: TRUE or FALSE.
191 anjuta_preferences_get_pair (AnjutaPreferences
*pr
, const gchar
*key
,
192 GConfValueType car_type
, GConfValueType cdr_type
,
193 gpointer car_retloc
, gpointer cdr_retloc
)
195 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
196 g_return_val_if_fail (key
!= NULL
, FALSE
);
198 return gconf_client_get_pair(pr
->priv
->gclient
, build_key (key
),
200 car_retloc
, cdr_retloc
, NULL
);
204 * anjuta_preferences_get_int:
205 * @pr: A #AnjutaPreferences object
208 * Gets the value of @key as integer.
210 * Return value: Key value as integer or 0 if the key is not defined.
216 anjuta_preferences_get_int (AnjutaPreferences
*pr
, const gchar
*key
)
221 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), 0);
222 g_return_val_if_fail (key
!= NULL
, 0);
225 value
= gconf_client_get (pr
->priv
->gclient
, build_key (key
), NULL
);
230 case GCONF_VALUE_INT
:
231 ret_val
= gconf_value_get_int (value
);
233 case GCONF_VALUE_BOOL
:
234 ret_val
= gconf_value_get_bool (value
);
237 g_warning ("Invalid gconf type for key: %s", key
);
239 gconf_value_free (value
);
242 g_warning ("The preference key %s is not defined", key); */
247 * anjuta_preferences_get_int_with_default:
248 * @pr: A #AnjutaPreferences object
250 * @default_value: Default value to return if the key is not defined.
252 * Gets the value of @key as integer.
254 * Return value: Key value as integer or @default_value if the
255 * key is not defined.
261 anjuta_preferences_get_int_with_default (AnjutaPreferences
*pr
,
262 const gchar
*key
, gint default_value
)
267 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), 0);
268 g_return_val_if_fail (key
!= NULL
, 0);
270 ret_val
= default_value
;
271 value
= gconf_client_get (pr
->priv
->gclient
, build_key (key
), NULL
);
276 case GCONF_VALUE_INT
:
277 ret_val
= gconf_value_get_int (value
);
279 case GCONF_VALUE_BOOL
:
280 ret_val
= gconf_value_get_bool (value
);
283 g_warning ("Invalid gconf type for key: %s", key
);
285 gconf_value_free (value
);
291 * anjuta_preferences_default_get:
292 * @pr: A #AnjutaPreferences object
295 * Gets the default value of @key as string. The default value of the key
296 * is the value defined in System defaults (generally installed during
297 * program installation). Returned value must be g_freed() when not required.
299 * Return value: Default key value as string or NULL if not defined.
305 anjuta_preferences_default_get (AnjutaPreferences
* pr
, const gchar
* key
)
311 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), NULL
);
312 g_return_val_if_fail (key
!= NULL
, NULL
);
314 val
= gconf_client_get_default_from_schema (pr
->priv
->gclient
, build_key (key
), &err
);
319 str
= g_strdup (gconf_value_get_string (val
));
320 gconf_value_free (val
);
325 * anjuta_preferences_default_get_int:
326 * @pr: A #AnjutaPreferences object
329 * Gets the default value of @key as integer. The default value of the key
330 * is the value defined in System defaults (generally installed during
331 * program installation).
333 * Return value: Default key value as integer or 0 if the key is not defined.
339 anjuta_preferences_default_get_int (AnjutaPreferences
*pr
, const gchar
*key
)
345 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), 0);
346 g_return_val_if_fail (key
!= NULL
, 0);
347 val
= gconf_client_get_default_from_schema (pr
->priv
->gclient
, build_key (key
), &err
);
352 ret
= gconf_value_get_int (val
);
353 gconf_value_free (val
);
358 * anjuta_preferences_set:
359 * @pr: A #AnjutaPreferences object.
360 * @key: Property key.
361 * @value: Value of the key.
363 * Sets the value of @key in current session.
369 anjuta_preferences_set (AnjutaPreferences
*pr
, const gchar
*key
,
372 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
373 g_return_if_fail (key
!= NULL
);
375 if (value
&& (strlen (value
) > 0))
377 gconf_client_set_string (pr
->priv
->gclient
, build_key (key
), value
, NULL
);
381 gconf_client_set_string (pr
->priv
->gclient
, build_key (key
), "", NULL
);
386 * anjuta_preferences_set_list:
387 * @pr: A #AnjutaPreferences object.
388 * @key: Property key.
389 * @list_type: Type of each element.
390 * @list: New value of the key.
392 * Sets a list in current session.
398 anjuta_preferences_set_list (AnjutaPreferences
*pr
, const gchar
*key
,
399 GConfValueType list_type
, GSList
*list
)
401 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
402 g_return_if_fail (key
!= NULL
);
404 gconf_client_set_list(pr
->priv
->gclient
, build_key (key
),
405 list_type
, list
, NULL
);
409 * anjuta_preferences_set_pair:
410 * @pr: A #AnjutaPreferences object.
411 * @key: Property key.
412 * @car_type: Type of the pair's first field (car).
413 * @cdr_type: Type of the pair's second field (cdr).
414 * @address_of_car: Address of the car.
415 * @address_of_cdr: Address of the cdr.
422 anjuta_preferences_set_pair (AnjutaPreferences
*pr
, const gchar
*key
,
423 GConfValueType car_type
, GConfValueType cdr_type
,
424 gconstpointer address_of_car
,
425 gconstpointer address_of_cdr
)
427 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
428 g_return_val_if_fail (key
!= NULL
, FALSE
);
430 return gconf_client_set_pair (pr
->priv
->gclient
, build_key (key
),
432 address_of_car
, address_of_cdr
,
437 * anjuta_preferences_set_int:
438 * @pr: A #AnjutaPreferences object.
439 * @key: Property key.
440 * @value: Integer value of the key.
442 * Sets the value of @key in current session.
448 anjuta_preferences_set_int (AnjutaPreferences
*pr
, const gchar
*key
,
453 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
454 g_return_if_fail (key
!= NULL
);
456 gvalue
= gconf_client_get (pr
->priv
->gclient
, build_key (key
), NULL
);
459 switch (gvalue
->type
)
461 case GCONF_VALUE_BOOL
:
462 gconf_client_set_bool (pr
->priv
->gclient
, build_key (key
),
465 case GCONF_VALUE_INT
:
466 gconf_client_set_int (pr
->priv
->gclient
, build_key (key
),
470 g_warning ("Invalid gconf type for key: %s", key
);
472 gconf_value_free (gvalue
);
476 /* g_warning ("The preference key %s is not defined", key); */
477 gconf_client_set_int (pr
->priv
->gclient
, build_key (key
),
483 property_destroy (AnjutaProperty
*property
)
485 g_return_if_fail (property
);
486 if (property
->key
) g_free (property
->key
);
487 if (property
->default_value
) g_free (property
->default_value
);
488 g_object_unref (property
->object
);
489 gconf_client_notify_remove (property
->gclient
, property
->notify_id
);
494 * anjuta_property_get_widget:
495 * @prop: an #AnjutaProperty reference
497 * Gets the widget associated with the property.
499 * Returns: a #GtkWidget object associated with the property.
502 anjuta_property_get_widget (AnjutaProperty
*prop
)
507 static AnjutaPropertyObjectType
508 get_object_type_from_string (const gchar
* object_type
)
510 if (strcmp (object_type
, "entry") == 0)
511 return ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY
;
512 else if (strcmp (object_type
, "combo") == 0)
513 return ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
;
514 else if (strcmp (object_type
, "spin") == 0)
515 return ANJUTA_PROPERTY_OBJECT_TYPE_SPIN
;
516 else if (strcmp (object_type
, "toggle") == 0)
517 return ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE
;
518 else if (strcmp (object_type
, "text") == 0)
519 return ANJUTA_PROPERTY_OBJECT_TYPE_TEXT
;
520 else if (strcmp (object_type
, "color") == 0)
521 return ANJUTA_PROPERTY_OBJECT_TYPE_COLOR
;
522 else if (strcmp (object_type
, "font") == 0)
523 return ANJUTA_PROPERTY_OBJECT_TYPE_FONT
;
524 else if (strcmp (object_type
, "file") == 0)
525 return ANJUTA_PROPERTY_OBJECT_TYPE_FILE
;
526 else if (strcmp (object_type
, "folder") == 0)
527 return ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER
;
529 return (AnjutaPropertyObjectType
)(-1);
532 static AnjutaPropertyDataType
533 get_data_type_from_string (const gchar
* data_type
)
535 if (strcmp (data_type
, "bool") == 0)
536 return ANJUTA_PROPERTY_DATA_TYPE_BOOL
;
537 else if (strcmp (data_type
, "int") == 0)
538 return ANJUTA_PROPERTY_DATA_TYPE_INT
;
539 else if (strcmp (data_type
, "text") == 0)
540 return ANJUTA_PROPERTY_DATA_TYPE_TEXT
;
541 else if (strcmp (data_type
, "color") == 0)
542 return ANJUTA_PROPERTY_DATA_TYPE_COLOR
;
543 else if (strcmp (data_type
, "font") == 0)
544 return ANJUTA_PROPERTY_DATA_TYPE_FONT
;
546 return (AnjutaPropertyDataType
)(-1);
550 get_property_value_as_string (AnjutaProperty
*prop
)
554 gchar
*text_value
= NULL
;
558 if (prop
->get_property
!= NULL
)
559 return prop
->get_property (prop
);
562 g_warning ("%s: Undefined get_property() for custom object",
567 switch (prop
->object_type
)
569 case ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE
:
571 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prop
->object
));
572 text_value
= g_strdup_printf ("%d", int_value
);
575 case ANJUTA_PROPERTY_OBJECT_TYPE_SPIN
:
577 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (prop
->object
));
578 text_value
= g_strdup_printf ("%d", int_value
);
581 case ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY
:
583 gtk_editable_get_chars (GTK_EDITABLE (prop
->object
), 0, -1);
585 case ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
:
588 values
= g_object_get_data(G_OBJECT(prop
->object
), "untranslated");
589 idx
= gtk_combo_box_get_active(GTK_COMBO_BOX(prop
->object
));
590 if (values
[idx
] != NULL
)
591 text_value
= g_strdup(values
[idx
]);
594 case ANJUTA_PROPERTY_OBJECT_TYPE_TEXT
:
596 GtkTextBuffer
*buffer
;
597 GtkTextIter start_iter
;
598 GtkTextIter end_iter
;
599 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (prop
->object
));
600 gtk_text_buffer_get_start_iter (buffer
, &start_iter
);
601 gtk_text_buffer_get_end_iter (buffer
, &end_iter
);
603 gtk_text_buffer_get_text (buffer
, &start_iter
, &end_iter
, TRUE
);
606 case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR
:
609 gtk_color_button_get_color(GTK_COLOR_BUTTON (prop
->object
),
611 text_value
= anjuta_util_string_from_color (color
.red
, color
.green
, color
.blue
);
614 case ANJUTA_PROPERTY_OBJECT_TYPE_FONT
:
617 font
= gtk_font_button_get_font_name (GTK_FONT_BUTTON
619 text_value
= g_strdup (font
);
622 case ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER
:
623 case ANJUTA_PROPERTY_OBJECT_TYPE_FILE
:
624 text_value
= gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (prop
->object
));
627 if (text_value
&& (strlen (text_value
) == 0))
636 get_property_value_as_int (AnjutaProperty
*prop
)
640 text_value
= get_property_value_as_string (prop
);
641 int_value
= atoi (text_value
);
647 set_property_value_as_string (AnjutaProperty
*prop
, const gchar
*value
)
655 if (prop
->set_property
!= NULL
)
657 prop
->set_property (prop
, value
);
662 g_warning ("%s: Undefined set_property() for custom object",
667 switch (prop
->object_type
)
669 case ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE
:
671 int_value
= atoi (value
);
675 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prop
->object
),
679 case ANJUTA_PROPERTY_OBJECT_TYPE_SPIN
:
681 int_value
= atoi (value
);
685 gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop
->object
), int_value
);
688 case ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY
:
690 gtk_entry_set_text (GTK_ENTRY (prop
->object
), value
);
692 gtk_entry_set_text (GTK_ENTRY (prop
->object
), "");
694 case ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
:
695 values
= g_object_get_data(G_OBJECT(prop
->object
), "untranslated");
698 for (i
=0; values
[i
] != NULL
; i
++)
700 if (strcmp(value
, values
[i
]) == 0)
702 gtk_combo_box_set_active(GTK_COMBO_BOX(prop
->object
), i
);
708 case ANJUTA_PROPERTY_OBJECT_TYPE_TEXT
:
710 GtkTextBuffer
*buffer
;
711 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (prop
->object
));
713 gtk_text_buffer_set_text (buffer
, value
, -1);
715 gtk_text_buffer_set_text (buffer
, "", -1);
719 case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR
:
724 anjuta_util_color_from_string (value
, &color
.red
, &color
.green
, &color
.blue
);
726 gtk_color_button_set_color(GTK_COLOR_BUTTON(prop
->object
), &color
);
730 case ANJUTA_PROPERTY_OBJECT_TYPE_FONT
:
733 /* If the font name is Xfont name, convert it into
734 Pango font description text -- Just take the family name :) */
737 /* Font is xfont name */
738 gchar
*font_name
, *tmp
;
739 const gchar
*end
, *start
;
741 start
= g_strstr_len (&start
[1], strlen (&start
[1]), "-");
742 end
= g_strstr_len (&start
[1], strlen (&start
[1]), "-");
743 font_name
= g_strndup (&start
[1], end
-start
-1);
746 /* Set font size to (arbitrary) 12 points */
747 font_name
= g_strconcat (tmp
, " 12", NULL
);
750 /* DEBUG_PRINT ("Font set as: %s", font_name); */
752 gtk_font_button_set_font_name (GTK_FONT_BUTTON
753 (prop
->object
), font_name
);
758 gtk_font_button_set_font_name (GTK_FONT_BUTTON
759 (prop
->object
), value
);
762 /* FIXME: Set a standard font as default.
765 gnome_font_picker_set_font_name (GNOME_FONT_PICKER (prop->object),
770 case ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER
:
775 /* When the user change the folder, the
776 * current-folder-changed signal is emitted the
777 * gconf key is updated and this function is called.
778 * But setting the current folder here emits
779 * the current-folder-changed signal too.
780 * Moreover this signal is emitted asynchronously so
781 * it is not possible to block it here.
783 * The solution here is to update the widget only
784 * if it is really needed.
786 old_folder
= gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (prop
->object
));
787 if ((old_folder
== NULL
) || strcmp (old_folder
, value
))
789 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (prop
->object
), value
);
794 case ANJUTA_PROPERTY_OBJECT_TYPE_FILE
:
797 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (prop
->object
),
805 set_property_value_as_int (AnjutaProperty
*prop
, gint value
)
808 text_value
= g_strdup_printf ("%d", value
);
809 set_property_value_as_string (prop
, text_value
);
814 update_property_on_event_str (GtkWidget
*widget
, GdkEvent
*event
,
817 AnjutaPreferences
*pr
;
821 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
822 "AnjutaPreferences"));
823 p
= (AnjutaProperty
*) user_data
;
824 val
= get_property_value_as_string (p
);
825 anjuta_preferences_set (pr
, p
->key
, val
);
831 update_property_on_change_str (GtkWidget
*widget
, gpointer user_data
)
833 AnjutaPreferences
*pr
;
837 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
838 "AnjutaPreferences"));
839 p
= (AnjutaProperty
*) user_data
;
840 val
= get_property_value_as_string (p
);
841 anjuta_preferences_set (pr
, p
->key
, val
);
846 block_update_property_on_change_str (GtkWidget
*widget
, GdkEvent
*event
,
849 AnjutaProperty
*p
= (AnjutaProperty
*) user_data
;
851 gtk_signal_handler_block_by_func (GTK_OBJECT(p
->object
), G_CALLBACK (update_property_on_change_str
), p
);
856 unblock_update_property_on_change_str (GtkWidget
*widget
, GdkEvent
*event
,
859 AnjutaProperty
*p
= (AnjutaProperty
*) user_data
;
861 gtk_signal_handler_unblock_by_func (GTK_OBJECT(p
->object
), G_CALLBACK (update_property_on_change_str
), p
);
866 update_property_on_change_int (GtkWidget
*widget
, gpointer user_data
)
868 AnjutaPreferences
*pr
;
872 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
873 "AnjutaPreferences"));
874 p
= (AnjutaProperty
*) user_data
;
875 val
= get_property_value_as_int (p
);
876 anjuta_preferences_set_int (pr
, p
->key
, val
);
880 update_property_on_change_color (GtkWidget
*widget
, gpointer user_data
)
882 AnjutaPreferences
*pr
;
886 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
887 "AnjutaPreferences"));
888 p
= (AnjutaProperty
*) user_data
;
889 val
= get_property_value_as_string (p
);
890 anjuta_preferences_set (pr
, p
->key
, val
);
895 update_property_on_change_font (GtkWidget
*widget
,
898 AnjutaPreferences
*pr
;
902 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
903 "AnjutaPreferences"));
904 p
= (AnjutaProperty
*) user_data
;
905 val
= get_property_value_as_string (p
);
906 anjuta_preferences_set (pr
, p
->key
, val
);
911 unregister_preferences_key (GtkWidget
*widget
,
915 AnjutaPreferences
*pr
;
918 p
= (AnjutaProperty
*) user_data
;
919 pr
= g_object_get_data (G_OBJECT (widget
),
920 "AnjutaPreferences");
921 key
= g_strdup (p
->key
);
923 g_hash_table_remove (pr
->priv
->properties
, key
);
928 get_property (GConfClient
*gclient
, guint cnxt_id
,
929 GConfEntry
*entry
, gpointer user_data
)
934 AnjutaProperty
*p
= (AnjutaProperty
*) user_data
;
935 key
= gconf_entry_get_key (entry
);
936 value
= gconf_entry_get_value (entry
);
937 /* DEBUG_PRINT ("Preference changed %s", key); */
939 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
)
941 gboolean gconf_value
;
943 gconf_value
= gconf_value_get_bool (value
);
944 set_property_value_as_int (p
, gconf_value
);
946 else if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
950 gconf_value
= gconf_value_get_int (value
);
951 set_property_value_as_int (p
, gconf_value
);
955 const gchar
*gconf_value
;
956 gconf_value
= gconf_value_get_string (value
);
957 set_property_value_as_string (p
, gconf_value
);
962 register_callbacks (AnjutaPreferences
*pr
, AnjutaProperty
*p
)
964 GConfClient
*gclient
;
965 gchar
*key_error_msg
;
967 gclient
= pr
->priv
->gclient
;
968 g_object_set_data (G_OBJECT (p
->object
), "AnjutaPreferences", pr
);
969 switch (p
->object_type
) {
970 case ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY
:
971 g_signal_connect (G_OBJECT(p
->object
), "changed",
972 G_CALLBACK (update_property_on_change_str
), p
);
973 g_signal_connect (G_OBJECT(p
->object
), "focus_out_event",
974 G_CALLBACK (update_property_on_event_str
), p
);
975 g_signal_connect (G_OBJECT(p
->object
), "focus_out_event",
976 G_CALLBACK (unblock_update_property_on_change_str
), p
);
977 g_signal_connect (G_OBJECT(p
->object
), "focus_in_event",
978 G_CALLBACK (block_update_property_on_change_str
), p
);
980 case ANJUTA_PROPERTY_OBJECT_TYPE_SPIN
:
981 g_signal_connect (G_OBJECT(p
->object
), "value-changed",
982 G_CALLBACK (update_property_on_change_int
), p
);
984 case ANJUTA_PROPERTY_OBJECT_TYPE_FONT
:
985 g_signal_connect (G_OBJECT(p
->object
), "font-set",
986 G_CALLBACK (update_property_on_change_font
), p
);
988 case ANJUTA_PROPERTY_OBJECT_TYPE_TEXT
:
989 g_signal_connect (G_OBJECT(p
->object
), "focus_out_event",
990 G_CALLBACK (update_property_on_event_str
), p
);
992 case ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
:
993 g_signal_connect (G_OBJECT(p
->object
), "changed",
994 G_CALLBACK (update_property_on_change_str
), p
);
996 case ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE
:
997 g_signal_connect (G_OBJECT(p
->object
), "toggled",
998 G_CALLBACK (update_property_on_change_int
), p
);
1000 case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR
:
1001 g_signal_connect (G_OBJECT(p
->object
), "color-set",
1002 G_CALLBACK (update_property_on_change_color
), p
);
1004 case ANJUTA_PROPERTY_OBJECT_TYPE_FILE
:
1005 g_signal_connect (G_OBJECT(p
->object
), "file-set",
1006 G_CALLBACK (update_property_on_change_str
), p
);
1008 case ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER
:
1009 g_signal_connect (G_OBJECT(p
->object
), "current-folder-changed",
1010 G_CALLBACK (update_property_on_change_str
), p
);
1015 if (!gconf_valid_key (build_key (p
->key
), &key_error_msg
))
1017 g_warning ("Invalid key \"%s\": Error: \"%s\"", build_key (p
->key
),
1019 g_free (key_error_msg
);
1021 p
->notify_id
= gconf_client_notify_add (gclient
, build_key (p
->key
),
1022 get_property
, p
, NULL
, NULL
);
1024 /* Connect to widget destroy signal so we can automatically unregister
1025 * keys so there aren't any potential conflicts or references to
1026 * nonexistent widgets on subsequent uses of the prefs dialog. */
1027 g_signal_connect (G_OBJECT (p
->object
), "destroy",
1028 G_CALLBACK (unregister_preferences_key
),
1033 preferences_foreach_callback (gchar
*key
, struct _AnjutaProperty
*p
,
1034 struct _AnjutaPreferencesForeachData
*data
)
1036 if (p
->object_type
!= ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
)
1038 if (data
->filter
== ANJUTA_PREFERENCES_FILTER_NONE
)
1039 return data
->callback (data
->pr
, key
, data
->callback_data
);
1040 else if (p
->flags
& data
->filter
)
1041 return data
->callback (data
->pr
, key
, data
->callback_data
);
1048 connect_prop_to_object (AnjutaPreferences
*pr
, AnjutaProperty
*p
)
1053 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
||
1054 p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
1056 gconf_value
= anjuta_preferences_get_int (pr
, p
->key
);
1057 value
= g_strdup_printf ("%d", gconf_value
);
1058 set_property_value_as_string (p
, value
);
1062 value
= anjuta_preferences_get (pr
, p
->key
);
1063 set_property_value_as_string (p
, value
);
1070 * anjuta_preferences_register_property_raw:
1071 * @pr: a #AnjutaPreferences object
1072 * @object: Widget to register
1073 * @key: Property key
1074 * @default_value: Default value of the key
1076 * @object_type: Object type of widget
1077 * @data_type: Data type of the property
1079 * This also registers only one widget, but instead of supplying the property
1080 * parameters as a single parsable string (as done in previous method), it
1081 * takes them separately.
1083 * Return value: TRUE if sucessful.
1086 anjuta_preferences_register_property_raw (AnjutaPreferences
*pr
,
1089 const gchar
*default_value
,
1091 AnjutaPropertyObjectType object_type
,
1092 AnjutaPropertyDataType data_type
)
1097 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
1098 g_return_val_if_fail (GTK_IS_WIDGET (object
), FALSE
);
1099 g_return_val_if_fail (key
!= NULL
, FALSE
);
1100 g_return_val_if_fail (strlen(key
) > 0, FALSE
);
1101 g_return_val_if_fail ((object_type
!= ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
) ||
1102 ((default_value
!= NULL
) &&
1103 (*default_value
!= '\0')), FALSE
);
1105 p
= g_new0 (AnjutaProperty
, 1);
1106 g_object_ref (object
);
1108 p
->object_type
= object_type
;
1109 p
->data_type
= data_type
;
1110 p
->key
= g_strdup (key
);
1111 p
->gclient
= pr
->priv
->gclient
;
1113 value
= gconf_client_get (pr
->priv
->gclient
,
1114 build_key (p
->key
), NULL
);
1117 /* Verify key type. Unset key if type mismatch. */
1118 if (!((value
->type
== GCONF_VALUE_BOOL
&&
1119 data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
) ||
1120 (value
->type
== GCONF_VALUE_INT
&&
1121 data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
) ||
1122 (value
->type
== GCONF_VALUE_STRING
&&
1123 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1124 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)))
1126 gconf_client_unset (pr
->priv
->gclient
, build_key (key
), NULL
);
1128 gconf_value_free (value
);
1132 p
->default_value
= g_strdup (default_value
);
1133 if (strlen (default_value
) > 0)
1135 /* For combo, initialize the untranslated strings */
1136 if (object_type
== ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
)
1141 vstr
= g_strsplit (default_value
, ",", 100);
1142 g_object_set_data(G_OBJECT(p
->object
), "untranslated",
1144 old_value
= anjuta_preferences_get (pr
, p
->key
);
1145 if (old_value
== NULL
&& vstr
[0])
1147 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1148 p->key, default_value); */
1149 anjuta_preferences_set (pr
, p
->key
, vstr
[0]);
1154 else if (p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1155 p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)
1158 old_value
= anjuta_preferences_get (pr
, p
->key
);
1159 if (old_value
== NULL
)
1161 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1162 p->key, default_value);*/
1163 anjuta_preferences_set (pr
, p
->key
, default_value
);
1170 value
= gconf_client_get (pr
->priv
->gclient
,
1171 build_key (p
->key
), NULL
);
1174 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1175 p->key, default_value);*/
1176 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
1177 gconf_client_set_int (pr
->priv
->gclient
,
1179 atoi (default_value
), NULL
);
1181 gconf_client_set_bool (pr
->priv
->gclient
,
1183 atoi (default_value
), NULL
);
1186 gconf_value_free (value
);
1192 p
->set_property
= NULL
;
1193 p
->get_property
= NULL
;
1195 g_hash_table_insert (pr
->priv
->properties
, g_strdup (key
), p
);
1196 connect_prop_to_object (pr
, p
);
1197 register_callbacks (pr
, p
);
1202 * anjuta_preferences_register_property_custom:
1203 * @pr: a #AnjutaPreferences object.
1204 * @object: Object to register.
1205 * @key: Property key.
1206 * @default_value: Default value of the key.
1207 * @data_type: property data type.
1209 * @set_property: Set property to widget callback.
1210 * @get_property: Get property from widget callback.
1212 * This is meant for complex widgets which can not be set/get with the
1213 * standard object set/get methods. Custom set/get methods are passed for
1214 * the property to set/get the value to/from the widget.
1216 * Return value: TRUE if sucessful.
1219 anjuta_preferences_register_property_custom (AnjutaPreferences
*pr
,
1222 const gchar
*default_value
,
1223 AnjutaPropertyDataType data_type
,
1225 void (*set_property
) (AnjutaProperty
*prop
, const gchar
*value
),
1226 gchar
* (*get_property
) (AnjutaProperty
*))
1231 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
1232 g_return_val_if_fail (GTK_IS_WIDGET (object
), FALSE
);
1233 g_return_val_if_fail (key
!= NULL
, FALSE
);
1234 g_return_val_if_fail (strlen(key
) > 0, FALSE
);
1236 p
= g_new0 (AnjutaProperty
, 1);
1237 g_object_ref (object
);
1239 p
->object_type
= (AnjutaPropertyObjectType
) 0;
1240 p
->data_type
= data_type
;
1241 p
->key
= g_strdup (key
);
1242 p
->gclient
= pr
->priv
->gclient
;
1244 value
= gconf_client_get (pr
->priv
->gclient
,
1245 build_key (p
->key
), NULL
);
1248 /* Verify key type. Unset key if type mismatch. */
1249 if (!((value
->type
== GCONF_VALUE_BOOL
&&
1250 data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
) ||
1251 (value
->type
== GCONF_VALUE_INT
&&
1252 data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
) ||
1253 (value
->type
== GCONF_VALUE_STRING
&&
1254 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1255 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)))
1257 gconf_client_unset (pr
->priv
->gclient
, build_key (key
), NULL
);
1259 gconf_value_free (value
);
1263 p
->default_value
= g_strdup (default_value
);
1264 if (p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1265 p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)
1268 old_value
= anjuta_preferences_get (pr
, p
->key
);
1269 if (old_value
== NULL
)
1271 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1272 p->key, default_value); */
1273 anjuta_preferences_set (pr
, p
->key
, default_value
);
1280 value
= gconf_client_get (pr
->priv
->gclient
,
1281 build_key (p
->key
), NULL
);
1284 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1285 p->key, default_value);*/
1286 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
1287 gconf_client_set_int (pr
->priv
->gclient
,
1289 atoi (default_value
), NULL
);
1291 gconf_client_set_bool (pr
->priv
->gclient
,
1293 atoi (default_value
), NULL
);
1296 gconf_value_free (value
);
1301 p
->set_property
= set_property
;
1302 p
->get_property
= get_property
;
1304 g_hash_table_insert (pr
->priv
->properties
, g_strdup (key
), p
);
1306 /* Connect to widget destroy signal so we can automatically unregister
1307 * keys so there aren't any potential conflicts or references to
1308 * nonexistent widgets on subsequent uses of the prefs dialog. */
1309 g_object_set_data (G_OBJECT (p
->object
), "AnjutaPreferences", pr
);
1310 g_signal_connect (G_OBJECT (p
->object
), "destroy",
1311 G_CALLBACK (unregister_preferences_key
),
1317 * anjuta_preferences_register_property_from_string:
1318 * @pr: a #AnjutaPreferences object
1319 * @object: Widget to register
1320 * @property_desc: Property description (see anjuta_preferences_add_page())
1322 * This registers only one widget. The widget could be shown elsewhere.
1323 * the property_description should be of the form described before.
1325 * Return value: TRUE if sucessful.
1328 anjuta_preferences_register_property_from_string (AnjutaPreferences
*pr
,
1330 const gchar
*property_desc
)
1335 AnjutaPropertyObjectType object_type
;
1336 AnjutaPropertyDataType data_type
;
1338 gchar
*default_value
;
1341 g_return_val_if_fail (ANJUTA_IS_PREFERENCES(pr
), FALSE
);
1342 g_return_val_if_fail ((GTK_IS_WIDGET (object
)), FALSE
);
1343 g_return_val_if_fail (property_desc
!= NULL
, FALSE
);
1345 fields
= g_strsplit (property_desc
, ":", 5);
1346 g_return_val_if_fail (fields
, FALSE
);
1347 for (n_fields
= 0; fields
[n_fields
]; n_fields
++);
1350 g_strfreev (fields
);
1353 object_type
= get_object_type_from_string (fields
[0]);
1354 data_type
= get_data_type_from_string (fields
[1]);
1355 default_value
= fields
[2];
1356 flags
= atoi (fields
[3]);
1358 if (object_type
< 0)
1360 g_warning ("Invalid property object type in property description");
1361 g_strfreev (fields
);
1366 g_warning ("Invalid property data type in property description");
1367 g_strfreev (fields
);
1370 anjuta_preferences_register_property_raw (pr
, object
, key
, default_value
,
1373 g_strfreev (fields
);
1378 * anjuta_preferences_register_all_properties_from_glade_xml:
1379 * @pr: a #AnjutaPreferences Object
1380 * @gxml: GladeXML object containing the properties widgets.
1381 * @parent: Parent widget in the gxml object
1383 * This will register all the properties names of the format described above
1384 * without considering the UI. Useful if you have the widgets shown elsewhere
1385 * but you want them to be part of preferences system.
1388 anjuta_preferences_register_all_properties_from_glade_xml (AnjutaPreferences
*pr
,
1395 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1396 g_return_if_fail (gxml
!= NULL
);
1398 widgets
= glade_xml_get_widget_prefix (gxml
, "preferences_");
1403 GtkWidget
*widget
, *p
;
1404 gboolean cont_flag
= FALSE
;
1406 widget
= node
->data
;
1408 p
= gtk_widget_get_parent (widget
);
1409 /* Added only if it's a desendend child of the parent */
1417 p
= gtk_widget_get_parent (p
);
1419 if (cont_flag
== TRUE
)
1421 node
= g_list_next (node
);
1425 name
= glade_get_widget_name (widget
);
1426 if (strncmp (name
, PREFERENCE_PROPERTY_PREFIX
,
1427 strlen (PREFERENCE_PROPERTY_PREFIX
)) == 0)
1429 const gchar
*property
= &name
[strlen (PREFERENCE_PROPERTY_PREFIX
)];
1430 anjuta_preferences_register_property_from_string (pr
, widget
,
1433 node
= g_list_next (node
);
1438 * anjuta_preferences_reset_defaults:
1439 * @pr: a #AnjutaPreferences object.
1441 * Resets the default values into the keys
1444 anjuta_preferences_reset_defaults (AnjutaPreferences
* pr
)
1448 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1450 dlg
= gtk_message_dialog_new (GTK_WINDOW (pr
),
1451 GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_QUESTION
,
1453 _("Are you sure you want to reset the preferences to\n"
1454 "their default settings?"));
1455 gtk_dialog_add_button (GTK_DIALOG (dlg
), GTK_STOCK_CANCEL
,
1456 GTK_RESPONSE_CANCEL
);
1457 anjuta_util_dialog_add_button (GTK_DIALOG (dlg
), _("_Reset"),
1458 GTK_STOCK_REVERT_TO_SAVED
,
1460 if (gtk_dialog_run (GTK_DIALOG (dlg
)) == GTK_RESPONSE_YES
)
1462 /* FIXME: Reset preferences to built-in default values. */
1464 gtk_widget_destroy (dlg
);
1468 * anjuta_preferences_foreach:
1469 * @pr: A #AnjutaPreferences object.
1470 * @filter: Keys to filter out from the loop.
1471 * @callback: User callback function.
1472 * @data: User data passed to @callback
1474 * Calls @callback function for each of the registered property keys. Keys
1475 * with matching @filter flags are left out of the loop. If @filter is
1476 * ANJUTA_PREFERENCES_FILTER_NONE, all properties are selected for the loop.
1479 anjuta_preferences_foreach (AnjutaPreferences
*pr
,
1480 AnjutaPreferencesFilterType filter
,
1481 AnjutaPreferencesCallback callback
,
1484 struct _AnjutaPreferencesForeachData foreach_data
;
1486 foreach_data
.pr
= pr
;
1487 foreach_data
.filter
= filter
;
1488 foreach_data
.callback
= callback
;
1489 foreach_data
.callback_data
= data
;
1491 g_hash_table_find (pr
->priv
->properties
,
1492 (GHRFunc
) preferences_foreach_callback
,
1498 * anjuta_preferences_add_page:
1499 * @pr: a #AnjutaPreferences object
1500 * @gxml: #GladeXML object containing the preferences page
1501 * @glade_widget_name: Page widget name (as give with glade interface editor).
1502 * The widget will be searched with the given name and detached
1503 * (that is, removed from the container, if present) from it's parent.
1504 * @icon_filename: File name (of the form filename.png) of the icon representing
1505 * the preference page.
1507 * Add a page to the preferences sytem.
1508 * gxml is the GladeXML object of the glade dialog containing the page widget.
1509 * The glade dialog will contain the layout of the preferences widgets.
1510 * The widgets which are preference widgets (e.g. toggle button) should have
1511 * widget names of the form:
1514 * preferences_OBJECTTYPE:DATATYPE:DEFAULT:FLAGS:PROPERTYKEY
1516 * OBJECTTYPE is 'toggle', 'spin', 'entry', 'text', 'color', 'font' or 'file' .
1517 * DATATYPE is 'bool', 'int', 'float', 'text', 'color' or 'font'.
1518 * DEFAULT is the default value (in the appropriate format). The format
1519 * for color is '#XXXXXX' representing RGB value and for
1520 * font, it is the pango font description.
1521 * FLAGS is any flag associated with the property. Currently it
1522 * has only two values -- 0 and 1. For normal preference
1523 * property which is saved/retrieved globally, the flag = 0.
1524 * For preference property which is also saved/retrieved
1525 * along with the project, the flag = 1.
1526 * PROPERTYKEY is the property key. e.g - 'tab.size'.
1529 * All widgets having the above names in the gxml tree will be registered
1530 * and will become part of auto saving/loading. For example, refer to
1531 * anjuta preferences dialogs and study the widget names.
1534 anjuta_preferences_add_page (AnjutaPreferences
* pr
, GladeXML
*gxml
,
1535 const gchar
* glade_widget_name
,
1537 const gchar
*icon_filename
)
1544 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1545 g_return_if_fail (glade_widget_name
!= NULL
);
1546 g_return_if_fail (icon_filename
!= NULL
);
1548 page
= glade_xml_get_widget (gxml
, glade_widget_name
);
1549 g_object_ref (page
);
1550 g_return_if_fail (GTK_IS_WIDGET (page
));
1551 parent
= gtk_widget_get_parent (page
);
1552 if (parent
&& GTK_IS_CONTAINER (parent
))
1554 if (GTK_IS_NOTEBOOK (parent
))
1558 page_num
= gtk_notebook_page_num (GTK_NOTEBOOK (parent
), page
);
1559 gtk_notebook_remove_page (GTK_NOTEBOOK (parent
), page_num
);
1563 gtk_container_remove (GTK_CONTAINER (parent
), page
);
1566 image_path
= anjuta_res_get_pixmap_file (icon_filename
);
1567 pixbuf
= gdk_pixbuf_new_from_file (image_path
, NULL
);
1568 anjuta_preferences_dialog_add_page (ANJUTA_PREFERENCES_DIALOG (pr
->priv
->prefs_dialog
),
1569 glade_widget_name
, title
, pixbuf
, page
);
1570 anjuta_preferences_register_all_properties_from_glade_xml (pr
, gxml
, page
);
1571 g_object_unref (page
);
1572 g_free (image_path
);
1573 g_object_unref (pixbuf
);
1577 anjuta_preferences_remove_page (AnjutaPreferences
*pr
,
1578 const gchar
*page_name
)
1580 if (pr
->priv
->prefs_dialog
)
1582 anjuta_preferences_dialog_remove_page (ANJUTA_PREFERENCES_DIALOG (pr
->priv
->prefs_dialog
),
1588 on_preferences_dialog_destroyed (GtkWidget
*preferencess_dialog
,
1589 AnjutaPreferences
*pr
)
1592 GList
*current_plugin
;
1594 plugins
= anjuta_plugin_manager_get_active_plugin_objects (pr
->priv
->plugin_manager
);
1595 current_plugin
= plugins
;
1597 while (current_plugin
)
1599 if (IANJUTA_IS_PREFERENCES (current_plugin
->data
))
1601 ianjuta_preferences_unmerge (IANJUTA_PREFERENCES (current_plugin
->data
),
1605 current_plugin
= g_list_next (current_plugin
);
1609 g_object_unref (pr
->priv
->prefs_dialog
);
1611 g_list_free (plugins
);
1612 pr
->priv
->prefs_dialog
= NULL
;
1616 anjuta_preferences_get_dialog (AnjutaPreferences
*pr
)
1619 GList
*current_plugin
;
1621 if (pr
->priv
->prefs_dialog
)
1622 return pr
->priv
->prefs_dialog
;
1625 pr
->priv
->prefs_dialog
= anjuta_preferences_dialog_new ();
1627 g_signal_connect (G_OBJECT (pr
->priv
->prefs_dialog
), "destroy",
1628 G_CALLBACK (on_preferences_dialog_destroyed
),
1631 plugins
= anjuta_plugin_manager_get_active_plugin_objects (pr
->priv
->plugin_manager
);
1632 current_plugin
= plugins
;
1634 while (current_plugin
)
1636 if (IANJUTA_IS_PREFERENCES (current_plugin
->data
))
1638 ianjuta_preferences_merge (IANJUTA_PREFERENCES (current_plugin
->data
),
1642 current_plugin
= g_list_next (current_plugin
);
1645 g_list_free (plugins
);
1647 return g_object_ref_sink (pr
->priv
->prefs_dialog
);
1652 anjuta_preferences_is_dialog_created (AnjutaPreferences
*pr
)
1654 return (pr
->priv
->prefs_dialog
!= NULL
);
1657 static void anjuta_preferences_class_init (AnjutaPreferencesClass
*class);
1658 static void anjuta_preferences_instance_init (AnjutaPreferences
*pr
);
1661 anjuta_preferences_get_type ()
1663 static GType obj_type
= 0;
1667 static const GTypeInfo obj_info
=
1669 sizeof (AnjutaPreferencesClass
),
1670 (GBaseInitFunc
) NULL
,
1671 (GBaseFinalizeFunc
) NULL
,
1672 (GClassInitFunc
) anjuta_preferences_class_init
,
1673 (GClassFinalizeFunc
) NULL
,
1674 NULL
, /* class_data */
1675 sizeof (AnjutaPreferencesClass
),
1676 0, /* n_preallocs */
1677 (GInstanceInitFunc
) anjuta_preferences_instance_init
,
1678 NULL
/* value_table */
1680 obj_type
= g_type_register_static (G_TYPE_OBJECT
,
1681 "AnjutaPreferences", &obj_info
, 0);
1687 anjuta_preferences_dispose (GObject
*obj
)
1689 AnjutaPreferences
*pr
= ANJUTA_PREFERENCES (obj
);
1691 if (pr
->priv
->properties
)
1693 /* This will release the refs on property objects */
1694 g_hash_table_destroy (pr
->priv
->properties
);
1695 pr
->priv
->properties
= NULL
;
1700 anjuta_preferences_instance_init (AnjutaPreferences
*pr
)
1702 pr
->priv
= g_new0 (AnjutaPreferencesPriv
, 1);
1704 pr
->priv
->properties
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
1706 (GDestroyNotify
) property_destroy
);
1708 pr
->priv
->gclient
= gconf_client_get_default();
1709 gconf_client_add_dir (pr
->priv
->gclient
, GCONF_KEY_PREFIX
,
1710 GCONF_CLIENT_PRELOAD_ONELEVEL
, NULL
);
1715 anjuta_preferences_finalize (GObject
*obj
)
1717 AnjutaPreferences
*pr
= ANJUTA_PREFERENCES (obj
);
1719 if (pr
->priv
->prefs_dialog
)
1720 gtk_widget_destroy (pr
->priv
->prefs_dialog
);
1722 g_object_unref (pr
->priv
->plugin_manager
);
1727 anjuta_preferences_class_init (AnjutaPreferencesClass
*class)
1729 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
1731 object_class
->dispose
= anjuta_preferences_dispose
;
1732 object_class
->finalize
= anjuta_preferences_finalize
;
1736 * anjuta_preferences_new:
1738 * Creates a new #AnjutaPreferences object
1740 * Return value: A #AnjutaPreferences object.
1743 anjuta_preferences_new (AnjutaPluginManager
*plugin_manager
)
1745 AnjutaPreferences
*pr
;
1747 pr
= g_object_new (ANJUTA_TYPE_PREFERENCES
, NULL
);
1748 pr
->priv
->plugin_manager
= g_object_ref (plugin_manager
);
1755 * anjuta_preferences_notify_add:
1756 * @pr: A #AnjutaPreferences object.
1757 * @key: Key to monitor.
1758 * @func: User callback function.
1759 * @data: User data passed to @func
1760 * @destroy_notify: Destroy notify function - called when notify is removed.
1762 * This is similar to gconf_client_notify_add(), except that the key is not
1763 * given as full path. Only anjuta preference key is given. The key prefix
1764 * is added internally.
1766 * Return value: Notify ID.
1769 anjuta_preferences_notify_add (AnjutaPreferences
*pr
,
1771 GConfClientNotifyFunc func
,
1773 GFreeFunc destroy_notify
)
1775 return gconf_client_notify_add (pr
->priv
->gclient
,
1777 func
, data
, destroy_notify
, NULL
);
1781 * anjuta_preferences_notify_remove:
1782 * @pr: A #AnjutaPreferences object.
1783 * @notify_id: Notify ID returned by anjuta_preferences_notify_add().
1785 * Removes the notify callback added with anjuta_preferences_notify_add().
1788 anjuta_preferences_notify_remove (AnjutaPreferences
*pr
, guint notify_id
)
1790 gconf_client_notify_remove (pr
->priv
->gclient
, notify_id
);
1794 * anjuta_preferences_get_prefix:
1795 * @pr: A #AnjutaPreferences object.
1797 * Returns the gconf key prefix used by anjuta to store its preferences.
1799 * Return value: preferences keys prefix.
1802 anjuta_preferences_get_prefix (AnjutaPreferences
*pr
)
1804 return PREFERENCE_PROPERTY_PREFIX
;
1808 * anjuta_preferences_dir_exists:
1809 * @pr: A #AnjutaPreferences object.
1810 * @dir: Directory to checkfor.
1812 * Returns TRUE if dir exists.
1818 anjuta_preferences_dir_exists (AnjutaPreferences
*pr
, const gchar
*dir
)
1820 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
1821 g_return_val_if_fail (dir
!= NULL
, FALSE
);
1823 return gconf_client_dir_exists(pr
->priv
->gclient
, build_key (dir
), NULL
);
1827 * anjuta_preferences_add_dir:
1828 * @pr: A #AnjutaPreferences object.
1829 * @dir: Directory to add to the list.
1830 * @preload: Degree of preload.
1832 * Add a directory to the list of directories the GConfClient.
1838 anjuta_preferences_add_dir (AnjutaPreferences
*pr
, const gchar
*dir
,
1839 GConfClientPreloadType preload
)
1841 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1842 g_return_if_fail (dir
!= NULL
);
1844 gconf_client_add_dir(pr
->priv
->gclient
, build_key (dir
),
1849 * anjuta_preferences_remove_dir:
1850 * @pr: A #AnjutaPreferences object.
1851 * @dir: Directory to remove from the list.
1853 * Remove a directory from the list of directories.
1859 anjuta_preferences_remove_dir (AnjutaPreferences
*pr
, const gchar
*dir
)
1861 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1862 g_return_if_fail (dir
!= NULL
);
1864 gconf_client_remove_dir(pr
->priv
->gclient
, build_key (dir
), NULL
);