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

« back to all changes in this revision

Viewing changes to gnome/src/config/hooks-config.c

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2011-11-25 13:24:12 UTC
  • mfrom: (4.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20111125132412-dc4qvhyosk74cd42
Tags: 1.0.1-4
Don't assume that arch:all packages will get built (closes: #649726)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
 
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 3 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 *
 
19
 *  Additional permission under GNU GPL version 3 section 7:
 
20
 *
 
21
 *  If you modify this program, or any covered work, by linking or
 
22
 *  combining it with the OpenSSL project's OpenSSL library (or a
 
23
 *  modified version of that library), containing parts covered by the
 
24
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 
25
 *  grants you additional permission to convey the resulting work.
 
26
 *  Corresponding Source for a non-source form of such a combination
 
27
 *  shall include the source code for the parts of OpenSSL used as well
 
28
 *  as that of the covered work.
 
29
 */
 
30
 
 
31
#include "hooks-config.h"
 
32
#include "dbus.h"
 
33
 
 
34
URLHook_Config *_urlhook_config;
 
35
 
 
36
GtkWidget *field, *command, *prefix;
 
37
 
 
38
void hooks_load_parameters(URLHook_Config** settings)
 
39
{
 
40
 
 
41
    GHashTable *_params = NULL;
 
42
    URLHook_Config *_settings;
 
43
 
 
44
    // Allocate a struct
 
45
    _settings = g_new0(URLHook_Config, 1);
 
46
 
 
47
    // Fetch the settings from D-Bus
 
48
    _params = (GHashTable*) dbus_get_hook_settings();
 
49
 
 
50
    if (_params == NULL) {
 
51
        _settings->sip_field = DEFAULT_SIP_URL_FIELD;
 
52
        _settings->command = DEFAULT_URL_COMMAND;
 
53
        _settings->sip_enabled = "false";
 
54
        _settings->iax2_enabled = "false";
 
55
        _settings->phone_number_enabled = "false";
 
56
        _settings->phone_number_prefix = "";
 
57
    } else {
 
58
        _settings->sip_field = (gchar*)(g_hash_table_lookup(_params, URLHOOK_SIP_FIELD));
 
59
        _settings->command = (gchar*)(g_hash_table_lookup(_params, URLHOOK_COMMAND));
 
60
        _settings->sip_enabled = (gchar*)(g_hash_table_lookup(_params, URLHOOK_SIP_ENABLED));
 
61
        _settings->iax2_enabled = (gchar*)(g_hash_table_lookup(_params, URLHOOK_IAX2_ENABLED));
 
62
        _settings->phone_number_enabled = (gchar*)(g_hash_table_lookup(_params, PHONE_NUMBER_HOOK_ENABLED));
 
63
        _settings->phone_number_prefix = (gchar*)(g_hash_table_lookup(_params, PHONE_NUMBER_HOOK_ADD_PREFIX));
 
64
    }
 
65
 
 
66
    *settings = _settings;
 
67
}
 
68
 
 
69
 
 
70
void hooks_save_parameters(void)
 
71
{
 
72
 
 
73
    GHashTable *params = NULL;
 
74
 
 
75
    params = g_hash_table_new(NULL, g_str_equal);
 
76
    g_hash_table_replace(params, (gpointer) URLHOOK_SIP_FIELD,
 
77
                         g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(field))));
 
78
    g_hash_table_replace(params, (gpointer) URLHOOK_COMMAND,
 
79
                         g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(command))));
 
80
    g_hash_table_replace(params, (gpointer) URLHOOK_SIP_ENABLED,
 
81
                         (gpointer) g_strdup(_urlhook_config->sip_enabled));
 
82
    g_hash_table_replace(params, (gpointer) URLHOOK_IAX2_ENABLED,
 
83
                         (gpointer) g_strdup(_urlhook_config->iax2_enabled));
 
84
    g_hash_table_replace(params, (gpointer) PHONE_NUMBER_HOOK_ENABLED,
 
85
                         (gpointer) g_strdup(_urlhook_config->phone_number_enabled));
 
86
    g_hash_table_replace(params, (gpointer) PHONE_NUMBER_HOOK_ADD_PREFIX,
 
87
                         g_strdup((gchar *) gtk_entry_get_text(GTK_ENTRY(prefix))));
 
88
 
 
89
    dbus_set_hook_settings(params);
 
90
 
 
91
    // Decrement the reference count
 
92
    g_hash_table_unref(params);
 
93
 
 
94
}
 
95
 
 
96
static void sip_enabled_cb(GtkWidget *widget)
 
97
{
 
98
 
 
99
    guint check;
 
100
 
 
101
    check = (guint) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
 
102
 
 
103
    if (check)
 
104
        _urlhook_config->sip_enabled="true";
 
105
    else
 
106
        _urlhook_config->sip_enabled="false";
 
107
}
 
108
 
 
109
static void iax2_enabled_cb(GtkWidget *widget)
 
110
{
 
111
 
 
112
    guint check;
 
113
 
 
114
    check = (guint) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
 
115
 
 
116
    if (check)
 
117
        _urlhook_config->iax2_enabled="true";
 
118
    else
 
119
        _urlhook_config->iax2_enabled="false";
 
120
}
 
121
 
 
122
static void phone_number_enabled_cb(GtkWidget *widget)
 
123
{
 
124
 
 
125
    guint check;
 
126
 
 
127
    check = (guint) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
 
128
 
 
129
    if (check) {
 
130
        _urlhook_config->phone_number_enabled="true";
 
131
        gtk_widget_set_sensitive(GTK_WIDGET(prefix), TRUE);
 
132
    } else {
 
133
        _urlhook_config->phone_number_enabled="false";
 
134
        gtk_widget_set_sensitive(GTK_WIDGET(prefix), FALSE);
 
135
    }
 
136
}
 
137
 
 
138
 
 
139
GtkWidget* create_hooks_settings()
 
140
{
 
141
    GtkWidget *ret, *frame, *table, *label, *widg;
 
142
 
 
143
    // Load the user value
 
144
    hooks_load_parameters(&_urlhook_config);
 
145
 
 
146
    ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
 
147
    gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
 
148
 
 
149
    gnome_main_section_new_with_table(_("URL Argument"), &frame, &table, 5, 2);
 
150
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
 
151
    gtk_widget_show(frame);
 
152
 
 
153
    gchar *message = "<small>Custom commands on incoming calls with URL. %s will be replaced with the passed URL.</small>";
 
154
    GtkWidget *info_bar = gnome_info_bar(message, GTK_MESSAGE_INFO);
 
155
    gtk_table_attach(GTK_TABLE(table), info_bar, 0, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 10, 10);
 
156
 
 
157
    widg = gtk_check_button_new_with_mnemonic(_("Trigger on specific _SIP header"));
 
158
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widg), (g_strcasecmp(_urlhook_config->sip_enabled, "true") ==0) ?TRUE:FALSE);
 
159
    g_signal_connect(G_OBJECT(widg) , "clicked" , G_CALLBACK(sip_enabled_cb), NULL);
 
160
    gtk_table_attach(GTK_TABLE(table), widg, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
161
 
 
162
    field = gtk_entry_new();
 
163
    gtk_entry_set_text(GTK_ENTRY(field), _urlhook_config->sip_field);
 
164
    gtk_table_attach(GTK_TABLE(table), field, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
165
 
 
166
    widg = gtk_check_button_new_with_mnemonic(_("Trigger on _IAX2 URL"));
 
167
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widg), (g_strcasecmp(_urlhook_config->iax2_enabled, "true") ==0) ?TRUE:FALSE);
 
168
    g_signal_connect(G_OBJECT(widg) , "clicked" , G_CALLBACK(iax2_enabled_cb), NULL);
 
169
    gtk_table_attach(GTK_TABLE(table), widg, 0, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
170
 
 
171
    label = gtk_label_new_with_mnemonic(_("Command to _run"));
 
172
    gtk_misc_set_alignment(GTK_MISC(label), 0.05, 0.5);
 
173
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
174
    command = gtk_entry_new();
 
175
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), command);
 
176
    gtk_entry_set_text(GTK_ENTRY(command), _urlhook_config->command);
 
177
    gtk_table_attach(GTK_TABLE(table), command, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 10);
 
178
 
 
179
 
 
180
 
 
181
    gnome_main_section_new_with_table(_("Phone number rewriting"), &frame, &table, 4, 2);
 
182
    gtk_box_pack_start(GTK_BOX(ret), frame, FALSE, FALSE, 0);
 
183
    gtk_widget_show(frame);
 
184
 
 
185
    widg = gtk_check_button_new_with_mnemonic(_("_Prefix dialed numbers with"));
 
186
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widg), (g_strcasecmp(_urlhook_config->phone_number_enabled, "true") ==0) ?TRUE:FALSE);
 
187
    g_signal_connect(G_OBJECT(widg) , "clicked" , G_CALLBACK(phone_number_enabled_cb), NULL);
 
188
    gtk_table_attach(GTK_TABLE(table), widg, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
189
 
 
190
    prefix = gtk_entry_new();
 
191
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), prefix);
 
192
    gtk_entry_set_text(GTK_ENTRY(prefix), _urlhook_config->phone_number_prefix);
 
193
    gtk_widget_set_sensitive(GTK_WIDGET(prefix), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widg)));
 
194
    gtk_table_attach(GTK_TABLE(table), prefix, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 10);
 
195
 
 
196
    gtk_widget_show_all(ret);
 
197
 
 
198
    return ret;
 
199
}