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