Commit 88e48a62 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

place a call with the default account

If an registered account is set by default, a call is placed with this account.
If no account is set by default, the call is made with the first registered account of the list
If a non-registered account is set as default, no call is placed and a message popup is thrown.
parent e3f4bacf
......@@ -22,6 +22,7 @@
#include <string.h>
GQueue * accountQueue;
gchar * DEFAULT_ACCOUNT=NULL;
/* GCompareFunc to compare a accountID (gchar* and a account_t) */
gint
......@@ -98,6 +99,20 @@ account_list_get_by_state (account_state_t state )
}
account_t *
account_list_get_by_id(gchar * accountID)
{
GList * c = g_queue_find_custom (accountQueue, accountID, is_accountID_struct);
if(c)
{
return (account_t *)c->data;
}
else
{
return NULL;
}
}
guint
account_list_get_size ( )
{
......@@ -120,6 +135,7 @@ void
account_list_set_default(const gchar * accountID)
{
DEFAULT_ACCOUNT = g_strdup(accountID);
g_print("DEFAULT_ACCOUNT = %s\n", DEFAULT_ACCOUNT);
}
const gchar * account_state_name(account_state_t s)
......
......@@ -70,7 +70,6 @@ typedef struct {
} account_t;
gchar * DEFAULT_ACCOUNT;
/** This function initialize the account list. */
void account_list_init ();
......@@ -116,4 +115,10 @@ void account_list_set_default(const gchar * accountID);
const gchar * account_state_name(account_state_t s);
void account_list_clear ( );
/** Return the account associated with an ID
* @param accountID The ID of the account
* @return An account or NULL */
account_t * account_list_get_by_id(gchar * accountID);
#endif
/*
* Copyright (C) 2007 Savoir-Faire Linux inc.
* Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info>
* 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 2 of the License, or
* 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,
......@@ -34,511 +35,534 @@
#include <unistd.h>
void
void
sflphone_notify_voice_mail (guint count)
{
if(count > 0)
{
gchar * message = g_new0(gchar, 50);
g_sprintf(message, "%d new voice mail%s", count, (count > 1? "s" : ""));
status_bar_message(message);
g_free(message);
}
else
{
status_bar_message("");
}
if(count > 0)
{
gchar * message = g_new0(gchar, 50);
g_sprintf(message, "%d new voice mail%s", count, (count > 1? "s" : ""));
status_bar_message(message);
g_free(message);
}
else
{
status_bar_message("");
}
}
gboolean
gboolean
sflphone_quit ()
{
gboolean quit = FALSE;
guint count = call_list_get_size();
if(count > 0){
quit = main_window_ask_quit();
}
else{
quit = TRUE;
}
if (quit)
{
dbus_unregister(getpid());
dbus_clean ();
//call_list_clean(); TODO
//account_list_clean()
gtk_main_quit ();
}
return quit;
gboolean quit = FALSE;
guint count = call_list_get_size();
if(count > 0){
quit = main_window_ask_quit();
}
else{
quit = TRUE;
}
if (quit)
{
dbus_unregister(getpid());
dbus_clean ();
//call_list_clean(); TODO
//account_list_clean()
gtk_main_quit ();
}
return quit;
}
void
void
sflphone_hold(call_t * c )
{
c->state = CALL_STATE_HOLD;
update_call_tree(c);
update_menus();
screen_clear();
c->state = CALL_STATE_HOLD;
update_call_tree(c);
update_menus();
screen_clear();
}
void
void
sflphone_ringing(call_t * c )
{
c->state = CALL_STATE_RINGING;
update_call_tree(c);
update_menus();
c->state = CALL_STATE_RINGING;
update_call_tree(c);
update_menus();
}
/** Internal to actions: Fill account list */
void
void
sflphone_fill_account_list()
{
account_list_clear ( );
gchar ** array = (gchar **)dbus_account_list();
gchar ** accountID;
for (accountID = array; *accountID; accountID++)
{
account_t * a = g_new0(account_t,1);
a->accountID = g_strdup(*accountID);
account_list_add(a);
}
g_strfreev (array);
int i;
for( i = 0; i < account_list_get_size(); i++)
account_list_clear ( );
gchar ** array = (gchar **)dbus_account_list();
gchar ** accountID;
for (accountID = array; *accountID; accountID++)
{
account_t * a = account_list_get_nth (i);
GHashTable * details = (GHashTable *) dbus_account_details(a->accountID);
a->properties = details;
gchar * status = g_hash_table_lookup(details, "Status");
if(strcmp(status, "REGISTERED") == 0)
{
a->state = ACCOUNT_STATE_REGISTERED;
}
else if(strcmp(status, "UNREGISTERED") == 0)
{
a->state = ACCOUNT_STATE_UNREGISTERED;
}
else if(strcmp(status, "TRYING") == 0)
{
a->state = ACCOUNT_STATE_TRYING;
}
else if(strcmp(status, "ERROR") == 0)
{
a->state = ACCOUNT_STATE_ERROR;
}
else
{
a->state = ACCOUNT_STATE_INVALID;
}
}
account_t * a = g_new0(account_t,1);
a->accountID = g_strdup(*accountID);
account_list_add(a);
}
g_strfreev (array);
int i;
for( i = 0; i < account_list_get_size(); i++)
{
account_t * a = account_list_get_nth (i);
GHashTable * details = (GHashTable *) dbus_account_details(a->accountID);
a->properties = details;
gchar * status = g_hash_table_lookup(details, "Status");
if(strcmp(status, "REGISTERED") == 0)
{
a->state = ACCOUNT_STATE_REGISTERED;
}
else if(strcmp(status, "UNREGISTERED") == 0)
{
a->state = ACCOUNT_STATE_UNREGISTERED;
}
else if(strcmp(status, "TRYING") == 0)
{
a->state = ACCOUNT_STATE_TRYING;
}
else if(strcmp(status, "ERROR") == 0)
{
a->state = ACCOUNT_STATE_ERROR;
}
else
{
a->state = ACCOUNT_STATE_INVALID;
}
}
toolbar_update_buttons();
}
gboolean
gboolean
sflphone_init()
{
call_list_init ();
account_list_init ();
if(!dbus_connect ())
{
main_window_error_message("Unable to connect to the SFLphone server.\nMake sure the daemon is running.");
return FALSE;
}
else
{
dbus_register(getpid(), "Gtk+ Client");
sflphone_fill_account_list();
sflphone_set_default_account();
return TRUE;
}
call_list_init ();
account_list_init ();
if(!dbus_connect ())
{
main_window_error_message("Unable to connect to the SFLphone server.\nMake sure the daemon is running.");
return FALSE;
}
else
{
dbus_register(getpid(), "Gtk+ Client");
sflphone_fill_account_list();
sflphone_set_default_account();
return TRUE;
}
}
void
void
sflphone_hang_up()
{
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_CURRENT:
case CALL_STATE_HOLD:
case CALL_STATE_DIALING:
case CALL_STATE_RINGING:
case CALL_STATE_BUSY:
case CALL_STATE_FAILURE:
dbus_hang_up (selectedCall);
break;
case CALL_STATE_INCOMING:
dbus_refuse (selectedCall);
break;
case CALL_STATE_TRANSFERT:
dbus_hang_up (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_hang_up()!");
break;
}
}
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_CURRENT:
case CALL_STATE_HOLD:
case CALL_STATE_DIALING:
case CALL_STATE_RINGING:
case CALL_STATE_BUSY:
case CALL_STATE_FAILURE:
dbus_hang_up (selectedCall);
break;
case CALL_STATE_INCOMING:
dbus_refuse (selectedCall);
break;
case CALL_STATE_TRANSFERT:
dbus_hang_up (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_hang_up()!");
break;
}
}
}
void
void
sflphone_pick_up()
{
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_DIALING:
sflphone_place_call (selectedCall);
break;
case CALL_STATE_INCOMING:
dbus_accept (selectedCall);
break;
case CALL_STATE_HOLD:
dbus_unhold (selectedCall);
break;
case CALL_STATE_TRANSFERT:
dbus_transfert (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_pick_up()!");
break;
}
}
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_DIALING:
sflphone_place_call (selectedCall);
break;
case CALL_STATE_INCOMING:
dbus_accept (selectedCall);
break;
case CALL_STATE_HOLD:
dbus_unhold (selectedCall);
break;
case CALL_STATE_TRANSFERT:
dbus_transfert (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_pick_up()!");
break;
}
}
}
void
void
sflphone_on_hold ()
{
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_CURRENT:
dbus_hold (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_on_hold!");
break;
}
}
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_CURRENT:
dbus_hold (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_on_hold!");
break;
}
}
}
void
void
sflphone_off_hold ()
{
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_HOLD:
dbus_unhold (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_off_hold ()!");
break;
}
}
call_t * selectedCall = call_get_selected();
if(selectedCall)
{
switch(selectedCall->state)
{
case CALL_STATE_HOLD:
dbus_unhold (selectedCall);
break;
default:
g_warning("Should not happen in sflphone_off_hold ()!");
break;
}
}
}
void
void
sflphone_fail( call_t * c )
{
c->state = CALL_STATE_FAILURE;
update_call_tree(c);
update_menus();
screen_set_call(c);
c->state = CALL_STATE_FAILURE;
update_call_tree(c);
update_menus();
screen_set_call(c);
}
void
void
sflphone_busy( call_t * c )
{
c->state = CALL_STATE_BUSY;
update_call_tree(c);
update_menus();
screen_set_call(c);
c->state = CALL_STATE_BUSY;
update_call_tree(c);
update_menus();
screen_set_call(c);
}
void
void
sflphone_current( call_t * c )
{
c->state = CALL_STATE_CURRENT;
update_call_tree(c);
update_menus();
screen_set_call(c);
c->state = CALL_STATE_CURRENT;
update_call_tree(c);
update_menus();
screen_set_call(c);
}
void
void
sflphone_set_transfert()
{
call_t * c = call_get_selected();
if(c)
{
c->state = CALL_STATE_TRANSFERT;
c->to = g_strdup("");
screen_set_call(c);
update_call_tree(c);
update_menus();
}
toolbar_update_buttons();
call_t * c = call_get_selected();
if(c)
{
c->state = CALL_STATE_TRANSFERT;
c->to = g_strdup("");
screen_set_call(c);
update_call_tree(c);
update_menus();
}
toolbar_update_buttons();
}
void
void
sflphone_unset_transfert()
{
call_t * c = call_get_selected();
if(c)
{
c->state = CALL_STATE_CURRENT;
c->to = g_strdup("");
screen_set_call(c);
update_call_tree(c);
update_menus();
}
toolbar_update_buttons();
call_t * c = call_get_selected();
if(c)
{
c->state = CALL_STATE_CURRENT;
c->to = g_strdup("");
screen_set_call(c);
update_call_tree(c);
update_menus();
}
toolbar_update_buttons();
}
void
void
sflphone_incoming_call (call_t * c)
{
call_list_add ( c );
status_icon_unminimize();
update_call_tree_add(c);
update_menus();
call_list_add ( c );
status_icon_unminimize();
update_call_tree_add(c);
update_menus();
}
void
void
sflphone_hung_up (call_t * c )
{
call_list_remove(c->callID);
update_call_tree_remove(c);
update_menus();
screen_clear();
call_list_remove(c->callID);
update_call_tree_remove(c);
update_menus();
screen_clear();
}
void process_dialing(call_t * c, guint keyval, gchar * key)
{
switch (keyval)
{
case 65293: /* ENTER */
case 65421: /* ENTER numpad */
sflphone_place_call(c);
break;
case 65307: /* ESCAPE */
dbus_hang_up(c);
break;
case 65288: /* BACKSPACE */
{ /* Brackets mandatory because of local vars */
gchar * before = c->to;
if(strlen(c->to) > 1){
c->to = g_strndup(c->to, strlen(c->to) -1);
g_free(before);
g_print("TO: %s\n", c->to);
if(c->state == CALL_STATE_DIALING)
{
g_free(c->from);
c->from = g_strconcat("\"\" <", c->to, ">", NULL);
}
screen_set_call(c);
update_call_tree(c);
}
else if(strlen(c->to) == 1)
{
dbus_hang_up(c);
}
}
break;
case 65289: /* TAB */