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 -------------------------------------------------------------------------------------------------- // 18*f8a1135cSAdrien Destugues #include <stdio.h> 19*f8a1135cSAdrien Destugues 20a10cf76eSAxel Dörfler #include <Box.h> 21a10cf76eSAxel Dörfler #include <Button.h> 22*f8a1135cSAdrien Destugues #include <Catalog.h> 23a10cf76eSAxel Dörfler #include <Deskbar.h> 24a10cf76eSAxel Dörfler #include <Entry.h> 25*f8a1135cSAdrien Destugues #include <GroupView.h> 26*f8a1135cSAdrien Destugues #include <Locale.h> 27a10cf76eSAxel Dörfler #include <MediaAddOn.h> 28*f8a1135cSAdrien Destugues #include <MediaRoster.h> 29*f8a1135cSAdrien Destugues #include <MenuField.h> 30*f8a1135cSAdrien Destugues #include <PopUpMenu.h> 31*f8a1135cSAdrien Destugues #include <SpaceLayoutItem.h> 32a10cf76eSAxel Dörfler #include <String.h> 33b4a12470SJérôme Duval #include <TextView.h> 342af5f895SStephan Aßmus 35a10cf76eSAxel Dörfler #include "MediaViews.h" 36a10cf76eSAxel Dörfler 37*f8a1135cSAdrien Destugues #define TR_CONTEXT "Media views" 38*f8a1135cSAdrien Destugues 39c8602bcdSRene Gollent BarView::BarView() 40c8602bcdSRene Gollent : BView ("barView", B_WILL_DRAW ), 41b4a12470SJérôme Duval fDisplay(true) 42a10cf76eSAxel Dörfler { 43a10cf76eSAxel Dörfler } 44a10cf76eSAxel Dörfler 45a10cf76eSAxel Dörfler void 46a10cf76eSAxel Dörfler BarView::Draw(BRect updateRect) 47a10cf76eSAxel Dörfler { 48a10cf76eSAxel Dörfler BRect r = Bounds(); 49a10cf76eSAxel Dörfler 50b4a12470SJérôme Duval if (fDisplay) { 51a10cf76eSAxel Dörfler // Display the 3D Look Divider Bar 52a10cf76eSAxel Dörfler SetHighColor(140,140,140,0); 53a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 54a10cf76eSAxel Dörfler SetHighColor(255,255,255,0); 55a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 56a10cf76eSAxel Dörfler } else { 57a10cf76eSAxel Dörfler SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 58a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 59a10cf76eSAxel Dörfler StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 60a10cf76eSAxel Dörfler } 61a10cf76eSAxel Dörfler } 62a10cf76eSAxel Dörfler 63a10cf76eSAxel Dörfler 64c8602bcdSRene Gollent SettingsView::SettingsView (bool isVideo) 65c8602bcdSRene Gollent : BView ("SettingsView", B_WILL_DRAW | B_SUPPORTS_LAYOUT), 66b4a12470SJérôme Duval fIsVideo(isVideo) 67a10cf76eSAxel Dörfler { 68a10cf76eSAxel Dörfler SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 692af5f895SStephan Aßmus 70c8602bcdSRene Gollent BBox *defaultsBox = new BBox("defaults"); 71*f8a1135cSAdrien Destugues defaultsBox->SetLabel(fIsVideo ? TR("Default Nodes") : TR("Defaults")); 722af5f895SStephan Aßmus 732af5f895SStephan Aßmus // create the default box 742af5f895SStephan Aßmus BGroupLayout* defaultBoxLayout = new BGroupLayout(B_VERTICAL, 5); 75c8602bcdSRene Gollent defaultBoxLayout->SetInsets(10,10,10,10); 762af5f895SStephan Aßmus defaultsBox->SetLayout(defaultBoxLayout); 772af5f895SStephan Aßmus defaultBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5)); 782af5f895SStephan Aßmus 792af5f895SStephan Aßmus BGroupView* inputField = new BGroupView(B_HORIZONTAL); 802af5f895SStephan Aßmus BGroupView* outputField = new BGroupView(B_HORIZONTAL); 812af5f895SStephan Aßmus defaultsBox->GetLayout()->AddView(inputField); 822af5f895SStephan Aßmus defaultsBox->GetLayout()->AddView(outputField); 83a10cf76eSAxel Dörfler 84*f8a1135cSAdrien Destugues float divider = StringWidth(fIsVideo ? TR("Video Output:") 85*f8a1135cSAdrien Destugues : TR("Audio Output:")) + 5; 86b4a12470SJérôme Duval fMenu1 = new BPopUpMenu("<none>"); 87b4a12470SJérôme Duval fMenu1->SetLabelFromMarked(true); 88c8602bcdSRene Gollent BMenuField *menuField1 = new BMenuField("menuField1", 89*f8a1135cSAdrien Destugues fIsVideo ? TR("Video Input:") : TR("Audio Input:"), fMenu1, NULL); 90aaa9b739SJérôme Duval menuField1->SetDivider(divider); 91a10cf76eSAxel Dörfler 92b4a12470SJérôme Duval fMenu2 = new BPopUpMenu("<none>"); 93b4a12470SJérôme Duval fMenu2->SetLabelFromMarked(true); 94c8602bcdSRene Gollent BMenuField *menuField2 = new BMenuField("menuField2", 95*f8a1135cSAdrien Destugues fIsVideo ? TR("Video Output:") : TR("Audio Output:"), fMenu2, NULL); 96aaa9b739SJérôme Duval menuField2->SetDivider(divider); 97a10cf76eSAxel Dörfler 982af5f895SStephan Aßmus inputField->GroupLayout()->AddView(menuField1); 992af5f895SStephan Aßmus outputField->GroupLayout()->AddView(menuField2); 1002af5f895SStephan Aßmus 1012af5f895SStephan Aßmus BMenuField *menuField3 = NULL; 102b4a12470SJérôme Duval if (!fIsVideo) { 103b4a12470SJérôme Duval fMenu3 = new BPopUpMenu("<none>"); 104b4a12470SJérôme Duval fMenu3->SetLabelFromMarked(true); 105c8602bcdSRene Gollent menuField3 = new BMenuField("menuField3", 106*f8a1135cSAdrien Destugues TR("Channel:"), fMenu3, NULL); 1072af5f895SStephan Aßmus outputField->GroupLayout()->AddView(menuField3); 108*f8a1135cSAdrien Destugues menuField3->SetDivider(StringWidth(TR("Channel:"))+5); 109a10cf76eSAxel Dörfler } 110a10cf76eSAxel Dörfler 111a10cf76eSAxel Dörfler rgb_color red_color = {222, 32, 33}; 112c8602bcdSRene Gollent fRestartView = new BStringView("restartStringView", 113*f8a1135cSAdrien Destugues TR("Restart the Media Server to apply changes.")); 114b4a12470SJérôme Duval fRestartView->SetHighColor(red_color); 115b4a12470SJérôme Duval defaultsBox->AddChild(fRestartView); 116b4a12470SJérôme Duval fRestartView->Hide(); 117a10cf76eSAxel Dörfler 1182af5f895SStephan Aßmus // create the realtime box 119c8602bcdSRene Gollent BBox *realtimeBox = new BBox("realtime"); 120*f8a1135cSAdrien Destugues realtimeBox->SetLabel(TR("Real-Time")); 121a10cf76eSAxel Dörfler 122a10cf76eSAxel Dörfler BMessage *message = new BMessage(ML_ENABLE_REAL_TIME); 123b4a12470SJérôme Duval message->AddBool("isVideo", fIsVideo); 124c8602bcdSRene Gollent fRealtimeCheckBox = new BCheckBox("realtimeCheckBox", 125*f8a1135cSAdrien Destugues fIsVideo ? TR("Enable Real-Time Video") : TR("Enable Real-Time Audio"), 126c8602bcdSRene Gollent message); 127a10cf76eSAxel Dörfler 128a10cf76eSAxel Dörfler uint32 flags; 129a10cf76eSAxel Dörfler BMediaRoster::Roster()->GetRealtimeFlags(&flags); 130b4a12470SJérôme Duval if (flags & (fIsVideo ? B_MEDIA_REALTIME_VIDEO : B_MEDIA_REALTIME_AUDIO)) 131b4a12470SJérôme Duval fRealtimeCheckBox->SetValue(B_CONTROL_ON); 132a10cf76eSAxel Dörfler 133c8602bcdSRene Gollent BTextView *textView = new BTextView("stringView"); 134*f8a1135cSAdrien Destugues textView->Insert(fIsVideo ? TR("Enabling Real-Time Video allows system to " 135*f8a1135cSAdrien Destugues "perform video operations as fast and smoothly as possible. It " 136*f8a1135cSAdrien Destugues "achieves optimum performance by using more RAM." 137*f8a1135cSAdrien Destugues "\n\nOnly enable this feature if you need the lowest latency possible.") 138*f8a1135cSAdrien Destugues : TR("Enabling Real-time Audio allows system to record and play audio " 139*f8a1135cSAdrien Destugues "as fast as possible. It achieves this performance by using more CPU and RAM." 140*f8a1135cSAdrien Destugues "\n\nOnly enable this feature if you need the lowest latency possible.")); 141b4a12470SJérôme Duval textView->MakeEditable(false); 142b4a12470SJérôme Duval textView->MakeSelectable(false); 143a10cf76eSAxel Dörfler textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 144a10cf76eSAxel Dörfler 1452af5f895SStephan Aßmus BGroupLayout* realtimeBoxLayout = new BGroupLayout(B_VERTICAL, 5); 146c8602bcdSRene Gollent realtimeBoxLayout->SetInsets(10,10,10,10); 1472af5f895SStephan Aßmus realtimeBox->SetLayout(realtimeBoxLayout); 1482af5f895SStephan Aßmus 1492af5f895SStephan Aßmus realtimeBoxLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(5)); 1502af5f895SStephan Aßmus realtimeBoxLayout->AddView(fRealtimeCheckBox); 1512af5f895SStephan Aßmus realtimeBoxLayout->AddView(textView); 1522af5f895SStephan Aßmus 1532af5f895SStephan Aßmus // create the bottom line: volumen in deskbar checkbox and restart button 1542af5f895SStephan Aßmus BGroupView* bottomView = new BGroupView(B_HORIZONTAL); 155c8602bcdSRene Gollent BButton *restartButton = new BButton("restartButton", 156*f8a1135cSAdrien Destugues TR("Restart Media Services"), new BMessage(ML_RESTART_MEDIA_SERVER)); 157a10cf76eSAxel Dörfler 158b4a12470SJérôme Duval if (!fIsVideo) { 159c8602bcdSRene Gollent fVolumeCheckBox = new BCheckBox("volumeCheckBox", 160*f8a1135cSAdrien Destugues TR("Show Volume Control on Deskbar"), new BMessage(ML_SHOW_VOLUME_CONTROL)); 1612af5f895SStephan Aßmus bottomView->GroupLayout()->AddView(fVolumeCheckBox); 162a10cf76eSAxel Dörfler if (BDeskbar().HasItem("MediaReplicant")) 163b4a12470SJérôme Duval fVolumeCheckBox->SetValue(B_CONTROL_ON); 164a10cf76eSAxel Dörfler } 1652af5f895SStephan Aßmus else{ 1662af5f895SStephan Aßmus bottomView->GroupLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); 1672af5f895SStephan Aßmus } 1682af5f895SStephan Aßmus bottomView->GroupLayout()->AddView(restartButton); 1692af5f895SStephan Aßmus 1702af5f895SStephan Aßmus // compose all stuff 1712af5f895SStephan Aßmus BGroupLayout* rootlayout = new BGroupLayout(B_VERTICAL, 5); 1722af5f895SStephan Aßmus SetLayout(rootlayout); 1732af5f895SStephan Aßmus 1742af5f895SStephan Aßmus rootlayout->AddView(defaultsBox); 1752af5f895SStephan Aßmus rootlayout->AddView(realtimeBox); 1762af5f895SStephan Aßmus rootlayout->AddView(bottomView); 177a10cf76eSAxel Dörfler } 178a10cf76eSAxel Dörfler 179a10cf76eSAxel Dörfler void 180a10cf76eSAxel Dörfler SettingsView::AddNodes(BList &list, bool isInput) 181a10cf76eSAxel Dörfler { 182b4a12470SJérôme Duval BMenu *menu = isInput ? fMenu1 : fMenu2; 183a10cf76eSAxel Dörfler void *item; 184a10cf76eSAxel Dörfler while ((item = menu->RemoveItem((int32)0)) != NULL) 185a10cf76eSAxel Dörfler delete static_cast<dormant_node_info *>(item); 186a10cf76eSAxel Dörfler 187a10cf76eSAxel Dörfler BMessage message(ML_DEFAULT_CHANGE); 188b4a12470SJérôme Duval message.AddBool("isVideo", fIsVideo); 189a10cf76eSAxel Dörfler message.AddBool("isInput", isInput); 190a10cf76eSAxel Dörfler 191a10cf76eSAxel Dörfler for (int32 i = 0; i < list.CountItems(); i++) { 192a10cf76eSAxel Dörfler dormant_node_info *info = static_cast<dormant_node_info *>(list.ItemAt(i)); 193a10cf76eSAxel Dörfler menu->AddItem(new SettingsItem(info, new BMessage(message))); 194a10cf76eSAxel Dörfler } 195a10cf76eSAxel Dörfler } 196a10cf76eSAxel Dörfler 197a10cf76eSAxel Dörfler void 198a10cf76eSAxel Dörfler SettingsView::SetDefault(dormant_node_info &info, bool isInput, int32 outputID) 199a10cf76eSAxel Dörfler { 200b4a12470SJérôme Duval BMenu *menu = isInput ? fMenu1 : fMenu2; 201a10cf76eSAxel Dörfler 202a10cf76eSAxel Dörfler for (int32 i = 0; i < menu->CountItems(); i++) { 203a10cf76eSAxel Dörfler SettingsItem *item = static_cast<SettingsItem *>(menu->ItemAt(i)); 204b4a12470SJérôme Duval if (item->fInfo && item->fInfo->addon == info.addon && item->fInfo->flavor_id == info.flavor_id) { 205a10cf76eSAxel Dörfler item->SetMarked(true); 206a10cf76eSAxel Dörfler break; 207a10cf76eSAxel Dörfler } 208a10cf76eSAxel Dörfler } 209a10cf76eSAxel Dörfler 210b4a12470SJérôme Duval if (!fIsVideo&&!isInput&&outputID>-1) { 211a10cf76eSAxel Dörfler BMenuItem *item; 212b4a12470SJérôme Duval while ((item = fMenu3->RemoveItem((int32)0)) != NULL) 213a10cf76eSAxel Dörfler delete item; 214a10cf76eSAxel Dörfler BMediaRoster *roster = BMediaRoster::Roster(); 215a10cf76eSAxel Dörfler media_node node; 216a10cf76eSAxel Dörfler media_node_id node_id; 217a10cf76eSAxel Dörfler status_t err; 218a10cf76eSAxel Dörfler if (roster->GetInstancesFor(info.addon, info.flavor_id, &node_id)!=B_OK) 219a10cf76eSAxel Dörfler err = roster->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL); 220a10cf76eSAxel Dörfler else 221a10cf76eSAxel Dörfler err = roster->GetNodeFor(node_id, &node); 222a10cf76eSAxel Dörfler 223a10cf76eSAxel Dörfler if (err == B_OK) { 224a10cf76eSAxel Dörfler media_input inputs[16]; 225a10cf76eSAxel Dörfler int32 inputCount = 16; 226a10cf76eSAxel Dörfler if (roster->GetAllInputsFor(node, inputs, 16, &inputCount)==B_OK) { 227a10cf76eSAxel Dörfler BMessage message(ML_DEFAULTOUTPUT_CHANGE); 228a10cf76eSAxel Dörfler 229a10cf76eSAxel Dörfler for (int32 i = 0; i < inputCount; i++) { 230a10cf76eSAxel Dörfler media_input *input = new media_input(); 231a10cf76eSAxel Dörfler memcpy(input, &inputs[i], sizeof(*input)); 232b4a12470SJérôme Duval fMenu3->AddItem(item = new Settings2Item(&info, input, new BMessage(message))); 233a10cf76eSAxel Dörfler if (inputs[i].destination.id == outputID) 234a10cf76eSAxel Dörfler item->SetMarked(true); 235a10cf76eSAxel Dörfler } 236a10cf76eSAxel Dörfler } 237a10cf76eSAxel Dörfler } 238a10cf76eSAxel Dörfler } 239a10cf76eSAxel Dörfler } 240a10cf76eSAxel Dörfler 241a10cf76eSAxel Dörfler SettingsItem::SettingsItem(dormant_node_info *info, BMessage *message, 242a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 243a10cf76eSAxel Dörfler : BMenuItem(info->name, message, shortcut, modifiers), 244b4a12470SJérôme Duval fInfo(info) 245a10cf76eSAxel Dörfler { 246a10cf76eSAxel Dörfler 247a10cf76eSAxel Dörfler } 248a10cf76eSAxel Dörfler 2496df0b2d5SJérôme Duval 2506df0b2d5SJérôme Duval status_t 2516df0b2d5SJérôme Duval SettingsItem::Invoke(BMessage *message) 2526df0b2d5SJérôme Duval { 2536df0b2d5SJérôme Duval if (IsMarked()) 2546df0b2d5SJérôme Duval return B_OK; 2556df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2566df0b2d5SJérôme Duval } 2576df0b2d5SJérôme Duval 2586df0b2d5SJérôme Duval 259a10cf76eSAxel Dörfler Settings2Item::Settings2Item(dormant_node_info *info, media_input *input, BMessage *message, 260a10cf76eSAxel Dörfler char shortcut, uint32 modifiers) 261a10cf76eSAxel Dörfler : BMenuItem(input->name, message, shortcut, modifiers), 262b4a12470SJérôme Duval fInfo(info), 263b4a12470SJérôme Duval fInput(input) 264a10cf76eSAxel Dörfler { 265a10cf76eSAxel Dörfler 266a10cf76eSAxel Dörfler } 267a10cf76eSAxel Dörfler 2686df0b2d5SJérôme Duval 269a10cf76eSAxel Dörfler Settings2Item::~Settings2Item() 270a10cf76eSAxel Dörfler { 271b4a12470SJérôme Duval delete fInput; 272a10cf76eSAxel Dörfler } 273a10cf76eSAxel Dörfler 2746df0b2d5SJérôme Duval 2756df0b2d5SJérôme Duval status_t 2766df0b2d5SJérôme Duval Settings2Item::Invoke(BMessage *message) 2776df0b2d5SJérôme Duval { 2786df0b2d5SJérôme Duval if (IsMarked()) 2796df0b2d5SJérôme Duval return B_OK; 2806df0b2d5SJérôme Duval return BMenuItem::Invoke(message); 2816df0b2d5SJérôme Duval } 2826df0b2d5SJérôme Duval 283