Update called vala api.
[stuffkeeper.git] / src / stuffkeeper-data-expander.gob
blobab9e08eb3231541cdf9d8e57b40800434d05af5b
1 requires 2.0.10
3 %h{
4 #include <gtk/gtk.h>
5 #include "stuffkeeper-data-item.h"
6 #include "stuffkeeper-data-label.h"
7 %}
9 %ph{
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};
21     /* lock signal */
22     private gulong signal_backend_locked = {0};
24     private
25     void
26     expander_changed(self, gpointer data)
27     {
28         int value = gtk_expander_get_expanded(GTK_EXPANDER(self));
29         stuffkeeper_data_item_set_integer(self->_priv->item, self->_priv->field, value);
30     }
32     private
33     void
34     item_changed(self,const gchar *field, StuffkeeperDataItem *item)
35     {
36         if(field && self->_priv->field && strcmp(field, self->_priv->field) == 0)
37         {
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)
41             {
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);
45             }
46         }
47     }
49     private
50         void
51         backend_locked(self, GParamSpec *arg1, StuffkeeperDataBackend *backend)
52         {
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);
56             */
57         }
59     public
60         GtkWidget *
61         new(StuffkeeperDataItem *item, const gchar *field)
62     {
63         int new_value = 0;
64         Self *obj = GET_NEW;
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);
69         /* store item */
70         obj->_priv->item = item; 
71         /* field */
72         obj->_priv->field = g_strdup(field);
73            
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);
88     }
90     override (G:Object)
91         void
92         finalize (G:Object *obj)
93         {
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;
98             }
100             if(self->_priv->changed_item_entry)
101             {
102                 g_signal_handler_disconnect(self->_priv->item,self->_priv->changed_item_entry);
103                 self->_priv->changed_item_entry = 0;
104             }
105             PARENT_HANDLER(obj);
106         }