[gnome-bluetooth] wizard: make it possible to choose a random PIN after choosing a fixed one
- From: Daniele Forsi <dforsi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth] wizard: make it possible to choose a random PIN after choosing a fixed one
- Date: Sun, 18 Dec 2011 18:50:34 +0000 (UTC)
commit 3d7d1d70cefe332c66d4561f71b722321f5df45e
Author: Daniele Forsi <dforsi src gnome org>
Date: Sun Dec 18 19:08:38 2011 +0100
wizard: make it possible to choose a random PIN after choosing a fixed one
Do not overwrite the user PIN with the random PIN and vice versa and generate
the random PIN only when it's needed; this also means that restarting the
pairing process doesn't silently overwrite user choices.
Also rewrite the generating function without side effects and fix the upper
limit of g_random_int_range() which is open.
wizard/main.c | 21 +++++++++------------
1 files changed, 9 insertions(+), 12 deletions(-)
---
diff --git a/wizard/main.c b/wizard/main.c
index 4b3eb16..48a2863 100644
--- a/wizard/main.c
+++ b/wizard/main.c
@@ -64,7 +64,6 @@ static BluetoothAgent *agent;
static gchar *target_address = NULL;
static gchar *target_name = NULL;
-static gchar *target_pincode = NULL;
static guint target_max_digits = 0;
static guint target_type = BLUETOOTH_TYPE_ANY;
static gboolean target_ssp = FALSE;
@@ -143,15 +142,13 @@ set_large_label (GtkLabel *label, const char *text)
g_free(str);
}
-static void
-update_random_pincode (void)
+static gchar*
+get_random_pincode (guint num_digits)
{
- g_free (target_pincode);
- target_pincode = g_strdup_printf ("%d", g_random_int_range (pow (10, PIN_NUM_DIGITS - 1),
- pow (10, PIN_NUM_DIGITS) - 1));
- automatic_pincode = FALSE;
- g_free (user_pincode);
- user_pincode = NULL;
+ if (num_digits == 0)
+ num_digits = PIN_NUM_DIGITS;
+ return g_strdup_printf ("%d", g_random_int_range (pow (10, num_digits - 1),
+ pow (10, num_digits)));
}
static gboolean
@@ -175,7 +172,6 @@ restart_button_clicked (GtkButton *button,
gpointer user_data)
{
/* Clean up old state */
- update_random_pincode ();
target_ssp = FALSE;
target_type = BLUETOOTH_TYPE_ANY;
display_called = FALSE;
@@ -477,6 +473,9 @@ void prepare_callback (GtkWidget *assistant,
if (automatic_pincode == FALSE && target_ssp == FALSE) {
char *text;
+ g_free (pincode);
+ pincode = get_random_pincode (target_max_digits);
+
if (target_type == BLUETOOTH_TYPE_KEYBOARD) {
text = g_strdup_printf (_("Please enter the following PIN on '%s' and press âEnterâ on the keyboard:"), target_name);
} else {
@@ -921,8 +920,6 @@ int main (int argc, char **argv)
gtk_window_set_default_icon_name("bluetooth");
- update_random_pincode ();
-
client = bluetooth_client_new();
agent = bluetooth_agent_new();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]