Skip to content
Snippets Groups Projects
Commit 613faa40 authored by pierre-luc's avatar pierre-luc
Browse files

Merge branch 'pierre-luc'

parents 115b44fe a0a5d19f
Branches
Tags
No related merge requests found
/*
* Copyright (C) 2007 Savoir-Faire Linux inc.
* Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
* Author: Pierre-Luc Bacon <pierre-luc.bacon@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 <accountlistconfigdialog.h>
#include <dbus/dbus.h>
#include <actions.h>
#include <utils.h>
#define CONTEXT_ID_REGISTRATION 0
GtkWidget *addButton;
GtkWidget *editButton;
GtkWidget *deleteButton;
GtkWidget *restoreButton;
GtkWidget *accountMoveDownButton;
GtkWidget *accountMoveUpButton;
GtkWidget * status_bar;
GtkListStore * accountStore;
GtkDialog * accountListDialog = NULL;
account_t * selectedAccount = NULL;
// Account properties
enum {
COLUMN_ACCOUNT_ALIAS,
COLUMN_ACCOUNT_TYPE,
COLUMN_ACCOUNT_STATUS,
COLUMN_ACCOUNT_ACTIVE,
COLUMN_ACCOUNT_DATA,
COLUMN_ACCOUNT_COUNT
};
/**
* Fills the treelist with accounts
*/
void
account_list_config_dialog_fill()
{
if (accountListDialog == NULL) {
DEBUG("Dialog is not opened");
return;
}
GtkTreeIter iter;
gtk_list_store_clear(accountStore);
unsigned int i;
for(i = 0; i < account_list_get_size(); i++) {
account_t * a = account_list_get_nth (i);
if (a) {
gtk_list_store_append (accountStore, &iter);
DEBUG("Filling accounts: Account is enabled :%s", g_hash_table_lookup(a->properties, ACCOUNT_ENABLED));
gtk_list_store_set(accountStore, &iter,
COLUMN_ACCOUNT_ALIAS, g_hash_table_lookup(a->properties, ACCOUNT_ALIAS), // Name
COLUMN_ACCOUNT_TYPE, g_hash_table_lookup(a->properties, ACCOUNT_TYPE), // Protocol
COLUMN_ACCOUNT_STATUS, account_state_name(a->state), // Status
COLUMN_ACCOUNT_ACTIVE, (g_strcasecmp(g_hash_table_lookup(a->properties, ACCOUNT_ENABLED),"true") == 0)? TRUE:FALSE, // Enable/Disable
COLUMN_ACCOUNT_DATA, a, // Pointer
-1);
}
}
}
/**
* Delete an account
*/
static void
delete_account_cb(GtkWidget *widget UNUSED, gpointer data UNUSED)
{
if(selectedAccount != NULL) {
dbus_remove_account(selectedAccount->accountID);
}
}
/**
* Edit an account
*/
static void
edit_account_cb(GtkWidget *widget UNUSED, gpointer data UNUSED)
{
if(selectedAccount != NULL)
{
show_account_window(selectedAccount);
}
}
/**
* Add an account
*/
static void
add_account_cb(GtkWidget *widget UNUSED, gpointer data UNUSED)
{
show_account_window(NULL);
}
/**
* Call back when the user click on an account in the list
*/
static void
select_account_cb(GtkTreeSelection *selection, GtkTreeModel *model)
{
GtkTreeIter iter;
GValue val;
memset (&val, 0, sizeof(val));
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);
gtk_widget_set_sensitive(GTK_WIDGET(editButton), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(deleteButton), FALSE);
return;
}
// The Gvalue will be initialized in the following function
gtk_tree_model_get_value(model, &iter, COLUMN_ACCOUNT_DATA, &val);
selectedAccount = (account_t*)g_value_get_pointer(&val);
g_value_unset(&val);
if(selectedAccount != NULL)
{
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveUpButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveDownButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(editButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(deleteButton), TRUE);
/* Update status bar about current registration state */
gtk_statusbar_pop(status_bar, CONTEXT_ID_REGISTRATION);
if (selectedAccount->protocol_state_description != NULL
&& selectedAccount->protocol_state_code != 0) {
gchar code[4];
g_snprintf(code, 4, "%d", selectedAccount->protocol_state_code);
gchar * message = g_strconcat(
account_state_name(selectedAccount->state),
". ",
_("Server returned \""),
selectedAccount->protocol_state_description,
"\" (",
code,
") ",
NULL);
gtk_statusbar_push(status_bar, CONTEXT_ID_REGISTRATION, message);
g_free(message);
} else {
gchar * state = account_state_name(selectedAccount->state);
gtk_statusbar_push(status_bar, CONTEXT_ID_REGISTRATION, state);
}
}
DEBUG("Selecting account in account window");
}
static void
enable_account_cb(GtkCellRendererToggle *rend UNUSED, gchar* path, gpointer data )
{
GtkTreeIter iter;
GtkTreePath *treePath;
GtkTreeModel *model;
gboolean enable;
account_t* acc ;
// Get pointer on object
treePath = gtk_tree_path_new_from_string(path);
model = gtk_tree_view_get_model(GTK_TREE_VIEW(data));
gtk_tree_model_get_iter(model, &iter, treePath);
gtk_tree_model_get(model, &iter,
COLUMN_ACCOUNT_ACTIVE, &enable,
COLUMN_ACCOUNT_DATA, &acc,
-1);
enable = !enable;
DEBUG("Account is %d enabled", enable);
// Store value
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
COLUMN_ACCOUNT_ACTIVE, enable,
-1);
// Modify account state
gchar * registrationState;
if (enable == TRUE) {
registrationState = g_strdup("true");
} else {
registrationState = g_strdup("false");
}
DEBUG("Replacing with %s", registrationState);
g_hash_table_replace( acc->properties , g_strdup(ACCOUNT_ENABLED), registrationState);
dbus_send_register(acc->accountID, enable);
}
/**
* 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);
// Set the order in the configuration file
dbus_set_accounts_order (account_list_get_ordered_list ());
}
/**
* Called from move up account button signal
*/
static void
account_move_up_cb(GtkButton *button UNUSED, gpointer data)
{
// Change tree view ordering and get indice changed
account_move(TRUE, data);
}
/**
* Called from move down account button signal
*/
static void
account_move_down_cb(GtkButton *button UNUSED, gpointer data)
{
// Change tree view ordering and get indice changed
account_move(FALSE, data);
}
static void
help_contents_cb (GtkWidget * widget,
gpointer data UNUSED)
{
GError *error = NULL;
gboolean success = gtk_show_uri (NULL, "ghelp: sflphone.xml", GDK_CURRENT_TIME, &error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
}
}
static void
close_dialog_cb (GtkWidget * widget,
gpointer data UNUSED)
{
gtk_dialog_response(GTK_DIALOG(accountListDialog), GTK_RESPONSE_ACCEPT);
}
/**
* Account settings tab
*/
GtkWidget *
create_account_list(GtkDialog * dialog)
{
GtkWidget *table;
GtkWidget *scrolledWindow;
GtkWidget *buttonBox;
GtkCellRenderer *renderer;
GtkTreeView * treeView;
GtkTreeViewColumn *treeViewColumn;
GtkTreeSelection *treeSelection;
GtkRequisition requisition;
selectedAccount = NULL;
table = gtk_table_new (1, 2, FALSE/* homogeneous */);
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
gtk_container_set_border_width(GTK_TABLE(table), 10);
scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_SHADOW_IN);
gtk_table_attach (GTK_TABLE(table), scrolledWindow, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
accountStore = gtk_list_store_new(COLUMN_ACCOUNT_COUNT,
G_TYPE_STRING, // Name
G_TYPE_STRING, // Protocol
G_TYPE_STRING, // Status
G_TYPE_BOOLEAN, // Enabled / Disabled
G_TYPE_POINTER // Pointer to the Object
);
treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(accountStore));
treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW (treeView));
g_signal_connect(G_OBJECT (treeSelection), "changed",
G_CALLBACK (select_account_cb),
accountStore);
renderer = gtk_cell_renderer_toggle_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes("Enabled", 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_cb), (gpointer)treeView );
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);
// 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_cb ) , NULL );
renderer = gtk_cell_renderer_text_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes (_("Protocol"),
renderer,
"markup", COLUMN_ACCOUNT_TYPE,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeView), treeViewColumn);
renderer = gtk_cell_renderer_text_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes (_("Status"),
renderer,
"markup", COLUMN_ACCOUNT_STATUS,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeView), treeViewColumn);
g_object_unref(G_OBJECT(accountStore));
gtk_container_add(GTK_CONTAINER(scrolledWindow), treeView);
/* The buttons to press! */
buttonBox = gtk_vbutton_box_new();
gtk_box_set_spacing(GTK_BOX(buttonBox), 10);
gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_START);
gtk_table_attach (GTK_TABLE(table), buttonBox, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 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_cb), 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_cb), treeView);
addButton = gtk_button_new_from_stock (GTK_STOCK_ADD);
g_signal_connect_swapped(G_OBJECT(addButton), "clicked",
G_CALLBACK(add_account_cb), NULL);
gtk_box_pack_start(GTK_BOX(buttonBox), addButton, FALSE, FALSE, 0);
editButton = gtk_button_new_from_stock (GTK_STOCK_EDIT);
gtk_widget_set_sensitive(GTK_WIDGET(editButton), FALSE);
g_signal_connect_swapped(G_OBJECT(editButton), "clicked",
G_CALLBACK(edit_account_cb), NULL);
gtk_box_pack_start(GTK_BOX(buttonBox), editButton, FALSE, FALSE, 0);
deleteButton = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
gtk_widget_set_sensitive(GTK_WIDGET(deleteButton), FALSE);
g_signal_connect_swapped(G_OBJECT(deleteButton), "clicked",
G_CALLBACK(delete_account_cb), NULL);
gtk_box_pack_start(GTK_BOX(buttonBox), deleteButton, FALSE, FALSE, 0);
/* help and close buttons */
GtkWidget * buttonHbox = gtk_hbutton_box_new();
gtk_table_attach(GTK_TABLE(table), buttonHbox, 0, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 10);
GtkWidget * helpButton = gtk_button_new_from_stock (GTK_STOCK_HELP);
g_signal_connect_swapped(G_OBJECT(helpButton), "clicked",
G_CALLBACK(help_contents_cb), NULL);
gtk_box_pack_start(GTK_BOX(buttonHbox), helpButton, FALSE, FALSE, 0);
GtkWidget * closeButton = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
g_signal_connect_swapped(G_OBJECT(closeButton), "clicked", G_CALLBACK(close_dialog_cb), NULL);
gtk_box_pack_start(GTK_BOX(buttonHbox), closeButton, FALSE, FALSE, 0);
gtk_widget_show_all(table);
account_list_config_dialog_fill();
/* Resize the scrolledWindow for a better view */
gtk_widget_size_request(GTK_WIDGET(treeView), &requisition);
gtk_widget_set_size_request(GTK_WIDGET(scrolledWindow), requisition.width + 20, requisition.height);
GtkRequisition requisitionButton;
gtk_widget_size_request(GTK_WIDGET(deleteButton), &requisitionButton);
gtk_widget_set_size_request(GTK_WIDGET(closeButton), requisitionButton.width, -1);
gtk_widget_set_size_request(GTK_WIDGET(helpButton), requisitionButton.width, -1);
gtk_widget_show_all(table);
return table;
}
void
show_account_list_config_dialog(void)
{
GtkWidget * accountFrame;
GtkWidget * tab;
accountListDialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Accounts"),
GTK_WINDOW(get_main_window()),
GTK_DIALOG_DESTROY_WITH_PARENT,
NULL));
/* Set window properties */
gtk_dialog_set_has_separator(accountListDialog, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(accountListDialog), 0);
gnome_main_section_new (_("Configured Accounts"), &accountFrame);
gtk_box_pack_start( GTK_BOX(accountListDialog->vbox ), accountFrame , TRUE, TRUE, 0);
gtk_widget_show(accountFrame);
/* Accounts tab */
tab = create_account_list(accountListDialog);
gtk_widget_show(tab);
gtk_container_add(GTK_CONTAINER(accountFrame), tab);
/* Status bar for the account list */
status_bar = gtk_statusbar_new();
gtk_widget_show(status_bar);
gtk_box_pack_start(GTK_BOX(accountListDialog->vbox ), status_bar, TRUE, TRUE, 0);
gtk_dialog_run(accountListDialog);
status_bar_display_account ();
gtk_widget_destroy(GTK_WIDGET(accountListDialog));
accountListDialog = NULL;
toolbar_update_buttons();
}
/*
* Copyright (C) 2007 Savoir-Faire Linux inc.
* Author: Pierre-Luc Bacon <pierre-luc.bacon@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 __SFL_ACCOUNTLISTDIALOG_H__
#define __SFL_ACCOUNTLISTDIALOG_H__
void show_account_list_config_dialog(void);
void account_list_config_dialog_fill(void);
#endif
...@@ -45,16 +45,6 @@ gboolean accDialogOpen = FALSE; ...@@ -45,16 +45,6 @@ gboolean accDialogOpen = FALSE;
gboolean dialogOpen = FALSE; gboolean dialogOpen = FALSE;
gboolean ringtoneEnabled = TRUE; gboolean ringtoneEnabled = TRUE;
GtkListStore *accountStore;
// instead of keeping selected codec as a variable
GtkWidget *addButton;
GtkWidget *editButton;
GtkWidget *deleteButton;
GtkWidget *restoreButton;
GtkWidget *accountMoveDownButton;
GtkWidget *accountMoveUpButton;
/* STUN configuration part */ /* STUN configuration part */
GtkWidget * stunEnable; GtkWidget * stunEnable;
GtkWidget * stunFrame; GtkWidget * stunFrame;
...@@ -67,95 +57,16 @@ GtkWidget * status; ...@@ -67,95 +57,16 @@ GtkWidget * status;
static int history_limit; static int history_limit;
static gboolean history_enabled = TRUE; static gboolean history_enabled = TRUE;
account_t * selectedAccount = NULL;
GHashTable * directIpCallsProperties = NULL;
GtkDialog * accountListDialog;
// Account properties
enum {
COLUMN_ACCOUNT_ALIAS,
COLUMN_ACCOUNT_TYPE,
COLUMN_ACCOUNT_STATUS,
COLUMN_ACCOUNT_ACTIVE,
COLUMN_ACCOUNT_DATA,
COLUMN_ACCOUNT_COUNT
};
// Mail notification // Mail notification
GtkWidget * widg; GtkWidget * widg;
GHashTable * directIpCallsProperties = NULL;
static void update_port_cb ( GtkSpinButton *button UNUSED, void *ptr )
/**
* Fills the treelist with accounts
*/
void
config_window_fill_account_list()
{
if(accDialogOpen) {
GtkTreeIter iter;
gtk_list_store_clear(accountStore);
unsigned int i;
for(i = 0; i < account_list_get_size(); i++) {
account_t * a = account_list_get_nth (i);
if (a) {
gtk_list_store_append (accountStore, &iter);
DEBUG("Filling accounts: Account is enabled :%s", g_hash_table_lookup(a->properties, ACCOUNT_ENABLED));
gtk_list_store_set(accountStore, &iter,
COLUMN_ACCOUNT_ALIAS, g_hash_table_lookup(a->properties, ACCOUNT_ALIAS), // Name
COLUMN_ACCOUNT_TYPE, g_hash_table_lookup(a->properties, ACCOUNT_TYPE), // Protocol
COLUMN_ACCOUNT_STATUS, account_state_name(a->state), // Status
COLUMN_ACCOUNT_ACTIVE, (g_strcasecmp(g_hash_table_lookup(a->properties, ACCOUNT_ENABLED),"true") == 0)? TRUE:FALSE, // Enable/Disable
COLUMN_ACCOUNT_DATA, a, // Pointer
-1);
}
}
}
}
/**
* Delete an account
*/
static void
delete_account(GtkWidget *widget UNUSED, gpointer data UNUSED)
{
if(selectedAccount != NULL)
{
dbus_remove_account(selectedAccount->accountID);
if(account_list_get_sip_account_number() == 1 &&
strcmp(g_hash_table_lookup(selectedAccount->properties, ACCOUNT_TYPE), "SIP")==0 )
gtk_widget_set_sensitive(GTK_WIDGET(stunFrame), FALSE);
}
}
/**
* Edit an account
*/
static void
edit_account(GtkWidget *widget UNUSED, gpointer data UNUSED)
{
if(selectedAccount != NULL)
{ {
show_account_window(selectedAccount); dbus_set_sip_port(gtk_spin_button_get_value_as_int((GtkSpinButton *)(ptr)));
}
} }
/**
* Add an account
*/
static void
add_account(GtkWidget *widget UNUSED, gpointer data UNUSED)
{
show_account_window(NULL);
}
static void static void
set_md5_hash_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) set_md5_hash_cb(GtkWidget *widget UNUSED, gpointer data UNUSED)
...@@ -218,324 +129,6 @@ clean_history( void ) ...@@ -218,324 +129,6 @@ clean_history( void )
calllist_clean_history(); calllist_clean_history();
} }
/**
* Call back when the user click on an account in the list
*/
static void
select_account(GtkTreeSelection *selection, GtkTreeModel *model)
{
GtkTreeIter iter;
GValue val;
memset (&val, 0, sizeof(val));
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);
gtk_widget_set_sensitive(GTK_WIDGET(editButton), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(deleteButton), FALSE);
return;
}
// The Gvalue will be initialized in the following function
gtk_tree_model_get_value(model, &iter, COLUMN_ACCOUNT_DATA, &val);
selectedAccount = (account_t*)g_value_get_pointer(&val);
g_value_unset(&val);
if(selectedAccount != NULL)
{
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveUpButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(accountMoveDownButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(editButton), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(deleteButton), TRUE);
}
DEBUG("Selecting account in account window");
}
static void
enable_account(GtkCellRendererToggle *rend UNUSED, gchar* path, gpointer data )
{
GtkTreeIter iter;
GtkTreePath *treePath;
GtkTreeModel *model;
gboolean enable;
account_t* acc ;
// Get pointer on object
treePath = gtk_tree_path_new_from_string(path);
model = gtk_tree_view_get_model(GTK_TREE_VIEW(data));
gtk_tree_model_get_iter(model, &iter, treePath);
gtk_tree_model_get(model, &iter,
COLUMN_ACCOUNT_ACTIVE, &enable,
COLUMN_ACCOUNT_DATA, &acc,
-1);
enable = !enable;
DEBUG("Account is %d enabled", enable);
// Store value
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
COLUMN_ACCOUNT_ACTIVE, enable,
-1);
// Modify account state
gchar * registrationState;
if (enable == TRUE) {
registrationState = g_strdup("true");
} else {
registrationState = g_strdup("false");
}
DEBUG("Replacing with %s\n", registrationState);
g_hash_table_replace( acc->properties , g_strdup(ACCOUNT_ENABLED), registrationState);
dbus_send_register(acc->accountID, enable);
}
/**
* 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);
// Set the order in the configuration file
dbus_set_accounts_order (account_list_get_ordered_list ());
}
/**
* Called from move up account button signal
*/
static void
account_move_up(GtkButton *button UNUSED, gpointer data)
{
// 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 UNUSED, gpointer data)
{
// Change tree view ordering and get indice changed
account_move(FALSE, data);
}
static void update_port_cb ( GtkSpinButton *button UNUSED, void *ptr )
{
dbus_set_sip_port(gtk_spin_button_get_value_as_int((GtkSpinButton *)(ptr)));
}
static void
help_contents_cb (GtkWidget * widget,
gpointer data UNUSED)
{
GError *error = NULL;
gboolean success = gtk_show_uri (NULL, "ghelp: sflphone.xml", GDK_CURRENT_TIME, &error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
}
}
static void
close_dialog_cb (GtkWidget * widget,
gpointer data UNUSED)
{
gtk_dialog_response(GTK_DIALOG(accountListDialog), GTK_RESPONSE_ACCEPT);
}
/**
* Account settings tab
*/
GtkWidget *
create_accounts_tab(GtkDialog * dialog)
{
GtkWidget *table;
GtkWidget *scrolledWindow;
GtkWidget *buttonBox;
GtkCellRenderer *renderer;
GtkTreeView * treeView;
GtkTreeViewColumn *treeViewColumn;
GtkTreeSelection *treeSelection;
GtkRequisition requisition;
selectedAccount = NULL;
table = gtk_table_new (1, 2, FALSE/* homogeneous */);
gtk_table_set_col_spacings(GTK_TABLE(table), 10);
gtk_container_set_border_width(GTK_TABLE(table), 10);
scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledWindow), GTK_SHADOW_IN);
gtk_table_attach (GTK_TABLE(table), scrolledWindow, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
accountStore = gtk_list_store_new(COLUMN_ACCOUNT_COUNT,
G_TYPE_STRING, // Name
G_TYPE_STRING, // Protocol
G_TYPE_STRING, // Status
G_TYPE_BOOLEAN, // Enabled / Disabled
G_TYPE_POINTER // Pointer to the Object
);
treeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(accountStore));
treeSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW (treeView));
g_signal_connect(G_OBJECT (treeSelection), "changed",
G_CALLBACK (select_account),
accountStore);
renderer = gtk_cell_renderer_toggle_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes("Enabled", 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 );
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);
// 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 );
renderer = gtk_cell_renderer_text_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes (_("Protocol"),
renderer,
"markup", COLUMN_ACCOUNT_TYPE,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeView), treeViewColumn);
renderer = gtk_cell_renderer_text_new();
treeViewColumn = gtk_tree_view_column_new_with_attributes (_("Status"),
renderer,
"markup", COLUMN_ACCOUNT_STATUS,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeView), treeViewColumn);
g_object_unref(G_OBJECT(accountStore));
gtk_container_add(GTK_CONTAINER(scrolledWindow), treeView);
/* The buttons to press! */
buttonBox = gtk_vbutton_box_new();
gtk_box_set_spacing(GTK_BOX(buttonBox), 10);
gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_START);
gtk_table_attach (GTK_TABLE(table), buttonBox, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 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);
addButton = gtk_button_new_from_stock (GTK_STOCK_ADD);
g_signal_connect_swapped(G_OBJECT(addButton), "clicked",
G_CALLBACK(add_account), NULL);
gtk_box_pack_start(GTK_BOX(buttonBox), addButton, FALSE, FALSE, 0);
editButton = gtk_button_new_from_stock (GTK_STOCK_EDIT);
gtk_widget_set_sensitive(GTK_WIDGET(editButton), FALSE);
g_signal_connect_swapped(G_OBJECT(editButton), "clicked",
G_CALLBACK(edit_account), NULL);
gtk_box_pack_start(GTK_BOX(buttonBox), editButton, FALSE, FALSE, 0);
deleteButton = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
gtk_widget_set_sensitive(GTK_WIDGET(deleteButton), FALSE);
g_signal_connect_swapped(G_OBJECT(deleteButton), "clicked",
G_CALLBACK(delete_account), stunFrame);
gtk_box_pack_start(GTK_BOX(buttonBox), deleteButton, FALSE, FALSE, 0);
/* help and close buttons */
GtkWidget * buttonHbox = gtk_hbutton_box_new();
gtk_table_attach(GTK_TABLE(table), buttonHbox, 0, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 10);
GtkWidget * helpButton = gtk_button_new_from_stock (GTK_STOCK_HELP);
g_signal_connect_swapped(G_OBJECT(helpButton), "clicked",
G_CALLBACK(help_contents_cb), NULL);
gtk_box_pack_start(GTK_BOX(buttonHbox), helpButton, FALSE, FALSE, 0);
GtkWidget * closeButton = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
g_signal_connect_swapped(G_OBJECT(closeButton), "clicked", G_CALLBACK(close_dialog_cb), NULL);
gtk_box_pack_start(GTK_BOX(buttonHbox), closeButton, FALSE, FALSE, 0);
gtk_widget_show_all(table);
config_window_fill_account_list();
/* Resize the scrolledWindow for a better view */
gtk_widget_size_request(GTK_WIDGET(treeView), &requisition);
gtk_widget_set_size_request(GTK_WIDGET(scrolledWindow), requisition.width + 20, requisition.height);
GtkRequisition requisitionButton;
gtk_widget_size_request(GTK_WIDGET(deleteButton), &requisitionButton);
gtk_widget_set_size_request(GTK_WIDGET(closeButton), requisitionButton.width, -1);
gtk_widget_set_size_request(GTK_WIDGET(helpButton), requisitionButton.width, -1);
gtk_widget_show_all(table);
return table;
}
void stun_state( void ) void stun_state( void )
{ {
...@@ -881,11 +474,24 @@ void save_configuration_parameters (void) { ...@@ -881,11 +474,24 @@ void save_configuration_parameters (void) {
dbus_set_ip2ip_details(directIpCallsProperties); dbus_set_ip2ip_details(directIpCallsProperties);
} }
void history_load_configuration ()
{
history_limit = dbus_get_history_limit ();
history_enabled = TRUE;
if (dbus_get_history_enabled () == 0)
history_enabled = FALSE;
}
void preferences_dialog_set_stun_visible()
{
gtk_widget_set_sensitive( GTK_WIDGET(stunFrame), TRUE );
}
/** /**
* Show configuration window with tabs * Show configuration window with tabs
*/ */
void void
show_config_window () show_preferences_dialog ()
{ {
GtkDialog * dialog; GtkDialog * dialog;
GtkWidget * notebook; GtkWidget * notebook;
...@@ -954,55 +560,3 @@ show_config_window () ...@@ -954,55 +560,3 @@ show_config_window ()
gtk_widget_destroy(GTK_WIDGET(dialog)); gtk_widget_destroy(GTK_WIDGET(dialog));
} }
/*
* Show accounts tab in a different window
*/
void
show_accounts_window( void )
{
GtkWidget * accountFrame;
GtkWidget * tab;
accDialogOpen = TRUE;
accountListDialog = GTK_DIALOG(gtk_dialog_new_with_buttons (_("Accounts"),
GTK_WINDOW(get_main_window()),
GTK_DIALOG_DESTROY_WITH_PARENT,
NULL));
// Set window properties
gtk_dialog_set_has_separator(accountListDialog, FALSE);
gtk_container_set_border_width(GTK_CONTAINER(accountListDialog), 0);
gnome_main_section_new (_("Configured Accounts"), &accountFrame);
gtk_box_pack_start( GTK_BOX( accountListDialog->vbox ), accountFrame , TRUE, TRUE, 0);
gtk_widget_show(accountFrame);
// Accounts tab
tab = create_accounts_tab(accountListDialog);
gtk_widget_show(tab);
gtk_container_add(GTK_CONTAINER(accountFrame), tab);
gtk_dialog_run(accountListDialog);
status_bar_display_account ();
accDialogOpen=FALSE;
gtk_widget_destroy(GTK_WIDGET(accountListDialog));
toolbar_update_buttons();
}
void history_load_configuration ()
{
history_limit = dbus_get_history_limit ();
history_enabled = TRUE;
if (dbus_get_history_enabled () == 0)
history_enabled = FALSE;
}
void config_window_set_stun_visible()
{
gtk_widget_set_sensitive( GTK_WIDGET(stunFrame), TRUE );
}
...@@ -23,35 +23,30 @@ ...@@ -23,35 +23,30 @@
#include <calllist.h> #include <calllist.h>
/** /**
* @file configwindow.h * @file preferencesdialog.h
* @brief The Preferences window. * @brief The Preferences window.
*/ */
/**
* Fill the account list widget with the data the server send
*/
void config_window_fill_account_list();
/** /**
* Fill the codec list widget with the data the server send * Fill the codec list widget with the data the server send
*/ */
void config_window_fill_codec_list(); void preferences_dialog_fill_codec_list();
/** /**
* Fill the input audio plugin list widget with the data the server send * Fill the input audio plugin list widget with the data the server send
* Currently not used * Currently not used
*/ */
void config_window_fill_input_audio_plugin_list(); void preferences_dialog_fill_input_audio_plugin_list();
/** /**
* Fill the output audio plugin list widget with the data the server send * Fill the output audio plugin list widget with the data the server send
*/ */
void config_window_fill_output_audio_plugin_list(); void preferences_dialog_fill_output_audio_plugin_list();
/** /**
* Fill the output audio device list widget with the data the server send * Fill the output audio device list widget with the data the server send
*/ */
void config_window_fill_output_audio_device_list(); void preferences_dialog_fill_output_audio_device_list();
/** /**
* Select an output audio device * Select an output audio device
...@@ -61,7 +56,7 @@ void select_active_output_audio_device(); ...@@ -61,7 +56,7 @@ void select_active_output_audio_device();
/** /**
* Fill the input audio device list widget with the data the server send * Fill the input audio device list widget with the data the server send
*/ */
void config_window_fill_input_audio_device_list(); void preferences_dialog_fill_input_audio_device_list();
/** /**
* Select an input audio device * Select an input audio device
...@@ -107,14 +102,9 @@ GtkWidget * create_recording_settings(); ...@@ -107,14 +102,9 @@ GtkWidget * create_recording_settings();
/** /**
* Display the main configuration window * Display the main configuration window
*/ */
void show_config_window(); void show_preferences_dialog();
/**
* Display the main account window
*/
void show_accounts_window();
void config_window_set_stun_visible(); void preferences_dialog_set_stun_visible();
void save_configuration_parameters (void); void save_configuration_parameters (void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment