2
* Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc.
3
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
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.
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.
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.
19
* Additional permission under GNU GPL version 3 section 7:
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.
31
#include "hooks-config.h"
34
URLHook_Config *_urlhook_config;
36
GtkWidget *field, *command, *prefix;
38
void hooks_load_parameters(URLHook_Config** settings)
41
GHashTable *_params = NULL;
42
URLHook_Config *_settings;
45
_settings = g_new0(URLHook_Config, 1);
47
// Fetch the settings from D-Bus
48
_params = (GHashTable*) dbus_get_hook_settings();
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 = "";
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));
66
*settings = _settings;
70
void hooks_save_parameters(void)
73
GHashTable *params = NULL;
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))));
89
dbus_set_hook_settings(params);
91
// Decrement the reference count
92
g_hash_table_unref(params);
96
static void sip_enabled_cb(GtkWidget *widget)
101
check = (guint) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
104
_urlhook_config->sip_enabled="true";
106
_urlhook_config->sip_enabled="false";
109
static void iax2_enabled_cb(GtkWidget *widget)
114
check = (guint) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
117
_urlhook_config->iax2_enabled="true";
119
_urlhook_config->iax2_enabled="false";
122
static void phone_number_enabled_cb(GtkWidget *widget)
127
check = (guint) gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
130
_urlhook_config->phone_number_enabled="true";
131
gtk_widget_set_sensitive(GTK_WIDGET(prefix), TRUE);
133
_urlhook_config->phone_number_enabled="false";
134
gtk_widget_set_sensitive(GTK_WIDGET(prefix), FALSE);
139
GtkWidget* create_hooks_settings()
141
GtkWidget *ret, *frame, *table, *label, *widg;
143
// Load the user value
144
hooks_load_parameters(&_urlhook_config);
146
ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
147
gtk_container_set_border_width(GTK_CONTAINER(ret), 10);
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);
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);
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);
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);
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);
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);
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);
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);
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);
196
gtk_widget_show_all(ret);