From 4ec27bb165e706955713f4dae81be1c6b67d4eba Mon Sep 17 00:00:00 2001
From: Julien Bonjean <julien@bonjean.info>
Date: Mon, 2 Mar 2009 15:01:24 -0500
Subject: [PATCH] Fixed contact list refresh, added icon

---
 sflphone-gtk/pixmaps/contacts.svg |  99 +++++++++++++++++++++++++++++
 sflphone-gtk/src/actions.c        |   2 +
 sflphone-gtk/src/calllist.c       |  42 ++++++------
 sflphone-gtk/src/calltree.c       | 102 ++++++++++--------------------
 sflphone-gtk/src/calltree.h       |   2 +
 5 files changed, 159 insertions(+), 88 deletions(-)
 create mode 100644 sflphone-gtk/pixmaps/contacts.svg

diff --git a/sflphone-gtk/pixmaps/contacts.svg b/sflphone-gtk/pixmaps/contacts.svg
new file mode 100644
index 0000000000..5574fc0166
--- /dev/null
+++ b/sflphone-gtk/pixmaps/contacts.svg
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:xlink="http://www.w3.org/1999/xlink"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   id="svg2"
+   sodipodi:version="0.32"
+   inkscape:version="0.46"
+   width="22"
+   height="22"
+   version="1.0"
+   sodipodi:docname="contacts.svg"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape">
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <defs
+     id="defs5">
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       id="perspective9" />
+  </defs>
+  <sodipodi:namedview
+     inkscape:window-height="684"
+     inkscape:window-width="640"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     guidetolerance="10.0"
+     gridtolerance="10.0"
+     objecttolerance="10.0"
+     borderopacity="1.0"
+     bordercolor="#666666"
+     pagecolor="#ffffff"
+     id="base"
+     showgrid="false"
+     inkscape:zoom="21"
+     inkscape:cx="11"
+     inkscape:cy="11"
+     inkscape:window-x="1445"
+     inkscape:window-y="50"
+     inkscape:current-layer="svg2" />
+  <image
+     xlink:href="contacts.png"
+     sodipodi:absref="/home/jbonjean/img/contacts.png"
+     width="22"
+     height="22"
+     id="image11"
+     x="0"
+     y="0" />
+  <g
+     id="g2402">
+    <path
+       style="fill:#9dccf4"
+       d="M 0.2521834,15.5 C 0.24108402,13.3 0.43678756,12.282253 0.68708016,13.238341 C 0.93737277,14.194428 0.94645408,15.994428 0.70726087,17.238341 C 0.46806765,18.482253 0.26328279,17.7 0.2521834,15.5 z M 5,12 C 5,11.45 5.45,11 6,11 C 6.55,11 7,11.45 7,12 C 7,12.55 6.55,13 6,13 C 5.45,13 5,12.55 5,12 z M 15,6 C 15,5.45 13.7625,4.9644737 12.25,4.9210526 C 10.7375,4.8776316 10.081811,4.6086947 10.792913,4.323415 C 12.573354,3.6091382 17,4.8183986 17,6.019052 C 17,6.5585734 16.55,7 16,7 C 15.45,7 15,6.55 15,6 z M 1,3.8613281 C 1,3.3875977 2.125,3 3.5,3 C 6.7094136,3 6.7094136,3.6312327 3.5,4.244751 C 2.125,4.5075989 1,4.3350586 1,3.8613281 z M 9.25,2.2837456 C 10.7625,2.0546209 13.2375,2.0546209 14.75,2.2837456 C 16.2625,2.5128702 15.025,2.7003358 12,2.7003358 C 8.975,2.7003358 7.7375,2.5128702 9.25,2.2837456 z"
+       id="path2416" />
+    <path
+       style="fill:#58a2e8"
+       d="M 1,12.626405 C 1,8.4968008 1.4576322,4.8352017 2.0169604,4.4895179 C 3.9027007,3.3240663 19.468558,2.1368069 20.45,3.083569 C 21.02965,3.6427365 19.177899,4 15.7,4 L 10,4 L 10,10.980948 C 10,17.781498 9.928936,17.977711 7.25,18.573893 C 5.7375,18.910491 3.7125,19.399389 2.75,19.660333 C 1.1965898,20.081478 1,19.291307 1,12.626405 z M 9,9.3865006 C 9,5.0400237 8.968065,5 5.5,5 C 2.0384615,5 2,5.047619 2,9.3333333 C 2,14.558033 2.1770643,14.774396 5.9943091,14.214143 C 8.8113757,13.800685 9,13.497723 9,9.3865006 z M 20.078947,11.583333 C 20.035526,10.529167 20.271875,9.9385417 20.604167,10.270833 C 20.936458,10.603125 20.971985,11.465625 20.683114,12.1875 C 20.363888,12.985233 20.126931,12.748276 20.078947,11.583333 z"
+       id="path2414" />
+    <path
+       style="fill:#9c9c9d"
+       d="M 18,21.059017 C 18,20.476558 18.45,20 19,20 C 19.55,20 20,20.198442 20,20.440983 C 20,20.683524 19.55,21.160081 19,21.5 C 18.45,21.839919 18,21.641476 18,21.059017 z M 18.570027,16.113307 C 18.268624,15.625626 18.804566,14.613126 19.76101,13.863307 C 21.297177,12.659006 21.355221,12.68568 20.258676,14.092009 C 19.575948,14.967614 19.313448,15.980114 19.675343,16.342009 C 20.037238,16.703904 20.059891,17 19.725684,17 C 19.391476,17 18.871431,16.600988 18.570027,16.113307 z M 13.75,13.337719 C 14.4375,13.060307 15.5625,13.060307 16.25,13.337719 C 16.9375,13.615132 16.375,13.842105 15,13.842105 C 13.625,13.842105 13.0625,13.615132 13.75,13.337719 z M 15.270833,8.3958333 C 15.603125,8.0635417 16.465625,8.0280154 17.1875,8.316886 C 17.985233,8.6361123 17.748276,8.8730687 16.583333,8.9210526 C 15.529167,8.9644737 14.938542,8.728125 15.270833,8.3958333 z M 11.75,6.3377193 C 12.4375,6.060307 13.5625,6.060307 14.25,6.3377193 C 14.9375,6.6151316 14.375,6.8421053 13,6.8421053 C 11.625,6.8421053 11.0625,6.6151316 11.75,6.3377193 z M 17.270833,5.3958333 C 17.603125,5.0635417 18.465625,5.0280154 19.1875,5.316886 C 19.985233,5.6361123 19.748276,5.8730687 18.583333,5.9210526 C 17.529167,5.9644737 16.938542,5.728125 17.270833,5.3958333 z"
+       id="path2412" />
+    <path
+       style="fill:#d99e37"
+       d="M 4.6875,10.354167 C 3.3834011,9.0500678 4.0060077,8 6.0833333,8 C 7.247076,8 7.9919444,8.5241667 7.7708333,9.1875 C 7.283719,10.648843 5.6139723,11.280639 4.6875,10.354167 z"
+       id="path2410" />
+    <path
+       style="fill:#6a6c6f"
+       d="M 13.730968,21.344063 C 14.408001,21.07014 15.758001,21.053466 16.730968,21.307009 C 17.703936,21.560553 17.15,21.784672 15.5,21.805051 C 13.85,21.825431 13.053936,21.617986 13.730968,21.344063 z M 5.2708333,19.395833 C 5.603125,19.063542 6.465625,19.028015 7.1875,19.316886 C 7.9852327,19.636112 7.7482763,19.873069 6.5833333,19.921053 C 5.5291667,19.964474 4.9385417,19.728125 5.2708333,19.395833 z M 19.575839,18 C 19.952889,16.625 20.581769,12.575 20.973351,9 L 21.685316,2.5 L 21.842658,8.1351902 C 21.935064,11.444713 21.358305,15.159052 20.445147,17.13519 C 19.509398,19.160216 19.163261,19.504562 19.575839,18 z M 13.75,14.337719 C 14.4375,14.060307 15.5625,14.060307 16.25,14.337719 C 16.9375,14.615132 16.375,14.842105 15,14.842105 C 13.625,14.842105 13.0625,14.615132 13.75,14.337719 z"
+       id="path2408" />
+    <path
+       style="fill:#1364be"
+       d="M 13.201803,17.543564 C 11.626143,14.085366 11.723875,13.052161 13.415695,15.282342 C 14.680186,16.949212 14.937274,16.863258 17.383892,13.955617 C 18.822751,12.24563 19.987895,11.443576 19.973099,12.173275 C 19.958304,12.902974 18.699115,15.003278 17.174902,16.840617 L 14.403606,20.181234 L 13.201803,17.543564 z M 2,13.059017 C 2,11.361136 4.2025454,10.713671 5.1879344,12.121885 C 5.9336962,13.187649 6.2672199,13.216686 6.6594643,12.25 C 7.365864,10.509078 9,10.683626 9,12.5 C 9,13.547619 7.9444444,14 5.5,14 C 3.575,14 2,13.576558 2,13.059017 z"
+       id="path2406" />
+    <path
+       style="fill:#a36f02"
+       d="M 3,8.5 C 3,6.5 3.5,6 5.5,6 C 6.875,6 8,6.45 8,7 C 8,7.55 7.051855,8 5.8930112,8 C 4.4309749,8 3.9622157,8.4591523 4.3616264,9.5 C 4.6782086,10.325 4.5013536,11 3.9686152,11 C 3.4358768,11 3,9.875 3,8.5 z"
+       id="path2404" />
+  </g>
+</svg>
diff --git a/sflphone-gtk/src/actions.c b/sflphone-gtk/src/actions.c
index f66b2e922c..d3c26360d5 100644
--- a/sflphone-gtk/src/actions.c
+++ b/sflphone-gtk/src/actions.c
@@ -26,6 +26,7 @@
 #include <statusicon.h>
 #include <calltab.h>
 #include <historyfilter.h>
