Commit fe5ac8ae authored by Emmanuel Milou's avatar Emmanuel Milou

[#1214] Add callable_object instead of call_t, refactoring

parent d56af3ed
......@@ -18,7 +18,7 @@ sflphone_client_gnome_SOURCES = \
dialpad.c \
menus.c \
toolbar.c \
call.c \
callable_obj.c \
actions.c \
accountlist.c \
sliders.c \
......@@ -29,7 +29,7 @@ sflphone_client_gnome_SOURCES = \
noinst_HEADERS = actions.h sflnotify.h mainwindow.h dialpad.h codeclist.h \
assistant.h timestamp.h reqaccount.h errors.h sflphone_const.h \
menus.h accountlist.h sliders.h statusicon.h call.h toolbar.h
menus.h accountlist.h sliders.h statusicon.h callable_obj.h toolbar.h
sflphone_client_gnome_LDADD = $(DEPS_LIBS) $(NOTIFY_LIBS) $(SFLPHONEGTK_LIBS) $(LIBSEXY_LIBS) $(LOG4C)
......
This diff is collapsed.
......@@ -23,6 +23,7 @@
#include <libintl.h>
#include <locale.h>
#include <accountlist.h>
#include <codeclist.h>
#include <sflphone_const.h>
......@@ -64,9 +65,9 @@ void sflphone_off_hold ();
/**
* Open a new call
* @return call_t* A pointer on the call structure
* @return callable_obj_t* A pointer on the call structure
*/
call_t * sflphone_new_call();
callable_obj_t * sflphone_new_call();
/**
* Notify voice mails to the application
......@@ -95,43 +96,43 @@ void sflphone_pick_up ();
* Put the call on hold state
* @param c The current call
*/
void sflphone_hold ( call_t * c);
void sflphone_hold ( callable_obj_t * c);
/**
* Put the call in Ringing state
* @param c* The current call
*/
void sflphone_ringing(call_t * c );
void sflphone_ringing(callable_obj_t * c );
/**
* Put the call in Busy state
* @param c* The current call
*/
void sflphone_busy( call_t * c );
void sflphone_busy( callable_obj_t * c );
/**
* Put the call in Failure state
* @param c* The current call
*/
void sflphone_fail( call_t * c );
void sflphone_fail( callable_obj_t * c );
/**
* Put the call in Current state
* @param c The current call
*/
void sflphone_current ( call_t * c);
void sflphone_current ( callable_obj_t * c);
/**
* The callee has hung up
* @param c The current call
*/
void sflphone_hung_up( call_t * c);
void sflphone_hung_up( callable_obj_t * c);
/**
* Incoming call
* @param c The incoming call
*/
void sflphone_incoming_call ( call_t * c);
void sflphone_incoming_call ( callable_obj_t * c);
/**
* Dial the number
......@@ -142,10 +143,10 @@ void sflphone_incoming_call ( call_t * c);
void sflphone_keypad ( guint keyval, gchar * key);
/**
* Place a call with a filled call_t.to
* Place a call with a filled callable_obj_t.to
* @param c A call in CALL_STATE_DIALING state
*/
void sflphone_place_call ( call_t * c );
void sflphone_place_call ( callable_obj_t * c );
/**
* Initialize the accounts data structure
......@@ -165,7 +166,7 @@ void sflphone_set_current_account();
*/
void sflphone_fill_codec_list();
void sflphone_record (call_t *c);
void sflphone_record (callable_obj_t *c);
void sflphone_rec_call (void);
......
......@@ -17,95 +17,82 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <call.h>
#include <callable_obj.h>
/* GCompareFunc to compare a callID (gchar* and a call_t) */
gint
is_callID_callstruct ( gconstpointer a, gconstpointer b)
gint is_callID_callstruct ( gconstpointer a, gconstpointer b)
{
call_t * c = (call_t*)a;
if(g_strcasecmp(c->callID, (const gchar*) b) == 0)
{
return 0;
}
else
{
return 1;
}
callable_obj_t * c = (callable_obj_t*)a;
if(g_strcasecmp(c->_callID, (const gchar*) b) == 0)
{
return 0;
}
else
{
return 1;
}
}
/* GCompareFunc to get current call (gchar* and a call_t) */
gint
get_state_callstruct ( gconstpointer a, gconstpointer b)
gint get_state_callstruct ( gconstpointer a, gconstpointer b)
{
call_t * c = (call_t*)a;
if( c->state == *((call_state_t*)b))
{
return 0;
}
else
{
return 1;
}
callable_obj_t * c = (callable_obj_t*)a;
if( c->_state == *((call_state_t*)b))
{
return 0;
}
else
{
return 1;
}
}
gchar *
call_get_name (const call_t * c)
gchar* call_get_peer_name (const callable_obj_t * c)
{
gchar * end = g_strrstr(c->from, "\"");
if (!end) {
return g_strndup(c->from, 0);
} else {
gchar * name = c->from +1;
return g_strndup(name, end - name);
}
return c->_peer_name;
}
gchar *
call_get_number (const call_t * c)
gchar* call_get_peer_number (const callable_obj_t * c)
{
gchar * number = g_strrstr(c->from, "<") + 1;
gchar * end = g_strrstr(c->from, ">");
number = g_strndup(number, end - number );
return number;
return c->_peer_number;
}
gchar *
call_get_recipient( const call_t * c )
{
return c->to;
}
void create_new_call (gchar *to, gchar *from, call_state_t state, gchar *accountID, call_t **new_call) {
void create_new_call (callable_type_t type, call_state_t state, gchar* callID , gchar* accountID, gchar* peer_name, gchar* peer_number, callable_obj_t ** new_call)
{
callable_obj_t *obj;
gchar *call_id;
call_t *call;
call = g_new0 (call_t, 1);
call->to = g_strdup (to);
call->from = g_strdup (from);
call->state = state;
call->accountID = g_strdup (accountID);
call->_start = 0;
call->_stop = 0;
// Allocate memory
obj = g_new0 (callable_obj_t, 1);
call_id = g_new0(gchar, 30);
g_sprintf(call_id, "%d", rand());
call->callID = g_strdup (call_id);
// Set fields
obj->_type = type;
obj->_state = state;
obj->_accountID = g_strdup (accountID);
obj->_peer_name = g_strdup (peer_name);
obj->_peer_number = g_strdup (peer_number);
obj->_peer_info = g_strdup (get_peer_info (peer_name, peer_number));
obj->_duration = "NaN";
if (g_strcasecmp (callID, "") == 0)
call_id = generate_call_id ();
else
call_id = callID;
// Set the ID
obj->_callID = g_strdup (call_id);
*new_call = call;
*new_call = obj;
}
void create_new_call_from_details (const gchar *call_id, GHashTable *details, call_t **call)
void create_new_call_from_details (const gchar *call_id, GHashTable *details, callable_obj_t **call)
{
gchar *from, *to, *accountID, *state_str;
call_t *new_call;
gchar *peer_name, *peer_number, *accountID, *state_str;
callable_obj_t *new_call;
call_state_t state;
// GHashTable *call_details;
accountID = g_hash_table_lookup (details, "ACCOUNTID");
to = g_hash_table_lookup (details, "PEER_NUMBER");
from = g_markup_printf_escaped("\"\" <%s>", to);
peer_number = g_hash_table_lookup (details, "PEER_NUMBER");
peer_name = g_strdup ("");
state_str = g_hash_table_lookup (details, "CALL_STATE");
if (g_strcasecmp (state_str, "CURRENT") == 0)
......@@ -120,38 +107,52 @@ void create_new_call_from_details (const gchar *call_id, GHashTable *details, ca
else
state = CALL_STATE_FAILURE;
create_new_call (from, from, state, accountID, &new_call);
create_new_call (CALL, state, call_id, accountID, peer_name, peer_number, &new_call);
*call = new_call;
}
void create_new_call_from_serialized_form (gchar *timestamp, gchar *details, call_t **call)
void create_history_entry_from_serialized_form (gchar *timestamp, gchar *details, callable_obj_t **call)
{
gchar *from, *to, *accountID, *state_str;
call_t *new_call;
call_state_t state;
gchar *peer_name, *peer_number, *accountID, *state_str;
callable_obj_t *new_call;
// details is in serialized form, i e: calltype%to%from%callid
state = CALL_STATE_DIALING;
to = g_strdup (details);
from = g_markup_printf_escaped("\"\" <%s>", to);
create_new_call (from, from, state, "", &new_call);
new_call->history_state = MISSED;
peer_name = g_strdup (details);
peer_number = g_strdup (details);
create_new_call (HISTORY_ENTRY, CALL_STATE_DIALING, "", "", peer_name, peer_number, &new_call);
new_call->_history_state = MISSED;
*call = new_call;
}
void free_callable_obj_t (callable_obj_t *c)
{
g_free (c->_callID);
g_free (c->_accountID);
g_free (c->_peer_name);
g_free (c->_peer_number);
g_free (c->_peer_info);
g_free (c);
}
void attach_thumbnail (callable_obj_t *call, GdkPixbuf *pixbuf) {
call->_contact_thumbnail = pixbuf;
}
void
free_call_t (call_t *c)
gchar* generate_call_id (void)
{
g_free (c->callID);
g_free (c->accountID);
g_free (c->from);
g_free (c->to);
g_free (c);
gchar *call_id;
call_id = g_new0(gchar, 30);
g_sprintf(call_id, "%d", rand());
return call_id;
}
void attach_thumbnail (call_t *call, GdkPixbuf *pixbuf) {
call->contact_thumbnail = pixbuf;
gchar* get_peer_info (gchar* number, gchar* name)
{
gchar *info;
info = g_strconcat("\"", name, "\" <", number, ">", NULL);
return info;
}
......@@ -17,8 +17,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CALLL_H__
#define __CALLL_H__
#ifndef __CALLABLE_OBJ_H__
#define __CALLABLE_OBJ_H__
#include <gtk/gtk.h>
#include <glib/gprintf.h>
......@@ -30,10 +30,9 @@
*/
typedef enum
{
NONE,
MISSED,
INCOMING,
OUTGOING,
MISSED
OUTGOING
} history_state_t;
/**
......@@ -48,111 +47,111 @@ typedef enum
} contact_type_t;
/**
* @enum call_type
* This enum have all types of call
* @enum callable_obj_type
* This enum have all types of items
*/
typedef enum
{
CALL,
HISTORY,
HISTORY_ENTRY,
CONTACT
} call_type_t;
} callable_type_t;
/** @enum call_state_t
* This enum have all the states a call can take.
*/
typedef enum
{ /** Invalid state */
{
CALL_STATE_INVALID = 0,
/** Ringing incoming call */
CALL_STATE_INCOMING,
/** Ringing outgoing call */
CALL_STATE_RINGING,
/** Call to which the user can speak and hear */
CALL_STATE_CURRENT,
/** Call which numbers are being added by the user */
CALL_STATE_DIALING,
/** Call is on hold */
CALL_STATE_HOLD,
/** Call has failed */
CALL_STATE_FAILURE,
/** Call is busy */
CALL_STATE_BUSY,
/** Call is being transfert. During this state, the user can enter the new number. */
CALL_STATE_TRANSFERT,
/** Call is on hold */
CALL_STATE_RECORD
} call_state_t;
/** @struct call_t
/** @struct callable_obj_t
* @brief Call information.
* This struct holds information about a call.
*/
typedef struct {
/** Type of call entry */
call_type_t call_type;
/** Unique identifier of the call */
gchar * callID;
/** The account used to place/receive the call */
gchar * accountID;
/** The information about the calling person. See call_get_name() and call_get_number()
* on how to get the name and number separately. */
gchar * from;
/** The number we are calling. Only used when dialing out */
gchar * to;
/** The current state of the call */
call_state_t state;
/** The history state if necessary */
history_state_t history_state;
GdkPixbuf *contact_thumbnail;
time_t _start;
time_t _stop;
} call_t;
/* GCompareFunc to compare a callID (gchar* and a call_t) */
gint
is_callID_callstruct ( gconstpointer, gconstpointer);
/* GCompareFunc to get current call (gchar* and a call_t) */
gint
get_state_callstruct ( gconstpointer, gconstpointer);
/** This function parse the call_t.from field to return the name
callable_type_t _type; // CALL - HISTORY ENTRY - CONTACT
call_state_t _state; // The state of the call
gchar * _callID; // The call ID
gchar * _accountID; // The account the call is made with
time_t _start_date; // The timestamp the call was initiating
gchar *_duration; // The duration of the call
history_state_t _history_state; // The history state if necessary
/**
* The information about the person we are talking
*/
gchar *_peer_name;
gchar *_peer_number;
/**
* A well-formatted phone information
*/
gchar *_peer_info;
/**
* The thumbnail, if callable_obj_type=CONTACT
*/
GdkPixbuf *_contact_thumbnail;
} callable_obj_t;
void create_new_call (callable_type_t, call_state_t, gchar*, gchar*, gchar*, gchar*, callable_obj_t **);
void create_new_call_from_details (const gchar *, GHashTable *, callable_obj_t **);
void create_history_entry_from_serialized_form (gchar *, gchar *, callable_obj_t **);
/*
* GCompareFunc to compare a callID (gchar* and a callable_obj_t)
*/
gint is_callID_callstruct ( gconstpointer, gconstpointer);
/*
* GCompareFunc to get current call (gchar* and a callable_obj_t)
*/
gint get_state_callstruct ( gconstpointer, gconstpointer);
/**
* This function parse the callable_obj_t.from field to return the name
* @param c The call
* @return The full name of the caller or an empty string */
gchar *
call_get_name (const call_t *);
* @return The full name of the caller or an empty string
*/
gchar* call_get_peer_name (const callable_obj_t *);
/**
* This function parse the call_t.from field to return the number
* This function parse the callable_obj_t.from field to return the number
* @param c The call
* @return The number of the caller
*/
gchar *
call_get_number (const call_t *);
gchar *
call_get_recipient( const call_t *);
gchar* call_get_peer_number (const callable_obj_t *);
void
create_new_call (gchar *, gchar *, call_state_t, gchar *, call_t **);
void
create_new_call_from_details (const gchar *, GHashTable *, call_t **);
void
create_new_call_from_serialized_form (gchar *, gchar *, call_t **);
void
attach_thumbnail (call_t *, GdkPixbuf *);
attach_thumbnail (callable_obj_t *, GdkPixbuf *);
void
free_call_t (call_t *c);
free_callable_obj_t (callable_obj_t *c);
/**
* @return gchar* A random ID
*/
gchar* generate_call_id (void);
gchar* get_peer_info (gchar*, gchar*);
#endif
......@@ -143,12 +143,12 @@ handler_async_search(GList *hits, gpointer user_data)
GList *i;
GdkPixbuf *photo = NULL;
AddressBook_Config *addressbook_config;
call_t *j;
callable_obj_t *j;
// freeing calls
while ((j = (call_t *) g_queue_pop_tail(contacts->callQueue)) != NULL)
while ((j = (callable_obj_t *) g_queue_pop_tail(_contacts->callQueue)) != NULL)
{
free_call_t(j);
free_callable_obj_t(j);
}
// Retrieve the address book parameters
......
......@@ -24,14 +24,12 @@
// TODO : sflphoneGTK : try to do this more generic
void calllist_add_contact (gchar *contact_name, gchar *contact_phone, contact_type_t type, GdkPixbuf *photo){
gchar *from;
call_t *new_call;
callable_obj_t *new_call;
GdkPixbuf *pixbuf;
/* Check if the information is valid */
if (g_strcasecmp (contact_phone, EMPTY_ENTRY) != 0){
from = g_strconcat("\"" , contact_name, "\"<", contact_phone, ">", NULL);
create_new_call (from, from, CALL_STATE_DIALING, "", &new_call);
create_new_call (CONTACT, CALL_STATE_DIALING, "", "", contact_name, contact_phone, &new_call);
// Attach a pixbuf to a contact
if (photo) {
......@@ -81,7 +79,7 @@ calllist_reset (calltab_t* tab)
}
void
calllist_add (calltab_t* tab, call_t * c)
calllist_add (calltab_t* tab, callable_obj_t * c)
{
if( tab == history )
{
......@@ -94,7 +92,7 @@ calllist_add (calltab_t* tab, call_t * c)
// List full -> Remove the last call from history and preprend the new call to the list
else
{
calltree_remove_call( history , (call_t*)g_queue_pop_head( tab -> callQueue ) );
calltree_remove_call( history , (callable_obj_t*)g_queue_pop_head( tab -> callQueue ) );
g_queue_push_tail (tab->callQueue, (gpointer *) c);
calltree_add_call( history , c );
}
......@@ -113,7 +111,7 @@ calllist_clean_history( void )
for( i = 0 ; i < size ; i++ )
{
DEBUG("Delete calls");
call_t* c = calllist_get_nth( history , i );
callable_obj_t* c = calllist_get_nth( history , i );
// Delete the call from the call tree
DEBUG("Delete calls");
calltree_remove_call(history , c);
......@@ -123,9 +121,9 @@ calllist_clean_history( void )
// TODO : sflphoneGTK : try to do this more generic
void
calllist_remove_from_history( call_t* c )
calllist_remove_from_history( callable_obj_t* c )
{
calllist_remove( history, c->callID );
calllist_remove( history, c->_callID );
calltree_remove_call( history, c );
DEBUG("Size of history = %i" , calllist_get_size( history ));
}
......@@ -133,7 +131,7 @@ calllist_remove_from_history( call_t* c )
void
calllist_remove (calltab_t* tab, const gchar * callID)
{
call_t * c = calllist_get(tab, callID);
callable_obj_t * c = calllist_get(tab, callID);