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 void
Controller::_AdoptGlobalSettings() Controller::_AdoptGlobalSettings()
{ {
mpSettings settings = Settings::CurrentSettings(); mpSettings settings;
// thread safe Settings::Default()->Get(settings);
fAutoplaySetting = settings.autostart; fAutoplaySetting = settings.autostart;
// not yet used: // not yet used:
+8 -15
View File
@@ -75,8 +75,7 @@ MainApp::MainApp()
fAudioWindowFrameSaved(false), fAudioWindowFrameSaved(false),
fLastSavedAudioWindowCreationTime(0) fLastSavedAudioWindowCreationTime(0)
{ {
mpSettings settings = Settings::CurrentSettings(); fLastFilePanelFolder = Settings::Default()->FilePanelFolder();
fLastFilePanelFolder = settings.filePanelFolder;
// Now tell the application roster, that we're interested // Now tell the application roster, that we're interested
// in getting notifications of apps being launched or quit. // in getting notifications of apps being launched or quit.
@@ -145,9 +144,7 @@ MainApp::QuitRequested()
fSettingsWindow = NULL; fSettingsWindow = NULL;
// store the current file panel ref in the global settings // store the current file panel ref in the global settings
mpSettings settings = Settings::CurrentSettings(); Settings::Default()->SetFilePanelFolder(fLastFilePanelFolder);
settings.filePanelFolder = fLastFilePanelFolder;
Settings::Default()->SaveSettings(settings);
return BApplication::QuitRequested(); return BApplication::QuitRequested();
} }
@@ -294,16 +291,12 @@ MainApp::MessageReceived(BMessage* message)
&& message->FindBool("audio only", &audioOnly) == B_OK && message->FindBool("audio only", &audioOnly) == B_OK
&& message->FindRect("window frame", &windowFrame) == B_OK && message->FindRect("window frame", &windowFrame) == B_OK
&& message->FindInt64("creation time", &creationTime) == B_OK) { && message->FindInt64("creation time", &creationTime) == B_OK) {
if (audioOnly) { if (audioOnly && (!fAudioWindowFrameSaved
if (!fAudioWindowFrameSaved || creationTime < fLastSavedAudioWindowCreationTime)) {
|| creationTime < fLastSavedAudioWindowCreationTime) { fAudioWindowFrameSaved = true;
fAudioWindowFrameSaved = true; fLastSavedAudioWindowCreationTime = creationTime;
fLastSavedAudioWindowCreationTime = creationTime;
mpSettings settings Settings::Default()->SetAudioPlayerWindowFrame(windowFrame);
= Settings::Default()->CurrentSettings();
settings.audioPlayerWindowFrame = windowFrame;
Settings::Default()->SaveSettings(settings);
}
} }
} }
+3 -4
View File
@@ -211,8 +211,7 @@ MainWin::MainWin(bool isFirstWindow, BMessage* message)
MoveBy(pos * 25, pos * 25); MoveBy(pos * 25, pos * 25);
pos = (pos + 1) % 15; pos = (pos + 1) % 15;
BRect frame = Settings::Default()->CurrentSettings() BRect frame = Settings::Default()->AudioPlayerWindowFrame();
.audioPlayerWindowFrame;
if (frame.IsValid()) { if (frame.IsValid()) {
if (isFirstWindow) { if (isFirstWindow) {
if (message == NULL) { if (message == NULL) {
@@ -2585,8 +2584,8 @@ MainWin::_MarkItem(BMenu* menu, uint32 command, bool mark)
void void
MainWin::_AdoptGlobalSettings() MainWin::_AdoptGlobalSettings()
{ {
mpSettings settings = Settings::CurrentSettings(); mpSettings settings;
// thread safe Settings::Default()->Get(settings);
fCloseWhenDonePlayingMovie = settings.closeWhenDonePlayingMovie; fCloseWhenDonePlayingMovie = settings.closeWhenDonePlayingMovie;
fCloseWhenDonePlayingSound = settings.closeWhenDonePlayingSound; fCloseWhenDonePlayingSound = settings.closeWhenDonePlayingSound;
+4 -6
View File
@@ -168,8 +168,7 @@ VideoView::SetBitmap(const BBitmap* bitmap)
rgb_color key; rgb_color key;
status_t ret = SetViewOverlay(bitmap, bitmap->Bounds(), status_t ret = SetViewOverlay(bitmap, bitmap->Bounds(),
fVideoFrame, &key, B_FOLLOW_ALL, fVideoFrame, &key, B_FOLLOW_ALL,
B_OVERLAY_FILTER_HORIZONTAL B_OVERLAY_FILTER_HORIZONTAL | B_OVERLAY_FILTER_VERTICAL);
| B_OVERLAY_FILTER_VERTICAL);
if (ret == B_OK) { if (ret == B_OK) {
fOverlayKeyColor = key; fOverlayKeyColor = key;
SetLowColor(key); SetLowColor(key);
@@ -181,8 +180,7 @@ VideoView::SetBitmap(const BBitmap* bitmap)
// update restrictions // update restrictions
overlay_restrictions restrictions; overlay_restrictions restrictions;
if (bitmap->GetOverlayRestrictions(&restrictions) if (bitmap->GetOverlayRestrictions(&restrictions) == B_OK)
== B_OK)
fOverlayRestrictions = restrictions; fOverlayRestrictions = restrictions;
} else { } else {
// try again next time // try again next time
@@ -391,8 +389,8 @@ VideoView::_DrawSubtitle()
void void
VideoView::_AdoptGlobalSettings() VideoView::_AdoptGlobalSettings()
{ {
mpSettings settings = Settings::CurrentSettings(); mpSettings settings;
// thread safe Settings::Default()->Get(settings);
fUseOverlays = settings.useOverlays; fUseOverlays = settings.useOverlays;
fUseBilinearScaling = settings.scaleBilinear; fUseBilinearScaling = settings.scaleBilinear;
+41 -28
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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Fredrik Modéen <[email protected]> * Fredrik Modéen <[email protected]>
*/ */
#include "Settings.h" #include "Settings.h"
#include <Autolock.h> #include <Autolock.h>
/*static*/ Settings Settings::sGlobalInstance;
bool bool
mpSettings::operator!=(const mpSettings& other) const mpSettings::operator!=(const mpSettings& other) const
{ {
@@ -40,7 +44,7 @@ Settings::Settings(const char* filename)
void void
Settings::LoadSettings(mpSettings& settings) const Settings::Get(mpSettings& settings) const
{ {
BAutolock _(const_cast<Settings*>(this)); BAutolock _(const_cast<Settings*>(this));
@@ -68,18 +72,13 @@ Settings::LoadSettings(mpSettings& settings) const
= fSettingsMessage.GetValue("bgMovieVolumeMode", = fSettingsMessage.GetValue("bgMovieVolumeMode",
(uint32)mpSettings::BG_MOVIES_FULL_VOLUME); (uint32)mpSettings::BG_MOVIES_FULL_VOLUME);
entry_ref defaultFilePanelFolder; settings.filePanelFolder = FilePanelFolder();
// an "unset" entry_ref settings.audioPlayerWindowFrame = AudioPlayerWindowFrame();
settings.filePanelFolder = fSettingsMessage.GetValue(
"filePanelDirectory", defaultFilePanelFolder);
settings.audioPlayerWindowFrame = fSettingsMessage.GetValue(
"audioPlayerWindowFrame", BRect());
} }
void void
Settings::SaveSettings(const mpSettings& settings) Settings::Update(const mpSettings& settings)
{ {
BAutolock _(this); BAutolock _(this);
@@ -105,33 +104,47 @@ Settings::SaveSettings(const mpSettings& settings)
fSettingsMessage.SetValue("filePanelDirectory", fSettingsMessage.SetValue("filePanelDirectory",
settings.filePanelFolder); settings.filePanelFolder);
fSettingsMessage.SetValue("audioPlayerWindowFrame", SetAudioPlayerWindowFrame(settings.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();
Notify(); Notify();
} }
// #pragma mark - static entry_ref
Settings::FilePanelFolder() const
/*static*/ Settings
Settings::sGlobalInstance;
/*static*/ mpSettings
Settings::CurrentSettings()
{ {
mpSettings settings; BAutolock locker(const_cast<Settings*>(this));
sGlobalInstance.LoadSettings(settings); return fSettingsMessage.GetValue("filePanelDirectory", entry_ref());
return settings;
} }
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* /*static*/ Settings*
Settings::Default() Settings::Default()
{ {
+15 -6
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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Fredrik Modéen <[email protected]> * Fredrik Modéen <[email protected]>
*/ */
#ifndef SETTINGS_H #ifndef SETTINGS_H
#define SETTINGS_H #define SETTINGS_H
#include <Entry.h> #include <Entry.h>
#include <Locker.h> #include <Locker.h>
#include "Notifier.h" #include "Notifier.h"
#include "SettingsMessage.h" #include "SettingsMessage.h"
#define SETTINGS_FILENAME "MediaPlayer"
struct mpSettings { struct mpSettings {
enum { enum {
SUBTITLE_SIZE_SMALL = 0, SUBTITLE_SIZE_SMALL = 0,
@@ -49,17 +53,21 @@ struct mpSettings {
BRect audioPlayerWindowFrame; BRect audioPlayerWindowFrame;
}; };
#define SETTINGS_FILENAME "MediaPlayer"
class Settings : public BLocker, public Notifier { class Settings : public BLocker, public Notifier {
public: public:
Settings( Settings(
const char* filename = SETTINGS_FILENAME); const char* filename = SETTINGS_FILENAME);
void LoadSettings(mpSettings& settings) const; void Get(mpSettings& settings) const;
void SaveSettings(const mpSettings& settings); 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(); static Settings* Default();
private: private:
@@ -69,4 +77,5 @@ private:
static Settings sGlobalInstance; static Settings sGlobalInstance;
}; };
#endif // SETTINGS_H #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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -208,7 +208,7 @@ SettingsWindow::Show()
// The Settings that we want to be able to revert to is the state at which // 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 // the SettingsWindow was shown. So the current settings are stored in
// fLastSettings. // fLastSettings.
Settings::Default()->LoadSettings(fLastSettings); Settings::Default()->Get(fLastSettings);
fSettings = fLastSettings; fSettings = fLastSettings;
AdoptSettings(); AdoptSettings();
@@ -313,7 +313,7 @@ SettingsWindow::ApplySettings()
= mpSettings::BG_MOVIES_MUTED; = mpSettings::BG_MOVIES_MUTED;
} }
Settings::Default()->SaveSettings(fSettings); Settings::Default()->Update(fSettings);
fRevertB->SetEnabled(IsRevertable()); fRevertB->SetEnabled(IsRevertable());
} }
@@ -324,7 +324,7 @@ SettingsWindow::Revert()
{ {
fSettings = fLastSettings; fSettings = fLastSettings;
AdoptSettings(); AdoptSettings();
Settings::Default()->SaveSettings(fSettings); Settings::Default()->Update(fSettings);
} }