Skip to content
Snippets Groups Projects
Commit 6e15ff5a authored by Julien Bonjean's avatar Julien Bonjean
Browse files

Cleaning

parent fcb969ed
No related branches found
No related tags found
No related merge requests found
...@@ -208,7 +208,6 @@ toggle_contacts(GtkToggleToolButton *toggle_tool_button UNUSED, ...@@ -208,7 +208,6 @@ toggle_contacts(GtkToggleToolButton *toggle_tool_button UNUSED,
GtkTreeSelection *sel; GtkTreeSelection *sel;
GList *results; GList *results;
GList *i; GList *i;
char ext[30];
printf("EDS : %s\n",gtk_entry_get_text(GTK_ENTRY(filter_entry))); printf("EDS : %s\n",gtk_entry_get_text(GTK_ENTRY(filter_entry)));
...@@ -234,11 +233,7 @@ toggle_contacts(GtkToggleToolButton *toggle_tool_button UNUSED, ...@@ -234,11 +233,7 @@ toggle_contacts(GtkToggleToolButton *toggle_tool_button UNUSED,
call_t * call; call_t * call;
call = g_new0 (call_t, 1); call = g_new0 (call_t, 1);
call->accountID = g_strdup("Account:1235677223"); call->from = g_strconcat("\"" , entry->name, "\"<", entry->phone, ">", NULL);
call->callID = g_new0(gchar, 30);
g_sprintf(call->callID, "%d", rand());
sprintf(ext, "%d", rand()%100 + 100);
call->from = g_strconcat("\"" , entry->text, "\"<", ext, ">", NULL);
call->state = CALL_STATE_RECORD; call->state = CALL_STATE_RECORD;
call->history_state = OUTGOING; call->history_state = OUTGOING;
......
...@@ -5,67 +5,16 @@ ...@@ -5,67 +5,16 @@
#include <string.h> #include <string.h>
#include "eds.h" #include "eds.h"
typedef struct _Handler_And_Data {
SearchAsyncHandler handler;
gpointer user_data;
GList *hits;
int max_results_remaining;
int book_views_remaining;
} Handler_And_Data;
static GSList *books = NULL; static GSList *books = NULL;
static int pixbuf_size = 16;
static EContactField search_fields[] = { E_CONTACT_FULL_NAME, E_CONTACT_EMAIL, E_CONTACT_NICKNAME, 0 }; static EContactField search_fields[] = { E_CONTACT_FULL_NAME, E_CONTACT_PHONE_BUSINESS, E_CONTACT_NICKNAME, 0 };
static int n_search_fields = G_N_ELEMENTS (search_fields) - 1; static int n_search_fields = G_N_ELEMENTS (search_fields) - 1;
/*
int
main (int argc, char *argv[])
{
GList *results;
GList *i;
gtk_init (&argc, &argv);
init();
results = search_sync ("sch", 50);
if(results == NULL)
{
printf("null\n");
return -1;
}
for (i = results; i != NULL; i = i->next)
{
Hit *entry;
entry = i->data;
printf("entree\n");
if (i->data) {
printf("email : %s\n", entry->email);
printf("text : %s\n", entry->text);
}
}
printf("fini\n");
return 0;
}
*/
void void
free_hit (Hit *h, gpointer unused) free_hit (Hit *h, gpointer unused)
{ {
g_free (h->text); g_free (h->name);
g_free (h->email); g_free (h->phone);
g_free (h->uri);
g_free (h); g_free (h);
} }
...@@ -136,103 +85,6 @@ create_query (const char* s) ...@@ -136,103 +85,6 @@ create_query (const char* s)
return query; return query;
} }
static GdkPixbuf*
pixbuf_from_contact (EContact *contact)
{
GdkPixbuf *pixbuf = NULL;
EContactPhoto *photo = e_contact_get (contact, E_CONTACT_PHOTO);
if (photo) {
GdkPixbufLoader *loader;
loader = gdk_pixbuf_loader_new ();
if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
if (gdk_pixbuf_loader_write (loader, (guchar *) photo->data.inlined.data, photo->data.inlined.length, NULL))
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
}
if (pixbuf) {
GdkPixbuf *tmp;
gint width = gdk_pixbuf_get_width (pixbuf);
gint height = gdk_pixbuf_get_height (pixbuf);
double scale = 1.0;
if (height > width) {
scale = pixbuf_size / (double) height;
} else {
scale = pixbuf_size / (double) width;
}
if (scale < 1.0) {
tmp = gdk_pixbuf_scale_simple (pixbuf, width * scale, height * scale, GDK_INTERP_BILINEAR);
g_object_unref (pixbuf);
pixbuf = tmp;
}
}
e_contact_photo_free (photo);
}
return pixbuf;
}
static void
view_finish (EBookView *book_view, Handler_And_Data *had)
{
SearchAsyncHandler had_handler = had->handler;
GList *had_hits = had->hits;
gpointer had_user_data = had->user_data;
g_free (had);
g_return_if_fail (book_view != NULL);
g_object_unref (book_view);
had_handler (had_hits, had_user_data);
}
static void
view_contacts_added_cb (EBookView *book_view, GList *contacts, gpointer user_data)
{
Handler_And_Data *had = (Handler_And_Data *) user_data;
if (had->max_results_remaining <= 0) {
e_book_view_stop (book_view);
had->book_views_remaining--;
if (had->book_views_remaining == 0) {
view_finish (book_view, had);
return;
}
}
for (; contacts != NULL; contacts = g_list_next (contacts)) {
EContact *contact;
Hit *hit;
contact = E_CONTACT (contacts->data);
hit = g_new (Hit, 1);
hit->email = g_strdup ((char*) e_contact_get_const (contact, E_CONTACT_EMAIL_1));
hit->text = g_strdup_printf ("%s <%s>", (char*)e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG), hit->email);
hit->pixbuf = pixbuf_from_contact (contact);
had->hits = g_list_append (had->hits, hit);
had->max_results_remaining--;
if (had->max_results_remaining <= 0) {
e_book_view_stop (book_view);
had->book_views_remaining--;
if (had->book_views_remaining == 0) {
view_finish (book_view, had);
}
break;
}
}
}
static void
view_completed_cb (EBookView *book_view, EBookViewStatus status, gpointer user_data)
{
Handler_And_Data *had = (Handler_And_Data *) user_data;
had->book_views_remaining--;
if (had->book_views_remaining == 0) {
view_finish (book_view, had);
}
}
void void
init (void) init (void)
{ {
...@@ -251,12 +103,6 @@ init (void) ...@@ -251,12 +103,6 @@ init (void)
sources = e_source_group_peek_sources (group); sources = e_source_group_peek_sources (group);
for (m = sources; m != NULL; m = m->next) { for (m = sources; m != NULL; m = m->next) {
ESource *source = m->data; ESource *source = m->data;
const char *p;
/*p = e_source_get_property (source, "completion");*/
/*if (p != NULL && strcmp (p, "true") == 0) {*/
if (1) {
EBook *book = e_book_new (source, NULL); EBook *book = e_book_new (source, NULL);
if (book != NULL) { if (book != NULL) {
books = g_slist_prepend (books, book); books = g_slist_prepend (books, book);
...@@ -264,90 +110,10 @@ init (void) ...@@ -264,90 +110,10 @@ init (void)
} }
} }
} }
}
g_object_unref (source_list); g_object_unref (source_list);
} }
int
num_address_books_with_completion (void)
{
int result = 0;
GSList *list, *l;
ESourceList *source_list;
source_list = e_source_list_new_for_gconf_default ("/apps/evolution/addressbook/sources");
if (source_list == NULL) {
return 0;
}
list = e_source_list_peek_groups (source_list);
for (l = list; l != NULL; l = l->next) {
ESourceGroup *group = l->data;
GSList *sources = NULL, *m;
sources = e_source_group_peek_sources (group);
for (m = sources; m != NULL; m = m->next) {
ESource *source = m->data;
const char *p;
p = e_source_get_property (source, "completion");
if (p != NULL && strcmp (p, "true") == 0) {
result++;
}
}
}
g_object_unref (source_list);
return result;
}
void
set_pixbuf_size (int size)
{
pixbuf_size = size;
}
void
search_async (const char *query,
int max_results,
SearchAsyncHandler handler,
gpointer user_data)
{
GSList *iter;
EBookQuery* book_query = create_query (query);
Handler_And_Data *had = g_new (Handler_And_Data, 1);
had->handler = handler;
had->user_data = user_data;
had->hits = NULL;
had->max_results_remaining = max_results;
had->book_views_remaining = 0;
for (iter = books; 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) {
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) {
g_free (had);
}
e_book_query_unref (book_query);
}
/*
* Note: you may get a message "WARNING **: FIXME: wait for completion unimplemented"
* if you call search_sync but are not running the gobject main loop.
* This appears to be harmless: http://bugzilla.gnome.org/show_bug.cgi?id=314544
*/
GList * GList *
search_sync (const char *query, search_sync (const char *query,
int max_results) int max_results)
...@@ -355,6 +121,7 @@ search_sync (const char *query, ...@@ -355,6 +121,7 @@ search_sync (const char *query,
GSList *iter = NULL; GSList *iter = NULL;
GList *contacts = NULL; GList *contacts = NULL;
GList *hits = NULL; GList *hits = NULL;
char ext[30];
EBookQuery* book_query = create_query (query); EBookQuery* book_query = create_query (query);
for (iter = books; iter != NULL; iter = iter->next) { for (iter = books; iter != NULL; iter = iter->next) {
...@@ -366,30 +133,22 @@ search_sync (const char *query, ...@@ -366,30 +133,22 @@ search_sync (const char *query,
for (; contacts != NULL; contacts = g_list_next (contacts)) { for (; contacts != NULL; contacts = g_list_next (contacts)) {
EContact *contact; EContact *contact;
Hit *hit; Hit *hit;
const char *uid;
ESource *source;
const char *source_uid;
contact = E_CONTACT (contacts->data); contact = E_CONTACT (contacts->data);
hit = g_new (Hit, 1); hit = g_new (Hit, 1);
if (e_contact_get (contact, E_CONTACT_IS_LIST)){
GList *emailList = e_contact_get (contact, E_CONTACT_EMAIL); hit->phone = g_strdup ((char*) e_contact_get_const (contact, E_CONTACT_PHONE_BUSINESS));
int i=0; if(! hit->phone)
hit->email = (gchar*)g_list_nth(emailList,i)->data; {
for (i=1; g_list_nth(emailList,i) != NULL; i++) // Temporary fix for empty phone numbers
hit->email = g_strjoin(",",hit->email,((gchar*)g_list_nth(emailList,i)->data), NULL); sprintf(ext, "%d", rand()%100 + 100);
g_list_foreach(emailList, (GFunc)g_free, NULL); hit->phone = g_strdup(ext);
g_list_free(emailList); //hit->phone = "";
} }
else
hit->email = g_strdup ((char*) e_contact_get_const (contact, E_CONTACT_EMAIL_1));
hit->text = g_strdup ((char*) e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG));
hit->pixbuf = pixbuf_from_contact (contact);
uid = e_contact_get_const (contact, E_CONTACT_UID); hit->name = g_strdup ((char*) e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG));
source = e_book_get_source (book); if(! hit->name)
source_uid = e_source_peek_uid (source); hit->name = "";
hit->uri = g_strdup_printf ("contacts:///?source-uid=%s&contact-uid=%s", source_uid, uid);
hits = g_list_append (hits, hit); hits = g_list_append (hits, hit);
max_results--; max_results--;
......
...@@ -8,25 +8,14 @@ ...@@ -8,25 +8,14 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _Hit { typedef struct _Hit {
gchar *text; gchar *name;
gchar *email; gchar *phone;
GdkPixbuf *pixbuf;
gchar *uri;
} Hit; } Hit;
void free_hit (Hit *hit, gpointer unused); void free_hit (Hit *hit, gpointer unused);
typedef void (* SearchAsyncHandler) (GList *hits, gpointer user_data);
void init (void); void init (void);
void set_pixbuf_size (int size);
void search_async (const char *query,
int max_results,
SearchAsyncHandler handler,
gpointer user_data);
GList * search_sync (const char *query, GList * search_sync (const char *query,
int max_results); int max_results);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment