~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to gnome/src/config/accountlistconfigdialog.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
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>
5
5
 *
38
38
#include "actions.h"
39
39
#include "mainwindow.h"
40
40
#include "utils.h"
 
41
#include "presence.h"
41
42
#include <glib/gi18n.h>
42
43
#include <string.h>
43
44
 
52
53
static GtkDialog *account_list_dialog;
53
54
 
54
55
// Account properties
55
 
enum {
 
56
typedef enum {
56
57
    COLUMN_ACCOUNT_ALIAS,
57
58
    COLUMN_ACCOUNT_TYPE,
58
59
    COLUMN_ACCOUNT_STATUS,
59
60
    COLUMN_ACCOUNT_ACTIVE,
60
61
    COLUMN_ACCOUNT_ID,
61
62
    COLUMN_ACCOUNT_COUNT
62
 
};
 
63
} column_t;
63
64
 
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 */
66
67
static gchar *
67
 
get_selected_accountID(GtkTreeView *tree_view)
 
68
get_selected_account_column(GtkTreeView *tree_view, column_t column)
68
69
{
 
70
    g_assert(column == COLUMN_ACCOUNT_ALIAS || column == COLUMN_ACCOUNT_ID);
 
71
 
69
72
    GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
70
73
    GtkTreeSelection *selection = gtk_tree_view_get_selection(tree_view);
71
74
 
75
78
    // The Gvalue will be initialized in the following function
76
79
    GValue val;
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);
79
82
 
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;
 
85
    return result;
83
86
}
84
87
 
 
88
 
85
89
static gboolean
86
90
find_account_in_account_store(const gchar *accountID, GtkTreeModel *model,
87
91
                              GtkTreeIter *iter)
100
104
    return found;
101
105
}
102
106
 
103
 
 
104
 
static void delete_account_cb(G_GNUC_UNUSED GtkButton *button, gpointer data)
105
 
{
106
 
    gchar *selected_accountID = get_selected_accountID(data);
107
 
    g_return_if_fail(selected_accountID != NULL);
 
107
static gboolean
 
108
confirm_account_deletion(GtkWidget *window, const gchar *alias)
 
109
{
 
110
    gchar *msg;
 
111
    if (strlen(alias) > 0)
 
112
        msg = g_markup_printf_escaped(_("Are you sure want to delete \"%s\"?"), alias);
 
113
    else
 
114
        msg = g_markup_printf_escaped(_("Are you sure want to delete account?"));
 
115
 
 
116
    /* Create the widgets */
 
117
    GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window),
 
118
            GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
119
            GTK_MESSAGE_WARNING,
 
120
            GTK_BUTTONS_CANCEL,
 
121
            "%s", msg);
 
122
 
 
123
    gtk_dialog_add_buttons(GTK_DIALOG(dialog), _("Remove"), GTK_RESPONSE_OK, NULL);
 
124
 
 
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);
 
128
 
 
129
    g_free(msg);
 
130
 
 
131
    return response == GTK_RESPONSE_OK;
 
132
}
 
133
 
 
134
 
 
135
static void delete_account_cb(GtkButton *button, gpointer data)
 
136
{
 
137
    GtkWidget *window = g_object_get_data(G_OBJECT(button), "window");
 
138
 
 
139
    gchar *account_name = get_selected_account_column(data, COLUMN_ACCOUNT_ALIAS);
 
140
    g_return_if_fail(account_name != NULL);
 
141
 
 
142
    const gboolean confirmed = confirm_account_deletion(window, account_name);
 
143
    g_free(account_name);
 
144
    if (!confirmed)
 
145
        return;
 
146
 
 
147
    gchar *account_id = get_selected_account_column(data, COLUMN_ACCOUNT_ID);
 
148
 
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);
112
153
 
113
 
    dbus_remove_account(selected_accountID);
114
 
    g_free(selected_accountID);
 
154
    dbus_remove_account(account_id);
 
155
    g_free(account_id);
115
156
}
116
157
 
117
158
static void account_store_fill();
119
160
static void
120
161
run_account_dialog(const gchar *selected_accountID, SFLPhoneClient *client, gboolean is_new)
121
162
{
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);
 
164
    if (dialog) {
 
165
        update_account_from_dialog(dialog, selected_accountID);
 
166
        account_store_fill();
 
167
    }
126
168
}
127
169
 
128
170
static void row_activated_cb(GtkTreeView *view,
130
172
                             G_GNUC_UNUSED GtkTreeViewColumn *col,
131
173
                             SFLPhoneClient *client)
132
174
{
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);
143
185
 
144
186
static void edit_account_cb(G_GNUC_UNUSED GtkButton *button, EditData *data)
145
187
{
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);
270
312
 
271
313
    // Store value
272
314
    gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_ACCOUNT_ACTIVE,
273
 
                       enable, -1);
 
315
                      enable, -1);
274
316
 
275
317
    // Modify account state
276
318
    const gchar * enabled_str = enable ? "true" : "false";
543
585
 
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);
608
651
 
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);
 
658
    }
 
659
}
 
660
 
 
661
void dialog_destroy_cb()
 
662
{
 
663
#ifdef SFL_PRESENCE
 
664
    // update ui
 
665
    update_presence_statusbar();
 
666
#endif
613
667
}
614
668
 
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);
630
686
 
631
687
    /* Accounts tab */
632
688
    GtkWidget *tab = create_account_list(client);