From ac6b0fc9d204ee771eeae68f0f00cddc53adf77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 11 Oct 2008 23:33:59 +0000 Subject: [PATCH] Remember the last used file panel folder. Also remember the folder even if the user cancled the file panel. Some improvements to the SettingsMessage and some more helpful comments here and there. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27986 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainApp.cpp | 20 +++++++++++ src/apps/mediaplayer/settings/Settings.cpp | 14 ++++++-- src/apps/mediaplayer/settings/Settings.h | 34 ++++++++++--------- .../mediaplayer/settings/SettingsWindow.cpp | 3 ++ .../mediaplayer/support/SettingsMessage.cpp | 24 +++++++++++-- .../mediaplayer/support/SettingsMessage.h | 7 ++-- 6 files changed, 80 insertions(+), 22 deletions(-) diff --git a/src/apps/mediaplayer/MainApp.cpp b/src/apps/mediaplayer/MainApp.cpp index f6d1d59697..9d3cb41a8d 100644 --- a/src/apps/mediaplayer/MainApp.cpp +++ b/src/apps/mediaplayer/MainApp.cpp @@ -33,6 +33,7 @@ #include #include "EventQueue.h" +#include "Settings.h" #include "SettingsWindow.h" @@ -56,6 +57,8 @@ MainApp::MainApp() fMediaServerRunning(false), fMediaAddOnServerRunning(false) { + mpSettings settings = Settings::CurrentSettings(); + fLastFilePanelFolder = settings.filePanelFolder; } @@ -76,6 +79,11 @@ MainApp::QuitRequested() fSettingsWindow->Quit(); fSettingsWindow = NULL; + // store the current file panel ref in the global settings + mpSettings settings = Settings::CurrentSettings(); + settings.filePanelFolder = fLastFilePanelFolder; + Settings::Default()->SaveSettings(settings); + return BApplication::QuitRequested(); } @@ -260,6 +268,18 @@ MainApp::MessageReceived(BMessage* message) case M_SAVE_PANEL_RESULT: _HandleSavePanelResult(message); break; + case B_CANCEL: { + // The user canceled a file panel, but store at least the current + // file panel folder. + uint32 oldWhat; + if (message->FindInt32("old_what", (int32*)&oldWhat) != B_OK) + break; + if (oldWhat == M_OPEN_PANEL_RESULT && fOpenFilePanel != NULL) + fOpenFilePanel->GetPanelDirectory(&fLastFilePanelFolder); + else if (oldWhat == M_SAVE_PANEL_RESULT && fSaveFilePanel != NULL) + fSaveFilePanel->GetPanelDirectory(&fLastFilePanelFolder); + break; + } default: BApplication::MessageReceived(message); diff --git a/src/apps/mediaplayer/settings/Settings.cpp b/src/apps/mediaplayer/settings/Settings.cpp index 851fdac899..28a22db20b 100644 --- a/src/apps/mediaplayer/settings/Settings.cpp +++ b/src/apps/mediaplayer/settings/Settings.cpp @@ -21,14 +21,16 @@ mpSettings::operator!=(const mpSettings& other) const || loopSound != other.loopSound || useOverlays != other.useOverlays || scaleBilinear != other.scaleBilinear - || backgroundMovieVolumeMode != other.backgroundMovieVolumeMode; + || backgroundMovieVolumeMode != other.backgroundMovieVolumeMode + || filePanelFolder != other.filePanelFolder; } Settings::Settings(const char* filename) : BLocker("settings lock"), - fSettingsMessage(B_USER_CONFIG_DIRECTORY, filename) + fSettingsMessage(B_USER_SETTINGS_DIRECTORY, filename) { + // The settings are loaded from disk in the SettingsMessage constructor. } @@ -51,6 +53,11 @@ Settings::LoadSettings(mpSettings& settings) const settings.backgroundMovieVolumeMode = fSettingsMessage.GetValue("bgMovieVolumeMode", (uint32)mpSettings::BG_MOVIES_FULL_VOLUME); + + entry_ref defaultFilePanelFolder; + // an "unset" entry_ref + settings.filePanelFolder = fSettingsMessage.GetValue( + "filePanelDirectory", defaultFilePanelFolder); } @@ -73,6 +80,9 @@ Settings::SaveSettings(const mpSettings& settings) fSettingsMessage.SetValue("bgMovieVolumeMode", settings.backgroundMovieVolumeMode); + fSettingsMessage.SetValue("filePanelDirectory", + settings.filePanelFolder); + // Save at this point, although saving is also done on destruction, // this will make sure the settings are saved even when the player // crashes. diff --git a/src/apps/mediaplayer/settings/Settings.h b/src/apps/mediaplayer/settings/Settings.h index 2aeecd7b17..86bdd58ce7 100644 --- a/src/apps/mediaplayer/settings/Settings.h +++ b/src/apps/mediaplayer/settings/Settings.h @@ -9,30 +9,32 @@ #ifndef SETTINGS_H #define SETTINGS_H +#include #include #include "Notifier.h" #include "SettingsMessage.h" struct mpSettings { - bool autostart; - bool closeWhenDonePlayingMovie; - bool closeWhenDonePlayingSound; - bool loopMovie; - bool loopSound; - bool useOverlays; - bool scaleBilinear; - enum { - BG_MOVIES_FULL_VOLUME = 0, - BG_MOVIES_HALF_VLUME = 1, - BG_MOVIES_MUTED = 2 - }; - uint32 backgroundMovieVolumeMode; - - bool operator!=(const mpSettings& other) const; + bool autostart; + bool closeWhenDonePlayingMovie; + bool closeWhenDonePlayingSound; + bool loopMovie; + bool loopSound; + bool useOverlays; + bool scaleBilinear; + enum { + BG_MOVIES_FULL_VOLUME = 0, + BG_MOVIES_HALF_VLUME = 1, + BG_MOVIES_MUTED = 2 + }; + uint32 backgroundMovieVolumeMode; + entry_ref filePanelFolder; + + bool operator!=(const mpSettings& other) const; }; -#define SETTINGS_FILENAME "MediaPlayerSettings" +#define SETTINGS_FILENAME "MediaPlayer" class Settings : public BLocker, public Notifier { public: diff --git a/src/apps/mediaplayer/settings/SettingsWindow.cpp b/src/apps/mediaplayer/settings/SettingsWindow.cpp index a05bd6a49e..a8d462a2a2 100644 --- a/src/apps/mediaplayer/settings/SettingsWindow.cpp +++ b/src/apps/mediaplayer/settings/SettingsWindow.cpp @@ -276,6 +276,9 @@ SettingsWindow::~SettingsWindow() void 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); fSettings = fLastSettings; AdoptSettings(); diff --git a/src/apps/mediaplayer/support/SettingsMessage.cpp b/src/apps/mediaplayer/support/SettingsMessage.cpp index 685ef320e4..c3f7529128 100644 --- a/src/apps/mediaplayer/support/SettingsMessage.cpp +++ b/src/apps/mediaplayer/support/SettingsMessage.cpp @@ -9,6 +9,7 @@ #include "SettingsMessage.h" +#include #include #include @@ -158,7 +159,7 @@ SettingsMessage::SetValue(const char* name, const BString& value) status_t -SettingsMessage::SetValue(const char* name, BPoint value) +SettingsMessage::SetValue(const char* name, const BPoint& value) { if (ReplacePoint(name, value) == B_OK) return B_OK; @@ -167,7 +168,7 @@ SettingsMessage::SetValue(const char* name, BPoint value) status_t -SettingsMessage::SetValue(const char* name, BRect value) +SettingsMessage::SetValue(const char* name, const BRect& value) { if (ReplaceRect(name, value) == B_OK) return B_OK; @@ -175,6 +176,15 @@ SettingsMessage::SetValue(const char* name, BRect value) } +status_t +SettingsMessage::SetValue(const char* name, const entry_ref& value) +{ + if (ReplaceRef(name, &value) == B_OK) + return B_OK; + return AddRef(name, &value); +} + + status_t SettingsMessage::SetValue(const char* name, const BMessage* value) { @@ -305,6 +315,16 @@ SettingsMessage::GetValue(const char* name, BRect defaultValue) const } +entry_ref +SettingsMessage::GetValue(const char* name, const entry_ref& defaultValue) const +{ + entry_ref value; + if (FindRef(name, &value) != B_OK) + return defaultValue; + return value; +} + + BMessage SettingsMessage::GetValue(const char* name, const BMessage& defaultValue) const { diff --git a/src/apps/mediaplayer/support/SettingsMessage.h b/src/apps/mediaplayer/support/SettingsMessage.h index aa15217f65..f98121b5bb 100644 --- a/src/apps/mediaplayer/support/SettingsMessage.h +++ b/src/apps/mediaplayer/support/SettingsMessage.h @@ -36,8 +36,9 @@ public: const char* value); status_t SetValue(const char* name, const BString& value); - status_t SetValue(const char *name, BPoint value); - status_t SetValue(const char* name, BRect value); + status_t SetValue(const char *name, const BPoint& value); + status_t SetValue(const char* name, const BRect& value); + status_t SetValue(const char* name, const entry_ref& value); status_t SetValue(const char* name, const BMessage* value); status_t SetValue(const char* name, @@ -65,6 +66,8 @@ public: BPoint defaultValue) const; BRect GetValue(const char* name, BRect defaultValue) const; + entry_ref GetValue(const char* name, + const entry_ref& defaultValue) const; BMessage GetValue(const char* name, const BMessage& defaultValue) const;