changeset 2876:07bbc6cae113

merge
author Andrew O. Shadoura <bugzilla@tut.by>
date Thu, 07 Aug 2008 14:00:40 +0300
parents 9d06c6456f98 (current diff) 455e6e37feae (diff)
children 74c302381136
files
diffstat 32 files changed, 2948 insertions(+), 207 deletions(-) [+]
line wrap: on
line diff
--- a/acinclude.m4	Thu Aug 07 14:00:20 2008 +0300
+++ b/acinclude.m4	Thu Aug 07 14:00:40 2008 +0300
@@ -91,18 +91,18 @@
 
 dnl ** Check for GNU make
 AC_DEFUN([AUD_CHECK_GNU_MAKE],[
-    AC_CACHE_CHECK([for GNU make],cv_gnu_make_command,[
-    cv_gnu_make_command=""
+    AC_CACHE_CHECK([for GNU make],_cv_gnu_make_command,[
+    _cv_gnu_make_command=""
     for a in "$MAKE" make gmake gnumake; do
         test "x$a" = "x" && continue
         if ( sh -c "$a --version" 2>/dev/null | grep "GNU Make" >/dev/null ) ; then
-            cv_gnu_make_command="$a"
+            _cv_gnu_make_command="$a"
             break
         fi
     done
     ])
-    if test "x$cv_gnu_make_command" != "x" ; then
-        MAKE="$cv_gnu_make_command"
+    if test "x$_cv_gnu_make_command" != "x" ; then
+        MAKE="$_cv_gnu_make_command"
     else
         AC_MSG_ERROR([** GNU make not found. If it is installed, try setting MAKE environment variable. **])
     fi
@@ -206,6 +206,7 @@
 int main()
 {
   _mm_setzero_pd();
+  asm volatile("xorpd %xmm0,%xmm0\n\t");
   return 0;
 }
     ],[
--- a/buildsys.mk.in	Thu Aug 07 14:00:20 2008 +0300
+++ b/buildsys.mk.in	Thu Aug 07 14:00:40 2008 +0300
@@ -1,5 +1,5 @@
 #
-#  Copyright (c) 2007, Jonathan Schleifer <js-buildsys@webkeks.org>
+#  Copyright (c) 2007 - 2008, Jonathan Schleifer <js-buildsys@webkeks.org>
 #
 #  https://webkeks.org/hg/buildsys/
 #
@@ -46,7 +46,7 @@
 LIB_LDFLAGS = @LIB_LDFLAGS@
 LIB_PREFIX = @LIB_PREFIX@
 LIB_SUFFIX = @LIB_SUFFIX@
-PLUGIN_DEFNAME = `echo -n ${subst ${PLUGIN_SUFFIX},,${PLUGIN}} | tr [:lower:] [:upper:] | tr -C [:alnum:] _`
+PLUGIN_DEFNAME = `echo ${subst ${PLUGIN_SUFFIX},,${PLUGIN}} | tr [:lower:] [:upper:]`
 PLUGIN_CPPFLAGS = @PLUGIN_CPPFLAGS@ -D${PLUGIN_DEFNAME}_CFGID=\"${subst ${PLUGIN_SUFFIX},,${PLUGIN}}\"
 PLUGIN_CFLAGS = @PLUGIN_CFLAGS@
 PLUGIN_LDFLAGS = @PLUGIN_LDFLAGS@
@@ -75,11 +75,11 @@
 OBJS3 = ${OBJS2:.cxx=.o}
 OBJS4 = ${OBJS3:.d=.o}
 OBJS5 = ${OBJS4:.erl=.beam}
-OBJS += ${OBJS5:.m=.o}
-DEPS += ${OBJS:.o=.dep}
+OBJS6 = ${OBJS5:.m=.o}
+OBJS += ${OBJS6:.xpm=.o}
 
 .SILENT:
-.SUFFIXES: .beam .c .cc .cxx .d .dep .erl .m
+.SUFFIXES: .beam .c .cc .cxx .d .dep .erl .m .xpm
 .PHONY: all subdirs pre-depend depend install install-extra uninstall uninstall-extra clean distclean
 
 all:
@@ -96,17 +96,25 @@
 
 depend: pre-depend ${SRCS}
 	regen=0; \
+	deps=""; \
 	test -f .deps || regen=1; \
-	for i in ${SRCS}; do test $$i -nt .deps && regen=1; done; \
-	if test x"$$regen" = x"1" -a x"${DEPS}" != "x"; then \
+	for i in ${SRCS}; do \
+		case $$i in \
+			*.o) \
+				test $$i -nt .deps && regen=1; \
+				deps="$${deps%.o}.dep $$i"; \
+				;; \
+		esac; \
+	done; \
+	if test x"$$regen" = x"1" -a x"$$deps" != "x"; then \
 		${DEPEND_STATUS}; \
 		rm -f .deps; \
-		if ${MAKE} ${MFLAGS} ${DEPS}; then \
-			cat ${DEPS} >.deps; \
-			rm -f ${DEPS}; \
+		if ${MAKE} ${MFLAGS} $$deps; then \
+			cat $$deps >.deps; \
+			rm -f $$deps; \
 			${DEPEND_OK}; \
 		else \
-			rm -f .deps ${DEPS}; \
+			rm -f .deps $$deps; \
 			${DEPEND_FAILED}; \
 		fi; \
 	fi
@@ -115,6 +123,7 @@
 	${CPP} ${CPPFLAGS} -M $< >$@
 
 .d.dep:
+.xpm.dep:
 
 pre-depend:
 
@@ -198,6 +207,14 @@
 		${COMPILE_FAILED}; \
 	fi
 
+.xpm.o:
+	${COMPILE_STATUS}
+	if ${CC} ${CFLAGS} ${CPPFLAGS} -x c -c -o $@ $<; then \
+		${COMPILE_OK}; \
+	else \
+		${COMPILE_FAILED}; \
+	fi
+
 install: ${LIB} ${STATIC_LIB} ${PLUGIN} ${PROG} install-extra
 	for i in ${SUBDIRS}; do \
 		${DIR_ENTER}; \
--- a/src/OSS/OSS.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/OSS/OSS.c	Thu Aug 07 14:00:40 2008 +0300
@@ -27,31 +27,31 @@
 
 OSSConfig oss_cfg;
 
+static GtkWidget *about_dialog = NULL;
+
 static void oss_about(void)
 {
-    static GtkWidget *dialog;
-
-    if (dialog != NULL)
+    if (about_dialog != NULL)
         return;
 
-    dialog = audacious_info_dialog(_("About OSS Driver"),
-                               _("Audacious OSS Driver\n\n "
-                                 "This program is free software; you can redistribute it and/or modify\n"
-                                 "it under the terms of the GNU General Public License as published by\n"
-                                 "the Free Software Foundation; either version 2 of the License, or\n"
-                                 "(at your option) any later version.\n"
-                                 "\n"
-                                 "This program is distributed in the hope that it will be useful,\n"
-                                 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-                                 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-                                 "GNU General Public License for more details.\n"
-                                 "\n"
-                                 "You should have received a copy of the GNU General Public License\n"
-                                 "along with this program; if not, write to the Free Software\n"
-                                 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\n"
-                                 "USA."), _("Ok"), FALSE, NULL, NULL);
-    g_signal_connect(G_OBJECT(dialog), "destroy",
-                     G_CALLBACK(gtk_widget_destroyed), &dialog);
+    about_dialog = audacious_info_dialog(_("About OSS Driver"),
+    _("Audacious OSS Driver\n\n "
+    "This program is free software; you can redistribute it and/or modify\n"
+    "it under the terms of the GNU General Public License as published by\n"
+    "the Free Software Foundation; either version 2 of the License, or\n"
+    "(at your option) any later version.\n"
+    "\n"
+    "This program is distributed in the hope that it will be useful,\n"
+    "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+    "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
+    "GNU General Public License for more details.\n"
+    "\n"
+    "You should have received a copy of the GNU General Public License\n"
+    "along with this program; if not, write to the Free Software\n"
+    "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,\n"
+    "USA."), _("Ok"), FALSE, NULL, NULL);
+    g_signal_connect(G_OBJECT(about_dialog), "destroy",
+                     G_CALLBACK(gtk_widget_destroyed), &about_dialog);
 }
 
 static void oss_init(void)
--- a/src/OSS/configure.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/OSS/configure.c	Thu Aug 07 14:00:40 2008 +0300
@@ -72,6 +72,7 @@
         if (oss_cfg.alt_mixer_device[0] != '/')
             oss_cfg.use_alt_mixer_device = FALSE;
 
+    /* Save configuration */
     db = aud_cfg_db_open();
 
     aud_cfg_db_set_int(db, "OSS", "audio_device", oss_cfg.audio_device);
--- a/src/aac/libfaad2/ic_predict.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/aac/libfaad2/ic_predict.c	Thu Aug 07 14:00:40 2008 +0300
@@ -52,9 +52,9 @@
         tmp2 = tmp;                             /* add 1 lsb and elided one */
         tmp &= (uint32_t)0xff800000;       /* extract exponent and sign */
         
-        *pf = *(float32_t*)(void*)&tmp1 + *(float32_t*)(void*)&tmp2 - *(float32_t*)(void*)&tmp;
+        *pf = (float32_t)tmp1 + (float32_t)tmp2 - (float32_t)tmp;
     } else {
-        *pf = *(float32_t*)(void*)&tmp;
+        *pf = (float32_t)tmp;
     }
 }
 
--- a/src/adplug/core/adlibemu.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/adplug/core/adlibemu.c	Thu Aug 07 14:00:40 2008 +0300
@@ -144,7 +144,7 @@
 
     ftol(ctc->t+modulator,&i);
 
-    if (*(long *)&ctc->amp <= 0x37800000)
+    if ((long)ctc->amp <= 0x37800000)
     {
 	ctc->amp = 0;
 	ctc->cellfunc = docell4;
@@ -160,7 +160,7 @@
 
     ftol(ctc->t+modulator,&i);
 
-    if ((*(long *)&ctc->amp) <= (*(long *)&ctc->sustain))
+    if ((long)ctc->amp <= (long)ctc->sustain)
     {
 	if (ctc->flags&32)
 	{
@@ -183,7 +183,7 @@
     ftol(ctc->t+modulator,&i);
 
     ctc->amp = ((ctc->a3*ctc->amp + ctc->a2)*ctc->amp + ctc->a1)*ctc->amp + ctc->a0;
-    if ((*(long *)&ctc->amp) > 0x3f800000)
+    if ((long)ctc->amp > 0x3f800000)
     {
 	ctc->amp = 1;
 	ctc->cellfunc = docell1;
--- a/src/adplug/core/fmc.cxx	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/adplug/core/fmc.cxx	Thu Aug 07 14:00:40 2008 +0300
@@ -130,6 +130,7 @@
         if (tracks[t][k].command == 0x0E)   // 0x0E (14): Retrig
           tracks[t][k].param1 = 3;
         if (tracks[t][k].command == 0x1A)   // 0x1A (26): Volume Slide
+        {
           if (tracks[t][k].param1 > tracks[t][k].param2)
           {
             tracks[t][k].param1 -= tracks[t][k].param2;
@@ -140,6 +141,7 @@
             tracks[t][k].param2 -= tracks[t][k].param1;
             tracks[t][k].param1 = 0;
           }
+        }
       }
 
       t++;
--- a/src/adplug/core/mid.cxx	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/adplug/core/mid.cxx	Thu Aug 07 14:00:40 2008 +0300
@@ -328,11 +328,13 @@
     break;
   case 0x84:
     if (s[1] == 0x00 && load_sierra_ins (filename, fp))
+    {
       if (s[2] == 0xf0)
         good = FILE_ADVSIERRA;
       else
         good = FILE_SIERRA;
     break;
+    }
   default:
     if (s[4] == 'A' && s[5] == 'D')
       good = FILE_OLDLUCAS;
@@ -900,10 +902,12 @@
   midiprintf ("\n");
   for (i = 0; i < 16; i++)
     if (track[i].on)
+    {
       if (track[i].pos < track[i].tend)
         midiprintf ("<%d>", track[i].iwait);
       else
         midiprintf ("stop");
+    }
 
   /*
      if (ret==0 && type==FILE_ADVSIERRA)
--- a/src/adplug/core/s3m.cxx	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/adplug/core/s3m.cxx	Thu Aug 07 14:00:40 2008 +0300
@@ -212,15 +212,19 @@
         tone_portamento (realchan, channel[realchan].dualinfo);
     case 4:
       if (info <= 0x0f)         // volume slide down
+      {
         if (channel[realchan].vol - info >= 0)
           channel[realchan].vol -= info;
         else
           channel[realchan].vol = 0;
+      }
       if ((info & 0x0f) == 0)   // volume slide up
+      {
         if (channel[realchan].vol + (info >> 4) <= 63)
           channel[realchan].vol += info >> 4;
         else
           channel[realchan].vol = 63;
+      }
       setvolume (realchan);
       break;
     case 5:
@@ -323,6 +327,7 @@
       // set channel values
       donote = 0;
       if (pattern[pattnr][row][chan].note < 14)
+      {
         // tone portamento
         if (pattern[pattnr][row][chan].command == 7
             || pattern[pattnr][row][chan].command == 12)
@@ -339,6 +344,7 @@
           channel[realchan].key = 1;
           donote = 1;
         }
+      }
       if (pattern[pattnr][row][chan].note == 14)
       {                         // key off (is 14 here, cause note is only first 4 bits)
         channel[realchan].key = 0;
@@ -371,10 +377,12 @@
           donote = 1;
       }
       if (pattern[pattnr][row][chan].volume != 255)
+      {
         if (pattern[pattnr][row][chan].volume < 64) // set volume
           channel[realchan].vol = pattern[pattnr][row][chan].volume;
         else
           channel[realchan].vol = 63;
+      }
       channel[realchan].fx = pattern[pattnr][row][chan].command;    // set command
       if (pattern[pattnr][row][chan].info)  // set infobyte
         channel[realchan].info = pattern[pattnr][row][chan].info;
@@ -420,15 +428,19 @@
         break;                  // pattern break
       case 4:
         if (info > 0xf0)        // fine volume down
+        {
           if (channel[realchan].vol - (info & 0x0f) >= 0)
             channel[realchan].vol -= info & 0x0f;
           else
             channel[realchan].vol = 0;
+        }
         if ((info & 0x0f) == 0x0f && info >= 0x1f)  // fine volume up
+        {
           if (channel[realchan].vol + ((info & 0xf0) >> 4) <= 63)
             channel[realchan].vol += (info & 0xf0) >> 4;
           else
             channel[realchan].vol = 63;
+        }
         setvolume (realchan);
         break;
       case 5:
@@ -468,6 +480,7 @@
         if (info == 0xb0)       // set loop start
           loopstart = row;
         if (info > 0xb0 && info <= 0xbf)    // pattern loop
+        {
           if (!loopcnt)
           {
             loopcnt = info & 0x0f;
@@ -479,6 +492,7 @@
             crow = loopstart;
             pattbreak = 1;
           }
+        }
         if ((info & 0xf0) == 0xe0)  // patterndelay
           del = speed * (info & 0x0f) - 1;
         break;
--- a/src/amidi-plug/i_configure.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/amidi-plug/i_configure.c	Thu Aug 07 14:00:40 2008 +0300
@@ -30,6 +30,7 @@
 #include "i_utils.h"
 #include <audacious/plugin.h>
 #include <audacious/auddrct.h>
+#include <audacious/plugin.h>
 
 
 amidiplug_cfg_backend_t * amidiplug_cfg_backend;
--- a/src/bluetooth/Makefile	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/bluetooth/Makefile	Thu Aug 07 14:00:40 2008 +0300
@@ -1,11 +1,10 @@
 PLUGIN = bluetooth${PLUGIN_SUFFIX}
 
-SRCS = bluetooth.c gui.c marshal.c scan_gui.c
+SRCS = bluetooth.c gui.c marshal.c scan_gui.c agent.c 
 include ../../buildsys.mk
 include ../../extra.mk
-
 plugindir := ${plugindir}/${GENERAL_PLUGIN_DIR}
+CFLAGS += ${PLUGIN_CFLAGS}
+CPPFLAGS += ${PLUGIN_CPPFLAGS} ${BEEP_DEFINES} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${DBUS_GLIB_CFLAGS} ${PANGO_CFLAGS} -I../../intl -I../.. ${BLUEZ_CFLAGS}
+LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${BLUEZ_LIBS}
 
-CFLAGS += ${PLUGIN_CFLAGS}
-CPPFLAGS += ${PLUGIN_CPPFLAGS} ${BEEP_DEFINES} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} -I../../intl -I../.. ${BLUEZ_CFLAGS}
-LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${BLUEZ_LIBS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bluetooth/agent.c	Thu Aug 07 14:00:40 2008 +0300
@@ -0,0 +1,1082 @@
+/*
+ *  Audacious Bluetooth headset suport plugin
+ *
+ *  Copyright (c) 2008 Paula Stanciu <paula.stanciu@gmail.com>
+ *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
+ *  Copyright (C) 2006-2007  Bastien Nocera <hadess@hadess.net>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <glib/gprintf.h>
+#include "bluetooth.h"
+#include "agent.h"
+#include "gui.h"
+
+#define PASSKEY_AGENT_PATH	"/org/bluez/audacious_passkey"
+#define AUTH_AGENT_PATH		"/org/bluez/audacious_auth"
+
+static GtkWidget *agent_window = NULL;
+static GtkWidget *window_box = NULL;
+static GtkWidget *top_box = NULL;
+static GtkWidget *middle_box = NULL;
+static GtkWidget *bottom_box = NULL;
+static GtkWidget *pair_label = NULL;
+static GtkWidget *device_label = NULL;
+static GtkWidget *passkey_entry = NULL;
+static GtkWidget *ok_button = NULL;
+static GtkWidget *cancel_button = NULL;
+static const char* passkey;
+static GList *adapter_list = NULL;
+DBusGProxy *pair_obj = NULL;
+
+static DBusGConnection *connection;
+
+struct adapter_data {
+	char *path;
+	int attached;
+	char *old_mode;
+};
+
+void ok_button_call()
+{
+    passkey = gtk_entry_get_text(GTK_ENTRY(passkey_entry));
+    printf("Key entered : %s\n",passkey);
+}
+
+void cancel_button_call()
+{
+    gtk_widget_destroy (agent_window);
+    agent_window = NULL;
+}
+
+void gui_agent()
+{
+    if (!agent_window)
+    {
+        agent_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+        g_signal_connect (agent_window, "destroy",G_CALLBACK (gtk_widget_destroyed), &agent_window);
+        window_box = gtk_vbox_new(FALSE,2);
+        top_box = gtk_vbox_new(FALSE,2);
+        middle_box = gtk_hbox_new(FALSE,2);
+        bottom_box = gtk_hbox_new(FALSE,2);
+
+        gtk_container_add(GTK_CONTAINER(agent_window),window_box);
+        gtk_container_add(GTK_CONTAINER(window_box),top_box);
+        gtk_container_set_border_width (GTK_CONTAINER(middle_box), 20);
+        gtk_container_add(GTK_CONTAINER(window_box),middle_box);
+        gtk_container_add(GTK_CONTAINER(window_box),bottom_box);
+
+        pair_label = gtk_label_new_with_mnemonic("Enter passkey for pairing");
+        device_label = gtk_label_new_with_mnemonic(((DeviceData*)(selected_dev->data))->name);
+
+        gtk_container_add(GTK_CONTAINER(top_box),pair_label);
+        gtk_container_add(GTK_CONTAINER(top_box),device_label);
+
+        passkey_entry = gtk_entry_new();
+        gtk_container_add(GTK_CONTAINER(middle_box),passkey_entry);
+
+        ok_button = gtk_button_new_with_mnemonic("OK");
+        cancel_button = gtk_button_new_with_mnemonic("Cancel");
+        gtk_container_add(GTK_CONTAINER(bottom_box),ok_button);
+        g_signal_connect(ok_button,"clicked",G_CALLBACK(ok_button_call),NULL);
+
+        gtk_container_add(GTK_CONTAINER(bottom_box),cancel_button);
+        g_signal_connect(cancel_button,"clicked",G_CALLBACK (cancel_button_call),NULL);
+
+
+        gtk_window_set_title(GTK_WINDOW(agent_window),"Pairing passkey request");
+        if (!GTK_WIDGET_VISIBLE (agent_window))
+            gtk_widget_show_all (agent_window);
+        else
+        {   
+            gtk_widget_destroy (agent_window);
+            agent_window = NULL;
+        }
+
+    }
+
+
+}
+static DBusGConnection *connection;
+
+static int volatile registered_passkey	= 0;
+static int volatile registered_auth	= 0;
+
+static gboolean auto_authorize = FALSE;
+
+typedef enum {
+    AGENT_ERROR_REJECT
+} AgentError;
+
+#define AGENT_ERROR (agent_error_quark())
+
+#define AGENT_ERROR_TYPE (agent_error_get_type()) 
+
+static GQuark agent_error_quark(void)
+{
+    static GQuark quark = 0;
+    if (!quark)
+        quark = g_quark_from_static_string("agent");
+
+    return quark;
+}
+
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+
+static GType agent_error_get_type(void)
+{
+    static GType etype = 0;
+    if (etype == 0) {
+        static const GEnumValue values[] = {
+            ENUM_ENTRY(AGENT_ERROR_REJECT, "Rejected"),
+            { 0, 0, 0 }
+        };
+
+        etype = g_enum_register_static("agent", values);
+    }
+
+    return etype;
+}
+
+static GList *input_list = NULL;
+
+struct input_data {
+    char *path;
+    char *address;
+    char *service;
+    char *uuid;
+    DBusGMethodInvocation *context;
+};
+
+static gint input_compare(gconstpointer a, gconstpointer b)
+{
+    struct input_data *a_data = (struct input_data *) a;
+    struct input_data *b_data = (struct input_data *) b;
+
+    return g_ascii_strcasecmp(a_data->address, b_data->address);
+}
+
+static void input_free(struct input_data *input)
+{
+
+    input_list = g_list_remove(input_list, input);
+
+    g_free(input->uuid);
+    g_free(input->service);
+    g_free(input->address);
+    g_free(input->path);
+    g_free(input);
+
+    //	if (g_list_length(input_list) == 0)
+    //	disable_blinking();
+}
+
+static void passkey_callback(gint response, gpointer user_data)
+{
+    struct input_data *input = user_data;
+
+    if (response == GTK_RESPONSE_ACCEPT) {
+        const char *passkey;
+        /*!!!!!!!!! hardcoded passkey !!!!!!!!!!!!! to modify*/
+        passkey ="0000";
+        dbus_g_method_return(input->context, passkey);
+    } else {
+        GError *error;
+        error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
+                "Pairing request rejected");
+        printf("passkey error\n");
+        dbus_g_method_return_error(input->context, error);
+    }
+
+    input_free(input);
+}
+
+/*static void confirm_callback(gint response, gpointer user_data)
+{
+    struct input_data *input = user_data;
+
+    if (response != GTK_RESPONSE_YES) {
+        GError *error;
+        error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
+                "Confirmation request rejected");
+        dbus_g_method_return_error(input->context, error);
+    } else
+        dbus_g_method_return(input->context);
+
+    input_free(input);
+}
+*/
+/*
+static void set_trusted(struct input_data *input)
+{
+    DBusGProxy *object;
+    //aways set trusted -- we dont have yet an active button -
+    //maybe I'll add one	
+    object = dbus_g_proxy_new_for_name(connection, "org.bluez",
+            input->path, "org.bluez.Adapter");
+
+    dbus_g_proxy_call(object, "SetTrusted", NULL,
+            G_TYPE_STRING, input->address, G_TYPE_INVALID,
+            G_TYPE_INVALID);
+}
+*/
+/*
+static void auth_callback(gint response, gpointer user_data)
+{
+
+    struct input_data *input = user_data;
+
+    if (response == GTK_RESPONSE_YES) {
+        set_trusted(input);
+        dbus_g_method_return(input->context);
+    } else {
+        GError *error;
+        error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
+                "Authorization request rejected");
+        dbus_g_method_return_error(input->context, error);
+    }
+
+    input_free(input);
+}
+*/
+
+static void passkey_dialog(const char *path, const char *address,
+        const gchar *device, DBusGMethodInvocation *context)
+{
+    struct input_data *input;
+
+    input = g_try_malloc0(sizeof(*input));
+    if (!input)
+        return;
+
+    input->path = g_strdup(path);
+    input->address = g_strdup(address);
+
+    input->context = context;
+
+
+
+    /*
+       g_signal_connect(G_OBJECT(entry), "changed",
+       G_CALLBACK(changed_callback), input);
+
+
+       g_signal_connect(G_OBJECT(button), "toggled",
+       G_CALLBACK(toggled_callback), input);
+
+       gtk_container_add(GTK_CONTAINER(vbox), button);
+
+       input_list = g_list_append(input_list, input);
+
+       g_signal_connect(G_OBJECT(dialog), "response",
+       G_CALLBACK(passkey_callback), input);
+
+       enable_blinking();
+       */
+    printf("passkey callback\n");
+    passkey_callback(GTK_RESPONSE_ACCEPT,input);
+
+
+}
+
+static void confirm_dialog(const char *path, const char *address,
+        const char *value, const gchar *device,
+        DBusGMethodInvocation *context)
+{
+    struct input_data *input;
+
+    input = g_try_malloc0(sizeof(*input));
+    if (!input)
+        return;
+
+    input->path = g_strdup(path);
+    input->address = g_strdup(address);
+
+    input->context = context;
+
+printf("confirm dialog\n");
+    //	g_signal_connect(G_OBJECT(dialog), "response",
+    //				G_CALLBACK(confirm_callback), input);
+
+    //enable_blinking();
+}
+
+static void auth_dialog(const char *path, const char *address,
+        const char *service, const char *uuid, const gchar *device,
+        const gchar *profile, DBusGMethodInvocation *context)
+{
+    struct input_data *input;
+
+    input = g_try_malloc0(sizeof(*input));
+    if (!input)
+        return;
+
+    input->path = g_strdup(path);
+    input->address = g_strdup(address);
+    input->service = g_strdup(service);
+    input->uuid = g_strdup(uuid);
+
+    input->context = context;
+
+
+    /* translators: Whether to grant access to a particular service
+     * to the device mentioned */
+
+   /* 	g_signal_connect(G_OBJECT(dialog), "response",
+    				G_CALLBACK(auth_callback), input);
+
+    enable_blinking();
+    */
+}
+
+typedef struct {
+    GObject parent;
+} PasskeyAgent;
+
+typedef struct {
+    GObjectClass parent;
+} PasskeyAgentClass;
+
+static GObjectClass *passkey_agent_parent;
+
+G_DEFINE_TYPE(PasskeyAgent, passkey_agent, G_TYPE_OBJECT)
+
+#define PASSKEY_AGENT_OBJECT_TYPE (passkey_agent_get_type())
+
+#define PASSKEY_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+            PASSKEY_AGENT_OBJECT_TYPE, PasskeyAgent))
+
+static void passkey_agent_finalize(GObject *obj)
+{
+    passkey_agent_parent->finalize(obj);
+}
+
+static void passkey_agent_init(PasskeyAgent *obj)
+{
+    g_printf("passkeyagent init\n");
+}
+
+static void passkey_agent_class_init(PasskeyAgentClass *klass)
+{
+    GObjectClass *gobject_class;
+
+    passkey_agent_parent = g_type_class_peek_parent(klass);
+
+    gobject_class = G_OBJECT_CLASS(klass);
+    gobject_class->finalize = passkey_agent_finalize;
+}
+
+static PasskeyAgent *passkey_agent_new(const char *path)
+{
+    PasskeyAgent *agent;
+
+    agent = g_object_new(PASSKEY_AGENT_OBJECT_TYPE, NULL);
+
+    dbus_g_connection_register_g_object(connection, path, G_OBJECT(agent));
+    g_printf("new passkey agent \n");
+    return agent;
+}
+static gboolean passkey_agent_request(PasskeyAgent *agent,
+        const char *path, const char *address,
+        DBusGMethodInvocation *context)
+{
+    printf("passkey_agent request\n");
+    DBusGProxy *object;
+    const char *adapter = NULL, *name = NULL;
+    gchar *device, *line;
+
+    object = dbus_g_proxy_new_for_name(connection, "org.bluez",
+            path, "org.bluez.Adapter");
+
+    dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+            G_TYPE_STRING, &adapter, G_TYPE_INVALID);
+
+    dbus_g_proxy_call(object, "GetRemoteName", NULL,
+            G_TYPE_STRING, address, G_TYPE_INVALID,
+            G_TYPE_STRING, &name, G_TYPE_INVALID);
+
+    if (name) {
+        if (g_strrstr(name, address))
+            device = g_strdup(name);
+        else
+            device = g_strdup_printf("%s (%s)", name, address);
+    } else
+        device = g_strdup(address);
+
+    passkey_dialog(path, address, device, context);
+    /* translators: this is a popup telling you a particular device
+     * has asked for pairing */
+    line = g_strdup_printf(_("Pairing request for '%s'"), device);
+    g_free(device);
+
+    /*show_notification(adapter ? adapter : _("Bluetooth device"),
+      line, _("Enter passkey"), 0,
+      G_CALLBACK(notification_closed));
+      */
+    g_free(line);
+
+    return TRUE;
+}
+
+static gboolean passkey_agent_confirm(PasskeyAgent *agent,
+        const char *path, const char *address,
+        const char *value, DBusGMethodInvocation *context)
+{
+    DBusGProxy *object;
+    const char *adapter = NULL, *name = NULL;
+    gchar *device, *line;
+
+    object = dbus_g_proxy_new_for_name(connection, "org.bluez",
+            path, "org.bluez.Adapter");
+
+    dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+            G_TYPE_STRING, &adapter, G_TYPE_INVALID);
+
+    dbus_g_proxy_call(object, "GetRemoteName", NULL,
+            G_TYPE_STRING, address, G_TYPE_INVALID,
+            G_TYPE_STRING, &name, G_TYPE_INVALID);
+
+    if (name) {
+        if (g_strrstr(name, address))
+            device = g_strdup(name);
+        else
+            device = g_strdup_printf("%s (%s)", name, address);
+    } else
+        device = g_strdup(address);
+
+    confirm_dialog(path, address, value, device, context);
+
+    line = g_strdup_printf(_("Pairing request for '%s'"), device);
+    g_free(device);
+
+    /*show_notification(adapter ? adapter : _("Bluetooth device"),
+      line, _("Confirm pairing"), 0,
+      G_CALLBACK(notification_closed));
+      */
+    g_free (line);
+
+    return TRUE;
+}
+
+static gboolean passkey_agent_cancel(PasskeyAgent *agent,
+        const char *path, const char *address, GError **error)
+{
+    GList *list;
+    GError *result;
+    struct input_data *input;
+
+    input = g_try_malloc0(sizeof(*input));
+    if (!input)
+        return FALSE;
+
+    input->path = g_strdup(path);
+    input->address = g_strdup(address);
+
+    list = g_list_find_custom(input_list, input, input_compare);
+
+    g_free(input->address);
+    g_free(input->path);
+    g_free(input);
+
+    if (!list || !list->data)
+        return FALSE;
+
+    input = list->data;
+
+    //close_notification();
+
+    result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
+            "Agent callback canceled");
+
+    dbus_g_method_return_error(input->context, result);
+
+    input_free(input);
+
+    return TRUE;
+}
+
+static gboolean passkey_agent_release(PasskeyAgent *agent, GError **error)
+{
+    registered_passkey = 0;
+
+    return TRUE;
+}
+
+#include "passkey-agent-glue.h"
+
+typedef struct {
+    GObject parent;
+} AuthAgent;
+
+typedef struct {
+    GObjectClass parent;
+} AuthAgentClass;
+
+static GObjectClass *auth_agent_parent;
+
+G_DEFINE_TYPE(AuthAgent, auth_agent, G_TYPE_OBJECT)
+
+#define AUTH_AGENT_OBJECT_TYPE (auth_agent_get_type())
+
+#define AUTH_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+            AUTH_AGENT_OBJECT_TYPE, AuthAgent))
+
+static void auth_agent_finalize(GObject *obj)
+{
+    auth_agent_parent->finalize(obj);
+}
+
+static void auth_agent_init(AuthAgent *obj)
+{
+}
+
+static void auth_agent_class_init(AuthAgentClass *klass)
+{
+    GObjectClass *gobject_class;
+
+    auth_agent_parent = g_type_class_peek_parent(klass);
+
+    gobject_class = G_OBJECT_CLASS(klass);
+    gobject_class->finalize = auth_agent_finalize;
+}
+
+static AuthAgent *auth_agent_new(const char *path)
+{
+    AuthAgent *agent;
+
+    agent = g_object_new(AUTH_AGENT_OBJECT_TYPE, NULL);
+
+    dbus_g_connection_register_g_object(connection, path, G_OBJECT(agent));
+
+    return agent;
+}
+
+static gboolean auth_agent_authorize(PasskeyAgent *agent,
+        const char *path, const char *address, const char *service,
+        const char *uuid, DBusGMethodInvocation *context)
+{
+    DBusGProxy *object;
+    const char *adapter = NULL, *name = NULL;
+    gchar *device, *profile, *line;
+
+    if (auto_authorize == TRUE) {
+        dbus_g_method_return(context);
+        return TRUE;
+    }
+
+    object = dbus_g_proxy_new_for_name(connection, "org.bluez",
+            path, "org.bluez.Adapter");
+
+    dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+            G_TYPE_STRING, &adapter, G_TYPE_INVALID);
+
+    dbus_g_proxy_call(object, "GetRemoteName", NULL,
+            G_TYPE_STRING, address, G_TYPE_INVALID,
+            G_TYPE_STRING, &name, G_TYPE_INVALID);
+
+    object = dbus_g_proxy_new_for_name(connection, "org.bluez",
+            service, "org.bluez.Service");
+
+    dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+            G_TYPE_STRING, &profile, G_TYPE_INVALID);
+
+    if (name) {
+        if (g_strrstr(name, address))
+            device = g_strdup(name);
+        else
+            device = g_strdup_printf("%s (%s)", name, address);
+    } else
+        device = g_strdup(address);
+
+    auth_dialog(path, address, service, uuid, device, profile, context);
+
+    line = g_strdup_printf(_("Authorization request for %s"), device);
+    g_free(device);
+
+    /*show_notification(adapter ? adapter : _("Bluetooth device"),
+      line, _("Check authorization"), 0,
+      G_CALLBACK(notification_closed));
+      */
+    g_free(line);
+
+    return TRUE;
+}
+
+static gboolean auth_agent_cancel(PasskeyAgent *agent,
+        const char *path, const char *address, const char *service,
+        const char *uuid, DBusGMethodInvocation *context)
+{
+    GList *list;
+    GError *result;
+    struct input_data *input;
+
+    input = g_try_malloc0(sizeof(*input));
+    if (!input)
+        return FALSE;
+
+    input->path = g_strdup(path);
+    input->address = g_strdup(address);
+    input->service = g_strdup(service);
+    input->uuid = g_strdup(uuid);
+
+    list = g_list_find_custom(input_list, input, input_compare);
+
+    g_free(input->uuid);
+    g_free(input->service);
+    g_free(input->address);
+    g_free(input->path);
+    g_free(input);
+
+    if (!list || !list->data)
+        return FALSE;
+
+    input = list->data;
+
+    //close_notification();
+
+    result = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT,
+            "Agent callback canceled");
+
+    dbus_g_method_return_error(input->context, result);
+
+    input_free(input);
+
+    return TRUE;
+}
+
+static gboolean auth_agent_release(PasskeyAgent *agent, GError **error)
+{
+    registered_auth = 0;
+
+    return TRUE;
+}
+
+#include "auth-agent-glue.h"
+
+int register_agents(void)
+{
+    DBusGProxy *object;
+    GError *error = NULL;
+
+    if (registered_passkey && registered_auth)
+        return 0;
+
+    object = dbus_g_proxy_new_for_name(connection, "org.bluez",
+            "/org/bluez", "org.bluez.Security");
+
+    if (!registered_passkey) {
+
+        dbus_g_proxy_call(object, "RegisterDefaultPasskeyAgent",
+                &error, G_TYPE_STRING, PASSKEY_AGENT_PATH,
+                G_TYPE_INVALID, G_TYPE_INVALID);
+
+        if (error != NULL) {
+            g_error_free(error);
+            return -1;
+        }
+
+        registered_passkey = 1;
+    }
+
+    if (!registered_auth) {
+        dbus_g_proxy_call(object, "RegisterDefaultAuthorizationAgent",
+                &error,	G_TYPE_STRING, AUTH_AGENT_PATH,
+                G_TYPE_INVALID, G_TYPE_INVALID);
+
+        if (error != NULL) {
+            g_error_free(error);
+            return -1;
+        }
+
+        registered_auth = 1;
+    }
+
+    return 0;
+}
+
+void unregister_agents(void)
+{
+    registered_passkey = 0;
+    registered_auth = 0;
+}
+
+int setup_agents(DBusGConnection *conn)
+{
+    void *agent;
+
+    connection = dbus_g_connection_ref(conn);
+
+    dbus_g_object_type_install_info(PASSKEY_AGENT_OBJECT_TYPE,
+            &dbus_glib_passkey_agent_object_info);
+
+    dbus_g_object_type_install_info(AUTH_AGENT_OBJECT_TYPE,
+            &dbus_glib_auth_agent_object_info);
+
+    dbus_g_error_domain_register(AGENT_ERROR, "org.bluez.Error",
+            AGENT_ERROR_TYPE);
+
+    agent = passkey_agent_new(PASSKEY_AGENT_PATH);
+
+    agent = auth_agent_new(AUTH_AGENT_PATH);
+
+    return 0;
+}
+
+void cleanup_agents(void)
+{
+    unregister_agents();
+
+    dbus_g_connection_unref(connection);
+}
+
+void show_agents(void)
+{
+    printf("show_agents\n");
+    //close_notification();
+
+    //	g_list_foreach(input_list, show_dialog, NULL);
+
+    //	disable_blinking();
+}
+
+void set_auto_authorize(gboolean value)
+{
+    auto_authorize = value;
+}
+
+static void bonding_created(DBusGProxy *object,
+				const char *address, gpointer user_data)
+{
+	const char *adapter = NULL, *name = NULL;
+	gchar *device, *text;
+
+	dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+				G_TYPE_STRING, &adapter, G_TYPE_INVALID);
+
+	dbus_g_proxy_call(object, "GetRemoteName", NULL,
+				G_TYPE_STRING, address, G_TYPE_INVALID,
+				G_TYPE_STRING, &name, G_TYPE_INVALID);
+
+	if (name) {
+		if (g_strrstr(name, address))
+			device = g_strdup(name);
+		else
+			device = g_strdup_printf("%s (%s)", name, address);
+	} else
+		device = g_strdup(address);
+
+	text = g_strdup_printf(_("Created bonding with %s"), device);
+    bonding_finish = 1;
+	g_free(device);
+
+	g_printf("%s\n",text);
+	g_free(text);
+}
+
+static void bonding_removed(DBusGProxy *object,
+				const char *address, gpointer user_data)
+{
+	const char *adapter = NULL, *name = NULL;
+	gchar *device, *text;
+
+	dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+				G_TYPE_STRING, &adapter, G_TYPE_INVALID);
+
+	dbus_g_proxy_call(object, "GetRemoteName", NULL,
+				G_TYPE_STRING, address, G_TYPE_INVALID,
+				G_TYPE_STRING, &name, G_TYPE_INVALID);
+
+	if (name) {
+		if (g_strrstr(name, address))
+			device = g_strdup(name);
+		else
+			device = g_strdup_printf("%s (%s)", name, address);
+	} else
+		device = g_strdup(address);
+
+	text = g_strdup_printf(_("Removed bonding with %s"), device);
+
+	g_free(device);
+    printf("bonding removed");
+
+//	show_notification(adapter ? adapter : _("Bluetooth device"),
+//						text, NULL, 6000, NULL);
+
+	g_free(text);
+    bonding_finish =0;
+}
+
+
+static void trust_added(DBusGProxy *object,
+				const char *address, gpointer user_data)
+{
+}
+
+static void trust_removed(DBusGProxy *object,
+				const char *address, gpointer user_data)
+{
+}
+
+static void set_new_mode(struct adapter_data *adapter, const char *mode)
+{
+	g_free(adapter->old_mode);
+
+	adapter->old_mode = g_strdup(mode);
+}
+
+static void mode_changed(DBusGProxy *object,
+				const char *mode, gpointer user_data)
+{
+	struct adapter_data *adapter = (struct adapter_data *) user_data;
+	const char *adapter_name = NULL;
+	const char *text;
+
+		if (g_str_equal(mode, "off") == TRUE) {
+			set_new_mode(adapter, mode);
+			return;
+		}
+		if (g_str_equal(adapter->old_mode, "off")
+				&& g_str_equal(mode, "connectable")) {
+			set_new_mode(adapter, mode);
+			return;
+		}
+	
+
+	if (g_str_equal(mode, "off") != FALSE) {
+		text = N_("Device has been switched off");
+	} else if (g_str_equal(mode, "connectable") != FALSE
+		   && g_str_equal(adapter->old_mode, "discoverable") != FALSE) {
+		text = N_("Device has been made non-discoverable");
+	} else if (g_str_equal(mode, "connectable") != FALSE) {
+		text = N_("Device has been made connectable");
+	} else if (g_str_equal (mode, "discoverable") != FALSE) {
+		text = N_("Device has been made discoverable");
+	} else if (g_str_equal(mode, "limited") != FALSE) {
+		text = N_("Device has been made limited discoverable");
+	} else if (g_str_equal(mode, "pairing") != FALSE) {
+		text = N_("Device has been switched into pairing mode");
+	} else {
+		set_new_mode(adapter, mode);
+		return;
+	}
+
+	dbus_g_proxy_call(object, "GetName", NULL, G_TYPE_INVALID,
+				G_TYPE_STRING, &adapter_name, G_TYPE_INVALID);
+
+	/*show_notification(adapter_name ? adapter_name : _("Bluetooth device"),
+							_(text), NULL, 3000, NULL);
+    */
+
+	set_new_mode(adapter, mode);
+}
+/*
+static void adapter_free(gpointer data, gpointer user_data)
+{
+	struct adapter_data *adapter = data;
+
+	adapter_list = g_list_remove(adapter_list, adapter);
+
+	g_free(adapter->path);
+	g_free(adapter->old_mode);
+	g_free(adapter);
+}
+
+static void adapter_disable(gpointer data, gpointer user_data)
+{
+	struct adapter_data *adapter = data;
+
+	adapter->attached = 0;
+}
+*/
+
+static gint adapter_compare(gconstpointer a, gconstpointer b)
+{
+	const struct adapter_data *adapter = a;
+	const char *path = b;
+
+	return g_ascii_strcasecmp(adapter->path, path);
+}
+/*
+static void adapter_count(gpointer data, gpointer user_data)
+{
+	struct adapter_data *adapter = data;
+	int *count = user_data;
+
+	if (adapter->attached)
+		(*count)++;
+}
+
+*/
+
+
+void add_bonding(){
+    DBusGProxy *object;
+    
+	object = dbus_g_proxy_new_for_name(bus, "org.bluez",
+						"/org/bluez/passkey", "org.bluez.Adapter");
+
+    dbus_g_proxy_add_signal(object, "BondingCreated",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "BondingCreated",
+				G_CALLBACK(bonding_created), NULL, NULL);
+
+	dbus_g_proxy_add_signal(object, "BondingRemoved",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "BondingRemoved",
+				G_CALLBACK(bonding_removed), NULL, NULL);
+}
+static void add_adapter(const char *path)
+{
+	GList *list;
+	DBusGProxy *object;
+	struct adapter_data *adapter;
+	const char *old_mode;
+
+	list = g_list_find_custom(adapter_list, path, adapter_compare);
+	if (list && list->data) {
+		struct adapter_data *adapter = list->data;
+
+		adapter->attached = 1;
+		return;
+	}
+
+	adapter = g_try_malloc0(sizeof(*adapter));
+	if (!adapter)
+		return;
+
+	adapter->path = g_strdup(path);
+	adapter->attached = 1;
+
+	adapter_list = g_list_append(adapter_list, adapter);
+
+
+	object = dbus_g_proxy_new_for_name(bus, "org.bluez",
+						path, "org.bluez.Adapter");
+
+	dbus_g_proxy_add_signal(object, "ModeChanged",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "ModeChanged",
+				G_CALLBACK(mode_changed), adapter, NULL);
+
+	dbus_g_proxy_add_signal(object, "BondingCreated",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "BondingCreated",
+				G_CALLBACK(bonding_created), NULL, NULL);
+
+	dbus_g_proxy_add_signal(object, "BondingRemoved",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "BondingRemoved",
+				G_CALLBACK(bonding_removed), NULL, NULL);
+
+	dbus_g_proxy_add_signal(object, "TrustAdded",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "TrustAdded",
+				G_CALLBACK(trust_added), NULL, NULL);
+
+	dbus_g_proxy_add_signal(object, "TrustRemoved",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "TrustRemoved",
+				G_CALLBACK(trust_removed), NULL, NULL);
+
+	old_mode = NULL;
+	dbus_g_proxy_call(object, "GetMode", NULL,
+			  G_TYPE_INVALID, G_TYPE_STRING,
+			  &old_mode, G_TYPE_INVALID);
+	if (old_mode != NULL)
+		set_new_mode(adapter, old_mode);
+        register_agents();
+}
+
+static void adapter_added(DBusGProxy *object,
+				const char *path, gpointer user_data)
+{
+	printf("adapter added\n");
+    register_agents();
+
+	add_adapter(path);
+}
+
+static void adapter_removed(DBusGProxy *object,
+				const char *path, gpointer user_data)
+{
+	GList *list;
+
+	list = g_list_find_custom(adapter_list, path, adapter_compare);
+	if (list && list->data) {
+		struct adapter_data *adapter = list->data;
+
+		adapter->attached = 0;
+	}
+
+}
+
+
+static int setup_manager(void)
+{
+	DBusGProxy *object;
+	GError *error = NULL;
+	const gchar **array = NULL;
+
+	object = dbus_g_proxy_new_for_name(bus, "org.bluez",
+					"/org/bluez", "org.bluez.Manager");
+
+	dbus_g_proxy_add_signal(object, "AdapterAdded",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "AdapterAdded",
+				G_CALLBACK(adapter_added), NULL, NULL);
+
+	dbus_g_proxy_add_signal(object, "AdapterRemoved",
+					G_TYPE_STRING, G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal(object, "AdapterRemoved",
+				G_CALLBACK(adapter_removed), NULL, NULL);
+
+	dbus_g_proxy_call(object, "ListAdapters", &error,
+			G_TYPE_INVALID,	G_TYPE_STRV, &array, G_TYPE_INVALID);
+
+	if (error == NULL) {
+		while (*array) {
+            printf("add adapter\n");
+			add_adapter(*array);
+			array++;
+		}
+	} else
+		g_error_free(error);
+
+	return 0;
+}
+
+
+void run_agents()
+{
+    bonding_finish =0;
+    setup_agents(bus);
+    //to add the bounding signals 
+//    register_agents();
+    setup_manager();
+
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bluetooth/agent.h	Thu Aug 07 14:00:40 2008 +0300
@@ -0,0 +1,37 @@
+/*
+ *  Audacious Bluetooth headset suport plugin
+ *
+ *  Copyright (c) 2008 Paula Stanciu <paula.stanciu@gmail.com>
+ *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
+ *  Copyright (C) 2006-2007  Bastien Nocera <hadess@hadess.net>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#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);
+
+int register_agents(void);
+void unregister_agents(void);
+
+void show_agents(void);
+void set_auto_authorize(gboolean value);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bluetooth/auth-agent-glue.h	Thu Aug 07 14:00:40 2008 +0300
@@ -0,0 +1,223 @@
+/* Generated by dbus-binding-tool; do not edit! */
+
+
+#ifndef __dbus_glib_marshal_auth_agent_MARSHAL_H__
+#define __dbus_glib_marshal_auth_agent_MARSHAL_H__
+
+#include	<glib-object.h>
+
+G_BEGIN_DECLS
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v)     g_value_get_char (v)
+#define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v)      g_value_get_int (v)
+#define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
+#define g_marshal_value_peek_long(v)     g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
+#define g_marshal_value_peek_float(v)    g_value_get_float (v)
+#define g_marshal_value_peek_double(v)   g_value_get_double (v)
+#define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v)    g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v)   g_value_get_object (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ *          Do not access GValues directly in your code. Instead, use the
+ *          g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
+#define g_marshal_value_peek_char(v)     (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v)      (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v)    (v)->data[0].v_float
+#define g_marshal_value_peek_double(v)   (v)->data[0].v_double
+#define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+
+/* BOOLEAN:STRING,STRING,STRING,STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.9NIBEU:1) */
+extern void dbus_glib_marshal_auth_agent_BOOLEAN__STRING_STRING_STRING_STRING_POINTER (GClosure     *closure,
+                                                                                       GValue       *return_value,
+                                                                                       guint         n_param_values,
+                                                                                       const GValue *param_values,
+                                                                                       gpointer      invocation_hint,
+                                                                                       gpointer      marshal_data);
+void
+dbus_glib_marshal_auth_agent_BOOLEAN__STRING_STRING_STRING_STRING_POINTER (GClosure     *closure,
+                                                                           GValue       *return_value G_GNUC_UNUSED,
+                                                                           guint         n_param_values,
+                                                                           const GValue *param_values,
+                                                                           gpointer      invocation_hint G_GNUC_UNUSED,
+                                                                           gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__STRING_STRING_STRING_STRING_POINTER) (gpointer     data1,
+                                                                                 gpointer     arg_1,
+                                                                                 gpointer     arg_2,
+                                                                                 gpointer     arg_3,
+                                                                                 gpointer     arg_4,
+                                                                                 gpointer     arg_5,
+                                                                                 gpointer     data2);
+  register GMarshalFunc_BOOLEAN__STRING_STRING_STRING_STRING_POINTER callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 6);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__STRING_STRING_STRING_STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_string (param_values + 1),
+                       g_marshal_value_peek_string (param_values + 2),
+                       g_marshal_value_peek_string (param_values + 3),
+                       g_marshal_value_peek_string (param_values + 4),
+                       g_marshal_value_peek_pointer (param_values + 5),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+/* NONE:STRING,STRING,STRING,STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.9NIBEU:2) */
+extern void dbus_glib_marshal_auth_agent_VOID__STRING_STRING_STRING_STRING_POINTER (GClosure     *closure,
+                                                                                    GValue       *return_value,
+                                                                                    guint         n_param_values,
+                                                                                    const GValue *param_values,
+                                                                                    gpointer      invocation_hint,
+                                                                                    gpointer      marshal_data);
+void
+dbus_glib_marshal_auth_agent_VOID__STRING_STRING_STRING_STRING_POINTER (GClosure     *closure,
+                                                                        GValue       *return_value G_GNUC_UNUSED,
+                                                                        guint         n_param_values,
+                                                                        const GValue *param_values,
+                                                                        gpointer      invocation_hint G_GNUC_UNUSED,
+                                                                        gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__STRING_STRING_STRING_STRING_POINTER) (gpointer     data1,
+                                                                          gpointer     arg_1,
+                                                                          gpointer     arg_2,
+                                                                          gpointer     arg_3,
+                                                                          gpointer     arg_4,
+                                                                          gpointer     arg_5,
+                                                                          gpointer     data2);
+  register GMarshalFunc_VOID__STRING_STRING_STRING_STRING_POINTER callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+
+  g_return_if_fail (n_param_values == 6);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__STRING_STRING_STRING_STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_string (param_values + 1),
+            g_marshal_value_peek_string (param_values + 2),
+            g_marshal_value_peek_string (param_values + 3),
+            g_marshal_value_peek_string (param_values + 4),
+            g_marshal_value_peek_pointer (param_values + 5),
+            data2);
+}
+#define dbus_glib_marshal_auth_agent_NONE__STRING_STRING_STRING_STRING_POINTER	dbus_glib_marshal_auth_agent_VOID__STRING_STRING_STRING_STRING_POINTER
+
+/* BOOLEAN:POINTER (/tmp/dbus-binding-tool-c-marshallers.9NIBEU:3) */
+extern void dbus_glib_marshal_auth_agent_BOOLEAN__POINTER (GClosure     *closure,
+                                                           GValue       *return_value,
+                                                           guint         n_param_values,
+                                                           const GValue *param_values,
+                                                           gpointer      invocation_hint,
+                                                           gpointer      marshal_data);
+void
+dbus_glib_marshal_auth_agent_BOOLEAN__POINTER (GClosure     *closure,
+                                               GValue       *return_value G_GNUC_UNUSED,
+                                               guint         n_param_values,
+                                               const GValue *param_values,
+                                               gpointer      invocation_hint G_GNUC_UNUSED,
+                                               gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER) (gpointer     data1,
+                                                     gpointer     arg_1,
+                                                     gpointer     data2);
+  register GMarshalFunc_BOOLEAN__POINTER callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 2);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_pointer (param_values + 1),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+G_END_DECLS
+
+#endif /* __dbus_glib_marshal_auth_agent_MARSHAL_H__ */
+
+#include <dbus/dbus-glib.h>
+static const DBusGMethodInfo dbus_glib_auth_agent_methods[] = {
+  { (GCallback) auth_agent_authorize, dbus_glib_marshal_auth_agent_NONE__STRING_STRING_STRING_STRING_POINTER, 0 },
+  { (GCallback) auth_agent_cancel, dbus_glib_marshal_auth_agent_BOOLEAN__STRING_STRING_STRING_STRING_POINTER, 87 },
+  { (GCallback) auth_agent_release, dbus_glib_marshal_auth_agent_BOOLEAN__POINTER, 171 },
+};
+
+const DBusGObjectInfo dbus_glib_auth_agent_object_info = {
+  0,
+  dbus_glib_auth_agent_methods,
+  3,
+"org.bluez.AuthorizationAgent\0Authorize\0A\0adapter\0I\0s\0address\0I\0s\0service\0I\0s\0uuid\0I\0s\0\0org.bluez.AuthorizationAgent\0Cancel\0S\0adapter\0I\0s\0address\0I\0s\0service\0I\0s\0uuid\0I\0s\0\0org.bluez.AuthorizationAgent\0Release\0S\0\0\0",
+"\0",
+"\0"
+};
+
--- a/src/bluetooth/bluetooth.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/bluetooth/bluetooth.c	Thu Aug 07 14:00:40 2008 +0300
@@ -1,20 +1,37 @@
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <glib-object.h>
-#include <stdio.h>
+/*
+ * Audacious Bluetooth headset suport plugin
+ *
+ * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ */
+
+#include <glib/gstdio.h>
+#include <errno.h>
+#include <string.h>
 #include "bluetooth.h"
 #include "marshal.h"
 #include "gui.h"
 #include "scan_gui.h"
