5 #include "stuffkeeper-data-item.h"
6 #include "stuffkeeper-data-label.h"
10 #include "stuffkeeper-data-backend.h"
14 class Stuffkeeper:Data:Expander from Gtk:Expander
16 private StuffkeeperDataItem *item = {NULL};
17 private gchar *field = {NULL} destroywith g_free;
18 private gulong changed_item_entry = {0};
19 private gulong changed_expander = {0};
22 private gulong signal_backend_locked = {0};
26 expander_changed(self, gpointer data)
28 int value = gtk_expander_get_expanded(GTK_EXPANDER(self));
29 stuffkeeper_data_item_set_integer(self->_priv->item, self->_priv->field, value);
34 item_changed(self,const gchar *field, StuffkeeperDataItem *item)
36 if(field && self->_priv->field && strcmp(field, self->_priv->field) == 0)
38 const int new_value = stuffkeeper_data_item_get_integer(item, self->_priv->field);
39 int value = gtk_expander_get_expanded(GTK_EXPANDER(self));
40 if(value != new_value)
42 g_signal_handler_block(self,self->_priv->changed_expander);
43 gtk_expander_set_expanded(GTK_EXPANDER(self), new_value);
44 g_signal_handler_unblock(self,self->_priv->changed_expander);
51 backend_locked(self, GParamSpec *arg1, StuffkeeperDataBackend *backend)
53 /* Don't lock expander, it does not gain anything
54 gboolean locked = stuffkeeper_data_backend_get_locked(backend);
55 gtk_widget_set_sensitive(GTK_WIDGET(self), !locked);
61 new(StuffkeeperDataItem *item, const gchar *field)
65 StuffkeeperDataSchema *schema = stuffkeeper_data_item_get_schema(item);
66 GtkWidget *label = (GtkWidget *)stuffkeeper_data_label_new_schema_field(STUFFKEEPER_DATA_SCHEMA(schema),field);
67 gtk_widget_modify_fg(GTK_WIDGET(label), GTK_STATE_NORMAL, &(GTK_WIDGET(obj)->style->black));
68 gtk_expander_set_label_widget(GTK_EXPANDER(obj), label);
70 obj->_priv->item = item;
72 obj->_priv->field = g_strdup(field);
75 new_value = stuffkeeper_data_item_get_integer(item, obj->_priv->field);
76 gtk_expander_set_expanded(GTK_EXPANDER(obj), new_value);
79 obj->_priv->changed_item_entry = g_signal_connect_swapped(G_OBJECT(item), "item-changed", G_CALLBACK(self_item_changed), obj);
80 obj->_priv->changed_expander = g_signal_connect(G_OBJECT(obj), "notify::expanded", G_CALLBACK(self_expander_changed), NULL);
82 obj->_priv->signal_backend_locked = g_signal_connect_swapped(G_OBJECT(stuffkeeper_data_item_get_backend(item)),
83 "notify::locked", G_CALLBACK(self_backend_locked), obj);
84 self_backend_locked(obj,NULL, STUFFKEEPER_DATA_BACKEND(stuffkeeper_data_item_get_backend(item)));
87 return GTK_WIDGET(obj);
92 finalize (G:Object *obj)
94 Self *self = SELF(obj);
95 if(self->_priv->signal_backend_locked) {
96 g_signal_handler_disconnect(G_OBJECT(stuffkeeper_data_item_get_backend(self->_priv->item)), self->_priv->signal_backend_locked);
97 self->_priv->signal_backend_locked = 0;
100 if(self->_priv->changed_item_entry)
102 g_signal_handler_disconnect(self->_priv->item,self->_priv->changed_item_entry);
103 self->_priv->changed_item_entry = 0;