531
/* Gets a newly allocated string with the active text, the caller must
532
* free this string */
534
get_active_text(GtkComboBox *box)
537
int comboBoxIndex = gtk_combo_box_get_active(box);
538
if (comboBoxIndex >= 0) {
540
gtk_combo_box_get_active_iter(box, &iter);
541
gtk_tree_model_get(gtk_combo_box_get_model(box), &iter, 0, &text, -1);
546
/* Return 0 if string was found in the combo box, != 0 if the string was not found */
548
set_combo_index_from_str(GtkComboBox *box, const gchar *str, size_t max)
552
GtkTreeModel *model = gtk_combo_box_get_model(box);
555
gtk_tree_model_get_iter_first(model, &iter);
558
gtk_tree_model_get(model, &iter, 0, &boxstr, -1);
559
if (boxstr && !g_strcmp0(boxstr, str))
561
} while (idx++ < max && gtk_tree_model_iter_next(model, &iter));
566
gtk_combo_box_set_active(box, idx);
572
* Fill video input device rate store
575
preferences_dialog_fill_video_input_device_rate_list()
581
gtk_list_store_clear(v4l2RateList);
583
gchar *dev = get_active_text(GTK_COMBO_BOX(v4l2Device));
584
gchar *chan = get_active_text(GTK_COMBO_BOX(v4l2Channel));
585
gchar *size = get_active_text(GTK_COMBO_BOX(v4l2Size));
587
// Call dbus to retreive list
588
if (dev && chan && size) {
589
list = dbus_get_video_device_rate_list(dev, chan, size);
595
// For each device name included in list
598
for (gchar **tmp = list; *tmp; c++, tmp++) {
599
gtk_list_store_append(v4l2RateList, &iter);
600
gtk_list_store_set(v4l2RateList, &iter, 0, *tmp, 1, c, -1);
604
gchar *rate = dbus_get_active_video_device_rate();
605
if (!rate || !*rate || set_combo_index_from_str(GTK_COMBO_BOX(v4l2Rate), rate, c)) {
606
// if setting is invalid, choose first entry
607
gtk_combo_box_set_active(GTK_COMBO_BOX(v4l2Rate), 0);
608
gchar *selected = get_active_text(GTK_COMBO_BOX(v4l2Rate));
610
dbus_set_active_video_device_rate(selected);
616
g_warning("No video rate list found for device");
621
* Set the video input device rate on the server
624
select_video_input_device_rate_cb(GtkComboBox* comboBox, G_GNUC_UNUSED gpointer data)
626
gchar *str = get_active_text(comboBox);
628
dbus_set_active_video_device_rate(str);
633
* Fill video input device size store
636
preferences_dialog_fill_video_input_device_size_list()
639
gtk_list_store_clear(v4l2SizeList);
641
gchar *dev = get_active_text(GTK_COMBO_BOX(v4l2Device));
642
gchar *chan = get_active_text(GTK_COMBO_BOX(v4l2Channel));
645
// Call dbus to retrieve list
647
list = dbus_get_video_device_size_list(dev, chan);
653
// For each device name included in list
655
for (gchar **tmp = list; *tmp; c++, tmp++) {
657
gtk_list_store_append(v4l2SizeList, &iter);
658
gtk_list_store_set(v4l2SizeList, &iter, 0, *tmp, 1, c, -1);
661
gchar *size = dbus_get_active_video_device_size();
662
if (!size || !*size || set_combo_index_from_str(GTK_COMBO_BOX(v4l2Size), size, c)) {
663
// if setting is invalid, choose first entry
664
gtk_combo_box_set_active(GTK_COMBO_BOX(v4l2Size), 0);
665
gchar *selected = get_active_text(GTK_COMBO_BOX(v4l2Size));
667
dbus_set_active_video_device_size(selected);
673
g_warning("No device size list found");
677
* Set the video input device size on the server
680
select_video_input_device_size_cb(GtkComboBox* comboBox, G_GNUC_UNUSED gpointer data)
682
gchar *str = get_active_text(comboBox);
684
dbus_set_active_video_device_size(str);
685
preferences_dialog_fill_video_input_device_rate_list();
691
* Fill video input device input store
694
preferences_dialog_fill_video_input_device_channel_list()
697
gtk_list_store_clear(v4l2ChannelList);
699
gchar *dev = get_active_text(GTK_COMBO_BOX(v4l2Device));
702
// Call dbus to retrieve list
704
list = dbus_get_video_device_channel_list(dev);
709
// For each device name included in list
711
for (gchar **tmp = list; *tmp; c++, tmp++) {
713
gtk_list_store_append(v4l2ChannelList, &iter);
714
gtk_list_store_set(v4l2ChannelList, &iter, 0, *tmp, 1, c, -1);
717
gchar *channel = dbus_get_active_video_device_channel();
718
if (!channel || !*channel || set_combo_index_from_str(GTK_COMBO_BOX(v4l2Channel), channel, c)) {
719
// if setting is invalid, choose first entry
720
gtk_combo_box_set_active(GTK_COMBO_BOX(v4l2Channel), 0);
721
gchar *selected = get_active_text(GTK_COMBO_BOX(v4l2Channel));
723
dbus_set_active_video_device_channel(selected);
729
g_warning("No channel list found");
733
* Set the video input device input on the server
736
select_video_input_device_channel_cb(GtkComboBox* comboBox, G_GNUC_UNUSED gpointer data)
738
gchar *str = get_active_text(comboBox);
740
dbus_set_active_video_device_channel(str);
741
preferences_dialog_fill_video_input_device_size_list();
747
* Fill video input device store
750
preferences_dialog_fill_video_input_device_list()
752
gtk_list_store_clear(v4l2DeviceList);
754
// Call dbus to retrieve list
755
gchar **list = dbus_get_video_device_list();
756
if (!list || !*list) {
757
g_warning("No device list found");
760
// For each device name included in list
762
for (gchar **tmp = list; *tmp; c++, tmp++) {
764
gtk_list_store_append(v4l2DeviceList, &iter);
765
gtk_list_store_set(v4l2DeviceList, &iter, 0, *tmp, 1, c, -1);
768
gchar *dev = dbus_get_active_video_device();
769
if (!dev || !*dev || set_combo_index_from_str(GTK_COMBO_BOX(v4l2Device), dev, c)) {
770
// if setting is invalid, choose first entry
771
gtk_combo_box_set_active(GTK_COMBO_BOX(v4l2Device), 0);
772
gchar *selected = get_active_text(GTK_COMBO_BOX(v4l2Device));
774
dbus_set_active_video_device(selected);
784
* Set the video input device on the server
787
select_video_input_device_cb(GtkComboBox* comboBox, G_GNUC_UNUSED gpointer data)
789
gchar *str = get_active_text(comboBox);
791
g_debug("Setting video input device to %s", str);
792
dbus_set_active_video_device(str);
793
preferences_dialog_fill_video_input_device_channel_list();
801
if (preferences_dialog_fill_video_input_device_list()) {
548
reset_combo_box(GtkComboBoxText *combo, gchar **entries, const gchar *preferred)
550
g_assert(GTK_IS_WIDGET(combo));
552
guint index = 0; /* first one if not found */
554
/* Temporarily deactivate the "changed" signal to clear the list */
555
const guint signal_id = g_signal_lookup("changed", G_OBJECT_TYPE(combo));
556
const gulong handler_id = g_signal_handler_find(combo, G_SIGNAL_MATCH_ID, signal_id, 0, NULL, NULL, NULL);
557
g_signal_handler_block(combo, handler_id);
558
gtk_combo_box_text_remove_all(combo);
559
g_signal_handler_unblock(combo, handler_id);
561
for (guint i = 0; entries[i]; ++i) {
562
gtk_combo_box_text_insert_text(combo, i, entries[i]);
563
if (g_strcmp0(entries[i], preferred) == 0)
567
/* NOTE This will invoke the combo box's "changed" callback */
568
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), index);
574
gchar **devices = dbus_video_get_device_list();
578
gchar *default_device = dbus_video_get_default_device();
579
reset_combo_box(v4l2Device, devices, default_device);
580
g_free(default_device);
802
582
gtk_widget_show_all(v4l2_hbox);
803
583
gtk_widget_hide(v4l2_nodev);
804
584
gtk_widget_set_sensitive(camera_button, TRUE);
805
585
} else if (GTK_IS_WIDGET(v4l2_hbox)) {
586
g_warning("No video devices");
806
587
gtk_widget_hide(v4l2_hbox);
807
588
gtk_widget_show(v4l2_nodev);
808
589
gtk_widget_set_sensitive(camera_button, FALSE);
596
combo_box_device_changed_cb(G_GNUC_UNUSED GtkComboBoxText* combo, gpointer data)
598
VideoDevice *dev = (VideoDevice *) data;
599
gchar *name = gtk_combo_box_text_get_active_text(v4l2Device);
602
/* Clear the video device */
604
video_capabilities_free(dev->cap);
611
dev->cap = video_capabilities_new(name);
613
/* Fetch user preferences for this device */
614
GHashTable *hash = dbus_video_get_settings(name);
615
dev->chan = g_strdup(g_hash_table_lookup(hash, "channel"));
616
dev->size = g_strdup(g_hash_table_lookup(hash, "size"));
617
dev->rate = g_strdup(g_hash_table_lookup(hash, "rate"));
618
g_hash_table_destroy(hash);
620
/* Start the cascade into the channel combo box */
621
gchar **channels = video_capabilities_get_channels(dev->cap);
622
reset_combo_box(v4l2Channel, channels, dev->chan);
623
g_strfreev(channels);
627
combo_box_channel_changed_cb(G_GNUC_UNUSED GtkComboBoxText *combo, gpointer data)
629
VideoDevice *dev = (VideoDevice *) data;
630
gchar *chan = gtk_combo_box_text_get_active_text(v4l2Channel);
635
/* Cascade into the size combo box */
636
gchar** sizes = video_capabilities_get_sizes(dev->cap, dev->chan);
637
reset_combo_box(v4l2Size, sizes, dev->size);
642
combo_box_size_changed_cb(G_GNUC_UNUSED GtkComboBoxText *combo, gpointer data)
644
VideoDevice *dev = (VideoDevice *) data;
645
gchar *size = gtk_combo_box_text_get_active_text(v4l2Size);
650
/* Cascade into the rate combo box */
651
gchar **rates = video_capabilities_get_rates(dev->cap, dev->chan, dev->size);
652
reset_combo_box(v4l2Rate, rates, dev->rate);
657
combo_box_rate_changed_cb(G_GNUC_UNUSED GtkComboBoxText *combo, gpointer data)
659
VideoDevice *dev = (VideoDevice *) data;
660
gchar *rate = gtk_combo_box_text_get_active_text(v4l2Rate);
665
/* End of the cascade, save the default device and its settings */
666
dbus_video_set_default_device(dev->name);
667
GHashTable *hash = g_hash_table_new(g_str_hash, g_str_equal);
668
g_hash_table_insert(hash, "channel", dev->chan);
669
g_hash_table_insert(hash, "size", dev->size);
670
g_hash_table_insert(hash, "rate", dev->rate);
671
dbus_video_apply_settings(dev->name, hash);
672
g_hash_table_destroy(hash);
813
676
video_device_event_cb(G_GNUC_UNUSED DBusGProxy *proxy, G_GNUC_UNUSED gpointer foo)
678
/* FIXME: get rid of these global widgets */
679
g_return_if_fail(GTK_IS_WIDGET(v4l2Device));
683
static GtkComboBoxText *
684
attach_combo_box(GtkGrid *grid, const guint row, const gchar *label, GCallback callback, gpointer data)
686
/* Attach the label on left */
687
GtkWidget *item = gtk_label_new(_(label));
688
gtk_grid_attach(grid, item, 0, row, 1, 1);
690
/* Attach the combo combo on right */
691
GtkWidget *combo = gtk_combo_box_text_new();
692
g_signal_connect(G_OBJECT(combo), "changed", callback, data);
693
gtk_grid_attach(grid, combo, 1, row, 1, 1);
695
return GTK_COMBO_BOX_TEXT(combo);
819
698
static GtkWidget *
831
710
gtk_grid_set_column_spacing(GTK_GRID(grid), 40);
832
711
gtk_box_pack_start(GTK_BOX(v4l2_hbox), grid, TRUE, TRUE, 1);
834
// Set choices of input devices
835
GtkWidget *item = gtk_label_new(_("Device"));
836
v4l2DeviceList = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
837
v4l2Device = gtk_combo_box_new_with_model(GTK_TREE_MODEL(v4l2DeviceList));
838
gtk_label_set_mnemonic_widget(GTK_LABEL(item), v4l2Device);
840
g_signal_connect(G_OBJECT(v4l2Device), "changed", G_CALLBACK(select_video_input_device_cb), NULL);
841
gtk_grid_attach(GTK_GRID(grid), item, 0, 0, 1, 1);
844
GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
845
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(v4l2Device), renderer, TRUE);
846
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(v4l2Device), renderer, "text", 0, NULL);
847
gtk_grid_attach(GTK_GRID(grid), v4l2Device, 1, 0, 1, 1);
849
// Set choices of input
850
item = gtk_label_new(_("Channel"));
851
v4l2ChannelList = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
852
v4l2Channel = gtk_combo_box_new_with_model(GTK_TREE_MODEL(v4l2ChannelList));
853
gtk_label_set_mnemonic_widget(GTK_LABEL(item), v4l2Channel);
854
g_signal_connect(G_OBJECT(v4l2Channel), "changed", G_CALLBACK(select_video_input_device_channel_cb), NULL);
855
gtk_grid_attach(GTK_GRID(grid), item, 0, 1, 1, 1);
858
renderer = gtk_cell_renderer_text_new();
859
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(v4l2Channel), renderer, TRUE);
860
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(v4l2Channel), renderer, "text", 0, NULL);
861
gtk_grid_attach(GTK_GRID(grid), v4l2Channel, 1, 1, 1, 1);
863
// Set choices of sizes
864
item = gtk_label_new(_("Size"));
865
v4l2SizeList = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
866
v4l2Size = gtk_combo_box_new_with_model(GTK_TREE_MODEL(v4l2SizeList));
867
gtk_label_set_mnemonic_widget(GTK_LABEL(item), v4l2Size);
868
g_signal_connect(G_OBJECT(v4l2Size), "changed", G_CALLBACK(select_video_input_device_size_cb), NULL);
869
gtk_grid_attach(GTK_GRID(grid), item, 0, 2, 1, 1);
872
renderer = gtk_cell_renderer_text_new();
873
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(v4l2Size), renderer, TRUE);
874
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(v4l2Size), renderer, "text", 0, NULL);
875
gtk_grid_attach(GTK_GRID(grid), v4l2Size, 1, 2, 1, 1);
877
// Set choices of rates
878
item = gtk_label_new(_("Rate"));
879
v4l2RateList = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
880
v4l2Rate = gtk_combo_box_new_with_model(GTK_TREE_MODEL(v4l2RateList));
881
gtk_label_set_mnemonic_widget(GTK_LABEL(item), v4l2Rate);
882
g_signal_connect(G_OBJECT(v4l2Rate), "changed", G_CALLBACK(select_video_input_device_rate_cb), NULL);
883
gtk_grid_attach(GTK_GRID(grid), item, 0, 3, 1, 1);
886
renderer = gtk_cell_renderer_text_new();
887
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(v4l2Rate), renderer, TRUE);
888
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(v4l2Rate), renderer, "text", 0, NULL);
889
gtk_grid_attach(GTK_GRID(grid), v4l2Rate, 1, 3, 1, 1);
713
VideoDevice *dev = g_new0(VideoDevice, 1);
715
v4l2Device = attach_combo_box(GTK_GRID(grid), 0, "Device", G_CALLBACK(combo_box_device_changed_cb), dev);
716
v4l2Channel = attach_combo_box(GTK_GRID(grid), 1, "Channel", G_CALLBACK(combo_box_channel_changed_cb), dev);
717
v4l2Size = attach_combo_box(GTK_GRID(grid), 2, "Size", G_CALLBACK(combo_box_size_changed_cb), dev);
718
v4l2Rate = attach_combo_box(GTK_GRID(grid), 3, "Rate", G_CALLBACK(combo_box_rate_changed_cb), dev);
896
724
create_video_configuration()