diff --git a/sflphone-gtk/src/config/addressbook-config.c b/sflphone-gtk/src/config/addressbook-config.c index 29451d2b225f3d8464f5048b608854af69932832..2a3919fec172c1614738047379ac8ae5a7a65052 100644 --- a/sflphone-gtk/src/config/addressbook-config.c +++ b/sflphone-gtk/src/config/addressbook-config.c @@ -19,13 +19,15 @@ #include "addressbook-config.h" #include <contacts/addressbook/eds.h> +#include <string.h> +#include <stdlib.h> AddressBook_Config *addressbook_config; GtkWidget *book_tree_view; enum { - COLUMN_BOOK_ACTIVE, COLUMN_BOOK_NAME + COLUMN_BOOK_ACTIVE, COLUMN_BOOK_NAME, COLUMN_BOOK_UID }; void @@ -141,27 +143,69 @@ addressbook_config_book_active_toggled( GtkTreePath *treePath; GtkTreeModel *model; gboolean active; - char* name; + gchar* name; + gchar* uid; // Get path of clicked book active toggle box treePath = gtk_tree_path_new_from_string(path); model = gtk_tree_view_get_model(GTK_TREE_VIEW(data)); gtk_tree_model_get_iter(model, &iter, treePath); - // Get active value and name at iteration + // Get active value at iteration gtk_tree_model_get(model, &iter, COLUMN_BOOK_ACTIVE, &active, - COLUMN_BOOK_NAME, &name, -1); + COLUMN_BOOK_UID, &uid, COLUMN_BOOK_NAME, &name, -1); // Toggle active value active = !active; + printf("-> change active to : %d for %s\n", active, uid); + // Store value gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_BOOK_ACTIVE, active, -1); gtk_tree_path_free(treePath); - printf("%s : %d\n", name, active); - printf("Not implemented !\n"); + // Update current memory stored books data + books_get_book_data_by_uid(uid)->active = active; + + // Save data + + gboolean valid; + + // Initiate double array char list for one string + const gchar** list = (void*) malloc(sizeof(void*)); + int c = 0; + + /* Get the first iter in the list */ + valid = gtk_tree_model_get_iter_first(model, &iter); + + while (valid) + { + // Get active value at iteration + gtk_tree_model_get(model, &iter, COLUMN_BOOK_ACTIVE, &active, + COLUMN_BOOK_UID, &uid, COLUMN_BOOK_NAME, &name, -1); + + if (active) + { + // Reallocate memory each time + if (c != 0) + list = (void*) realloc(list, (c + 1) * sizeof(void*)); + + *(list + c) = uid; + c++; + } + + valid = gtk_tree_model_iter_next(model, &iter); + } + + // Allocate NULL array at the end for Dbus + list = (void*) realloc(list, (c + 1) * sizeof(void*)); + *(list + c) = NULL; + + // Call daemon to store in config file + dbus_set_addressbook_list(list); + + free(list); } static void @@ -170,26 +214,25 @@ addressbook_config_fill_book_list() GtkTreeIter list_store_iterator; GSList *book_list_iterator; GtkListStore *store; - EBook *book; - ESource *source; + book_data_t *book_data; // Get model of view and clear it store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(book_tree_view))); gtk_list_store_clear(store); - // Get list of books - GSList *books = get_books(); - // Populate window - for (book_list_iterator = books; book_list_iterator != NULL; book_list_iterator + for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator = book_list_iterator->next) { - book = (EBook *) book_list_iterator->data; - source = e_book_get_source(book); + book_data = (book_data_t *) book_list_iterator->data; gtk_list_store_append(store, &list_store_iterator); - gtk_list_store_set(store, &list_store_iterator, COLUMN_BOOK_ACTIVE, TRUE, - COLUMN_BOOK_NAME, e_source_peek_name(source), -1); + gtk_list_store_set(store, &list_store_iterator, COLUMN_BOOK_ACTIVE, + book_data->active, COLUMN_BOOK_UID, book_data->uid, COLUMN_BOOK_NAME, + book_data->name, -1); } + + store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(book_tree_view))); + } GtkWidget* @@ -275,8 +318,9 @@ create_addressbook_settings() gtk_container_add( GTK_CONTAINER (result_frame) , scrolled_window ); - store = gtk_list_store_new(2, + store = gtk_list_store_new(3, G_TYPE_BOOLEAN, // Active + G_TYPE_STRING, // uid G_TYPE_STRING // Name ); diff --git a/sflphone-gtk/src/contacts/addressbook.c b/sflphone-gtk/src/contacts/addressbook.c index 083d7ade72bb053b47ec98cd988782c7d62243e8..079d7d01cc74abeffbe45302675413ff7c0ea34c 100644 --- a/sflphone-gtk/src/contacts/addressbook.c +++ b/sflphone-gtk/src/contacts/addressbook.c @@ -19,6 +19,7 @@ #include <addressbook.h> #include <searchbar.h> +#include <string.h> #include <addressbook-config.h> static void @@ -44,7 +45,22 @@ addressbook_search(GtkEntry* entry) void addressbook_init() { + gchar **list; + gchar **config_book_uid; + init(); + + list = (gchar **) dbus_get_addressbook_list(); + + if (list) + { + for (config_book_uid = list; *config_book_uid; config_book_uid++) + { + books_get_book_data_by_uid(*config_book_uid)->active = TRUE; + } + g_strfreev(list); + } + } static void diff --git a/sflphone-gtk/src/contacts/addressbook/eds.c b/sflphone-gtk/src/contacts/addressbook/eds.c index 7552640abd00ca1985a743db97fb0a9840bcd98f..df9cee053413259ceddacbb9b21fcb2b77b68c0e 100644 --- a/sflphone-gtk/src/contacts/addressbook/eds.c +++ b/sflphone-gtk/src/contacts/addressbook/eds.c @@ -40,7 +40,6 @@ typedef struct _Handler_And_Data int book_views_remaining; } Handler_And_Data; -static GSList *books = NULL; static int pixbuf_size = 32; static EContactField search_fields[] = @@ -57,6 +56,22 @@ free_hit(Hit *h) g_free(h); } +book_data_t * +books_get_book_data_by_uid(gchar *uid) +{ + GSList *book_list_iterator; + book_data_t *book_data; + + for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator + = book_list_iterator->next) + { + book_data = (book_data_t *) book_list_iterator->data; + if (strcmp(book_data->uid, uid) == 0) + return book_data; + } + return NULL; +} + /** * Split a string of tokens separated by whitespace into an array of tokens. */ @@ -196,6 +211,8 @@ init(void) { GSList *list, *l; ESourceList *source_list; + book_data_t *book_data; + source_list = e_source_list_new_for_gconf_default( "/apps/evolution/addressbook/sources"); @@ -213,14 +230,15 @@ init(void) for (m = sources; m != NULL; m = m->next) { ESource *source = m->data; - //printf("%s\n",e_source_peek_name(source)); - //printf("%s\n",e_source_get_property (source, "limit")); - //printf("%s\n",e_source_get_property (source, "timeout")); - //printf("end\n"); EBook *book = e_book_new(source, NULL); if (book != NULL) { - books = g_slist_prepend(books, book); + book_data = g_new(book_data_t, 1); + book_data->active = FALSE; + book_data->name = e_source_peek_name(source); + book_data->uid = e_source_peek_uid(source); + book_data->ebook = book; + books_data = g_slist_prepend(books_data, book_data); e_book_open(book, TRUE, NULL); } } @@ -229,18 +247,11 @@ init(void) current_search_id = 0; g_object_unref (source_list); - get_books(); } -GSList* -get_books(void) -{ - return books; -} - -/** - * Final callback after all books have been processed. - */ + /** + * Final callback after all books have been processed. + */ static void view_finish(EBookView *book_view, Handler_And_Data *had) { @@ -391,18 +402,22 @@ search_async(const char *query, int max_results, SearchAsyncHandler handler, had->hits = NULL; had->max_results_remaining = max_results; had->book_views_remaining = 0; - for (iter = books; iter != NULL; iter = iter->next) + for (iter = books_data; iter != NULL; iter = iter->next) { - EBook *book = (EBook *) iter->data; - EBookView *book_view = NULL; - e_book_get_book_view(book, book_query, NULL, max_results, &book_view, - NULL); - if (book_view != NULL) + book_data_t *book_data = (book_data_t *) iter->data; + + if (book_data->active) { - had->book_views_remaining++; - g_signal_connect (book_view, "contacts_added", (GCallback) view_contacts_added_cb, had); - g_signal_connect (book_view, "sequence_complete", (GCallback) view_completed_cb, had); - e_book_view_start(book_view); + EBookView *book_view = NULL; + e_book_get_book_view(book_data->ebook, book_query, NULL, max_results, + &book_view, NULL); + if (book_view != NULL) + { + had->book_views_remaining++; + g_signal_connect (book_view, "contacts_added", (GCallback) view_contacts_added_cb, had); + g_signal_connect (book_view, "sequence_complete", (GCallback) view_completed_cb, had); + e_book_view_start(book_view); + } } } if (had->book_views_remaining == 0) diff --git a/sflphone-gtk/src/contacts/addressbook/eds.h b/sflphone-gtk/src/contacts/addressbook/eds.h index be5c3d9a421054a62bce06815ab98eb31d047a99..ea6654dc20b9614e147bdb3b77c686a06a1dee1d 100644 --- a/sflphone-gtk/src/contacts/addressbook/eds.h +++ b/sflphone-gtk/src/contacts/addressbook/eds.h @@ -49,6 +49,19 @@ typedef struct _Hit gchar *phone_mobile; } Hit; +/** + * Book structure for "outside world" + */ +typedef struct +{ + gchar *uid; + gchar *name; + gboolean active; + EBook *ebook; +} book_data_t; + +GSList *books_data; + /** * Free a contact entry */ @@ -85,6 +98,9 @@ fetch_information_from_contact(EContact *contact, EContactField field, GSList* get_books(void); +book_data_t * +books_get_book_data_by_uid(gchar *uid); + G_END_DECLS #endif /* __EDS_H__ */ diff --git a/sflphone-gtk/src/dbus/dbus.c b/sflphone-gtk/src/dbus/dbus.c index 41a917bb845a8304be04df414808e544b33bfa0c..9eabf1a43227ccddb9ab5f54bf585b53f69c3164 100644 --- a/sflphone-gtk/src/dbus/dbus.c +++ b/sflphone-gtk/src/dbus/dbus.c @@ -1497,6 +1497,31 @@ void dbus_set_addressbook_settings (GHashTable * settings){ } } +gchar** dbus_get_addressbook_list (void) { + + GError *error = NULL; + gchar** array; + + org_sflphone_SFLphone_ConfigurationManager_get_addressbook_list (configurationManagerProxy, &array, &error); + if (error){ + g_print ("Error calling org_sflphone_SFLphone_ConfigurationManager_get_addressbook_list\n"); + g_error_free (error); + } + + return array; +} + +void dbus_set_addressbook_list (const gchar** list){ + + GError *error = NULL; + + org_sflphone_SFLphone_ConfigurationManager_set_addressbook_list(configurationManagerProxy, list, &error); + if (error){ + g_print ("Error calling org_sflphone_SFLphone_ConfigurationManager_set_addressbook_list\n"); + g_error_free (error); + } +} + GHashTable* dbus_get_hook_settings (void) { GError *error = NULL; diff --git a/sflphone-gtk/src/dbus/dbus.h b/sflphone-gtk/src/dbus/dbus.h index be66278b30e6daee13bd4308a372be68a53c1859..220e0557336c0f854d4c887e31994b71d9950692 100644 --- a/sflphone-gtk/src/dbus/dbus.h +++ b/sflphone-gtk/src/dbus/dbus.h @@ -458,6 +458,10 @@ GHashTable* dbus_get_addressbook_settings (void); */ void dbus_set_addressbook_settings (GHashTable *); +gchar** dbus_get_addressbook_list (void); + +void dbus_set_addressbook_list (const gchar** list); + /** * Encapsulate all the url hook-related configuration * Get the configuration diff --git a/src/dbus/configurationmanager.cpp b/src/dbus/configurationmanager.cpp index 8411f30dc1f45630a946776b16b46316f937d115..a82eaf1d7c946ae244871f8217b2f72b7e5dd056 100644 --- a/src/dbus/configurationmanager.cpp +++ b/src/dbus/configurationmanager.cpp @@ -439,6 +439,7 @@ std::vector< std::string > ConfigurationManager::getAddressbookList ( void ) { } void ConfigurationManager::setAddressbookList( const std::vector< std::string >& list ) { + _debug("Manager received setAddressbookList") ; Manager::instance().setAddressbookList(list); }