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
+33 -4
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* kMediaServerSig = B_MEDIA_SERVER_SIGNATURE;
static const char* kMediaServerAddOnSig = "application/x-vnd.Be.addon-host"; static const char* kMediaServerAddOnSig = "application/x-vnd.Be.addon-host";
MainApp::MainApp() MainApp::MainApp()
: :
BApplication(kAppSig), BApplication(kAppSig),
@@ -59,7 +58,10 @@ MainApp::MainApp()
fLastFilePanelFolder(), fLastFilePanelFolder(),
fMediaServerRunning(false), fMediaServerRunning(false),
fMediaAddOnServerRunning(false) fMediaAddOnServerRunning(false),
fAudioWindowFrameSaved(false),
fLastSavedAudioWindowCreationTime(0)
{ {
mpSettings settings = Settings::CurrentSettings(); mpSettings settings = Settings::CurrentSettings();
fLastFilePanelFolder = settings.filePanelFolder; fLastFilePanelFolder = settings.filePanelFolder;
@@ -107,7 +109,7 @@ MainApp::NewWindow()
{ {
BAutolock _(this); BAutolock _(this);
fPlayerCount++; fPlayerCount++;
BWindow* window = new MainWin(); BWindow* window = new MainWin(fFirstWindow == NULL);
if (fFirstWindow == NULL) if (fFirstWindow == NULL)
fFirstWindow = window; fFirstWindow = window;
return window; return window;
@@ -219,10 +221,36 @@ MainApp::MessageReceived(BMessage* message)
{ {
switch (message->what) { switch (message->what) {
case M_PLAYER_QUIT: 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--; fPlayerCount--;
if (fPlayerCount == 0) if (fPlayerCount == 0)
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
break; break;
}
case B_SOME_APP_LAUNCHED: case B_SOME_APP_LAUNCHED:
case B_SOME_APP_QUIT: case B_SOME_APP_QUIT:
@@ -288,7 +316,8 @@ MainApp::MessageReceived(BMessage* message)
case M_SAVE_PANEL_RESULT: case M_SAVE_PANEL_RESULT:
_HandleSavePanelResult(message); _HandleSavePanelResult(message);
break; break;
case B_CANCEL: { case B_CANCEL:
{
// The user canceled a file panel, but store at least the current // The user canceled a file panel, but store at least the current
// file panel folder. // file panel folder.
uint32 oldWhat; uint32 oldWhat;
+3
View File
@@ -96,6 +96,9 @@ private:
bool fMediaServerRunning; bool fMediaServerRunning;
bool fMediaAddOnServerRunning; bool fMediaAddOnServerRunning;
bool fAudioWindowFrameSaved;
bigtime_t fLastSavedAudioWindowCreationTime;
}; };
extern MainApp* gMainApp; extern MainApp* gMainApp;
+36 -5
View File
@@ -100,10 +100,11 @@ enum {
//#define printf(a...) //#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 */), B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */),
fCreationTime(system_time()),
fInfoWin(NULL), fInfoWin(NULL),
fPlaylistWindow(NULL), fPlaylistWindow(NULL),
fHasFile(false), fHasFile(false),
@@ -130,6 +131,15 @@ MainWin::MainWin()
MoveBy(pos * 25, pos * 25); MoveBy(pos * 25, pos * 25);
pos = (pos + 1) % 15; 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(); BRect rect = Bounds();
// background // background
@@ -697,7 +707,26 @@ MainWin::WindowActivated(bool active)
bool bool
MainWin::QuitRequested() 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; return true;
} }
@@ -917,7 +946,7 @@ MainWin::_SetupWindow()
if (!fIsFullscreen) { if (!fIsFullscreen) {
// Resize to 100% but stay on screen // Resize to 100% but stay on screen
_ResizeWindow(100, true); _ResizeWindow(100, !fHasVideo, true);
} else { } else {
// Make sure we relayout the video view when in full screen mode // Make sure we relayout the video view when in full screen mode
FrameResized(Frame().Width(), Frame().Height()); FrameResized(Frame().Width(), Frame().Height());
@@ -1181,7 +1210,7 @@ MainWin::_CurrentVideoSizeInPercent() const
void void
MainWin::_ResizeWindow(int percent, bool stayOnScreen) MainWin::_ResizeWindow(int percent, bool keepWidth, bool stayOnScreen)
{ {
// Get required window size // Get required window size
int videoWidth; int videoWidth;
@@ -1197,6 +1226,8 @@ MainWin::_ResizeWindow(int percent, bool stayOnScreen)
_GetMinimumWindowSize(width, height); _GetMinimumWindowSize(width, height);
width = max_c(width, videoWidth) - 1; width = max_c(width, videoWidth) - 1;
if (keepWidth)
width = max_c(width, (int)Frame().Width());
height = height + videoHeight - 1; height = height + videoHeight - 1;
if (stayOnScreen) { if (stayOnScreen) {
+4 -1
View File
@@ -43,7 +43,7 @@ class PlaylistWindow;
class MainWin : public BWindow { class MainWin : public BWindow {
public: public:
MainWin(); MainWin(bool isFirstWindow);
virtual ~MainWin(); virtual ~MainWin();
virtual void FrameResized(float newWidth, float newHeight); virtual void FrameResized(float newWidth, float newHeight);
@@ -86,6 +86,7 @@ private:
int& videoHeight) const; int& videoHeight) const;
int _CurrentVideoSizeInPercent() const; int _CurrentVideoSizeInPercent() const;
void _ResizeWindow(int percent, void _ResizeWindow(int percent,
bool keepWidth = false,
bool stayOnScreen = false); bool stayOnScreen = false);
void _ResizeVideoView(int x, int y, int width, void _ResizeVideoView(int x, int y, int width,
int height); int height);
@@ -114,6 +115,8 @@ private:
void _AdoptGlobalSettings(); void _AdoptGlobalSettings();
bigtime_t fCreationTime;
BMenuBar* fMenuBar; BMenuBar* fMenuBar;
BView* fBackground; BView* fBackground;
VideoView* fVideoView; VideoView* fVideoView;
+9 -2
View File
@@ -22,7 +22,8 @@ mpSettings::operator!=(const mpSettings& other) const
|| useOverlays != other.useOverlays || useOverlays != other.useOverlays
|| scaleBilinear != other.scaleBilinear || scaleBilinear != other.scaleBilinear
|| backgroundMovieVolumeMode != other.backgroundMovieVolumeMode || 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 // an "unset" entry_ref
settings.filePanelFolder = fSettingsMessage.GetValue( settings.filePanelFolder = fSettingsMessage.GetValue(
"filePanelDirectory", defaultFilePanelFolder); "filePanelDirectory", defaultFilePanelFolder);
settings.audioPlayerWindowFrame = fSettingsMessage.GetValue(
"audioPlayerWindowFrame", BRect());
} }
@@ -83,6 +87,9 @@ Settings::SaveSettings(const mpSettings& settings)
fSettingsMessage.SetValue("filePanelDirectory", fSettingsMessage.SetValue("filePanelDirectory",
settings.filePanelFolder); settings.filePanelFolder);
fSettingsMessage.SetValue("audioPlayerWindowFrame",
settings.audioPlayerWindowFrame);
// Save at this point, although saving is also done on destruction, // Save at this point, although saving is also done on destruction,
// this will make sure the settings are saved even when the player // this will make sure the settings are saved even when the player
// crashes. // crashes.
@@ -103,7 +110,7 @@ Settings::CurrentSettings()
{ {
mpSettings settings; mpSettings settings;
sGlobalInstance.LoadSettings(settings); sGlobalInstance.LoadSettings(settings);
return settings; return settings;
} }
+2
View File
@@ -32,6 +32,8 @@ struct mpSettings {
entry_ref filePanelFolder; entry_ref filePanelFolder;
bool operator!=(const mpSettings& other) const; bool operator!=(const mpSettings& other) const;
BRect audioPlayerWindowFrame;
}; };
#define SETTINGS_FILENAME "MediaPlayer" #define SETTINGS_FILENAME "MediaPlayer"