Mercurial > audlegacy-plugins
annotate src/bluetooth/scan_gui.c @ 2853:fed560b80720
added Retry button for the pairing interface
author | Paula Stanciu <paula.stanciu@gmail.com> |
---|---|
date | Tue, 29 Jul 2008 18:49:04 +0300 |
parents | 671cdfc2d62d |
children | 43557eb3180f |
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 |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
34 gpointer progress() |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
35 { |
2728 | 36 |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
37 for(;;){ |
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
38 if(window){ |
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
39 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
|
40 } |
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
41 sleep(1); |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
42 if(usage == 0){ |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
43 if(discover_finish == 2 ) { |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
44 if(window){ |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
45 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
46 } |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
47 return 0; |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
48 } |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
49 }else |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
50 { |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
51 if(bonding_finish == 1 ) { |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
52 if(window){ |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
53 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),1); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
54 show_pairing_ok(); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
55 } |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
56 return 0; |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
57 } |
2728 | 58 } |
59 } | |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
60 return 0; |
2728 | 61 } |
62 | |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
63 void show_pairing_ok() |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
64 { |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
65 if(window ){ |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
66 gtk_label_set_text(GTK_LABEL(scan_label),_("Bonding finish!")); |
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 } |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
69 |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
70 void show_no_devices() |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
71 { |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
72 if(window ){ |
2764
d45b4beadf6c
Made "bluetooth" and "streambrowser" plugins translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
2756
diff
changeset
|
73 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
|
74 } |
2728 | 75 } |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
76 void destroy_scan_window() |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
77 { |
2728 | 78 gtk_widget_hide(window); |
79 } | |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
80 void close_window(void) |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
81 { |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
82 printf("scan_gui close callback \n"); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
83 gtk_widget_destroy (window); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
84 window = NULL; |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
85 } |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
86 void retry_call(void) |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
87 { |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
88 printf("retry callback\n"); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
89 } |
2728 | 90 |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
91 void show_scan(gint use) |
2728 | 92 { |
93 GThread *th1; | |
94 gchar *filename; | |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
95 usage = use; |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
96 /* |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
97 * 0 - discovery |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
98 * 1 - pairing |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
99 */ |
2728 | 100 if (!window) |
101 { | |
102 window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | |
103 g_signal_connect (window, "destroy",G_CALLBACK (gtk_widget_destroyed), &window); | |
104 | |
105 winbox = gtk_vbox_new(FALSE,2); | |
106 gtk_container_set_border_width (GTK_CONTAINER (winbox), 2); | |
107 gtk_container_add (GTK_CONTAINER (window), winbox); | |
108 | |
109 scanbox = gtk_hbox_new(FALSE,2); | |
110 gtk_container_set_border_width(GTK_CONTAINER(scanbox),2); | |
111 gtk_container_add(GTK_CONTAINER(winbox),scanbox); | |
112 | |
113 progressbox = gtk_vbox_new(FALSE,2); | |
114 gtk_container_set_border_width(GTK_CONTAINER(progressbox),4); | |
115 gtk_container_add(GTK_CONTAINER(winbox),progressbox); | |
116 filename = DATA_DIR G_DIR_SEPARATOR_S "images" G_DIR_SEPARATOR_S "blue.png"; | |
117 bluetooth_img = gtk_image_new_from_file(filename); | |
118 gtk_image_set_pixel_size(GTK_IMAGE(bluetooth_img),-1); | |
119 gtk_container_add(GTK_CONTAINER(scanbox),bluetooth_img); | |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
120 if(usage == 0){ |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
121 scan_label = gtk_label_new_with_mnemonic(_("Scanning...")); |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
122 }else |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
123 { |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
124 scan_label = gtk_label_new_with_mnemonic(_("Pairing...")); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
125 } |
2728 | 126 |
127 gtk_container_add(GTK_CONTAINER(scanbox),scan_label); | |
128 | |
129 progress_bar = gtk_progress_bar_new(); | |
130 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); | |
131 gtk_container_add(GTK_CONTAINER(progressbox),progress_bar); | |
132 th1 = g_thread_create((GThreadFunc)progress, NULL,TRUE,NULL); | |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
133 buttonsbox = gtk_hbox_new(FALSE,2); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
134 gtk_container_set_border_width(GTK_CONTAINER(buttonsbox),2); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
135 gtk_container_add(GTK_CONTAINER(progressbox),buttonsbox); |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
136 /* 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
|
137 * and treat the case when the bounding is not ok |
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2839
diff
changeset
|
138 */ |
2853
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
139 if(usage == 0){ |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
140 rescan_buttton = gtk_button_new_with_mnemonic(_("Rescan")); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
141 g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (refresh_call),NULL); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
142 }else{ |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
143 rescan_buttton = gtk_button_new_with_mnemonic(_("Retry")); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
144 g_signal_connect(rescan_buttton,"clicked",G_CALLBACK (retry_call),NULL); |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
145 } |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
146 |
fed560b80720
added Retry button for the pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2847
diff
changeset
|
147 |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
148 |
2764
d45b4beadf6c
Made "bluetooth" and "streambrowser" plugins translatable.
Stany HENRY <StrassBoy@gmail.com>
parents:
2756
diff
changeset
|
149 close_button = gtk_button_new_with_mnemonic(_("Close")); |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
150 gtk_container_add(GTK_CONTAINER(buttonsbox),rescan_buttton); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
151 gtk_container_add(GTK_CONTAINER(buttonsbox),close_button); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
152 g_signal_connect(close_button,"clicked",G_CALLBACK (close_window),NULL); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
153 |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
154 gtk_window_set_default_size (GTK_WINDOW (window), 60, 40); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2732
diff
changeset
|
155 gtk_window_set_resizable(GTK_WINDOW(window),FALSE); |
2728 | 156 if (!GTK_WIDGET_VISIBLE (window)) |
157 gtk_widget_show_all (window); | |
158 else | |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
159 { |
2728 | 160 gtk_widget_destroy (window); |
161 g_free(filename); | |
162 window = NULL; | |
163 } | |
164 | |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
165 } |
2728 | 166 |
167 } |