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 516e62e744SAlex Wilson fInputMenu = new BPopUpMenu(B_TRANSLATE("<none>")); 526e62e744SAlex Wilson fInputMenu->SetLabelFromMarked(true); 536e62e744SAlex Wilson 547afc7756SAlex Wilson // input menu 556e62e744SAlex Wilson fOutputMenu = new BPopUpMenu(B_TRANSLATE("<none>")); 566e62e744SAlex Wilson fOutputMenu->SetLabelFromMarked(true); 576e62e744SAlex Wilson } 586e62e744SAlex Wilson 592af5f895SStephan Aßmus 607afc7756SAlex Wilson BButton* 617afc7756SAlex Wilson SettingsView::MakeRestartButton() 627afc7756SAlex Wilson { 637afc7756SAlex Wilson return new BButton("restartButton", 64176fb40fSMatt Madia B_TRANSLATE("Restart media services"), 65*939b40d6SJessica Hamilton new BMessage(ML_RESTART_MEDIA_SERVER)); 66a10cf76eSAxel Dörfler } 672af5f895SStephan Aßmus 682af5f895SStephan Aßmus 697afc7756SAlex Wilson 707afc7756SAlex Wilson void 717afc7756SAlex Wilson SettingsView::AddInputNodes(NodeList& list) 727afc7756SAlex Wilson { 737afc7756SAlex Wilson _EmptyMenu(fInputMenu); 747afc7756SAlex Wilson 757afc7756SAlex Wilson BMessage message(MEDIA_DEFAULT_INPUT_CHANGE); 767afc7756SAlex Wilson _PopulateMenu(fInputMenu, list, message); 77a10cf76eSAxel Dörfler } 78a10cf76eSAxel Dörfler 79a633251fSAlex Wilson 80a10cf76eSAxel Dörfler void 817afc7756SAlex Wilson SettingsView::AddOutputNodes(NodeList& list) 82a10cf76eSAxel Dörfler { 837afc7756SAlex Wilson _EmptyMenu(fOutputMenu); 846e62e744SAlex Wilson 857afc7756SAlex Wilson BMessage message(MEDIA_DEFAULT_OUTPUT_CHANGE); 867afc7756SAlex Wilson _PopulateMenu(fOutputMenu, list, message); 87a10cf76eSAxel Dörfler } 88a10cf76eSAxel Dörfler 89a633251fSAlex Wilson 90a10cf76eSAxel Dörfler void 917afc7756SAlex Wilson SettingsView::SetDefaultInput(const dormant_node_info* info) 92a10cf76eSAxel Dörfler { 937afc7756SAlex Wilson _ClearMenuSelection(fInputMenu); 947afc7756SAlex Wilson NodeMenuItem* item = _FindNodeItem(fInputMenu, info); 957afc7756SAlex Wilson if (item) 96a10cf76eSAxel Dörfler item->SetMarked(true); 977afc7756SAlex Wilson } 987afc7756SAlex Wilson 997afc7756SAlex Wilson 1007afc7756SAlex Wilson void 1017afc7756SAlex Wilson SettingsView::SetDefaultOutput(const dormant_node_info* info) 1027afc7756SAlex Wilson { 1037afc7756SAlex Wilson _ClearMenuSelection(fOutputMenu); 1047afc7756SAlex Wilson NodeMenuItem* item = _FindNodeItem(fOutputMenu, info); 1057afc7756SAlex Wilson if (item) 1067afc7756SAlex Wilson item->SetMarked(true); 1077afc7756SAlex Wilson } 1087afc7756SAlex Wilson 1097afc7756SAlex Wilson 1107afc7756SAlex Wilson void 1117afc7756SAlex Wilson SettingsView::MessageReceived(BMessage* message) 1127afc7756SAlex Wilson { 1137afc7756SAlex Wilson switch (message->what) { 1147afc7756SAlex Wilson case MEDIA_DEFAULT_INPUT_CHANGE: 1157afc7756SAlex Wilson { 1167afc7756SAlex Wilson int32 index; 1177afc7756SAlex Wilson if (message->FindInt32("index", &index)!=B_OK) 1187afc7756SAlex Wilson break; 1197afc7756SAlex Wilson NodeMenuItem* item 1207afc7756SAlex Wilson = static_cast<NodeMenuItem*>(fInputMenu->ItemAt(index)); 1217afc7756SAlex Wilson SetDefaultInput(item->NodeInfo()); 122d2772fb4SAlex Wilson break; 1237afc7756SAlex Wilson } 1247afc7756SAlex Wilson case MEDIA_DEFAULT_OUTPUT_CHANGE: 1257afc7756SAlex Wilson { 1267afc7756SAlex Wilson int32 index; 1277afc7756SAlex Wilson if (message->FindInt32("index", &index)!=B_OK) 1287afc7756SAlex Wilson break; 1297afc7756SAlex Wilson NodeMenuItem* item 1307afc7756SAlex Wilson = static_cast<NodeMenuItem*>(fOutputMenu->ItemAt(index)); 1317afc7756SAlex Wilson SetDefaultOutput(item->NodeInfo()); 132a10cf76eSAxel Dörfler break; 133a10cf76eSAxel Dörfler } 134d2772fb4SAlex Wilson default: 135c97121d3SAlex Wilson BGroupView::MessageReceived(message); 1367afc7756SAlex Wilson } 137d2772fb4SAlex Wilson } 138a10cf76eSAxel Dörfler 139a633251fSAlex Wilson 1407afc7756SAlex Wilson void 1417afc7756SAlex Wilson SettingsView::AttachedToWindow() 1427afc7756SAlex Wilson { 1437afc7756SAlex Wilson BMessenger thisMessenger(this); 1447afc7756SAlex Wilson fInputMenu->SetTargetForItems(thisMessenger); 1457afc7756SAlex Wilson fOutputMenu->SetTargetForItems(thisMessenger); 1467afc7756SAlex Wilson } 1477afc7756SAlex Wilson 1487afc7756SAlex Wilson 1497afc7756SAlex Wilson MediaWindow* 1507afc7756SAlex Wilson SettingsView::_MediaWindow() const 1517afc7756SAlex Wilson { 1527afc7756SAlex Wilson return static_cast<MediaWindow*>(Window()); 1537afc7756SAlex Wilson } 1547afc7756SAlex Wilson 1557afc7756SAlex Wilson 1567afc7756SAlex Wilson void 1577afc7756SAlex Wilson SettingsView::_EmptyMenu(BMenu* menu) 1587afc7756SAlex Wilson { 1597afc7756SAlex Wilson while (menu->CountItems() > 0) 1607afc7756SAlex Wilson delete menu->RemoveItem((int32)0); 1617afc7756SAlex Wilson } 1627afc7756SAlex Wilson 1637afc7756SAlex Wilson 1647afc7756SAlex Wilson void 1657afc7756SAlex Wilson SettingsView::_PopulateMenu(BMenu* menu, NodeList& nodes, 1667afc7756SAlex Wilson const BMessage& message) 1677afc7756SAlex Wilson { 1687afc7756SAlex Wilson for (int32 i = 0; i < nodes.CountItems(); i++) { 1697afc7756SAlex Wilson dormant_node_info* info = nodes.ItemAt(i); 1707afc7756SAlex Wilson menu->AddItem(new NodeMenuItem(info, new BMessage(message))); 1717afc7756SAlex Wilson } 1727afc7756SAlex Wilson 1737afc7756SAlex Wilson if (Window() != NULL) 1747afc7756SAlex Wilson menu->SetTargetForItems(BMessenger(this)); 1757afc7756SAlex Wilson } 1767afc7756SAlex Wilson 1777afc7756SAlex Wilson 1787afc7756SAlex Wilson NodeMenuItem* 1797afc7756SAlex Wilson SettingsView::_FindNodeItem(BMenu* menu, const dormant_node_info* nodeInfo) 1807afc7756SAlex Wilson { 1817afc7756SAlex Wilson for (int32 i = 0; i < menu->CountItems(); i++) { 1827afc7756SAlex Wilson NodeMenuItem* item = static_cast<NodeMenuItem*>(menu->ItemAt(i)); 1837afc7756SAlex Wilson const dormant_node_info* itemInfo = item->NodeInfo(); 1847afc7756SAlex Wilson if (itemInfo && itemInfo->addon == nodeInfo->addon 1857afc7756SAlex Wilson && itemInfo->flavor_id == nodeInfo->flavor_id) { 1867afc7756SAlex Wilson return item; 187a10cf76eSAxel Dörfler } 188a10cf76eSAxel Dörfler } 1897afc7756SAlex Wilson return NULL; 190a10cf76eSAxel Dörfler } 1917afc7756SAlex Wilson 1927afc7756SAlex Wilson 1937afc7756SAlex Wilson void 1947afc7756SAlex Wilson SettingsView::_ClearMenuSelection(BMenu* menu) 1957afc7756SAlex Wilson { 1967afc7756SAlex Wilson for (int32 i = 0; i < menu->CountItems(); i++) { 1977afc7756SAlex Wilson BMenuItem* item = menu->ItemAt(i); 1987afc7756SAlex Wilson item->SetMarked(false); 199a10cf76eSAxel Dörfler } 200a10cf76eSAxel Dörfler } 201a10cf76eSAxel Dörfler 202a633251fSAlex Wilson 2037afc7756SAlex Wilson NodeMenuItem::NodeMenuItem(const dormant_node_info* info, BMessage* message, 204a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 205a633251fSAlex Wilson : 206a633251fSAlex Wilson BMenuItem(info->name, message, shortcut, modifiers), 207b4a12470SJérôme Duval fInfo(info) 208a10cf76eSAxel Dörfler { 209a10cf76eSAxel Dörfler 210a10cf76eSAxel Dörfler } 211a10cf76eSAxel Dörfler 2126df0b2d5SJérôme Duval 2136df0b2d5SJérôme Duval status_t 2147afc7756SAlex Wilson NodeMenuItem::Invoke(BMessage* message) 2156df0b2d5SJérôme Duval { 2166df0b2d5SJérôme Duval if (IsMarked()) 2176df0b2d5SJérôme Duval return B_OK; 2186df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2196df0b2d5SJérôme Duval } 2206df0b2d5SJérôme Duval 2216df0b2d5SJérôme Duval 2227afc7756SAlex Wilson ChannelMenuItem::ChannelMenuItem(media_input* input, BMessage* message, 2237afc7756SAlex Wilson char shortcut, uint32 modifiers) 224a633251fSAlex Wilson : 225a633251fSAlex Wilson BMenuItem(input->name, message, shortcut, modifiers), 226b4a12470SJérôme Duval fInput(input) 227a10cf76eSAxel Dörfler { 228a10cf76eSAxel Dörfler } 229a10cf76eSAxel Dörfler 2306df0b2d5SJérôme Duval 2317afc7756SAlex Wilson ChannelMenuItem::~ChannelMenuItem() 232a10cf76eSAxel Dörfler { 233b4a12470SJérôme Duval delete fInput; 234a10cf76eSAxel Dörfler } 235a10cf76eSAxel Dörfler 2366df0b2d5SJérôme Duval 2377afc7756SAlex Wilson int32 2387afc7756SAlex Wilson ChannelMenuItem::DestinationID() 2397afc7756SAlex Wilson { 2407afc7756SAlex Wilson return fInput->destination.id; 2417afc7756SAlex Wilson } 2427afc7756SAlex Wilson 2437afc7756SAlex Wilson 2447afc7756SAlex Wilson media_input* 2457afc7756SAlex Wilson ChannelMenuItem::Input() 2467afc7756SAlex Wilson { 2477afc7756SAlex Wilson return fInput; 2487afc7756SAlex Wilson } 2497afc7756SAlex Wilson 2507afc7756SAlex Wilson 2516df0b2d5SJérôme Duval status_t 2527afc7756SAlex Wilson ChannelMenuItem::Invoke(BMessage* message) 2536df0b2d5SJérôme Duval { 2546df0b2d5SJérôme Duval if (IsMarked()) 2556df0b2d5SJérôme Duval return B_OK; 2566df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2576df0b2d5SJérôme Duval } 2586df0b2d5SJérôme Duval 2597afc7756SAlex Wilson 2607afc7756SAlex Wilson AudioSettingsView::AudioSettingsView() 2617afc7756SAlex Wilson { 2627afc7756SAlex Wilson BBox* defaultsBox = new BBox("defaults"); 2637afc7756SAlex Wilson defaultsBox->SetLabel(B_TRANSLATE("Defaults")); 2647afc7756SAlex Wilson BGridView* defaultsGridView = new BGridView(); 2657afc7756SAlex Wilson 2667afc7756SAlex Wilson BMenuField* inputMenuField = new BMenuField("inputMenuField", 26710dfe897SAxel Dörfler B_TRANSLATE("Audio input:"), InputMenu()); 2687afc7756SAlex Wilson 2697afc7756SAlex Wilson BMenuField* outputMenuField = new BMenuField("outputMenuField", 27010dfe897SAxel Dörfler B_TRANSLATE("Audio output:"), OutputMenu()); 2717afc7756SAlex Wilson 2727afc7756SAlex Wilson BLayoutBuilder::Grid<>(defaultsGridView) 273c97121d3SAlex Wilson .SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING, 274c97121d3SAlex Wilson B_USE_DEFAULT_SPACING) 2757afc7756SAlex Wilson .AddMenuField(inputMenuField, 0, 0, B_ALIGN_HORIZONTAL_UNSET, 1, 3, 1) 2767afc7756SAlex Wilson .AddMenuField(outputMenuField, 0, 1) 277c97121d3SAlex Wilson .AddMenuField(_MakeChannelMenu(), 2, 1); 2787afc7756SAlex Wilson 2797afc7756SAlex Wilson defaultsBox->AddChild(defaultsGridView); 2807afc7756SAlex Wilson 281c97121d3SAlex Wilson BLayoutBuilder::Group<>(this) 2827afc7756SAlex Wilson .SetInsets(0, 0, 0, 0) 283c97121d3SAlex Wilson .Add(defaultsBox) 284c97121d3SAlex Wilson .AddGroup(B_HORIZONTAL) 285c97121d3SAlex Wilson .Add(_MakeVolumeCheckBox()) 2868a28f849SDario Casalinuovo .AddGlue() 287c97121d3SAlex Wilson .Add(MakeRestartButton()) 288c97121d3SAlex Wilson .End() 289c97121d3SAlex Wilson .AddGlue(); 2907afc7756SAlex Wilson } 2917afc7756SAlex Wilson 2927afc7756SAlex Wilson 2937afc7756SAlex Wilson void 2947afc7756SAlex Wilson AudioSettingsView::SetDefaultChannel(int32 channelID) 2957afc7756SAlex Wilson { 2967afc7756SAlex Wilson for (int32 i = 0; i < fChannelMenu->CountItems(); i++) { 2977afc7756SAlex Wilson ChannelMenuItem* item = _ChannelMenuItemAt(i); 2987afc7756SAlex Wilson item->SetMarked(item->DestinationID() == channelID); 2997afc7756SAlex Wilson } 3007afc7756SAlex Wilson } 3017afc7756SAlex Wilson 3027afc7756SAlex Wilson 3037afc7756SAlex Wilson void 3047afc7756SAlex Wilson AudioSettingsView::AttachedToWindow() 3057afc7756SAlex Wilson { 3067afc7756SAlex Wilson SettingsView::AttachedToWindow(); 3077afc7756SAlex Wilson 3087afc7756SAlex Wilson BMessenger thisMessenger(this); 3097afc7756SAlex Wilson fChannelMenu->SetTargetForItems(thisMessenger); 3107afc7756SAlex Wilson fVolumeCheckBox->SetTarget(thisMessenger); 3117afc7756SAlex Wilson } 3127afc7756SAlex Wilson 3137afc7756SAlex Wilson 3147afc7756SAlex Wilson void 3157afc7756SAlex Wilson AudioSettingsView::MessageReceived(BMessage* message) 3167afc7756SAlex Wilson { 3177afc7756SAlex Wilson switch (message->what) { 3187afc7756SAlex Wilson case ML_DEFAULT_CHANNEL_CHANGED: 3197afc7756SAlex Wilson { 3207afc7756SAlex Wilson int32 index; 3217afc7756SAlex Wilson if (message->FindInt32("index", &index) != B_OK) 3227afc7756SAlex Wilson break; 3237afc7756SAlex Wilson ChannelMenuItem* item = _ChannelMenuItemAt(index); 3247afc7756SAlex Wilson 3257afc7756SAlex Wilson if (item) { 3267afc7756SAlex Wilson BMediaRoster* roster = BMediaRoster::Roster(); 3277afc7756SAlex Wilson roster->SetAudioOutput(*item->Input()); 3287afc7756SAlex Wilson } else 3297afc7756SAlex Wilson fprintf(stderr, "ChannelMenuItem not found\n"); 3307afc7756SAlex Wilson } 3317afc7756SAlex Wilson break; 3327afc7756SAlex Wilson case MEDIA_SHOW_HIDE_VOLUME_CONTROL: 3337afc7756SAlex Wilson { 3347afc7756SAlex Wilson if (fVolumeCheckBox->Value() == B_CONTROL_ON) 3357afc7756SAlex Wilson _ShowDeskbarVolumeControl(); 3367afc7756SAlex Wilson else 3377afc7756SAlex Wilson _HideDeskbarVolumeControl(); 3387afc7756SAlex Wilson break; 3397afc7756SAlex Wilson } 3407afc7756SAlex Wilson 3417afc7756SAlex Wilson default: 3427afc7756SAlex Wilson SettingsView::MessageReceived(message); 3437afc7756SAlex Wilson } 3447afc7756SAlex Wilson } 3457afc7756SAlex Wilson 3467afc7756SAlex Wilson 3477afc7756SAlex Wilson void 3487afc7756SAlex Wilson AudioSettingsView::SetDefaultInput(const dormant_node_info* info) 3497afc7756SAlex Wilson { 3507afc7756SAlex Wilson SettingsView::SetDefaultInput(info); 3517afc7756SAlex Wilson _MediaWindow()->UpdateInputListItem(MediaListItem::AUDIO_TYPE, info); 3527afc7756SAlex Wilson BMediaRoster::Roster()->SetAudioInput(*info); 3537afc7756SAlex Wilson } 3547afc7756SAlex Wilson 3557afc7756SAlex Wilson 3567afc7756SAlex Wilson void 3577afc7756SAlex Wilson AudioSettingsView::SetDefaultOutput(const dormant_node_info* info) 3587afc7756SAlex Wilson { 3597afc7756SAlex Wilson SettingsView::SetDefaultOutput(info); 3607afc7756SAlex Wilson _MediaWindow()->UpdateOutputListItem(MediaListItem::AUDIO_TYPE, info); 3617afc7756SAlex Wilson _FillChannelMenu(info); 3627afc7756SAlex Wilson BMediaRoster::Roster()->SetAudioOutput(*info); 3637afc7756SAlex Wilson } 3647afc7756SAlex Wilson 3657afc7756SAlex Wilson 3667afc7756SAlex Wilson BMenuField* 3677afc7756SAlex Wilson AudioSettingsView::_MakeChannelMenu() 3687afc7756SAlex Wilson { 3697afc7756SAlex Wilson fChannelMenu = new BPopUpMenu(B_TRANSLATE("<none>")); 3707afc7756SAlex Wilson fChannelMenu->SetLabelFromMarked(true); 3717afc7756SAlex Wilson BMenuField* channelMenuField = new BMenuField("channelMenuField", 37210dfe897SAxel Dörfler B_TRANSLATE("Channel:"), fChannelMenu); 3737afc7756SAlex Wilson return channelMenuField; 3747afc7756SAlex Wilson } 3757afc7756SAlex Wilson 3767afc7756SAlex Wilson 3777afc7756SAlex Wilson BCheckBox* 3787afc7756SAlex Wilson AudioSettingsView::_MakeVolumeCheckBox() 3797afc7756SAlex Wilson { 3807afc7756SAlex Wilson fVolumeCheckBox = new BCheckBox("volumeCheckBox", 3817afc7756SAlex Wilson B_TRANSLATE("Show volume control on Deskbar"), 3827afc7756SAlex Wilson new BMessage(MEDIA_SHOW_HIDE_VOLUME_CONTROL)); 3837afc7756SAlex Wilson 3847afc7756SAlex Wilson if (BDeskbar().HasItem("MediaReplicant")) 3857afc7756SAlex Wilson fVolumeCheckBox->SetValue(B_CONTROL_ON); 3867afc7756SAlex Wilson 3877afc7756SAlex Wilson return fVolumeCheckBox; 3887afc7756SAlex Wilson } 3897afc7756SAlex Wilson 3907afc7756SAlex Wilson 3917afc7756SAlex Wilson void 3927afc7756SAlex Wilson AudioSettingsView::_FillChannelMenu(const dormant_node_info* nodeInfo) 3937afc7756SAlex Wilson { 3947afc7756SAlex Wilson _EmptyMenu(fChannelMenu); 3957afc7756SAlex Wilson 3967afc7756SAlex Wilson BMediaRoster* roster = BMediaRoster::Roster(); 3977afc7756SAlex Wilson media_node node; 3987afc7756SAlex Wilson media_node_id node_id; 3997afc7756SAlex Wilson 4007afc7756SAlex Wilson status_t err = roster->GetInstancesFor(nodeInfo->addon, 4017afc7756SAlex Wilson nodeInfo->flavor_id, &node_id); 4027afc7756SAlex Wilson if (err != B_OK) { 4037afc7756SAlex Wilson err = roster->InstantiateDormantNode(*nodeInfo, &node, 4047afc7756SAlex Wilson B_FLAVOR_IS_GLOBAL); 4057afc7756SAlex Wilson } else { 4067afc7756SAlex Wilson err = roster->GetNodeFor(node_id, &node); 4077afc7756SAlex Wilson } 4087afc7756SAlex Wilson 4097afc7756SAlex Wilson if (err == B_OK) { 4107afc7756SAlex Wilson int32 inputCount = 4; 4117afc7756SAlex Wilson media_input* inputs = new media_input[inputCount]; 4127afc7756SAlex Wilson BPrivate::ArrayDeleter<media_input> inputDeleter(inputs); 4137afc7756SAlex Wilson 4147afc7756SAlex Wilson while (true) { 4157afc7756SAlex Wilson int32 realInputCount = 0; 4167afc7756SAlex Wilson err = roster->GetAllInputsFor(node, inputs, 4177afc7756SAlex Wilson inputCount, &realInputCount); 4187afc7756SAlex Wilson if (realInputCount > inputCount) { 4197afc7756SAlex Wilson inputCount *= 2; 4207afc7756SAlex Wilson inputs = new media_input[inputCount]; 4217afc7756SAlex Wilson inputDeleter.SetTo(inputs); 4227afc7756SAlex Wilson } else { 4237afc7756SAlex Wilson inputCount = realInputCount; 4247afc7756SAlex Wilson break; 4257afc7756SAlex Wilson } 4267afc7756SAlex Wilson } 4277afc7756SAlex Wilson 4287afc7756SAlex Wilson if (err == B_OK) { 4297afc7756SAlex Wilson BMessage message(ML_DEFAULT_CHANNEL_CHANGED); 4307afc7756SAlex Wilson 4317afc7756SAlex Wilson for (int32 i = 0; i < inputCount; i++) { 4327afc7756SAlex Wilson media_input* input = new media_input(); 4337afc7756SAlex Wilson memcpy(input, &inputs[i], sizeof(*input)); 4347afc7756SAlex Wilson ChannelMenuItem* channelItem = new ChannelMenuItem(input, 4357afc7756SAlex Wilson new BMessage(message)); 4367afc7756SAlex Wilson fChannelMenu->AddItem(channelItem); 4377afc7756SAlex Wilson 4387afc7756SAlex Wilson if (channelItem->DestinationID() == 0) 4397afc7756SAlex Wilson channelItem->SetMarked(true); 4407afc7756SAlex Wilson } 4417afc7756SAlex Wilson } 4427afc7756SAlex Wilson } 4437afc7756SAlex Wilson 4447afc7756SAlex Wilson if (Window()) 4457afc7756SAlex Wilson fChannelMenu->SetTargetForItems(BMessenger(this)); 4467afc7756SAlex Wilson } 4477afc7756SAlex Wilson 4487afc7756SAlex Wilson 4497afc7756SAlex Wilson void 4507afc7756SAlex Wilson AudioSettingsView::_ShowDeskbarVolumeControl() 4517afc7756SAlex Wilson { 4527afc7756SAlex Wilson BDeskbar deskbar; 4537afc7756SAlex Wilson BEntry entry("/bin/desklink", true); 4547afc7756SAlex Wilson int32 id; 4557afc7756SAlex Wilson entry_ref ref; 4567afc7756SAlex Wilson status_t status = entry.GetRef(&ref); 4577afc7756SAlex Wilson if (status == B_OK) 4587afc7756SAlex Wilson status = deskbar.AddItem(&ref, &id); 4597afc7756SAlex Wilson 4607afc7756SAlex Wilson if (status != B_OK) { 4617afc7756SAlex Wilson fprintf(stderr, B_TRANSLATE( 4627afc7756SAlex Wilson "Couldn't add volume control in Deskbar: %s\n"), 4637afc7756SAlex Wilson strerror(status)); 4647afc7756SAlex Wilson } 4657afc7756SAlex Wilson } 4667afc7756SAlex Wilson 4677afc7756SAlex Wilson 4687afc7756SAlex Wilson void 4697afc7756SAlex Wilson AudioSettingsView::_HideDeskbarVolumeControl() 4707afc7756SAlex Wilson { 4717afc7756SAlex Wilson BDeskbar deskbar; 4727afc7756SAlex Wilson status_t status = deskbar.RemoveItem("MediaReplicant"); 4737afc7756SAlex Wilson if (status != B_OK) { 4747afc7756SAlex Wilson fprintf(stderr, B_TRANSLATE( 4757afc7756SAlex Wilson "Couldn't remove volume control in Deskbar: %s\n"), 4767afc7756SAlex Wilson strerror(status)); 4777afc7756SAlex Wilson } 4787afc7756SAlex Wilson } 4797afc7756SAlex Wilson 4807afc7756SAlex Wilson 4817afc7756SAlex Wilson ChannelMenuItem* 4827afc7756SAlex Wilson AudioSettingsView::_ChannelMenuItemAt(int32 index) 4837afc7756SAlex Wilson { 4847afc7756SAlex Wilson return static_cast<ChannelMenuItem*>(fChannelMenu->ItemAt(index)); 4857afc7756SAlex Wilson } 4867afc7756SAlex Wilson 4877afc7756SAlex Wilson 4887afc7756SAlex Wilson VideoSettingsView::VideoSettingsView() 4897afc7756SAlex Wilson { 4907afc7756SAlex Wilson BBox* defaultsBox = new BBox("defaults"); 4917afc7756SAlex Wilson defaultsBox->SetLabel(B_TRANSLATE("Defaults")); 4927afc7756SAlex Wilson BGridView* defaultsGridView = new BGridView(); 4937afc7756SAlex Wilson 4947afc7756SAlex Wilson BMenuField* inputMenuField = new BMenuField("inputMenuField", 49510dfe897SAxel Dörfler B_TRANSLATE("Video input:"), InputMenu()); 4967afc7756SAlex Wilson 4977afc7756SAlex Wilson BMenuField* outputMenuField = new BMenuField("outputMenuField", 49810dfe897SAxel Dörfler B_TRANSLATE("Video output:"), OutputMenu()); 4997afc7756SAlex Wilson 5007afc7756SAlex Wilson BLayoutBuilder::Grid<>(defaultsGridView) 501c97121d3SAlex Wilson .SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING, 502c97121d3SAlex Wilson B_USE_DEFAULT_SPACING) 5037afc7756SAlex Wilson .AddMenuField(inputMenuField, 0, 0) 504c97121d3SAlex Wilson .AddMenuField(outputMenuField, 0, 1); 5057afc7756SAlex Wilson 5067afc7756SAlex Wilson defaultsBox->AddChild(defaultsGridView); 5077afc7756SAlex Wilson 508c97121d3SAlex Wilson BLayoutBuilder::Group<>(this) 5097afc7756SAlex Wilson .SetInsets(0, 0, 0, 0) 510c97121d3SAlex Wilson .Add(defaultsBox) 511c97121d3SAlex Wilson .AddGroup(B_HORIZONTAL) 512c97121d3SAlex Wilson .AddGlue() 513c97121d3SAlex Wilson .Add(MakeRestartButton()) 514c97121d3SAlex Wilson .End() 515c97121d3SAlex Wilson .AddGlue(); 5167afc7756SAlex Wilson } 5177afc7756SAlex Wilson 5187afc7756SAlex Wilson 5197afc7756SAlex Wilson void 5207afc7756SAlex Wilson VideoSettingsView::SetDefaultInput(const dormant_node_info* info) 5217afc7756SAlex Wilson { 5227afc7756SAlex Wilson SettingsView::SetDefaultInput(info); 5237afc7756SAlex Wilson _MediaWindow()->UpdateInputListItem(MediaListItem::VIDEO_TYPE, info); 5247afc7756SAlex Wilson BMediaRoster::Roster()->SetVideoInput(*info); 5257afc7756SAlex Wilson } 5267afc7756SAlex Wilson 5277afc7756SAlex Wilson 5287afc7756SAlex Wilson void 5297afc7756SAlex Wilson VideoSettingsView::SetDefaultOutput(const dormant_node_info* info) 5307afc7756SAlex Wilson { 5317afc7756SAlex Wilson SettingsView::SetDefaultOutput(info); 5327afc7756SAlex Wilson _MediaWindow()->UpdateOutputListItem(MediaListItem::VIDEO_TYPE, info); 5337afc7756SAlex Wilson BMediaRoster::Roster()->SetVideoOutput(*info); 5347afc7756SAlex Wilson } 535