Commit 292f811d authored by Julien Bonjean's avatar Julien Bonjean
Browse files

Refactoring - step 3

Refactor calltab/calltree
parent 33406baf
......@@ -19,6 +19,8 @@ sflphone_gtk_SOURCES = \
calllist.c \
dialpad.c \
menus.c \
toolbar.c \
call.c \
calltab.c \
calltree.c \
actions.c \
......@@ -32,7 +34,7 @@ sflphone_gtk_SOURCES = \
noinst_HEADERS = actions.h dbus.h sflnotify.h mainwindow.h calllist.h dialpad.h codeclist.h assistant.h timestamp.h reqaccount.h \
callmanager-glue.h errors.h sflphone_const.h configurationmanager-glue.h instance-glue.h menus.h calltab.h calltree.h \
accountlist.h marshaller.h sliders.h statusicon.h
accountlist.h marshaller.h sliders.h statusicon.h call.h toolbar.h
EXTRA_DIST = marshaller.list
......
......@@ -19,15 +19,13 @@
*/
#include <actions.h>
#include <calltree.h>
#include <dbus.h>
#include <mainwindow.h>
#include <menus.h>
#include <statusicon.h>
#include <calltab.h>
#include <toolbar.h>
#include <contacts/searchfilter.h>
#include <contacts/addressbook/eds.h>
#include <gtk/gtk.h>
#include <string.h>
#include <glib/gprintf.h>
......
......@@ -2,29 +2,27 @@
* Copyright (C) 2007 Savoir-Faire Linux inc.
* Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
* Author: Emmanuel Milou <emmanuel.milou@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.
*/
#ifndef __ACTIONS_H__
#define __ACTIONS_H__
#include <libintl.h>
#include <locale.h>
#include <calllist.h>
#include <accountlist.h>
#include <codeclist.h>
#include <sflphone_const.h>
......@@ -38,7 +36,7 @@
/**
* Initialize lists and configurations
* Initialize lists and configurations
* @return TRUE if succeeded, FALSE otherwise
*/
gboolean sflphone_init ( ) ;
......@@ -55,7 +53,7 @@ gboolean sflphone_quit ( ) ;
void sflphone_hang_up ();
/**
* Put the selected call on hold
* Put the selected call on hold
*/
void sflphone_on_hold ();
......@@ -124,7 +122,7 @@ void sflphone_fail( call_t * c );
void sflphone_current ( call_t * c);
/**
* The callee has hung up
* The callee has hung up
* @param c The current call
*/
void sflphone_hung_up( call_t * c);
......@@ -144,7 +142,7 @@ 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 call_t.to
* @param c A call in CALL_STATE_DIALING state
*/
void sflphone_place_call ( call_t * c );
......@@ -157,7 +155,7 @@ void sflphone_fill_account_list(gboolean toolbarInitialized);
/**
* Set an account as current. The current account is to one used to place calls with by default
* The current account is the first in the account list ( index 0 )
*/
*/
void sflphone_set_current_account();
/**
......@@ -172,4 +170,4 @@ void sflphone_rec_call (void);
gchar* sflphone_get_current_codec_name();
void sflphone_display_selected_codec (const gchar* codecName);
#endif
#endif
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Julien Bonjean <julien.bonjean@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 <call.h>
/* GCompareFunc to compare a callID (gchar* and a call_t) */
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;
}
}
/* GCompareFunc to get current call (gchar* and a call_t) */
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;
}
}
gchar *
call_get_name (const call_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);
}
}
gchar *
call_get_number (const call_t * c)
{
gchar * number = g_strrstr(c->from, "<") + 1;
gchar * end = g_strrstr(c->from, ">");
number = g_strndup(number, end - number );
return 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) {
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;
call_id = g_new0(gchar, 30);
g_sprintf(call_id, "%d", rand());
call->callID = g_strdup (call_id);
*new_call = call;
}
void
free_call_t (call_t *c)
{
g_free (c->callID);
g_free (c->accountID);
g_free (c->from);
g_free (c->to);
g_free (c);
}
void attach_thumbnail (call_t *call, GdkPixbuf *pixbuf) {
call->contact_thumbnail = pixbuf;
}
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Julien Bonjean <julien.bonjean@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.
*/
#ifndef __CALLL_H__
#define __CALLL_H__
#include <gtk/gtk.h>
#include <glib/gprintf.h>
#include <stdlib.h>
/**
* @enum history_state
* This enum have all the state a call can take in the history
*/
typedef enum
{
NONE,
INCOMING,
OUTGOING,
MISSED
} history_state_t;
/**
* @enum contact_type
* This enum have all types of contacts: HOME phone, cell phone, etc...
*/
typedef enum
{
CONTACT_PHONE_HOME,
CONTACT_PHONE_BUSINESS,
CONTACT_PHONE_MOBILE
} contact_type_t;
/**
* @enum call_type
* This enum have all types of call
*/
typedef enum
{
CALL,
HISTORY,
CONTACT
} call_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
* @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
* @param c The call
* @return The full name of the caller or an empty string */
gchar *
call_get_name (const call_t *);
/**
* This function parse the call_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 *);
void
create_new_call (gchar *, gchar *, call_state_t, gchar *, call_t **);
void
attach_thumbnail (call_t *, GdkPixbuf *);
void
free_call_t (call_t *c);
#endif
......@@ -19,43 +19,44 @@
#include <calllist.h>
#include <calltree.h>
#include <dbus.h>
#include <glib/gprintf.h>
/*
* GQueue * callQueue = NULL;
* call_t * selectedCall = NULL;
*/
/* GCompareFunc to compare a callID (gchar* and a call_t) */
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;
}
}
/* GCompareFunc to get current call (gchar* and a call_t) */
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;
}
#include <contacts/addressbook/eds.h>
void create_new_entry_in_contactlist (gchar *contact_name, gchar *contact_phone, contact_type_t type, GdkPixbuf *photo){
gchar *from;
call_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);
// Attach a pixbuf to a contact
if (photo) {
attach_thumbnail (new_call, photo);
}
else {
switch (type) {
case CONTACT_PHONE_BUSINESS:
pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/face-monkey.svg", NULL);
break;
case CONTACT_PHONE_HOME:
pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/home.svg", NULL);
break;
case CONTACT_PHONE_MOBILE:
pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/users.svg", NULL);
break;
default:
pixbuf = gdk_pixbuf_new_from_file(ICONS_DIR "/contact_default.svg", NULL);
break;
}
attach_thumbnail (new_call, pixbuf);
}
call_list_add (contacts, new_call);
update_call_tree_add(contacts, new_call);
}
}
void
......@@ -164,34 +165,6 @@ call_list_get_nth (calltab_t* tab, guint n )
return g_queue_peek_nth (tab->callQueue, n);
}
gchar *
call_get_name (const call_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);
}
}
gchar *
call_get_number (const call_t * c)
{
gchar * number = g_strrstr(c->from, "<") + 1;
gchar * end = g_strrstr(c->from, ">");
number = g_strndup(number, end - number );
return number;
}
gchar *
call_get_recipient( const call_t * c )
{
return c->to;
}
call_t *
call_list_get (calltab_t* tab, const gchar * callID )
{
......@@ -205,40 +178,3 @@ call_list_get (calltab_t* tab, const gchar * callID )
return NULL;
}
}
void
call_select (calltab_t* tab, call_t * c )
{
tab->selectedCall = c;
}
call_t *
call_get_selected (calltab_t* tab)
{
return tab->selectedCall;
}
void create_new_call (gchar *to, gchar *from, call_state_t state, gchar *accountID, call_t **new_call) {
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;
call_id = g_new0(gchar, 30);
g_sprintf(call_id, "%d", rand());
call->callID = g_strdup (call_id);
*new_call = call;
}
void attach_thumbnail (call_t *call, GdkPixbuf *pixbuf) {
call->contact_thumbnail = pixbuf;
}
......@@ -20,100 +20,13 @@
#ifndef __CALLLIST_H__
#define __CALLLIST_H__
#include <call.h>
#include <gtk/gtk.h>
/** @file calllist.h
* @brief A list to hold calls.
*/
/** @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;
/**
* @enum history_state
* This enum have all the state a call can take in the history
*/
typedef enum
{
NONE,
INCOMING,
OUTGOING,
MISSED
} history_state_t;
/**
* @enum call_type
* This enum have all types of call
*/
typedef enum
{
CALL,
HISTORY,
CONTACT
} call_type_t;
/**
* @enum contact_type
* This enum have all types of contacts: HOME phone, cell phone, etc...
*/
typedef enum
{
CONTACT_PHONE_HOME,
CONTACT_PHONE_BUSINESS,
CONTACT_PHONE_MOBILE
} contact_type_t;
/** @struct call_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;