1
# Description: Allow the user to enter a custom PIN for pairing. A lot of devices use a hardcoded PIN and do not have a keyboard for entering a random one.
2
# Ubuntu: https://launchpad.net/bugs/284994
3
# Upstream: http://bugzilla.gnome.org/show_bug.cgi?id=570457
4
Index: bluez-gnome-1.8/wizard/main.c
5
===================================================================
6
--- bluez-gnome-1.8.orig/wizard/main.c
7
+++ bluez-gnome-1.8/wizard/main.c
10
#include <glib/gi18n.h>
12
+#include <gdk/gdkkeysyms.h>
14
#include <dbus/dbus-glib.h>
16
@@ -47,6 +48,11 @@ static gchar *target_pincode = NULL;
17
static guint target_type = BLUETOOTH_TYPE_ANY;
18
static gboolean target_ssp = FALSE;
20
+/* NULL means automatic, anything else is a pincode specified by the user */
21
+static const gchar *user_pincode = NULL;
22
+static const gchar *last_fixed_pincode = "0000";
24
+static GtkWidget *window_assistant = NULL;
25
static GtkWidget *page_search = NULL;
26
static GtkWidget *page_setup = NULL;
27
static GtkWidget *page_summary = NULL;
28
@@ -72,6 +78,9 @@ static gboolean pincode_callback(DBusGMe
29
target_type == BLUETOOTH_TYPE_HEADPHONE)
32
+ if (user_pincode != NULL && strlen(user_pincode) == 4)
33
+ pincode = user_pincode;
35
text = g_strdup_printf(_("Please enter the following PIN code: %s"),
37
gtk_label_set_markup(GTK_LABEL(label_passkey), text);
38
@@ -337,6 +346,19 @@ static void create_type(GtkWidget *assis
42
+static void set_page_search_complete(void)
47
+ selected = gtk_tree_selection_count_selected_rows (search_selection);
48
+ complete = (selected != 0 &&
49
+ (user_pincode == NULL || strlen(user_pincode) == 4));
51
+ gtk_assistant_set_page_complete(GTK_ASSISTANT (window_assistant),
52
+ page_search, complete);
55
static void select_callback(GtkTreeSelection *selection, gpointer user_data)
57
GtkAssistant *assistant = user_data;
58
@@ -368,7 +390,7 @@ static void select_callback(GtkTreeSelec
62
- gtk_assistant_set_page_complete(assistant, page_search, selected);
63
+ set_page_search_complete();
66
static gboolean device_filter(GtkTreeModel *model,
67
@@ -381,6 +403,54 @@ static gboolean device_filter(GtkTreeMod
68
return (paired == TRUE) ? FALSE : TRUE;
71
+static gboolean entry_custom_event(GtkWidget *entry,
72
+ GdkEventKey *event, GtkWidget *box)
74
+ if (event->length == 0)
77
+ if ((event->keyval >= GDK_0 && event->keyval <= GDK_9) ||
78
+ (event->keyval >= GDK_KP_0 && event->keyval <= GDK_KP_9))
84
+static void entry_custom_changed(GtkWidget *entry, gpointer user_data)
86
+ user_pincode = gtk_entry_get_text(GTK_ENTRY(entry));
87
+ set_page_search_complete();
90
+static void toggle_set_sensitive(GtkWidget *button, GtkWidget *widget)
94
+ active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
95
+ gtk_widget_set_sensitive(widget, active);
98
+static void set_user_pincode(GtkWidget *button, const gchar *pincode)
100
+ if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
103
+ if (pincode == NULL && user_pincode != NULL)
104
+ last_fixed_pincode = user_pincode;
106
+ user_pincode = pincode;
107
+ set_page_search_complete();
110
+static void set_from_last_fixed_pincode(GtkWidget *button, gpointer user_data)
112
+ if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
115
+ user_pincode = last_fixed_pincode;
116
+ set_page_search_complete();
119
static void create_search(GtkWidget *assistant)
122
@@ -389,6 +459,16 @@ static void create_search(GtkWidget *ass
124
GtkTreeModel *sorted;
125
GtkTreeSelection *selection;
126
+ GtkWidget *radio_auto;
127
+ GtkWidget *radio_fixed;
128
+ GtkWidget *align_fixed;
129
+ GtkWidget *vbox_fixed;
130
+ GtkWidget *radio_0000;
131
+ GtkWidget *radio_1111;
132
+ GtkWidget *radio_1234;
133
+ GtkWidget *hbox_custom;
134
+ GtkWidget *radio_custom;
135
+ GtkWidget *entry_custom;
137
vbox = create_vbox(assistant, GTK_ASSISTANT_PAGE_CONTENT,
139
@@ -418,6 +498,62 @@ static void create_search(GtkWidget *ass
141
gtk_container_add(GTK_CONTAINER(scrolled), tree);
143
+ radio_auto = gtk_radio_button_new_with_mnemonic(NULL,
144
+ _("_Automatic PIN code selection"));
145
+ gtk_container_add(GTK_CONTAINER(vbox), radio_auto);
147
+ radio_fixed = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(radio_auto), _("Use _fixed PIN code:"));
148
+ gtk_container_add(GTK_CONTAINER(vbox), radio_fixed);
150
+ align_fixed = gtk_alignment_new(0, 0, 1, 1);
151
+ gtk_alignment_set_padding(GTK_ALIGNMENT(align_fixed), 0, 0, 24, 0);
152
+ gtk_container_add(GTK_CONTAINER(vbox), align_fixed);
153
+ vbox_fixed = gtk_vbox_new(FALSE, 0);
154
+ gtk_container_add(GTK_CONTAINER(align_fixed), vbox_fixed);
156
+ radio_0000 = gtk_radio_button_new_with_label(NULL, _("'0000' (most headsets, mice and GPS devices)"));
157
+ gtk_container_add(GTK_CONTAINER(vbox_fixed), radio_0000);
159
+ radio_1111 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio_0000), _("'1111'"));
160
+ gtk_container_add(GTK_CONTAINER(vbox_fixed), radio_1111);
162
+ radio_1234 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio_0000), _("'1234'"));
163
+ gtk_container_add(GTK_CONTAINER(vbox_fixed), radio_1234);
165
+ hbox_custom = gtk_hbox_new(FALSE, 6);
166
+ radio_custom = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(radio_0000), _("Custom PIN code:"));
167
+ entry_custom = gtk_entry_new_with_max_length(4);
168
+ gtk_entry_set_width_chars(GTK_ENTRY(entry_custom), 4);
169
+ g_signal_connect (entry_custom, "key-press-event",
170
+ G_CALLBACK (entry_custom_event), NULL);
171
+ g_signal_connect (entry_custom, "changed",
172
+ G_CALLBACK (entry_custom_changed), NULL);
173
+ gtk_box_pack_start(GTK_BOX(hbox_custom), radio_custom,
175
+ gtk_box_pack_start(GTK_BOX(hbox_custom), entry_custom,
177
+ gtk_container_add(GTK_CONTAINER(vbox_fixed), hbox_custom);
179
+ toggle_set_sensitive(radio_fixed, vbox_fixed);
180
+ g_signal_connect(radio_fixed, "toggled",
181
+ G_CALLBACK(toggle_set_sensitive), vbox_fixed);
182
+ toggle_set_sensitive(radio_custom, entry_custom);
183
+ g_signal_connect(radio_custom, "toggled",
184
+ G_CALLBACK(toggle_set_sensitive), entry_custom);
186
+ g_signal_connect(radio_auto, "toggled",
187
+ G_CALLBACK(set_user_pincode), NULL);
188
+ g_signal_connect(radio_fixed, "toggled",
189
+ G_CALLBACK(set_from_last_fixed_pincode), NULL);
190
+ g_signal_connect(radio_0000, "toggled",
191
+ G_CALLBACK(set_user_pincode), "0000");
192
+ g_signal_connect(radio_1111, "toggled",
193
+ G_CALLBACK(set_user_pincode), "1111");
194
+ g_signal_connect(radio_1234, "toggled",
195
+ G_CALLBACK(set_user_pincode), "1234");
196
+ g_signal_connect_swapped (radio_custom, "toggled",
197
+ G_CALLBACK (entry_custom_changed), entry_custom);
202
@@ -529,6 +665,7 @@ int main(int argc, char *argv[])
203
bluetooth_agent_setup(agent, AGENT_PATH);
205
window = create_wizard();
206
+ window_assistant = window;
208
bluetooth_instance_set_window(instance, GTK_WINDOW(window));