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
;
559 if (prop
->get_property
!= NULL
)
560 return prop
->get_property (prop
);
563 g_warning ("%s: Undefined get_property() for custom object",
568 switch (prop
->object_type
)
570 case ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE
:
572 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prop
->object
));
573 text_value
= g_strdup_printf ("%d", int_value
);
576 case ANJUTA_PROPERTY_OBJECT_TYPE_SPIN
:
578 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (prop
->object
));
579 text_value
= g_strdup_printf ("%d", int_value
);
582 case ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY
:
584 gtk_editable_get_chars (GTK_EDITABLE (prop
->object
), 0, -1);
586 case ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
:
589 values
= g_object_get_data(G_OBJECT(prop
->object
), "untranslated");
590 idx
= gtk_combo_box_get_active(GTK_COMBO_BOX(prop
->object
));
591 if (values
[idx
] != NULL
)
592 text_value
= g_strdup(values
[idx
]);
595 case ANJUTA_PROPERTY_OBJECT_TYPE_TEXT
:
597 GtkTextBuffer
*buffer
;
598 GtkTextIter start_iter
;
599 GtkTextIter end_iter
;
600 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (prop
->object
));
601 gtk_text_buffer_get_start_iter (buffer
, &start_iter
);
602 gtk_text_buffer_get_end_iter (buffer
, &end_iter
);
604 gtk_text_buffer_get_text (buffer
, &start_iter
, &end_iter
, TRUE
);
607 case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR
:
610 gtk_color_button_get_color(GTK_COLOR_BUTTON (prop
->object
),
612 text_value
= anjuta_util_string_from_color (color
.red
, color
.green
, color
.blue
);
615 case ANJUTA_PROPERTY_OBJECT_TYPE_FONT
:
618 font
= gtk_font_button_get_font_name (GTK_FONT_BUTTON
620 text_value
= g_strdup (font
);
623 case ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER
:
624 uri
= gtk_file_chooser_get_uri (
625 GTK_FILE_CHOOSER (prop
->object
));
626 text_value
= gnome_vfs_get_local_path_from_uri (uri
);
629 case ANJUTA_PROPERTY_OBJECT_TYPE_FILE
:
630 text_value
= gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (prop
->object
));
633 if (text_value
&& (strlen (text_value
) == 0))
642 get_property_value_as_int (AnjutaProperty
*prop
)
646 text_value
= get_property_value_as_string (prop
);
647 int_value
= atoi (text_value
);
653 set_property_value_as_string (AnjutaProperty
*prop
, const gchar
*value
)
661 if (prop
->set_property
!= NULL
)
663 prop
->set_property (prop
, value
);
668 g_warning ("%s: Undefined set_property() for custom object",
673 switch (prop
->object_type
)
675 case ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE
:
677 int_value
= atoi (value
);
681 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prop
->object
),
685 case ANJUTA_PROPERTY_OBJECT_TYPE_SPIN
:
687 int_value
= atoi (value
);
691 gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop
->object
), int_value
);
694 case ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY
:
696 gtk_entry_set_text (GTK_ENTRY (prop
->object
), value
);
698 gtk_entry_set_text (GTK_ENTRY (prop
->object
), "");
700 case ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
:
701 values
= g_object_get_data(G_OBJECT(prop
->object
), "untranslated");
704 for (i
=0; values
[i
] != NULL
; i
++)
706 if (strcmp(value
, values
[i
]) == 0)
708 gtk_combo_box_set_active(GTK_COMBO_BOX(prop
->object
), i
);
714 case ANJUTA_PROPERTY_OBJECT_TYPE_TEXT
:
716 GtkTextBuffer
*buffer
;
717 buffer
= gtk_text_view_get_buffer (GTK_TEXT_VIEW (prop
->object
));
719 gtk_text_buffer_set_text (buffer
, value
, -1);
721 gtk_text_buffer_set_text (buffer
, "", -1);
725 case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR
:
730 anjuta_util_color_from_string (value
, &color
.red
, &color
.green
, &color
.blue
);
732 gtk_color_button_set_color(GTK_COLOR_BUTTON(prop
->object
), &color
);
736 case ANJUTA_PROPERTY_OBJECT_TYPE_FONT
:
739 /* If the font name is Xfont name, convert it into
740 Pango font description text -- Just take the family name :) */
743 /* Font is xfont name */
744 gchar
*font_name
, *tmp
;
745 const gchar
*end
, *start
;
747 start
= g_strstr_len (&start
[1], strlen (&start
[1]), "-");
748 end
= g_strstr_len (&start
[1], strlen (&start
[1]), "-");
749 font_name
= g_strndup (&start
[1], end
-start
-1);
752 /* Set font size to (arbitrary) 12 points */
753 font_name
= g_strconcat (tmp
, " 12", NULL
);
756 /* DEBUG_PRINT ("Font set as: %s", font_name); */
758 gtk_font_button_set_font_name (GTK_FONT_BUTTON
759 (prop
->object
), font_name
);
764 gtk_font_button_set_font_name (GTK_FONT_BUTTON
765 (prop
->object
), value
);
768 /* FIXME: Set a standard font as default.
771 gnome_font_picker_set_font_name (GNOME_FONT_PICKER (prop->object),
776 case ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER
:
781 /* When the user change the folder, the
782 * current-folder-changed signal is emitted the
783 * gconf key is updated and this function is called.
784 * But setting the current folder here emits
785 * the current-folder-changed signal too.
786 * Moreover this signal is emitted asynchronously so
787 * it is not possible to block it here.
789 * The solution here is to update the widget only
790 * if it is really needed.
792 old_folder
= gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (prop
->object
));
793 if ((old_folder
== NULL
) || strcmp (old_folder
, value
))
795 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (prop
->object
), value
);
800 case ANJUTA_PROPERTY_OBJECT_TYPE_FILE
:
803 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (prop
->object
),
811 set_property_value_as_int (AnjutaProperty
*prop
, gint value
)
814 text_value
= g_strdup_printf ("%d", value
);
815 set_property_value_as_string (prop
, text_value
);
820 update_property_on_event_str (GtkWidget
*widget
, GdkEvent
*event
,
823 AnjutaPreferences
*pr
;
827 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
828 "AnjutaPreferences"));
829 p
= (AnjutaProperty
*) user_data
;
830 val
= get_property_value_as_string (p
);
831 anjuta_preferences_set (pr
, p
->key
, val
);
837 update_property_on_change_str (GtkWidget
*widget
, gpointer user_data
)
839 AnjutaPreferences
*pr
;
843 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
844 "AnjutaPreferences"));
845 p
= (AnjutaProperty
*) user_data
;
846 val
= get_property_value_as_string (p
);
847 anjuta_preferences_set (pr
, p
->key
, val
);
852 block_update_property_on_change_str (GtkWidget
*widget
, GdkEvent
*event
,
855 AnjutaProperty
*p
= (AnjutaProperty
*) user_data
;
857 gtk_signal_handler_block_by_func (GTK_OBJECT(p
->object
), G_CALLBACK (update_property_on_change_str
), p
);
862 unblock_update_property_on_change_str (GtkWidget
*widget
, GdkEvent
*event
,
865 AnjutaProperty
*p
= (AnjutaProperty
*) user_data
;
867 gtk_signal_handler_unblock_by_func (GTK_OBJECT(p
->object
), G_CALLBACK (update_property_on_change_str
), p
);
872 update_property_on_change_int (GtkWidget
*widget
, gpointer user_data
)
874 AnjutaPreferences
*pr
;
878 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
879 "AnjutaPreferences"));
880 p
= (AnjutaProperty
*) user_data
;
881 val
= get_property_value_as_int (p
);
882 anjuta_preferences_set_int (pr
, p
->key
, val
);
886 update_property_on_change_color (GtkWidget
*widget
, gpointer user_data
)
888 AnjutaPreferences
*pr
;
892 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
893 "AnjutaPreferences"));
894 p
= (AnjutaProperty
*) user_data
;
895 val
= get_property_value_as_string (p
);
896 anjuta_preferences_set (pr
, p
->key
, val
);
901 update_property_on_change_font (GtkWidget
*widget
,
904 AnjutaPreferences
*pr
;
908 pr
= ANJUTA_PREFERENCES (g_object_get_data (G_OBJECT (widget
),
909 "AnjutaPreferences"));
910 p
= (AnjutaProperty
*) user_data
;
911 val
= get_property_value_as_string (p
);
912 anjuta_preferences_set (pr
, p
->key
, val
);
917 unregister_preferences_key (GtkWidget
*widget
,
921 AnjutaPreferences
*pr
;
924 p
= (AnjutaProperty
*) user_data
;
925 pr
= g_object_get_data (G_OBJECT (widget
),
926 "AnjutaPreferences");
927 key
= g_strdup (p
->key
);
929 g_hash_table_remove (pr
->priv
->properties
, key
);
934 get_property (GConfClient
*gclient
, guint cnxt_id
,
935 GConfEntry
*entry
, gpointer user_data
)
940 AnjutaProperty
*p
= (AnjutaProperty
*) user_data
;
941 key
= gconf_entry_get_key (entry
);
942 value
= gconf_entry_get_value (entry
);
943 /* DEBUG_PRINT ("Preference changed %s", key); */
945 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
)
947 gboolean gconf_value
;
949 gconf_value
= gconf_value_get_bool (value
);
950 set_property_value_as_int (p
, gconf_value
);
952 else if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
956 gconf_value
= gconf_value_get_int (value
);
957 set_property_value_as_int (p
, gconf_value
);
961 const gchar
*gconf_value
;
962 gconf_value
= gconf_value_get_string (value
);
963 set_property_value_as_string (p
, gconf_value
);
968 register_callbacks (AnjutaPreferences
*pr
, AnjutaProperty
*p
)
970 GConfClient
*gclient
;
971 gchar
*key_error_msg
;
973 gclient
= pr
->priv
->gclient
;
974 g_object_set_data (G_OBJECT (p
->object
), "AnjutaPreferences", pr
);
975 switch (p
->object_type
) {
976 case ANJUTA_PROPERTY_OBJECT_TYPE_ENTRY
:
977 g_signal_connect (G_OBJECT(p
->object
), "changed",
978 G_CALLBACK (update_property_on_change_str
), p
);
979 g_signal_connect (G_OBJECT(p
->object
), "focus_out_event",
980 G_CALLBACK (update_property_on_event_str
), p
);
981 g_signal_connect (G_OBJECT(p
->object
), "focus_out_event",
982 G_CALLBACK (unblock_update_property_on_change_str
), p
);
983 g_signal_connect (G_OBJECT(p
->object
), "focus_in_event",
984 G_CALLBACK (block_update_property_on_change_str
), p
);
986 case ANJUTA_PROPERTY_OBJECT_TYPE_SPIN
:
987 g_signal_connect (G_OBJECT(p
->object
), "value-changed",
988 G_CALLBACK (update_property_on_change_int
), p
);
990 case ANJUTA_PROPERTY_OBJECT_TYPE_FONT
:
991 g_signal_connect (G_OBJECT(p
->object
), "font-set",
992 G_CALLBACK (update_property_on_change_font
), p
);
994 case ANJUTA_PROPERTY_OBJECT_TYPE_TEXT
:
995 g_signal_connect (G_OBJECT(p
->object
), "focus_out_event",
996 G_CALLBACK (update_property_on_event_str
), p
);
998 case ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
:
999 g_signal_connect (G_OBJECT(p
->object
), "changed",
1000 G_CALLBACK (update_property_on_change_str
), p
);
1002 case ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE
:
1003 g_signal_connect (G_OBJECT(p
->object
), "toggled",
1004 G_CALLBACK (update_property_on_change_int
), p
);
1006 case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR
:
1007 g_signal_connect (G_OBJECT(p
->object
), "color-set",
1008 G_CALLBACK (update_property_on_change_color
), p
);
1010 case ANJUTA_PROPERTY_OBJECT_TYPE_FILE
:
1011 g_signal_connect (G_OBJECT(p
->object
), "file-set",
1012 G_CALLBACK (update_property_on_change_str
), p
);
1014 case ANJUTA_PROPERTY_OBJECT_TYPE_FOLDER
:
1015 g_signal_connect (G_OBJECT(p
->object
), "current-folder-changed",
1016 G_CALLBACK (update_property_on_change_str
), p
);
1021 if (!gconf_valid_key (build_key (p
->key
), &key_error_msg
))
1023 g_warning ("Invalid key \"%s\": Error: \"%s\"", build_key (p
->key
),
1025 g_free (key_error_msg
);
1027 p
->notify_id
= gconf_client_notify_add (gclient
, build_key (p
->key
),
1028 get_property
, p
, NULL
, NULL
);
1030 /* Connect to widget destroy signal so we can automatically unregister
1031 * keys so there aren't any potential conflicts or references to
1032 * nonexistent widgets on subsequent uses of the prefs dialog. */
1033 g_signal_connect (G_OBJECT (p
->object
), "destroy",
1034 G_CALLBACK (unregister_preferences_key
),
1039 preferences_foreach_callback (gchar
*key
, struct _AnjutaProperty
*p
,
1040 struct _AnjutaPreferencesForeachData
*data
)
1042 if (p
->object_type
!= ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
)
1044 if (data
->filter
== ANJUTA_PREFERENCES_FILTER_NONE
)
1045 return data
->callback (data
->pr
, key
, data
->callback_data
);
1046 else if (p
->flags
& data
->filter
)
1047 return data
->callback (data
->pr
, key
, data
->callback_data
);
1054 connect_prop_to_object (AnjutaPreferences
*pr
, AnjutaProperty
*p
)
1059 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
||
1060 p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
1062 gconf_value
= anjuta_preferences_get_int (pr
, p
->key
);
1063 value
= g_strdup_printf ("%d", gconf_value
);
1064 set_property_value_as_string (p
, value
);
1068 value
= anjuta_preferences_get (pr
, p
->key
);
1069 set_property_value_as_string (p
, value
);
1076 * anjuta_preferences_register_property_raw:
1077 * @pr: a #AnjutaPreferences object
1078 * @object: Widget to register
1079 * @key: Property key
1080 * @default_value: Default value of the key
1082 * @object_type: Object type of widget
1083 * @data_type: Data type of the property
1085 * This also registers only one widget, but instead of supplying the property
1086 * parameters as a single parsable string (as done in previous method), it
1087 * takes them separately.
1089 * Return value: TRUE if sucessful.
1092 anjuta_preferences_register_property_raw (AnjutaPreferences
*pr
,
1095 const gchar
*default_value
,
1097 AnjutaPropertyObjectType object_type
,
1098 AnjutaPropertyDataType data_type
)
1103 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
1104 g_return_val_if_fail (GTK_IS_WIDGET (object
), FALSE
);
1105 g_return_val_if_fail (key
!= NULL
, FALSE
);
1106 g_return_val_if_fail (strlen(key
) > 0, FALSE
);
1108 p
= g_new0 (AnjutaProperty
, 1);
1109 g_object_ref (object
);
1111 p
->object_type
= object_type
;
1112 p
->data_type
= data_type
;
1113 p
->key
= g_strdup (key
);
1114 p
->gclient
= pr
->priv
->gclient
;
1116 value
= gconf_client_get (pr
->priv
->gclient
,
1117 build_key (p
->key
), NULL
);
1120 /* Verify key type. Unset key if type mismatch. */
1121 if (!((value
->type
== GCONF_VALUE_BOOL
&&
1122 data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
) ||
1123 (value
->type
== GCONF_VALUE_INT
&&
1124 data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
) ||
1125 (value
->type
== GCONF_VALUE_STRING
&&
1126 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1127 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)))
1129 gconf_client_unset (pr
->priv
->gclient
, build_key (key
), NULL
);
1131 gconf_value_free (value
);
1135 p
->default_value
= g_strdup (default_value
);
1136 if (strlen (default_value
) > 0)
1138 /* For combo, initialize the untranslated strings */
1139 if (object_type
== ANJUTA_PROPERTY_OBJECT_TYPE_COMBO
)
1144 vstr
= g_strsplit (default_value
, ",", 100);
1145 g_object_set_data(G_OBJECT(p
->object
), "untranslated",
1147 old_value
= anjuta_preferences_get (pr
, p
->key
);
1148 if (old_value
== NULL
&& vstr
[0])
1150 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1151 p->key, default_value); */
1152 anjuta_preferences_set (pr
, p
->key
, vstr
[0]);
1157 else if (p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1158 p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)
1161 old_value
= anjuta_preferences_get (pr
, p
->key
);
1162 if (old_value
== NULL
)
1164 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1165 p->key, default_value);*/
1166 anjuta_preferences_set (pr
, p
->key
, default_value
);
1173 value
= gconf_client_get (pr
->priv
->gclient
,
1174 build_key (p
->key
), NULL
);
1177 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1178 p->key, default_value);*/
1179 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
1180 gconf_client_set_int (pr
->priv
->gclient
,
1182 atoi (default_value
), NULL
);
1184 gconf_client_set_bool (pr
->priv
->gclient
,
1186 atoi (default_value
), NULL
);
1189 gconf_value_free (value
);
1195 p
->set_property
= NULL
;
1196 p
->get_property
= NULL
;
1198 g_hash_table_insert (pr
->priv
->properties
, g_strdup (key
), p
);
1199 connect_prop_to_object (pr
, p
);
1200 register_callbacks (pr
, p
);
1205 * anjuta_preferences_register_property_custom:
1206 * @pr: a #AnjutaPreferences object.
1207 * @object: Object to register.
1208 * @key: Property key.
1209 * @default_value: Default value of the key.
1210 * @data_type: property data type.
1212 * @set_property: Set property to widget callback.
1213 * @get_property: Get property from widget callback.
1215 * This is meant for complex widgets which can not be set/get with the
1216 * standard object set/get methods. Custom set/get methods are passed for
1217 * the property to set/get the value to/from the widget.
1219 * Return value: TRUE if sucessful.
1222 anjuta_preferences_register_property_custom (AnjutaPreferences
*pr
,
1225 const gchar
*default_value
,
1226 AnjutaPropertyDataType data_type
,
1228 void (*set_property
) (AnjutaProperty
*prop
, const gchar
*value
),
1229 gchar
* (*get_property
) (AnjutaProperty
*))
1234 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
1235 g_return_val_if_fail (GTK_IS_WIDGET (object
), FALSE
);
1236 g_return_val_if_fail (key
!= NULL
, FALSE
);
1237 g_return_val_if_fail (strlen(key
) > 0, FALSE
);
1239 p
= g_new0 (AnjutaProperty
, 1);
1240 g_object_ref (object
);
1242 p
->object_type
= (AnjutaPropertyObjectType
) 0;
1243 p
->data_type
= data_type
;
1244 p
->key
= g_strdup (key
);
1245 p
->gclient
= pr
->priv
->gclient
;
1247 value
= gconf_client_get (pr
->priv
->gclient
,
1248 build_key (p
->key
), NULL
);
1251 /* Verify key type. Unset key if type mismatch. */
1252 if (!((value
->type
== GCONF_VALUE_BOOL
&&
1253 data_type
== ANJUTA_PROPERTY_DATA_TYPE_BOOL
) ||
1254 (value
->type
== GCONF_VALUE_INT
&&
1255 data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
) ||
1256 (value
->type
== GCONF_VALUE_STRING
&&
1257 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1258 data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)))
1260 gconf_client_unset (pr
->priv
->gclient
, build_key (key
), NULL
);
1262 gconf_value_free (value
);
1266 p
->default_value
= g_strdup (default_value
);
1267 if (p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_BOOL
&&
1268 p
->data_type
!= ANJUTA_PROPERTY_DATA_TYPE_INT
)
1271 old_value
= anjuta_preferences_get (pr
, p
->key
);
1272 if (old_value
== NULL
)
1274 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1275 p->key, default_value); */
1276 anjuta_preferences_set (pr
, p
->key
, default_value
);
1283 value
= gconf_client_get (pr
->priv
->gclient
,
1284 build_key (p
->key
), NULL
);
1287 /* DEBUG_PRINT ("Setting default pref value: %s = %s",
1288 p->key, default_value);*/
1289 if (p
->data_type
== ANJUTA_PROPERTY_DATA_TYPE_INT
)
1290 gconf_client_set_int (pr
->priv
->gclient
,
1292 atoi (default_value
), NULL
);
1294 gconf_client_set_bool (pr
->priv
->gclient
,
1296 atoi (default_value
), NULL
);
1299 gconf_value_free (value
);
1304 p
->set_property
= set_property
;
1305 p
->get_property
= get_property
;
1307 g_hash_table_insert (pr
->priv
->properties
, g_strdup (key
), p
);
1309 /* Connect to widget destroy signal so we can automatically unregister
1310 * keys so there aren't any potential conflicts or references to
1311 * nonexistent widgets on subsequent uses of the prefs dialog. */
1312 g_object_set_data (G_OBJECT (p
->object
), "AnjutaPreferences", pr
);
1313 g_signal_connect (G_OBJECT (p
->object
), "destroy",
1314 G_CALLBACK (unregister_preferences_key
),
1320 * anjuta_preferences_register_property_from_string:
1321 * @pr: a #AnjutaPreferences object
1322 * @object: Widget to register
1323 * @property_desc: Property description (see anjuta_preferences_add_page())
1325 * This registers only one widget. The widget could be shown elsewhere.
1326 * the property_description should be of the form described before.
1328 * Return value: TRUE if sucessful.
1331 anjuta_preferences_register_property_from_string (AnjutaPreferences
*pr
,
1333 const gchar
*property_desc
)
1338 AnjutaPropertyObjectType object_type
;
1339 AnjutaPropertyDataType data_type
;
1341 gchar
*default_value
;
1344 g_return_val_if_fail (ANJUTA_IS_PREFERENCES(pr
), FALSE
);
1345 g_return_val_if_fail ((GTK_IS_WIDGET (object
)), FALSE
);
1346 g_return_val_if_fail (property_desc
!= NULL
, FALSE
);
1348 fields
= g_strsplit (property_desc
, ":", 5);
1349 g_return_val_if_fail (fields
, FALSE
);
1350 for (n_fields
= 0; fields
[n_fields
]; n_fields
++);
1353 g_strfreev (fields
);
1356 object_type
= get_object_type_from_string (fields
[0]);
1357 data_type
= get_data_type_from_string (fields
[1]);
1358 default_value
= fields
[2];
1359 flags
= atoi (fields
[3]);
1361 if (object_type
< 0)
1363 g_warning ("Invalid property object type in property description");
1364 g_strfreev (fields
);
1369 g_warning ("Invalid property data type in property description");
1370 g_strfreev (fields
);
1373 anjuta_preferences_register_property_raw (pr
, object
, key
, default_value
,
1376 g_strfreev (fields
);
1381 * anjuta_preferences_register_all_properties_from_glade_xml:
1382 * @pr: a #AnjutaPreferences Object
1383 * @gxml: GladeXML object containing the properties widgets.
1384 * @parent: Parent widget in the gxml object
1386 * This will register all the properties names of the format described above
1387 * without considering the UI. Useful if you have the widgets shown elsewhere
1388 * but you want them to be part of preferences system.
1391 anjuta_preferences_register_all_properties_from_glade_xml (AnjutaPreferences
*pr
,
1398 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1399 g_return_if_fail (gxml
!= NULL
);
1401 widgets
= glade_xml_get_widget_prefix (gxml
, "preferences_");
1406 GtkWidget
*widget
, *p
;
1407 gboolean cont_flag
= FALSE
;
1409 widget
= node
->data
;
1411 p
= gtk_widget_get_parent (widget
);
1412 /* Added only if it's a desendend child of the parent */
1420 p
= gtk_widget_get_parent (p
);
1422 if (cont_flag
== TRUE
)
1424 node
= g_list_next (node
);
1428 name
= glade_get_widget_name (widget
);
1429 if (strncmp (name
, PREFERENCE_PROPERTY_PREFIX
,
1430 strlen (PREFERENCE_PROPERTY_PREFIX
)) == 0)
1432 const gchar
*property
= &name
[strlen (PREFERENCE_PROPERTY_PREFIX
)];
1433 anjuta_preferences_register_property_from_string (pr
, widget
,
1436 node
= g_list_next (node
);
1441 * anjuta_preferences_reset_defaults:
1442 * @pr: a #AnjutaPreferences object.
1444 * Resets the default values into the keys
1447 anjuta_preferences_reset_defaults (AnjutaPreferences
* pr
)
1451 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1453 dlg
= gtk_message_dialog_new (GTK_WINDOW (pr
),
1454 GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_QUESTION
,
1456 _("Are you sure you want to reset the preferences to\n"
1457 "their default settings?"));
1458 gtk_dialog_add_button (GTK_DIALOG (dlg
), GTK_STOCK_CANCEL
,
1459 GTK_RESPONSE_CANCEL
);
1460 anjuta_util_dialog_add_button (GTK_DIALOG (dlg
), _("_Reset"),
1461 GTK_STOCK_REVERT_TO_SAVED
,
1463 if (gtk_dialog_run (GTK_DIALOG (dlg
)) == GTK_RESPONSE_YES
)
1465 /* FIXME: Reset preferences to built-in default values. */
1467 gtk_widget_destroy (dlg
);
1471 * anjuta_preferences_foreach:
1472 * @pr: A #AnjutaPreferences object.
1473 * @filter: Keys to filter out from the loop.
1474 * @callback: User callback function.
1475 * @data: User data passed to @callback
1477 * Calls @callback function for each of the registered property keys. Keys
1478 * with matching @filter flags are left out of the loop. If @filter is
1479 * ANJUTA_PREFERENCES_FILTER_NONE, all properties are selected for the loop.
1482 anjuta_preferences_foreach (AnjutaPreferences
*pr
,
1483 AnjutaPreferencesFilterType filter
,
1484 AnjutaPreferencesCallback callback
,
1487 struct _AnjutaPreferencesForeachData foreach_data
;
1489 foreach_data
.pr
= pr
;
1490 foreach_data
.filter
= filter
;
1491 foreach_data
.callback
= callback
;
1492 foreach_data
.callback_data
= data
;
1494 g_hash_table_find (pr
->priv
->properties
,
1495 (GHRFunc
) preferences_foreach_callback
,
1501 * anjuta_preferences_add_page:
1502 * @pr: a #AnjutaPreferences object
1503 * @gxml: #GladeXML object containing the preferences page
1504 * @glade_widget_name: Page widget name (as give with glade interface editor).
1505 * The widget will be searched with the given name and detached
1506 * (that is, removed from the container, if present) from it's parent.
1507 * @icon_filename: File name (of the form filename.png) of the icon representing
1508 * the preference page.
1510 * Add a page to the preferences sytem.
1511 * gxml is the GladeXML object of the glade dialog containing the page widget.
1512 * The glade dialog will contain the layout of the preferences widgets.
1513 * The widgets which are preference widgets (e.g. toggle button) should have
1514 * widget names of the form:
1517 * preferences_OBJECTTYPE:DATATYPE:DEFAULT:FLAGS:PROPERTYKEY
1519 * OBJECTTYPE is 'toggle', 'spin', 'entry', 'text', 'color', 'font' or 'file' .
1520 * DATATYPE is 'bool', 'int', 'float', 'text', 'color' or 'font'.
1521 * DEFAULT is the default value (in the appropriate format). The format
1522 * for color is '#XXXXXX' representing RGB value and for
1523 * font, it is the pango font description.
1524 * FLAGS is any flag associated with the property. Currently it
1525 * has only two values -- 0 and 1. For normal preference
1526 * property which is saved/retrieved globally, the flag = 0.
1527 * For preference property which is also saved/retrieved
1528 * along with the project, the flag = 1.
1529 * PROPERTYKEY is the property key. e.g - 'tab.size'.
1532 * All widgets having the above names in the gxml tree will be registered
1533 * and will become part of auto saving/loading. For example, refer to
1534 * anjuta preferences dialogs and study the widget names.
1537 anjuta_preferences_add_page (AnjutaPreferences
* pr
, GladeXML
*gxml
,
1538 const gchar
* glade_widget_name
,
1540 const gchar
*icon_filename
)
1547 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1548 g_return_if_fail (glade_widget_name
!= NULL
);
1549 g_return_if_fail (icon_filename
!= NULL
);
1551 page
= glade_xml_get_widget (gxml
, glade_widget_name
);
1552 g_object_ref (page
);
1553 g_return_if_fail (GTK_IS_WIDGET (page
));
1554 parent
= gtk_widget_get_parent (page
);
1555 if (parent
&& GTK_IS_CONTAINER (parent
))
1557 if (GTK_IS_NOTEBOOK (parent
))
1561 page_num
= gtk_notebook_page_num (GTK_NOTEBOOK (parent
), page
);
1562 gtk_notebook_remove_page (GTK_NOTEBOOK (parent
), page_num
);
1566 gtk_container_remove (GTK_CONTAINER (parent
), page
);
1569 image_path
= anjuta_res_get_pixmap_file (icon_filename
);
1570 pixbuf
= gdk_pixbuf_new_from_file (image_path
, NULL
);
1571 anjuta_preferences_dialog_add_page (ANJUTA_PREFERENCES_DIALOG (pr
->priv
->prefs_dialog
),
1572 glade_widget_name
, title
, pixbuf
, page
);
1573 anjuta_preferences_register_all_properties_from_glade_xml (pr
, gxml
, page
);
1574 g_object_unref (page
);
1575 g_free (image_path
);
1576 g_object_unref (pixbuf
);
1580 anjuta_preferences_remove_page (AnjutaPreferences
*pr
,
1581 const gchar
*page_name
)
1583 if (pr
->priv
->prefs_dialog
)
1585 anjuta_preferences_dialog_remove_page (ANJUTA_PREFERENCES_DIALOG (pr
->priv
->prefs_dialog
),
1591 on_preferences_dialog_destroyed (GtkWidget
*preferencess_dialog
,
1592 AnjutaPreferences
*pr
)
1595 GList
*current_plugin
;
1597 plugins
= anjuta_plugin_manager_get_active_plugin_objects (pr
->priv
->plugin_manager
);
1598 current_plugin
= plugins
;
1600 while (current_plugin
)
1602 if (IANJUTA_IS_PREFERENCES (current_plugin
->data
))
1604 ianjuta_preferences_unmerge (IANJUTA_PREFERENCES (current_plugin
->data
),
1608 current_plugin
= g_list_next (current_plugin
);
1612 g_object_unref (pr
->priv
->prefs_dialog
);
1614 g_list_free (plugins
);
1615 pr
->priv
->prefs_dialog
= NULL
;
1619 anjuta_preferences_get_dialog (AnjutaPreferences
*pr
)
1622 GList
*current_plugin
;
1624 if (pr
->priv
->prefs_dialog
)
1625 return pr
->priv
->prefs_dialog
;
1628 pr
->priv
->prefs_dialog
= anjuta_preferences_dialog_new ();
1630 g_signal_connect (G_OBJECT (pr
->priv
->prefs_dialog
), "destroy",
1631 G_CALLBACK (on_preferences_dialog_destroyed
),
1634 plugins
= anjuta_plugin_manager_get_active_plugin_objects (pr
->priv
->plugin_manager
);
1635 current_plugin
= plugins
;
1637 while (current_plugin
)
1639 if (IANJUTA_IS_PREFERENCES (current_plugin
->data
))
1641 ianjuta_preferences_merge (IANJUTA_PREFERENCES (current_plugin
->data
),
1645 current_plugin
= g_list_next (current_plugin
);
1648 g_list_free (plugins
);
1650 return g_object_ref_sink (pr
->priv
->prefs_dialog
);
1655 anjuta_preferences_is_dialog_created (AnjutaPreferences
*pr
)
1657 return pr
->priv
->prefs_dialog
;
1660 static void anjuta_preferences_class_init (AnjutaPreferencesClass
*class);
1661 static void anjuta_preferences_instance_init (AnjutaPreferences
*pr
);
1664 anjuta_preferences_get_type ()
1666 static GType obj_type
= 0;
1670 static const GTypeInfo obj_info
=
1672 sizeof (AnjutaPreferencesClass
),
1673 (GBaseInitFunc
) NULL
,
1674 (GBaseFinalizeFunc
) NULL
,
1675 (GClassInitFunc
) anjuta_preferences_class_init
,
1676 (GClassFinalizeFunc
) NULL
,
1677 NULL
, /* class_data */
1678 sizeof (AnjutaPreferencesClass
),
1679 0, /* n_preallocs */
1680 (GInstanceInitFunc
) anjuta_preferences_instance_init
,
1681 NULL
/* value_table */
1683 obj_type
= g_type_register_static (G_TYPE_OBJECT
,
1684 "AnjutaPreferences", &obj_info
, 0);
1690 anjuta_preferences_dispose (GObject
*obj
)
1692 AnjutaPreferences
*pr
= ANJUTA_PREFERENCES (obj
);
1694 if (pr
->priv
->properties
)
1696 /* This will release the refs on property objects */
1697 g_hash_table_destroy (pr
->priv
->properties
);
1698 pr
->priv
->properties
= NULL
;
1703 anjuta_preferences_instance_init (AnjutaPreferences
*pr
)
1705 pr
->priv
= g_new0 (AnjutaPreferencesPriv
, 1);
1707 pr
->priv
->properties
= g_hash_table_new_full (g_str_hash
, g_str_equal
,
1709 (GDestroyNotify
) property_destroy
);
1711 pr
->priv
->gclient
= gconf_client_get_default();
1712 gconf_client_add_dir (pr
->priv
->gclient
, GCONF_KEY_PREFIX
,
1713 GCONF_CLIENT_PRELOAD_ONELEVEL
, NULL
);
1718 anjuta_preferences_finalize (GObject
*obj
)
1720 AnjutaPreferences
*pr
= ANJUTA_PREFERENCES (obj
);
1722 if (pr
->priv
->prefs_dialog
)
1723 gtk_widget_destroy (pr
->priv
->prefs_dialog
);
1725 g_object_unref (pr
->priv
->plugin_manager
);
1730 anjuta_preferences_class_init (AnjutaPreferencesClass
*class)
1732 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
1734 object_class
->dispose
= anjuta_preferences_dispose
;
1735 object_class
->finalize
= anjuta_preferences_finalize
;
1739 * anjuta_preferences_new:
1741 * Creates a new #AnjutaPreferences object
1743 * Return value: A #AnjutaPreferences object.
1746 anjuta_preferences_new (AnjutaPluginManager
*plugin_manager
)
1748 AnjutaPreferences
*pr
;
1750 pr
= g_object_new (ANJUTA_TYPE_PREFERENCES
, NULL
);
1751 pr
->priv
->plugin_manager
= g_object_ref (plugin_manager
);
1758 * anjuta_preferences_notify_add:
1759 * @pr: A #AnjutaPreferences object.
1760 * @key: Key to monitor.
1761 * @func: User callback function.
1762 * @data: User data passed to @func
1763 * @destroy_notify: Destroy notify function - called when notify is removed.
1765 * This is similar to gconf_client_notify_add(), except that the key is not
1766 * given as full path. Only anjuta preference key is given. The key prefix
1767 * is added internally.
1769 * Return value: Notify ID.
1772 anjuta_preferences_notify_add (AnjutaPreferences
*pr
,
1774 GConfClientNotifyFunc func
,
1776 GFreeFunc destroy_notify
)
1778 return gconf_client_notify_add (pr
->priv
->gclient
,
1780 func
, data
, destroy_notify
, NULL
);
1784 * anjuta_preferences_notify_remove:
1785 * @pr: A #AnjutaPreferences object.
1786 * @notify_id: Notify ID returned by anjuta_preferences_notify_add().
1788 * Removes the notify callback added with anjuta_preferences_notify_add().
1791 anjuta_preferences_notify_remove (AnjutaPreferences
*pr
, guint notify_id
)
1793 gconf_client_notify_remove (pr
->priv
->gclient
, notify_id
);
1797 * anjuta_preferences_get_prefix:
1798 * @pr: A #AnjutaPreferences object.
1800 * Returns the gconf key prefix used by anjuta to store its preferences.
1802 * Return value: preferences keys prefix.
1805 anjuta_preferences_get_prefix (AnjutaPreferences
*pr
)
1807 return PREFERENCE_PROPERTY_PREFIX
;
1811 * anjuta_preferences_dir_exists:
1812 * @pr: A #AnjutaPreferences object.
1813 * @dir: Directory to checkfor.
1815 * Returns TRUE if dir exists.
1821 anjuta_preferences_dir_exists (AnjutaPreferences
*pr
, const gchar
*dir
)
1823 g_return_val_if_fail (ANJUTA_IS_PREFERENCES (pr
), FALSE
);
1824 g_return_val_if_fail (dir
!= NULL
, FALSE
);
1826 return gconf_client_dir_exists(pr
->priv
->gclient
, build_key (dir
), NULL
);
1830 * anjuta_preferences_add_dir:
1831 * @pr: A #AnjutaPreferences object.
1832 * @dir: Directory to add to the list.
1833 * @preload: Degree of preload.
1835 * Add a directory to the list of directories the GConfClient.
1841 anjuta_preferences_add_dir (AnjutaPreferences
*pr
, const gchar
*dir
,
1842 GConfClientPreloadType preload
)
1844 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1845 g_return_if_fail (dir
!= NULL
);
1847 gconf_client_add_dir(pr
->priv
->gclient
, build_key (dir
),
1852 * anjuta_preferences_remove_dir:
1853 * @pr: A #AnjutaPreferences object.
1854 * @dir: Directory to remove from the list.
1856 * Remove a directory from the list of directories.
1862 anjuta_preferences_remove_dir (AnjutaPreferences
*pr
, const gchar
*dir
)
1864 g_return_if_fail (ANJUTA_IS_PREFERENCES (pr
));
1865 g_return_if_fail (dir
!= NULL
);
1867 gconf_client_remove_dir(pr
->priv
->gclient
, build_key (dir
), NULL
);