Work in progress for storing some window position/size related settings of

the first window, and restoring them for audio content.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34075 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2009-11-16 17:36:32 +00:00
parent 07d4556346
commit f907fa59c3
6 changed files with 87 additions and 12 deletions

View File

@ -46,7 +46,6 @@ const char* kAppSig = "application/x-vnd.Haiku-MediaPlayer";
static const char* kMediaServerSig = B_MEDIA_SERVER_SIGNATURE;
static const char* kMediaServerAddOnSig = "application/x-vnd.Be.addon-host";
MainApp::MainApp()
:
BApplication(kAppSig),
@ -59,7 +58,10 @@ MainApp::MainApp()
fLastFilePanelFolder(),
fMediaServerRunning(false),
fMediaAddOnServerRunning(false)
fMediaAddOnServerRunning(false),
fAudioWindowFrameSaved(false),
fLastSavedAudioWindowCreationTime(0)
{
mpSettings settings = Settings::CurrentSettings();
fLastFilePanelFolder = settings.filePanelFolder;
@ -107,7 +109,7 @@ MainApp::NewWindow()
{
BAutolock _(this);
fPlayerCount++;
BWindow* window = new MainWin();
BWindow* window = new MainWin(fFirstWindow == NULL);
if (fFirstWindow == NULL)
fFirstWindow = window;
return window;
@ -219,10 +221,36 @@ MainApp::MessageReceived(BMessage* message)
{
switch (message->what) {
case M_PLAYER_QUIT:
{
// store the window settings of this instance
MainWin* window = NULL;
bool audioOnly = false;
BRect windowFrame;
bigtime_t creationTime;
if (message->FindPointer("instance", (void**)&window) == B_OK
&& message->FindBool("audio only", &audioOnly) == B_OK
&& message->FindRect("window frame", &windowFrame) == B_OK
&& message->FindInt64("creation time", &creationTime) == B_OK) {
if (window == fFirstWindow)
fFirstWindow = NULL;
if (audioOnly) {
if (!fAudioWindowFrameSaved
|| creationTime < fLastSavedAudioWindowCreationTime) {
fAudioWindowFrameSaved = true;
fLastSavedAudioWindowCreationTime = creationTime;
mpSettings settings
= Settings::Default()->CurrentSettings();
settings.audioPlayerWindowFrame = windowFrame;
Settings::Default()->SaveSettings(settings);
}
}
}
// quit if this was the last player window
fPlayerCount--;
if (fPlayerCount == 0)
PostMessage(B_QUIT_REQUESTED);
break;
}
case B_SOME_APP_LAUNCHED:
case B_SOME_APP_QUIT:
@ -288,7 +316,8 @@ MainApp::MessageReceived(BMessage* message)
case M_SAVE_PANEL_RESULT:
_HandleSavePanelResult(message);
break;
case B_CANCEL: {
case B_CANCEL:
{
// The user canceled a file panel, but store at least the current
// file panel folder.
uint32 oldWhat;

View File

@ -96,6 +96,9 @@ private:
bool fMediaServerRunning;
bool fMediaAddOnServerRunning;
bool fAudioWindowFrameSaved;
bigtime_t fLastSavedAudioWindowCreationTime;
};
extern MainApp* gMainApp;

View File

@ -100,10 +100,11 @@ enum {
//#define printf(a...)
MainWin::MainWin()
MainWin::MainWin(bool isFirstWindow)
:
BWindow(BRect(100,100,400,300), NAME, B_TITLED_WINDOW,
BWindow(BRect(100, 100, 400, 300), NAME, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */),
fCreationTime(system_time()),
fInfoWin(NULL),
fPlaylistWindow(NULL),
fHasFile(false),
@ -130,6 +131,15 @@ MainWin::MainWin()
MoveBy(pos * 25, pos * 25);
pos = (pos + 1) % 15;
if (isFirstWindow) {
BRect frame = Settings::Default()
->CurrentSettings().audioPlayerWindowFrame;
if (frame.IsValid()) {
MoveTo(frame.LeftTop());
ResizeTo(frame.Width(), frame.Height());
}
}
BRect rect = Bounds();
// background
@ -697,7 +707,26 @@ MainWin::WindowActivated(bool active)
bool
MainWin::QuitRequested()
{
be_app->PostMessage(M_PLAYER_QUIT);
BMessage message(M_PLAYER_QUIT);
message.AddPointer("instance", this);
message.AddRect("window frame", Frame());
message.AddBool("audio only", !fHasVideo);
message.AddInt64("creation time", fCreationTime);
if (!fHasVideo && fHasAudio) {
// store playlist and position if this is audio
BMessage playlistArchive;
BAutolock controllerLocker(fController);
playlistArchive.AddInt64("position", fController->TimePosition());
controllerLocker.Unlock();
BAutolock playlistLocker(fPlaylist);
if (fPlaylist->Archive(&playlistArchive) != B_OK
|| message.AddMessage("playlist", &playlistArchive) != B_OK) {
fprintf(stderr, "Failed to store current playlist.\n");
}
}
be_app->PostMessage(&message);
return true;
}
@ -917,7 +946,7 @@ MainWin::_SetupWindow()
if (!fIsFullscreen) {
// Resize to 100% but stay on screen
_ResizeWindow(100, true);
_ResizeWindow(100, !fHasVideo, true);
} else {
// Make sure we relayout the video view when in full screen mode
FrameResized(Frame().Width(), Frame().Height());
@ -1181,7 +1210,7 @@ MainWin::_CurrentVideoSizeInPercent() const
void
MainWin::_ResizeWindow(int percent, bool stayOnScreen)
MainWin::_ResizeWindow(int percent, bool keepWidth, bool stayOnScreen)
{
// Get required window size
int videoWidth;
@ -1197,6 +1226,8 @@ MainWin::_ResizeWindow(int percent, bool stayOnScreen)
_GetMinimumWindowSize(width, height);
width = max_c(width, videoWidth) - 1;
if (keepWidth)
width = max_c(width, (int)Frame().Width());
height = height + videoHeight - 1;
if (stayOnScreen) {

View File

@ -43,7 +43,7 @@ class PlaylistWindow;
class MainWin : public BWindow {
public:
MainWin();
MainWin(bool isFirstWindow);
virtual ~MainWin();
virtual void FrameResized(float newWidth, float newHeight);
@ -86,6 +86,7 @@ private:
int& videoHeight) const;
int _CurrentVideoSizeInPercent() const;
void _ResizeWindow(int percent,
bool keepWidth = false,
bool stayOnScreen = false);
void _ResizeVideoView(int x, int y, int width,
int height);
@ -114,6 +115,8 @@ private:
void _AdoptGlobalSettings();
bigtime_t fCreationTime;
BMenuBar* fMenuBar;
BView* fBackground;
VideoView* fVideoView;

View File

@ -22,7 +22,8 @@ mpSettings::operator!=(const mpSettings& other) const
|| useOverlays != other.useOverlays
|| scaleBilinear != other.scaleBilinear
|| backgroundMovieVolumeMode != other.backgroundMovieVolumeMode
|| filePanelFolder != other.filePanelFolder;
|| filePanelFolder != other.filePanelFolder
|| audioPlayerWindowFrame != other.audioPlayerWindowFrame;
}
@ -58,6 +59,9 @@ Settings::LoadSettings(mpSettings& settings) const
// an "unset" entry_ref
settings.filePanelFolder = fSettingsMessage.GetValue(
"filePanelDirectory", defaultFilePanelFolder);
settings.audioPlayerWindowFrame = fSettingsMessage.GetValue(
"audioPlayerWindowFrame", BRect());
}
@ -83,6 +87,9 @@ 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.
@ -103,7 +110,7 @@ Settings::CurrentSettings()
{
mpSettings settings;
sGlobalInstance.LoadSettings(settings);
return settings;
return settings;
}

View File

@ -32,6 +32,8 @@ struct mpSettings {
entry_ref filePanelFolder;
bool operator!=(const mpSettings& other) const;
BRect audioPlayerWindowFrame;
};
#define SETTINGS_FILENAME "MediaPlayer"