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.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42732 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2011-09-09 21:33:16 +00:00
parent f6766f291e
commit a178983df6
7 changed files with 93 additions and 81 deletions
+2 -2
View File
@@ -966,8 +966,8 @@ Controller::RemoveListener(Listener* listener)
void
Controller::_AdoptGlobalSettings()
{
mpSettings settings = Settings::CurrentSettings();
// thread safe
mpSettings settings;
Settings::Default()->Get(settings);
fAutoplaySetting = settings.autostart;
// not yet used:
+9 -16
View File
@@ -75,8 +75,7 @@ MainApp::MainApp()
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 @@ MainApp::MainApp()
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 @@ MainApp::QuitRequested()
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 @@ MainApp::MessageReceived(BMessage* message)
&& 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);
}
}
+3 -4
View File
@@ -211,8 +211,7 @@ MainWin::MainWin(bool isFirstWindow, BMessage* message)
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 @@ MainWin::_MarkItem(BMenu* menu, uint32 command, bool mark)
void
MainWin::_AdoptGlobalSettings()
{
mpSettings settings = Settings::CurrentSettings();
// thread safe
mpSettings settings;
Settings::Default()->Get(settings);
fCloseWhenDonePlayingMovie = settings.closeWhenDonePlayingMovie;
fCloseWhenDonePlayingSound = settings.closeWhenDonePlayingSound;
+4 -6
View File
@@ -168,8 +168,7 @@ VideoView::SetBitmap(const BBitmap* bitmap)
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 @@ VideoView::SetBitmap(const BBitmap* bitmap)
// 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 @@ VideoView::_DrawSubtitle()
void
VideoView::_AdoptGlobalSettings()
{
mpSettings settings = Settings::CurrentSettings();
// thread safe
mpSettings settings;
Settings::Default()->Get(settings);
fUseOverlays = settings.useOverlays;
fUseBilinearScaling = settings.scaleBilinear;
+43 -30
View File
@@ -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@modeen.se>
*/
#include "Settings.h"
#include <Autolock.h>
/*static*/ Settings Settings::sGlobalInstance;
bool
mpSettings::operator!=(const mpSettings& other) const
{
@@ -40,7 +44,7 @@ Settings::Settings(const char* filename)
void
Settings::LoadSettings(mpSettings& settings) const
Settings::Get(mpSettings& settings) const
{
BAutolock _(const_cast<Settings*>(this));
@@ -68,25 +72,20 @@ Settings::LoadSettings(mpSettings& settings) const
= 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 @@ Settings::SaveSettings(const mpSettings& settings)
fSettingsMessage.SetValue("filePanelDirectory",
settings.filePanelFolder);
fSettingsMessage.SetValue("audioPlayerWindowFrame",
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();
SetAudioPlayerWindowFrame(settings.audioPlayerWindowFrame);
Notify();
}
// #pragma mark - static
/*static*/ Settings
Settings::sGlobalInstance;
/*static*/ mpSettings
Settings::CurrentSettings()
entry_ref
Settings::FilePanelFolder() const
{
mpSettings settings;
sGlobalInstance.LoadSettings(settings);
return settings;
BAutolock locker(const_cast<Settings*>(this));
return fSettingsMessage.GetValue("filePanelDirectory", entry_ref());
}
void
Settings::SetFilePanelFolder(const entry_ref& ref)
{
BAutolock locker(this);
fSettingsMessage.SetValue("filePanelDirectory", ref);
}
BRect
Settings::AudioPlayerWindowFrame() const
{
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()
{
+16 -7
View File
@@ -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@modeen.se>
*/
#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 @@ struct mpSettings {
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);
entry_ref FilePanelFolder() const;
void SetFilePanelFolder(const entry_ref& ref);
BRect AudioPlayerWindowFrame() const;
void SetAudioPlayerWindowFrame(BRect frame);
static mpSettings CurrentSettings();
static Settings* Default();
private:
@@ -69,4 +77,5 @@ private:
static Settings sGlobalInstance;
};
#endif // SETTINGS_H
@@ -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 @@ enum {
#define SPACE 10
#define SPACEING 7
#define SPACEING 7
#define BUTTONHEIGHT 20
@@ -61,9 +61,9 @@ SettingsWindow::SettingsWindow(BRect frame)
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 @@ SettingsWindow::SettingsWindow(BRect frame)
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 @@ SettingsWindow::SettingsWindow(BRect frame)
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 @@ SettingsWindow::Show()
// 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 @@ SettingsWindow::ApplySettings()
= mpSettings::BG_MOVIES_MUTED;
}
Settings::Default()->SaveSettings(fSettings);
Settings::Default()->Update(fSettings);
fRevertB->SetEnabled(IsRevertable());
}
@@ -324,7 +324,7 @@ SettingsWindow::Revert()
{
fSettings = fLastSettings;
AdoptSettings();
Settings::Default()->SaveSettings(fSettings);
Settings::Default()->Update(fSettings);
}