+#include "agent.h"
+#include <audacious/plugin.h>
 #define DEBUG 1
-static gboolean plugin_active = FALSE,exiting=FALSE;
 GList * current_device = NULL;
-DBusGConnection * bus = NULL;
-DBusGProxy * obj = NULL;
 gint config = 0;
 gint devices_no = 0;
 GStaticMutex mutex = G_STATIC_MUTEX_INIT;
-
+static gchar *current_address=NULL;
+static GThread *connect_th;
 void bluetooth_init ( void );
 void bluetooth_cleanup ( void );
 void bt_cfg(void);
@@ -26,8 +43,8 @@
 static void discovery_completed(DBusGProxy *object, gpointer user_data);
 void discover_devices(void);
 void disconnect_dbus_signals(void);
-
-
+/*static void show_restart_dialog(void); */
+static void remove_bonding();
 GeneralPlugin bluetooth_gp =
 {
     .description = "Bluetooth audio support",
@@ -42,28 +59,36 @@
 void bluetooth_init ( void )
 {
     audio_devices = NULL;
+    bus = NULL;
+    obj = NULL;
     discover_devices();
 }
 
 void bluetooth_cleanup ( void )
 {
     printf("bluetooth: exit\n");
-    if (config ==1 ){
+    if (config ==1 )
+    {
         close_window();
         config =0;
     }
+    remove_bonding();
     if(discover_finish == 2) {
         dbus_g_connection_flush (bus);
         dbus_g_connection_unref(bus);
         disconnect_dbus_signals();
 
     }
+    /* switching back to default pcm device at cleanup */
+    mcs_handle_t *cfgfile = aud_cfg_db_open();
+    aud_cfg_db_set_string(cfgfile,"ALSA","pcm_device", "default");
+    aud_cfg_db_close(cfgfile);
+
 }
 
 void bt_about( void )
 {
     printf("about call\n");
-    show_scan();
 }
 
 void bt_cfg(void)
@@ -73,12 +98,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");
 }
 
@@ -91,14 +116,20 @@
 
 }
 