+#include <contactlist/eds.h>
 
 #include <gtk/gtk.h>
 #include <string.h>
@@ -234,6 +235,7 @@ gboolean sflphone_init()
 	  contacts = calltab_init();
 	  if(SHOW_SEARCHBAR)  histfilter = create_filter(GTK_TREE_MODEL(history->store));
 	  contactfilter = create_filter(GTK_TREE_MODEL(contacts->store));
+	  init();
 	  account_list_init ();
     codec_list_init();
 		sflphone_fill_account_list(FALSE);
diff --git a/sflphone-gtk/src/calllist.c b/sflphone-gtk/src/calllist.c
index c9629ad463..ce12521404 100644
--- a/sflphone-gtk/src/calllist.c
+++ b/sflphone-gtk/src/calllist.c
@@ -1,22 +1,22 @@
 /*
  *  Copyright (C) 2007 Savoir-Faire Linux inc.
  *  Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
- *                                                                              
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
- *                                                                                
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *                                                                              
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
- 
+
 #include <calllist.h>
 #include <calltree.h>
 #include <dbus.h>
@@ -29,7 +29,7 @@
  */
 
 /* GCompareFunc to compare a callID (gchar* and a call_t) */
-gint 
+gint
 is_callID_callstruct ( gconstpointer a, gconstpointer b)
 {
   call_t * c = (call_t*)a;
@@ -44,7 +44,7 @@ is_callID_callstruct ( gconstpointer a, gconstpointer b)
 }
 
 /* GCompareFunc to get current call (gchar* and a call_t) */
