Update called vala api.
[stuffkeeper.git] / src / stuffkeeper-data-label.gob
blob9c0549b6dbe484c5148cbea008bf77e23c3a551e
1 requires 2.0.10
3 %h{
4 #include <gtk/gtk.h>
5 #include <time.h>
6 #include "stuffkeeper-data-tag.h"
7 #include "stuffkeeper-data-schema.h"
8 #include "stuffkeeper-data-item.h"
9 %}
12 class Stuffkeeper:Data:Label from Gtk:Label
14     private GObject *item = {NULL};
15     private gchar *field = {NULL} destroywith g_free;
16     private gulong changed_item_entry = {0};
19     private
20     void
21     field_item_changed(self,const gchar *id, Stuffkeeper:Data:Schema *schema)
22     {
23         gchar *value;
24         value = stuffkeeper_data_schema_get_field_name(STUFFKEEPER_DATA_SCHEMA(self->_priv->item),self->_priv->field);
25         if(value)
26         {
27             gchar *markup = g_markup_printf_escaped("<b>%s</b>", value);
28             gtk_label_set_text(GTK_LABEL(self), value);
29             gtk_label_set_markup(GTK_LABEL(self), markup);
30             g_free(markup);
31             g_free(value);
32         }
33     }
36     private
37     void
38     schema_item_changed(self,GObject *item, gpointer data)
39     {
40         gchar *value;
41         if(STUFFKEEPER_IS_DATA_SCHEMA(self->_priv->item))
42         {
43             value = stuffkeeper_data_schema_get_title(STUFFKEEPER_DATA_SCHEMA(self->_priv->item));
44             if(value)
45             {
46                 gtk_label_set_text(GTK_LABEL(self), value);
47                 g_free(value);
48             }
49         }
50     }
52     private
53     void
54     tag_item_changed(self, GObject *item, gpointer data)
55     {
56         gchar *value;
57         if (STUFFKEEPER_IS_DATA_TAG(self->_priv->item))
58         {
59             value = stuffkeeper_data_tag_get_title(STUFFKEEPER_DATA_TAG(self->_priv->item));
60             if(value)
61             {
62                 gtk_label_set_text(GTK_LABEL(self), value);
63                 g_free(value);
64             }
65         }
66     }
69     private
70     void
71     item_changed(self, char *field,GObject *item)
72     {
73         if (STUFFKEEPER_IS_DATA_ITEM(self->_priv->item))
74         {
75             time_t time = stuffkeeper_data_item_get_modification_time(STUFFKEEPER_DATA_ITEM(item));
76             struct tm *t  = localtime(&time);
77             char buffer[256];
78             strftime(buffer,256, "%x", t);
79             gtk_label_set(GTK_LABEL(self), buffer);
80         }
81     }
85     /**
86      * Creates a label that keeps track of the name of a tag.
87      */
88     public
89     GtkWidget *
90     new_tag(StuffkeeperDataTag *tag)
91     {
92         Self *obj = GET_NEW;
93         gchar *value =NULL;
95         gtk_misc_set_alignment(GTK_MISC(obj), 0, 0.5);
96         
97         /* store item */
98         obj->_priv->item = G_OBJECT(tag); 
99             
100         obj->_priv->changed_item_entry = g_signal_connect_swapped(G_OBJECT(obj->_priv->item), "tag-changed", G_CALLBACK(self_tag_item_changed), obj);
102         value = stuffkeeper_data_tag_get_title(STUFFKEEPER_DATA_TAG(obj->_priv->item));
103         if(value)
104         {
105             gtk_label_set_text(GTK_LABEL(obj), value);
106             g_free(value);
107         }
108         return GTK_WIDGET(obj);
109     }
111     /**
112      * Creates a label that keeps track of the name of a schema 
113      */
114     public
115     GtkWidget *
116     new_schema(StuffkeeperDataSchema *schema)
117     {
118         Self *obj = GET_NEW;
119         gchar *value =NULL;
121         gtk_misc_set_alignment(GTK_MISC(obj), 0, 0.5);
122         
123         /* store item */
124         obj->_priv->item = G_OBJECT(schema); 
126             
127         obj->_priv->changed_item_entry = g_signal_connect_swapped(G_OBJECT(obj->_priv->item), "schema-changed", G_CALLBACK(self_schema_item_changed), obj);
129         value = stuffkeeper_data_schema_get_title(STUFFKEEPER_DATA_SCHEMA(obj->_priv->item));
130         if(value)
131         {
132             gtk_label_set_text(GTK_LABEL(obj), value);
133             g_free(value);
134         }
135         return GTK_WIDGET(obj);
136     }
137     
138     /**
139      * Creates a label that keeps track of the name of a field in a schema 
140      */
141     public
142     GtkWidget *
143     new_schema_field(StuffkeeperDataSchema *schema,const gchar *field)
144     {
145         Self *obj = GET_NEW;
146         gchar *value =NULL;
148         gtk_misc_set_alignment(GTK_MISC(obj), 0, 0.5);
149         
150         /* store item */
151         obj->_priv->item = G_OBJECT(schema); 
153         obj->_priv->field = g_strdup(field); 
154         obj->_priv->changed_item_entry = g_signal_connect_swapped(G_OBJECT(obj->_priv->item), 
155                         "schema-field-changed", 
156                         G_CALLBACK(self_field_item_changed),
157                         obj);
159         value = stuffkeeper_data_schema_get_field_name(STUFFKEEPER_DATA_SCHEMA(obj->_priv->item),obj->_priv->field);
160         if(value)
161         {
162             gchar *markup = g_markup_printf_escaped("<b>%s</b>", value);
163             gtk_label_set_text(GTK_LABEL(obj), value);
164             gtk_label_set_markup(GTK_LABEL(obj), markup);
165             g_free(markup);
166             g_free(value);
167         }
168         return GTK_WIDGET(obj);
169     }
171     /**
172      * Creates a label that keeps track of the modification time of a tag 
173      */
174     public
175     GtkWidget *
176     new_modifcation_time_item(StuffkeeperDataItem *item)
177     {
178         Self *obj = GET_NEW;
179         gtk_misc_set_alignment(GTK_MISC(obj), 0, 0.5);
180         
181         /* store item */
182         obj->_priv->item = G_OBJECT(item); 
183             
184         obj->_priv->changed_item_entry = g_signal_connect_swapped(G_OBJECT(obj->_priv->item), "item-changed", G_CALLBACK(self_item_changed), obj);
186         /* update the label */
187         self_item_changed(obj,NULL, obj->_priv->item);
189         return GTK_WIDGET(obj);
190     }
194     override (G:Object)
195         void
196         finalize (G:Object *obj)
197         {
198             Self *self = SELF(obj);
199             if(self->_priv->changed_item_entry)
200             {
201                 g_signal_handler_disconnect(self->_priv->item,self->_priv->changed_item_entry);
202                 self->_priv->changed_item_entry = 0;
203             }
204             PARENT_HANDLER(obj);
205         }