1 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 2 // 3 // Copyright (c) 2003, OpenBeOS 4 // 5 // This software is part of the OpenBeOS distribution and is covered 6 // by the OpenBeOS license. 7 // 8 // 9 // File: MediaViews.cpp 10 // Author: Sikosis, Jérôme Duval 11 // Description: Media Preferences 12 // Created : June 25, 2003 13 // 14 // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ 15 16 17 // Includes -------------------------------------------------------------------------------------------------- // 18 #include <Box.h> 19 #include <Button.h> 20 #include <TextView.h> 21 #include <MenuField.h> 22 #include <PopUpMenu.h> 23 #include <MediaRoster.h> 24 #include <Deskbar.h> 25 #include <Entry.h> 26 #include <stdio.h> 27 #include <MediaAddOn.h> 28 #include <String.h> 29 #include "MediaViews.h" 30 31 BarView::BarView(BRect frame) 32 : BView (frame, "barView", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW ), 33 mDisplay(true) 34 { 35 } 36 37 void 38 BarView::Draw(BRect updateRect) 39 { 40 BRect r = Bounds(); 41 42 if(mDisplay) { 43 // Display the 3D Look Divider Bar 44 SetHighColor(140,140,140,0); 45 StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 46 SetHighColor(255,255,255,0); 47 StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 48 } else { 49 SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 50 StrokeLine(BPoint(r.left,r.top),BPoint(r.right,r.top)); 51 StrokeLine(BPoint(r.left,r.bottom),BPoint(r.right,r.bottom)); 52 } 53 } 54 55 56 SettingsView::SettingsView (BRect frame, bool isVideo) 57 : BView (frame, "SettingsView", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW ), 58 mIsVideo(isVideo) 59 { 60 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 61 BRect rect(frame); 62 rect.left += 10; 63 rect.top += 12; 64 rect.right -=21; 65 rect.bottom = rect.top + 104; 66 BBox *defaultsBox = new BBox(rect, "defaults"); 67 defaultsBox->SetLabel(mIsVideo ? "Default Nodes" : "Defaults"); 68 AddChild(defaultsBox); 69 70 BRect defaultRect(20, 22, 250, 40); 71 mMenu1 = new BPopUpMenu("<none>"); 72 mMenu1->SetLabelFromMarked(true); 73 BMenuField *menuField1 = new BMenuField(defaultRect, "menuField1", 74 mIsVideo ? "Video Input:" : "Audio Input:", mMenu1); 75 defaultsBox->AddChild(menuField1); 76 menuField1->SetDivider(75); 77 78 defaultRect.OffsetBy(0, 26); 79 mMenu2 = new BPopUpMenu("<none>"); 80 mMenu2->SetLabelFromMarked(true); 81 BMenuField *menuField2 = new BMenuField(defaultRect, "menuField2", 82 mIsVideo ? "Video Output:" : "Audio Output:", mMenu2); 83 defaultsBox->AddChild(menuField2); 84 menuField2->SetDivider(75); 85 86 if(!mIsVideo) { 87 defaultRect.OffsetBy(186, 0); 88 mMenu3 = new BPopUpMenu("<none>"); 89 mMenu3->SetLabelFromMarked(true); 90 BMenuField *mMenuField3 = new BMenuField(defaultRect, "menuField3", 91 "Channel:", mMenu3); 92 defaultsBox->AddChild(mMenuField3); 93 mMenuField3->SetDivider(50); 94 defaultRect.OffsetBy(-186, 0); 95 } 96 97 defaultRect.OffsetBy(0, 32); 98 BRect restartTextRect(defaultRect); 99 restartTextRect.OffsetTo(B_ORIGIN); 100 restartTextRect.InsetBy(1,1); 101 rgb_color red_color = {222, 32, 33}; 102 mRestartTextView = new BTextView(defaultRect, "restartTextView", restartTextRect, 103 be_plain_font, &red_color, B_FOLLOW_ALL, B_WILL_DRAW); 104 mRestartTextView->Insert("Restart the Media Server to apply changes."); 105 mRestartTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 106 defaultsBox->AddChild(mRestartTextView); 107 mRestartTextView->Hide(); 108 109 rect.top = rect.bottom + 10; 110 rect.bottom = rect.top + 162; 111 BBox *realtimeBox = new BBox(rect, "realtime"); 112 realtimeBox->SetLabel("Real-Time"); 113 AddChild(realtimeBox); 114 115 BMessage *message = new BMessage(ML_ENABLE_REAL_TIME); 116 message->AddBool("isVideo", mIsVideo); 117 BRect rect2(22,20, 190, 40); 118 mRealtimeCheckBox = new BCheckBox(rect2, "realtimeCheckBox", 119 mIsVideo ? "Enable Real-Time Video" : "Enable Real-Time Audio", message); 120 realtimeBox->AddChild(mRealtimeCheckBox); 121 122 uint32 flags; 123 BMediaRoster::Roster()->GetRealtimeFlags(&flags); 124 if(flags & (mIsVideo ? B_MEDIA_REALTIME_VIDEO : B_MEDIA_REALTIME_AUDIO)) 125 mRealtimeCheckBox->SetValue(B_CONTROL_ON); 126 127 rect2.top += 26; 128 rect2.bottom = rect2.top + 80; 129 rect2.right = rect.right - 15; 130 BRect textRect(3, 3, rect2.Width() - 3, rect2.Height() - 3); 131 BTextView *textView = new BTextView(rect2, "textView", textRect, B_FOLLOW_ALL, B_WILL_DRAW); 132 textView->Insert(mIsVideo ? "Enabling Real-Time Video allows the BeOS to perform video operations as fast and smoothly as possible. It achieves optimum performance by using more RAM." 133 : "Enabling Real-time Audio allows BeOS to record and play audio as fast as possible. It achieves this performance by using more CPU and RAM."); 134 textView->Insert("\n\nOnly enable this feature if you need the lowest latency possible."); 135 textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 136 realtimeBox->AddChild(textView); 137 138 rect.top = rect.bottom + 11; 139 rect.bottom = rect.top + 20; 140 rect.left = rect.right - 130; 141 BButton *restartButton = new BButton(rect, "restartButton", 142 "Restart Media Services", new BMessage(ML_RESTART_MEDIA_SERVER)); 143 AddChild(restartButton); 144 145 if(!mIsVideo) { 146 rect.top += 4; 147 rect.left = frame.left + 33; 148 rect.right = rect.left + 180; 149 150 mVolumeCheckBox = new BCheckBox(rect, "volumeCheckBox", 151 "Show Volume Control on Deskbar", new BMessage(ML_SHOW_VOLUME_CONTROL)); 152 AddChild(mVolumeCheckBox); 153 154 if(BDeskbar().HasItem("MediaReplicant")) 155 mVolumeCheckBox->SetValue(B_CONTROL_ON); 156 } 157 } 158 159 void 160 SettingsView::AddNodes(BList &list, bool isInput) 161 { 162 BMenu *menu = isInput ? mMenu1 : mMenu2; 163 void *item; 164 while ((item = menu->RemoveItem((int32)0)) != NULL) 165 delete static_cast<dormant_node_info *>(item); 166 167 BMessage message(ML_DEFAULT_CHANGE); 168 message.AddBool("isVideo", mIsVideo); 169 message.AddBool("isInput", isInput); 170 171 for (int32 i = 0; i < list.CountItems(); i++) { 172 dormant_node_info *info = static_cast<dormant_node_info *>(list.ItemAt(i)); 173 menu->AddItem(new SettingsItem(info, new BMessage(message))); 174 } 175 } 176 177 void 178 SettingsView::SetDefault(dormant_node_info &info, bool isInput, int32 outputID) 179 { 180 BMenu *menu = isInput ? mMenu1 : mMenu2; 181 182 for (int32 i = 0; i < menu->CountItems(); i++) { 183 SettingsItem *item = static_cast<SettingsItem *>(menu->ItemAt(i)); 184 if(item->mInfo && item->mInfo->addon == info.addon && item->mInfo->flavor_id == info.flavor_id) { 185 item->SetMarked(true); 186 break; 187 } 188 } 189 190 if (!mIsVideo&&!isInput&&outputID>-1) { 191 BMenuItem *item; 192 while ((item = mMenu3->RemoveItem((int32)0)) != NULL) 193 delete item; 194 BMediaRoster *roster = BMediaRoster::Roster(); 195 media_node node; 196 media_node_id node_id; 197 status_t err; 198 if (roster->GetInstancesFor(info.addon, info.flavor_id, &node_id)!=B_OK) 199 err = roster->InstantiateDormantNode(info, &node, B_FLAVOR_IS_GLOBAL); 200 else 201 err = roster->GetNodeFor(node_id, &node); 202 203 if (err == B_OK) { 204 media_input inputs[16]; 205 int32 inputCount = 16; 206 if (roster->GetAllInputsFor(node, inputs, 16, &inputCount)==B_OK) { 207 BMessage message(ML_DEFAULTOUTPUT_CHANGE); 208 209 for (int32 i = 0; i < inputCount; i++) { 210 media_input *input = new media_input(); 211 memcpy(input, &inputs[i], sizeof(*input)); 212 mMenu3->AddItem(item = new Settings2Item(&info, input, new BMessage(message))); 213 if(inputs[i].destination.id == outputID) 214 item->SetMarked(true); 215 } 216 } 217 } 218 } 219 } 220 221 SettingsItem::SettingsItem(dormant_node_info *info, BMessage *message, 222 char shortcut, uint32 modifiers) 223 : BMenuItem(info->name, message, shortcut, modifiers), 224 mInfo(info) 225 { 226 227 } 228 229 Settings2Item::Settings2Item(dormant_node_info *info, media_input *input, BMessage *message, 230 char shortcut, uint32 modifiers) 231 : BMenuItem(input->name, message, shortcut, modifiers), 232 mInfo(info), 233 mInput(input) 234 { 235 236 } 237 238 Settings2Item::~Settings2Item() 239 { 240 delete mInput; 241 } 242 243