2
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
2
* Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3
3
* Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
4
4
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
52
53
static GtkDialog *account_list_dialog;
54
55
// Account properties
56
57
COLUMN_ACCOUNT_ALIAS,
57
58
COLUMN_ACCOUNT_TYPE,
58
59
COLUMN_ACCOUNT_STATUS,
59
60
COLUMN_ACCOUNT_ACTIVE,
61
62
COLUMN_ACCOUNT_COUNT
64
/* Get selected account ID from treeview
65
* @return copied selected_accountID, must be freed by caller */
65
/* Get selected account string field from treeview
66
* @return newly allocated string, must be freed by caller */
67
get_selected_accountID(GtkTreeView *tree_view)
68
get_selected_account_column(GtkTreeView *tree_view, column_t column)
70
g_assert(column == COLUMN_ACCOUNT_ALIAS || column == COLUMN_ACCOUNT_ID);
69
72
GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
70
73
GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
75
78
// The Gvalue will be initialized in the following function
77
80
memset(&val, 0, sizeof(val));
78
gtk_tree_model_get_value(model, &iter, COLUMN_ACCOUNT_ID, &val);
81
gtk_tree_model_get_value(model, &iter, column, &val);
80
gchar *selected_accountID = g_strdup(g_value_get_string(&val));
83
gchar *result = g_strdup(g_value_get_string(&val));
81
84
g_value_unset(&val);
82
return selected_accountID;
86
90
find_account_in_account_store(const gchar *accountID, GtkTreeModel *model,
104
static void delete_account_cb(G_GNUC_UNUSED GtkButton *button, gpointer data)
106
gchar *selected_accountID = get_selected_accountID(data);
107
g_return_if_fail(selected_accountID != NULL);
108
confirm_account_deletion(GtkWidget *window, const gchar *alias)
111
if (strlen(alias) > 0)
112
msg = g_markup_printf_escaped(_("Are you sure want to delete \"%s\"?"), alias);
114
msg = g_markup_printf_escaped(_("Are you sure want to delete account?"));
116
/* Create the widgets */
117
GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window),
118
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
123
gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Remove"), GTK_RESPONSE_OK, NULL);
125
gtk_window_set_title(GTK_WINDOW(dialog), _("Remove account"));
126
const gint response = gtk_dialog_run(GTK_DIALOG(dialog));
127
gtk_widget_destroy(dialog);
131
return response == GTK_RESPONSE_OK;
135
static void delete_account_cb(GtkButton *button, gpointer data)
137
GtkWidget *window = g_object_get_data(G_OBJECT(button), "window");
139
gchar *account_name = get_selected_account_column(data, COLUMN_ACCOUNT_ALIAS);
140
g_return_if_fail(account_name != NULL);
142
const gboolean confirmed = confirm_account_deletion(window, account_name);
143
g_free(account_name);
147
gchar *account_id = get_selected_account_column(data, COLUMN_ACCOUNT_ID);
108
149
GtkTreeModel *model = GTK_TREE_MODEL(account_store);
109
150
GtkTreeIter iter;
110
if (find_account_in_account_store(selected_accountID, model, &iter))
151
if (find_account_in_account_store(account_id, model, &iter))
111
152
gtk_list_store_remove(account_store, &iter);
113
dbus_remove_account(selected_accountID);
114
g_free(selected_accountID);
154
dbus_remove_account(account_id);
117
158
static void account_store_fill();
120
161
run_account_dialog(const gchar *selected_accountID, SFLPhoneClient *client, gboolean is_new)
122
account_t *account = account_list_get_by_id(selected_accountID);
123
GtkWidget *dialog = show_account_window(account, client, is_new);
124
update_account_from_dialog(dialog, account);
125
account_store_fill();
163
GtkWidget *dialog = show_account_window(selected_accountID, account_list_dialog, client, is_new);
165
update_account_from_dialog(dialog, selected_accountID);
166
account_store_fill();
128
170
static void row_activated_cb(GtkTreeView *view,
130
172
G_GNUC_UNUSED GtkTreeViewColumn *col,
131
173
SFLPhoneClient *client)
133
gchar *selected_accountID = get_selected_accountID(view);
175
gchar *selected_accountID = get_selected_account_column(view, COLUMN_ACCOUNT_ID);
134
176
g_return_if_fail(selected_accountID != NULL);
135
177
run_account_dialog(selected_accountID, client, FALSE);
136
178
g_free(selected_accountID);
144
186
static void edit_account_cb(G_GNUC_UNUSED GtkButton *button, EditData *data)
146
gchar *selected_accountID = get_selected_accountID(GTK_TREE_VIEW(data->view));
188
gchar *selected_accountID = get_selected_account_column(GTK_TREE_VIEW(data->view), COLUMN_ACCOUNT_ID);
147
189
g_return_if_fail(selected_accountID != NULL);
148
190
run_account_dialog(selected_accountID, data->client, FALSE);
149
191
g_free(selected_accountID);
544
586
delete_button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
545
587
gtk_widget_set_sensitive(delete_button, FALSE);
588
g_object_set_data(G_OBJECT(delete_button), "window", client->win);
546
589
g_signal_connect(G_OBJECT(delete_button), "clicked",
547
590
G_CALLBACK(delete_account_cb), tree_view);
548
591
gtk_box_pack_start(GTK_BOX(button_box), delete_button, FALSE, FALSE, 0);
609
652
GtkTreeModel *model = GTK_TREE_MODEL(account_store);
610
653
GtkTreeIter iter;
611
if (find_account_in_account_store(account->accountID, model, &iter))
654
if (find_account_in_account_store(account->accountID, model, &iter)) {
612
655
gtk_list_store_set(account_store, &iter, COLUMN_ACCOUNT_STATUS, state_name, -1);
656
gtk_list_store_set(account_store, &iter, COLUMN_ACCOUNT_ACTIVE,
657
account->state == ACCOUNT_STATE_REGISTERED, -1);
661
void dialog_destroy_cb()
665
update_presence_statusbar();
615
669
void show_account_list_config_dialog(SFLPhoneClient *client)
627
681
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(account_list_dialog)),
628
682
accountFrame, TRUE, TRUE, 0);
629
683
gtk_widget_show(accountFrame);
684
g_signal_connect(G_OBJECT(account_list_dialog), "destroy",
685
G_CALLBACK(dialog_destroy_cb), NULL);
631
687
/* Accounts tab */
632
688
GtkWidget *tab = create_account_list(client);