xref: /haiku/src/preferences/media/MediaViews.cpp (revision 8a28f8496597f67b9e0f80c1143398763062239b)
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"),
657482390aSDario Casalinuovo 		new BMessage(ML_RESTART_MEDIA_SERVER),
667482390aSDario Casalinuovo 			B_ALIGN_RIGHT);
67a10cf76eSAxel Dörfler }
682af5f895SStephan Aßmus 
692af5f895SStephan Aßmus 
707afc7756SAlex Wilson 
717afc7756SAlex Wilson void
727afc7756SAlex Wilson SettingsView::AddInputNodes(NodeList& list)
737afc7756SAlex Wilson {
747afc7756SAlex Wilson 	_EmptyMenu(fInputMenu);
757afc7756SAlex Wilson 
767afc7756SAlex Wilson 	BMessage message(MEDIA_DEFAULT_INPUT_CHANGE);
777afc7756SAlex Wilson 	_PopulateMenu(fInputMenu, list, message);
78a10cf76eSAxel Dörfler }
79a10cf76eSAxel Dörfler 
80a633251fSAlex Wilson 
81a10cf76eSAxel Dörfler void
827afc7756SAlex Wilson SettingsView::AddOutputNodes(NodeList& list)
83a10cf76eSAxel Dörfler {
847afc7756SAlex Wilson 	_EmptyMenu(fOutputMenu);
856e62e744SAlex Wilson 
867afc7756SAlex Wilson 	BMessage message(MEDIA_DEFAULT_OUTPUT_CHANGE);
877afc7756SAlex Wilson 	_PopulateMenu(fOutputMenu, list, message);
88a10cf76eSAxel Dörfler }
89a10cf76eSAxel Dörfler 
90a633251fSAlex Wilson 
91a10cf76eSAxel Dörfler void
927afc7756SAlex Wilson SettingsView::SetDefaultInput(const dormant_node_info* info)
93a10cf76eSAxel Dörfler {
947afc7756SAlex Wilson 	_ClearMenuSelection(fInputMenu);
957afc7756SAlex Wilson 	NodeMenuItem* item = _FindNodeItem(fInputMenu, info);
967afc7756SAlex Wilson 	if (item)
97a10cf76eSAxel Dörfler 		item->SetMarked(true);
987afc7756SAlex Wilson }
997afc7756SAlex Wilson 
1007afc7756SAlex Wilson 
1017afc7756SAlex Wilson void
1027afc7756SAlex Wilson SettingsView::SetDefaultOutput(const dormant_node_info* info)
1037afc7756SAlex Wilson {
1047afc7756SAlex Wilson 	_ClearMenuSelection(fOutputMenu);
1057afc7756SAlex Wilson 	NodeMenuItem* item = _FindNodeItem(fOutputMenu, info);
1067afc7756SAlex Wilson 	if (item)
1077afc7756SAlex Wilson 		item->SetMarked(true);
1087afc7756SAlex Wilson }
1097afc7756SAlex Wilson 
1107afc7756SAlex Wilson 
1117afc7756SAlex Wilson void
1127afc7756SAlex Wilson SettingsView::MessageReceived(BMessage* message)
1137afc7756SAlex Wilson {
1147afc7756SAlex Wilson 	switch (message->what) {
1157afc7756SAlex Wilson 		case MEDIA_DEFAULT_INPUT_CHANGE:
1167afc7756SAlex Wilson 		{
1177afc7756SAlex Wilson 			int32 index;
1187afc7756SAlex Wilson 			if (message->FindInt32("index", &index)!=B_OK)
1197afc7756SAlex Wilson 				break;
1207afc7756SAlex Wilson 			NodeMenuItem* item
1217afc7756SAlex Wilson 				= static_cast<NodeMenuItem*>(fInputMenu->ItemAt(index));
1227afc7756SAlex Wilson 			SetDefaultInput(item->NodeInfo());
123d2772fb4SAlex Wilson 			break;
1247afc7756SAlex Wilson 		}
1257afc7756SAlex Wilson 		case MEDIA_DEFAULT_OUTPUT_CHANGE:
1267afc7756SAlex Wilson 		{
1277afc7756SAlex Wilson 			int32 index;
1287afc7756SAlex Wilson 			if (message->FindInt32("index", &index)!=B_OK)
1297afc7756SAlex Wilson 				break;
1307afc7756SAlex Wilson 			NodeMenuItem* item
1317afc7756SAlex Wilson 				= static_cast<NodeMenuItem*>(fOutputMenu->ItemAt(index));
1327afc7756SAlex Wilson 			SetDefaultOutput(item->NodeInfo());
133a10cf76eSAxel Dörfler 			break;
134a10cf76eSAxel Dörfler 		}
135d2772fb4SAlex Wilson 		default:
136c97121d3SAlex Wilson 			BGroupView::MessageReceived(message);
1377afc7756SAlex Wilson 	}
138d2772fb4SAlex Wilson }
139a10cf76eSAxel Dörfler 
140a633251fSAlex Wilson 
1417afc7756SAlex Wilson void
1427afc7756SAlex Wilson SettingsView::AttachedToWindow()
1437afc7756SAlex Wilson {
1447afc7756SAlex Wilson 	BMessenger thisMessenger(this);
1457afc7756SAlex Wilson 	fInputMenu->SetTargetForItems(thisMessenger);
1467afc7756SAlex Wilson 	fOutputMenu->SetTargetForItems(thisMessenger);
1477afc7756SAlex Wilson }
1487afc7756SAlex Wilson 
1497afc7756SAlex Wilson 
1507afc7756SAlex Wilson MediaWindow*
1517afc7756SAlex Wilson SettingsView::_MediaWindow() const
1527afc7756SAlex Wilson {
1537afc7756SAlex Wilson 	return static_cast<MediaWindow*>(Window());
1547afc7756SAlex Wilson }
1557afc7756SAlex Wilson 
1567afc7756SAlex Wilson 
1577afc7756SAlex Wilson void
1587afc7756SAlex Wilson SettingsView::_EmptyMenu(BMenu* menu)
1597afc7756SAlex Wilson {
1607afc7756SAlex Wilson 	while (menu->CountItems() > 0)
1617afc7756SAlex Wilson 		delete menu->RemoveItem((int32)0);
1627afc7756SAlex Wilson }
1637afc7756SAlex Wilson 
1647afc7756SAlex Wilson 
1657afc7756SAlex Wilson void
1667afc7756SAlex Wilson SettingsView::_PopulateMenu(BMenu* menu, NodeList& nodes,
1677afc7756SAlex Wilson 	const BMessage& message)
1687afc7756SAlex Wilson {
1697afc7756SAlex Wilson 	for (int32 i = 0; i < nodes.CountItems(); i++) {
1707afc7756SAlex Wilson 		dormant_node_info* info = nodes.ItemAt(i);
1717afc7756SAlex Wilson 		menu->AddItem(new NodeMenuItem(info, new BMessage(message)));
1727afc7756SAlex Wilson 	}
1737afc7756SAlex Wilson 
1747afc7756SAlex Wilson 	if (Window() != NULL)
1757afc7756SAlex Wilson 		menu->SetTargetForItems(BMessenger(this));
1767afc7756SAlex Wilson }
1777afc7756SAlex Wilson 
1787afc7756SAlex Wilson 
1797afc7756SAlex Wilson NodeMenuItem*
1807afc7756SAlex Wilson SettingsView::_FindNodeItem(BMenu* menu, const dormant_node_info* nodeInfo)
1817afc7756SAlex Wilson {
1827afc7756SAlex Wilson 	for (int32 i = 0; i < menu->CountItems(); i++) {
1837afc7756SAlex Wilson 		NodeMenuItem* item = static_cast<NodeMenuItem*>(menu->ItemAt(i));
1847afc7756SAlex Wilson 		const dormant_node_info* itemInfo = item->NodeInfo();
1857afc7756SAlex Wilson 		if (itemInfo && itemInfo->addon == nodeInfo->addon
1867afc7756SAlex Wilson 			&& itemInfo->flavor_id == nodeInfo->flavor_id) {
1877afc7756SAlex Wilson 			return item;
188a10cf76eSAxel Dörfler 		}
189a10cf76eSAxel Dörfler 	}
1907afc7756SAlex Wilson 	return NULL;
191a10cf76eSAxel Dörfler }
1927afc7756SAlex Wilson 
1937afc7756SAlex Wilson 
1947afc7756SAlex Wilson void
1957afc7756SAlex Wilson SettingsView::_ClearMenuSelection(BMenu* menu)
1967afc7756SAlex Wilson {
1977afc7756SAlex Wilson 	for (int32 i = 0; i < menu->CountItems(); i++) {
1987afc7756SAlex Wilson 		BMenuItem* item = menu->ItemAt(i);
1997afc7756SAlex Wilson 		item->SetMarked(false);
200a10cf76eSAxel Dörfler 	}
201a10cf76eSAxel Dörfler }
202a10cf76eSAxel Dörfler 
203a633251fSAlex Wilson 
2047afc7756SAlex Wilson NodeMenuItem::NodeMenuItem(const dormant_node_info* info, BMessage* message,
205a10cf76eSAxel Dörfler 	char shortcut, uint32 modifiers)
206a633251fSAlex Wilson 	:
207a633251fSAlex Wilson 	BMenuItem(info->name, message, shortcut, modifiers),
208b4a12470SJérôme Duval 	fInfo(info)
209a10cf76eSAxel Dörfler {
210a10cf76eSAxel Dörfler 
211a10cf76eSAxel Dörfler }
212a10cf76eSAxel Dörfler 
2136df0b2d5SJérôme Duval 
2146df0b2d5SJérôme Duval status_t
2157afc7756SAlex Wilson NodeMenuItem::Invoke(BMessage* message)
2166df0b2d5SJérôme Duval {
2176df0b2d5SJérôme Duval 	if (IsMarked())
2186df0b2d5SJérôme Duval 		return B_OK;
2196df0b2d5SJérôme Duval 	return BMenuItem::Invoke(message);
2206df0b2d5SJérôme Duval }
2216df0b2d5SJérôme Duval 
2226df0b2d5SJérôme Duval 
2237afc7756SAlex Wilson ChannelMenuItem::ChannelMenuItem(media_input* input, BMessage* message,
2247afc7756SAlex Wilson 	char shortcut, uint32 modifiers)
225a633251fSAlex Wilson 	:
226a633251fSAlex Wilson 	BMenuItem(input->name, message, shortcut, modifiers),
227b4a12470SJérôme Duval 	fInput(input)
228a10cf76eSAxel Dörfler {
229a10cf76eSAxel Dörfler }
230a10cf76eSAxel Dörfler 
2316df0b2d5SJérôme Duval 
2327afc7756SAlex Wilson ChannelMenuItem::~ChannelMenuItem()
233a10cf76eSAxel Dörfler {
234b4a12470SJérôme Duval 	delete fInput;
235a10cf76eSAxel Dörfler }
236a10cf76eSAxel Dörfler 
2376df0b2d5SJérôme Duval 
2387afc7756SAlex Wilson int32
2397afc7756SAlex Wilson ChannelMenuItem::DestinationID()
2407afc7756SAlex Wilson {
2417afc7756SAlex Wilson 	return fInput->destination.id;
2427afc7756SAlex Wilson }
2437afc7756SAlex Wilson 
2447afc7756SAlex Wilson 
2457afc7756SAlex Wilson media_input*
2467afc7756SAlex Wilson ChannelMenuItem::Input()
2477afc7756SAlex Wilson {
2487afc7756SAlex Wilson 	return fInput;
2497afc7756SAlex Wilson }
2507afc7756SAlex Wilson 
2517afc7756SAlex Wilson 
2526df0b2d5SJérôme Duval status_t
2537afc7756SAlex Wilson ChannelMenuItem::Invoke(BMessage* message)
2546df0b2d5SJérôme Duval {
2556df0b2d5SJérôme Duval 	if (IsMarked())
2566df0b2d5SJérôme Duval 		return B_OK;
2576df0b2d5SJérôme Duval 	return BMenuItem::Invoke(message);
2586df0b2d5SJérôme Duval }
2596df0b2d5SJérôme Duval 
2607afc7756SAlex Wilson 
2617afc7756SAlex Wilson AudioSettingsView::AudioSettingsView()
2627afc7756SAlex Wilson {
2637afc7756SAlex Wilson 	BBox* defaultsBox = new BBox("defaults");
2647afc7756SAlex Wilson 	defaultsBox->SetLabel(B_TRANSLATE("Defaults"));
2657afc7756SAlex Wilson 	BGridView* defaultsGridView = new BGridView();
2667afc7756SAlex Wilson 
2677afc7756SAlex Wilson 	BMenuField* inputMenuField = new BMenuField("inputMenuField",
26810dfe897SAxel Dörfler 		B_TRANSLATE("Audio input:"), InputMenu());
2697afc7756SAlex Wilson 
2707afc7756SAlex Wilson 	BMenuField* outputMenuField = new BMenuField("outputMenuField",
27110dfe897SAxel Dörfler 		B_TRANSLATE("Audio output:"), OutputMenu());
2727afc7756SAlex Wilson 
2737afc7756SAlex Wilson 	BLayoutBuilder::Grid<>(defaultsGridView)
274c97121d3SAlex Wilson 		.SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING,
275c97121d3SAlex Wilson 			B_USE_DEFAULT_SPACING)
2767afc7756SAlex Wilson 		.AddMenuField(inputMenuField, 0, 0, B_ALIGN_HORIZONTAL_UNSET, 1, 3, 1)
2777afc7756SAlex Wilson 		.AddMenuField(outputMenuField, 0, 1)
278c97121d3SAlex Wilson 		.AddMenuField(_MakeChannelMenu(), 2, 1);
2797afc7756SAlex Wilson 
2807afc7756SAlex Wilson 	defaultsBox->AddChild(defaultsGridView);
2817afc7756SAlex Wilson 
282c97121d3SAlex Wilson 	BLayoutBuilder::Group<>(this)
2837afc7756SAlex Wilson 		.SetInsets(0, 0, 0, 0)
284c97121d3SAlex Wilson 		.Add(defaultsBox)
285c97121d3SAlex Wilson 		.AddGroup(B_HORIZONTAL)
286c97121d3SAlex Wilson 			.Add(_MakeVolumeCheckBox())
287*8a28f849SDario Casalinuovo 			.AddGlue()
288c97121d3SAlex Wilson 			.Add(MakeRestartButton())
289c97121d3SAlex Wilson 			.End()
290c97121d3SAlex Wilson 		.AddGlue();
2917afc7756SAlex Wilson }
2927afc7756SAlex Wilson 
2937afc7756SAlex Wilson 
2947afc7756SAlex Wilson void
2957afc7756SAlex Wilson AudioSettingsView::SetDefaultChannel(int32 channelID)
2967afc7756SAlex Wilson {
2977afc7756SAlex Wilson 	for (int32 i = 0; i < fChannelMenu->CountItems(); i++) {
2987afc7756SAlex Wilson 		ChannelMenuItem* item = _ChannelMenuItemAt(i);
2997afc7756SAlex Wilson 		item->SetMarked(item->DestinationID() == channelID);
3007afc7756SAlex Wilson 	}
3017afc7756SAlex Wilson }
3027afc7756SAlex Wilson 
3037afc7756SAlex Wilson 
3047afc7756SAlex Wilson void
3057afc7756SAlex Wilson AudioSettingsView::AttachedToWindow()
3067afc7756SAlex Wilson {
3077afc7756SAlex Wilson 	SettingsView::AttachedToWindow();
3087afc7756SAlex Wilson 
3097afc7756SAlex Wilson 	BMessenger thisMessenger(this);
3107afc7756SAlex Wilson 	fChannelMenu->SetTargetForItems(thisMessenger);
3117afc7756SAlex Wilson 	fVolumeCheckBox->SetTarget(thisMessenger);
3127afc7756SAlex Wilson }
3137afc7756SAlex Wilson 
3147afc7756SAlex Wilson 
3157afc7756SAlex Wilson void
3167afc7756SAlex Wilson AudioSettingsView::MessageReceived(BMessage* message)
3177afc7756SAlex Wilson {
3187afc7756SAlex Wilson 	switch (message->what) {
3197afc7756SAlex Wilson 		case ML_DEFAULT_CHANNEL_CHANGED:
3207afc7756SAlex Wilson 			{
3217afc7756SAlex Wilson 				int32 index;
3227afc7756SAlex Wilson 				if (message->FindInt32("index", &index) != B_OK)
3237afc7756SAlex Wilson 					break;
3247afc7756SAlex Wilson 				ChannelMenuItem* item = _ChannelMenuItemAt(index);
3257afc7756SAlex Wilson 
3267afc7756SAlex Wilson 				if (item) {
3277afc7756SAlex Wilson 					BMediaRoster* roster = BMediaRoster::Roster();
3287afc7756SAlex Wilson 					roster->SetAudioOutput(*item->Input());
3297afc7756SAlex Wilson 				} else
3307afc7756SAlex Wilson 					fprintf(stderr, "ChannelMenuItem not found\n");
3317afc7756SAlex Wilson 			}
3327afc7756SAlex Wilson 			break;
3337afc7756SAlex Wilson 		case MEDIA_SHOW_HIDE_VOLUME_CONTROL:
3347afc7756SAlex Wilson 		{
3357afc7756SAlex Wilson 			if (fVolumeCheckBox->Value() == B_CONTROL_ON)
3367afc7756SAlex Wilson 				_ShowDeskbarVolumeControl();
3377afc7756SAlex Wilson 			else
3387afc7756SAlex Wilson 				_HideDeskbarVolumeControl();
3397afc7756SAlex Wilson 			break;
3407afc7756SAlex Wilson 		}
3417afc7756SAlex Wilson 
3427afc7756SAlex Wilson 		default:
3437afc7756SAlex Wilson 			SettingsView::MessageReceived(message);
3447afc7756SAlex Wilson 	}
3457afc7756SAlex Wilson }
3467afc7756SAlex Wilson 
3477afc7756SAlex Wilson 
3487afc7756SAlex Wilson void
3497afc7756SAlex Wilson AudioSettingsView::SetDefaultInput(const dormant_node_info* info)
3507afc7756SAlex Wilson {
3517afc7756SAlex Wilson 	SettingsView::SetDefaultInput(info);
3527afc7756SAlex Wilson 	_MediaWindow()->UpdateInputListItem(MediaListItem::AUDIO_TYPE, info);
3537afc7756SAlex Wilson 	BMediaRoster::Roster()->SetAudioInput(*info);
3547afc7756SAlex Wilson }
3557afc7756SAlex Wilson 
3567afc7756SAlex Wilson 
3577afc7756SAlex Wilson void
3587afc7756SAlex Wilson AudioSettingsView::SetDefaultOutput(const dormant_node_info* info)
3597afc7756SAlex Wilson {
3607afc7756SAlex Wilson 	SettingsView::SetDefaultOutput(info);
3617afc7756SAlex Wilson 	_MediaWindow()->UpdateOutputListItem(MediaListItem::AUDIO_TYPE, info);
3627afc7756SAlex Wilson 	_FillChannelMenu(info);
3637afc7756SAlex Wilson 	BMediaRoster::Roster()->SetAudioOutput(*info);
3647afc7756SAlex Wilson }
3657afc7756SAlex Wilson 
3667afc7756SAlex Wilson 
3677afc7756SAlex Wilson BMenuField*
3687afc7756SAlex Wilson AudioSettingsView::_MakeChannelMenu()
3697afc7756SAlex Wilson {
3707afc7756SAlex Wilson 	fChannelMenu = new BPopUpMenu(B_TRANSLATE("<none>"));
3717afc7756SAlex Wilson 	fChannelMenu->SetLabelFromMarked(true);
3727afc7756SAlex Wilson 	BMenuField* channelMenuField = new BMenuField("channelMenuField",
37310dfe897SAxel Dörfler 		B_TRANSLATE("Channel:"), fChannelMenu);
3747afc7756SAlex Wilson 	return channelMenuField;
3757afc7756SAlex Wilson }
3767afc7756SAlex Wilson 
3777afc7756SAlex Wilson 
3787afc7756SAlex Wilson BCheckBox*
3797afc7756SAlex Wilson AudioSettingsView::_MakeVolumeCheckBox()
3807afc7756SAlex Wilson {
3817afc7756SAlex Wilson 	fVolumeCheckBox = new BCheckBox("volumeCheckBox",
3827afc7756SAlex Wilson 		B_TRANSLATE("Show volume control on Deskbar"),
3837afc7756SAlex Wilson 		new BMessage(MEDIA_SHOW_HIDE_VOLUME_CONTROL));
3847afc7756SAlex Wilson 
3857afc7756SAlex Wilson 	if (BDeskbar().HasItem("MediaReplicant"))
3867afc7756SAlex Wilson 		fVolumeCheckBox->SetValue(B_CONTROL_ON);
3877afc7756SAlex Wilson 
3887afc7756SAlex Wilson 	return fVolumeCheckBox;
3897afc7756SAlex Wilson }
3907afc7756SAlex Wilson 
3917afc7756SAlex Wilson 
3927afc7756SAlex Wilson void
3937afc7756SAlex Wilson AudioSettingsView::_FillChannelMenu(const dormant_node_info* nodeInfo)
3947afc7756SAlex Wilson {
3957afc7756SAlex Wilson 	_EmptyMenu(fChannelMenu);
3967afc7756SAlex Wilson 
3977afc7756SAlex Wilson 	BMediaRoster* roster = BMediaRoster::Roster();
3987afc7756SAlex Wilson 	media_node node;
3997afc7756SAlex Wilson 	media_node_id node_id;
4007afc7756SAlex Wilson 
4017afc7756SAlex Wilson 	status_t err = roster->GetInstancesFor(nodeInfo->addon,
4027afc7756SAlex Wilson 		nodeInfo->flavor_id, &node_id);
4037afc7756SAlex Wilson 	if (err != B_OK) {
4047afc7756SAlex Wilson 		err = roster->InstantiateDormantNode(*nodeInfo, &node,
4057afc7756SAlex Wilson 			B_FLAVOR_IS_GLOBAL);
4067afc7756SAlex Wilson 	} else {
4077afc7756SAlex Wilson 		err = roster->GetNodeFor(node_id, &node);
4087afc7756SAlex Wilson 	}
4097afc7756SAlex Wilson 
4107afc7756SAlex Wilson 	if (err == B_OK) {
4117afc7756SAlex Wilson 		int32 inputCount = 4;
4127afc7756SAlex Wilson 		media_input* inputs = new media_input[inputCount];
4137afc7756SAlex Wilson 		BPrivate::ArrayDeleter<media_input> inputDeleter(inputs);
4147afc7756SAlex Wilson 
4157afc7756SAlex Wilson 		while (true) {
4167afc7756SAlex Wilson 			int32 realInputCount = 0;
4177afc7756SAlex Wilson 			err = roster->GetAllInputsFor(node, inputs,
4187afc7756SAlex Wilson 				inputCount, &realInputCount);
4197afc7756SAlex Wilson 			if (realInputCount > inputCount) {
4207afc7756SAlex Wilson 				inputCount *= 2;
4217afc7756SAlex Wilson 				inputs = new media_input[inputCount];
4227afc7756SAlex Wilson 				inputDeleter.SetTo(inputs);
4237afc7756SAlex Wilson 			} else {
4247afc7756SAlex Wilson 				inputCount = realInputCount;
4257afc7756SAlex Wilson 				break;
4267afc7756SAlex Wilson 			}
4277afc7756SAlex Wilson 		}
4287afc7756SAlex Wilson 
4297afc7756SAlex Wilson 		if (err == B_OK) {
4307afc7756SAlex Wilson 			BMessage message(ML_DEFAULT_CHANNEL_CHANGED);
4317afc7756SAlex Wilson 
4327afc7756SAlex Wilson 			for (int32 i = 0; i < inputCount; i++) {
4337afc7756SAlex Wilson 				media_input* input = new media_input();
4347afc7756SAlex Wilson 				memcpy(input, &inputs[i], sizeof(*input));
4357afc7756SAlex Wilson 				ChannelMenuItem* channelItem = new ChannelMenuItem(input,
4367afc7756SAlex Wilson 					new BMessage(message));
4377afc7756SAlex Wilson 				fChannelMenu->AddItem(channelItem);
4387afc7756SAlex Wilson 
4397afc7756SAlex Wilson 				if (channelItem->DestinationID() == 0)
4407afc7756SAlex Wilson 					channelItem->SetMarked(true);
4417afc7756SAlex Wilson 			}
4427afc7756SAlex Wilson 		}
4437afc7756SAlex Wilson 	}
4447afc7756SAlex Wilson 
4457afc7756SAlex Wilson 	if (Window())
4467afc7756SAlex Wilson 		fChannelMenu->SetTargetForItems(BMessenger(this));
4477afc7756SAlex Wilson }
4487afc7756SAlex Wilson 
4497afc7756SAlex Wilson 
4507afc7756SAlex Wilson void
4517afc7756SAlex Wilson AudioSettingsView::_ShowDeskbarVolumeControl()
4527afc7756SAlex Wilson {
4537afc7756SAlex Wilson 	BDeskbar deskbar;
4547afc7756SAlex Wilson 	BEntry entry("/bin/desklink", true);
4557afc7756SAlex Wilson 	int32 id;
4567afc7756SAlex Wilson 	entry_ref ref;
4577afc7756SAlex Wilson 	status_t status = entry.GetRef(&ref);
4587afc7756SAlex Wilson 	if (status == B_OK)
4597afc7756SAlex Wilson 		status = deskbar.AddItem(&ref, &id);
4607afc7756SAlex Wilson 
4617afc7756SAlex Wilson 	if (status != B_OK) {
4627afc7756SAlex Wilson 		fprintf(stderr, B_TRANSLATE(
4637afc7756SAlex Wilson 			"Couldn't add volume control in Deskbar: %s\n"),
4647afc7756SAlex Wilson 			strerror(status));
4657afc7756SAlex Wilson 	}
4667afc7756SAlex Wilson }
4677afc7756SAlex Wilson 
4687afc7756SAlex Wilson 
4697afc7756SAlex Wilson void
4707afc7756SAlex Wilson AudioSettingsView::_HideDeskbarVolumeControl()
4717afc7756SAlex Wilson {
4727afc7756SAlex Wilson 	BDeskbar deskbar;
4737afc7756SAlex Wilson 	status_t status = deskbar.RemoveItem("MediaReplicant");
4747afc7756SAlex Wilson 	if (status != B_OK) {
4757afc7756SAlex Wilson 		fprintf(stderr, B_TRANSLATE(
4767afc7756SAlex Wilson 			"Couldn't remove volume control in Deskbar: %s\n"),
4777afc7756SAlex Wilson 			strerror(status));
4787afc7756SAlex Wilson 	}
4797afc7756SAlex Wilson }
4807afc7756SAlex Wilson 
4817afc7756SAlex Wilson 
4827afc7756SAlex Wilson ChannelMenuItem*
4837afc7756SAlex Wilson AudioSettingsView::_ChannelMenuItemAt(int32 index)
4847afc7756SAlex Wilson {
4857afc7756SAlex Wilson 	return static_cast<ChannelMenuItem*>(fChannelMenu->ItemAt(index));
4867afc7756SAlex Wilson }
4877afc7756SAlex Wilson 
4887afc7756SAlex Wilson 
4897afc7756SAlex Wilson VideoSettingsView::VideoSettingsView()
4907afc7756SAlex Wilson {
4917afc7756SAlex Wilson 	BBox* defaultsBox = new BBox("defaults");
4927afc7756SAlex Wilson 	defaultsBox->SetLabel(B_TRANSLATE("Defaults"));
4937afc7756SAlex Wilson 	BGridView* defaultsGridView = new BGridView();
4947afc7756SAlex Wilson 
4957afc7756SAlex Wilson 	BMenuField* inputMenuField = new BMenuField("inputMenuField",
49610dfe897SAxel Dörfler 		B_TRANSLATE("Video input:"), InputMenu());
4977afc7756SAlex Wilson 
4987afc7756SAlex Wilson 	BMenuField* outputMenuField = new BMenuField("outputMenuField",
49910dfe897SAxel Dörfler 		B_TRANSLATE("Video output:"), OutputMenu());
5007afc7756SAlex Wilson 
5017afc7756SAlex Wilson 	BLayoutBuilder::Grid<>(defaultsGridView)
502c97121d3SAlex Wilson 		.SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING,
503c97121d3SAlex Wilson 			B_USE_DEFAULT_SPACING)
5047afc7756SAlex Wilson 		.AddMenuField(inputMenuField, 0, 0)
505c97121d3SAlex Wilson 		.AddMenuField(outputMenuField, 0, 1);
5067afc7756SAlex Wilson 
5077afc7756SAlex Wilson 	defaultsBox->AddChild(defaultsGridView);
5087afc7756SAlex Wilson 
509c97121d3SAlex Wilson 	BLayoutBuilder::Group<>(this)
5107afc7756SAlex Wilson 		.SetInsets(0, 0, 0, 0)
511c97121d3SAlex Wilson 		.Add(defaultsBox)
512c97121d3SAlex Wilson 		.AddGroup(B_HORIZONTAL)
513c97121d3SAlex Wilson 			.AddGlue()
514c97121d3SAlex Wilson 			.Add(MakeRestartButton())
515c97121d3SAlex Wilson 			.End()
516c97121d3SAlex Wilson 		.AddGlue();
5177afc7756SAlex Wilson }
5187afc7756SAlex Wilson 
5197afc7756SAlex Wilson 
5207afc7756SAlex Wilson void
5217afc7756SAlex Wilson VideoSettingsView::SetDefaultInput(const dormant_node_info* info)
5227afc7756SAlex Wilson {
5237afc7756SAlex Wilson 	SettingsView::SetDefaultInput(info);
5247afc7756SAlex Wilson 	_MediaWindow()->UpdateInputListItem(MediaListItem::VIDEO_TYPE, info);
5257afc7756SAlex Wilson 	BMediaRoster::Roster()->SetVideoInput(*info);
5267afc7756SAlex Wilson }
5277afc7756SAlex Wilson 
5287afc7756SAlex Wilson 
5297afc7756SAlex Wilson void
5307afc7756SAlex Wilson VideoSettingsView::SetDefaultOutput(const dormant_node_info* info)
5317afc7756SAlex Wilson {
5327afc7756SAlex Wilson 	SettingsView::SetDefaultOutput(info);
5337afc7756SAlex Wilson 	_MediaWindow()->UpdateOutputListItem(MediaListItem::VIDEO_TYPE, info);
5347afc7756SAlex Wilson 	BMediaRoster::Roster()->SetVideoOutput(*info);
5357afc7756SAlex Wilson }
536