Mercurial > audlegacy-plugins
changeset 2736:4d9540bcd7e2
Automated merge with ssh://hg.atheme-project.org//hg//audacious-plugins
author | Calin Crisan ccrisan@gmail.com |
---|---|
date | Tue, 01 Jul 2008 02:06:01 +0300 |
parents | 6d6a3eb67510 (current diff) 8a102490a8c0 (diff) |
children | b7beb9fea309 4ec0e13208de |
files | |
diffstat | 8 files changed, 284 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/src/bluetooth/Makefile Tue Jul 01 02:05:25 2008 +0300 +++ b/src/bluetooth/Makefile Tue Jul 01 02:06:01 2008 +0300 @@ -1,6 +1,6 @@ PLUGIN = bluetooth${PLUGIN_SUFFIX} -SRCS = bluetooth.c gui.c marshal.c +SRCS = bluetooth.c gui.c marshal.c scan_gui.c include ../../buildsys.mk include ../../extra.mk
--- a/src/bluetooth/bluetooth.c Tue Jul 01 02:05:25 2008 +0300 +++ b/src/bluetooth/bluetooth.c Tue Jul 01 02:06:01 2008 +0300 @@ -5,12 +5,14 @@ #include "bluetooth.h" #include "marshal.h" #include "gui.h" - +#include "scan_gui.h" #define DEBUG 1 static gboolean plugin_active = FALSE,exiting=FALSE; GList * current_device = NULL; DBusGConnection * bus = NULL; -gint discover_finish =0; +DBusGProxy * obj = NULL; +gint config = 0; +gint devices_no = 0; GStaticMutex mutex = G_STATIC_MUTEX_INIT; void bluetooth_init ( void ); @@ -23,7 +25,7 @@ static void print_results(void); static void discovery_completed(DBusGProxy *object, gpointer user_data); void discover_devices(void); - +void disconnect_dbus_signals(void); GeneralPlugin bluetooth_gp = @@ -36,6 +38,7 @@ }; GeneralPlugin *bluetooth_gplist[] = { &bluetooth_gp, NULL }; DECLARE_PLUGIN(bluetooth_gp, NULL, NULL, NULL, NULL, NULL, bluetooth_gplist, NULL, NULL) + void bluetooth_init ( void ) { audio_devices = NULL; @@ -45,33 +48,65 @@ void bluetooth_cleanup ( void ) { printf("bluetooth: exit\n"); + if (config ==1 ){ + destroy_scan_window(); + config =0; + } if(discover_finish == 2) { dbus_g_connection_flush (bus); dbus_g_connection_unref(bus); + disconnect_dbus_signals(); + } - } -/*void bt_cfg( void ) - { - } - */ void bt_about( void ) { + printf("about call\n"); + show_scan(); +} + +void bt_cfg(void) +{ + printf("bt_cfg\n"); + config =1; + if(discover_finish == 2){ + if (devices_no == 0){ + printf("no devs!\n"); + show_scan(); + show_no_devices(); + }else + results_ui(); + } + else show_scan(); + printf("end of bt_cfg\n"); +} + +void disconnect_dbus_signals() +{ + dbus_g_proxy_disconnect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus); + dbus_g_proxy_disconnect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus); + dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus); + dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL); } -void refresh_call(void){ - if(discover_finish == 0 ||discover_finish== 2) - discover_devices(); - else - printf("Scanning please wait!\n"); +void refresh_call(void) +{ printf("refresh function called\n"); + disconnect_dbus_signals(); + if(discover_finish == 0 ||discover_finish== 2){ + discover_finish = 0; + discover_devices(); + } + else + printf("Scanning please wait!\n"); } -void connect_call(void){ - printf("connect function \n"); +void connect_call(void) +{ + printf("connect function \n"); } @@ -82,7 +117,6 @@ current_device = audio_devices; if((class & 0x200404)==0x200404) { - while(current_device != NULL) { if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) @@ -98,8 +132,7 @@ dev->class = class; dev->address = g_strdup(address); dev->name = NULL; - audio_devices=g_list_prepend(audio_devices, dev); - + audio_devices=g_list_prepend(audio_devices, dev); } } g_static_mutex_unlock(&mutex); @@ -126,49 +159,60 @@ } g_static_mutex_unlock(&mutex); } + static void print_results() { int i=0; g_print("Final Scan results:\n"); - g_print("Number of audio devices: %d \n",g_list_length(audio_devices)); - current_device=audio_devices; - while(current_device != NULL) - { - g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i, - ((DeviceData*)(current_device->data))-> name, - ((DeviceData*)(current_device->data))-> class, - ((DeviceData*)(current_device->data))-> address); + devices_no = g_list_length(audio_devices); + g_print("Number of audio devices: %d \n",devices_no); + if(devices_no==0 ) { + if(config ==1) show_no_devices(); + } else { + current_device=audio_devices; + while(current_device != NULL) + { + g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i, + ((DeviceData*)(current_device->data))-> name, + ((DeviceData*)(current_device->data))-> class, + ((DeviceData*)(current_device->data))-> address); + current_device=g_list_next(current_device); + } + destroy_scan_window(); + if(config==1) { + destroy_scan_window(); + results_ui(); + } + // refresh_tree(); + } +} - current_device=g_list_next(current_device); - } - refresh_tree(); -} static void discovery_completed(DBusGProxy *object, gpointer user_data) { g_print("Signal: DiscoveryCompleted()\n"); + discover_finish =2; print_results(); - discover_finish =2; } -void discover_devices(void){ + +void discover_devices(void) +{ GError *error = NULL; - DBusGProxy * obj = NULL; - g_type_init(); + // g_type_init(); g_log_set_always_fatal (G_LOG_LEVEL_WARNING); - bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (error != NULL) { g_printerr("Connecting to system bus failed: %s\n", error->message); g_error_free(error); - exit(EXIT_FAILURE); } obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"); + printf("bluetooth plugin - start discovery \n"); + 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_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, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); dbus_g_proxy_connect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus, NULL); @@ -179,6 +223,7 @@ dbus_g_proxy_connect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus, NULL); dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL, NULL); @@ -187,8 +232,6 @@ { g_printerr("Failed to discover devices: %s\n", error->message); g_error_free(error); - exit(EXIT_FAILURE); } - dbus_g_connection_flush (bus); - dbus_g_connection_unref(bus); -} + +}
--- a/src/bluetooth/bluetooth.h Tue Jul 01 02:05:25 2008 +0300 +++ b/src/bluetooth/bluetooth.h Tue Jul 01 02:06:01 2008 +0300 @@ -19,4 +19,6 @@ void refresh_call(void); void connect_call(void); GList * audio_devices; +gint discover_finish ; +
--- a/src/bluetooth/gui.c Tue Jul 01 02:05:25 2008 +0300 +++ b/src/bluetooth/gui.c Tue Jul 01 02:06:01 2008 +0300 @@ -3,101 +3,110 @@ static GtkWidget *window = NULL; static GtkTreeModel *model; -GtkWidget *mainbox; -GtkWidget *hbox_top; -GtkWidget *hbox_bottom; -GtkWidget *box_about; -GtkWidget *box_about_left; -GtkWidget *box_about_right; -GtkWidget *headset_frame; -GtkWidget *about_frame; -GtkWidget *refresh; -GtkWidget *connect_button; -GtkWidget *close_button; -GtkWidget *treeview; -GtkWidget *label_p; -GtkWidget *label_c; -GtkWidget *label_a; -GtkWidget *label_prod; -GtkWidget *label_class; -GtkWidget *label_address; -GList * dev = NULL; +static GtkWidget *mainbox; +static GtkWidget *hbox_top; +static GtkWidget *hbox_bottom; +static GtkWidget *box_about; +static GtkWidget *box_about_left; +static GtkWidget *box_about_right; +static GtkWidget *headset_frame; +static GtkWidget *about_frame; +static GtkWidget *refresh; +static GtkWidget *connect_button; +static GtkWidget *close_button; +static GtkWidget *treeview; +static GtkWidget *label_p; +static GtkWidget *label_c; +static GtkWidget *label_a; +static GtkWidget *label_prod; +static GtkWidget *label_class; +static GtkWidget *label_address; +static GList * dev = NULL; +gchar *status = NULL; enum{ COLUMN_PRODUCER, NUM_COLUMNS }; -static DeviceData test_data[]= -{ - {0,"00:00:00:00:00","Scanning"} -}; - static GtkTreeModel * create_model(void) { GtkListStore *store; GtkTreeIter iter; - gint i=0; - /* create list store */ + /* create list store */ store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_STRING); - - /* add data to the list store */ - for(i = 0;i<G_N_ELEMENTS(test_data);i++) + dev = audio_devices; + if(dev == NULL) { + /*if we are scanning for devices now then print the Scanning message, + * else we print the "no devices found message */ + if(discover_finish == 1) + /*we are scanning*/ + status = g_strdup_printf("Scanning"); + else + status = g_strdup_printf("No devices found!"); + /* add the status to the list */ + gtk_list_store_append(store,&iter); + gtk_list_store_set(store,&iter, COLUMN_PRODUCER,status,-1); + return GTK_TREE_MODEL(store); + } + while(dev != NULL) { gtk_list_store_append(store,&iter); - gtk_list_store_set(store,&iter, - COLUMN_PRODUCER, test_data[i].name,-1); + gtk_list_store_set(store,&iter, COLUMN_PRODUCER, + ((DeviceData*)(dev->data))-> name,-1); + dev = g_list_next(dev); } - return GTK_TREE_MODEL(store); + return GTK_TREE_MODEL(store); } static GtkTreeModel * rebuild_model(void) { GtkListStore *store; GtkTreeIter iter; - gint i=0; gint dev_no=0; GList *dev; gchar *temp; if(!window) return NULL; - /* create list store */ + /* create list store */ store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_STRING); - + /*add inf to test_data from audio_devices */ dev_no = g_list_length(audio_devices); dev = audio_devices; + if(dev == NULL || discover_finish == 0) { + /*if we are scanning for devices now then print the Scanning message, + * else we print the "no devices found message */ + printf("discover: %d\n",discover_finish); + if(discover_finish == 1) { + /*we are scanning*/ + status = g_strdup_printf("Scanning"); + } else + status = g_strdup_printf("No devices found!"); + /* add the status to the list */ + gtk_list_store_append(store,&iter); + gtk_list_store_set(store,&iter, COLUMN_PRODUCER,status,-1); + gtk_label_set_text(GTK_LABEL(label_prod),status); + return GTK_TREE_MODEL(store); + } + + /* add data to the list store */ while(dev != NULL) { - test_data[i].name = ((DeviceData*)(dev->data))-> name; - test_data[i].class = ((DeviceData*)(dev->data))-> class; - test_data[i].address = ((DeviceData*)(dev->data))-> address; - i++; - dev=g_list_next(dev); - } - if (dev_no == 0) - { - test_data[0].name = "No devices found!"; - test_data[0].class = 0; - test_data[0].address = "00:00:00:00:00"; + gtk_list_store_append(store,&iter); + gtk_list_store_set(store,&iter, COLUMN_PRODUCER, + ((DeviceData*)(dev->data))-> name,-1); + dev = g_list_next(dev); } - - /* add data to the list store */ - for(i = 0;i<G_N_ELEMENTS(test_data);i++) - { - gtk_list_store_append(store,&iter); - gtk_list_store_set(store,&iter, - COLUMN_PRODUCER, test_data[i].name,-1); - } - //set the labels - temp = g_strdup_printf("0x%x",test_data[0].class); - gtk_label_set_text(GTK_LABEL(label_prod),test_data[0].name); - gtk_label_set_text(GTK_LABEL(label_class),temp); - gtk_label_set_text(GTK_LABEL(label_address),test_data[0].address); - - return GTK_TREE_MODEL(store); + //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_address),((DeviceData*)(dev->data))->address); + g_free(temp); + return GTK_TREE_MODEL(store); } @@ -106,8 +115,8 @@ { if(!window) return; - model = rebuild_model(); - gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),GTK_TREE_MODEL(model)); + model = rebuild_model(); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),GTK_TREE_MODEL(model)); } @@ -139,6 +148,7 @@ GtkTreeIter iter; gint sel; gchar *temp; + gint i; printf("select\n"); GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(treeview)); if(gtk_tree_selection_get_selected (selection, NULL,&iter)){ @@ -146,21 +156,26 @@ path = gtk_tree_model_get_path (model, &iter); sel = gtk_tree_path_get_indices (path)[0]; printf("i=%d\n",sel); - temp = g_strdup_printf("0x%x",test_data[sel].class); - gtk_label_set_text(GTK_LABEL(label_prod),test_data[sel].name); - gtk_label_set_text(GTK_LABEL(label_class),temp); - gtk_label_set_text(GTK_LABEL(label_address),test_data[sel].address); - gtk_tree_path_free (path); - g_free(temp); + dev = audio_devices; + for(i=0;i<sel;i++) + 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); + gtk_label_set_text(GTK_LABEL(label_class),temp); + gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address); + gtk_tree_path_free (path); + g_free(temp); + }else + gtk_label_set_text(GTK_LABEL(label_prod),status); + g_free(status); } - - +} -} -void bt_cfg() +void results_ui() { - + gchar *temp; if (!window) { window = gtk_window_new (GTK_WINDOW_TOPLEVEL); @@ -206,7 +221,7 @@ gtk_container_add (GTK_CONTAINER (headset_frame), treeview); /* add columns to the tree view */ add_columns (GTK_TREE_VIEW (treeview)); - + g_signal_connect(treeview,"cursor-changed",G_CALLBACK(select_row),treeview); @@ -238,7 +253,7 @@ /*right labels */ - label_prod = gtk_label_new("Scanning"); + label_prod = gtk_label_new(" "); gtk_container_add(GTK_CONTAINER(box_about_right),label_prod); label_class = gtk_label_new(" "); @@ -248,7 +263,16 @@ label_address = gtk_label_new(" "); gtk_container_add(GTK_CONTAINER(box_about_right),label_address); - gtk_window_set_default_size (GTK_WINDOW (window), 480, 180); + dev = audio_devices; + 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); + gtk_label_set_text(GTK_LABEL(label_class),temp); + gtk_label_set_text(GTK_LABEL(label_address),((DeviceData*)(dev->data))->address); + g_free(temp); + } + + gtk_window_set_default_size (GTK_WINDOW (window), 460, 150); if (!GTK_WIDGET_VISIBLE (window)) gtk_widget_show_all (window); else
--- a/src/bluetooth/gui.h Tue Jul 01 02:05:25 2008 +0300 +++ b/src/bluetooth/gui.h Tue Jul 01 02:06:01 2008 +0300 @@ -1,3 +1,6 @@ #include <gtk/gtk.h> #include <glib.h> void refresh_tree(void); +void results_ui(); + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bluetooth/scan_gui.c Tue Jul 01 02:06:01 2008 +0300 @@ -0,0 +1,84 @@ +#include "scan_gui.h" +#include "bluetooth.h" +static GtkWidget *window = NULL; +static GtkWidget *winbox; +static GtkWidget *scanbox; +static GtkWidget *progressbox; +static GtkWidget *bluetooth_img; +static GtkWidget *scan_label; +static GtkWidget *progress_bar; + +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); + } + return 0; + } + } + return 0; +} + +void show_no_devices(){ + if(window ){ + gtk_label_set_text(GTK_LABEL(scan_label),"No devices found!"); + } +} +void destroy_scan_window(){ + gtk_widget_hide(window); +} + +void show_scan() +{ + GThread *th1; + gchar *filename; + if (!window) + { + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (window, "destroy",G_CALLBACK (gtk_widget_destroyed), &window); + + winbox = gtk_vbox_new(FALSE,2); + gtk_container_set_border_width (GTK_CONTAINER (winbox), 2); + gtk_container_add (GTK_CONTAINER (window), winbox); + + scanbox = gtk_hbox_new(FALSE,2); + gtk_container_set_border_width(GTK_CONTAINER(scanbox),2); + gtk_container_add(GTK_CONTAINER(winbox),scanbox); + + progressbox = gtk_vbox_new(FALSE,2); + gtk_container_set_border_width(GTK_CONTAINER(progressbox),4); + gtk_container_add(GTK_CONTAINER(winbox),progressbox); + filename = DATA_DIR G_DIR_SEPARATOR_S "images" G_DIR_SEPARATOR_S "blue.png"; + 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); + + 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 + */ + gtk_window_set_default_size (GTK_WINDOW (window), 50, 40); + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show_all (window); + else + { + gtk_widget_destroy (window); + g_free(filename); + window = NULL; + } + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bluetooth/scan_gui.h Tue Jul 01 02:06:01 2008 +0300 @@ -0,0 +1,5 @@ +#include <gtk/gtk.h> +#include <glib.h> +void show_scan(); +void show_no_devices(); +void destroy_scan_window();
--- a/src/madplug/plugin.c Tue Jul 01 02:05:25 2008 +0300 +++ b/src/madplug/plugin.c Tue Jul 01 02:06:01 2008 +0300 @@ -277,7 +277,9 @@ ((guint32) hbuf[3]); } -#if 0 +#undef MADPROBE_DEBUG + +#ifdef MADPROBE_DEBUG static gchar *mp3_ver_table[4] = { "2.5", "INVALID", "2", "1" }; #define LULZ(...) do { fprintf(stderr, "madprobe: "); fprintf(stderr, __VA_ARGS__); } while (0) #define LOL(...) do { fprintf(stderr, __VA_ARGS__); } while (0) @@ -396,7 +398,7 @@ /* Not similar frame... */ LOL(" .. but does not match (%d)!\n", chkcount); state = STATE_RESYNC; - } else if (chkcount >= 5) { + } else if (chkcount >= 3) { /* Okay, accept this stream */ LOL(" .. accepted as mp3!!!\n"); return 1;