~ubuntu-branches/ubuntu/precise/bluez-gnome/precise

« back to all changes in this revision

Viewing changes to debian/patches/10_wizard-custom-pin.patch

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-16 13:26:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090316132600-gf1dw73s8ibw0e1o
Tags: 1.8-0ubuntu3
Add 10_wizard-custom-pin.patch: 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. Patch by Vincent Untz, merci! (LP: #284994)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
8
@@ -27,6 +27,7 @@
 
9
 
 
10
 #include <glib/gi18n.h>
 
11
 #include <gtk/gtk.h>
 
12
+#include <gdk/gdkkeysyms.h>
 
13
 
 
14
 #include <dbus/dbus-glib.h>
 
15
 
 
16
@@ -47,6 +48,11 @@ static gchar *target_pincode = NULL;
 
17
 static guint target_type = BLUETOOTH_TYPE_ANY;
 
18
 static gboolean target_ssp = FALSE;
 
19
 
 
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";
 
23
+
 
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)
 
30
                pincode = "0000";
 
31
 
 
32
+       if (user_pincode != NULL && strlen(user_pincode) == 4)
 
33
+               pincode = user_pincode;
 
34
+
 
35
        text = g_strdup_printf(_("Please enter the following PIN code: %s"),
 
36
                                                                pincode);
 
37
        gtk_label_set_markup(GTK_LABEL(label_passkey), text);
 
38
@@ -337,6 +346,19 @@ static void create_type(GtkWidget *assis
 
39
 }
 
40
 #endif
 
41
 
 
42
+static void set_page_search_complete(void)
 
43
+{
 
44
+       int selected;
 
45
+       gboolean complete;
 
46
+
 
47
+       selected = gtk_tree_selection_count_selected_rows (search_selection);
 
48
+       complete = (selected != 0 &&
 
49
+                       (user_pincode == NULL || strlen(user_pincode) == 4));
 
50
+
 
51
+       gtk_assistant_set_page_complete(GTK_ASSISTANT (window_assistant),
 
52
+                                       page_search, complete);
 
53
+}
 
54
+
 
55
 static void select_callback(GtkTreeSelection *selection, gpointer user_data)
 
56
 {
 
57
        GtkAssistant *assistant = user_data;
 
58
@@ -368,7 +390,7 @@ static void select_callback(GtkTreeSelec
 
59
                target_type = type;
 
60
        }
 
61
 
 
62
-       gtk_assistant_set_page_complete(assistant, page_search, selected);
 
63
+       set_page_search_complete();
 
64
 }
 
65
 
 
66
 static gboolean device_filter(GtkTreeModel *model,
 
67
@@ -381,6 +403,54 @@ static gboolean device_filter(GtkTreeMod
 
68
        return (paired == TRUE) ? FALSE : TRUE;
 
69
 }
 
70
 
 
71
+static gboolean entry_custom_event(GtkWidget *entry,
 
72
+                                       GdkEventKey *event, GtkWidget *box)
 
73
+{
 
74
+       if (event->length == 0)
 
75
+               return FALSE;
 
76
+
 
77
+       if ((event->keyval >= GDK_0 && event->keyval <= GDK_9) ||
 
78
+           (event->keyval >= GDK_KP_0 && event->keyval <= GDK_KP_9))
 
79
+               return FALSE;
 
80
+
 
81
+       return TRUE;
 
82
+}
 
83
+
 
84
+static void entry_custom_changed(GtkWidget *entry, gpointer user_data)
 
85
+{
 
86
+       user_pincode = gtk_entry_get_text(GTK_ENTRY(entry));
 
87
+       set_page_search_complete();
 
88
+}
 
89
+
 
90
+static void toggle_set_sensitive(GtkWidget *button, GtkWidget *widget)
 
91
+{
 
92
+       gboolean active;
 
93
+
 
94
+       active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
 
95
+       gtk_widget_set_sensitive(widget, active);
 
96
+}
 
97
+
 
98
+static void set_user_pincode(GtkWidget *button, const gchar *pincode)
 
99
+{
 
100
+       if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
 
101
+               return;
 
102
+
 
103
+       if (pincode == NULL && user_pincode != NULL)
 
104
+               last_fixed_pincode = user_pincode;
 
105
+
 
106
+       user_pincode = pincode;
 
107
+       set_page_search_complete();
 
108
+}
 
109
+
 
110
+static void set_from_last_fixed_pincode(GtkWidget *button, gpointer user_data)
 
111
+{
 
112
+       if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
 
113
+               return;
 
114
+
 
115
+       user_pincode = last_fixed_pincode;
 
116
+       set_page_search_complete();
 
117
+}
 
118
+
 
119
 static void create_search(GtkWidget *assistant)
 
120
 {
 
121
        GtkWidget *vbox;
 
122
@@ -389,6 +459,16 @@ static void create_search(GtkWidget *ass
 
123
        GtkTreeModel *model;
 
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;
 
136
 
 
137
        vbox = create_vbox(assistant, GTK_ASSISTANT_PAGE_CONTENT,
 
138
                                _("Device search"),
 
139
@@ -418,6 +498,62 @@ static void create_search(GtkWidget *ass
 
140
 
 
141
        gtk_container_add(GTK_CONTAINER(scrolled), tree);
 
142
 
 
143
+       radio_auto = gtk_radio_button_new_with_mnemonic(NULL,
 
144
+                                       _("_Automatic PIN code selection"));
 
145
+       gtk_container_add(GTK_CONTAINER(vbox), radio_auto);
 
146
+
 
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);
 
149
+
 
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);
 
155
+
 
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);
 
158
+
 
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);
 
161
+
 
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);
 
164
+
 
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,
 
174
+                       FALSE, FALSE, 0);
 
175
+       gtk_box_pack_start(GTK_BOX(hbox_custom), entry_custom,
 
176
+                       FALSE, FALSE, 0);
 
177
+       gtk_container_add(GTK_CONTAINER(vbox_fixed), hbox_custom);
 
178
+
 
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);
 
185
+
 
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);
 
198
+
 
199
        page_search = vbox;
 
200
 }
 
201
 
 
202
@@ -529,6 +665,7 @@ int main(int argc, char *argv[])
 
203
        bluetooth_agent_setup(agent, AGENT_PATH);
 
204
 
 
205
        window = create_wizard();
 
206
+       window_assistant = window;
 
207
 
 
208
        bluetooth_instance_set_window(instance, GTK_WINDOW(window));
 
209