Commit 26c0f2a9 authored by Emmanuel Milou's avatar Emmanuel Milou

[#1214] Save name/number, successfully load the history if no fields are empty

parent 5247b98c
......@@ -237,15 +237,13 @@ gboolean sflphone_init()
history = calltab_init("history");
account_list_init ();
codec_list_init();
// Fetch the configured accounts
sflphone_fill_account_list(FALSE);
// Fetch the audio codecs
sflphone_fill_codec_list();
// Fetch the history list
// sflphone_fill_history ();
return TRUE;
}
}
......@@ -939,6 +937,7 @@ void sflphone_fill_history (void)
g_hash_table_iter_init (&iter, entries);
while (g_hash_table_iter_next (&iter, &key, &value))
{
DEBUG ("%s\n", (gchar*)value);
/* do something with key and value */
create_history_entry_from_serialized_form ((gchar*)key, (gchar*)value, &history_entry);
// Add it and update the GUI
......
......@@ -126,13 +126,36 @@ void create_history_entry_from_serialized_form (gchar *timestamp, gchar *details
{
gchar *peer_name, *peer_number, *accountID, *state_str;
callable_obj_t *new_call;
history_state_t history_state;
char *ptr;
const char *delim="|";
int token=0;
// details is in serialized form, i e: calltype%to%from%callid
peer_name = g_strdup (details);
peer_number = g_strdup (details);
if ((ptr = strtok(details, delim)) != NULL) {
do {
switch (token)
{
case 0:
history_state = get_history_state_from_id (ptr);
break;
case 1:
peer_number = ptr;
break;
case 2:
peer_name = ptr;
break;
default:
break;
}
token ++;
} while ((ptr = strtok(NULL, delim)) != NULL);
}
create_new_call (HISTORY_ENTRY, CALL_STATE_DIALING, "", "", peer_name, peer_number, &new_call);
new_call->_history_state = MISSED;
new_call->_history_state = history_state;
*call = new_call;
}
......@@ -167,3 +190,19 @@ gchar* get_peer_info (gchar* number, gchar* name)
info = g_strconcat("\"", name, "\" <", number, ">", NULL);
return info;
}
history_state_t get_history_state_from_id (gchar *indice){
history_state_t state;
if (g_strcasecmp (indice, "0") ==0)
state = MISSED;
else if (g_strcasecmp (indice, "1") ==0)
state = INCOMING;
else if (g_strcasecmp (indice, "2") ==0)
state = OUTGOING;
else
state = MISSED;
return state;
}
......@@ -154,4 +154,6 @@ gchar* generate_call_id (void);
gchar* get_peer_info (gchar*, gchar*);
history_state_t get_history_state_from_id (gchar *indice);
#endif
......@@ -24,8 +24,8 @@
#define ITEM_SEPARATOR "|"
HistoryItem::HistoryItem (std::string timestamp, CallType call_type, std::string to, std::string from, std::string caller_id, std::string account_id)
: _timestamp (timestamp), _call_type (call_type), _to (to), _from (from), _caller_id (caller_id), _account_id (account_id)
HistoryItem::HistoryItem (std::string timestamp, CallType call_type, std::string name, std::string number, std::string account_id)
: _timestamp (timestamp), _call_type (call_type), _name (name), _number (number), _account_id (account_id)
{
}
......@@ -34,7 +34,7 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
: _timestamp (timestamp)
{
size_t pos;
std::string tmp, id, to, from, callerid;
std::string tmp, id, name, number;
int indice=0;
while (serialized_form.find(ITEM_SEPARATOR, 0) != std::string::npos)
......@@ -47,14 +47,11 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
case 0: // The call type
id = tmp;
break;
case 1: // The to field
to = tmp;
case 1: // The number field
number = tmp;
break;
case 2: // The from field
from = tmp;
break;
case 3: // The calller id information
callerid = tmp;
case 2: // The name field
name = tmp;
break;
default: // error
std::cout <<"[ERROR] unserialized form not recognized."<<std::endl;
......@@ -64,9 +61,8 @@ HistoryItem::HistoryItem (std::string timestamp, std::string serialized_form)
}
_call_type = (CallType)atoi (id.c_str());
_to = to;
_from = from;
_caller_id = serialized_form;
_number = number;
_name = serialized_form;
}
HistoryItem::~HistoryItem ()
......@@ -87,9 +83,8 @@ bool HistoryItem::save (Conf::ConfigTree **history){
res = ( (*history)->setConfigTreeItem(section, "type", call_type.str())
&& (*history)->setConfigTreeItem(section, "timestamp", timestamp)
&& (*history)->setConfigTreeItem(section, "to", _to)
&& (*history)->setConfigTreeItem(section, "from", _from)
&& (*history)->setConfigTreeItem(section, "id", _caller_id) );
&& (*history)->setConfigTreeItem(section, "number", _number)
&& (*history)->setConfigTreeItem(section, "name", _name) );
return res;
}
......@@ -99,7 +94,7 @@ std::string HistoryItem::serialize (void)
std::stringstream res;
std::string separator = ITEM_SEPARATOR;
res << _call_type << separator << _to << separator << _from << separator << _caller_id;
res << _call_type << separator << _number << separator << _name;
return res.str();
}
......
......@@ -38,7 +38,7 @@ class HistoryItem {
/*
* Constructor
*/
HistoryItem (std::string, CallType, std::string, std::string, std::string, std::string="");
HistoryItem (std::string, CallType, std::string, std::string, std::string="");
/*
* Constructor from a serialized form
......@@ -72,11 +72,10 @@ class HistoryItem {
CallType _call_type;
/*
* The information about the callee/caller, depending on the type of call. One field may be empty.
* The information about the callee/caller, depending on the type of call.
*/
std::string _to;
std::string _from;
std::string _caller_id;
std::string _name;
std::string _number;
/*
* The account the call was made with
......
......@@ -66,7 +66,7 @@ int HistoryManager::load_history_items_map (Conf::ConfigTree *history_list)
Conf::TokenList sections;
HistoryItem *item;
Conf::TokenList::iterator iter;
std::string to, from, caller_id, accountID, timestamp;
std::string number, name, caller_id, accountID, timestamp;
CallType type;
sections = history_list->getSections();
......@@ -76,11 +76,10 @@ int HistoryManager::load_history_items_map (Conf::ConfigTree *history_list)
type = (CallType) getConfigInt (*iter, "type", history_list);
timestamp = getConfigString (*iter, "timestamp", history_list);
to = getConfigString (*iter, "to", history_list);
from = getConfigString (*iter, "from", history_list);
caller_id = getConfigString (*iter, "id", history_list);
name = getConfigString (*iter, "name", history_list);
number = getConfigString (*iter, "number", history_list);
item = new HistoryItem (timestamp, type, to, from, caller_id);
item = new HistoryItem (timestamp, type, name, number);
add_new_history_entry (item);
nb_items ++;
......@@ -204,7 +203,7 @@ int HistoryManager::set_serialized_history (std::map <std::string, std::string>
{
std::map <std::string, std::string>::iterator iter;
HistoryItem *new_item;
int items_added;
int items_added = 0;
// Clear the existing history
_history_items.clear ();
......
[144562436]
from=514-276-5468
id=Savoir-faire Linux
name=Savoir-faire Linux
number=514-276-5468
timestamp=144562436
to=
type=0
[747638685]
from=
id=Emmanuel Milou
name=Emmanuel Milou
number=136
timestamp=747638685
to=136
type=2
[775354456]
from=5143848557
id=Chez wam
name=Chez wam
number=5143848557
timestamp=775354456
to=
type=1
[144562436]
from=514-276-5468
id=Savoir-faire Linux
number=514-276-5468
name=Savoir-faire Linux
timestamp=144562436
to=
type=0
[747638685]
from=
id=Emmanuel Milou
name=Emmanuel Milou
timestamp=747638685
to=136
number=136
type=2
[775354456]
from=5143848557
id=Chez wam
number=5143848557
name=Chez wam
timestamp=775354456
to=
type=1
......@@ -114,13 +114,14 @@ void HistoryTest::test_get_history_serialized ()
// The serialized form is: calltype%to%from%callid
// Check the first
tmp = "0||514-276-5468|Savoir-faire Linux";
tmp = "0|514-276-5468|Savoir-faire Linux";
CPPUNIT_ASSERT (tmp == res ["144562436"]);
tmp = "2|136||Emmanuel Milou";
tmp = "2|136|Emmanuel Milou";
CPPUNIT_ASSERT (tmp == res ["747638685"]);
tmp = "1||5143848557|Chez wam";
tmp = "1|5143848557|Chez wam";
std::cout << res ["775354456"] << std::endl;
CPPUNIT_ASSERT (tmp == res ["775354456"]);
}
......@@ -131,9 +132,9 @@ void HistoryTest::test_set_serialized_history ()
std::string tmp;
Conf::ConfigTree history_list;
map_test["144562436"] = "0||514-276-5468|Savoir-faire Linux";
map_test["747638685"] = "2|136||Emmanuel Milou";
map_test["775354456"] = "1||5143848557|Chez wam";
map_test["144562436"] = "0|514-276-5468|Savoir-faire Linux";
map_test["747638685"] = "2|136|Emmanuel Milou";
map_test["775354456"] = "1|5143848557|Chez wam";
CPPUNIT_ASSERT (history->load_history (HISTORY_SAMPLE) == HISTORY_SAMPLE_SIZE);
CPPUNIT_ASSERT (history->set_serialized_history (map_test) == 3);
......@@ -144,13 +145,13 @@ void HistoryTest::test_set_serialized_history ()
CPPUNIT_ASSERT (map_test.size()==HISTORY_SAMPLE_SIZE);
// Check the first
tmp = "0||514-276-5468|Savoir-faire Linux";
tmp = "0|514-276-5468|Savoir-faire Linux";
CPPUNIT_ASSERT (tmp == map_test ["144562436"]);
tmp = "2|136||Emmanuel Milou";
tmp = "2|136|Emmanuel Milou";
CPPUNIT_ASSERT (tmp == map_test ["747638685"]);
tmp = "1||5143848557|Chez wam";
tmp = "1|5143848557|Chez wam";
CPPUNIT_ASSERT (tmp == map_test ["775354456"]);
history->save_history_items_map (&history_list);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment