1a10cf76eSAxel Dörfler // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 2a10cf76eSAxel Dörfler // 3a10cf76eSAxel Dörfler // Copyright (c) 2003, OpenBeOS 4a10cf76eSAxel Dörfler // 5a10cf76eSAxel Dörfler // This software is part of the OpenBeOS distribution and is covered 6a10cf76eSAxel Dörfler // by the OpenBeOS license. 7a10cf76eSAxel Dörfler // 8a10cf76eSAxel Dörfler // 9a10cf76eSAxel Dörfler // File: MediaViews.cpp 10a10cf76eSAxel Dörfler // Author: Sikosis, Jérôme Duval 11a10cf76eSAxel Dörfler // Description: Media Preferences 12a10cf76eSAxel Dörfler // Created : June 25, 2003 13a10cf76eSAxel Dörfler // 14a10cf76eSAxel Dörfler // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 15a633251fSAlex Wilson #include "MediaViews.h" 16f8a1135cSAdrien Destugues 177afc7756SAlex Wilson #include <AutoDeleter.h> 18a10cf76eSAxel Dörfler #include <Box.h> 19a10cf76eSAxel Dörfler #include <Button.h> 20f8a1135cSAdrien Destugues #include <Catalog.h> 217afc7756SAlex Wilson #include <CheckBox.h> 22a10cf76eSAxel Dörfler #include <Deskbar.h> 23a10cf76eSAxel Dörfler #include <Entry.h> 247afc7756SAlex Wilson #include <LayoutBuilder.h> 25f8a1135cSAdrien Destugues #include <Locale.h> 26a10cf76eSAxel Dörfler #include <MediaAddOn.h> 27f8a1135cSAdrien Destugues #include <MediaRoster.h> 28f8a1135cSAdrien Destugues #include <MenuField.h> 29f8a1135cSAdrien Destugues #include <PopUpMenu.h> 30a10cf76eSAxel Dörfler #include <String.h> 317afc7756SAlex Wilson #include <StringView.h> 32b4a12470SJérôme Duval #include <TextView.h> 332af5f895SStephan Aßmus 347afc7756SAlex Wilson #include <assert.h> 35a633251fSAlex Wilson #include <stdio.h> 36a10cf76eSAxel Dörfler 377afc7756SAlex Wilson #include "MediaWindow.h" 387afc7756SAlex Wilson 399cedafe6SWim van der Meer 409cedafe6SWim van der Meer #undef B_TRANSLATE_CONTEXT 414eb0cbb0SMatt Madia #define B_TRANSLATE_CONTEXT "Media views" 42f8a1135cSAdrien Destugues 437afc7756SAlex Wilson #define MEDIA_DEFAULT_INPUT_CHANGE 'dich' 447afc7756SAlex Wilson #define MEDIA_DEFAULT_OUTPUT_CHANGE 'doch' 457afc7756SAlex Wilson #define MEDIA_SHOW_HIDE_VOLUME_CONTROL 'shvc' 469cedafe6SWim van der Meer 477afc7756SAlex Wilson 487afc7756SAlex Wilson SettingsView::SettingsView() 49a633251fSAlex Wilson : 50*c97121d3SAlex Wilson BGroupView(B_VERTICAL, B_USE_DEFAULT_SPACING), 517afc7756SAlex Wilson fInputMenu(NULL), 52*c97121d3SAlex Wilson fOutputMenu(NULL) 53a10cf76eSAxel Dörfler { 546e62e744SAlex Wilson // input menu 556e62e744SAlex Wilson fInputMenu = new BPopUpMenu(B_TRANSLATE("<none>")); 566e62e744SAlex Wilson fInputMenu->SetLabelFromMarked(true); 576e62e744SAlex Wilson 587afc7756SAlex Wilson // input menu 596e62e744SAlex Wilson fOutputMenu = new BPopUpMenu(B_TRANSLATE("<none>")); 606e62e744SAlex Wilson fOutputMenu->SetLabelFromMarked(true); 616e62e744SAlex Wilson } 626e62e744SAlex Wilson 632af5f895SStephan Aßmus 647afc7756SAlex Wilson BButton* 657afc7756SAlex Wilson SettingsView::MakeRestartButton() 667afc7756SAlex Wilson { 677afc7756SAlex Wilson return new BButton("restartButton", 68176fb40fSMatt Madia B_TRANSLATE("Restart media services"), 69176fb40fSMatt Madia new BMessage(ML_RESTART_MEDIA_SERVER)); 70a10cf76eSAxel Dörfler } 712af5f895SStephan Aßmus 722af5f895SStephan Aßmus 737afc7756SAlex Wilson 747afc7756SAlex Wilson void 757afc7756SAlex Wilson SettingsView::AddInputNodes(NodeList& list) 767afc7756SAlex Wilson { 777afc7756SAlex Wilson _EmptyMenu(fInputMenu); 787afc7756SAlex Wilson 797afc7756SAlex Wilson BMessage message(MEDIA_DEFAULT_INPUT_CHANGE); 807afc7756SAlex Wilson _PopulateMenu(fInputMenu, list, message); 81a10cf76eSAxel Dörfler } 82a10cf76eSAxel Dörfler 83a633251fSAlex Wilson 84a10cf76eSAxel Dörfler void 857afc7756SAlex Wilson SettingsView::AddOutputNodes(NodeList& list) 86a10cf76eSAxel Dörfler { 877afc7756SAlex Wilson _EmptyMenu(fOutputMenu); 886e62e744SAlex Wilson 897afc7756SAlex Wilson BMessage message(MEDIA_DEFAULT_OUTPUT_CHANGE); 907afc7756SAlex Wilson _PopulateMenu(fOutputMenu, list, message); 91a10cf76eSAxel Dörfler } 92a10cf76eSAxel Dörfler 93a633251fSAlex Wilson 94a10cf76eSAxel Dörfler void 957afc7756SAlex Wilson SettingsView::SetDefaultInput(const dormant_node_info* info) 96a10cf76eSAxel Dörfler { 977afc7756SAlex Wilson _ClearMenuSelection(fInputMenu); 987afc7756SAlex Wilson NodeMenuItem* item = _FindNodeItem(fInputMenu, info); 997afc7756SAlex Wilson if (item) 100a10cf76eSAxel Dörfler item->SetMarked(true); 1017afc7756SAlex Wilson } 1027afc7756SAlex Wilson 1037afc7756SAlex Wilson 1047afc7756SAlex Wilson void 1057afc7756SAlex Wilson SettingsView::SetDefaultOutput(const dormant_node_info* info) 1067afc7756SAlex Wilson { 1077afc7756SAlex Wilson _ClearMenuSelection(fOutputMenu); 1087afc7756SAlex Wilson NodeMenuItem* item = _FindNodeItem(fOutputMenu, info); 1097afc7756SAlex Wilson if (item) 1107afc7756SAlex Wilson item->SetMarked(true); 1117afc7756SAlex Wilson } 1127afc7756SAlex Wilson 1137afc7756SAlex Wilson 1147afc7756SAlex Wilson void 1157afc7756SAlex Wilson SettingsView::MessageReceived(BMessage* message) 1167afc7756SAlex Wilson { 1177afc7756SAlex Wilson switch (message->what) { 1187afc7756SAlex Wilson case MEDIA_DEFAULT_INPUT_CHANGE: 1197afc7756SAlex Wilson { 1207afc7756SAlex Wilson int32 index; 1217afc7756SAlex Wilson if (message->FindInt32("index", &index)!=B_OK) 1227afc7756SAlex Wilson break; 1237afc7756SAlex Wilson NodeMenuItem* item 1247afc7756SAlex Wilson = static_cast<NodeMenuItem*>(fInputMenu->ItemAt(index)); 1257afc7756SAlex Wilson SetDefaultInput(item->NodeInfo()); 126d2772fb4SAlex Wilson break; 1277afc7756SAlex Wilson } 1287afc7756SAlex Wilson case MEDIA_DEFAULT_OUTPUT_CHANGE: 1297afc7756SAlex Wilson { 1307afc7756SAlex Wilson int32 index; 1317afc7756SAlex Wilson if (message->FindInt32("index", &index)!=B_OK) 1327afc7756SAlex Wilson break; 1337afc7756SAlex Wilson NodeMenuItem* item 1347afc7756SAlex Wilson = static_cast<NodeMenuItem*>(fOutputMenu->ItemAt(index)); 1357afc7756SAlex Wilson SetDefaultOutput(item->NodeInfo()); 136a10cf76eSAxel Dörfler break; 137a10cf76eSAxel Dörfler } 138d2772fb4SAlex Wilson default: 139*c97121d3SAlex Wilson BGroupView::MessageReceived(message); 1407afc7756SAlex Wilson } 141d2772fb4SAlex Wilson } 142a10cf76eSAxel Dörfler 143a633251fSAlex Wilson 1447afc7756SAlex Wilson void 1457afc7756SAlex Wilson SettingsView::AttachedToWindow() 1467afc7756SAlex Wilson { 1477afc7756SAlex Wilson BMessenger thisMessenger(this); 1487afc7756SAlex Wilson fInputMenu->SetTargetForItems(thisMessenger); 1497afc7756SAlex Wilson fOutputMenu->SetTargetForItems(thisMessenger); 1507afc7756SAlex Wilson } 1517afc7756SAlex Wilson 1527afc7756SAlex Wilson 1537afc7756SAlex Wilson MediaWindow* 1547afc7756SAlex Wilson SettingsView::_MediaWindow() const 1557afc7756SAlex Wilson { 1567afc7756SAlex Wilson return static_cast<MediaWindow*>(Window()); 1577afc7756SAlex Wilson } 1587afc7756SAlex Wilson 1597afc7756SAlex Wilson 1607afc7756SAlex Wilson void 1617afc7756SAlex Wilson SettingsView::_EmptyMenu(BMenu* menu) 1627afc7756SAlex Wilson { 1637afc7756SAlex Wilson while (menu->CountItems() > 0) 1647afc7756SAlex Wilson delete menu->RemoveItem((int32)0); 1657afc7756SAlex Wilson } 1667afc7756SAlex Wilson 1677afc7756SAlex Wilson 1687afc7756SAlex Wilson void 1697afc7756SAlex Wilson SettingsView::_PopulateMenu(BMenu* menu, NodeList& nodes, 1707afc7756SAlex Wilson const BMessage& message) 1717afc7756SAlex Wilson { 1727afc7756SAlex Wilson for (int32 i = 0; i < nodes.CountItems(); i++) { 1737afc7756SAlex Wilson dormant_node_info* info = nodes.ItemAt(i); 1747afc7756SAlex Wilson menu->AddItem(new NodeMenuItem(info, new BMessage(message))); 1757afc7756SAlex Wilson } 1767afc7756SAlex Wilson 1777afc7756SAlex Wilson if (Window() != NULL) 1787afc7756SAlex Wilson menu->SetTargetForItems(BMessenger(this)); 1797afc7756SAlex Wilson } 1807afc7756SAlex Wilson 1817afc7756SAlex Wilson 1827afc7756SAlex Wilson NodeMenuItem* 1837afc7756SAlex Wilson SettingsView::_FindNodeItem(BMenu* menu, const dormant_node_info* nodeInfo) 1847afc7756SAlex Wilson { 1857afc7756SAlex Wilson for (int32 i = 0; i < menu->CountItems(); i++) { 1867afc7756SAlex Wilson NodeMenuItem* item = static_cast<NodeMenuItem*>(menu->ItemAt(i)); 1877afc7756SAlex Wilson const dormant_node_info* itemInfo = item->NodeInfo(); 1887afc7756SAlex Wilson if (itemInfo && itemInfo->addon == nodeInfo->addon 1897afc7756SAlex Wilson && itemInfo->flavor_id == nodeInfo->flavor_id) { 1907afc7756SAlex Wilson return item; 191a10cf76eSAxel Dörfler } 192a10cf76eSAxel Dörfler } 1937afc7756SAlex Wilson return NULL; 194a10cf76eSAxel Dörfler } 1957afc7756SAlex Wilson 1967afc7756SAlex Wilson 1977afc7756SAlex Wilson void 1987afc7756SAlex Wilson SettingsView::_ClearMenuSelection(BMenu* menu) 1997afc7756SAlex Wilson { 2007afc7756SAlex Wilson for (int32 i = 0; i < menu->CountItems(); i++) { 2017afc7756SAlex Wilson BMenuItem* item = menu->ItemAt(i); 2027afc7756SAlex Wilson item->SetMarked(false); 203a10cf76eSAxel Dörfler } 204a10cf76eSAxel Dörfler } 205a10cf76eSAxel Dörfler 206a633251fSAlex Wilson 2077afc7756SAlex Wilson NodeMenuItem::NodeMenuItem(const dormant_node_info* info, BMessage* message, 208a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 209a633251fSAlex Wilson : 210a633251fSAlex Wilson BMenuItem(info->name, message, shortcut, modifiers), 211b4a12470SJérôme Duval fInfo(info) 212a10cf76eSAxel Dörfler { 213a10cf76eSAxel Dörfler 214a10cf76eSAxel Dörfler } 215a10cf76eSAxel Dörfler 2166df0b2d5SJérôme Duval 2176df0b2d5SJérôme Duval status_t 2187afc7756SAlex Wilson NodeMenuItem::Invoke(BMessage* message) 2196df0b2d5SJérôme Duval { 2206df0b2d5SJérôme Duval if (IsMarked()) 2216df0b2d5SJérôme Duval return B_OK; 2226df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2236df0b2d5SJérôme Duval } 2246df0b2d5SJérôme Duval 2256df0b2d5SJérôme Duval 2267afc7756SAlex Wilson ChannelMenuItem::ChannelMenuItem(media_input* input, BMessage* message, 2277afc7756SAlex Wilson char shortcut, uint32 modifiers) 228a633251fSAlex Wilson : 229a633251fSAlex Wilson BMenuItem(input->name, message, shortcut, modifiers), 230b4a12470SJérôme Duval fInput(input) 231a10cf76eSAxel Dörfler { 232a10cf76eSAxel Dörfler } 233a10cf76eSAxel Dörfler 2346df0b2d5SJérôme Duval 2357afc7756SAlex Wilson ChannelMenuItem::~ChannelMenuItem() 236a10cf76eSAxel Dörfler { 237b4a12470SJérôme Duval delete fInput; 238a10cf76eSAxel Dörfler } 239a10cf76eSAxel Dörfler 2406df0b2d5SJérôme Duval 2417afc7756SAlex Wilson int32 2427afc7756SAlex Wilson ChannelMenuItem::DestinationID() 2437afc7756SAlex Wilson { 2447afc7756SAlex Wilson return fInput->destination.id; 2457afc7756SAlex Wilson } 2467afc7756SAlex Wilson 2477afc7756SAlex Wilson 2487afc7756SAlex Wilson media_input* 2497afc7756SAlex Wilson ChannelMenuItem::Input() 2507afc7756SAlex Wilson { 2517afc7756SAlex Wilson return fInput; 2527afc7756SAlex Wilson } 2537afc7756SAlex Wilson 2547afc7756SAlex Wilson 2556df0b2d5SJérôme Duval status_t 2567afc7756SAlex Wilson ChannelMenuItem::Invoke(BMessage* message) 2576df0b2d5SJérôme Duval { 2586df0b2d5SJérôme Duval if (IsMarked()) 2596df0b2d5SJérôme Duval return B_OK; 2606df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2616df0b2d5SJérôme Duval } 2626df0b2d5SJérôme Duval 2637afc7756SAlex Wilson 2647afc7756SAlex Wilson AudioSettingsView::AudioSettingsView() 2657afc7756SAlex Wilson { 2667afc7756SAlex Wilson BBox* defaultsBox = new BBox("defaults"); 2677afc7756SAlex Wilson defaultsBox->SetLabel(B_TRANSLATE("Defaults")); 2687afc7756SAlex Wilson BGridView* defaultsGridView = new BGridView(); 2697afc7756SAlex Wilson 2707afc7756SAlex Wilson BMenuField* inputMenuField = new BMenuField("inputMenuField", 2717afc7756SAlex Wilson B_TRANSLATE("Audio input:"), InputMenu(), NULL); 2727afc7756SAlex Wilson 2737afc7756SAlex Wilson BMenuField* outputMenuField = new BMenuField("outputMenuField", 2747afc7756SAlex Wilson B_TRANSLATE("Audio output:"), OutputMenu(), NULL); 2757afc7756SAlex Wilson 2767afc7756SAlex Wilson BLayoutBuilder::Grid<>(defaultsGridView) 277*c97121d3SAlex Wilson .SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING, 278*c97121d3SAlex Wilson B_USE_DEFAULT_SPACING) 2797afc7756SAlex Wilson .AddMenuField(inputMenuField, 0, 0, B_ALIGN_HORIZONTAL_UNSET, 1, 3, 1) 2807afc7756SAlex Wilson .AddMenuField(outputMenuField, 0, 1) 281*c97121d3SAlex Wilson .AddMenuField(_MakeChannelMenu(), 2, 1); 2827afc7756SAlex Wilson 2837afc7756SAlex Wilson defaultsBox->AddChild(defaultsGridView); 2847afc7756SAlex Wilson 285*c97121d3SAlex Wilson BLayoutBuilder::Group<>(this) 2867afc7756SAlex Wilson .SetInsets(0, 0, 0, 0) 287*c97121d3SAlex Wilson .Add(defaultsBox) 288*c97121d3SAlex Wilson .AddGroup(B_HORIZONTAL) 289*c97121d3SAlex Wilson .Add(_MakeVolumeCheckBox()) 290*c97121d3SAlex Wilson .Add(MakeRestartButton()) 291*c97121d3SAlex Wilson .End() 292*c97121d3SAlex Wilson .AddGlue(); 2937afc7756SAlex Wilson } 2947afc7756SAlex Wilson 2957afc7756SAlex Wilson 2967afc7756SAlex Wilson void 2977afc7756SAlex Wilson AudioSettingsView::SetDefaultChannel(int32 channelID) 2987afc7756SAlex Wilson { 2997afc7756SAlex Wilson for (int32 i = 0; i < fChannelMenu->CountItems(); i++) { 3007afc7756SAlex Wilson ChannelMenuItem* item = _ChannelMenuItemAt(i); 3017afc7756SAlex Wilson item->SetMarked(item->DestinationID() == channelID); 3027afc7756SAlex Wilson } 3037afc7756SAlex Wilson } 3047afc7756SAlex Wilson 3057afc7756SAlex Wilson 3067afc7756SAlex Wilson void 3077afc7756SAlex Wilson AudioSettingsView::AttachedToWindow() 3087afc7756SAlex Wilson { 3097afc7756SAlex Wilson SettingsView::AttachedToWindow(); 3107afc7756SAlex Wilson 3117afc7756SAlex Wilson BMessenger thisMessenger(this); 3127afc7756SAlex Wilson fChannelMenu->SetTargetForItems(thisMessenger); 3137afc7756SAlex Wilson fVolumeCheckBox->SetTarget(thisMessenger); 3147afc7756SAlex Wilson } 3157afc7756SAlex Wilson 3167afc7756SAlex Wilson 3177afc7756SAlex Wilson void 3187afc7756SAlex Wilson AudioSettingsView::MessageReceived(BMessage* message) 3197afc7756SAlex Wilson { 3207afc7756SAlex Wilson switch (message->what) { 3217afc7756SAlex Wilson case ML_DEFAULT_CHANNEL_CHANGED: 3227afc7756SAlex Wilson { 3237afc7756SAlex Wilson int32 index; 3247afc7756SAlex Wilson if (message->FindInt32("index", &index) != B_OK) 3257afc7756SAlex Wilson break; 3267afc7756SAlex Wilson ChannelMenuItem* item = _ChannelMenuItemAt(index); 3277afc7756SAlex Wilson 3287afc7756SAlex Wilson if (item) { 3297afc7756SAlex Wilson BMediaRoster* roster = BMediaRoster::Roster(); 3307afc7756SAlex Wilson roster->SetAudioOutput(*item->Input()); 3317afc7756SAlex Wilson } else 3327afc7756SAlex Wilson fprintf(stderr, "ChannelMenuItem not found\n"); 3337afc7756SAlex Wilson } 3347afc7756SAlex Wilson break; 3357afc7756SAlex Wilson case MEDIA_SHOW_HIDE_VOLUME_CONTROL: 3367afc7756SAlex Wilson { 3377afc7756SAlex Wilson if (fVolumeCheckBox->Value() == B_CONTROL_ON) 3387afc7756SAlex Wilson _ShowDeskbarVolumeControl(); 3397afc7756SAlex Wilson else 3407afc7756SAlex Wilson _HideDeskbarVolumeControl(); 3417afc7756SAlex Wilson break; 3427afc7756SAlex Wilson } 3437afc7756SAlex Wilson 3447afc7756SAlex Wilson default: 3457afc7756SAlex Wilson SettingsView::MessageReceived(message); 3467afc7756SAlex Wilson } 3477afc7756SAlex Wilson } 3487afc7756SAlex Wilson 3497afc7756SAlex Wilson 3507afc7756SAlex Wilson void 3517afc7756SAlex Wilson AudioSettingsView::SetDefaultInput(const dormant_node_info* info) 3527afc7756SAlex Wilson { 3537afc7756SAlex Wilson SettingsView::SetDefaultInput(info); 3547afc7756SAlex Wilson _MediaWindow()->UpdateInputListItem(MediaListItem::AUDIO_TYPE, info); 3557afc7756SAlex Wilson BMediaRoster::Roster()->SetAudioInput(*info); 3567afc7756SAlex Wilson } 3577afc7756SAlex Wilson 3587afc7756SAlex Wilson 3597afc7756SAlex Wilson void 3607afc7756SAlex Wilson AudioSettingsView::SetDefaultOutput(const dormant_node_info* info) 3617afc7756SAlex Wilson { 3627afc7756SAlex Wilson SettingsView::SetDefaultOutput(info); 3637afc7756SAlex Wilson _MediaWindow()->UpdateOutputListItem(MediaListItem::AUDIO_TYPE, info); 3647afc7756SAlex Wilson _FillChannelMenu(info); 3657afc7756SAlex Wilson BMediaRoster::Roster()->SetAudioOutput(*info); 3667afc7756SAlex Wilson } 3677afc7756SAlex Wilson 3687afc7756SAlex Wilson 3697afc7756SAlex Wilson BMenuField* 3707afc7756SAlex Wilson AudioSettingsView::_MakeChannelMenu() 3717afc7756SAlex Wilson { 3727afc7756SAlex Wilson fChannelMenu = new BPopUpMenu(B_TRANSLATE("<none>")); 3737afc7756SAlex Wilson fChannelMenu->SetLabelFromMarked(true); 3747afc7756SAlex Wilson BMenuField* channelMenuField = new BMenuField("channelMenuField", 3757afc7756SAlex Wilson B_TRANSLATE("Channel:"), fChannelMenu, NULL); 3767afc7756SAlex Wilson return channelMenuField; 3777afc7756SAlex Wilson } 3787afc7756SAlex Wilson 3797afc7756SAlex Wilson 3807afc7756SAlex Wilson BCheckBox* 3817afc7756SAlex Wilson AudioSettingsView::_MakeVolumeCheckBox() 3827afc7756SAlex Wilson { 3837afc7756SAlex Wilson fVolumeCheckBox = new BCheckBox("volumeCheckBox", 3847afc7756SAlex Wilson B_TRANSLATE("Show volume control on Deskbar"), 3857afc7756SAlex Wilson new BMessage(MEDIA_SHOW_HIDE_VOLUME_CONTROL)); 3867afc7756SAlex Wilson 3877afc7756SAlex Wilson if (BDeskbar().HasItem("MediaReplicant")) 3887afc7756SAlex Wilson fVolumeCheckBox->SetValue(B_CONTROL_ON); 3897afc7756SAlex Wilson 3907afc7756SAlex Wilson return fVolumeCheckBox; 3917afc7756SAlex Wilson } 3927afc7756SAlex Wilson 3937afc7756SAlex Wilson 3947afc7756SAlex Wilson void 3957afc7756SAlex Wilson AudioSettingsView::_FillChannelMenu(const dormant_node_info* nodeInfo) 3967afc7756SAlex Wilson { 3977afc7756SAlex Wilson _EmptyMenu(fChannelMenu); 3987afc7756SAlex Wilson 3997afc7756SAlex Wilson BMediaRoster* roster = BMediaRoster::Roster(); 4007afc7756SAlex Wilson media_node node; 4017afc7756SAlex Wilson media_node_id node_id; 4027afc7756SAlex Wilson 4037afc7756SAlex Wilson status_t err = roster->GetInstancesFor(nodeInfo->addon, 4047afc7756SAlex Wilson nodeInfo->flavor_id, &node_id); 4057afc7756SAlex Wilson if (err != B_OK) { 4067afc7756SAlex Wilson err = roster->InstantiateDormantNode(*nodeInfo, &node, 4077afc7756SAlex Wilson B_FLAVOR_IS_GLOBAL); 4087afc7756SAlex Wilson } else { 4097afc7756SAlex Wilson err = roster->GetNodeFor(node_id, &node); 4107afc7756SAlex Wilson } 4117afc7756SAlex Wilson 4127afc7756SAlex Wilson if (err == B_OK) { 4137afc7756SAlex Wilson int32 inputCount = 4; 4147afc7756SAlex Wilson media_input* inputs = new media_input[inputCount]; 4157afc7756SAlex Wilson BPrivate::ArrayDeleter<media_input> inputDeleter(inputs); 4167afc7756SAlex Wilson 4177afc7756SAlex Wilson while (true) { 4187afc7756SAlex Wilson int32 realInputCount = 0; 4197afc7756SAlex Wilson err = roster->GetAllInputsFor(node, inputs, 4207afc7756SAlex Wilson inputCount, &realInputCount); 4217afc7756SAlex Wilson if (realInputCount > inputCount) { 4227afc7756SAlex Wilson inputCount *= 2; 4237afc7756SAlex Wilson inputs = new media_input[inputCount]; 4247afc7756SAlex Wilson inputDeleter.SetTo(inputs); 4257afc7756SAlex Wilson } else { 4267afc7756SAlex Wilson inputCount = realInputCount; 4277afc7756SAlex Wilson break; 4287afc7756SAlex Wilson } 4297afc7756SAlex Wilson } 4307afc7756SAlex Wilson 4317afc7756SAlex Wilson if (err == B_OK) { 4327afc7756SAlex Wilson BMessage message(ML_DEFAULT_CHANNEL_CHANGED); 4337afc7756SAlex Wilson 4347afc7756SAlex Wilson for (int32 i = 0; i < inputCount; i++) { 4357afc7756SAlex Wilson media_input* input = new media_input(); 4367afc7756SAlex Wilson memcpy(input, &inputs[i], sizeof(*input)); 4377afc7756SAlex Wilson ChannelMenuItem* channelItem = new ChannelMenuItem(input, 4387afc7756SAlex Wilson new BMessage(message)); 4397afc7756SAlex Wilson fChannelMenu->AddItem(channelItem); 4407afc7756SAlex Wilson 4417afc7756SAlex Wilson if (channelItem->DestinationID() == 0) 4427afc7756SAlex Wilson channelItem->SetMarked(true); 4437afc7756SAlex Wilson } 4447afc7756SAlex Wilson } 4457afc7756SAlex Wilson } 4467afc7756SAlex Wilson 4477afc7756SAlex Wilson if (Window()) 4487afc7756SAlex Wilson fChannelMenu->SetTargetForItems(BMessenger(this)); 4497afc7756SAlex Wilson } 4507afc7756SAlex Wilson 4517afc7756SAlex Wilson 4527afc7756SAlex Wilson void 4537afc7756SAlex Wilson AudioSettingsView::_ShowDeskbarVolumeControl() 4547afc7756SAlex Wilson { 4557afc7756SAlex Wilson BDeskbar deskbar; 4567afc7756SAlex Wilson BEntry entry("/bin/desklink", true); 4577afc7756SAlex Wilson int32 id; 4587afc7756SAlex Wilson entry_ref ref; 4597afc7756SAlex Wilson status_t status = entry.GetRef(&ref); 4607afc7756SAlex Wilson if (status == B_OK) 4617afc7756SAlex Wilson status = deskbar.AddItem(&ref, &id); 4627afc7756SAlex Wilson 4637afc7756SAlex Wilson if (status != B_OK) { 4647afc7756SAlex Wilson fprintf(stderr, B_TRANSLATE( 4657afc7756SAlex Wilson "Couldn't add volume control in Deskbar: %s\n"), 4667afc7756SAlex Wilson strerror(status)); 4677afc7756SAlex Wilson } 4687afc7756SAlex Wilson } 4697afc7756SAlex Wilson 4707afc7756SAlex Wilson 4717afc7756SAlex Wilson void 4727afc7756SAlex Wilson AudioSettingsView::_HideDeskbarVolumeControl() 4737afc7756SAlex Wilson { 4747afc7756SAlex Wilson BDeskbar deskbar; 4757afc7756SAlex Wilson status_t status = deskbar.RemoveItem("MediaReplicant"); 4767afc7756SAlex Wilson if (status != B_OK) { 4777afc7756SAlex Wilson fprintf(stderr, B_TRANSLATE( 4787afc7756SAlex Wilson "Couldn't remove volume control in Deskbar: %s\n"), 4797afc7756SAlex Wilson strerror(status)); 4807afc7756SAlex Wilson } 4817afc7756SAlex Wilson } 4827afc7756SAlex Wilson 4837afc7756SAlex Wilson 4847afc7756SAlex Wilson ChannelMenuItem* 4857afc7756SAlex Wilson AudioSettingsView::_ChannelMenuItemAt(int32 index) 4867afc7756SAlex Wilson { 4877afc7756SAlex Wilson return static_cast<ChannelMenuItem*>(fChannelMenu->ItemAt(index)); 4887afc7756SAlex Wilson } 4897afc7756SAlex Wilson 4907afc7756SAlex Wilson 4917afc7756SAlex Wilson VideoSettingsView::VideoSettingsView() 4927afc7756SAlex Wilson { 4937afc7756SAlex Wilson BBox* defaultsBox = new BBox("defaults"); 4947afc7756SAlex Wilson defaultsBox->SetLabel(B_TRANSLATE("Defaults")); 4957afc7756SAlex Wilson BGridView* defaultsGridView = new BGridView(); 4967afc7756SAlex Wilson 4977afc7756SAlex Wilson BMenuField* inputMenuField = new BMenuField("inputMenuField", 4987afc7756SAlex Wilson B_TRANSLATE("Video input:"), InputMenu(), NULL); 4997afc7756SAlex Wilson 5007afc7756SAlex Wilson BMenuField* outputMenuField = new BMenuField("outputMenuField", 5017afc7756SAlex Wilson B_TRANSLATE("Video output:"), OutputMenu(), NULL); 5027afc7756SAlex Wilson 5037afc7756SAlex Wilson BLayoutBuilder::Grid<>(defaultsGridView) 504*c97121d3SAlex Wilson .SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING, 505*c97121d3SAlex Wilson B_USE_DEFAULT_SPACING) 5067afc7756SAlex Wilson .AddMenuField(inputMenuField, 0, 0) 507*c97121d3SAlex Wilson .AddMenuField(outputMenuField, 0, 1); 5087afc7756SAlex Wilson 5097afc7756SAlex Wilson defaultsBox->AddChild(defaultsGridView); 5107afc7756SAlex Wilson 511*c97121d3SAlex Wilson BLayoutBuilder::Group<>(this) 5127afc7756SAlex Wilson .SetInsets(0, 0, 0, 0) 513*c97121d3SAlex Wilson .Add(defaultsBox) 514*c97121d3SAlex Wilson .AddGroup(B_HORIZONTAL) 515*c97121d3SAlex Wilson .AddGlue() 516*c97121d3SAlex Wilson .Add(MakeRestartButton()) 517*c97121d3SAlex Wilson .End() 518*c97121d3SAlex Wilson .AddGlue(); 5197afc7756SAlex Wilson } 5207afc7756SAlex Wilson 5217afc7756SAlex Wilson 5227afc7756SAlex Wilson void 5237afc7756SAlex Wilson VideoSettingsView::SetDefaultInput(const dormant_node_info* info) 5247afc7756SAlex Wilson { 5257afc7756SAlex Wilson SettingsView::SetDefaultInput(info); 5267afc7756SAlex Wilson _MediaWindow()->UpdateInputListItem(MediaListItem::VIDEO_TYPE, info); 5277afc7756SAlex Wilson BMediaRoster::Roster()->SetVideoInput(*info); 5287afc7756SAlex Wilson } 5297afc7756SAlex Wilson 5307afc7756SAlex Wilson 5317afc7756SAlex Wilson void 5327afc7756SAlex Wilson VideoSettingsView::SetDefaultOutput(const dormant_node_info* info) 5337afc7756SAlex Wilson { 5347afc7756SAlex Wilson SettingsView::SetDefaultOutput(info); 5357afc7756SAlex Wilson _MediaWindow()->UpdateOutputListItem(MediaListItem::VIDEO_TYPE, info); 5367afc7756SAlex Wilson BMediaRoster::Roster()->SetVideoOutput(*info); 5377afc7756SAlex Wilson } 538