Mercurial > audlegacy-plugins
changeset 2849:3ba1579e37a5
Automated merge with ssh://hg.atheme-project.org//hg//audacious-plugins
author | Calin Crisan ccrisan@gmail.com |
---|---|
date | Mon, 28 Jul 2008 23:44:00 +0300 |
parents | 671cdfc2d62d (diff) fbb32674bfd2 (current diff) |
children | 587b3657990d |
files | |
diffstat | 6 files changed, 374 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bluetooth/agent.c Mon Jul 28 23:43:31 2008 +0300 +++ b/src/bluetooth/agent.c Mon Jul 28 23:44:00 2008 +0300 @@ -24,6 +24,7 @@ #include <glib/gprintf.h> #include "bluetooth.h" +#include "agent.h" #include "gui.h" #define PASSKEY_AGENT_PATH "/org/bluez/audacious_passkey" @@ -40,8 +41,17 @@ static GtkWidget *ok_button = NULL; static GtkWidget *cancel_button = NULL; static 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)); @@ -282,6 +292,8 @@ */ printf("passkey callback\n"); passkey_callback(GTK_RESPONSE_ACCEPT,input); + + } static void confirm_dialog(const char *path, const char *address, @@ -299,7 +311,7 @@ input->context = context; - +printf("confirm dialog\n"); // g_signal_connect(G_OBJECT(dialog), "response", // G_CALLBACK(confirm_callback), input); @@ -310,13 +322,6 @@ const char *service, const char *uuid, const gchar *device, const gchar *profile, DBusGMethodInvocation *context) { - GtkWidget *dialog; - GtkWidget *button; - GtkWidget *image; - GtkWidget *label; - GtkWidget *table; - GtkWidget *vbox; - gchar *markup, *text; struct input_data *input; input = g_try_malloc0(sizeof(*input)); @@ -418,7 +423,6 @@ device = g_strdup(address); passkey_dialog(path, address, device, context); - printf ("pairing request for device :%s",address); /* translators: this is a popup telling you a particular device * has asked for pairing */ line = g_strdup_printf(_("Pairing request for '%s'"), device); @@ -758,11 +762,323 @@ { auto_authorize = value; } -void run_agents() + +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); + +// 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) { - setup_agents(bus); + 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(); + +} +
--- a/src/bluetooth/agent.h Mon Jul 28 23:43:31 2008 +0300 +++ b/src/bluetooth/agent.h Mon Jul 28 23:44:00 2008 +0300 @@ -25,6 +25,7 @@ #include <gtk/gtk.h> #include <glib.h> #include <dbus/dbus-glib.h> +gint bonding_finish; void run_agents(void); int setup_agents(DBusGConnection *conn); void cleanup_agents(void);
--- a/src/bluetooth/bluetooth.c Mon Jul 28 23:43:31 2008 +0300 +++ b/src/bluetooth/bluetooth.c Mon Jul 28 23:44:00 2008 +0300 @@ -87,12 +87,12 @@ if(discover_finish == 2){ if (devices_no == 0){ printf("no devs!\n"); - show_scan(); + show_scan(0); show_no_devices(); }else results_ui(); } - else show_scan(); + else show_scan(0); printf("end of bt_cfg\n"); } @@ -123,43 +123,28 @@ discover_devices(); close_window(); - show_scan(); + show_scan(0); } else printf("Scanning please wait!\n"); } -void bounding_created(gchar* address) -{ - printf("Signal BoundingCreated : %s\n",address); - -} - -void bounding_removed(gchar* address) -{ - printf("Signal: BoundingRemoved: %s\n",address); - -} - - gpointer connect_call_th(void) { //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); - dbus_g_proxy_add_signal(obj, "BondingCreated", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(obj, "BondingCreated", G_CALLBACK(bounding_created), bus, NULL); - - dbus_g_proxy_add_signal(obj, "BondingRemoved", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(obj, "BondingRemoved", G_CALLBACK(bounding_removed), bus, NULL); run_agents(); dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,((DeviceData*)(selected_dev->data))->address,G_TYPE_INVALID,G_TYPE_INVALID); } void connect_call(void) { - connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; + connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; + close_call(); + close_window(); + show_scan(1); }
--- a/src/bluetooth/gui.h Mon Jul 28 23:43:31 2008 +0300 +++ b/src/bluetooth/gui.h Mon Jul 28 23:44:00 2008 +0300 @@ -22,5 +22,6 @@ GList *selected_dev ; void refresh_tree(void); void results_ui(); +void close_call(void);
--- a/src/bluetooth/scan_gui.c Mon Jul 28 23:43:31 2008 +0300 +++ b/src/bluetooth/scan_gui.c Mon Jul 28 23:44:00 2008 +0300 @@ -18,6 +18,7 @@ #include "scan_gui.h" #include "bluetooth.h" +#include "agent.h" static GtkWidget *window = NULL; static GtkWidget *winbox; static GtkWidget *scanbox; @@ -28,6 +29,8 @@ static GtkWidget *progress_bar; static GtkWidget *rescan_buttton; static GtkWidget *close_button; +static gint usage=0; + gpointer progress() { for(;;){ @@ -35,16 +38,34 @@ gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); } sleep(1); - if(discover_finish == 2 ) { + if(usage == 0){ + if(discover_finish == 2 ) { if(window){ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); } return 0; } + }else + { + if(bonding_finish == 1 ) { + if(window){ + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); + show_pairing_ok(); + } + return 0; + } + } } return 0; } +void show_pairing_ok() +{ + if(window ){ + gtk_label_set_text(GTK_LABEL(scan_label),_("Bonding finish!")); + } +} + void show_no_devices(){ if(window ){ gtk_label_set_text(GTK_LABEL(scan_label),_("No devices found!")); @@ -60,10 +81,15 @@ } -void show_scan() +void show_scan(gint use) { GThread *th1; gchar *filename; + usage = use; + /* + * 0 - discovery + * 1 - pairing + */ if (!window) { window = gtk_window_new (GTK_WINDOW_TOPLEVEL); @@ -84,20 +110,25 @@ bluetooth_img = gtk_image_new_from_file(filename); gtk_image_set_pixel_size(GTK_IMAGE(bluetooth_img),-1); gtk_container_add(GTK_CONTAINER(scanbox),bluetooth_img); + if(usage == 0){ + scan_label = gtk_label_new_with_mnemonic(_("Scanning...")); + }else + { + scan_label = gtk_label_new_with_mnemonic(_("Pairing...")); + } - scan_label = gtk_label_new_with_mnemonic(_("Scanning...")); gtk_container_add(GTK_CONTAINER(scanbox),scan_label); progress_bar = gtk_progress_bar_new(); gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); gtk_container_add(GTK_CONTAINER(progressbox),progress_bar); th1 = g_thread_create((GThreadFunc)progress, NULL,TRUE,NULL); - /* I have to add a button for Rescan when there are - * no devices found and not currently scanning - */ buttonsbox = gtk_hbox_new(FALSE,2); gtk_container_set_border_width(GTK_CONTAINER(buttonsbox),2); gtk_container_add(GTK_CONTAINER(progressbox),buttonsbox); + /* I have to modify the rescan button with a play one + * and treat the case when the bounding is not ok + */ rescan_buttton = gtk_button_new_with_mnemonic(_("Rescan")); g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (refresh_call),NULL);