Commit 7dd04827 authored by Emmanuel Milou's avatar Emmanuel Milou

Replace default account by current account

Actual behaviour: you can select an order of account, the first in the list is the one used to make calls
If this one isn't registered, we loop on the rest of the list and call with the fisrt registered account we encounter
parent 5dea0e92
......@@ -23,8 +23,7 @@
#include <string.h>
GQueue * accountQueue;
gchar * DEFAULT_ACCOUNT=NULL;
gchar * CURRENT_ACCOUNT=NULL;
account_t * __CURRENT_ACCOUNT=NULL;
/* GCompareFunc to compare a accountID (gchar* and a account_t) */
gint
......@@ -127,35 +126,28 @@ account_list_get_nth ( guint n )
return g_queue_peek_nth (accountQueue, n);
}
gchar *
account_list_get_default( )
account_t*
account_list_get_current( )
{
return DEFAULT_ACCOUNT;
return __CURRENT_ACCOUNT;
}
void
account_list_set_default(const gchar * accountID)
{
DEFAULT_ACCOUNT = g_strdup(accountID);
g_print("DEFAULT_ACCOUNT = %s\n", DEFAULT_ACCOUNT);
}
gchar *
account_list_get_current( )
account_list_set_current_id(const gchar * accountID)
{
return CURRENT_ACCOUNT;
__CURRENT_ACCOUNT = account_list_get_by_id(g_strdup(accountID));
}
void
account_list_set_current(const gchar * accountID)
account_list_set_current_pos( guint n)
{
CURRENT_ACCOUNT = g_strdup(accountID);
__CURRENT_ACCOUNT = account_list_get_nth(n);
}
const gchar * account_state_name(account_state_t s)
{
gchar * state;
switch(s)
switch(s)
{
case ACCOUNT_STATE_REGISTERED:
state = _("Registered");
......@@ -182,3 +174,25 @@ account_list_clear ( )
g_queue_free (accountQueue);
accountQueue = g_queue_new ();
}
void
account_list_move_up(guint index)
{
if(index != 0)
{
gpointer acc = g_queue_pop_nth(accountQueue, index);
g_queue_push_nth(accountQueue, acc, index-1);
}
account_list_set_current_pos( 0 );
}
void
account_list_move_down(guint index)
{
if(index != accountQueue->length)
{
gpointer acc = g_queue_pop_nth(accountQueue, index);
g_queue_push_nth(accountQueue, acc, index+1);
}
account_list_set_current_pos( 0 );
}
/*
* Copyright (C) 2007 Savoir-Faire Linux inc.
* Author: Pierre-Luc Beaudoin <pierre-luc@squidy.info>
* Author: Pierre-Luc Beaudoin <pierre-luc@savoirfairelinux.com>
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -102,24 +102,20 @@ guint account_list_get_size ( );
* @return An account or NULL */
account_t * account_list_get_nth ( guint n );
/** Return the account's id chosen as default
* @return The default account */
gchar * account_list_get_default( );
/** This function sets an account as default
* @param n The position of the account you want to select
/** Return the current account struct
* @return The current account struct
*/
void account_list_set_default(const gchar * accountID);
account_t * account_list_get_current( );
/** Return the current account id
* @return The current account id
/** This function sets an account as the current one
* @param accountID The ID of the current account
*/
gchar * account_list_get_current( );
void account_list_set_current_id(const gchar * accountID);
/** This function sets an account as the current one
* @param accountID The ID of the current account
* @param n the position of the account you want to use
*/
void account_list_set_current(const gchar * accountID);
void account_list_set_current_pos( guint n );
/** This function maps account_state_t enums to a description.
* @param s The state
......@@ -133,4 +129,7 @@ void account_list_clear ( );
* @return An account or NULL */
account_t * account_list_get_by_id(gchar * accountID);
void account_list_move_up( guint index );
void account_list_move_down( guint index );
#endif
......@@ -115,7 +115,7 @@ void sflphone_keypad ( guint keyval, gchar * key);
void sflphone_place_call ( call_t * c );
void sflphone_fill_account_list();
void sflphone_set_default_account();
void sflphone_set_current_account();
void sflphone_throw_exception( int errCode );
void sflphone_fill_codec_list();
......
......@@ -48,15 +48,17 @@ GtkListStore *inputAudioDeviceManagerStore;
GtkWidget *addButton;
GtkWidget *editButton;
GtkWidget *deleteButton;
GtkWidget *defaultButton;
//GtkWidget *defaultButton;
GtkWidget *restoreButton;
GtkWidget *accountMoveDownButton;
GtkWidget *accountMoveUpButton;
GtkWidget *outputDeviceComboBox;
GtkWidget *inputDeviceComboBox;
GtkWidget *pluginComboBox;
GtkWidget *moveUpButton;
GtkWidget *moveDownButton;
GtkWidget *codecMoveUpButton;
GtkWidget *codecMoveDownButton;
account_t *selectedAccount;
......@@ -111,7 +113,7 @@ config_window_fill_account_list()
gtk_widget_set_sensitive( GTK_WIDGET(editButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(deleteButton), FALSE);
gtk_widget_set_sensitive( GTK_WIDGET(defaultButton), FALSE);
//gtk_widget_set_sensitive( GTK_WIDGET(defaultButton), FALSE);
}
}
......@@ -491,20 +493,6 @@ add_account(GtkWidget *widget, gpointer data)
show_account_window(NULL);
}
/*
* Should mark the account as default
*/
void
default_account(GtkWidget *widget, gpointer data)
{
// set account as default
if(selectedAccount)
{
account_list_set_default(selectedAccount->accountID);
dbus_set_default_account(selectedAccount->accountID);
}
}
int
is_ringtone_enabled( void )
{
......@@ -554,6 +542,8 @@ select_account(GtkTreeSelection *selection, GtkTreeModel *model)
if (!gtk_tree_selection_get_selected(selection, &model, &iter))
{
selectedAccount = NULL;
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveUpButton), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveDownButton), FALSE);
return;
}
......@@ -567,7 +557,9 @@ select_account(GtkTreeSelection *selection, GtkTreeModel *model)
{
gtk_widget_set_sensitive(GTK_WIDGET(editButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(deleteButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(defaultButton), TRUE);
//gtk_widget_set_sensitive(GTK_WIDGET(defaultButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveUpButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveDownButton), TRUE);
}
g_print("select");
}
......@@ -582,13 +574,13 @@ select_codec(GtkTreeSelection *selection, GtkTreeModel *model)
if(!gtk_tree_selection_get_selected(selection, &model, &iter))
{
gtk_widget_set_sensitive(GTK_WIDGET(moveUpButton), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(moveDownButton), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(codecMoveUpButton), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(codecMoveDownButton), FALSE);
}
else
{
gtk_widget_set_sensitive(GTK_WIDGET(moveUpButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(moveDownButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(codecMoveUpButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(codecMoveDownButton), TRUE);
}
}
......@@ -730,14 +722,69 @@ codec_move(gboolean moveUp, gpointer data)
codec_list_update_to_daemon();
}
/**
* Move account in list depending on direction and selected account
*/
static void
account_move(gboolean moveUp, gpointer data)
{
GtkTreeIter iter;
GtkTreeIter *iter2;
GtkTreeView *treeView;
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreePath *treePath;
gchar *path;
// Get view, model and selection of codec store
treeView = GTK_TREE_VIEW(data);
model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeView));
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeView));
// Find selected iteration and create a copy
gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter);
iter2 = gtk_tree_iter_copy(&iter);
// Find path of iteration
path = gtk_tree_model_get_string_from_iter(GTK_TREE_MODEL(model), &iter);
treePath = gtk_tree_path_new_from_string(path);
gint *indices = gtk_tree_path_get_indices(treePath);
gint indice = indices[0];
// Depending on button direction get new path
if(moveUp)
gtk_tree_path_prev(treePath);
else
gtk_tree_path_next(treePath);
gtk_tree_model_get_iter(model, &iter, treePath);
// Swap iterations if valid
if(gtk_list_store_iter_is_valid(GTK_LIST_STORE(model), &iter))
gtk_list_store_swap(GTK_LIST_STORE(model), &iter, iter2);
// Scroll to new position
gtk_tree_view_scroll_to_cell(treeView, treePath, NULL, FALSE, 0, 0);
// Free resources
gtk_tree_path_free(treePath);
gtk_tree_iter_free(iter2);
g_free(path);
// Perpetuate changes in account queue
if(moveUp)
account_list_move_up(indice);
else
account_list_move_down(indice);
}
/**
* Called from move up codec button signal
*/
static void
codec_move_up(GtkButton *button, gpointer data)
{
// Change tree view ordering and get indice changed
codec_move(TRUE, data);
// Change tree view ordering and get indice changed
codec_move(TRUE, data);
}
/**
......@@ -746,28 +793,28 @@ codec_move_up(GtkButton *button, gpointer data)
static void
codec_move_down(GtkButton *button, gpointer data)
{
// Change tree view ordering and get indice changed
codec_move(FALSE, data);
// Change tree view ordering and get indice changed
codec_move(FALSE, data);
}
/**
* Select default account that is rendered in bold
* Called from move up account button signal
*/
void
bold_if_default_account(GtkTreeViewColumn *col,
GtkCellRenderer *rend,
GtkTreeModel *tree_model,
GtkTreeIter *iter,
gpointer data)
static void
account_move_up(GtkButton *button, gpointer data)
{
GValue val = { 0, };
gtk_tree_model_get_value(tree_model, iter, COLUMN_ACCOUNT_DATA, &val);
account_t *current = (account_t*)g_value_get_pointer(&val);
g_value_unset(&val);
if(g_strcasecmp(current->accountID, account_list_get_default()) == 0)
g_object_set(G_OBJECT(rend), "weight", 800, NULL);
else
g_object_set(G_OBJECT(rend), "weight", 400, NULL);
// Change tree view ordering and get indice changed
account_move(TRUE, data);
}
/**
* Called from move down account button signal
*/
static void
account_move_down(GtkButton *button, gpointer data)
{
// Change tree view ordering and get indice changed
account_move(FALSE, data);
}
GtkWidget*
......@@ -843,15 +890,15 @@ create_codec_table()
gtk_container_set_border_width(GTK_CONTAINER(buttonBox), 10);
gtk_box_pack_start(GTK_BOX(ret), buttonBox, FALSE, FALSE, 0);
moveUpButton = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
gtk_widget_set_sensitive(GTK_WIDGET(moveUpButton), FALSE);
gtk_box_pack_start(GTK_BOX(buttonBox), moveUpButton, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(moveUpButton), "clicked", G_CALLBACK(codec_move_up), codecTreeView);
codecMoveUpButton = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
gtk_widget_set_sensitive(GTK_WIDGET(codecMoveUpButton), FALSE);
gtk_box_pack_start(GTK_BOX(buttonBox), codecMoveUpButton, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(codecMoveUpButton), "clicked", G_CALLBACK(codec_move_up), codecTreeView);
moveDownButton = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
gtk_widget_set_sensitive(GTK_WIDGET(moveDownButton), FALSE);
gtk_box_pack_start(GTK_BOX(buttonBox), moveDownButton, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(moveDownButton), "clicked", G_CALLBACK(codec_move_down), codecTreeView);
codecMoveDownButton = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
gtk_widget_set_sensitive(GTK_WIDGET(codecMoveDownButton), FALSE);
gtk_box_pack_start(GTK_BOX(buttonBox), codecMoveDownButton, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(codecMoveDownButton), "clicked", G_CALLBACK(codec_move_down), codecTreeView);
config_window_fill_codec_list();
......@@ -896,16 +943,13 @@ create_accounts_tab()
G_CALLBACK (select_account),
accountStore);
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(accountStore),
2 , GTK_SORT_DESCENDING);
renderer = gtk_cell_renderer_text_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes ("Alias",
renderer,
"markup", COLUMN_ACCOUNT_ALIAS,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeView), treeViewColumn);
gtk_tree_view_column_set_cell_data_func(treeViewColumn, renderer, bold_if_default_account, NULL,NULL);
//gtk_tree_view_column_set_cell_data_func(treeViewColumn, renderer, bold_if_default_account, NULL,NULL);
// A double click on the account line opens the window to edit the account
g_signal_connect( G_OBJECT( treeView ) , "row-activated" , G_CALLBACK( edit_account ) , NULL );
......@@ -916,7 +960,7 @@ create_accounts_tab()
"markup", COLUMN_ACCOUNT_TYPE,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeView), treeViewColumn);
gtk_tree_view_column_set_cell_data_func(treeViewColumn, renderer, bold_if_default_account, NULL,NULL);
//gtk_tree_view_column_set_cell_data_func(treeViewColumn, renderer, bold_if_default_account, NULL,NULL);
renderer = gtk_cell_renderer_text_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes (_("Status"),
......@@ -924,21 +968,35 @@ create_accounts_tab()
"markup", COLUMN_ACCOUNT_STATUS,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeView), treeViewColumn);
gtk_tree_view_column_set_cell_data_func(treeViewColumn, renderer, bold_if_default_account, NULL,NULL);
//gtk_tree_view_column_set_cell_data_func(treeViewColumn, renderer, bold_if_default_account, NULL,NULL);
renderer = gtk_cell_renderer_toggle_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes("", renderer, "active", COLUMN_ACCOUNT_ACTIVE , NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeView), treeViewColumn);
g_signal_connect( G_OBJECT(renderer) , "toggled" , G_CALLBACK(enable_account), (gpointer)treeView );
g_object_unref(G_OBJECT(accountStore));
gtk_container_add(GTK_CONTAINER(scrolledWindow), treeView);
// Create button box
buttonBox = gtk_vbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(buttonBox), 10);
gtk_box_pack_start(GTK_BOX(ret), buttonBox, FALSE, FALSE, 0);
accountMoveUpButton = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveUpButton), FALSE);
gtk_box_pack_start(GTK_BOX(buttonBox), accountMoveUpButton, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(accountMoveUpButton), "clicked", G_CALLBACK(account_move_up), treeView);
accountMoveDownButton = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveDownButton), FALSE);
gtk_box_pack_start(GTK_BOX(buttonBox), accountMoveDownButton, FALSE, FALSE, 0);
g_signal_connect(G_OBJECT(accountMoveDownButton), "clicked", G_CALLBACK(account_move_down), treeView);
/* The buttons to press! */
buttonBox = gtk_hbutton_box_new();
gtk_box_set_spacing(GTK_BOX(buttonBox), 10); //GAIM_HIG_BOX_SPACE
gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_START);
gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_CENTER);
gtk_box_pack_start(GTK_BOX(ret), buttonBox, FALSE, FALSE, 0);
gtk_widget_show (buttonBox);
......@@ -960,12 +1018,13 @@ create_accounts_tab()
gtk_box_pack_start(GTK_BOX(buttonBox), deleteButton, FALSE, FALSE, 0);
gtk_widget_show(deleteButton);
defaultButton = gtk_button_new_with_mnemonic(_("Default"));
/*defaultButton = gtk_button_new_with_mnemonic(_("Default"));
gtk_widget_set_tooltip_text( GTK_WIDGET( defaultButton ) , _("Set the selected account as the default one to make calls"));
g_signal_connect_swapped(G_OBJECT(defaultButton), "clicked",
G_CALLBACK(default_account), NULL);
gtk_box_pack_start(GTK_BOX(buttonBox), defaultButton, FALSE, FALSE, 0);
gtk_widget_show(defaultButton);
*/
gtk_widget_show_all(ret);
......
......@@ -177,7 +177,7 @@ switch_account( GtkWidget* item , gpointer data )
{
account_t* acc = g_object_get_data( G_OBJECT(item) , "account" );
g_print("%s\n" , acc->accountID);
account_list_set_current( acc->accountID );
account_list_set_current_id( acc->accountID );
}
static void
......@@ -667,25 +667,22 @@ show_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
gchar* alias;
for( i = 0 ; i < account_list_get_size() ; i++ ){
acc = account_list_get_nth(i);
// Display only the registered accounts
if( g_strcasecmp( account_state_name(acc -> state) , account_state_name(ACCOUNT_STATE_REGISTERED) ) == 0 ){
alias = g_strconcat( g_hash_table_lookup(acc->properties , ACCOUNT_ALIAS) , " - ",g_hash_table_lookup(acc->properties , ACCOUNT_TYPE), NULL);
menu_items = gtk_check_menu_item_new_with_mnemonic(alias);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
g_object_set_data( G_OBJECT( menu_items ) , "account" , acc );
g_free( alias );
if( account_list_get_current() == NULL ){
if( account_list_get_current() != NULL ){
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items),
(g_strcasecmp( acc->accountID , account_list_get_default()) == 0)? TRUE : FALSE);
}
else{
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menu_items),
(g_strcasecmp( acc->accountID , account_list_get_current()) == 0)? TRUE : FALSE);
(g_strcasecmp( acc->accountID , account_list_get_current()->accountID) == 0)? TRUE : FALSE);
}
g_signal_connect (G_OBJECT (menu_items), "activate",
G_CALLBACK (switch_account),
NULL);
gtk_widget_show (menu_items);
}
} // fi
}
}
......
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