1 /* 2 * Copyright 2008-2011, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Fredrik Modéen <fredrik@modeen.se> 7 * Stephan Aßmus <superstippi@gmx.de> 8 */ 9 10 11 #include "SettingsWindow.h" 12 13 #include <stdio.h> 14 15 #include <Box.h> 16 #include <Button.h> 17 #include <Catalog.h> 18 #include <CheckBox.h> 19 #include <ControlLook.h> 20 #include <LayoutBuilder.h> 21 #include <Locale.h> 22 #include <OptionPopUp.h> 23 #include <SpaceLayoutItem.h> 24 #include <String.h> 25 #include <StringView.h> 26 #include <RadioButton.h> 27 #include <View.h> 28 29 30 #undef B_TRANSLATION_CONTEXT 31 #define B_TRANSLATION_CONTEXT "MediaPlayer-SettingsWindow" 32 33 34 enum { 35 M_SETTINGS_CHANGED = 0x3000, 36 37 M_SETTINGS_SAVE, 38 M_SETTINGS_CANCEL, 39 M_SETTINGS_REVERT 40 }; 41 42 43 SettingsWindow::SettingsWindow(BRect frame) 44 : 45 BWindow(frame, B_TRANSLATE("MediaPlayer settings"), B_FLOATING_WINDOW_LOOK, 46 B_FLOATING_ALL_WINDOW_FEEL, 47 B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE 48 | B_AUTO_UPDATE_SIZE_LIMITS) 49 { 50 const float kSpacing = be_control_look->DefaultItemSpacing(); 51 52 BBox* settingsBox = new BBox(B_PLAIN_BORDER, NULL); 53 BGroupLayout* settingsLayout = new BGroupLayout(B_VERTICAL, kSpacing / 2); 54 settingsBox->SetLayout(settingsLayout); 55 BBox* buttonBox = new BBox(B_PLAIN_BORDER, NULL); 56 BGroupLayout* buttonLayout = new BGroupLayout(B_HORIZONTAL, kSpacing / 2); 57 buttonBox->SetLayout(buttonLayout); 58 59 BStringView* playModeLabel = new BStringView("stringViewPlayMode", 60 B_TRANSLATE("Play mode")); 61 BStringView* viewOptionsLabel = new BStringView("stringViewViewOpions", 62 B_TRANSLATE("View options")); 63 BStringView* bgMoviesModeLabel = new BStringView("stringViewPlayBackg", 64 B_TRANSLATE("Volume of background clips")); 65 BAlignment alignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER); 66 playModeLabel->SetExplicitAlignment(alignment); 67 playModeLabel->SetFont(be_bold_font); 68 viewOptionsLabel->SetExplicitAlignment(alignment); 69 viewOptionsLabel->SetFont(be_bold_font); 70 bgMoviesModeLabel->SetExplicitAlignment(alignment); 71 bgMoviesModeLabel->SetFont(be_bold_font); 72 73 fAutostartCB = new BCheckBox("chkboxAutostart", 74 B_TRANSLATE("Automatically start playing"), 75 new BMessage(M_SETTINGS_CHANGED)); 76 77 fCloseWindowMoviesCB = new BCheckBox("chkBoxCloseWindowMovies", 78 B_TRANSLATE("Close window after playing video"), 79 new BMessage(M_SETTINGS_CHANGED)); 80 fCloseWindowSoundsCB = new BCheckBox("chkBoxCloseWindowSounds", 81 B_TRANSLATE("Close window after playing audio"), 82 new BMessage(M_SETTINGS_CHANGED)); 83 84 fLoopMoviesCB = new BCheckBox("chkBoxLoopMovie", 85 B_TRANSLATE("Loop video"), 86 new BMessage(M_SETTINGS_CHANGED)); 87 fLoopSoundsCB = new BCheckBox("chkBoxLoopSounds", 88 B_TRANSLATE("Loop audio"), 89 new BMessage(M_SETTINGS_CHANGED)); 90 91 fUseOverlaysCB = new BCheckBox("chkBoxUseOverlays", 92 B_TRANSLATE("Use hardware video overlays if available"), 93 new BMessage(M_SETTINGS_CHANGED)); 94 fScaleBilinearCB = new BCheckBox("chkBoxScaleBilinear", 95 B_TRANSLATE("Scale movies smoothly (non-overlay mode)"), 96 new BMessage(M_SETTINGS_CHANGED)); 97 98 fScaleFullscreenControlsCB = new BCheckBox("chkBoxScaleControls", 99 B_TRANSLATE("Scale controls in full screen mode"), 100 new BMessage(M_SETTINGS_CHANGED)); 101 102 fResumeOP = new BOptionPopUp("resume", 103 B_TRANSLATE("Resume:"), new BMessage(M_SETTINGS_CHANGED)); 104 fResumeOP->AddOption( 105 B_TRANSLATE("never"), mpSettings::RESUME_NEVER); 106 fResumeOP->AddOption( 107 B_TRANSLATE("ask every time"), mpSettings::RESUME_ASK); 108 fResumeOP->AddOption( 109 B_TRANSLATE("always"), mpSettings::RESUME_ALWAYS); 110 111 fSubtitleSizeOP = new BOptionPopUp("subtitleSize", 112 B_TRANSLATE("Subtitle size:"), new BMessage(M_SETTINGS_CHANGED)); 113 fSubtitleSizeOP->AddOption( 114 B_TRANSLATE("Small"), mpSettings::SUBTITLE_SIZE_SMALL); 115 fSubtitleSizeOP->AddOption( 116 B_TRANSLATE("Medium"), mpSettings::SUBTITLE_SIZE_MEDIUM); 117 fSubtitleSizeOP->AddOption( 118 B_TRANSLATE("Large"), mpSettings::SUBTITLE_SIZE_LARGE); 119 120 fSubtitlePlacementOP = new BOptionPopUp("subtitlePlacement", 121 B_TRANSLATE("Subtitle placement:"), new BMessage(M_SETTINGS_CHANGED)); 122 fSubtitlePlacementOP->AddOption(B_TRANSLATE("Bottom of video"), 123 mpSettings::SUBTITLE_PLACEMENT_BOTTOM_OF_VIDEO); 124 fSubtitlePlacementOP->AddOption(B_TRANSLATE("Bottom of screen"), 125 mpSettings::SUBTITLE_PLACEMENT_BOTTOM_OF_SCREEN); 126 127 fFullVolumeBGMoviesRB = new BRadioButton("rdbtnfullvolume", 128 B_TRANSLATE("Full volume"), new BMessage(M_SETTINGS_CHANGED)); 129 130 fHalfVolumeBGMoviesRB = new BRadioButton("rdbtnhalfvolume", 131 B_TRANSLATE("Low volume"), new BMessage(M_SETTINGS_CHANGED)); 132 133 fMutedVolumeBGMoviesRB = new BRadioButton("rdbtnfullvolume", 134 B_TRANSLATE("Muted"), new BMessage(M_SETTINGS_CHANGED)); 135 136 fRevertB = new BButton("revert", B_TRANSLATE("Revert"), 137 new BMessage(M_SETTINGS_REVERT)); 138 139 BButton* cancelButton = new BButton("cancel", B_TRANSLATE("Cancel"), 140 new BMessage(M_SETTINGS_CANCEL)); 141 142 BButton* okButton = new BButton("ok", B_TRANSLATE("OK"), 143 new BMessage(M_SETTINGS_SAVE)); 144 okButton->MakeDefault(true); 145 146 // Build the layout 147 BGroupLayout* volumeGroup; 148 BGroupLayout* startGroup; 149 BGroupLayout* playGroup; 150 BGroupLayout* controlsGroup; 151 152 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 153 .AddGroup(settingsLayout) 154 .SetInsets(B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING, 155 B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING) 156 .Add(playModeLabel) 157 .AddGroup(B_HORIZONTAL, 0) 158 .GetLayout(&playGroup) 159 .AddStrut(10) 160 .AddGroup(B_VERTICAL, 0) 161 .GetLayout(&startGroup) 162 .Add(fAutostartCB) 163 .AddGroup(B_HORIZONTAL,0) 164 .Add(BSpaceLayoutItem::CreateHorizontalStrut(kSpacing*1.9)) 165 .AddGroup(B_VERTICAL,0) 166 .GetLayout(&controlsGroup) 167 .Add(fCloseWindowMoviesCB) 168 .Add(fCloseWindowSoundsCB) 169 .End() 170 .End() 171 .Add(fLoopMoviesCB) 172 .Add(fLoopSoundsCB) 173 .Add(fResumeOP) 174 .End() 175 .End() 176 .AddStrut(kSpacing) 177 178 .Add(viewOptionsLabel) 179 .AddGroup(B_HORIZONTAL, 0) 180 .AddStrut(10) 181 .AddGroup(B_VERTICAL, 0) 182 .Add(fUseOverlaysCB) 183 .Add(fScaleBilinearCB) 184 .Add(fScaleFullscreenControlsCB) 185 .Add(fSubtitleSizeOP) 186 .Add(fSubtitlePlacementOP) 187 .End() 188 .End() 189 .AddStrut(kSpacing) 190 191 .Add(bgMoviesModeLabel) 192 .AddGroup(B_HORIZONTAL, 0) 193 .AddStrut(10) 194 .AddGroup(B_VERTICAL, 0) 195 .GetLayout(&volumeGroup) 196 .Add(fFullVolumeBGMoviesRB) 197 .Add(fHalfVolumeBGMoviesRB) 198 .Add(fMutedVolumeBGMoviesRB) 199 .End() 200 .End() 201 .AddStrut(kSpacing) 202 .End() 203 .AddGroup(buttonLayout) 204 .SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING, 205 B_USE_WINDOW_SPACING, B_USE_WINDOW_SPACING) 206 .Add(fRevertB) 207 .AddGlue() 208 .Add(cancelButton) 209 .Add(okButton); 210 211 startGroup->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 212 playGroup->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 213 volumeGroup->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 214 controlsGroup->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 215 } 216 217 218 SettingsWindow::~SettingsWindow() 219 { 220 } 221 222 223 void 224 SettingsWindow::Show() 225 { 226 // The Settings that we want to be able to revert to is the state at which 227 // the SettingsWindow was shown. So the current settings are stored in 228 // fLastSettings. 229 Settings::Default()->Get(fLastSettings); 230 fSettings = fLastSettings; 231 AdoptSettings(); 232 233 BWindow::Show(); 234 } 235 236 237 bool 238 SettingsWindow::QuitRequested() 239 { 240 Hide(); 241 return false; 242 } 243 244 245 void 246 SettingsWindow::MessageReceived(BMessage* message) 247 { 248 switch (message->what) { 249 case M_SETTINGS_CHANGED: 250 ApplySettings(); 251 break; 252 253 case B_KEY_DOWN: 254 int32 index; 255 if (message->FindInt32("key", &index) == B_OK && index == 1) 256 PostMessage(B_QUIT_REQUESTED); 257 break; 258 259 case M_SETTINGS_REVERT: 260 Revert(); 261 break; 262 263 case M_SETTINGS_CANCEL: 264 Revert(); 265 // fall through 266 case M_SETTINGS_SAVE: 267 PostMessage(B_QUIT_REQUESTED); 268 break; 269 270 default: 271 BWindow::MessageReceived(message); 272 break; 273 } 274 } 275 276 277 void 278 SettingsWindow::AdoptSettings() 279 { 280 fAutostartCB->SetValue(fSettings.autostart); 281 fCloseWindowMoviesCB->SetValue(fSettings.closeWhenDonePlayingMovie); 282 fCloseWindowSoundsCB->SetValue(fSettings.closeWhenDonePlayingSound); 283 fLoopMoviesCB->SetValue(fSettings.loopMovie); 284 fLoopSoundsCB->SetValue(fSettings.loopSound); 285 286 fUseOverlaysCB->SetValue(fSettings.useOverlays); 287 fScaleBilinearCB->SetValue(fSettings.scaleBilinear); 288 fScaleFullscreenControlsCB->SetValue(fSettings.scaleFullscreenControls); 289 290 fResumeOP->SetValue(fSettings.resume); 291 fSubtitleSizeOP->SetValue(fSettings.subtitleSize); 292 fSubtitlePlacementOP->SetValue(fSettings.subtitlePlacement); 293 294 fFullVolumeBGMoviesRB->SetValue(fSettings.backgroundMovieVolumeMode 295 == mpSettings::BG_MOVIES_FULL_VOLUME); 296 fHalfVolumeBGMoviesRB->SetValue(fSettings.backgroundMovieVolumeMode 297 == mpSettings::BG_MOVIES_HALF_VLUME); 298 fMutedVolumeBGMoviesRB->SetValue(fSettings.backgroundMovieVolumeMode 299 == mpSettings::BG_MOVIES_MUTED); 300 301 fRevertB->SetEnabled(IsRevertable()); 302 } 303 304 305 void 306 SettingsWindow::ApplySettings() 307 { 308 fSettings.autostart = fAutostartCB->Value() == B_CONTROL_ON; 309 fSettings.closeWhenDonePlayingMovie 310 = fCloseWindowMoviesCB->Value() == B_CONTROL_ON; 311 fSettings.closeWhenDonePlayingSound 312 = fCloseWindowSoundsCB->Value() == B_CONTROL_ON; 313 fSettings.loopMovie = fLoopMoviesCB->Value() == B_CONTROL_ON; 314 fSettings.loopSound = fLoopSoundsCB->Value() == B_CONTROL_ON; 315 316 fSettings.useOverlays = fUseOverlaysCB->Value() == B_CONTROL_ON; 317 fSettings.scaleBilinear = fScaleBilinearCB->Value() == B_CONTROL_ON; 318 fSettings.scaleFullscreenControls 319 = fScaleFullscreenControlsCB->Value() == B_CONTROL_ON; 320 321 fSettings.resume = fResumeOP->Value(); 322 fSettings.subtitleSize = fSubtitleSizeOP->Value(); 323 fSettings.subtitlePlacement = fSubtitlePlacementOP->Value(); 324 325 if (fFullVolumeBGMoviesRB->Value() == B_CONTROL_ON) { 326 fSettings.backgroundMovieVolumeMode 327 = mpSettings::BG_MOVIES_FULL_VOLUME; 328 } else if (fHalfVolumeBGMoviesRB->Value() == B_CONTROL_ON) { 329 fSettings.backgroundMovieVolumeMode 330 = mpSettings::BG_MOVIES_HALF_VLUME; 331 } else if (fMutedVolumeBGMoviesRB->Value() == B_CONTROL_ON) { 332 fSettings.backgroundMovieVolumeMode 333 = mpSettings::BG_MOVIES_MUTED; 334 } 335 336 Settings::Default()->Update(fSettings); 337 338 fRevertB->SetEnabled(IsRevertable()); 339 } 340 341 342 void 343 SettingsWindow::Revert() 344 { 345 fSettings = fLastSettings; 346 AdoptSettings(); 347 Settings::Default()->Update(fSettings); 348 } 349 350 351 bool 352 SettingsWindow::IsRevertable() const 353 { 354 return fSettings != fLastSettings; 355 } 356 357