Mercurial > audlegacy-plugins
annotate src/bluetooth/scan_gui.c @ 2847:671cdfc2d62d
Basic pairing interface
| author | Paula Stanciu <paula.stanciu@gmail.com> |
|---|---|
| date | Mon, 28 Jul 2008 21:48:39 +0300 |
| parents | 22a5075fc7f7 |
| children | fed560b80720 |
| rev | line source |
|---|---|
| 2839 | 1 /* |
| 2 * Audacious Bluetooth headset suport plugin | |
| 3 * | |
| 4 * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; under version 3 of the License. | |
| 9 * | |
| 10 * This program is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 * GNU General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU General Public License | |
| 16 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
| 17 */ | |
| 18 | |
| 2728 | 19 #include "scan_gui.h" |
| 20 #include "bluetooth.h" | |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
21 #include "agent.h" |
| 2728 | 22 static GtkWidget *window = NULL; |
| 23 static GtkWidget *winbox; | |
| 24 static GtkWidget *scanbox; | |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
25 static GtkWidget *buttonsbox; |
| 2728 | 26 static GtkWidget *progressbox; |
| 27 static GtkWidget *bluetooth_img; | |
| 28 static GtkWidget *scan_label; | |
| 29 static GtkWidget *progress_bar; | |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
30 static GtkWidget *rescan_buttton; |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
31 static GtkWidget *close_button; |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
32 static gint usage=0; |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
33 |
| 2728 | 34 gpointer progress() { |
| 35 | |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
36 for(;;){ |
|
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
37 if(window){ |
|
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
38 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); |
|
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
39 } |
|
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
40 sleep(1); |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
41 if(usage == 0){ |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
42 if(discover_finish == 2 ) { |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
43 if(window){ |
|
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
44 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); |
|
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
45 } |
| 2728 | 46 return 0; |
| 47 } | |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
48 }else |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
49 { |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
50 if(bonding_finish == 1 ) { |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
51 if(window){ |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
52 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
53 show_pairing_ok(); |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
54 } |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
55 return 0; |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
56 } |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
57 } |
| 2728 | 58 } |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
59 return 0; |
| 2728 | 60 } |
| 61 | |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
62 void show_pairing_ok() |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
63 { |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
64 if(window ){ |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
65 gtk_label_set_text(GTK_LABEL(scan_label),_("Bonding finish!")); |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
66 } |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
67 } |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
68 |
| 2728 | 69 void show_no_devices(){ |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
70 if(window ){ |
|
2764
d45b4beadf6c
Made "bluetooth" and "streambrowser" plugins translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
2756
diff
changeset
|
71 gtk_label_set_text(GTK_LABEL(scan_label),_("No devices found!")); |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
72 } |
| 2728 | 73 } |
| 74 void destroy_scan_window(){ | |
| 75 gtk_widget_hide(window); | |
| 76 } | |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
77 void close_window(void){ |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
78 printf("scan_gui close callback \n"); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
79 gtk_widget_destroy (window); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
80 window = NULL; |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
81 } |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
82 |
| 2728 | 83 |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
84 void show_scan(gint use) |
| 2728 | 85 { |
| 86 GThread *th1; | |
| 87 gchar *filename; | |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
88 usage = use; |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
89 /* |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
90 * 0 - discovery |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
91 * 1 - pairing |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
92 */ |
| 2728 | 93 if (!window) |
| 94 { | |
| 95 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
| 96 g_signal_connect (window, "destroy",G_CALLBACK (gtk_widget_destroyed), &window); | |
| 97 | |
| 98 winbox = gtk_vbox_new(FALSE,2); | |
| 99 gtk_container_set_border_width (GTK_CONTAINER (winbox), 2); | |
| 100 gtk_container_add (GTK_CONTAINER (window), winbox); | |
| 101 | |
| 102 scanbox = gtk_hbox_new(FALSE,2); | |
| 103 gtk_container_set_border_width(GTK_CONTAINER(scanbox),2); | |
| 104 gtk_container_add(GTK_CONTAINER(winbox),scanbox); | |
| 105 | |
| 106 progressbox = gtk_vbox_new(FALSE,2); | |
| 107 gtk_container_set_border_width(GTK_CONTAINER(progressbox),4); | |
| 108 gtk_container_add(GTK_CONTAINER(winbox),progressbox); | |
| 109 filename = DATA_DIR G_DIR_SEPARATOR_S "images" G_DIR_SEPARATOR_S "blue.png"; | |
| 110 bluetooth_img = gtk_image_new_from_file(filename); | |
| 111 gtk_image_set_pixel_size(GTK_IMAGE(bluetooth_img),-1); | |
| 112 gtk_container_add(GTK_CONTAINER(scanbox),bluetooth_img); | |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
113 if(usage == 0){ |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
114 scan_label = gtk_label_new_with_mnemonic(_("Scanning...")); |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
115 }else |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
116 { |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
117 scan_label = gtk_label_new_with_mnemonic(_("Pairing...")); |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
118 } |
| 2728 | 119 |
| 120 gtk_container_add(GTK_CONTAINER(scanbox),scan_label); | |
| 121 | |
| 122 progress_bar = gtk_progress_bar_new(); | |
| 123 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); | |
| 124 gtk_container_add(GTK_CONTAINER(progressbox),progress_bar); | |
| 125 th1 = g_thread_create((GThreadFunc)progress, NULL,TRUE,NULL); | |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
126 buttonsbox = gtk_hbox_new(FALSE,2); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
127 gtk_container_set_border_width(GTK_CONTAINER(buttonsbox),2); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
128 gtk_container_add(GTK_CONTAINER(progressbox),buttonsbox); |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
129 /* I have to modify the rescan button with a play one |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
130 * and treat the case when the bounding is not ok |
|
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
131 */ |
|
2764
d45b4beadf6c
Made "bluetooth" and "streambrowser" plugins translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
2756
diff
changeset
|
132 rescan_buttton = gtk_button_new_with_mnemonic(_("Rescan")); |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
133 g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (refresh_call),NULL); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
134 |
|
2764
d45b4beadf6c
Made "bluetooth" and "streambrowser" plugins translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
2756
diff
changeset
|
135 close_button = gtk_button_new_with_mnemonic(_("Close")); |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
136 gtk_container_add(GTK_CONTAINER(buttonsbox),rescan_buttton); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
137 gtk_container_add(GTK_CONTAINER(buttonsbox),close_button); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
138 g_signal_connect(close_button,"clicked",G_CALLBACK (close_window),NULL); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
139 |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
140 gtk_window_set_default_size (GTK_WINDOW (window), 60, 40); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
141 gtk_window_set_resizable(GTK_WINDOW(window),FALSE); |
| 2728 | 142 if (!GTK_WIDGET_VISIBLE (window)) |
| 143 gtk_widget_show_all (window); | |
| 144 else | |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
145 { |
| 2728 | 146 gtk_widget_destroy (window); |
| 147 g_free(filename); | |
| 148 window = NULL; | |
| 149 } | |
| 150 | |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
151 } |
| 2728 | 152 |
| 153 } |
