changeset 2847:671cdfc2d62d

Basic pairing interface
author Paula Stanciu <paula.stanciu@gmail.com>
date Mon, 28 Jul 2008 21:48:39 +0300
parents 3d7f01edb388
children 3ba1579e37a5 fed560b80720
files src/bluetooth/agent.c src/bluetooth/agent.h src/bluetooth/bluetooth.c src/bluetooth/gui.h src/bluetooth/scan_gui.c src/bluetooth/scan_gui.h
diffstat 6 files changed, 50 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/bluetooth/agent.c	Sun Jul 27 22:15:41 2008 +0300
+++ b/src/bluetooth/agent.c	Mon Jul 28 21:48:39 2008 +0300
@@ -24,6 +24,7 @@
 
 #include <glib/gprintf.h>
 #include "bluetooth.h"
+#include "agent.h"
 #include "gui.h"
 
 #define PASSKEY_AGENT_PATH	"/org/bluez/audacious_passkey"
@@ -42,7 +43,7 @@
 static char* passkey;
 static GList *adapter_list = NULL;
 DBusGProxy *pair_obj = NULL;
-static gint bonding_finish=0;
+
 static DBusGConnection *connection;
 
 struct adapter_data {
@@ -1073,6 +1074,7 @@
 
 void run_agents()
 {
+    bonding_finish =0;
     setup_agents(bus);
     //to add the bounding signals 
 //    register_agents();
--- a/src/bluetooth/agent.h	Sun Jul 27 22:15:41 2008 +0300
+++ b/src/bluetooth/agent.h	Mon Jul 28 21:48:39 2008 +0300
@@ -25,6 +25,7 @@
 #include <gtk/gtk.h>
 #include <glib.h>
 #include <dbus/dbus-glib.h>
+gint bonding_finish;
 void run_agents(void);
 int setup_agents(DBusGConnection *conn);
 void cleanup_agents(void);
--- a/src/bluetooth/bluetooth.c	Sun Jul 27 22:15:41 2008 +0300
+++ b/src/bluetooth/bluetooth.c	Mon Jul 28 21:48:39 2008 +0300
@@ -87,12 +87,12 @@
     if(discover_finish == 2){
         if (devices_no == 0){
             printf("no devs!\n");
-            show_scan();
+            show_scan(0);
             show_no_devices();
         }else 
             results_ui();
     }
-    else show_scan();    
+    else show_scan(0);    
     printf("end of bt_cfg\n");
 }
 
@@ -123,25 +123,12 @@
 
         discover_devices();
         close_window();
-        show_scan();
+        show_scan(0);
     }
     else 
         printf("Scanning please wait!\n");
 }
 
-void bounding_created(gchar* address)
-{
-    printf("Signal BoundingCreated : %s\n",address);
-
-}
-
-void bounding_removed(gchar* address)
-{
-    printf("Signal: BoundingRemoved: %s\n",address);
-
-}
-
-
 gpointer connect_call_th(void)
 {
 
@@ -154,7 +141,10 @@
 }
 void connect_call(void)
 {
- connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ;  
+ connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; 
+ close_call();
+ close_window();
+ show_scan(1);
 }
 
 
--- a/src/bluetooth/gui.h	Sun Jul 27 22:15:41 2008 +0300
+++ b/src/bluetooth/gui.h	Mon Jul 28 21:48:39 2008 +0300
@@ -22,5 +22,6 @@
 GList *selected_dev ;
 void refresh_tree(void);
 void results_ui();
+void close_call(void);
 
 
--- a/src/bluetooth/scan_gui.c	Sun Jul 27 22:15:41 2008 +0300
+++ b/src/bluetooth/scan_gui.c	Mon Jul 28 21:48:39 2008 +0300
@@ -18,6 +18,7 @@
 
 #include "scan_gui.h"
 #include "bluetooth.h"
+#include "agent.h"
 static GtkWidget *window = NULL;
 static GtkWidget *winbox;
 static GtkWidget *scanbox;
@@ -28,6 +29,8 @@
 static GtkWidget *progress_bar;
 static GtkWidget *rescan_buttton;
 static GtkWidget *close_button;
+static gint usage=0;
+
 gpointer progress() {
 
     for(;;){
@@ -35,16 +38,34 @@
             gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar));
         }
         sleep(1);
-        if(discover_finish == 2 ) {            
+       if(usage == 0){
+       if(discover_finish == 2 ) {            
             if(window){
                 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1);
             }
             return 0;
         }
+       }else 
+           {
+                if(bonding_finish == 1 ) {            
+                    if(window){
+                        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1);
+                        show_pairing_ok();
+                    }
+                return 0;
+                }
+           }
     }
     return 0;
 }
 
+void show_pairing_ok()
+{
+ if(window ){
+        gtk_label_set_text(GTK_LABEL(scan_label),_("Bonding finish!"));
+    }
+}
+
 void show_no_devices(){
     if(window ){
         gtk_label_set_text(GTK_LABEL(scan_label),_("No devices found!"));
@@ -60,10 +81,15 @@
 }
 
 
-void show_scan()
+void show_scan(gint use)
 {
     GThread *th1;
     gchar *filename;
+    usage = use;
+    /*
+     * 0 - discovery 
+     * 1 - pairing 
+     */
     if (!window)
     {
         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -84,20 +110,25 @@
         bluetooth_img = gtk_image_new_from_file(filename);
         gtk_image_set_pixel_size(GTK_IMAGE(bluetooth_img),-1);
         gtk_container_add(GTK_CONTAINER(scanbox),bluetooth_img);
+        if(usage == 0){
+            scan_label = gtk_label_new_with_mnemonic(_("Scanning..."));
+        }else
+            {
+                scan_label = gtk_label_new_with_mnemonic(_("Pairing..."));
+            }
 
-        scan_label = gtk_label_new_with_mnemonic(_("Scanning..."));
         gtk_container_add(GTK_CONTAINER(scanbox),scan_label);
 
         progress_bar = gtk_progress_bar_new();
         gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar));
         gtk_container_add(GTK_CONTAINER(progressbox),progress_bar);
         th1 =  g_thread_create((GThreadFunc)progress, NULL,TRUE,NULL);
-        /* I have to add a button for Rescan when there are
-         * no devices found and not currently scanning
-         */
         buttonsbox = gtk_hbox_new(FALSE,2);
         gtk_container_set_border_width(GTK_CONTAINER(buttonsbox),2);
         gtk_container_add(GTK_CONTAINER(progressbox),buttonsbox);
+        /* I have to modify the rescan button with a play one 
+         * and treat the case when the bounding is not ok
+         */
         rescan_buttton = gtk_button_new_with_mnemonic(_("Rescan"));
         g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (refresh_call),NULL);
 
--- a/src/bluetooth/scan_gui.h	Sun Jul 27 22:15:41 2008 +0300
+++ b/src/bluetooth/scan_gui.h	Mon Jul 28 21:48:39 2008 +0300
@@ -18,7 +18,7 @@
 
 #include <gtk/gtk.h>
 #include <glib.h>
-void show_scan();
+void show_scan(gint use);
 void show_no_devices();
 void destroy_scan_window();
 void close_window();