Skip to content
Snippets Groups Projects
Commit 91aa221f authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#4637] Fix opening default addressbook at sflphone init

parent 27b7c910
Branches
Tags
No related merge requests found
...@@ -133,7 +133,7 @@ addressbook_get_books_data() ...@@ -133,7 +133,7 @@ addressbook_get_books_data()
fill_books_data(); fill_books_data();
addressbook_config_books(); addressbook_config_books();
return books_data; return get_books_data();
} }
/** /**
......
...@@ -64,6 +64,8 @@ static int pixbuf_size = 32; ...@@ -64,6 +64,8 @@ static int pixbuf_size = 32;
*/ */
int remaining_books_to_open; int remaining_books_to_open;
GSList *books_data = NULL;
/** /**
* Current selected addressbook's uri and uid, initialized with default * Current selected addressbook's uri and uid, initialized with default
*/ */
...@@ -451,65 +453,27 @@ eds_async_open_callback (EBook *book, EBookStatus status, gpointer closure) ...@@ -451,65 +453,27 @@ eds_async_open_callback (EBook *book, EBookStatus status, gpointer closure)
void void
init () init ()
{ {
GError *err = NULL; GSList *book_list_iterator;
gchar *absuri, *reluri; book_data_t *book_data;
EBook *default_addressbook = e_book_new_default_addressbook (&err);
if (err)
ERROR ("Addressbook: Error: Could not create new book from source: %s", err->message);
ESource *default_source = e_book_get_source (default_addressbook);
// DEBUG ("Addressbook: Default source relative uri %s", e_source_peek_relative_uri (default_source)); DEBUG ("Addressbook: Init default addressbook");
// DEBUG ("Addressbook: Default source absolute uri %s", e_source_peek_absolute_uri (default_source));
if (current_uri) { if (books_data == NULL) {
g_free (current_uri); DEBUG ("Addressbook: No books data (%s:%d)", __FILE__, __LINE__);
current_uri = NULL; return;
}
if (current_uid) {
g_free (current_uid);
current_uid = NULL;
}
if (strcmp (current_name, "Default") != 0) {
g_free (current_name);
current_name = NULL;
} }
// TODO: This should work but return a NULL pointer ... // Iterate throw the list
// if (! (group = e_source_peek_group (default_source))); for (book_list_iterator = books_data; book_list_iterator != NULL;
book_list_iterator = book_list_iterator->next) {
// ERROR ("Addressbook: Error: No group found for default addressbook"); book_data = (book_data_t *) book_list_iterator->data;
absuri = g_strdup (e_source_peek_absolute_uri (default_source));
// absuri = g_strdup (e_source_group_peek_base_uri (group));
reluri = g_strdup (e_source_peek_relative_uri (default_source));
if (!absuri) { if (book_data->isdefault) {
absuri = g_malloc (1); current_uri = book_data->uri;
*absuri = 0; current_uid = book_data->uid;
current_name = book_data->name;
} }
if (!reluri) {
reluri = g_malloc (1);
*reluri = 0;
} }
// Do not overwrite current_name for default
// current_name = g_strdup (e_source_peek_name (default_source));
current_uid = g_strdup (e_source_peek_uid (default_source));
if (strcmp (absuri+strlen (absuri)-1, "/") == 0)
current_uri = g_strjoin ("", absuri, reluri, NULL);
else
current_uri = g_strjoin ("/", absuri, reluri, NULL);
g_free (absuri);
g_free (reluri);
} }
...@@ -522,7 +486,7 @@ fill_books_data () ...@@ -522,7 +486,7 @@ fill_books_data ()
GSList *list, *l; GSList *list, *l;
ESourceList *source_list = NULL; ESourceList *source_list = NULL;
remaining_books_to_open = 0; remaining_books_to_open = 0;
books_data = NULL; gboolean default_found;
source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources"); source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources");
...@@ -538,14 +502,14 @@ fill_books_data () ...@@ -538,14 +502,14 @@ fill_books_data ()
return; return;
} }
// in case default property is not set for any addressbook
default_found = FALSE;
for (l = list; l != NULL; l = l->next) { for (l = list; l != NULL; l = l->next) {
ESourceGroup *group = l->data; ESourceGroup *group = l->data;
GSList *sources = NULL, *m; GSList *sources = NULL, *m;
gchar *absuri; gchar *absuri = g_strdup (e_source_group_peek_base_uri (group));
absuri = g_strdup (e_source_group_peek_base_uri (group));
sources = e_source_group_peek_sources (group); sources = e_source_group_peek_sources (group);
...@@ -561,12 +525,13 @@ fill_books_data () ...@@ -561,12 +525,13 @@ fill_books_data ()
const gchar *property_name = "default"; const gchar *property_name = "default";
const gchar *prop = e_source_get_property (source, property_name); const gchar *prop = e_source_get_property (source, property_name);
if (prop) if (prop) {
if (strcmp (prop, "true") == 0) if (strcmp (prop, "true") == 0) {
book_data->isdefault = TRUE; book_data->isdefault = TRUE;
else default_found = TRUE;
} else
book_data->isdefault = FALSE; book_data->isdefault = FALSE;
else } else
book_data->isdefault = FALSE; book_data->isdefault = FALSE;
if (strcmp (absuri+strlen (absuri)-1, "/") == 0) if (strcmp (absuri+strlen (absuri)-1, "/") == 0)
...@@ -581,6 +546,12 @@ fill_books_data () ...@@ -581,6 +546,12 @@ fill_books_data ()
g_free (absuri); g_free (absuri);
} }
if (!default_found) {
DEBUG ("Addressbook: No default addressbook found, using first addressbook as default");
book_data_t *book_data = g_slist_nth_data (books_data, 0);
book_data->isdefault = TRUE;
}
g_object_unref (source_list); g_object_unref (source_list);
} }
...@@ -662,7 +633,7 @@ set_current_addressbook (const gchar *name) ...@@ -662,7 +633,7 @@ set_current_addressbook (const gchar *name)
if (!books_data) { if (!books_data) {
DEBUG ("Addressbook: No books data (%s:%d)", __FILE__, __LINE__); DEBUG ("Addressbook: No books data (%s:%d)", __FILE__, __LINE__);
return NULL; return;
} }
// Iterate throw the list // Iterate throw the list
...@@ -697,3 +668,9 @@ get_current_addressbook_test (void) ...@@ -697,3 +668,9 @@ get_current_addressbook_test (void)
{ {
return current_test; return current_test;
} }
GSList *
get_books_data()
{
return books_data;
}
...@@ -76,7 +76,6 @@ typedef struct { ...@@ -76,7 +76,6 @@ typedef struct {
gboolean isdefault; gboolean isdefault;
} book_data_t; } book_data_t;
GSList *books_data;
/** /**
* Free a contact entry * Free a contact entry
...@@ -164,6 +163,9 @@ set_current_addressbook_test (EBookQueryTest test); ...@@ -164,6 +163,9 @@ set_current_addressbook_test (EBookQueryTest test);
EBookQueryTest EBookQueryTest
get_current_addressbook_test (void); get_current_addressbook_test (void);
GSList *
get_books_data();
G_END_DECLS G_END_DECLS
......
...@@ -77,6 +77,8 @@ static void cbox_changed_cb (GtkWidget *widget, gpointer user_data UNUSED) ...@@ -77,6 +77,8 @@ static void cbox_changed_cb (GtkWidget *widget, gpointer user_data UNUSED)
{ {
gchar *name; gchar *name;
DEBUG ("Searchbar: CBOX changed callback");
name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget)); name = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
set_current_addressbook (name); set_current_addressbook (name);
...@@ -93,6 +95,8 @@ void update_searchbar_addressbook_list() ...@@ -93,6 +95,8 @@ void update_searchbar_addressbook_list()
book_data_t *book_data; book_data_t *book_data;
GSList *books_data = addressbook_get_books_data(); GSList *books_data = addressbook_get_books_data();
DEBUG ("Searchbar: Update addressbook list");
// we must disconnect signal from teh cbox while updating its content // we must disconnect signal from teh cbox while updating its content
gtk_signal_disconnect (cbox, cboxSignalId); gtk_signal_disconnect (cbox, cboxSignalId);
...@@ -365,6 +369,9 @@ GtkWidget* contacts_searchbar_new () ...@@ -365,6 +369,9 @@ GtkWidget* contacts_searchbar_new ()
int count, cbox_height, cbox_width; int count, cbox_height, cbox_width;
GtkTreeIter iter, activeIter; GtkTreeIter iter, activeIter;
GtkCellRenderer *cell; GtkCellRenderer *cell;
// gchar *current_addressbook = NULL;
DEBUG ("Addressbook: Create addressbook search bar");
ret = gtk_hbox_new (FALSE, 0); ret = gtk_hbox_new (FALSE, 0);
...@@ -380,13 +387,14 @@ GtkWidget* contacts_searchbar_new () ...@@ -380,13 +387,14 @@ GtkWidget* contacts_searchbar_new ()
count = 0; count = 0;
gboolean activeIsSet = FALSE; gboolean activeIsSet = FALSE;
for (book_list_iterator = books_data; book_list_iterator != NULL; book_list_iterator for (book_list_iterator = books_data; book_list_iterator != NULL;
= book_list_iterator->next) { book_list_iterator = book_list_iterator->next) {
book_data = (book_data_t *) book_list_iterator->data; book_data = (book_data_t *) book_list_iterator->data;
if (book_data->active) { if (book_data->active) {
gtk_list_store_append (liststore, &iter); gtk_list_store_append (liststore, &iter);
gtk_list_store_set (liststore, &iter, 0, book_data->name, -1); gtk_list_store_set (liststore, &iter, 0, book_data->name, -1);
if (book_data->isdefault) { if (book_data->isdefault) {
...@@ -398,6 +406,8 @@ GtkWidget* contacts_searchbar_new () ...@@ -398,6 +406,8 @@ GtkWidget* contacts_searchbar_new ()
} }
} }
// current_addressbook = get_current_addressbook();
cbox = gtk_combo_box_new_with_model ( (GtkTreeModel *) liststore); cbox = gtk_combo_box_new_with_model ( (GtkTreeModel *) liststore);
if (activeIsSet) if (activeIsSet)
...@@ -413,11 +423,14 @@ GtkWidget* contacts_searchbar_new () ...@@ -413,11 +423,14 @@ GtkWidget* contacts_searchbar_new ()
gtk_widget_set_size_request (GTK_WIDGET (cbox), cbox_width, 26); gtk_widget_set_size_request (GTK_WIDGET (cbox), cbox_width, 26);
cboxSignalId = gtk_signal_connect (GTK_OBJECT (cbox), "changed", G_CALLBACK (cbox_changed_cb), NULL); cboxSignalId = gtk_signal_connect (GTK_OBJECT (cbox), "changed", G_CALLBACK (cbox_changed_cb), NULL);
// cbox_changed_cb (GTK_WIDGET (cbox), NULL);
cell = gtk_cell_renderer_text_new(); cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbox), cell, TRUE); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbox), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbox), cell, "text", 0, NULL); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbox), cell, "text", 0, NULL);
#if GTK_CHECK_VERSION(2,16,0) #if GTK_CHECK_VERSION(2,16,0)
// GdkPixbuf *pixbuf; // GdkPixbuf *pixbuf;
...@@ -464,6 +477,10 @@ GtkWidget* contacts_searchbar_new () ...@@ -464,6 +477,10 @@ GtkWidget* contacts_searchbar_new ()
g_free (tooltip_text); g_free (tooltip_text);
// current_addressbook = gtk_combo_box_get_active_text (GTK_COMBO_BOX (cbox));
// set_current_addressbook (current_addressbook);
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment