Debian Codegraph @

src/av-cp/renderer-combo.c

raw
1 /*
2 * Copyright (C) 2007 Zeeshan Ali (Khattak) <[email protected]>
3 *
4 * Authors: Zeeshan Ali (Khattak) <[email protected]>
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; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21 #include <config.h>
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "renderer-combo.h"
27 #include "renderer-controls.h"
28 #include "icons.h"
29
30 #define CONNECTION_MANAGER "urn:schemas-upnp-org:service:ConnectionManager"
31 #define AV_TRANSPORT "urn:schemas-upnp-org:service:AVTransport"
32 #define RENDERING_CONTROL "urn:schemas-upnp-org:service:RenderingControl"
33
34 static GtkWidget *renderer_combo;
35 static GUPnPLastChangeParser *lc_parser;
36
37 static GUPnPServiceProxy *
38 get_av_transport (GUPnPDeviceProxy *renderer)
39 {
40 GUPnPDeviceInfo *info;
41 GUPnPServiceInfo *av_transport;
42
43 info = GUPNP_DEVICE_INFO (renderer);
44
45 av_transport = gupnp_device_info_get_service (info, AV_TRANSPORT);
46
47 return GUPNP_SERVICE_PROXY (av_transport);
48 }
49
50 GUPnPServiceProxy *
51 get_selected_av_transport (gchar **sink_protocol_info)
52 {
53 GUPnPServiceProxy *av_transport;
54 GtkComboBox *combo;
55 GtkTreeModel *model;
56 GtkTreeIter iter;
57
58 combo = GTK_COMBO_BOX (renderer_combo);
59 model = gtk_combo_box_get_model (combo);
60 g_assert (model != NULL);
61
62 if (!gtk_combo_box_get_active_iter (combo, &iter)) {
63 return NULL;
64 }
65
66 if (sink_protocol_info != NULL) {
67 gtk_tree_model_get (model,
68 &iter,
69 5, sink_protocol_info,
70 -1);
71
72 if (*sink_protocol_info == NULL) {
73 return NULL;
74 }
75 }
76
77 gtk_tree_model_get (model,
78 &iter,
79 3, &av_transport,
80 -1);
81
82 return av_transport;
83 }
84
85 GUPnPServiceProxy *
86 get_selected_rendering_control (void)
87 {
88 GUPnPServiceProxy *rendering_control;
89 GtkComboBox *combo;
90 GtkTreeModel *model;
91 GtkTreeIter iter;
92
93 combo = GTK_COMBO_BOX (renderer_combo);
94 model = gtk_combo_box_get_model (combo);
95 g_assert (model != NULL);
96
97 if (!gtk_combo_box_get_active_iter (combo, &iter)) {
98 return NULL;
99 }
100
101 gtk_tree_model_get (model,
102 &iter,
103 4, &rendering_control,
104 -1);
105
106 return rendering_control;
107 }
108
109 guint
110 get_selected_renderer_volume (void)
111 {
112 GtkComboBox *combo;
113 GtkTreeModel *model;
114 GtkTreeIter iter;
115 guint volume;
116
117 combo = GTK_COMBO_BOX (renderer_combo);
118 model = gtk_combo_box_get_model (combo);
119 g_assert (model != NULL);
120
121 if (!gtk_combo_box_get_active_iter (combo, &iter)) {
122 return 0;
123 }
124
125 gtk_tree_model_get (model,
126 &iter,
127 7, &volume,
128 -1);
129
130 return volume;
131 }
132
133 PlaybackState
134 get_selected_renderer_state (void)
135 {
136 PlaybackState state;
137 GtkComboBox *combo;
138 GtkTreeModel *model;
139 GtkTreeIter iter;
140
141 combo = GTK_COMBO_BOX (renderer_combo);
142 model = gtk_combo_box_get_model (combo);
143 g_assert (model != NULL);
144
145 if (!gtk_combo_box_get_active_iter (combo, &iter)) {
146 return PLAYBACK_STATE_UNKNOWN;
147 }
148
149 gtk_tree_model_get (model,
150 &iter,
151 6, &state,
152 -1);
153
154 return state;
155 }
156
157 static gboolean
158 find_renderer (GtkTreeModel *model,
159 const char *udn,
160 GtkTreeIter *iter)
161 {
162 gboolean found = FALSE;
163 gboolean more = TRUE;
164
165 g_assert (udn != NULL);
166 g_assert (iter != NULL);
167
168 more = gtk_tree_model_get_iter_first (model, iter);
169
170 while (more) {
171 GUPnPDeviceInfo *info;
172
173 gtk_tree_model_get (model,
174 iter,
175 2, &info,
176 -1);
177
178 if (info) {
179 const char *device_udn;
180
181 device_udn = gupnp_device_info_get_udn (info);
182
183 if (strcmp (device_udn, udn) == 0)
184 found = TRUE;
185
186 g_object_unref (info);
187 }
188
189 if (found)
190 break;
191
192 more = gtk_tree_model_iter_next (model, iter);
193 }
194
195 return found;
196 }
197
198 static PlaybackState
199 state_name_to_state (const char *state_name)
200 {
201 PlaybackState state;
202
203 if (strcmp ("STOPPED", state_name) == 0) {
204 state = PLAYBACK_STATE_STOPPED;
205 } else if (strcmp ("PLAYING", state_name) == 0) {
206 state = PLAYBACK_STATE_PLAYING;
207 } else if (strcmp ("PAUSED_PLAYBACK", state_name) == 0) {
208 state = PLAYBACK_STATE_PAUSED;
209 } else if (strcmp ("TRANSITIONING", state_name) == 0) {
210 state = PLAYBACK_STATE_TRANSITIONING;
211 } else {
212 state = PLAYBACK_STATE_UNKNOWN;
213 }
214
215 return state;
216 }
217
218 /* FIXME: is there a better implementation possible? */
219 static gboolean
220 is_iter_active (GtkComboBox *combo,
221 GtkTreeIter *iter)
222 {
223 GtkTreeModel *model;
224 GtkTreeIter active_iter;
225 GtkTreePath *active_path;
226 GtkTreePath *path;
227 gboolean ret;
228
229 model = gtk_combo_box_get_model (combo);
230 g_assert (model != NULL);
231
232 path = gtk_tree_model_get_path (model, iter);
233 g_assert (path != NULL);
234
235 if (!gtk_combo_box_get_active_iter (combo, &active_iter)) {
236 gtk_tree_path_free (path);
237
238 return FALSE;
239 }
240
241 active_path = gtk_tree_model_get_path (model, &active_iter);
242 g_assert (active_path != NULL);
243
244 ret = (gtk_tree_path_compare (path, active_path) == 0);
245
246 gtk_tree_path_free (path);
247 gtk_tree_path_free (active_path);
248
249 return ret;
250 }
251
252 static void
253 set_state (GtkTreeModel *model,
254 GtkTreeIter *iter,
255 PlaybackState state)
256 {
257 gtk_list_store_set (GTK_LIST_STORE (model),
258 iter,
259 6, state,
260 -1);
261
262 if (state == PLAYBACK_STATE_PLAYING ||
263 state == PLAYBACK_STATE_PAUSED ||
264 state == PLAYBACK_STATE_TRANSITIONING) {
265 gtk_widget_set_sensitive (renderer_combo, FALSE);
266 } else {
267 gtk_widget_set_sensitive (renderer_combo, TRUE);
268 }
269
270 if (is_iter_active (GTK_COMBO_BOX (renderer_combo), iter)) {
271 prepare_controls_for_state (state);
272 }
273 }
274
275 static void
276 set_state_by_name (const gchar *udn,
277 const gchar *state_name)
278 {
279 GtkTreeModel *model;
280 GtkTreeIter iter;
281
282 model = gtk_combo_box_get_model
283 (GTK_COMBO_BOX (renderer_combo));
284 g_assert (model != NULL);
285
286 if (find_renderer (model, udn, &iter)) {
287 PlaybackState state;
288
289 state = state_name_to_state (state_name),
290
291 set_state (model, &iter, state);
292 }
293 }
294
295 static void
296 set_volume (const gchar *udn,
297 guint volume)
298 {
299 GtkTreeModel *model;
300 GtkTreeIter iter;
301
302 model = gtk_combo_box_get_model
303 (GTK_COMBO_BOX (renderer_combo));
304 g_assert (model != NULL);
305
306 if (find_renderer (model, udn, &iter)) {
307 gtk_list_store_set (GTK_LIST_STORE (model),
308 &iter,
309 7, volume,
310 -1);
311
312 if (is_iter_active (GTK_COMBO_BOX (renderer_combo), &iter)) {
313 set_volume_scale (volume);
314 }
315 }
316 }
317
318 static void
319 set_duration (const gchar *udn,
320 const gchar *duration)
321 {
322 GtkTreeModel *model;
323 GtkTreeIter iter;
324
325 model = gtk_combo_box_get_model
326 (GTK_COMBO_BOX (renderer_combo));
327 g_assert (model != NULL);
328
329 if (find_renderer (model, udn, &iter)) {
330 gtk_list_store_set (GTK_LIST_STORE (model),
331 &iter,
332 8, duration,
333 -1);
334
335 if (is_iter_active (GTK_COMBO_BOX (renderer_combo), &iter)) {
336 set_position_scale_duration (duration);
337 }
338 }
339 }
340
341 static void
342 on_device_icon_available (GObject *source,
343 GAsyncResult *res,
344 gpointer user_data)
345 {
346 GtkTreeModel *model;
347 GtkTreeIter iter;
348 const char *udn;
349 g_autoptr (GdkPixbuf) icon;
350 g_autoptr (GError) error = NULL;
351
352 icon = update_icon_finish (GUPNP_DEVICE_INFO (source), res, &error);
353 if (error != NULL) {
354 g_debug ("Failed to download icon: %s", error->message);
355 }
356
357 if (icon == NULL)
358 return;
359
360 model = gtk_combo_box_get_model (GTK_COMBO_BOX (renderer_combo));
361 g_assert (model != NULL);
362
363 udn = gupnp_device_info_get_udn (GUPNP_DEVICE_INFO (source));
364
365 if (find_renderer (model, udn, &iter)) {
366 gtk_list_store_set (GTK_LIST_STORE (model),
367 &iter,
368 0, icon,
369 -1);
370 }
371
372 g_object_set_data (source, "icon-download-cancellable", NULL);
373 }
374
375 static void
376 on_last_change (GUPnPServiceProxy *av_transport,
377 const char *variable_name,
378 GValue *value,
379 gpointer user_data)
380 {
381 const char *last_change_xml;
382 char *state_name;
383 char *duration;
384 GError *error;
385
386 last_change_xml = g_value_get_string (value);
387 error = NULL;
388 state_name = NULL;
389 duration = NULL;
390
391 if (gupnp_last_change_parser_parse_last_change (lc_parser,
392 0,
393 last_change_xml,
394 &error,
395 "TransportState",
396 G_TYPE_STRING,
397 &state_name,
398 "CurrentMediaDuration",
399 G_TYPE_STRING,
400 &duration,
401 NULL)) {
402 const char *udn;
403
404 udn = gupnp_service_info_get_udn
405 (GUPNP_SERVICE_INFO (av_transport));
406 if (state_name != NULL) {
407 set_state_by_name (udn, state_name);
408 g_free (state_name);
409 }
410
411 if (duration != NULL) {
412 set_duration (udn, duration);
413 g_free (duration);
414 }
415 } else if (error) {
416 g_warning ("%s\n", error->message);
417
418 g_error_free (error);
419 }
420 }
421
422 static void
423 on_rendering_control_last_change (GUPnPServiceProxy *rendering_control,
424 const char *variable_name,
425 GValue *value,
426 gpointer user_data)
427 {
428 const char *last_change_xml;
429 guint volume;
430 GError *error;
431
432 last_change_xml = g_value_get_string (value);
433 error = NULL;
434
435 if (gupnp_last_change_parser_parse_last_change (lc_parser,
436 0,
437 last_change_xml,
438 &error,
439 "Volume",
440 G_TYPE_UINT,
441 &volume,
442 NULL)) {
443 const char *udn;
444
445 udn = gupnp_service_info_get_udn
446 (GUPNP_SERVICE_INFO
447 (rendering_control));
448 set_volume (udn, volume);
449 } else if (error) {
450 g_warning ("%s\n", error->message);
451
452 g_error_free (error);
453 }
454 }
455
456 void
457 clear_selected_renderer_state (void)
458 {
459 GtkComboBox *combo;
460 GtkTreeModel *model;
461 GtkTreeIter iter;
462
463 combo = GTK_COMBO_BOX (renderer_combo);
464 model = gtk_combo_box_get_model (combo);
465 g_assert (model != NULL);
466
467 if (gtk_combo_box_get_active_iter (combo, &iter)) {
468 set_state (model, &iter, PLAYBACK_STATE_UNKNOWN);
469 }
470 }
471
472 static void
473 append_media_renderer_to_tree (GUPnPDeviceProxy *proxy,
474 GUPnPServiceProxy *av_transport,
475 GUPnPServiceProxy *rendering_control,
476 const char *udn)
477 {
478 GUPnPDeviceInfo *info;
479 GtkComboBox *combo;
480 GtkTreeModel *model;
481 GtkTreeIter iter;
482 char *name;
483 gboolean was_empty;
484
485 info = GUPNP_DEVICE_INFO (proxy);
486 combo = GTK_COMBO_BOX (renderer_combo);
487
488 name = gupnp_device_info_get_friendly_name (info);
489 if (name == NULL)
490 name = g_strdup (udn);
491
492 model = gtk_combo_box_get_model (combo);
493
494 if (gtk_combo_box_get_active (combo) == -1)
495 was_empty = TRUE;
496 else
497 was_empty = FALSE;
498
499 memset (&iter, 0, sizeof (iter));
500 gtk_list_store_insert_with_values
501 (GTK_LIST_STORE (model),
502 &iter,
503 -1,
504 0, get_icon_by_id (ICON_MEDIA_RENDERER),
505 1, name,
506 2, proxy,
507 3, av_transport,
508 4, rendering_control,
509 6, PLAYBACK_STATE_UNKNOWN,
510 7, 0,
511 -1);
512
513 gupnp_service_proxy_add_notify (av_transport,
514 "LastChange",
515 G_TYPE_STRING,
516 on_last_change,
517 NULL);
518 gupnp_service_proxy_add_notify (rendering_control,
519 "LastChange",
520 G_TYPE_STRING,
521 on_rendering_control_last_change,
522 NULL);
523 gupnp_service_proxy_set_subscribed (av_transport, TRUE);
524 gupnp_service_proxy_set_subscribed (rendering_control, TRUE);
525
526 GCancellable *cancellable = g_cancellable_new ();
527 g_object_set_data_full (G_OBJECT (info),
528 "icon-download-cancellable",
529 cancellable,
530 g_object_unref);
531 update_icon_async (info, cancellable, on_device_icon_available, NULL);
532
533 if (was_empty)
534 gtk_combo_box_set_active_iter (combo, &iter);
535
536 g_free (name);
537 }
538
539 static GUPnPServiceProxy *
540 get_connection_manager (GUPnPDeviceProxy *proxy)
541 {
542 GUPnPDeviceInfo *info;
543 GUPnPServiceInfo *cm;
544
545 info = GUPNP_DEVICE_INFO (proxy);
546
547 cm = gupnp_device_info_get_service (info, CONNECTION_MANAGER);
548
549 return GUPNP_SERVICE_PROXY (cm);
550 }
551
552 static GUPnPServiceProxy *
553 get_rendering_control (GUPnPDeviceProxy *proxy)
554 {
555 GUPnPDeviceInfo *info;
556 GUPnPServiceInfo *rendering_control;
557
558 info = GUPNP_DEVICE_INFO (proxy);
559
560 rendering_control = gupnp_device_info_get_service (info,
561 RENDERING_CONTROL);
562
563 return GUPNP_SERVICE_PROXY (rendering_control);
564 }
565
566 static void
567 get_protocol_info_cb (GObject *object, GAsyncResult *res, gpointer user_data)
568 {
569 gchar *sink_protocol_info;
570 const gchar *udn;
571 GError *error = NULL;
572 GUPnPServiceProxyAction *action;
573 GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
574
575 udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
576 action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
577 if (error != NULL) {
578 g_warning ("Failed to get sink protocl info from "
579 "media renderer '%s': %s",
580 udn,
581 error->message);
582
583 goto return_point;
584 }
585
586 if (!gupnp_service_proxy_action_get_result (action,
587 &error,
588 "Sink",
589 G_TYPE_STRING,
590 &sink_protocol_info,
591 NULL)) {
592 g_warning ("Failed to get sink protocol info from "
593 "media renderer '%s':%s\n",
594 udn,
595 error->message);
596
597 goto return_point;
598 }
599
600 if (sink_protocol_info) {
601 GtkTreeModel *model;
602 GtkTreeIter iter;
603
604 model = gtk_combo_box_get_model
605 (GTK_COMBO_BOX (renderer_combo));
606 g_assert (model != NULL);
607
608 if (find_renderer (model, udn, &iter)) {
609 gtk_list_store_set (GTK_LIST_STORE (model),
610 &iter,
611 5, sink_protocol_info,
612 -1);
613 }
614
615 g_free (sink_protocol_info);
616 }
617
618 return_point:
619 g_clear_error (&error);
620 g_object_unref (object);
621 }
622
623 static void
624 get_transport_info_cb (GObject *object, GAsyncResult *res, gpointer user_data)
625 {
626 gchar *state_name;
627 const gchar *udn;
628 GError *error = NULL;
629 GUPnPServiceProxyAction *action;
630 GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
631
632 action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
633 udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
634 if (error != NULL) {
635 g_warning ("Failed to get transport info from media renderer"
636 " '%s':%s",
637 udn,
638 error->message);
639
640 goto return_point;
641 }
642
643 if (!gupnp_service_proxy_action_get_result (action,
644 &error,
645 "CurrentTransportState",
646 G_TYPE_STRING,
647 &state_name,
648 NULL)) {
649 g_warning ("Failed to get transport info from media renderer"
650 " '%s':%s\n",
651 udn,
652 error->message);
653
654 goto return_point;
655 }
656
657 if (state_name) {
658 set_state_by_name (udn, state_name);
659
660 g_free (state_name);
661 }
662
663 return_point:
664 g_clear_error (&error);
665 g_object_unref (object);
666 }
667
668 static void
669 get_volume_cb (GObject *object, GAsyncResult *res, gpointer user_data)
670 {
671 guint volume;
672 const gchar *udn;
673 GError *error = NULL;
674 GUPnPServiceProxyAction *action;
675 GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
676
677 udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
678 action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
679 if (error != NULL) {
680 g_warning ("Failed to get volume info from media renderer"
681 " '%s':%s",
682 udn,
683 error->message);
684
685 goto return_point;
686 }
687
688 if (!gupnp_service_proxy_action_get_result (action,
689 &error,
690 "CurrentVolume",
691 G_TYPE_UINT,
692 &volume,
693 NULL)) {
694 g_warning ("Failed to get volume from media renderer"
695 " '%s':%s\n",
696 udn,
697 error->message);
698
699 goto return_point;
700 }
701
702 set_volume (udn, volume);
703
704 return_point:
705 g_clear_error (&error);
706 g_object_unref (object);
707 }
708
709 static void
710
711 get_media_info_cb (GObject *object, GAsyncResult *res, gpointer user_data)
712 {
713 gchar *duration;
714 const gchar *udn;
715 GError *error = NULL;
716 GUPnPServiceProxyAction *action;
717 GUPnPServiceProxy *proxy = GUPNP_SERVICE_PROXY (object);
718
719 action = gupnp_service_proxy_call_action_finish (proxy, res, &error);
720 udn = gupnp_service_info_get_udn (GUPNP_SERVICE_INFO (object));
721 if (error != NULL) {
722 g_warning ("Failed to get media info from media renderer"
723 " '%s':%s",
724 udn,
725 error->message);
726
727 goto return_point;
728 }
729
730 if (!gupnp_service_proxy_action_get_result (action,
731 &error,
732 "MediaDuration",
733 G_TYPE_STRING,
734 &duration,
735 NULL)) {
736 g_warning ("Failed to get current media duration"
737 "from media renderer '%s':%s\n",
738 udn,
739 error->message);
740
741 goto return_point;
742 }
743
744 set_duration (udn, duration);
745 g_free (duration);
746
747 return_point:
748 g_clear_error (&error);
749 g_object_unref (object);
750 }
751
752 void
753 add_media_renderer (GUPnPDeviceProxy *proxy)
754 {
755 GtkTreeModel *model;
756 GtkTreeIter iter;
757 const char *udn;
758 GUPnPServiceProxy *cm;
759 GUPnPServiceProxy *av_transport;
760 GUPnPServiceProxy *rendering_control;
761
762 udn = gupnp_device_info_get_udn (GUPNP_DEVICE_INFO (proxy));
763 if (udn == NULL)
764 return;
765
766 cm = get_connection_manager (proxy);
767 if (G_UNLIKELY (cm == NULL))
768 return;
769
770 av_transport = get_av_transport (proxy);
771 if (av_transport == NULL)
772 goto no_av_transport;
773
774 rendering_control = get_rendering_control (proxy);
775 if (rendering_control == NULL)
776 goto no_rendering_control;
777
778 model = gtk_combo_box_get_model (GTK_COMBO_BOX (renderer_combo));
779
780 if (!find_renderer (model, udn, &iter))
781 append_media_renderer_to_tree (proxy,
782 av_transport,
783 rendering_control,
784 udn);
785
786 GUPnPServiceProxyAction *action;
787
788 action = gupnp_service_proxy_action_new ("GetProtocolInfo", NULL);
789 gupnp_service_proxy_call_action_async (g_object_ref (cm),
790 action,
791 NULL,
792 get_protocol_info_cb,
793 NULL);
794 gupnp_service_proxy_action_unref (action);
795
796 action = gupnp_service_proxy_action_new ("GetTransportInfo",
797 "InstanceID",
798 G_TYPE_UINT,
799 0,
800 NULL);
801 gupnp_service_proxy_call_action_async (g_object_ref (av_transport),
802 action,
803 NULL,
804 get_transport_info_cb,
805 NULL);
806 gupnp_service_proxy_action_unref (action);
807
808 action = gupnp_service_proxy_action_new ("GetMediaInfo",
809 "InstanceID",
810 G_TYPE_UINT,
811 0,
812 NULL);
813 gupnp_service_proxy_call_action_async (g_object_ref (av_transport),
814 action,
815 NULL,
816 get_media_info_cb,
817 NULL);
818 gupnp_service_proxy_action_unref (action);
819
820 action = gupnp_service_proxy_action_new ("GetVolume",
821 "InstanceID",
822 G_TYPE_UINT,
823 0,
824 "Channel",
825 G_TYPE_STRING,
826 "Master",
827 NULL);
828 gupnp_service_proxy_call_action_async (g_object_ref (rendering_control),
829 action,
830 NULL,
831 get_volume_cb,
832 NULL);
833 gupnp_service_proxy_action_unref (action);
834
835 g_object_unref (rendering_control);
836 no_rendering_control:
837 g_object_unref (av_transport);
838 no_av_transport:
839 g_object_unref (cm);
840 }
841
842 void
843 remove_media_renderer (GUPnPDeviceProxy *proxy)
844 {
845 GUPnPDeviceInfo *info;
846 GtkComboBox *combo;
847 GtkTreeModel *model;
848 GtkTreeIter iter;
849 const char *udn;
850
851 info = GUPNP_DEVICE_INFO (proxy);
852 combo = GTK_COMBO_BOX (renderer_combo);
853
854 udn = gupnp_device_info_get_udn (info);
855 if (udn == NULL)
856 return;
857
858 model = gtk_combo_box_get_model (combo);
859
860 if (find_renderer (model, udn, &iter)) {
861 GCancellable *cancellable =
862 g_object_get_data (G_OBJECT (info),
863 "icon-download-cancellable");
864 if (cancellable != NULL) {
865 g_cancellable_cancel (cancellable);
866
867 g_object_set_data (G_OBJECT (info),
868 "icon-download-cancellable",
869 NULL);
870 }
871 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
872 gtk_combo_box_set_active (combo, 0);
873 }
874 }
875
876 G_MODULE_EXPORT
877 void
878 on_renderer_combo_changed (GtkComboBox *widget,
879 gpointer user_data)
880 {
881 GtkComboBox *combo;
882 GtkTreeModel *model;
883 GtkTreeIter iter;
884 PlaybackState state;
885 guint volume;
886
887 combo = GTK_COMBO_BOX (widget);
888 model = gtk_combo_box_get_model (combo);
889 g_assert (model != NULL);
890
891 if (!gtk_combo_box_get_active_iter (combo, &iter)) {
892 return;
893 }
894
895 gtk_tree_model_get (model,
896 &iter,
897 6, &state,
898 7, &volume,
899 -1);
900 set_volume_scale (volume);
901 prepare_controls_for_state (state);
902 }
903
904 void
905 setup_renderer_combo (GtkBuilder *builder)
906 {
907 lc_parser = gupnp_last_change_parser_new ();
908 renderer_combo = GTK_WIDGET (gtk_builder_get_object (
909 builder,
910 "renderer-combobox"));
911 }
912