* cleanup in MainWin, better grouping of functions in .h and

moved functions in .cpp accordingly, prepended private methods with _
* disabled InfoWin, because it accessed members of MainWin directly, 
  will be reimplemented with notification mechanism
* fixed the bug with the multiple error alerts for an unsupported file,
  the window should use the current file index from the notification
  itself


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21300 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-06-02 23:22:30 +00:00
parent 9e448b6224
commit d329f1d6c1
8 changed files with 1116 additions and 1145 deletions
+164 -192
View File
@@ -70,19 +70,13 @@ InfoView::Draw(BRect updateRect)
}
InfoWin::InfoWin(MainWin *mainWin)
: BWindow(BRect(100,100,100+MIN_WIDTH-1,350), NAME, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE /* | B_WILL_ACCEPT_FIRST_CLICK */),
fMainWin(mainWin),
fController()
InfoWin::InfoWin(BPoint leftTop, Controller* controller)
: BWindow(BRect(leftTop.x, leftTop.y, leftTop.x + MIN_WIDTH - 1,
leftTop.y + 250), NAME, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE),
fController(controller)
{
BRect rect;
if (fMainWin->Lock()) {
rect = fMainWin->Frame();
MoveTo(rect.right, rect.top);
fMainWin->Unlock();
}
rect = Bounds();
BRect rect = Bounds();
// accomodate for big fonts
float div;
@@ -161,167 +155,164 @@ InfoWin::ResizeToPreferred()
void
InfoWin::Update(uint32 which)
{
status_t err;
//char buf[256];
printf("InfoWin::Update(0x%08lx)\n", which);
rgb_color vFgCol = ui_color(B_DOCUMENT_TEXT_COLOR);
fLabelsView->SelectAll();
fContentsView->SelectAll();
fLabelsView->Clear();
fContentsView->Clear();
fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kBlue);
fLabelsView->Insert("File Info\n");
fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol);
fContentsView->Insert("\n");
fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kRed);
//fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol);
// lock the Main Window as we must access some fields there...
if (fMainWin->LockWithTimeout(500000) < B_OK)
return; // XXX: resend msg to ourselves ?
Controller *c = fMainWin->fController;
BMediaFile *mf = c->fMediaFile;
if (which & INFO_VIDEO && c->VideoTrackCount() > 0) {
fLabelsView->Insert("Video\n\n");
BString s;
media_format fmt;
media_raw_video_format vfmt;
float fps;
err = c->fVideoTrack->EncodedFormat(&fmt);
//string_for_format(fmt, buf, sizeof(buf));
//printf("%s\n", buf);
if (err < 0) {
s << "(" << strerror(err) << ")";
} else if (fmt.type == B_MEDIA_ENCODED_VIDEO) {
vfmt = fmt.u.encoded_video.output;
media_codec_info mci;
err = c->fVideoTrack->GetCodecInfo(&mci);
if (err < 0)
s << "(" << strerror(err) << ")";
else
s << mci.pretty_name; //<< "(" << mci.short_name << ")";
} else if (fmt.type == B_MEDIA_RAW_VIDEO) {
vfmt = fmt.u.raw_video;
s << "raw video";
} else
s << "unknown format";
s << "\n";
s << fmt.Width() << " x " << fmt.Height();
// encoded has output as 1st field...
fps = vfmt.field_rate;
s << ", " << fps << " fps";
s << "\n";
fContentsView->Insert(s.String());
}
if (which & INFO_AUDIO && c->AudioTrackCount() > 0) {
fLabelsView->Insert("Sound\n\n");
BString s;
media_format fmt;
media_raw_audio_format afmt;
err = c->fAudioTrack->EncodedFormat(&fmt);
//string_for_format(fmt, buf, sizeof(buf));
//printf("%s\n", buf);
if (err < 0) {
s << "(" << strerror(err) << ")";
} else if (fmt.type == B_MEDIA_ENCODED_AUDIO) {
afmt = fmt.u.encoded_audio.output;
media_codec_info mci;
err = c->fAudioTrack->GetCodecInfo(&mci);
if (err < 0)
s << "(" << strerror(err) << ")";
else
s << mci.pretty_name; //<< "(" << mci.short_name << ")";
} else if (fmt.type == B_MEDIA_RAW_AUDIO) {
afmt = fmt.u.raw_audio;
s << "raw audio";
} else
s << "unknown format";
s << "\n";
uint32 bitps = 8 * (afmt.format & media_raw_audio_format::B_AUDIO_SIZE_MASK);
uint32 chans = afmt.channel_count;
float sr = afmt.frame_rate;
if (bitps)
s << bitps << " Bit ";
if (chans == 1)
s << "Mono";
else if (chans == 2)
s << "Stereo";
else
s << chans << "Channels";
s << ", ";
if (sr)
s << sr/1000;
else
s << "?";
s<< " kHz";
s << "\n";
fContentsView->Insert(s.String());
}
if (which & INFO_STATS && fMainWin->fHasFile) {
// TODO: check for live streams (no duration)
fLabelsView->Insert("Duration\n");
BString s;
bigtime_t d = c->Duration();
bigtime_t v;
//s << d << "µs; ";
d /= 1000;
v = d / (3600 * 1000);
d = d % (3600 * 1000);
if (v)
s << v << ":";
v = d / (60 * 1000);
d = d % (60 * 1000);
s << v << ":";
v = d / 1000;
d = d % 1000;
s << v;
if (d)
s << "." << d / 10;
s << "\n";
fContentsView->Insert(s.String());
// TODO: demux/video/audio/... perfs (Kb/s)
}
if (which & INFO_TRANSPORT) {
}
if ((which & INFO_FILE) && fMainWin->fHasFile) {
media_file_format ff;
if (mf && (mf->GetFileFormatInfo(&ff) == B_OK)) {
fLabelsView->Insert("Container\n");
BString s;
s << ff.pretty_name;
s << "\n";
fContentsView->Insert(s.String());
}
fLabelsView->Insert("Location\n");
// TODO: make Controller save the entry_ref (url actually).
fContentsView->Insert("file://\n");
fFilenameView->SetText(c->fName.String());
}
if (which & INFO_COPYRIGHT && mf && mf->Copyright()) {
fLabelsView->Insert("Copyright\n\n");
BString s;
s << mf->Copyright();
s << "\n\n";
fContentsView->Insert(s.String());
}
// we can unlock the main window now and let it work
fMainWin->Unlock();
// now resize the window to the list view size...
ResizeToPreferred();
if (IsHidden())
Show();
// status_t err;
// //char buf[256];
// printf("InfoWin::Update(0x%08lx)\n", which);
// rgb_color vFgCol = ui_color(B_DOCUMENT_TEXT_COLOR);
//
// fLabelsView->SelectAll();
// fContentsView->SelectAll();
// fLabelsView->Clear();
// fContentsView->Clear();
// fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kBlue);
// fLabelsView->Insert("File Info\n");
// fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol);
// fContentsView->Insert("\n");
//
// fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kRed);
// //fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol);
//
// // lock the Main Window as we must access some fields there...
// if (fMainWin->LockWithTimeout(500000) < B_OK)
// return; // XXX: resend msg to ourselves ?
//
// Controller *c = fMainWin->fController;
// BMediaFile *mf = c->fMediaFile;
//
// if (which & INFO_VIDEO && c->VideoTrackCount() > 0) {
// fLabelsView->Insert("Video\n\n");
// BString s;
// media_format fmt;
// media_raw_video_format vfmt;
// float fps;
// err = c->fVideoTrack->EncodedFormat(&fmt);
// //string_for_format(fmt, buf, sizeof(buf));
// //printf("%s\n", buf);
// if (err < 0) {
// s << "(" << strerror(err) << ")";
// } else if (fmt.type == B_MEDIA_ENCODED_VIDEO) {
// vfmt = fmt.u.encoded_video.output;
// media_codec_info mci;
// err = c->fVideoTrack->GetCodecInfo(&mci);
// if (err < 0)
// s << "(" << strerror(err) << ")";
// else
// s << mci.pretty_name; //<< "(" << mci.short_name << ")";
// } else if (fmt.type == B_MEDIA_RAW_VIDEO) {
// vfmt = fmt.u.raw_video;
// s << "raw video";
// } else
// s << "unknown format";
// s << "\n";
// s << fmt.Width() << " x " << fmt.Height();
// // encoded has output as 1st field...
// fps = vfmt.field_rate;
// s << ", " << fps << " fps";
// s << "\n";
// fContentsView->Insert(s.String());
// }
// if (which & INFO_AUDIO && c->AudioTrackCount() > 0) {
// fLabelsView->Insert("Sound\n\n");
// BString s;
// media_format fmt;
// media_raw_audio_format afmt;
// err = c->fAudioTrack->EncodedFormat(&fmt);
// //string_for_format(fmt, buf, sizeof(buf));
// //printf("%s\n", buf);
// if (err < 0) {
// s << "(" << strerror(err) << ")";
// } else if (fmt.type == B_MEDIA_ENCODED_AUDIO) {
// afmt = fmt.u.encoded_audio.output;
// media_codec_info mci;
// err = c->fAudioTrack->GetCodecInfo(&mci);
// if (err < 0)
// s << "(" << strerror(err) << ")";
// else
// s << mci.pretty_name; //<< "(" << mci.short_name << ")";
// } else if (fmt.type == B_MEDIA_RAW_AUDIO) {
// afmt = fmt.u.raw_audio;
// s << "raw audio";
// } else
// s << "unknown format";
// s << "\n";
// uint32 bitps = 8 * (afmt.format & media_raw_audio_format::B_AUDIO_SIZE_MASK);
// uint32 chans = afmt.channel_count;
// float sr = afmt.frame_rate;
//
// if (bitps)
// s << bitps << " Bit ";
// if (chans == 1)
// s << "Mono";
// else if (chans == 2)
// s << "Stereo";
// else
// s << chans << "Channels";
// s << ", ";
// if (sr)
// s << sr/1000;
// else
// s << "?";
// s<< " kHz";
// s << "\n";
// fContentsView->Insert(s.String());
// }
// if (which & INFO_STATS && fMainWin->fHasFile) {
// // TODO: check for live streams (no duration)
// fLabelsView->Insert("Duration\n");
// BString s;
// bigtime_t d = c->Duration();
// bigtime_t v;
//
// //s << d << "µs; ";
//
// d /= 1000;
//
// v = d / (3600 * 1000);
// d = d % (3600 * 1000);
// if (v)
// s << v << ":";
// v = d / (60 * 1000);
// d = d % (60 * 1000);
// s << v << ":";
// v = d / 1000;
// d = d % 1000;
// s << v;
// if (d)
// s << "." << d / 10;
// s << "\n";
// fContentsView->Insert(s.String());
// // TODO: demux/video/audio/... perfs (Kb/s)
// }
// if (which & INFO_TRANSPORT) {
// }
// if ((which & INFO_FILE) && fMainWin->fHasFile) {
// media_file_format ff;
// if (mf && (mf->GetFileFormatInfo(&ff) == B_OK)) {
// fLabelsView->Insert("Container\n");
// BString s;
// s << ff.pretty_name;
// s << "\n";
// fContentsView->Insert(s.String());
// }
// fLabelsView->Insert("Location\n");
// // TODO: make Controller save the entry_ref (url actually).
// fContentsView->Insert("file://\n");
// fFilenameView->SetText(c->fName.String());
// }
// if (which & INFO_COPYRIGHT && mf && mf->Copyright()) {
//
// fLabelsView->Insert("Copyright\n\n");
// BString s;
// s << mf->Copyright();
// s << "\n\n";
// fContentsView->Insert(s.String());
// }
//
// // we can unlock the main window now and let it work
// fMainWin->Unlock();
//
// // now resize the window to the list view size...
// ResizeToPreferred();
}
@@ -333,25 +324,6 @@ InfoWin::QuitRequested()
}
void
InfoWin::Show()
{
// notify the main window first
fMainWin->fInfoWinShowing = true;
BWindow::Show();
//SetPulseRate(1000000);
}
void
InfoWin::Hide()
{
SetPulseRate(0);
BWindow::Hide();
fMainWin->fInfoWinShowing = false;
}
void
InfoWin::Pulse()
{
+27 -28
View File
@@ -24,46 +24,45 @@
#include <TextView.h>
#include <StringView.h>
class MainWin;
class Controller;
class InfoView;
#define M_UPDATE_INFO 'upda'
#define INFO_STATS 0x00000001
#define INFO_TRANSPORT 0x00000002
#define INFO_FILE 0x00000004
#define INFO_AUDIO 0x00000008
#define INFO_VIDEO 0x00000010
#define INFO_COPYRIGHT 0x00000020
#define INFO_STATS 0x00000001
#define INFO_TRANSPORT 0x00000002
#define INFO_FILE 0x00000004
#define INFO_AUDIO 0x00000008
#define INFO_VIDEO 0x00000010
#define INFO_COPYRIGHT 0x00000020
#define INFO_ALL 0xffffffff
#define INFO_ALL 0xffffffff
class InfoWin : public BWindow
{
class InfoWin : public BWindow {
public:
InfoWin(MainWin *mainWin);
~InfoWin();
InfoWin(BPoint leftTop,
Controller* controller);
virtual ~InfoWin();
virtual void FrameResized(float newWidth, float newHeight);
virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();
virtual void Pulse();
void FrameResized(float new_width, float new_height);
void MessageReceived(BMessage *msg);
bool QuitRequested();
virtual void Show();
virtual void Hide();
virtual void Pulse();
void ResizeToPreferred();
void Update(uint32 which=INFO_ALL); // threadsafe
void ResizeToPreferred();
void Update(uint32 which=INFO_ALL); // threadsafe
MainWin * fMainWin;
Controller * fController;
InfoView * fInfoView;
BStringView * fFilenameView;
BTextView * fLabelsView;
BTextView * fContentsView;
private:
Controller* fController;
InfoView* fInfoView;
BStringView* fFilenameView;
BTextView* fLabelsView;
BTextView* fContentsView;
};
#endif
#endif // __FILE_INFO_WIN_H
+7
View File
@@ -122,6 +122,13 @@ MainApp::MessageReceived(BMessage *msg)
}
void
MainApp::AboutRequested()
{
fFirstWindow->PostMessage(B_ABOUT_REQUESTED);
}
int
main()
{
+1
View File
@@ -40,6 +40,7 @@ private:
void RefsReceived(BMessage *msg);
void ArgvReceived(int32 argc, char **argv);
void MessageReceived(BMessage *msg);
void AboutRequested();
private:
BWindow * fFirstWindow;
File diff suppressed because it is too large Load Diff
+96 -91
View File
@@ -32,106 +32,111 @@
#include "VideoView.h"
#include "Playlist.h"
class ControllerObserver;
class PlaylistObserver;
class PlaylistWindow;
class MainWin : public BWindow {
public:
MainWin();
~MainWin();
MainWin();
virtual ~MainWin();
void FrameResized(float new_width, float new_height);
void Zoom(BPoint rec_position, float rec_width, float rec_height);
void RefsReceived(BMessage *msg);
void DispatchMessage(BMessage *message, BHandler *handler);
void MessageReceived(BMessage *msg);
bool QuitRequested();
virtual void FrameResized(float newWidth, float newHeight);
virtual void Zoom(BPoint rectPosition, float rectWidth,
float rectHeight);
virtual void DispatchMessage(BMessage* message,
BHandler* handler);
virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();
void MouseDown(BMessage *msg, BView* originalHandler);
void MouseMoved(BMessage *msg, BView* originalHandler);
void MouseUp(BMessage *msg);
status_t KeyDown(BMessage *msg);
void CreateMenu();
void SetupWindow();
void SetupTrackMenus();
void SetWindowSizeLimits();
void ResizeWindow(int percent);
void ResizeVideoView(int x, int y, int width, int height);
void ShowFileInfo();
void ShowPlaylistWindow();
void MaybeUpdateFileInfo(uint32 which=INFO_ALL);
void OpenFile(const entry_ref &ref);
void VideoFormatChange(int width, int height, float width_scale, float height_scale);
void ToggleFullscreen();
void ToggleKeepAspectRatio();
void ToggleAlwaysOnTop();
void ToggleNoBorder();
void ToggleNoMenu();
void ToggleNoControls();
void ToggleNoBorderNoMenu();
void ShowContextMenu(const BPoint &screen_point);
void UpdateControlsEnabledStatus();
void _UpdatePlaylistMenu();
void _AddPlaylistItem(const entry_ref& ref, int32 index);
void _RemovePlaylistItem(int32 index);
void _MarkPlaylistItem(int32 index);
BMenuBar * fMenuBar;
BView * fBackground;
VideoView * fVideoView;
BFilePanel * fFilePanel;
ControllerView * fControls;
InfoWin * fInfoWin;
PlaylistWindow* fPlaylistWindow;
bool fInfoWinShowing;
BMenu * fFileMenu;
BMenu * fAudioMenu;
BMenu * fVideoMenu;
BMenu * fAudioTrackMenu;
BMenu * fVideoTrackMenu;
BMenu * fSettingsMenu;
BMenu * fPlaylistMenu;
BMenu * fDebugMenu;
bool fHasFile;
bool fHasVideo;
bool fHasAudio;
Playlist * fPlaylist;
PlaylistObserver* fPlaylistObserver;
Controller * fController;
ControllerObserver* fControllerObserver;
volatile bool fIsFullscreen;
volatile bool fKeepAspectRatio;
volatile bool fAlwaysOnTop;
volatile bool fNoMenu;
volatile bool fNoBorder;
volatile bool fNoControls;
int fSourceWidth;
int fSourceHeight;
float fWidthScale;
float fHeightScale;
int fMenuBarWidth;
int fMenuBarHeight;
int fControlsHeight;
int fControlsWidth;
BRect fSavedFrame;
bool fMouseDownTracking;
BPoint fMouseDownMousePos;
BPoint fMouseDownWindowPos;
void OpenFile(const entry_ref& ref);
void ShowFileInfo();
void ShowPlaylistWindow();
void VideoFormatChange(int width, int height,
float widthScale, float heightScale);
private:
void _AppendToPlaylist(const entry_ref& ref,
Playlist* playlist);
void _RefsReceived(BMessage *message);
void _SetupWindow();
void _CreateMenu();
void _SetupTrackMenus();
void _SetWindowSizeLimits();
void _ResizeWindow(int percent);
void _ResizeVideoView(int x, int y, int width,
int height);
void _MouseDown(BMessage* message,
BView* originalHandler);
void _MouseMoved(BMessage* message,
BView* originalHandler);
void _MouseUp(BMessage* message);
void _ShowContextMenu(const BPoint& screenPoint);
status_t _KeyDown(BMessage* message);
void _ToggleFullscreen();
void _ToggleKeepAspectRatio();
void _ToggleAlwaysOnTop();
void _ToggleNoBorder();
void _ToggleNoMenu();
void _ToggleNoControls();
void _ToggleNoBorderNoMenu();
void _UpdateControlsEnabledStatus();
void _UpdatePlaylistMenu();
void _AddPlaylistItem(const entry_ref& ref,
int32 index);
void _RemovePlaylistItem(int32 index);
void _MarkPlaylistItem(int32 index);
void _AppendToPlaylist(const entry_ref& ref,
Playlist* playlist);
BMenuBar* fMenuBar;
BView* fBackground;
VideoView* fVideoView;
BFilePanel* fFilePanel;
ControllerView* fControls;
InfoWin* fInfoWin;
PlaylistWindow* fPlaylistWindow;
BMenu* fFileMenu;
BMenu* fAudioMenu;
BMenu* fVideoMenu;
BMenu* fAudioTrackMenu;
BMenu* fVideoTrackMenu;
BMenu* fSettingsMenu;
BMenu* fPlaylistMenu;
BMenu* fDebugMenu;
bool fHasFile;
bool fHasVideo;
bool fHasAudio;
Playlist* fPlaylist;
PlaylistObserver* fPlaylistObserver;
Controller* fController;
ControllerObserver* fControllerObserver;
volatile bool fIsFullscreen;
volatile bool fKeepAspectRatio;
volatile bool fAlwaysOnTop;
volatile bool fNoMenu;
volatile bool fNoBorder;
volatile bool fNoControls;
int fSourceWidth;
int fSourceHeight;
float fWidthScale;
float fHeightScale;
int fMenuBarWidth;
int fMenuBarHeight;
int fControlsHeight;
int fControlsWidth;
BRect fSavedFrame;
bool fMouseDownTracking;
BPoint fMouseDownMousePos;
BPoint fMouseDownWindowPos;
};
#endif
#endif // __MAIN_WIN_H
+2 -23
View File
@@ -22,6 +22,7 @@
#include <debugger.h>
#include <new.h>
#include <stdio.h>
#include <string.h>
#include <Path.h>
@@ -188,28 +189,6 @@ Playlist::GetRefAt(int32 index, entry_ref* _ref) const
// #pragma mark -
//status_t
//Playlist::NextRef(entry_ref* ref)
//{
// int count = fRefs.CountItems();
// if (fCurrentIndex + 2 > count)
// return B_ERROR;
// *ref = *(entry_ref*)fRefs.ItemAt(++fCurrentIndex);
// return B_OK;
//}
//
//
//status_t
//Playlist::PrevRef(entry_ref* ref)
//{
// int count = fRefs.CountItems();
// if (count == 0 || fCurrentIndex <= 0)
// return B_ERROR;
// *ref = *(entry_ref*)fRefs.ItemAt(--fCurrentIndex);
// return B_OK;
//}
void
Playlist::SetCurrentRefIndex(int32 index)
{
@@ -257,7 +236,7 @@ Playlist::RemoveListener(Listener* listener)
}
// pragma mark -
// #pragma mark -
int
-4
View File
@@ -61,10 +61,6 @@ public:
// bool HasRef(const entry_ref& ref) const;
// navigating current ref
// TODO: replace with SetCurrentRef() and listener
// status_t NextRef(entry_ref* ref);
// status_t PrevRef(entry_ref* ref);
void SetCurrentRefIndex(int32 index);
int32 CurrentRefIndex() const;