7 #include "stuffkeeper-data-backend.h"
8 #include "stuffkeeper-data-item.h"
12 class Stuffkeeper:Data:Link from Gtk:Entry
14 private StuffkeeperDataItem *item = {NULL};
15 private gchar *field = {NULL} destroywith g_free;
16 private gulong changed_item_entry = {0};
17 private gulong changed_entry = {0};
19 private guint changed_entry_timeout = {0};
20 private GdkColor writing ;
21 private GdkColor base;
22 private GdkColor text;
25 private gulong signal_backend_locked = {0};
31 const gchar *text = gtk_entry_get_text(GTK_ENTRY(self));
32 UrlType type = url_type(text);
37 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(self), GTK_ENTRY_ICON_PRIMARY,"internet-mail");
38 } else if ( type == URL_HTTP )
40 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(self), GTK_ENTRY_ICON_PRIMARY,"internet-web-browser");
42 gtk_entry_set_icon_from_stock(GTK_ENTRY(self), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_JUMP_TO);
49 const gchar *text = gtk_entry_get_text(GTK_ENTRY(self));
52 gtk_widget_modify_text(GTK_WIDGET(self), GTK_STATE_NORMAL, &(self->_priv->text));
53 gtk_widget_modify_base(GTK_WIDGET(self), GTK_STATE_NORMAL, &(self->_priv->base));
54 self->_priv->changed_entry_timeout = 0;
56 self_update_icon(self);
57 if(self->_priv->field)
59 stuffkeeper_data_item_set_string(self->_priv->item, self->_priv->field, text);
61 stuffkeeper_data_item_set_title(self->_priv->item, text);
69 changed(self, gpointer data)
71 if(self->_priv->changed_entry_timeout)
73 g_source_remove(self->_priv->changed_entry_timeout);
75 self->_priv->changed_entry_timeout = g_timeout_add(1000,(GSourceFunc)self_save_changes,self);
77 gtk_widget_modify_text(GTK_WIDGET(self), GTK_STATE_NORMAL, &(GTK_WIDGET(self)->style->black));
78 gtk_widget_modify_base(GTK_WIDGET(self), GTK_STATE_NORMAL, &(self->_priv->writing));
83 item_changed(self,const gchar *field, StuffkeeperDataItem *item)
85 const gchar *text = gtk_entry_get_text(GTK_ENTRY(self));
87 if(self->_priv->field)
89 if(field && strcmp(field, self->_priv->field) == 0)
91 value = stuffkeeper_data_item_get_string(item, self->_priv->field);
94 value = stuffkeeper_data_item_get_title(item);
98 if(strcmp(text,value))
100 g_signal_handler_block(self,self->_priv->changed_entry);
101 gtk_entry_set_text(GTK_ENTRY(self), value);
102 self_update_icon(self);
103 g_signal_handler_unblock(self,self->_priv->changed_entry);
114 open_link(self, GtkEntry *entry)
116 const gchar *text = gtk_entry_get_text(GTK_ENTRY(self));
119 UrlType type = url_type(text);
120 if(type == URL_EMAIL)
133 link_icon_clicked(self, GtkEntryIconPosition icon_pos, GdkEventButton *event, GtkEntry *icon_entry)
135 if(event->button == 1 && icon_pos == GTK_ENTRY_ICON_PRIMARY)
137 self_open_link(self, GTK_ENTRY(icon_entry));
143 style_set(self, GtkStyle *prev, GtkWidget *wid)
146 if(self->_priv->changed_entry_timeout == 0)
148 self->_priv->base = (GTK_WIDGET(self)->style->base[GTK_STATE_NORMAL]);
149 self->_priv->text = (GTK_WIDGET(self)->style->text[GTK_STATE_NORMAL]);
154 backend_locked(self, GParamSpec *arg1, StuffkeeperDataBackend *backend)
156 gboolean locked = stuffkeeper_data_backend_get_locked(backend);
157 gtk_editable_set_editable(GTK_EDITABLE(self), !locked);
162 new(StuffkeeperDataItem *item, const gchar *field)
168 obj->_priv->base = (GTK_WIDGET(obj)->style->base[GTK_STATE_NORMAL]);
169 obj->_priv->text = (GTK_WIDGET(obj)->style->text[GTK_STATE_NORMAL]);
171 obj->_priv->writing.red = 255*255;
172 obj->_priv->writing.green = 253*255;
173 obj->_priv->writing.blue = 197*255;
175 gdk_colormap_alloc_color(gtk_widget_get_default_colormap(), &(obj->_priv->writing), TRUE,TRUE);
178 /* color.blue = 65535;
179 color.red = color.green = 0;
180 gdk_colormap_alloc_color(gtk_widget_get_default_colormap(), &color, TRUE,TRUE);
181 gtk_widget_modify_text(GTK_WIDGET(obj), GTK_STATE_NORMAL, &color);
183 g_signal_connect_swapped(G_OBJECT(obj), "style-set", G_CALLBACK(self_style_set), obj);
186 gtk_entry_set_icon_from_stock(GTK_ENTRY(obj), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_JUMP_TO);
191 if(!g_key_file_get_boolean(config_file, "interface", "has-border",NULL))
192 gtk_entry_set_has_frame(GTK_ENTRY(obj), FALSE);
194 g_signal_connect_swapped(G_OBJECT(obj), "icon-release", G_CALLBACK(self_link_icon_clicked), obj);
197 obj->_priv->item = item;
199 obj->_priv->field = g_strdup(field);
201 obj->_priv->changed_item_entry = g_signal_connect_swapped(G_OBJECT(item), "item-changed", G_CALLBACK(self_item_changed), obj);
203 /* update the entry */
204 if(obj->_priv->field)
206 value = stuffkeeper_data_item_get_string(item, obj->_priv->field);
208 value = stuffkeeper_data_item_get_title(item);
212 gtk_entry_set_text(GTK_ENTRY(obj), value);
215 self_update_icon(obj);
217 /* this is destroyed when self is destroyed, so no need to disconnect myself */
218 g_signal_connect_swapped(G_OBJECT(obj), "activate", G_CALLBACK(self_open_link), obj);
219 obj->_priv->changed_entry = g_signal_connect(G_OBJECT(obj), "changed", G_CALLBACK(self_changed), NULL);
221 obj->_priv->signal_backend_locked = g_signal_connect_swapped(G_OBJECT(stuffkeeper_data_item_get_backend(item)),
222 "notify::locked", G_CALLBACK(self_backend_locked), obj);
223 self_backend_locked(obj,NULL, STUFFKEEPER_DATA_BACKEND(stuffkeeper_data_item_get_backend(item)));
226 return GTK_WIDGET(obj);
231 finalize (G:Object *obj)
233 Self *self = SELF(obj);
234 if(self->_priv->signal_backend_locked) {
235 g_signal_handler_disconnect(G_OBJECT(stuffkeeper_data_item_get_backend(self->_priv->item)), self->_priv->signal_backend_locked);
236 self->_priv->signal_backend_locked = 0;
238 if(self->_priv->changed_item_entry)
240 g_signal_handler_disconnect(self->_priv->item,self->_priv->changed_item_entry);
241 self->_priv->changed_item_entry = 0;
243 if(self->_priv->changed_entry_timeout)
245 g_source_remove(self->_priv->changed_entry_timeout);
246 self->_priv->changed_entry_timeout = 0;
248 self_save_changes(self);