if (!name || !address) return -1;
+ debug_print( "completion: add_address: %s - %s\n", name, address );
+
ae = g_new0(address_entry, 1);
ce1 = g_new0(completion_entry, 1),
ce2 = g_new0(completion_entry, 1);
return 0;
}
-static gboolean get_all_addresses(GNode *node, gpointer ae)
-{
- XMLNode *xmlnode = (XMLNode *)node->data;
- address_entry *addr = (address_entry *)ae;
-
- /* this simply checks if tag is "item". in that case, it
- * verifies it has already seen an item. if it did, an
- * address retrieval was complete */
- if (!strcmp(xmlnode->tag->tag, "item")) {
- /* see if a previous item was complete */
- /* TODO: does sylpheed address book allow empty names to be entered?
- * if so, addr->name *AND* addr->address should be checked. */
- /* add address to our database */
- add_address(addr->name, addr->address);
- g_free(addr->name);
- g_free(addr->address);
- addr->name = NULL;
- addr->address = NULL;
- } else if (!strcmp(xmlnode->tag->tag, "name"))
- addr->name = g_strdup(xmlnode->element);
- else if (!strcmp(xmlnode->tag->tag, "address"))
- addr->address = g_strdup(xmlnode->element);
-
- return FALSE;
-}
-
/* read_address_book()
*/
-static void read_address_book(void)
-{
- gchar *path;
- GNode *tree;
- address_entry ad = {NULL, NULL};
-
- LOG_MESSAGE( _("%s%d entering read_address_book\n"), __FILE__, __LINE__);
- path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ADDRESS_BOOK, NULL);
- tree = xml_parse_file(path);
- g_free(path);
- if (!tree) {
- LOG_MESSAGE( _("%s(%d) no addressbook\n"), __FILE__, __LINE__);
- return;
- }
-
- /* retrieve all addresses */
- g_node_traverse(tree, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
- (GNodeTraverseFunc) get_all_addresses, &ad);
- /* still one pending? */
- if (ad.name) {
- add_address(ad.name, ad.address);
- if (ad.name)
- g_free(ad.name);
- if (ad.address)
- g_free(ad.address);
- }
-
- xml_free_tree(tree);
-
- LOG_MESSAGE(_("%s(%d) leaving read_address_book - OK\n"), __FILE__, __LINE__);
+static void read_address_book(void) {
+ addressbook_load_completion( add_address );
}
/* start_address_completion() - returns the number of addresses
mainwindow);
}
+/* Need unique data to make unregistering signal handler possible for the auto
+ * completed entry */
+#define COMPLETION_UNIQUE_DATA (GINT_TO_POINTER(0xfeefaa))
+
void address_completion_register_entry(GtkEntry *entry)
{
g_return_if_fail(entry != NULL);
gtk_signal_connect_full(GTK_OBJECT(entry), "key_press_event",
GTK_SIGNAL_FUNC(address_completion_entry_key_pressed),
NULL,
- NULL,
+ COMPLETION_UNIQUE_DATA,
NULL,
0,
0); /* magic */
}
+void address_completion_unregister_entry(GtkEntry *entry)
+{
+ GtkObject *entry_obj;
+
+ g_return_if_fail(entry != NULL);
+ g_return_if_fail(GTK_IS_ENTRY(entry));
+
+ entry_obj = gtk_object_get_data(GTK_OBJECT(entry), ENTRY_DATA_TAB_HOOK);
+ g_return_if_fail(entry_obj);
+ g_return_if_fail(entry_obj == GTK_OBJECT(entry));
+
+ /* has the hooked property? */
+ gtk_object_set_data(GTK_OBJECT(entry), ENTRY_DATA_TAB_HOOK, NULL);
+
+ /* remove the hook */
+ gtk_signal_disconnect_by_func(GTK_OBJECT(entry),
+ GTK_SIGNAL_FUNC(address_completion_entry_key_pressed),
+ COMPLETION_UNIQUE_DATA);
+}
+
/* should be called when main window with address completion entries
- * terminates */
+ * terminates.
+ * NOTE: this function assumes that it is called upon destruction of
+ * the window */
void address_completion_end(GtkWidget *mainwindow)
{
/* if address_completion_end() is really called on closing the window,