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 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 15a10cf76eSAxel Dörfler 16a10cf76eSAxel Dörfler 17a10cf76eSAxel Dörfler // Includes -------------------------------------------------------------------------------------------------- // 18a10cf76eSAxel Dörfler #include <Box.h> 19a10cf76eSAxel Dörfler #include <Button.h> 20a10cf76eSAxel Dörfler #include <MenuField.h> 21a10cf76eSAxel Dörfler #include <PopUpMenu.h> 22a10cf76eSAxel Dörfler #include <MediaRoster.h> 23a10cf76eSAxel Dörfler #include <Deskbar.h> 24a10cf76eSAxel Dörfler #include <Entry.h> 25a10cf76eSAxel Dörfler #include <stdio.h> 26a10cf76eSAxel Dörfler #include <MediaAddOn.h> 27a10cf76eSAxel Dörfler #include <String.h> 28b4a12470SJérôme Duval #include <TextView.h> 292af5f895SStephan Aßmus #include <GroupView.h> 302af5f895SStephan Aßmus #include <SpaceLayoutItem.h> 312af5f895SStephan Aßmus 32a10cf76eSAxel Dörfler #include "MediaViews.h" 33a10cf76eSAxel Dörfler 34*c8602bcdSRene Gollent BarView::BarView() 35*c8602bcdSRene Gollent : BView ("barView", B_WILL_DRAW ), 36b4a12470SJérôme Duval fDisplay(true) 37a10cf76eSAxel Dörfler { 38a10cf76eSAxel Dörfler } 39a10cf76eSAxel Dörfler 40a10cf76eSAxel Dörfler void 41a10cf76eSAxel Dörfler BarView::Draw(BRect updateRect) 42a10cf76eSAxel Dörfler { 43a10cf76eSAxel Dörfler BRect r = Bounds(); 44a10cf76eSAxel Dörfler 45b4a12470SJérôme Duval if (fDisplay) { 46a10cf76eSAxel Dörfler // Display the 3D Look Divider Bar 47a10cf76eSAxel Dörfler SetHighColor(140,140,140,0); 48a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 49a10cf76eSAxel Dörfler SetHighColor(255,255,255,0); 50a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 51a10cf76eSAxel Dörfler } else { 52a10cf76eSAxel Dörfler SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 53a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 54a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 55a10cf76eSAxel Dörfler } 56a10cf76eSAxel Dörfler } 57a10cf76eSAxel Dörfler 58a10cf76eSAxel Dörfler 59*c8602bcdSRene Gollent SettingsView::SettingsView (bool isVideo) 60*c8602bcdSRene Gollent : BView ("SettingsView", B_WILL_DRAW | B_SUPPORTS_LAYOUT), 61b4a12470SJérôme Duval fIsVideo(isVideo) 62a10cf76eSAxel Dörfler { 63a10cf76eSAxel Dörfler SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 642af5f895SStephan Aßmus 65*c8602bcdSRene Gollent BBox *defaultsBox = new BBox("defaults"); 66b4a12470SJérôme Duval defaultsBox->SetLabel(fIsVideo ? "Default Nodes" : "Defaults"); 672af5f895SStephan Aßmus 682af5f895SStephan Aßmus // create the default box 692af5f895SStephan Aßmus BGroupLayout* defaultBoxLayout = new BGroupLayout(B_VERTICAL, 5); 70*c8602bcdSRene Gollent defaultBoxLayout->SetInsets(10,10,10,10); 712af5f895SStephan Aßmus defaultsBox->SetLayout(defaultBoxLayout); 722af5f895SStephan Aßmus defaultBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5)); 732af5f895SStephan Aßmus 742af5f895SStephan Aßmus BGroupView* inputField = new BGroupView(B_HORIZONTAL); 752af5f895SStephan Aßmus BGroupView* outputField = new BGroupView(B_HORIZONTAL); 762af5f895SStephan Aßmus defaultsBox->GetLayout()->AddView(inputField); 772af5f895SStephan Aßmus defaultsBox->GetLayout()->AddView(outputField); 78a10cf76eSAxel Dörfler 79b4a12470SJérôme Duval float divider = StringWidth(fIsVideo ? "Video Output:" : "Audio Output:") + 5; 80b4a12470SJérôme Duval fMenu1 = new BPopUpMenu("<none>"); 81b4a12470SJérôme Duval fMenu1->SetLabelFromMarked(true); 82*c8602bcdSRene Gollent BMenuField *menuField1 = new BMenuField("menuField1", 83*c8602bcdSRene Gollent fIsVideo ? "Video Input:" : "Audio Input:", fMenu1, NULL); 84aaa9b739SJérôme Duval menuField1->SetDivider(divider); 85a10cf76eSAxel Dörfler 86b4a12470SJérôme Duval fMenu2 = new BPopUpMenu("<none>"); 87b4a12470SJérôme Duval fMenu2->SetLabelFromMarked(true); 88*c8602bcdSRene Gollent BMenuField *menuField2 = new BMenuField("menuField2", 89*c8602bcdSRene Gollent fIsVideo ? "Video Output:" : "Audio Output:", fMenu2, NULL); 90aaa9b739SJérôme Duval menuField2->SetDivider(divider); 91a10cf76eSAxel Dörfler 922af5f895SStephan Aßmus inputField->GroupLayout()->AddView(menuField1); 932af5f895SStephan Aßmus outputField->GroupLayout()->AddView(menuField2); 942af5f895SStephan Aßmus 952af5f895SStephan Aßmus BMenuField *menuField3 = NULL; 96b4a12470SJérôme Duval if (!fIsVideo) { 97b4a12470SJérôme Duval fMenu3 = new BPopUpMenu("<none>"); 98b4a12470SJérôme Duval fMenu3->SetLabelFromMarked(true); 99*c8602bcdSRene Gollent menuField3 = new BMenuField("menuField3", 100*c8602bcdSRene Gollent "Channel:", fMenu3, NULL); 1012af5f895SStephan Aßmus outputField->GroupLayout()->AddView(menuField3); 102b4a12470SJérôme Duval menuField3->SetDivider(StringWidth("Channel:")+5); 103a10cf76eSAxel Dörfler } 104a10cf76eSAxel Dörfler 105a10cf76eSAxel Dörfler rgb_color red_color = {222, 32, 33}; 106*c8602bcdSRene Gollent fRestartView = new BStringView("restartStringView", 107*c8602bcdSRene Gollent "Restart the Media Server to apply changes."); 108b4a12470SJérôme Duval fRestartView->SetHighColor(red_color); 109b4a12470SJérôme Duval defaultsBox->AddChild(fRestartView); 110b4a12470SJérôme Duval fRestartView->Hide(); 111a10cf76eSAxel Dörfler 1122af5f895SStephan Aßmus // create the realtime box 113*c8602bcdSRene Gollent BBox *realtimeBox = new BBox("realtime"); 114a10cf76eSAxel Dörfler realtimeBox->SetLabel("Real-Time"); 115a10cf76eSAxel Dörfler 116a10cf76eSAxel Dörfler BMessage *message = new BMessage(ML_ENABLE_REAL_TIME); 117b4a12470SJérôme Duval message->AddBool("isVideo", fIsVideo); 118*c8602bcdSRene Gollent fRealtimeCheckBox = new BCheckBox("realtimeCheckBox", 119*c8602bcdSRene Gollent fIsVideo ? "Enable Real-Time Video" : "Enable Real-Time Audio", 120*c8602bcdSRene Gollent message); 121a10cf76eSAxel Dörfler 122a10cf76eSAxel Dörfler uint32 flags; 123a10cf76eSAxel Dörfler BMediaRoster::Roster()->GetRealtimeFlags(&flags); 124b4a12470SJérôme Duval if (flags & (fIsVideo ? B_MEDIA_REALTIME_VIDEO : B_MEDIA_REALTIME_AUDIO)) 125b4a12470SJérôme Duval fRealtimeCheckBox->SetValue(B_CONTROL_ON); 126a10cf76eSAxel Dörfler 127*c8602bcdSRene Gollent BTextView *textView = new BTextView("stringView"); 128774e87aaSPhilippe Houdoin textView->Insert(fIsVideo ? "Enabling Real-Time Video allows system to perform video operations as fast and smoothly as possible. It achieves optimum performance by using more RAM." 129b4a12470SJérôme Duval "\n\nOnly enable this feature if you need the lowest latency possible." 130774e87aaSPhilippe Houdoin : "Enabling Real-time Audio allows system to record and play audio as fast as possible. It achieves this performance by using more CPU and RAM." 131b4a12470SJérôme Duval "\n\nOnly enable this feature if you need the lowest latency possible."); 132b4a12470SJérôme Duval textView->MakeEditable(false); 133b4a12470SJérôme Duval textView->MakeSelectable(false); 134a10cf76eSAxel Dörfler textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 135a10cf76eSAxel Dörfler 1362af5f895SStephan Aßmus BGroupLayout* realtimeBoxLayout = new BGroupLayout(B_VERTICAL, 5); 137*c8602bcdSRene Gollent realtimeBoxLayout->SetInsets(10,10,10,10); 1382af5f895SStephan Aßmus realtimeBox->SetLayout(realtimeBoxLayout); 1392af5f895SStephan Aßmus 1402af5f895SStephan Aßmus realtimeBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5)); 1412af5f895SStephan Aßmus realtimeBoxLayout->AddView(fRealtimeCheckBox); 1422af5f895SStephan Aßmus realtimeBoxLayout->AddView(textView); 1432af5f895SStephan Aßmus 1442af5f895SStephan Aßmus // create the bottom line: volumen in deskbar checkbox and restart button 1452af5f895SStephan Aßmus BGroupView* bottomView = new BGroupView(B_HORIZONTAL); 146*c8602bcdSRene Gollent BButton *restartButton = new BButton("restartButton", 147a10cf76eSAxel Dörfler "Restart Media Services", new BMessage(ML_RESTART_MEDIA_SERVER)); 148a10cf76eSAxel Dörfler 149b4a12470SJérôme Duval if (!fIsVideo) { 150*c8602bcdSRene Gollent fVolumeCheckBox = new BCheckBox("volumeCheckBox", 151a10cf76eSAxel Dörfler "Show Volume Control on Deskbar", new BMessage(ML_SHOW_VOLUME_CONTROL)); 1522af5f895SStephan Aßmus bottomView->GroupLayout()->AddView(fVolumeCheckBox); 153a10cf76eSAxel Dörfler if (BDeskbar().HasItem("MediaReplicant")) 154b4a12470SJérôme Duval fVolumeCheckBox->SetValue(B_CONTROL_ON); 155a10cf76eSAxel Dörfler } 1562af5f895SStephan Aßmus else{ 1572af5f895SStephan Aßmus bottomView->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); 1582af5f895SStephan Aßmus } 1592af5f895SStephan Aßmus bottomView->GroupLayout()->AddView(restartButton); 1602af5f895SStephan Aßmus 1612af5f895SStephan Aßmus // compose all stuff 1622af5f895SStephan Aßmus BGroupLayout* rootlayout = new BGroupLayout(B_VERTICAL, 5); 1632af5f895SStephan Aßmus SetLayout(rootlayout); 1642af5f895SStephan Aßmus 1652af5f895SStephan Aßmus rootlayout->AddView(defaultsBox); 1662af5f895SStephan Aßmus rootlayout->AddView(realtimeBox); 1672af5f895SStephan Aßmus rootlayout->AddView(bottomView); 168a10cf76eSAxel Dörfler } 169a10cf76eSAxel Dörfler 170a10cf76eSAxel Dörfler void 171a10cf76eSAxel Dörfler SettingsView::AddNodes(BList &list, bool isInput) 172a10cf76eSAxel Dörfler { 173b4a12470SJérôme Duval BMenu *menu = isInput ? fMenu1 : fMenu2; 174a10cf76eSAxel Dörfler void *item; 175a10cf76eSAxel Dörfler while ((item = menu->RemoveItem((int32)0)) != NULL) 176a10cf76eSAxel Dörfler delete static_cast<dormant_node_info *>(item); 177a10cf76eSAxel Dörfler 178a10cf76eSAxel Dörfler BMessage message(ML_DEFAULT_CHANGE); 179b4a12470SJérôme Duval message.AddBool("isVideo", fIsVideo); 180a10cf76eSAxel Dörfler message.AddBool("isInput", isInput); 181a10cf76eSAxel Dörfler 182a10cf76eSAxel Dörfler for (int32 i = 0; i < list.CountItems(); i++) { 183a10cf76eSAxel Dörfler dormant_node_info *info = static_cast<dormant_node_info *>(list.ItemAt(i)); 184a10cf76eSAxel Dörfler menu->AddItem(new SettingsItem(info, new BMessage(message))); 185a10cf76eSAxel Dörfler } 186a10cf76eSAxel Dörfler } 187a10cf76eSAxel Dörfler 188a10cf76eSAxel Dörfler void 189a10cf76eSAxel Dörfler SettingsView::SetDefault(dormant_node_info &info, bool isInput, int32 outputID) 190a10cf76eSAxel Dörfler { 191b4a12470SJérôme Duval BMenu *menu = isInput ? fMenu1 : fMenu2; 192a10cf76eSAxel Dörfler 193a10cf76eSAxel Dörfler for (int32 i = 0; i < menu->CountItems(); i++) { 194a10cf76eSAxel Dörfler SettingsItem *item = static_cast<SettingsItem *>(menu->ItemAt(i)); 195b4a12470SJérôme Duval if (item->fInfo && item->fInfo->addon == info.addon && item->fInfo->flavor_id == info.flavor_id) { 196a10cf76eSAxel Dörfler item->SetMarked(true); 197a10cf76eSAxel Dörfler break; 198a10cf76eSAxel Dörfler } 199a10cf76eSAxel Dörfler } 200a10cf76eSAxel Dörfler 201b4a12470SJérôme Duval if (!fIsVideo&&!isInput&&outputID>-1) { 202a10cf76eSAxel Dörfler BMenuItem *item; 203b4a12470SJérôme Duval while ((item = fMenu3->RemoveItem((int32)0)) != NULL) 204a10cf76eSAxel Dörfler delete item; 205a10cf76eSAxel Dörfler BMediaRoster *roster = BMediaRoster::Roster(); 206a10cf76eSAxel Dörfler media_node node; 207a10cf76eSAxel Dörfler media_node_id node_id; 208a10cf76eSAxel Dörfler status_t err; 209a10cf76eSAxel Dörfler if (roster->GetInstancesFor(info.addon, info.flavor_id, &node_id)!=B_OK) 210a10cf76eSAxel Dörfler err = roster->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL); 211a10cf76eSAxel Dörfler else 212a10cf76eSAxel Dörfler err = roster->GetNodeFor(node_id, &node); 213a10cf76eSAxel Dörfler 214a10cf76eSAxel Dörfler if (err == B_OK) { 215a10cf76eSAxel Dörfler media_input inputs[16]; 216a10cf76eSAxel Dörfler int32 inputCount = 16; 217a10cf76eSAxel Dörfler if (roster->GetAllInputsFor(node, inputs, 16, &inputCount)==B_OK) { 218a10cf76eSAxel Dörfler BMessage message(ML_DEFAULTOUTPUT_CHANGE); 219a10cf76eSAxel Dörfler 220a10cf76eSAxel Dörfler for (int32 i = 0; i < inputCount; i++) { 221a10cf76eSAxel Dörfler media_input *input = new media_input(); 222a10cf76eSAxel Dörfler memcpy(input, &inputs[i], sizeof(*input)); 223b4a12470SJérôme Duval fMenu3->AddItem(item = new Settings2Item(&info, input, new BMessage(message))); 224a10cf76eSAxel Dörfler if (inputs[i].destination.id == outputID) 225a10cf76eSAxel Dörfler item->SetMarked(true); 226a10cf76eSAxel Dörfler } 227a10cf76eSAxel Dörfler } 228a10cf76eSAxel Dörfler } 229a10cf76eSAxel Dörfler } 230a10cf76eSAxel Dörfler } 231a10cf76eSAxel Dörfler 232a10cf76eSAxel Dörfler SettingsItem::SettingsItem(dormant_node_info *info, BMessage *message, 233a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 234a10cf76eSAxel Dörfler : BMenuItem(info->name, message, shortcut, modifiers), 235b4a12470SJérôme Duval fInfo(info) 236a10cf76eSAxel Dörfler { 237a10cf76eSAxel Dörfler 238a10cf76eSAxel Dörfler } 239a10cf76eSAxel Dörfler 2406df0b2d5SJérôme Duval 2416df0b2d5SJérôme Duval status_t 2426df0b2d5SJérôme Duval SettingsItem::Invoke(BMessage *message) 2436df0b2d5SJérôme Duval { 2446df0b2d5SJérôme Duval if (IsMarked()) 2456df0b2d5SJérôme Duval return B_OK; 2466df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2476df0b2d5SJérôme Duval } 2486df0b2d5SJérôme Duval 2496df0b2d5SJérôme Duval 250a10cf76eSAxel Dörfler Settings2Item::Settings2Item(dormant_node_info *info, media_input *input, BMessage *message, 251a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 252a10cf76eSAxel Dörfler : BMenuItem(input->name, message, shortcut, modifiers), 253b4a12470SJérôme Duval fInfo(info), 254b4a12470SJérôme Duval fInput(input) 255a10cf76eSAxel Dörfler { 256a10cf76eSAxel Dörfler 257a10cf76eSAxel Dörfler } 258a10cf76eSAxel Dörfler 2596df0b2d5SJérôme Duval 260a10cf76eSAxel Dörfler Settings2Item::~Settings2Item() 261a10cf76eSAxel Dörfler { 262b4a12470SJérôme Duval delete fInput; 263a10cf76eSAxel Dörfler } 264a10cf76eSAxel Dörfler 2656df0b2d5SJérôme Duval 2666df0b2d5SJérôme Duval status_t 2676df0b2d5SJérôme Duval Settings2Item::Invoke(BMessage *message) 2686df0b2d5SJérôme Duval { 2696df0b2d5SJérôme Duval if (IsMarked()) 2706df0b2d5SJérôme Duval return B_OK; 2716df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2726df0b2d5SJérôme Duval } 2736df0b2d5SJérôme Duval 274