-gint 
+gint
 get_state_callstruct ( gconstpointer a, gconstpointer b)
 {
   call_t * c = (call_t*)a;
@@ -58,30 +58,30 @@ get_state_callstruct ( gconstpointer a, gconstpointer b)
   }
 }
 
-void 
+void
 call_list_init (calltab_t* tab)
 {
   tab->callQueue = g_queue_new ();
   tab->selectedCall = NULL;
 }
 
-void 
+void
 call_list_clean (calltab_t* tab)
 {
   g_queue_free (tab->callQueue);
 }
 
-void 
+void
 call_list_reset (calltab_t* tab)
 {
   g_queue_free (tab->callQueue);
   tab->callQueue = g_queue_new();
 }
 
-void 
+void
 call_list_add (calltab_t* tab, call_t * c)
 {
-  if( tab == history )	
+  if( tab == history )
   {
     // First case: can still add calls to the list
     if( call_list_get_size(tab) < dbus_get_max_calls() )
@@ -92,7 +92,7 @@ call_list_add (calltab_t* tab, call_t * c)
     // List full -> Remove the last call from history and preprend the new call to the list
     else
     {
-      update_call_tree_remove( history , (call_t*)g_queue_pop_head( tab -> callQueue ) );      
+      update_call_tree_remove( history , (call_t*)g_queue_pop_head( tab -> callQueue ) );
       g_queue_push_tail (tab->callQueue, (gpointer *) c);
       update_call_tree_add( history , c );
     }
@@ -126,7 +126,7 @@ call_list_remove_from_history( call_t* c )
   g_print("Size of history = %i\n" , call_list_get_size( history ));
 }
 
-void 
+void
 call_list_remove (calltab_t* tab, const gchar * callID)
 {
   call_t * c = call_list_get(tab, callID);
@@ -137,7 +137,7 @@ call_list_remove (calltab_t* tab, const gchar * callID)
 }
 
 
-call_t * 
+call_t *
 call_list_get_by_state (calltab_t* tab, call_state_t state )
 {
   GList * c = g_queue_find_custom (tab->callQueue, &state, get_state_callstruct);
@@ -145,11 +145,11 @@ call_list_get_by_state (calltab_t* tab, call_state_t state )
   {
     return (call_t *)c->data;
   }
-  else 
+  else
   {
     return NULL;
   }
-  
+
 }
 
 guint
@@ -158,13 +158,13 @@ call_list_get_size (calltab_t* tab)
   return g_queue_get_length (tab->callQueue);
 }
 