-void clean_devices_list(){
+void clean_devices_list()
+{
     g_list_free(audio_devices);
     dbus_g_connection_flush (bus);
     dbus_g_connection_unref(bus);
     audio_devices = NULL;
     //g_list_free(current_device);
 }
+static void remove_bonding()
+{
+    dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_INT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
+    dbus_g_proxy_call(obj,"RemoveBonding",NULL,G_TYPE_STRING,"00:0D:3C:B1:1C:7A",G_TYPE_INVALID,G_TYPE_INVALID); 
 
+}
 void refresh_call(void)
 {
     printf("refresh function called\n");
@@ -109,18 +140,106 @@
 
         discover_devices();
         close_window();
-        show_scan();
+        show_scan(0);
     }
     else 
         printf("Scanning please wait!\n");
 }
 
+gpointer connect_call_th(void)
+{
+
+    //I will have to enable the audio service if necessary 
+
+    dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_INT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID);
+    run_agents();
+    dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,current_address,G_TYPE_INVALID,G_TYPE_INVALID); 
+    return NULL;
+}
 void connect_call(void)
 {
-    printf("connect function \n");
+    current_address = g_strdup(((DeviceData*)(selected_dev->data))->address);
+    connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; 
+    close_call();
+    close_window();
+    show_scan(1);
 }
 
 
