4 #include "stuffkeeper-data-item.h"
8 #include "stuffkeeper-data-backend.h"
12 #define PRIVATE_FIELD_DEFAULT 0
16 class Stuffkeeper:Data:Entry:Config from Gtk:HBox
18 private GtkWidget *entry = {NULL};
19 private StuffkeeperDataSchema *schema = {NULL};
20 private gchar *field = {NULL} destroywith g_free;
21 private gulong changed_custom_field = {0};
22 private gulong changed_entry = {0};
24 private guint changed_entry_timeout = {0};
25 private GdkColor writing ;
26 private GdkColor base;
27 private GdkColor text;
30 private gulong signal_backend_locked = {0};
36 const gchar *text = gtk_entry_get_text(GTK_ENTRY(self->_priv->entry));
38 stuffkeeper_data_schema_set_custom_field_string(self->_priv->schema,self->_priv->field,PRIVATE_FIELD_DEFAULT,text);
40 gtk_widget_modify_text(GTK_WIDGET(self->_priv->entry), GTK_STATE_NORMAL, &(self->_priv->text));
41 gtk_widget_modify_base(GTK_WIDGET(self->_priv->entry), GTK_STATE_NORMAL, &(self->_priv->base));
42 self->_priv->changed_entry_timeout = 0;
50 changed(self, gpointer data)
52 if(self->_priv->changed_entry_timeout)
54 g_source_remove(self->_priv->changed_entry_timeout);
56 self->_priv->changed_entry_timeout = g_timeout_add(1000,(GSourceFunc)self_save_changes,self);
58 gtk_widget_modify_text(GTK_WIDGET(self->_priv->entry), GTK_STATE_NORMAL, &(GTK_WIDGET(self)->style->black));
59 gtk_widget_modify_base(GTK_WIDGET(self->_priv->entry), GTK_STATE_NORMAL, &(self->_priv->writing));
63 item_changed(self,const gchar *id, int field, StuffkeeperDataSchema *schema)
65 const gchar *text = gtk_entry_get_text(GTK_ENTRY(self->_priv->entry));
67 if(field != PRIVATE_FIELD_DEFAULT)
69 value = stuffkeeper_data_schema_get_custom_field_string(schema, self->_priv->field,field);
72 if(strcmp(text,value))
74 g_signal_handler_block(self->_priv->entry,self->_priv->changed_entry);
75 gtk_entry_set_text(GTK_ENTRY(self->_priv->entry), value);
76 g_signal_handler_unblock(self->_priv->entry,self->_priv->changed_entry);
83 style_set(self, GtkStyle *prev, GtkWidget *wid)
85 if(self->_priv->changed_entry_timeout == 0) {
86 self->_priv->base = (GTK_WIDGET(self)->style->base[GTK_STATE_NORMAL]);
87 self->_priv->text = (GTK_WIDGET(self)->style->text[GTK_STATE_NORMAL]);
93 new(StuffkeeperDataSchema *schema, const gchar *field (check null))
97 GtkWidget *label = gtk_label_new(_("Default value:"));
99 obj->_priv->text = (GTK_WIDGET(obj)->style->text[GTK_STATE_NORMAL]);
100 obj->_priv->writing.red = 255*255;
101 obj->_priv->writing.green = 253*255;
102 obj->_priv->writing.blue = 197*255;
103 gdk_colormap_alloc_color(gtk_widget_get_default_colormap(), &(obj->_priv->writing), TRUE,TRUE);
104 g_signal_connect_swapped(G_OBJECT(obj), "style-set", G_CALLBACK(self_style_set),obj);
109 obj->_priv->schema = schema;
111 obj->_priv->field = g_strdup(field);
112 obj->_priv->entry = gtk_entry_new();
114 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
115 gtk_box_pack_start(GTK_BOX(obj), label, FALSE, TRUE,0);
116 gtk_box_pack_start(GTK_BOX(obj), obj->_priv->entry, TRUE, TRUE,0);
118 obj->_priv->changed_custom_field = g_signal_connect_swapped(G_OBJECT(obj->_priv->schema),
119 "schema_custom_field_changed", G_CALLBACK(self_item_changed), obj);
121 value = stuffkeeper_data_schema_get_custom_field_string(schema, obj->_priv->field,PRIVATE_FIELD_DEFAULT);
122 /* update the entry */
125 gtk_entry_set_text(GTK_ENTRY(obj->_priv->entry), value);
129 /* this is destroyed when self is destroyed, so no need to disconnect myself */
130 obj->_priv->changed_entry = g_signal_connect_swapped(G_OBJECT(obj->_priv->entry), "changed", G_CALLBACK(self_changed), obj);
131 return GTK_WIDGET(obj);
136 dispose(G:Object *obj)
138 Self *self = SELF(obj);
140 if(self->_priv->changed_custom_field)
142 g_signal_handler_disconnect(self->_priv->schema,self->_priv->changed_custom_field);
143 self->_priv->changed_custom_field = 0;
146 if(self->_priv->changed_entry_timeout)
148 g_source_remove(self->_priv->changed_entry_timeout);
149 self->_priv->changed_entry_timeout = 0;
151 self_save_changes(self);