Author: axeld Date: 2011-09-09 23:33:16 +0200 (Fri, 09 Sep 2011) New Revision: 42732 Changeset: https://dev.haiku-os.org/changeset/42732 Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp haiku/trunk/src/apps/mediaplayer/MainApp.cpp haiku/trunk/src/apps/mediaplayer/MainWin.cpp haiku/trunk/src/apps/mediaplayer/VideoView.cpp haiku/trunk/src/apps/mediaplayer/settings/Settings.cpp haiku/trunk/src/apps/mediaplayer/settings/Settings.h haiku/trunk/src/apps/mediaplayer/settings/SettingsWindow.cpp Log: Cleanup while I was searching for a bug that ended up being in the app_server; the decorators now return non-sense as their frame, thank you Clemens! * Got rid of Settings::CurrentSettings() - the get/store pair wasn't really thread-safe anyway, as it always updated all fields, so settings could get lost easily. The mechanism is still being used in the settings window, though. * Introduced some getters/setters for the settings that work on the message directly which simplifies some code. * Minor style cleanups. * Automatic whitespace cleanup. Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/Controller.cpp 2011-09-09 19:43:09 UTC (rev 42731) +++ haiku/trunk/src/apps/mediaplayer/Controller.cpp 2011-09-09 21:33:16 UTC (rev 42732) @@ -966,8 +966,8 @@ void Controller::_AdoptGlobalSettings() { - mpSettings settings = Settings::CurrentSettings(); - // thread safe + mpSettings settings; + Settings::Default()->Get(settings); fAutoplaySetting = settings.autostart; // not yet used: Modified: haiku/trunk/src/apps/mediaplayer/MainApp.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainApp.cpp 2011-09-09 19:43:09 UTC (rev 42731) +++ haiku/trunk/src/apps/mediaplayer/MainApp.cpp 2011-09-09 21:33:16 UTC (rev 42732) @@ -75,8 +75,7 @@ fAudioWindowFrameSaved(false), fLastSavedAudioWindowCreationTime(0) { - mpSettings settings = Settings::CurrentSettings(); - fLastFilePanelFolder = settings.filePanelFolder; + fLastFilePanelFolder = Settings::Default()->FilePanelFolder(); // Now tell the application roster, that we're interested // in getting notifications of apps being launched or quit. @@ -91,7 +90,7 @@ if (!fMediaServerRunning || !fMediaAddOnServerRunning) { BAlert* alert = new BAlert("start_media_server", B_TRANSLATE("It appears the media server is not running.\n" - "Would you like to start it ?"), B_TRANSLATE("Quit"), + "Would you like to start it ?"), B_TRANSLATE("Quit"), B_TRANSLATE("Start media server"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); if (alert->Go() == 0) { @@ -145,9 +144,7 @@ fSettingsWindow = NULL; // store the current file panel ref in the global settings - mpSettings settings = Settings::CurrentSettings(); - settings.filePanelFolder = fLastFilePanelFolder; - Settings::Default()->SaveSettings(settings); + Settings::Default()->SetFilePanelFolder(fLastFilePanelFolder); return BApplication::QuitRequested(); } @@ -294,16 +291,12 @@ && message->FindBool("audio only", &audioOnly) == B_OK && message->FindRect("window frame", &windowFrame) == B_OK && message->FindInt64("creation time", &creationTime) == B_OK) { - if (audioOnly) { - if (!fAudioWindowFrameSaved - || creationTime < fLastSavedAudioWindowCreationTime) { - fAudioWindowFrameSaved = true; - fLastSavedAudioWindowCreationTime = creationTime; - mpSettings settings - = Settings::Default()->CurrentSettings(); - settings.audioPlayerWindowFrame = windowFrame; - Settings::Default()->SaveSettings(settings); - } + if (audioOnly && (!fAudioWindowFrameSaved + || creationTime < fLastSavedAudioWindowCreationTime)) { + fAudioWindowFrameSaved = true; + fLastSavedAudioWindowCreationTime = creationTime; + + Settings::Default()->SetAudioPlayerWindowFrame(windowFrame); } } Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2011-09-09 19:43:09 UTC (rev 42731) +++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2011-09-09 21:33:16 UTC (rev 42732) @@ -211,8 +211,7 @@ MoveBy(pos * 25, pos * 25); pos = (pos + 1) % 15; - BRect frame = Settings::Default()->CurrentSettings() - .audioPlayerWindowFrame; + BRect frame = Settings::Default()->AudioPlayerWindowFrame(); if (frame.IsValid()) { if (isFirstWindow) { if (message == NULL) { @@ -2585,8 +2584,8 @@ void MainWin::_AdoptGlobalSettings() { - mpSettings settings = Settings::CurrentSettings(); - // thread safe + mpSettings settings; + Settings::Default()->Get(settings); fCloseWhenDonePlayingMovie = settings.closeWhenDonePlayingMovie; fCloseWhenDonePlayingSound = settings.closeWhenDonePlayingSound; Modified: haiku/trunk/src/apps/mediaplayer/VideoView.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/VideoView.cpp 2011-09-09 19:43:09 UTC (rev 42731) +++ haiku/trunk/src/apps/mediaplayer/VideoView.cpp 2011-09-09 21:33:16 UTC (rev 42732) @@ -168,8 +168,7 @@ rgb_color key; status_t ret = SetViewOverlay(bitmap, bitmap->Bounds(), fVideoFrame, &key, B_FOLLOW_ALL, - B_OVERLAY_FILTER_HORIZONTAL - | B_OVERLAY_FILTER_VERTICAL); + B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL); if (ret == B_OK) { fOverlayKeyColor = key; SetLowColor(key); @@ -181,8 +180,7 @@ // update restrictions overlay_restrictions restrictions; - if (bitmap->GetOverlayRestrictions(&restrictions) - == B_OK) + if (bitmap->GetOverlayRestrictions(&restrictions) == B_OK) fOverlayRestrictions = restrictions; } else { // try again next time @@ -391,8 +389,8 @@ void VideoView::_AdoptGlobalSettings() { - mpSettings settings = Settings::CurrentSettings(); - // thread safe + mpSettings settings; + Settings::Default()->Get(settings); fUseOverlays = settings.useOverlays; fUseBilinearScaling = settings.scaleBilinear; Modified: haiku/trunk/src/apps/mediaplayer/settings/Settings.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/settings/Settings.cpp 2011-09-09 19:43:09 UTC (rev 42731) +++ haiku/trunk/src/apps/mediaplayer/settings/Settings.cpp 2011-09-09 21:33:16 UTC (rev 42732) @@ -1,16 +1,20 @@ /* - * Copyright 2008, Haiku. All rights reserved. + * Copyright 2008-2011, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Fredrik Modéen <fredrik@xxxxxxxxx> */ + #include "Settings.h" #include <Autolock.h> +/*static*/ Settings Settings::sGlobalInstance; + + bool mpSettings::operator!=(const mpSettings& other) const { @@ -40,7 +44,7 @@ void -Settings::LoadSettings(mpSettings& settings) const +Settings::Get(mpSettings& settings) const { BAutolock _(const_cast<Settings*>(this)); @@ -68,25 +72,20 @@ = fSettingsMessage.GetValue("bgMovieVolumeMode", (uint32)mpSettings::BG_MOVIES_FULL_VOLUME); - entry_ref defaultFilePanelFolder; - // an "unset" entry_ref - settings.filePanelFolder = fSettingsMessage.GetValue( - "filePanelDirectory", defaultFilePanelFolder); - - settings.audioPlayerWindowFrame = fSettingsMessage.GetValue( - "audioPlayerWindowFrame", BRect()); + settings.filePanelFolder = FilePanelFolder(); + settings.audioPlayerWindowFrame = AudioPlayerWindowFrame(); } void -Settings::SaveSettings(const mpSettings& settings) +Settings::Update(const mpSettings& settings) { BAutolock _(this); fSettingsMessage.SetValue("autostart", settings.autostart); - fSettingsMessage.SetValue("closeWhenDonePlayingMovie", + fSettingsMessage.SetValue("closeWhenDonePlayingMovie", settings.closeWhenDonePlayingMovie); - fSettingsMessage.SetValue("closeWhenDonePlayingSound", + fSettingsMessage.SetValue("closeWhenDonePlayingSound", settings.closeWhenDonePlayingSound); fSettingsMessage.SetValue("loopMovie", settings.loopMovie); fSettingsMessage.SetValue("loopSound", settings.loopSound); @@ -105,33 +104,47 @@ fSettingsMessage.SetValue("filePanelDirectory", settings.filePanelFolder); - fSettingsMessage.SetValue("audioPlayerWindowFrame", - settings.audioPlayerWindowFrame); + SetAudioPlayerWindowFrame(settings.audioPlayerWindowFrame); - // Save at this point, although saving is also done on destruction, - // this will make sure the settings are saved even when the player - // crashes. - fSettingsMessage.Save(); - Notify(); } -// #pragma mark - static +entry_ref +Settings::FilePanelFolder() const +{ + BAutolock locker(const_cast<Settings*>(this)); + return fSettingsMessage.GetValue("filePanelDirectory", entry_ref()); +} -/*static*/ Settings -Settings::sGlobalInstance; +void +Settings::SetFilePanelFolder(const entry_ref& ref) +{ + BAutolock locker(this); + fSettingsMessage.SetValue("filePanelDirectory", ref); +} -/*static*/ mpSettings -Settings::CurrentSettings() + +BRect +Settings::AudioPlayerWindowFrame() const { - mpSettings settings; - sGlobalInstance.LoadSettings(settings); - return settings; + BAutolock locker(const_cast<Settings*>(this)); + return fSettingsMessage.GetValue("audioPlayerWindowFrame", BRect()); } +void +Settings::SetAudioPlayerWindowFrame(BRect frame) +{ + BAutolock locker(this); + fSettingsMessage.SetValue("audioPlayerWindowFrame", frame); +} + + +// #pragma mark - static + + /*static*/ Settings* Settings::Default() { Modified: haiku/trunk/src/apps/mediaplayer/settings/Settings.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/settings/Settings.h 2011-09-09 19:43:09 UTC (rev 42731) +++ haiku/trunk/src/apps/mediaplayer/settings/Settings.h 2011-09-09 21:33:16 UTC (rev 42732) @@ -1,20 +1,24 @@ /* - * Copyright 2008, Haiku. All rights reserved. + * Copyright 2008-2011, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Fredrik Modéen <fredrik@xxxxxxxxx> */ - #ifndef SETTINGS_H #define SETTINGS_H + #include <Entry.h> #include <Locker.h> #include "Notifier.h" #include "SettingsMessage.h" + +#define SETTINGS_FILENAME "MediaPlayer" + + struct mpSettings { enum { SUBTITLE_SIZE_SMALL = 0, @@ -43,23 +47,27 @@ uint32 subtitlePlacement; uint32 backgroundMovieVolumeMode; entry_ref filePanelFolder; - + bool operator!=(const mpSettings& other) const; BRect audioPlayerWindowFrame; }; -#define SETTINGS_FILENAME "MediaPlayer" class Settings : public BLocker, public Notifier { public: Settings( const char* filename = SETTINGS_FILENAME); - void LoadSettings(mpSettings& settings) const; - void SaveSettings(const mpSettings& settings); + void Get(mpSettings& settings) const; + void Update(const mpSettings& settings); - static mpSettings CurrentSettings(); + entry_ref FilePanelFolder() const; + void SetFilePanelFolder(const entry_ref& ref); + + BRect AudioPlayerWindowFrame() const; + void SetAudioPlayerWindowFrame(BRect frame); + static Settings* Default(); private: @@ -69,4 +77,5 @@ static Settings sGlobalInstance; }; + #endif // SETTINGS_H Modified: haiku/trunk/src/apps/mediaplayer/settings/SettingsWindow.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/settings/SettingsWindow.cpp 2011-09-09 19:43:09 UTC (rev 42731) +++ haiku/trunk/src/apps/mediaplayer/settings/SettingsWindow.cpp 2011-09-09 21:33:16 UTC (rev 42732) @@ -1,5 +1,5 @@ /* - * Copyright 2008-2010, Haiku, Inc. All rights reserved. + * Copyright 2008-2011, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -41,7 +41,7 @@ #define SPACE 10 -#define SPACEING 7 +#define SPACEING 7 #define BUTTONHEIGHT 20 @@ -61,9 +61,9 @@ BStringView* playModeLabel = new BStringView("stringViewPlayMode", B_TRANSLATE("Play mode")); - BStringView* viewOptionsLabel = new BStringView("stringViewViewOpions", + BStringView* viewOptionsLabel = new BStringView("stringViewViewOpions", B_TRANSLATE("View options")); - BStringView* bgMoviesModeLabel = new BStringView("stringViewPlayBackg", + BStringView* bgMoviesModeLabel = new BStringView("stringViewPlayBackg", B_TRANSLATE("Volume of background clips")); BAlignment alignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER); playModeLabel->SetExplicitAlignment(alignment); @@ -73,14 +73,14 @@ bgMoviesModeLabel->SetExplicitAlignment(alignment); bgMoviesModeLabel->SetFont(be_bold_font); - fAutostartCB = new BCheckBox("chkboxAutostart", - B_TRANSLATE("Automatically start playing"), + fAutostartCB = new BCheckBox("chkboxAutostart", + B_TRANSLATE("Automatically start playing"), new BMessage(M_SETTINGS_CHANGED)); - fCloseWindowMoviesCB = new BCheckBox("chkBoxCloseWindowMovies", + fCloseWindowMoviesCB = new BCheckBox("chkBoxCloseWindowMovies", B_TRANSLATE("Close window after playing video"), new BMessage(M_SETTINGS_CHANGED)); - fCloseWindowSoundsCB = new BCheckBox("chkBoxCloseWindowSounds", + fCloseWindowSoundsCB = new BCheckBox("chkBoxCloseWindowSounds", B_TRANSLATE("Close window after playing audio"), new BMessage(M_SETTINGS_CHANGED)); @@ -120,17 +120,17 @@ fFullVolumeBGMoviesRB = new BRadioButton("rdbtnfullvolume", B_TRANSLATE("Full volume"), new BMessage(M_SETTINGS_CHANGED)); - - fHalfVolumeBGMoviesRB = new BRadioButton("rdbtnhalfvolume", + + fHalfVolumeBGMoviesRB = new BRadioButton("rdbtnhalfvolume", B_TRANSLATE("Low volume"), new BMessage(M_SETTINGS_CHANGED)); - + fMutedVolumeBGMoviesRB = new BRadioButton("rdbtnfullvolume", B_TRANSLATE("Muted"), new BMessage(M_SETTINGS_CHANGED)); - fRevertB = new BButton("revert", B_TRANSLATE("Revert"), + fRevertB = new BButton("revert", B_TRANSLATE("Revert"), new BMessage(M_SETTINGS_REVERT)); - BButton* cancelButton = new BButton("cancel", B_TRANSLATE("Cancel"), + BButton* cancelButton = new BButton("cancel", B_TRANSLATE("Cancel"), new BMessage(M_SETTINGS_CANCEL)); BButton* okButton = new BButton("ok", B_TRANSLATE("OK"), @@ -208,7 +208,7 @@ // The Settings that we want to be able to revert to is the state at which // the SettingsWindow was shown. So the current settings are stored in // fLastSettings. - Settings::Default()->LoadSettings(fLastSettings); + Settings::Default()->Get(fLastSettings); fSettings = fLastSettings; AdoptSettings(); @@ -313,7 +313,7 @@ = mpSettings::BG_MOVIES_MUTED; } - Settings::Default()->SaveSettings(fSettings); + Settings::Default()->Update(fSettings); fRevertB->SetEnabled(IsRevertable()); } @@ -324,7 +324,7 @@ { fSettings = fLastSettings; AdoptSettings(); - Settings::Default()->SaveSettings(fSettings); + Settings::Default()->Update(fSettings); }