-call_t * 
+call_t *
 call_list_get_nth (calltab_t* tab, guint n )
 {
   return g_queue_peek_nth (tab->callQueue, n);
 }
 
-gchar * 
+gchar *
 call_get_name (const call_t * c)
 {
   gchar * end = g_strrstr(c->from, "\"");
@@ -176,7 +176,7 @@ call_get_name (const call_t * c)
   }
 }
 
-gchar * 
+gchar *
 call_get_number (const call_t * c)
 {
   gchar * number = g_strrstr(c->from, "<") + 1;
@@ -192,7 +192,7 @@ call_get_recipient( const call_t * c )
 }
 
 
-call_t * 
+call_t *
 call_list_get (calltab_t* tab, const gchar * callID )
 {
   GList * c = g_queue_find_custom (tab->callQueue, callID, is_callID_callstruct);
@@ -200,7 +200,7 @@ call_list_get (calltab_t* tab, const gchar * callID )
   {
     return (call_t *)c->data;
   }
-  else 
+  else
   {
     return NULL;
   }
diff --git a/sflphone-gtk/src/calltree.c b/sflphone-gtk/src/calltree.c
index 1b4dcc9d73..30ea069130 100644
--- a/sflphone-gtk/src/calltree.c
+++ b/sflphone-gtk/src/calltree.c
@@ -180,17 +180,11 @@ toggle_history(GtkToggleToolButton *toggle_tool_button UNUSED,
 {
 	GtkTreeSelection *sel;
 
-	if(history_shown){
-		active_calltree = current_calls;
-		gtk_widget_hide(history->tree);
-		gtk_widget_show(current_calls->tree);
-		history_shown = FALSE;
-	}else{
-		active_calltree = history;
-		gtk_widget_hide(current_calls->tree);
-		gtk_widget_show(history->tree);
-		history_shown = TRUE;
-	}
+  active_calltree = history;
+  gtk_widget_hide(current_calls->tree);
+  gtk_widget_hide(contacts->tree);
+  gtk_widget_show(history->tree);
+  history_shown = TRUE;
 
 	sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (active_calltree->view));
 	g_signal_emit_by_name(sel, "changed");
@@ -207,15 +201,19 @@ toggle_contacts(GtkToggleToolButton *toggle_tool_button UNUSED,
   GtkTreeSelection *sel;
   GList *results;
   GList *i;
+  char ext[30];
 
-  //gtk_init (&argc, &argv);
-  init();
-  results = search_sync ("s", 50);
+  // Reset previous results
+  call_list_reset(contacts);
+  reset_call_tree(contacts);
+
+  // Do a synchronized search
+  results = search_sync ("j", 50);
 
   if(results == NULL)
   {
-    printf("null\n");
-    return -1;
+    printf("No results\n");
+    return ;
   }
 
   for (i = results; i != NULL; i = i->next)
@@ -228,11 +226,10 @@ toggle_contacts(GtkToggleToolButton *toggle_tool_button UNUSED,
 
       call = g_new0 (call_t, 1);
       call->accountID = g_strdup("Account:1235677223");
-      //call->callID = g_strdup("468809080");
       call->callID = g_new0(gchar, 30);
       g_sprintf(call->callID, "%d", rand());
-      call->to = g_strdup("\"\" <66e>");
-      call->from = g_strconcat("\"\" <", entry->text , ">");
+      sprintf(ext, "%d", rand()%100 + 100);
+      call->from = g_strconcat("\"" , entry->text, "\"<", ext, ">", NULL);
       call->state = CALL_STATE_RECORD;
       call->history_state = OUTGOING;
 
@@ -240,44 +237,7 @@ toggle_contacts(GtkToggleToolButton *toggle_tool_button UNUSED,
       update_call_tree_add(contacts,call);
     }
   }
-  /*
-  call_t * call;
-
-  call = g_new0 (call_t, 1);
-  call->accountID = g_strdup("Account:1235677223");
-  call->callID = g_strdup("468809080");
-  call->callID = g_new0(gchar, 30);
-  g_sprintf(call->callID, "%d", rand());
-  call->from = g_strdup("\"\" <666>");
-  call->to = g_strdup("");
-  call->state = CALL_STATE_INCOMING;
-  call->history_state = INCOMING;
-*/
-
-  /*
-  call_list_add (contacts, call);
-  update_call_tree_add(contacts,call);
-*/
-
-
-
-  /*
-  g_queue_push_tail (calltree->callQueue, (gpointer *) call);
-  g_queue_push_tail (calltree->callQueue, (gpointer *) call);
-  */
-  /*
-  if(history_shown){
-    active_calltree = current_calls;
-    gtk_widget_hide(history->tree);
-    gtk_widget_show(current_calls->tree);
-    history_shown = FALSE;
-  }else{
-    active_calltree = history;
-    gtk_widget_hide(current_calls->tree);
-    gtk_widget_show(history->tree);
-    history_shown = TRUE;
-  }
-  */
+
   gtk_widget_hide(current_calls->tree);
   gtk_widget_hide(history->tree);
   gtk_widget_show(contacts->tree);
@@ -585,26 +545,22 @@ create_toolbar ()
   gtk_toolbar_insert(GTK_TOOLBAR(ret), GTK_TOOL_ITEM(transfertButton), -1);
 
   image = gtk_image_new_from_file( ICONS_DIR "/history2.svg");
-  historyButton = gtk_toggle_tool_button_new();
-  gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(historyButton), image);
+  historyButton = gtk_tool_button_new(image, _("History"));
 #if GTK_CHECK_VERSION(2,12,0)
   gtk_widget_set_tooltip_text(GTK_WIDGET(historyButton), _("History"));
 #endif
-  gtk_tool_button_set_label(GTK_TOOL_BUTTON(historyButton), _("History"));
-  g_signal_connect (G_OBJECT (historyButton), "toggled",
+  g_signal_connect (G_OBJECT (historyButton), "clicked",
       G_CALLBACK (toggle_history), NULL);
   gtk_toolbar_insert(GTK_TOOLBAR(ret), GTK_TOOL_ITEM(historyButton), -1);
   history_shown = FALSE;
   active_calltree = current_calls;
 
-  image = gtk_image_new_from_file( ICONS_DIR "/history2.svg");
-  contactButton = gtk_toggle_tool_button_new();
-  gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(contactButton), image);
+  image = gtk_image_new_from_file( ICONS_DIR "/contacts.svg");
+  contactButton = gtk_tool_button_new(image, _("Contacts"));
 #if GTK_CHECK_VERSION(2,12,0)
   gtk_widget_set_tooltip_text(GTK_WIDGET(contactButton), _("Contacts"));
 #endif
-  gtk_tool_button_set_label(GTK_TOOL_BUTTON(contactButton), _("Contacts"));
-  g_signal_connect (G_OBJECT (contactButton), "toggled",
+  g_signal_connect (G_OBJECT (contactButton), "clicked",
       G_CALLBACK (toggle_contacts), NULL);
   gtk_toolbar_insert(GTK_TOOLBAR(ret), GTK_TOOL_ITEM(contactButton), -1);
 
@@ -657,6 +613,15 @@ on_key_released (GtkWidget   *widget UNUSED,
   return TRUE;
 }
 
+/**
+ * Reset call tree
+ */
+  void
+reset_call_tree (calltab_t* tab)
+{
+  gtk_list_store_clear (tab->store);
+}
+
   void
 create_call_tree (calltab_t* tab)
 {
@@ -933,7 +898,10 @@ update_call_tree_add (calltab_t* tab, call_t * c)
 	g_warning("History - Should not happen!");
     }
     date = timestamp_get_call_date();
-    description = g_strconcat( date , description , NULL);
+    if(tab == contacts)
+      description = g_strconcat( description , NULL);
+    else
+      description = g_strconcat( date , description , NULL);
   }
 
   //Resize it
diff --git a/sflphone-gtk/src/calltree.h b/sflphone-gtk/src/calltree.h
index 7d8d70eef8..216f23f1fb 100644
--- a/sflphone-gtk/src/calltree.h
+++ b/sflphone-gtk/src/calltree.h
@@ -63,6 +63,8 @@ void update_call_tree (calltab_t* ct, call_t * c);
  */
 void update_call_tree_remove (calltab_t* ct, call_t * c);
 
+void reset_call_tree (calltab_t* tab);
+
 /**
  * Build the toolbar
  * @return GtkWidget* The toolbar
-- 
GitLab