110dfe897SAxel Dörfler /* 210dfe897SAxel Dörfler * Copyright 2003-2011, Haiku. 310dfe897SAxel Dörfler * Distributed under the terms of the MIT License. 410dfe897SAxel Dörfler * 510dfe897SAxel Dörfler * Authors: 610dfe897SAxel Dörfler * Sikosis 710dfe897SAxel Dörfler * Jérôme Duval 810dfe897SAxel Dörfler */ 910dfe897SAxel Dörfler 1010dfe897SAxel Dörfler 11a633251fSAlex Wilson #include "MediaViews.h" 12f8a1135cSAdrien Destugues 137afc7756SAlex Wilson #include <AutoDeleter.h> 14a10cf76eSAxel Dörfler #include <Box.h> 15a10cf76eSAxel Dörfler #include <Button.h> 16f8a1135cSAdrien Destugues #include <Catalog.h> 177afc7756SAlex Wilson #include <CheckBox.h> 18a10cf76eSAxel Dörfler #include <Deskbar.h> 19a10cf76eSAxel Dörfler #include <Entry.h> 207afc7756SAlex Wilson #include <LayoutBuilder.h> 21f8a1135cSAdrien Destugues #include <Locale.h> 22a10cf76eSAxel Dörfler #include <MediaAddOn.h> 23f8a1135cSAdrien Destugues #include <MediaRoster.h> 24f8a1135cSAdrien Destugues #include <MenuField.h> 25f8a1135cSAdrien Destugues #include <PopUpMenu.h> 26a10cf76eSAxel Dörfler #include <String.h> 277afc7756SAlex Wilson #include <StringView.h> 28b4a12470SJérôme Duval #include <TextView.h> 292af5f895SStephan Aßmus 307afc7756SAlex Wilson #include <assert.h> 31a633251fSAlex Wilson #include <stdio.h> 32a10cf76eSAxel Dörfler 337afc7756SAlex Wilson #include "MediaWindow.h" 347afc7756SAlex Wilson 359cedafe6SWim van der Meer 36546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT 37546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "Media views" 38f8a1135cSAdrien Destugues 397afc7756SAlex Wilson #define MEDIA_DEFAULT_INPUT_CHANGE 'dich' 407afc7756SAlex Wilson #define MEDIA_DEFAULT_OUTPUT_CHANGE 'doch' 417afc7756SAlex Wilson #define MEDIA_SHOW_HIDE_VOLUME_CONTROL 'shvc' 429cedafe6SWim van der Meer 437afc7756SAlex Wilson 447afc7756SAlex Wilson SettingsView::SettingsView() 45a633251fSAlex Wilson : 46c97121d3SAlex Wilson BGroupView(B_VERTICAL, B_USE_DEFAULT_SPACING), 477afc7756SAlex Wilson fInputMenu(NULL), 48c97121d3SAlex Wilson fOutputMenu(NULL) 49a10cf76eSAxel Dörfler { 506e62e744SAlex Wilson // input menu 51*bc622f6bSHumdinger fInputMenu = new BPopUpMenu(B_TRANSLATE_ALL("<none>", 52*bc622f6bSHumdinger "VideoInputMenu", "Used when no video input is available")); 536e62e744SAlex Wilson fInputMenu->SetLabelFromMarked(true); 546e62e744SAlex Wilson 55*bc622f6bSHumdinger // output menu 56*bc622f6bSHumdinger fOutputMenu = new BPopUpMenu(B_TRANSLATE_ALL("<none>", 57*bc622f6bSHumdinger "VideoOutputMenu", "Used when no video output is available")); 586e62e744SAlex Wilson fOutputMenu->SetLabelFromMarked(true); 596e62e744SAlex Wilson } 606e62e744SAlex Wilson 612af5f895SStephan Aßmus 627afc7756SAlex Wilson BButton* 637afc7756SAlex Wilson SettingsView::MakeRestartButton() 647afc7756SAlex Wilson { 657afc7756SAlex Wilson return new BButton("restartButton", 66176fb40fSMatt Madia B_TRANSLATE("Restart media services"), 67939b40d6SJessica Hamilton new BMessage(ML_RESTART_MEDIA_SERVER)); 68a10cf76eSAxel Dörfler } 692af5f895SStephan Aßmus 702af5f895SStephan Aßmus 717afc7756SAlex Wilson 727afc7756SAlex Wilson void 737afc7756SAlex Wilson SettingsView::AddInputNodes(NodeList& list) 747afc7756SAlex Wilson { 757afc7756SAlex Wilson _EmptyMenu(fInputMenu); 767afc7756SAlex Wilson 777afc7756SAlex Wilson BMessage message(MEDIA_DEFAULT_INPUT_CHANGE); 787afc7756SAlex Wilson _PopulateMenu(fInputMenu, list, message); 79a10cf76eSAxel Dörfler } 80a10cf76eSAxel Dörfler 81a633251fSAlex Wilson 82a10cf76eSAxel Dörfler void 837afc7756SAlex Wilson SettingsView::AddOutputNodes(NodeList& list) 84a10cf76eSAxel Dörfler { 857afc7756SAlex Wilson _EmptyMenu(fOutputMenu); 866e62e744SAlex Wilson 877afc7756SAlex Wilson BMessage message(MEDIA_DEFAULT_OUTPUT_CHANGE); 887afc7756SAlex Wilson _PopulateMenu(fOutputMenu, list, message); 89a10cf76eSAxel Dörfler } 90a10cf76eSAxel Dörfler 91a633251fSAlex Wilson 92a10cf76eSAxel Dörfler void 937afc7756SAlex Wilson SettingsView::SetDefaultInput(const dormant_node_info* info) 94a10cf76eSAxel Dörfler { 957afc7756SAlex Wilson _ClearMenuSelection(fInputMenu); 967afc7756SAlex Wilson NodeMenuItem* item = _FindNodeItem(fInputMenu, info); 977afc7756SAlex Wilson if (item) 98a10cf76eSAxel Dörfler item->SetMarked(true); 997afc7756SAlex Wilson } 1007afc7756SAlex Wilson 1017afc7756SAlex Wilson 1027afc7756SAlex Wilson void 1037afc7756SAlex Wilson SettingsView::SetDefaultOutput(const dormant_node_info* info) 1047afc7756SAlex Wilson { 1057afc7756SAlex Wilson _ClearMenuSelection(fOutputMenu); 1067afc7756SAlex Wilson NodeMenuItem* item = _FindNodeItem(fOutputMenu, info); 1077afc7756SAlex Wilson if (item) 1087afc7756SAlex Wilson item->SetMarked(true); 1097afc7756SAlex Wilson } 1107afc7756SAlex Wilson 1117afc7756SAlex Wilson 1127afc7756SAlex Wilson void 1137afc7756SAlex Wilson SettingsView::MessageReceived(BMessage* message) 1147afc7756SAlex Wilson { 1157afc7756SAlex Wilson switch (message->what) { 1167afc7756SAlex Wilson case MEDIA_DEFAULT_INPUT_CHANGE: 1177afc7756SAlex Wilson { 1187afc7756SAlex Wilson int32 index; 1197afc7756SAlex Wilson if (message->FindInt32("index", &index)!=B_OK) 1207afc7756SAlex Wilson break; 1217afc7756SAlex Wilson NodeMenuItem* item 1227afc7756SAlex Wilson = static_cast<NodeMenuItem*>(fInputMenu->ItemAt(index)); 1237afc7756SAlex Wilson SetDefaultInput(item->NodeInfo()); 124d2772fb4SAlex Wilson break; 1257afc7756SAlex Wilson } 1267afc7756SAlex Wilson case MEDIA_DEFAULT_OUTPUT_CHANGE: 1277afc7756SAlex Wilson { 1287afc7756SAlex Wilson int32 index; 1297afc7756SAlex Wilson if (message->FindInt32("index", &index)!=B_OK) 1307afc7756SAlex Wilson break; 1317afc7756SAlex Wilson NodeMenuItem* item 1327afc7756SAlex Wilson = static_cast<NodeMenuItem*>(fOutputMenu->ItemAt(index)); 1337afc7756SAlex Wilson SetDefaultOutput(item->NodeInfo()); 134a10cf76eSAxel Dörfler break; 135a10cf76eSAxel Dörfler } 136d2772fb4SAlex Wilson default: 137c97121d3SAlex Wilson BGroupView::MessageReceived(message); 1387afc7756SAlex Wilson } 139d2772fb4SAlex Wilson } 140a10cf76eSAxel Dörfler 141a633251fSAlex Wilson 1427afc7756SAlex Wilson void 1437afc7756SAlex Wilson SettingsView::AttachedToWindow() 1447afc7756SAlex Wilson { 1457afc7756SAlex Wilson BMessenger thisMessenger(this); 1467afc7756SAlex Wilson fInputMenu->SetTargetForItems(thisMessenger); 1477afc7756SAlex Wilson fOutputMenu->SetTargetForItems(thisMessenger); 1487afc7756SAlex Wilson } 1497afc7756SAlex Wilson 1507afc7756SAlex Wilson 1517afc7756SAlex Wilson MediaWindow* 1527afc7756SAlex Wilson SettingsView::_MediaWindow() const 1537afc7756SAlex Wilson { 1547afc7756SAlex Wilson return static_cast<MediaWindow*>(Window()); 1557afc7756SAlex Wilson } 1567afc7756SAlex Wilson 1577afc7756SAlex Wilson 1587afc7756SAlex Wilson void 1597afc7756SAlex Wilson SettingsView::_EmptyMenu(BMenu* menu) 1607afc7756SAlex Wilson { 1617afc7756SAlex Wilson while (menu->CountItems() > 0) 1627afc7756SAlex Wilson delete menu->RemoveItem((int32)0); 1637afc7756SAlex Wilson } 1647afc7756SAlex Wilson 1657afc7756SAlex Wilson 1667afc7756SAlex Wilson void 1677afc7756SAlex Wilson SettingsView::_PopulateMenu(BMenu* menu, NodeList& nodes, 1687afc7756SAlex Wilson const BMessage& message) 1697afc7756SAlex Wilson { 1707afc7756SAlex Wilson for (int32 i = 0; i < nodes.CountItems(); i++) { 1717afc7756SAlex Wilson dormant_node_info* info = nodes.ItemAt(i); 1727afc7756SAlex Wilson menu->AddItem(new NodeMenuItem(info, new BMessage(message))); 1737afc7756SAlex Wilson } 1747afc7756SAlex Wilson 1757afc7756SAlex Wilson if (Window() != NULL) 1767afc7756SAlex Wilson menu->SetTargetForItems(BMessenger(this)); 1777afc7756SAlex Wilson } 1787afc7756SAlex Wilson 1797afc7756SAlex Wilson 1807afc7756SAlex Wilson NodeMenuItem* 1817afc7756SAlex Wilson SettingsView::_FindNodeItem(BMenu* menu, const dormant_node_info* nodeInfo) 1827afc7756SAlex Wilson { 1837afc7756SAlex Wilson for (int32 i = 0; i < menu->CountItems(); i++) { 1847afc7756SAlex Wilson NodeMenuItem* item = static_cast<NodeMenuItem*>(menu->ItemAt(i)); 1857afc7756SAlex Wilson const dormant_node_info* itemInfo = item->NodeInfo(); 1867afc7756SAlex Wilson if (itemInfo && itemInfo->addon == nodeInfo->addon 1877afc7756SAlex Wilson && itemInfo->flavor_id == nodeInfo->flavor_id) { 1887afc7756SAlex Wilson return item; 189a10cf76eSAxel Dörfler } 190a10cf76eSAxel Dörfler } 1917afc7756SAlex Wilson return NULL; 192a10cf76eSAxel Dörfler } 1937afc7756SAlex Wilson 1947afc7756SAlex Wilson 1957afc7756SAlex Wilson void 1967afc7756SAlex Wilson SettingsView::_ClearMenuSelection(BMenu* menu) 1977afc7756SAlex Wilson { 1987afc7756SAlex Wilson for (int32 i = 0; i < menu->CountItems(); i++) { 1997afc7756SAlex Wilson BMenuItem* item = menu->ItemAt(i); 2007afc7756SAlex Wilson item->SetMarked(false); 201a10cf76eSAxel Dörfler } 202a10cf76eSAxel Dörfler } 203a10cf76eSAxel Dörfler 204a633251fSAlex Wilson 2057afc7756SAlex Wilson NodeMenuItem::NodeMenuItem(const dormant_node_info* info, BMessage* message, 206a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 207a633251fSAlex Wilson : 208a633251fSAlex Wilson BMenuItem(info->name, message, shortcut, modifiers), 209b4a12470SJérôme Duval fInfo(info) 210a10cf76eSAxel Dörfler { 211a10cf76eSAxel Dörfler 212a10cf76eSAxel Dörfler } 213a10cf76eSAxel Dörfler 2146df0b2d5SJérôme Duval 2156df0b2d5SJérôme Duval status_t 2167afc7756SAlex Wilson NodeMenuItem::Invoke(BMessage* message) 2176df0b2d5SJérôme Duval { 2186df0b2d5SJérôme Duval if (IsMarked()) 2196df0b2d5SJérôme Duval return B_OK; 2206df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2216df0b2d5SJérôme Duval } 2226df0b2d5SJérôme Duval 2236df0b2d5SJérôme Duval 2247afc7756SAlex Wilson ChannelMenuItem::ChannelMenuItem(media_input* input, BMessage* message, 2257afc7756SAlex Wilson char shortcut, uint32 modifiers) 226a633251fSAlex Wilson : 227a633251fSAlex Wilson BMenuItem(input->name, message, shortcut, modifiers), 228b4a12470SJérôme Duval fInput(input) 229a10cf76eSAxel Dörfler { 230a10cf76eSAxel Dörfler } 231a10cf76eSAxel Dörfler 2326df0b2d5SJérôme Duval 2337afc7756SAlex Wilson ChannelMenuItem::~ChannelMenuItem() 234a10cf76eSAxel Dörfler { 235b4a12470SJérôme Duval delete fInput; 236a10cf76eSAxel Dörfler } 237a10cf76eSAxel Dörfler 2386df0b2d5SJérôme Duval 2397afc7756SAlex Wilson int32 2407afc7756SAlex Wilson ChannelMenuItem::DestinationID() 2417afc7756SAlex Wilson { 2427afc7756SAlex Wilson return fInput->destination.id; 2437afc7756SAlex Wilson } 2447afc7756SAlex Wilson 2457afc7756SAlex Wilson 2467afc7756SAlex Wilson media_input* 2477afc7756SAlex Wilson ChannelMenuItem::Input() 2487afc7756SAlex Wilson { 2497afc7756SAlex Wilson return fInput; 2507afc7756SAlex Wilson } 2517afc7756SAlex Wilson 2527afc7756SAlex Wilson 2536df0b2d5SJérôme Duval status_t 2547afc7756SAlex Wilson ChannelMenuItem::Invoke(BMessage* message) 2556df0b2d5SJérôme Duval { 2566df0b2d5SJérôme Duval if (IsMarked()) 2576df0b2d5SJérôme Duval return B_OK; 2586df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2596df0b2d5SJérôme Duval } 2606df0b2d5SJérôme Duval 2617afc7756SAlex Wilson 2627afc7756SAlex Wilson AudioSettingsView::AudioSettingsView() 2637afc7756SAlex Wilson { 2647afc7756SAlex Wilson BBox* defaultsBox = new BBox("defaults"); 2657afc7756SAlex Wilson defaultsBox->SetLabel(B_TRANSLATE("Defaults")); 2667afc7756SAlex Wilson BGridView* defaultsGridView = new BGridView(); 2677afc7756SAlex Wilson 2687afc7756SAlex Wilson BMenuField* inputMenuField = new BMenuField("inputMenuField", 26910dfe897SAxel Dörfler B_TRANSLATE("Audio input:"), InputMenu()); 2707afc7756SAlex Wilson 2717afc7756SAlex Wilson BMenuField* outputMenuField = new BMenuField("outputMenuField", 27210dfe897SAxel Dörfler B_TRANSLATE("Audio output:"), OutputMenu()); 2737afc7756SAlex Wilson 2747afc7756SAlex Wilson BLayoutBuilder::Grid<>(defaultsGridView) 275c97121d3SAlex Wilson .SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING, 276c97121d3SAlex Wilson B_USE_DEFAULT_SPACING) 2777afc7756SAlex Wilson .AddMenuField(inputMenuField, 0, 0, B_ALIGN_HORIZONTAL_UNSET, 1, 3, 1) 2787afc7756SAlex Wilson .AddMenuField(outputMenuField, 0, 1) 279c97121d3SAlex Wilson .AddMenuField(_MakeChannelMenu(), 2, 1); 2807afc7756SAlex Wilson 2817afc7756SAlex Wilson defaultsBox->AddChild(defaultsGridView); 2827afc7756SAlex Wilson 283c97121d3SAlex Wilson BLayoutBuilder::Group<>(this) 2847afc7756SAlex Wilson .SetInsets(0, 0, 0, 0) 285c97121d3SAlex Wilson .Add(defaultsBox) 286c97121d3SAlex Wilson .AddGroup(B_HORIZONTAL) 287c97121d3SAlex Wilson .Add(_MakeVolumeCheckBox()) 2888a28f849SDario Casalinuovo .AddGlue() 289c97121d3SAlex Wilson .Add(MakeRestartButton()) 290c97121d3SAlex Wilson .End() 291c97121d3SAlex Wilson .AddGlue(); 2927afc7756SAlex Wilson } 2937afc7756SAlex Wilson 2947afc7756SAlex Wilson 2957afc7756SAlex Wilson void 2967afc7756SAlex Wilson AudioSettingsView::SetDefaultChannel(int32 channelID) 2977afc7756SAlex Wilson { 2987afc7756SAlex Wilson for (int32 i = 0; i < fChannelMenu->CountItems(); i++) { 2997afc7756SAlex Wilson ChannelMenuItem* item = _ChannelMenuItemAt(i); 3007afc7756SAlex Wilson item->SetMarked(item->DestinationID() == channelID); 3017afc7756SAlex Wilson } 3027afc7756SAlex Wilson } 3037afc7756SAlex Wilson 3047afc7756SAlex Wilson 3057afc7756SAlex Wilson void 3067afc7756SAlex Wilson AudioSettingsView::AttachedToWindow() 3077afc7756SAlex Wilson { 3087afc7756SAlex Wilson SettingsView::AttachedToWindow(); 3097afc7756SAlex Wilson 3107afc7756SAlex Wilson BMessenger thisMessenger(this); 3117afc7756SAlex Wilson fChannelMenu->SetTargetForItems(thisMessenger); 3127afc7756SAlex Wilson fVolumeCheckBox->SetTarget(thisMessenger); 3137afc7756SAlex Wilson } 3147afc7756SAlex Wilson 3157afc7756SAlex Wilson 3167afc7756SAlex Wilson void 3177afc7756SAlex Wilson AudioSettingsView::MessageReceived(BMessage* message) 3187afc7756SAlex Wilson { 3197afc7756SAlex Wilson switch (message->what) { 3207afc7756SAlex Wilson case ML_DEFAULT_CHANNEL_CHANGED: 3217afc7756SAlex Wilson { 3227afc7756SAlex Wilson int32 index; 3237afc7756SAlex Wilson if (message->FindInt32("index", &index) != B_OK) 3247afc7756SAlex Wilson break; 3257afc7756SAlex Wilson ChannelMenuItem* item = _ChannelMenuItemAt(index); 3267afc7756SAlex Wilson 3277afc7756SAlex Wilson if (item) { 3287afc7756SAlex Wilson BMediaRoster* roster = BMediaRoster::Roster(); 3297afc7756SAlex Wilson roster->SetAudioOutput(*item->Input()); 3307afc7756SAlex Wilson } else 3317afc7756SAlex Wilson fprintf(stderr, "ChannelMenuItem not found\n"); 3327afc7756SAlex Wilson } 3337afc7756SAlex Wilson break; 3347afc7756SAlex Wilson case MEDIA_SHOW_HIDE_VOLUME_CONTROL: 3357afc7756SAlex Wilson { 3367afc7756SAlex Wilson if (fVolumeCheckBox->Value() == B_CONTROL_ON) 3377afc7756SAlex Wilson _ShowDeskbarVolumeControl(); 3387afc7756SAlex Wilson else 3397afc7756SAlex Wilson _HideDeskbarVolumeControl(); 3407afc7756SAlex Wilson break; 3417afc7756SAlex Wilson } 3427afc7756SAlex Wilson 3437afc7756SAlex Wilson default: 3447afc7756SAlex Wilson SettingsView::MessageReceived(message); 3457afc7756SAlex Wilson } 3467afc7756SAlex Wilson } 3477afc7756SAlex Wilson 3487afc7756SAlex Wilson 3497afc7756SAlex Wilson void 3507afc7756SAlex Wilson AudioSettingsView::SetDefaultInput(const dormant_node_info* info) 3517afc7756SAlex Wilson { 3527afc7756SAlex Wilson SettingsView::SetDefaultInput(info); 3537afc7756SAlex Wilson _MediaWindow()->UpdateInputListItem(MediaListItem::AUDIO_TYPE, info); 3547afc7756SAlex Wilson BMediaRoster::Roster()->SetAudioInput(*info); 3557afc7756SAlex Wilson } 3567afc7756SAlex Wilson 3577afc7756SAlex Wilson 3587afc7756SAlex Wilson void 3597afc7756SAlex Wilson AudioSettingsView::SetDefaultOutput(const dormant_node_info* info) 3607afc7756SAlex Wilson { 3617afc7756SAlex Wilson SettingsView::SetDefaultOutput(info); 3627afc7756SAlex Wilson _MediaWindow()->UpdateOutputListItem(MediaListItem::AUDIO_TYPE, info); 3637afc7756SAlex Wilson _FillChannelMenu(info); 3647afc7756SAlex Wilson BMediaRoster::Roster()->SetAudioOutput(*info); 3657afc7756SAlex Wilson } 3667afc7756SAlex Wilson 3677afc7756SAlex Wilson 3687afc7756SAlex Wilson BMenuField* 3697afc7756SAlex Wilson AudioSettingsView::_MakeChannelMenu() 3707afc7756SAlex Wilson { 3717afc7756SAlex Wilson fChannelMenu = new BPopUpMenu(B_TRANSLATE("<none>")); 3727afc7756SAlex Wilson fChannelMenu->SetLabelFromMarked(true); 3737afc7756SAlex Wilson BMenuField* channelMenuField = new BMenuField("channelMenuField", 37410dfe897SAxel Dörfler B_TRANSLATE("Channel:"), fChannelMenu); 3757afc7756SAlex Wilson return channelMenuField; 3767afc7756SAlex Wilson } 3777afc7756SAlex Wilson 3787afc7756SAlex Wilson 3797afc7756SAlex Wilson BCheckBox* 3807afc7756SAlex Wilson AudioSettingsView::_MakeVolumeCheckBox() 3817afc7756SAlex Wilson { 3827afc7756SAlex Wilson fVolumeCheckBox = new BCheckBox("volumeCheckBox", 3837afc7756SAlex Wilson B_TRANSLATE("Show volume control on Deskbar"), 3847afc7756SAlex Wilson new BMessage(MEDIA_SHOW_HIDE_VOLUME_CONTROL)); 3857afc7756SAlex Wilson 3867afc7756SAlex Wilson if (BDeskbar().HasItem("MediaReplicant")) 3877afc7756SAlex Wilson fVolumeCheckBox->SetValue(B_CONTROL_ON); 3887afc7756SAlex Wilson 3897afc7756SAlex Wilson return fVolumeCheckBox; 3907afc7756SAlex Wilson } 3917afc7756SAlex Wilson 3927afc7756SAlex Wilson 3937afc7756SAlex Wilson void 3947afc7756SAlex Wilson AudioSettingsView::_FillChannelMenu(const dormant_node_info* nodeInfo) 3957afc7756SAlex Wilson { 3967afc7756SAlex Wilson _EmptyMenu(fChannelMenu); 3977afc7756SAlex Wilson 3987afc7756SAlex Wilson BMediaRoster* roster = BMediaRoster::Roster(); 3997afc7756SAlex Wilson media_node node; 4007afc7756SAlex Wilson media_node_id node_id; 4017afc7756SAlex Wilson 4027afc7756SAlex Wilson status_t err = roster->GetInstancesFor(nodeInfo->addon, 4037afc7756SAlex Wilson nodeInfo->flavor_id, &node_id); 4047afc7756SAlex Wilson if (err != B_OK) { 4057afc7756SAlex Wilson err = roster->InstantiateDormantNode(*nodeInfo, &node, 4067afc7756SAlex Wilson B_FLAVOR_IS_GLOBAL); 4077afc7756SAlex Wilson } else { 4087afc7756SAlex Wilson err = roster->GetNodeFor(node_id, &node); 4097afc7756SAlex Wilson } 4107afc7756SAlex Wilson 4117afc7756SAlex Wilson if (err == B_OK) { 4127afc7756SAlex Wilson int32 inputCount = 4; 4137afc7756SAlex Wilson media_input* inputs = new media_input[inputCount]; 4147afc7756SAlex Wilson BPrivate::ArrayDeleter<media_input> inputDeleter(inputs); 4157afc7756SAlex Wilson 4167afc7756SAlex Wilson while (true) { 4177afc7756SAlex Wilson int32 realInputCount = 0; 4187afc7756SAlex Wilson err = roster->GetAllInputsFor(node, inputs, 4197afc7756SAlex Wilson inputCount, &realInputCount); 4207afc7756SAlex Wilson if (realInputCount > inputCount) { 4217afc7756SAlex Wilson inputCount *= 2; 4227afc7756SAlex Wilson inputs = new media_input[inputCount]; 4237afc7756SAlex Wilson inputDeleter.SetTo(inputs); 4247afc7756SAlex Wilson } else { 4257afc7756SAlex Wilson inputCount = realInputCount; 4267afc7756SAlex Wilson break; 4277afc7756SAlex Wilson } 4287afc7756SAlex Wilson } 4297afc7756SAlex Wilson 4307afc7756SAlex Wilson if (err == B_OK) { 4317afc7756SAlex Wilson BMessage message(ML_DEFAULT_CHANNEL_CHANGED); 4327afc7756SAlex Wilson 4337afc7756SAlex Wilson for (int32 i = 0; i < inputCount; i++) { 4347afc7756SAlex Wilson media_input* input = new media_input(); 4357afc7756SAlex Wilson memcpy(input, &inputs[i], sizeof(*input)); 4367afc7756SAlex Wilson ChannelMenuItem* channelItem = new ChannelMenuItem(input, 4377afc7756SAlex Wilson new BMessage(message)); 4387afc7756SAlex Wilson fChannelMenu->AddItem(channelItem); 4397afc7756SAlex Wilson 4407afc7756SAlex Wilson if (channelItem->DestinationID() == 0) 4417afc7756SAlex Wilson channelItem->SetMarked(true); 4427afc7756SAlex Wilson } 4437afc7756SAlex Wilson } 4447afc7756SAlex Wilson } 4457afc7756SAlex Wilson 4467afc7756SAlex Wilson if (Window()) 4477afc7756SAlex Wilson fChannelMenu->SetTargetForItems(BMessenger(this)); 4487afc7756SAlex Wilson } 4497afc7756SAlex Wilson 4507afc7756SAlex Wilson 4517afc7756SAlex Wilson void 4527afc7756SAlex Wilson AudioSettingsView::_ShowDeskbarVolumeControl() 4537afc7756SAlex Wilson { 4547afc7756SAlex Wilson BDeskbar deskbar; 4557afc7756SAlex Wilson BEntry entry("/bin/desklink", true); 4567afc7756SAlex Wilson int32 id; 4577afc7756SAlex Wilson entry_ref ref; 4587afc7756SAlex Wilson status_t status = entry.GetRef(&ref); 4597afc7756SAlex Wilson if (status == B_OK) 4607afc7756SAlex Wilson status = deskbar.AddItem(&ref, &id); 4617afc7756SAlex Wilson 4627afc7756SAlex Wilson if (status != B_OK) { 4637afc7756SAlex Wilson fprintf(stderr, B_TRANSLATE( 4647afc7756SAlex Wilson "Couldn't add volume control in Deskbar: %s\n"), 4657afc7756SAlex Wilson strerror(status)); 4667afc7756SAlex Wilson } 4677afc7756SAlex Wilson } 4687afc7756SAlex Wilson 4697afc7756SAlex Wilson 4707afc7756SAlex Wilson void 4717afc7756SAlex Wilson AudioSettingsView::_HideDeskbarVolumeControl() 4727afc7756SAlex Wilson { 4737afc7756SAlex Wilson BDeskbar deskbar; 4747afc7756SAlex Wilson status_t status = deskbar.RemoveItem("MediaReplicant"); 4757afc7756SAlex Wilson if (status != B_OK) { 4767afc7756SAlex Wilson fprintf(stderr, B_TRANSLATE( 4777afc7756SAlex Wilson "Couldn't remove volume control in Deskbar: %s\n"), 4787afc7756SAlex Wilson strerror(status)); 4797afc7756SAlex Wilson } 4807afc7756SAlex Wilson } 4817afc7756SAlex Wilson 4827afc7756SAlex Wilson 4837afc7756SAlex Wilson ChannelMenuItem* 4847afc7756SAlex Wilson AudioSettingsView::_ChannelMenuItemAt(int32 index) 4857afc7756SAlex Wilson { 4867afc7756SAlex Wilson return static_cast<ChannelMenuItem*>(fChannelMenu->ItemAt(index)); 4877afc7756SAlex Wilson } 4887afc7756SAlex Wilson 4897afc7756SAlex Wilson 4907afc7756SAlex Wilson VideoSettingsView::VideoSettingsView() 4917afc7756SAlex Wilson { 4927afc7756SAlex Wilson BBox* defaultsBox = new BBox("defaults"); 4937afc7756SAlex Wilson defaultsBox->SetLabel(B_TRANSLATE("Defaults")); 4947afc7756SAlex Wilson BGridView* defaultsGridView = new BGridView(); 4957afc7756SAlex Wilson 4967afc7756SAlex Wilson BMenuField* inputMenuField = new BMenuField("inputMenuField", 49710dfe897SAxel Dörfler B_TRANSLATE("Video input:"), InputMenu()); 4987afc7756SAlex Wilson 4997afc7756SAlex Wilson BMenuField* outputMenuField = new BMenuField("outputMenuField", 50010dfe897SAxel Dörfler B_TRANSLATE("Video output:"), OutputMenu()); 5017afc7756SAlex Wilson 5027afc7756SAlex Wilson BLayoutBuilder::Grid<>(defaultsGridView) 503c97121d3SAlex Wilson .SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING, 504c97121d3SAlex Wilson B_USE_DEFAULT_SPACING) 5057afc7756SAlex Wilson .AddMenuField(inputMenuField, 0, 0) 506c97121d3SAlex Wilson .AddMenuField(outputMenuField, 0, 1); 5077afc7756SAlex Wilson 5087afc7756SAlex Wilson defaultsBox->AddChild(defaultsGridView); 5097afc7756SAlex Wilson 510c97121d3SAlex Wilson BLayoutBuilder::Group<>(this) 5117afc7756SAlex Wilson .SetInsets(0, 0, 0, 0) 512c97121d3SAlex Wilson .Add(defaultsBox) 513c97121d3SAlex Wilson .AddGroup(B_HORIZONTAL) 514c97121d3SAlex Wilson .AddGlue() 515c97121d3SAlex Wilson .Add(MakeRestartButton()) 516c97121d3SAlex Wilson .End() 517c97121d3SAlex Wilson .AddGlue(); 5187afc7756SAlex Wilson } 5197afc7756SAlex Wilson 5207afc7756SAlex Wilson 5217afc7756SAlex Wilson void 5227afc7756SAlex Wilson VideoSettingsView::SetDefaultInput(const dormant_node_info* info) 5237afc7756SAlex Wilson { 5247afc7756SAlex Wilson SettingsView::SetDefaultInput(info); 5257afc7756SAlex Wilson _MediaWindow()->UpdateInputListItem(MediaListItem::VIDEO_TYPE, info); 5267afc7756SAlex Wilson BMediaRoster::Roster()->SetVideoInput(*info); 5277afc7756SAlex Wilson } 5287afc7756SAlex Wilson 5297afc7756SAlex Wilson 5307afc7756SAlex Wilson void 5317afc7756SAlex Wilson VideoSettingsView::SetDefaultOutput(const dormant_node_info* info) 5327afc7756SAlex Wilson { 5337afc7756SAlex Wilson SettingsView::SetDefaultOutput(info); 5347afc7756SAlex Wilson _MediaWindow()->UpdateOutputListItem(MediaListItem::VIDEO_TYPE, info); 5357afc7756SAlex Wilson BMediaRoster::Roster()->SetVideoOutput(*info); 5367afc7756SAlex Wilson } 537