+void play_call()
+{
+
+    FILE *file;
+    FILE *temp_file;
+    gint prev=0;
+    char line[128];
+    const gchar *home;
+    gchar *device_line;
+    gchar *file_name="";
+    gchar *temp_file_name;
+    home = g_get_home_dir();
+    file_name = g_strconcat(home,"/.asoundrc",NULL);
+    temp_file_name = g_strconcat(home,"/temp_bt",NULL);
+    file = fopen(file_name,"r");
+    temp_file = fopen(temp_file_name,"w");
+    device_line = g_strdup_printf("device %s\n",current_address);
+    if ( file != NULL )
+    {
+        while ( fgets ( line, sizeof line, file ) != NULL )
+        {
+            if(!(strcmp(line,"pcm.audacious_bt{\n"))){
+                fputs(line,temp_file);
+                fgets ( line, sizeof line, file ); /* type bluetooth */
+                fputs(line,temp_file);
+                fgets ( line, sizeof line, file ); /* device MAC */
+                fputs(device_line,temp_file);
+                prev = 1;
+            } else 
+                fputs(line,temp_file);
+        }
+
+        fclose (file);
+    }
+    if(!prev){
+        fputs("pcm.audacious_bt{\n",temp_file);
+        fputs("type bluetooth\n",temp_file);
+        fputs(device_line,temp_file);
+        fputs("}\n",temp_file);
+        prev = 0;
+    }
+
+    fclose(temp_file);
+    int err = rename(temp_file_name,file_name);
+    printf("rename error : %d",err);
+    perror("zz");
+    g_free(device_line);
+    g_free(file_name);
+    g_free(temp_file_name);
+    mcs_handle_t *cfgfile = aud_cfg_db_open();
+    aud_cfg_db_set_string(cfgfile,"ALSA","pcm_device", "audacious_bt");
+    aud_cfg_db_close(cfgfile);
+
+    printf("play callback\n");
+    close_window();
+    aud_output_plugin_cleanup();
+    audacious_drct_stop();
+    audacious_drct_play();
+
+
+}
+/*static void show_restart_dialog()
+{
+    static GtkWidget *window = NULL;
+    GtkWidget *dialog;
+    dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+            GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+            GTK_MESSAGE_INFO,
+            GTK_BUTTONS_OK,
+            "Please restart the player to apply the bluetooth audio settings!");
+    gtk_dialog_run (GTK_DIALOG (dialog));
+    gtk_widget_destroy (dialog);
+}
+*/
 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data)
 {
     int found_in_list=FALSE; 
--- a/src/bluetooth/bluetooth.h	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/bluetooth/bluetooth.h	Thu Aug 07 14:00:40 2008 +0300
@@ -1,5 +1,22 @@
+/*
+ * Audacious Bluetooth headset suport plugin
+ *
+ * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ */
+
 #include <config.h>
-
 #include <glib.h>
 #include <sys/types.h>
 #include <audacious/plugin.h>
@@ -7,6 +24,13 @@
 #include <audacious/i18n.h>
 #include <gtk/gtk.h>
 #include <audacious/util.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <glib-object.h>
+#include <stdio.h>
+#include <audacious/configdb.h>
+#include <audacious/i18n.h>
+#include <audacious/util.h>
 #include "gui.h"
 typedef struct {
     guint class;
@@ -18,7 +42,10 @@
 
 void refresh_call(void);
 void connect_call(void);
+void play_call(void);
 GList * audio_devices;
 gint discover_finish ;
+DBusGConnection * bus;
+DBusGProxy * obj;
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bluetooth/dbus-glue.h	Thu Aug 07 14:00:40 2008 +0300
@@ -0,0 +1,813 @@
+/* Generated by dbus-binding-tool; do not edit! */
+
+#include <glib/gtypes.h>
+#include <glib/gerror.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+#ifndef DBUS_GLIB_CLIENT_WRAPPERS_manager
+#define DBUS_GLIB_CLIENT_WRAPPERS_manager
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+manager_default_adapter (DBusGProxy *proxy, char ** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "DefaultAdapter", error, G_TYPE_INVALID, G_TYPE_STRING, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*manager_default_adapter_reply) (DBusGProxy *proxy, char * OUT_arg0, GError *error, gpointer userdata);
+
+static void
+manager_default_adapter_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char * OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_arg0, G_TYPE_INVALID);
+  (*(manager_default_adapter_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+manager_default_adapter_async (DBusGProxy *proxy, manager_default_adapter_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "DefaultAdapter", manager_default_adapter_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+manager_find_adapter (DBusGProxy *proxy, const char * IN_pattern, char ** OUT_arg1, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "FindAdapter", error, G_TYPE_STRING, IN_pattern, G_TYPE_INVALID, G_TYPE_STRING, OUT_arg1, G_TYPE_INVALID);
+}
+
+typedef void (*manager_find_adapter_reply) (DBusGProxy *proxy, char * OUT_arg1, GError *error, gpointer userdata);
+
+static void
+manager_find_adapter_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char * OUT_arg1;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_arg1, G_TYPE_INVALID);
+  (*(manager_find_adapter_reply)data->cb) (proxy, OUT_arg1, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+manager_find_adapter_async (DBusGProxy *proxy, const char * IN_pattern, manager_find_adapter_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "FindAdapter", manager_find_adapter_async_callback, stuff, g_free, G_TYPE_STRING, IN_pattern, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+manager_list_adapters (DBusGProxy *proxy, char *** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "ListAdapters", error, G_TYPE_INVALID, G_TYPE_STRV, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*manager_list_adapters_reply) (DBusGProxy *proxy, char * *OUT_arg0, GError *error, gpointer userdata);
+
+static void
+manager_list_adapters_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char ** OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRV, &OUT_arg0, G_TYPE_INVALID);
+  (*(manager_list_adapters_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+manager_list_adapters_async (DBusGProxy *proxy, manager_list_adapters_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "ListAdapters", manager_list_adapters_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_manager */
+
+#ifndef DBUS_GLIB_CLIENT_WRAPPERS_security
+#define DBUS_GLIB_CLIENT_WRAPPERS_security
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+security_register_default_passkey_agent (DBusGProxy *proxy, const char * IN_path, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "RegisterDefaultPasskeyAgent", error, G_TYPE_STRING, IN_path, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*security_register_default_passkey_agent_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+security_register_default_passkey_agent_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(security_register_default_passkey_agent_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+security_register_default_passkey_agent_async (DBusGProxy *proxy, const char * IN_path, security_register_default_passkey_agent_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "RegisterDefaultPasskeyAgent", security_register_default_passkey_agent_async_callback, stuff, g_free, G_TYPE_STRING, IN_path, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+security_unregister_default_passkey_agent (DBusGProxy *proxy, const char * IN_path, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "UnregisterDefaultPasskeyAgent", error, G_TYPE_STRING, IN_path, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*security_unregister_default_passkey_agent_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+security_unregister_default_passkey_agent_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(security_unregister_default_passkey_agent_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+security_unregister_default_passkey_agent_async (DBusGProxy *proxy, const char * IN_path, security_unregister_default_passkey_agent_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "UnregisterDefaultPasskeyAgent", security_unregister_default_passkey_agent_async_callback, stuff, g_free, G_TYPE_STRING, IN_path, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+security_register_passkey_agent (DBusGProxy *proxy, const char * IN_path, const char * IN_address, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "RegisterPasskeyAgent", error, G_TYPE_STRING, IN_path, G_TYPE_STRING, IN_address, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*security_register_passkey_agent_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+security_register_passkey_agent_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(security_register_passkey_agent_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+security_register_passkey_agent_async (DBusGProxy *proxy, const char * IN_path, const char * IN_address, security_register_passkey_agent_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "RegisterPasskeyAgent", security_register_passkey_agent_async_callback, stuff, g_free, G_TYPE_STRING, IN_path, G_TYPE_STRING, IN_address, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+security_unregister_passkey_agent (DBusGProxy *proxy, const char * IN_path, const char * IN_address, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "UnregisterPasskeyAgent", error, G_TYPE_STRING, IN_path, G_TYPE_STRING, IN_address, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*security_unregister_passkey_agent_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+security_unregister_passkey_agent_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(security_unregister_passkey_agent_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+security_unregister_passkey_agent_async (DBusGProxy *proxy, const char * IN_path, const char * IN_address, security_unregister_passkey_agent_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "UnregisterPasskeyAgent", security_unregister_passkey_agent_async_callback, stuff, g_free, G_TYPE_STRING, IN_path, G_TYPE_STRING, IN_address, G_TYPE_INVALID);
+}
+#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_security */
+
+#ifndef DBUS_GLIB_CLIENT_WRAPPERS_adapter
+#define DBUS_GLIB_CLIENT_WRAPPERS_adapter
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_get_address (DBusGProxy *proxy, char ** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "GetAddress", error, G_TYPE_INVALID, G_TYPE_STRING, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_get_address_reply) (DBusGProxy *proxy, char * OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_get_address_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char * OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_get_address_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_get_address_async (DBusGProxy *proxy, adapter_get_address_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "GetAddress", adapter_get_address_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_get_mode (DBusGProxy *proxy, char ** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "GetMode", error, G_TYPE_INVALID, G_TYPE_STRING, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_get_mode_reply) (DBusGProxy *proxy, char * OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_get_mode_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char * OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_get_mode_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_get_mode_async (DBusGProxy *proxy, adapter_get_mode_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "GetMode", adapter_get_mode_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_get_name (DBusGProxy *proxy, char ** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "GetName", error, G_TYPE_INVALID, G_TYPE_STRING, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_get_name_reply) (DBusGProxy *proxy, char * OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_get_name_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char * OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_get_name_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_get_name_async (DBusGProxy *proxy, adapter_get_name_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "GetName", adapter_get_name_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_get_major_class (DBusGProxy *proxy, char ** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "GetMajorClass", error, G_TYPE_INVALID, G_TYPE_STRING, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_get_major_class_reply) (DBusGProxy *proxy, char * OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_get_major_class_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char * OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_get_major_class_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_get_major_class_async (DBusGProxy *proxy, adapter_get_major_class_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "GetMajorClass", adapter_get_major_class_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_get_minor_class (DBusGProxy *proxy, char ** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "GetMinorClass", error, G_TYPE_INVALID, G_TYPE_STRING, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_get_minor_class_reply) (DBusGProxy *proxy, char * OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_get_minor_class_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char * OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_get_minor_class_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_get_minor_class_async (DBusGProxy *proxy, adapter_get_minor_class_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "GetMinorClass", adapter_get_minor_class_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_list_remote_devices (DBusGProxy *proxy, char *** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "ListRemoteDevices", error, G_TYPE_INVALID, G_TYPE_STRV, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_list_remote_devices_reply) (DBusGProxy *proxy, char * *OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_list_remote_devices_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char ** OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRV, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_list_remote_devices_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_list_remote_devices_async (DBusGProxy *proxy, adapter_list_remote_devices_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "ListRemoteDevices", adapter_list_remote_devices_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_list_connections (DBusGProxy *proxy, char *** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "ListConnections", error, G_TYPE_INVALID, G_TYPE_STRV, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_list_connections_reply) (DBusGProxy *proxy, char * *OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_list_connections_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char ** OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRV, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_list_connections_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_list_connections_async (DBusGProxy *proxy, adapter_list_connections_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "ListConnections", adapter_list_connections_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_list_bondings (DBusGProxy *proxy, char *** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "ListBondings", error, G_TYPE_INVALID, G_TYPE_STRV, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_list_bondings_reply) (DBusGProxy *proxy, char * *OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_list_bondings_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char ** OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRV, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_list_bondings_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_list_bondings_async (DBusGProxy *proxy, adapter_list_bondings_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "ListBondings", adapter_list_bondings_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_list_trusts (DBusGProxy *proxy, char *** OUT_arg0, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "ListTrusts", error, G_TYPE_INVALID, G_TYPE_STRV, OUT_arg0, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_list_trusts_reply) (DBusGProxy *proxy, char * *OUT_arg0, GError *error, gpointer userdata);
+
+static void
+adapter_list_trusts_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  char ** OUT_arg0;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRV, &OUT_arg0, G_TYPE_INVALID);
+  (*(adapter_list_trusts_reply)data->cb) (proxy, OUT_arg0, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_list_trusts_async (DBusGProxy *proxy, adapter_list_trusts_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "ListTrusts", adapter_list_trusts_async_callback, stuff, g_free, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_disconnect_remote_device (DBusGProxy *proxy, const char * IN_address, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "DisconnectRemoteDevice", error, G_TYPE_STRING, IN_address, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_disconnect_remote_device_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+adapter_disconnect_remote_device_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(adapter_disconnect_remote_device_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_disconnect_remote_device_async (DBusGProxy *proxy, const char * IN_address, adapter_disconnect_remote_device_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "DisconnectRemoteDevice", adapter_disconnect_remote_device_async_callback, stuff, g_free, G_TYPE_STRING, IN_address, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_create_bonding (DBusGProxy *proxy, const char * IN_address, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "CreateBonding", error, G_TYPE_STRING, IN_address, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_create_bonding_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+adapter_create_bonding_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(adapter_create_bonding_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_create_bonding_async (DBusGProxy *proxy, const char * IN_address, adapter_create_bonding_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "CreateBonding", adapter_create_bonding_async_callback, stuff, g_free, G_TYPE_STRING, IN_address, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_remove_bonding (DBusGProxy *proxy, const char * IN_address, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "RemoveBonding", error, G_TYPE_STRING, IN_address, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_remove_bonding_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+adapter_remove_bonding_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(adapter_remove_bonding_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_remove_bonding_async (DBusGProxy *proxy, const char * IN_address, adapter_remove_bonding_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "RemoveBonding", adapter_remove_bonding_async_callback, stuff, g_free, G_TYPE_STRING, IN_address, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_set_trusted (DBusGProxy *proxy, const char * IN_address, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "SetTrusted", error, G_TYPE_STRING, IN_address, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_set_trusted_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+adapter_set_trusted_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(adapter_set_trusted_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_set_trusted_async (DBusGProxy *proxy, const char * IN_address, adapter_set_trusted_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "SetTrusted", adapter_set_trusted_async_callback, stuff, g_free, G_TYPE_STRING, IN_address, G_TYPE_INVALID);
+}
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+gboolean
+adapter_remove_trust (DBusGProxy *proxy, const char * IN_address, GError **error)
+
+{
+  return dbus_g_proxy_call (proxy, "RemoveTrust", error, G_TYPE_STRING, IN_address, G_TYPE_INVALID, G_TYPE_INVALID);
+}
+
+typedef void (*adapter_remove_trust_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
+
+static void
+adapter_remove_trust_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
+{
+  DBusGAsyncData *data = (DBusGAsyncData*) user_data;
+  GError *error = NULL;
+  dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
+  (*(adapter_remove_trust_reply)data->cb) (proxy, error, data->userdata);
+  return;
+}
+
+static
+#ifdef G_HAVE_INLINE
+inline
+#endif
+DBusGProxyCall*
+adapter_remove_trust_async (DBusGProxy *proxy, const char * IN_address, adapter_remove_trust_reply callback, gpointer userdata)
+
+{
+  DBusGAsyncData *stuff;
+  stuff = g_new (DBusGAsyncData, 1);
+  stuff->cb = G_CALLBACK (callback);
+  stuff->userdata = userdata;
+  return dbus_g_proxy_begin_call (proxy, "RemoveTrust", adapter_remove_trust_async_callback, stuff, g_free, G_TYPE_STRING, IN_address, G_TYPE_INVALID);
+}
+#endif /* defined DBUS_GLIB_CLIENT_WRAPPERS_adapter */
+
+G_END_DECLS
--- a/src/bluetooth/gui.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/bluetooth/gui.c	Thu Aug 07 14:00:40 2008 +0300
@@ -1,3 +1,21 @@
+/*
+ * Audacious Bluetooth headset suport plugin
+ *
+ * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ */
+
 #include "gui.h"
 #include "bluetooth.h"
 
@@ -66,8 +84,7 @@
     GtkTreeIter iter;
     gint dev_no=0;
     GList *dev;
-    gchar *temp;
-    if(!window) 
+      if(!window) 
         return NULL;
     /* create list store */
     store = gtk_list_store_new(NUM_COLUMNS,
@@ -100,12 +117,12 @@
                 ((DeviceData*)(dev->data))-> name,-1);
         dev = g_list_next(dev);
     }
-    //set the labels
-    //   temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class);
+    /*set the labels */
+    /*   temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class); */
     gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(dev->data))->name);
-    //    gtk_label_set_text(GTK_LABEL(label_class),temp);
+    /*    gtk_label_set_text(GTK_LABEL(label_class),temp); */
     gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address);
-    g_free(temp);
+   /* g_free(temp); */
     return GTK_TREE_MODEL(store);          
 
 }
@@ -156,14 +173,14 @@
         path = gtk_tree_model_get_path (model, &iter);
         sel = gtk_tree_path_get_indices (path)[0];
         printf("i=%d\n",sel);
-        dev = audio_devices;
+        selected_dev = audio_devices;
         for(i=0;i<sel;i++) 
-            dev = g_list_next(dev);
+           selected_dev = g_list_next(dev);
         if(dev != NULL) {
-            temp = g_strdup_printf("0x%x",((DeviceData*)(dev->data))->class);
-            gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(dev->data))->name);
+            temp = g_strdup_printf("0x%x",((DeviceData*)(selected_dev->data))->class);
+            gtk_label_set_text(GTK_LABEL(label_prod),((DeviceData*)(selected_dev->data))->name);
             gtk_label_set_text(GTK_LABEL(label_class),temp);
-            gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address);
+            gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(selected_dev->data))->address);
             gtk_tree_path_free (path);
             g_free(temp);
         }else 
@@ -174,11 +191,12 @@
 }
 
 void refresh_resultsui(){
-  gtk_widget_destroy (window);
-  window = NULL;
-  refresh_call();
+    gtk_widget_destroy (window);
+    window = NULL;
+    selected_dev = NULL;
+    refresh_call();
 }
-   
+
 
 void results_ui()
 {
--- a/src/bluetooth/gui.h	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/bluetooth/gui.h	Thu Aug 07 14:00:40 2008 +0300
@@ -1,6 +1,27 @@
+/*
+ * Audacious Bluetooth headset suport plugin
+ *
+ * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ */
+
 #include <gtk/gtk.h>
 #include <glib.h>
+
+GList *selected_dev ;
 void refresh_tree(void);
 void results_ui();
+void close_call(void);
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/bluetooth/passkey-agent-glue.h	Thu Aug 07 14:00:40 2008 +0300
@@ -0,0 +1,264 @@
+/* Generated by dbus-binding-tool; do not edit! */
+
+
+#ifndef __dbus_glib_marshal_passkey_agent_MARSHAL_H__
+#define __dbus_glib_marshal_passkey_agent_MARSHAL_H__
+
+#include	<glib-object.h>
+
+G_BEGIN_DECLS
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v)     g_value_get_char (v)
+#define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v)      g_value_get_int (v)
+#define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
+#define g_marshal_value_peek_long(v)     g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
+#define g_marshal_value_peek_float(v)    g_value_get_float (v)
+#define g_marshal_value_peek_double(v)   g_value_get_double (v)
+#define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v)    g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v)   g_value_get_object (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ *          Do not access GValues directly in your code. Instead, use the
+ *          g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
+#define g_marshal_value_peek_char(v)     (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v)      (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v)    (v)->data[0].v_float
+#define g_marshal_value_peek_double(v)   (v)->data[0].v_double
+#define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+
+/* BOOLEAN:STRING,STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.70BCEU:1) */
+extern void dbus_glib_marshal_passkey_agent_BOOLEAN__STRING_STRING_POINTER (GClosure     *closure,
+                                                                            GValue       *return_value,
+                                                                            guint         n_param_values,
+                                                                            const GValue *param_values,
+                                                                            gpointer      invocation_hint,
+                                                                            gpointer      marshal_data);
+void
+dbus_glib_marshal_passkey_agent_BOOLEAN__STRING_STRING_POINTER (GClosure     *closure,
+                                                                GValue       *return_value G_GNUC_UNUSED,
+                                                                guint         n_param_values,
+                                                                const GValue *param_values,
+                                                                gpointer      invocation_hint G_GNUC_UNUSED,
+                                                                gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__STRING_STRING_POINTER) (gpointer     data1,
+                                                                   gpointer     arg_1,
+                                                                   gpointer     arg_2,
+                                                                   gpointer     arg_3,
+                                                                   gpointer     data2);
+  register GMarshalFunc_BOOLEAN__STRING_STRING_POINTER callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__STRING_STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_string (param_values + 1),
+                       g_marshal_value_peek_string (param_values + 2),
+                       g_marshal_value_peek_pointer (param_values + 3),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+/* NONE:STRING,STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.70BCEU:2) */
+extern void dbus_glib_marshal_passkey_agent_VOID__STRING_STRING_POINTER (GClosure     *closure,
+                                                                         GValue       *return_value,
+                                                                         guint         n_param_values,
+                                                                         const GValue *param_values,
+                                                                         gpointer      invocation_hint,
+                                                                         gpointer      marshal_data);
+void
+dbus_glib_marshal_passkey_agent_VOID__STRING_STRING_POINTER (GClosure     *closure,
+                                                             GValue       *return_value G_GNUC_UNUSED,
+                                                             guint         n_param_values,
+                                                             const GValue *param_values,
+                                                             gpointer      invocation_hint G_GNUC_UNUSED,
+                                                             gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__STRING_STRING_POINTER) (gpointer     data1,
+                                                            gpointer     arg_1,
+                                                            gpointer     arg_2,
+                                                            gpointer     arg_3,
+                                                            gpointer     data2);
+  register GMarshalFunc_VOID__STRING_STRING_POINTER callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__STRING_STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_string (param_values + 1),
+            g_marshal_value_peek_string (param_values + 2),
+            g_marshal_value_peek_pointer (param_values + 3),
+            data2);
+}
+#define dbus_glib_marshal_passkey_agent_NONE__STRING_STRING_POINTER	dbus_glib_marshal_passkey_agent_VOID__STRING_STRING_POINTER
+
+/* NONE:STRING,STRING,STRING,POINTER (/tmp/dbus-binding-tool-c-marshallers.70BCEU:3) */
+extern void dbus_glib_marshal_passkey_agent_VOID__STRING_STRING_STRING_POINTER (GClosure     *closure,
+                                                                                GValue       *return_value,
+                                                                                guint         n_param_values,
+                                                                                const GValue *param_values,
+                                                                                gpointer      invocation_hint,
+                                                                                gpointer      marshal_data);
+void
+dbus_glib_marshal_passkey_agent_VOID__STRING_STRING_STRING_POINTER (GClosure     *closure,
+                                                                    GValue       *return_value G_GNUC_UNUSED,
+                                                                    guint         n_param_values,
+                                                                    const GValue *param_values,
+                                                                    gpointer      invocation_hint G_GNUC_UNUSED,
+                                                                    gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__STRING_STRING_STRING_POINTER) (gpointer     data1,
+                                                                   gpointer     arg_1,
+                                                                   gpointer     arg_2,
+                                                                   gpointer     arg_3,
+                                                                   gpointer     arg_4,
+                                                                   gpointer     data2);
+  register GMarshalFunc_VOID__STRING_STRING_STRING_POINTER callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+
+  g_return_if_fail (n_param_values == 5);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__STRING_STRING_STRING_POINTER) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_string (param_values + 1),
+            g_marshal_value_peek_string (param_values + 2),
+            g_marshal_value_peek_string (param_values + 3),
+            g_marshal_value_peek_pointer (param_values + 4),
+            data2);
+}
+#define dbus_glib_marshal_passkey_agent_NONE__STRING_STRING_STRING_POINTER	dbus_glib_marshal_passkey_agent_VOID__STRING_STRING_STRING_POINTER
+
+/* BOOLEAN:POINTER (/tmp/dbus-binding-tool-c-marshallers.70BCEU:4) */
+extern void dbus_glib_marshal_passkey_agent_BOOLEAN__POINTER (GClosure     *closure,
+                                                              GValue       *return_value,
+                                                              guint         n_param_values,
+                                                              const GValue *param_values,
+                                                              gpointer      invocation_hint,
+                                                              gpointer      marshal_data);
+void
+dbus_glib_marshal_passkey_agent_BOOLEAN__POINTER (GClosure     *closure,
+                                                  GValue       *return_value G_GNUC_UNUSED,
+                                                  guint         n_param_values,
+                                                  const GValue *param_values,
+                                                  gpointer      invocation_hint G_GNUC_UNUSED,
+                                                  gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__POINTER) (gpointer     data1,
+                                                     gpointer     arg_1,
+                                                     gpointer     data2);
+  register GMarshalFunc_BOOLEAN__POINTER callback;
+  register GCClosure *cc = (GCClosure*) closure;
+  register gpointer data1, data2;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 2);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__POINTER) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_pointer (param_values + 1),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+G_END_DECLS
+
+#endif /* __dbus_glib_marshal_passkey_agent_MARSHAL_H__ */
+
+#include <dbus/dbus-glib.h>
+static const DBusGMethodInfo dbus_glib_passkey_agent_methods[] = {
+  { (GCallback) passkey_agent_request, dbus_glib_marshal_passkey_agent_NONE__STRING_STRING_POINTER, 0 },
+  { (GCallback) passkey_agent_confirm, dbus_glib_marshal_passkey_agent_NONE__STRING_STRING_STRING_POINTER, 68 },
+  { (GCallback) passkey_agent_cancel, dbus_glib_marshal_passkey_agent_BOOLEAN__STRING_STRING_POINTER, 133 },
+  { (GCallback) passkey_agent_release, dbus_glib_marshal_passkey_agent_BOOLEAN__POINTER, 187 },
+};
+
+const DBusGObjectInfo dbus_glib_passkey_agent_object_info = {
+  0,
+  dbus_glib_passkey_agent_methods,
+  4,
+"org.bluez.PasskeyAgent\0Request\0A\0path\0I\0s\0address\0I\0s\0arg2\0O\0F\0N\0s\0\0org.bluez.PasskeyAgent\0Confirm\0A\0path\0I\0s\0address\0I\0s\0value\0I\0s\0\0org.bluez.PasskeyAgent\0Cancel\0S\0path\0I\0s\0address\0I\0s\0\0org.bluez.PasskeyAgent\0Release\0S\0\0\0",
+"\0",
+"\0"
+};
+
--- a/src/bluetooth/scan_gui.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/bluetooth/scan_gui.c	Thu Aug 07 14:00:40 2008 +0300
@@ -1,5 +1,24 @@
+/*
+ * Audacious Bluetooth headset suport plugin
+ *
+ * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ */
+
 #include "scan_gui.h"
 #include "bluetooth.h"
+#include "agent.h"
 static GtkWidget *window = NULL;
 static GtkWidget *winbox;
 static GtkWidget *scanbox;
@@ -10,42 +29,69 @@
 static GtkWidget *progress_bar;
 static GtkWidget *rescan_buttton;
 static GtkWidget *close_button;
-gpointer progress() {
+static gint usage=0;
+void show_pairing_ok(void);
+gpointer progress()
+{
 
     for(;;){
         if(window){
             gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar));
         }
         sleep(1);
-        if(discover_finish == 2 ) {            
-            if(window){
-                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1);
+        if(usage == 0){
+            if(discover_finish == 2 ) {            
+                if(window){
+                    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1);
+                }
+                return 0;
             }
-            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_no_devices(){
+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!"));
     }
 }
-void destroy_scan_window(){
+void destroy_scan_window()
+{
     gtk_widget_hide(window);
 }
-void close_window(void){
+void close_window(void)
+{
     printf("scan_gui close callback \n");
     gtk_widget_destroy (window);
     window = NULL;
 }
-
-
-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);
@@ -66,22 +112,34 @@
         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);
-        rescan_buttton = gtk_button_new_with_mnemonic(_("Rescan"));
-        g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (refresh_call),NULL);
+        /* I have to modify the rescan button with a play one 
+         * and treat the case when the bounding is not ok
+         */
+        if(usage == 0){
+            rescan_buttton = gtk_button_new_with_mnemonic(_("Rescan"));
+            g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (refresh_call),NULL);
+        }else{
+            rescan_buttton = gtk_button_new_with_mnemonic(_("Play"));
+            g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (play_call),NULL);
+        }
+
+
 
         close_button = gtk_button_new_with_mnemonic(_("Close"));
         gtk_container_add(GTK_CONTAINER(buttonsbox),rescan_buttton);
--- a/src/bluetooth/scan_gui.h	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/bluetooth/scan_gui.h	Thu Aug 07 14:00:40 2008 +0300
@@ -1,6 +1,30 @@
+/*
+ * Audacious Bluetooth headset suport plugin
+ *
+ * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses>.
+ */
+
 #include <gtk/gtk.h>
 #include <glib.h>
-void show_scan();
+#include <alsa/asoundlib.h>
+#include <alsa/pcm_plugin.h>
+#include <audacious/plugin.h>
+#include <audacious/i18n.h>
+
+
+void show_scan(gint use);
 void show_no_devices();
 void destroy_scan_window();
 void close_window();
--- a/src/skins/plugin.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/plugin.c	Thu Aug 07 14:00:40 2008 +0300
@@ -79,6 +79,8 @@
     skins_init_paths();
     skins_cfg_load();
 
+    ui_main_check_theme_engine();
+
     register_aud_stock_icons();
     ui_manager_init();
     ui_manager_create_menus();
@@ -105,6 +107,7 @@
 gboolean skins_cleanup(void) {
     if (plugin_is_active == TRUE) {
         skins_cfg_save();
+        cleanup_skins();
         skins_free_paths();
         ui_main_evlistener_dissociate();
         ui_playlist_evlistener_dissociate();
@@ -113,8 +116,6 @@
         gtk_widget_destroy(equalizerwin);
         gtk_widget_destroy(playlistwin);
         ui_manager_destroy();
-        skin_destroy(aud_active_skin);
-        aud_active_skin = NULL;
         mainwin = NULL;
         equalizerwin = NULL;
         playlistwin = NULL;
--- a/src/skins/skins_cfg.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/skins_cfg.c	Thu Aug 07 14:00:40 2008 +0300
@@ -511,7 +511,7 @@
                                 gint x, gint y,
                                 GtkSelectionData * selection_data,
                                 guint info, guint time,
-                                gpointer user_data) 
+                                gpointer user_data)
 {
     mcs_handle_t *db;
     gchar *path;
--- a/src/skins/skins_cfg.h	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/skins_cfg.h	Thu Aug 07 14:00:40 2008 +0300
@@ -88,5 +88,11 @@
 void skins_cfg_save();
 
 GtkWidget* skins_configure(void);
+void on_skin_view_drag_data_received(GtkWidget * widget,
+                                GdkDragContext * context,
+                                gint x, gint y,
+                                GtkSelectionData * selection_data,
+                                guint info, guint time,
+                                gpointer user_data);
 
 #endif
--- a/src/skins/ui_main.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/ui_main.c	Thu Aug 07 14:00:40 2008 +0300
@@ -58,20 +58,6 @@
 #include "ui_hints.h"
 #include "dnd.h"
 #include "plugin.h"
-#if 0
-#include "configdb.h"
-#include "input.h"
-#include "main.h"
-#include "playback.h"
-#include "playlist.h"
-#include "pluginenum.h"
-#include "strings.h"
-#include "ui_dock.h"
-#include "ui_main_evlisteners.h"
-#include "ui_skinselector.h"
-#include "util.h"
-#include "visualization.h"
-#endif
 #include "ui_skinned_window.h"
 #include "ui_skinned_button.h"
 #include "ui_skinned_textbox.h"
@@ -81,6 +67,7 @@
 #include "ui_skinned_playstatus.h"
 #include "ui_skinned_monostereo.h"
 #include "ui_skinned_playlist.h"
+#include "ui_main_evlisteners.h"
 #include <audacious/plugin.h>
 #include "skins_cfg.h"
 
@@ -345,11 +332,7 @@
 static void
 mainwin_destroy(GtkWidget * widget, gpointer data)
 {
-/* we should detect whether plugin got unloaded and when user indeed
-   wants to close audacious */
-#if 0
     mainwin_quit_cb();
-#endif
 }
 
 static gchar *mainwin_tb_old_text = NULL;
@@ -848,7 +831,7 @@
             aud_playlist_next(playlist);
             break;
         case GDK_KP_Insert:
-            audacious_drct_jtf_show();
+            action_jump_to_file();
             break;
         case GDK_Return:
         case GDK_KP_Enter:
@@ -1060,8 +1043,8 @@
 
     /* perhaps make suffix check case-insensitive -- desowin */
     if (aud_str_has_prefix_nocase((char*)selection_data->data, "file:///")) {
-        if (str_has_suffix_nocase((char*)selection_data->data, ".wsz\r\n") ||
-            str_has_suffix_nocase((char*)selection_data->data, ".zip\r\n")) {
+        if (aud_str_has_suffix_nocase((char*)selection_data->data, ".wsz\r\n") ||
+            aud_str_has_suffix_nocase((char*)selection_data->data, ".zip\r\n")) {
             on_skin_view_drag_data_received(GTK_WIDGET(user_data), context, x, y, selection_data, info, time, NULL);
             return;
         }
@@ -1759,7 +1742,7 @@
             mainwin_jump_to_time();
             break;
         case MAINWIN_GENERAL_JTF:
-            audacious_drct_jtf_show();
+            action_jump_to_file();
             break;
         case MAINWIN_GENERAL_EXIT:
             mainwin_quit_cb();
@@ -2695,8 +2678,7 @@
 void
 action_about_audacious( void )
 {
-    gboolean show = TRUE;
-    aud_hook_call("aboutwin show", &show);
+    skins_interface.ops->aboutwin_show();
 }
 
 void
@@ -2759,7 +2741,7 @@
 void
 action_jump_to_file( void )
 {
-    audacious_drct_jtf_show();
+    skins_interface.ops->jump_to_track_show();
 }
 
 void
--- a/src/skins/ui_playlist.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/ui_playlist.c	Thu Aug 07 14:00:40 2008 +0300
@@ -42,14 +42,6 @@
 #include "actions-playlist.h"
 #include "dnd.h"
 #include "plugin.h"
-#if 0
-#include "input.h"
-#include "main.h"
-#include "playback.h"
-#include "playlist.h"
-#include "playlist_container.h"
-#include "strings.h"
-#endif
 #include "ui_dock.h"
 #include "ui_equalizer.h"
 #include "ui_main.h"
--- a/src/skins/ui_skin.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/ui_skin.c	Thu Aug 07 14:00:40 2008 +0300
@@ -1749,42 +1749,25 @@
                 gtk_widget_hide(widget);
                 return;
             }
-            gint x, y;
-            x = -1;
-            y = -1;
 
-            if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(mainwin)->normal) {
-                GList *iter;
-                for (iter = GTK_FIXED (SKINNED_WINDOW(mainwin)->normal)->children; iter; iter = g_list_next (iter)) {
-                     GtkFixedChild *child_data = (GtkFixedChild *) iter->data;
-                     if (child_data->widget == widget) {
-                         x = child_data->x;
-                         y = child_data->y;
-                         break;
-                     }
-                }
+            /* Some skins include SKIN_VOLUME and/or SKIN_BALANCE without knobs */
+            if (pixmap_id == SKIN_VOLUME || pixmap_id == SKIN_BALANCE) {
+                if (ysrc+height > 421 && xsrc+width <= pixmap->width)
+                    return;
+            }
 
-                if (x != -1 && y != -1) {
-                    /* Some skins include SKIN_VOLUME and/or SKIN_BALANCE
-                       without knobs */
-                    if (pixmap_id == SKIN_VOLUME || pixmap_id == SKIN_BALANCE) {
-                        if (ysrc+height > 421 && xsrc+width <= pixmap->width)
-                            return;
-                    }
-                    /* let's copy what's under widget */
-                    gdk_pixbuf_copy_area(skin_get_pixmap(aud_active_skin, SKIN_MAIN)->pixbuf,
-                                         x, y, width, height, pix, xdest, ydest);
+            /* XMMS skins seems to have SKIN_MONOSTEREO with size 58x20 instead of 58x24 */
+            if (pixmap_id == SKIN_MONOSTEREO)
+                height = pixmap->height/2;
 
-                    /* XMMS skins seems to have SKIN_MONOSTEREO with size 58x20 instead of 58x24 */
-                    if (pixmap_id == SKIN_MONOSTEREO)
-                        height = pixmap->height/2;
-                }
-            } else if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(equalizerwin)->normal) {
-                   if (!(pixmap_id == SKIN_EQMAIN && ysrc == 314)) /* equalizer preamp on equalizer graph */
-                         gtk_widget_hide(widget);
-            } else if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(playlistwin)->normal) {
-                   /* I haven't seen any skin with substandard playlist */
-                   gtk_widget_hide(widget);
+            if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(equalizerwin)->normal) {
+                if (!(pixmap_id == SKIN_EQMAIN && ysrc == 314)) /* equalizer preamp on equalizer graph */
+                    gtk_widget_hide(widget);
+            }
+
+            if (gtk_widget_get_parent(widget) == SKINNED_WINDOW(playlistwin)->normal) {
+                /* I haven't seen any skin with substandard playlist */
+                gtk_widget_hide(widget);
             }
         } else
             return;
@@ -2039,16 +2022,19 @@
     aud_active_skin_load(node->path);
 }
 
-
-void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale) {
+void ui_skinned_widget_draw_with_coordinates(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gint destx, gint desty, gboolean scale) {
     g_return_if_fail(widget != NULL);
     g_return_if_fail(obj != NULL);
 
     if (scale) {
         GdkPixbuf *image = gdk_pixbuf_scale_simple(obj, width * config.scale_factor, height* config.scale_factor, GDK_INTERP_NEAREST);
-        gdk_draw_pixbuf(widget->window, NULL, image, 0, 0, 0, 0, width * config.scale_factor , height * config.scale_factor, GDK_RGB_DITHER_NONE, 0, 0);
+        gdk_draw_pixbuf(widget->window, NULL, image, 0, 0, destx, desty, width * config.scale_factor , height * config.scale_factor, GDK_RGB_DITHER_NONE, 0, 0);
         g_object_unref(image);
     } else {
-        gdk_draw_pixbuf(widget->window, NULL, obj, 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, 0, 0);
+        gdk_draw_pixbuf(widget->window, NULL, obj, 0, 0, destx, desty, width, height, GDK_RGB_DITHER_NONE, 0, 0);
     }
 }
+
+void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale) {
+    ui_skinned_widget_draw_with_coordinates(widget, obj, width, height, 0, 0, scale);
+}
--- a/src/skins/ui_skin.h	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/ui_skin.h	Thu Aug 07 14:00:40 2008 +0300
@@ -239,7 +239,7 @@
 
 void skin_set_random_skin(void);
 
-
+void ui_skinned_widget_draw_with_coordinates(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gint destx, gint desty, gboolean scale);
 void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale);
 
 #endif
--- a/src/skins/ui_skinned_button.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/ui_skinned_button.c	Thu Aug 07 14:00:40 2008 +0300
@@ -157,6 +157,8 @@
     priv->move_x = 0;
     priv->move_y = 0;
     button->event_window = NULL;
+
+    GTK_WIDGET_SET_FLAGS (button, GTK_NO_WINDOW);
 }
 
 static void ui_skinned_button_destroy (GtkObject *object) {
@@ -174,38 +176,28 @@
 static void ui_skinned_button_realize (GtkWidget *widget) {
     g_return_if_fail (widget != NULL);
     g_return_if_fail (UI_SKINNED_IS_BUTTON(widget));
+
+    if (GTK_WIDGET_CLASS (parent_class)->realize)
+        (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
+
     UiSkinnedButton *button = UI_SKINNED_BUTTON (widget);
     GdkWindowAttr attributes;
     gint attributes_mask;
 
-    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
-
     attributes.x = widget->allocation.x;
     attributes.y = widget->allocation.y;
     attributes.width = widget->allocation.width;
     attributes.height = widget->allocation.height;
+    attributes.wclass = GDK_INPUT_ONLY;
     attributes.window_type = GDK_WINDOW_CHILD;
     attributes.event_mask = gtk_widget_get_events(widget);
     attributes.event_mask |= GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
 
-    if (button->type == TYPE_SMALL || button->type == TYPE_NOT_SET) {
-        widget->window = gtk_widget_get_parent_window (widget);
-        g_object_ref (widget->window);
-        attributes.wclass = GDK_INPUT_ONLY;
-        attributes_mask = GDK_WA_X | GDK_WA_Y;
-        button->event_window = gdk_window_new (widget->window, &attributes, attributes_mask);
-        GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
-        gdk_window_set_user_data(button->event_window, widget);
-    } else {
-        attributes.visual = gtk_widget_get_visual(widget);
-        attributes.colormap = gtk_widget_get_colormap(widget);
-        attributes.wclass = GDK_INPUT_OUTPUT;
-        attributes.event_mask |= GDK_EXPOSURE_MASK;
-        attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-        widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask);
-        GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
-        gdk_window_set_user_data(widget->window, widget);
-    }
+    attributes.wclass = GDK_INPUT_ONLY;
+    attributes_mask = GDK_WA_X | GDK_WA_Y;
+    button->event_window = gdk_window_new (widget->window, &attributes, attributes_mask);
+
+    gdk_window_set_user_data(button->event_window, widget);
 
     widget->style = gtk_style_attach(widget->style, widget->window);
 }
@@ -289,12 +281,9 @@
     if (button->type == TYPE_SMALL || button->type == TYPE_NOT_SET)
         return FALSE;
 
-    /* paranoia */
-    if (button->event_window != NULL)
-        return FALSE;
-
     GdkPixbuf *obj;
     obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, priv->w, priv->h);
+    gdk_pixbuf_fill(obj, 0x00000000); /* fill with alpha */
 
     switch (button->type) {
         case TYPE_PUSH:
@@ -322,7 +311,10 @@
             break;
     }
 
-    ui_skinned_widget_draw(widget, obj, priv->w, priv->h, priv->scaled);
+    ui_skinned_widget_draw_with_coordinates(widget, obj, priv->w, priv->h,
+                                            widget->allocation.x,
+                                            widget->allocation.y,
+                                            priv->scaled);
     g_object_unref(obj);
 
     return FALSE;
--- a/src/skins/ui_skinned_textbox.c	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/ui_skinned_textbox.c	Thu Aug 07 14:00:40 2008 +0300
@@ -69,6 +69,9 @@
 static void ui_skinned_textbox_init               (UiSkinnedTextbox *textbox);
 static void ui_skinned_textbox_destroy            (GtkObject *object);
 static void ui_skinned_textbox_realize            (GtkWidget *widget);
+static void ui_skinned_textbox_unrealize          (GtkWidget *widget);
+static void ui_skinned_textbox_map                (GtkWidget *widget);
+static void ui_skinned_textbox_unmap              (GtkWidget *widget);
 static void ui_skinned_textbox_size_request       (GtkWidget *widget, GtkRequisition *requisition);
 static void ui_skinned_textbox_size_allocate      (GtkWidget *widget, GtkAllocation *allocation);
 static gboolean ui_skinned_textbox_expose         (GtkWidget *widget, GdkEventExpose *event);
@@ -118,6 +121,9 @@
     object_class->destroy = ui_skinned_textbox_destroy;
 
     widget_class->realize = ui_skinned_textbox_realize;
+    widget_class->unrealize = ui_skinned_textbox_unrealize;
+    widget_class->map = ui_skinned_textbox_map;
+    widget_class->unmap = ui_skinned_textbox_unmap;
     widget_class->expose_event = ui_skinned_textbox_expose;
     widget_class->size_request = ui_skinned_textbox_size_request;
     widget_class->size_allocate = ui_skinned_textbox_size_allocate;
@@ -157,6 +163,9 @@
     UiSkinnedTextboxPrivate *priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(textbox);
     priv->move_x = 0;
     priv->move_y = 0;
+
+    textbox->event_window = NULL;
+    GTK_WIDGET_SET_FLAGS (textbox, GTK_NO_WINDOW);
 }
 
 GtkWidget* ui_skinned_textbox_new(GtkWidget *fixed, gint x, gint y, gint w, gboolean allow_scroll, SkinPixmapId si) {
@@ -185,11 +194,18 @@
 
 static void ui_skinned_textbox_destroy(GtkObject *object) {
     UiSkinnedTextbox *textbox;
+    UiSkinnedTextboxPrivate *priv;
 
     g_return_if_fail (object != NULL);
     g_return_if_fail (UI_SKINNED_IS_TEXTBOX (object));
 
     textbox = UI_SKINNED_TEXTBOX (object);
+    priv = UI_SKINNED_TEXTBOX_GET_PRIVATE(object);
+
+    if (priv->scroll_timeout) {
+        g_source_remove(priv->scroll_timeout);
+        priv->scroll_timeout = 0;
+    }
 
     if (GTK_OBJECT_CLASS (parent_class)->destroy)
         (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
@@ -203,28 +219,64 @@
     g_return_if_fail (widget != NULL);
     g_return_if_fail (UI_SKINNED_IS_TEXTBOX(widget));
 
-    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
+    if (GTK_WIDGET_CLASS (parent_class)->realize)
+        (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
+
     textbox = UI_SKINNED_TEXTBOX(widget);
 
     attributes.x = widget->allocation.x;
     attributes.y = widget->allocation.y;
     attributes.width = widget->allocation.width;
     attributes.height = widget->allocation.height;
-    attributes.wclass = GDK_INPUT_OUTPUT;
+    attributes.wclass = GDK_INPUT_ONLY;
     attributes.window_type = GDK_WINDOW_CHILD;
     attributes.event_mask = gtk_widget_get_events(widget);
-    attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | 
+    attributes.event_mask |= GDK_BUTTON_PRESS_MASK |
                              GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
                              GDK_POINTER_MOTION_HINT_MASK;
-    attributes.visual = gtk_widget_get_visual(widget);
-    attributes.colormap = gtk_widget_get_colormap(widget);
 
-    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-    widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask);
+    attributes_mask = GDK_WA_X | GDK_WA_Y;
+    textbox->event_window = gdk_window_new (widget->window, &attributes, attributes_mask);
 
     widget->style = gtk_style_attach(widget->style, widget->window);
 
-    gdk_window_set_user_data(widget->window, widget);
+    gdk_window_set_user_data(textbox->event_window, widget);
+}
+
+static void ui_skinned_textbox_unrealize(GtkWidget *widget) {
+    UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX(widget);
+
+    if ( textbox->event_window != NULL )
+    {
+      gdk_window_set_user_data( textbox->event_window , NULL );
+      gdk_window_destroy( textbox->event_window );
+      textbox->event_window = NULL;
+    }
+
+    if (GTK_WIDGET_CLASS (parent_class)->unrealize)
+        (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+}
+
+static void ui_skinned_textbox_map (GtkWidget *widget)
+{
+    UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget);
+
+    if (textbox->event_window != NULL)
+      gdk_window_show (textbox->event_window);
+
+    if (GTK_WIDGET_CLASS (parent_class)->map)
+      (* GTK_WIDGET_CLASS (parent_class)->map) (widget);
+}
+
+static void ui_skinned_textbox_unmap (GtkWidget *widget)
+{
+    UiSkinnedTextbox *textbox = UI_SKINNED_TEXTBOX (widget);
+
+    if (textbox->event_window != NULL)
+      gdk_window_hide (textbox->event_window);
+
+    if (GTK_WIDGET_CLASS (parent_class)->unmap)
+      (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget);
 }
 
 static void ui_skinned_textbox_size_request(GtkWidget *widget, GtkRequisition *requisition) {
@@ -243,7 +295,8 @@
     widget->allocation.x *= (priv->scaled ? config.scale_factor : 1);
     widget->allocation.y *= (priv->scaled ? config.scale_factor : 1);
     if (GTK_WIDGET_REALIZED (widget))
-        gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
+        if (textbox->event_window)
+            gdk_window_move_resize(textbox->event_window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
 
     if (textbox->x + priv->move_x - widget->allocation.x/(priv->scaled ? config.scale_factor : 1) <3);
         priv->move_x = 0;
@@ -310,7 +363,10 @@
             }
         }
 
-        ui_skinned_widget_draw(widget, obj, textbox->width, textbox->height, priv->scaled);
+        ui_skinned_widget_draw_with_coordinates(widget, obj, textbox->width, textbox->height,
+                                                widget->allocation.x,
+                                                widget->allocation.y,
+                                                priv->scaled);
 
         g_object_unref(obj);
     }
--- a/src/skins/ui_skinned_textbox.h	Thu Aug 07 14:00:20 2008 +0300
+++ b/src/skins/ui_skinned_textbox.h	Thu Aug 07 14:00:40 2008 +0300
@@ -44,6 +44,7 @@
 struct _UiSkinnedTextbox {
     GtkWidget        widget;
 
+    GdkWindow        *event_window;
     gint             x, y, width, height;
     gchar            *text;
 };