* 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) InfoWin::InfoWin(BPoint leftTop, Controller* controller)
: BWindow(BRect(100,100,100+MIN_WIDTH-1,350), NAME, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE /* | B_WILL_ACCEPT_FIRST_CLICK */), : BWindow(BRect(leftTop.x, leftTop.y, leftTop.x + MIN_WIDTH - 1,
fMainWin(mainWin), leftTop.y + 250), NAME, B_TITLED_WINDOW,
fController() B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE),
fController(controller)
{ {
BRect rect; BRect rect = Bounds();
if (fMainWin->Lock()) {
rect = fMainWin->Frame();
MoveTo(rect.right, rect.top);
fMainWin->Unlock();
}
rect = Bounds();
// accomodate for big fonts // accomodate for big fonts
float div; float div;
@@ -161,167 +155,164 @@ InfoWin::ResizeToPreferred()
void void
InfoWin::Update(uint32 which) InfoWin::Update(uint32 which)
{ {
status_t err; // status_t err;
//char buf[256]; // //char buf[256];
printf("InfoWin::Update(0x%08lx)\n", which); // printf("InfoWin::Update(0x%08lx)\n", which);
rgb_color vFgCol = ui_color(B_DOCUMENT_TEXT_COLOR); // rgb_color vFgCol = ui_color(B_DOCUMENT_TEXT_COLOR);
//
fLabelsView->SelectAll(); // fLabelsView->SelectAll();
fContentsView->SelectAll(); // fContentsView->SelectAll();
fLabelsView->Clear(); // fLabelsView->Clear();
fContentsView->Clear(); // fContentsView->Clear();
fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kBlue); // fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kBlue);
fLabelsView->Insert("File Info\n"); // fLabelsView->Insert("File Info\n");
fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol); // fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol);
fContentsView->Insert("\n"); // fContentsView->Insert("\n");
//
fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kRed); // fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kRed);
//fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol); // //fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol);
//
// lock the Main Window as we must access some fields there... // // lock the Main Window as we must access some fields there...
if (fMainWin->LockWithTimeout(500000) < B_OK) // if (fMainWin->LockWithTimeout(500000) < B_OK)
return; // XXX: resend msg to ourselves ? // return; // XXX: resend msg to ourselves ?
//
Controller *c = fMainWin->fController; // Controller *c = fMainWin->fController;
BMediaFile *mf = c->fMediaFile; // BMediaFile *mf = c->fMediaFile;
//
if (which & INFO_VIDEO && c->VideoTrackCount() > 0) { // if (which & INFO_VIDEO && c->VideoTrackCount() > 0) {
fLabelsView->Insert("Video\n\n"); // fLabelsView->Insert("Video\n\n");
BString s; // BString s;
media_format fmt; // media_format fmt;
media_raw_video_format vfmt; // media_raw_video_format vfmt;
float fps; // float fps;
err = c->fVideoTrack->EncodedFormat(&fmt); // err = c->fVideoTrack->EncodedFormat(&fmt);
//string_for_format(fmt, buf, sizeof(buf)); // //string_for_format(fmt, buf, sizeof(buf));
//printf("%s\n", buf); // //printf("%s\n", buf);
if (err < 0) { // if (err < 0) {
s << "(" << strerror(err) << ")"; // s << "(" << strerror(err) << ")";
} else if (fmt.type == B_MEDIA_ENCODED_VIDEO) { // } else if (fmt.type == B_MEDIA_ENCODED_VIDEO) {
vfmt = fmt.u.encoded_video.output; // vfmt = fmt.u.encoded_video.output;
media_codec_info mci; // media_codec_info mci;
err = c->fVideoTrack->GetCodecInfo(&mci); // err = c->fVideoTrack->GetCodecInfo(&mci);
if (err < 0) // if (err < 0)
s << "(" << strerror(err) << ")"; // s << "(" << strerror(err) << ")";
else // else
s << mci.pretty_name; //<< "(" << mci.short_name << ")"; // s << mci.pretty_name; //<< "(" << mci.short_name << ")";
} else if (fmt.type == B_MEDIA_RAW_VIDEO) { // } else if (fmt.type == B_MEDIA_RAW_VIDEO) {
vfmt = fmt.u.raw_video; // vfmt = fmt.u.raw_video;
s << "raw video"; // s << "raw video";
} else // } else
s << "unknown format"; // s << "unknown format";
s << "\n"; // s << "\n";
s << fmt.Width() << " x " << fmt.Height(); // s << fmt.Width() << " x " << fmt.Height();
// encoded has output as 1st field... // // encoded has output as 1st field...
fps = vfmt.field_rate; // fps = vfmt.field_rate;
s << ", " << fps << " fps"; // s << ", " << fps << " fps";
s << "\n"; // s << "\n";
fContentsView->Insert(s.String()); // fContentsView->Insert(s.String());
} // }
if (which & INFO_AUDIO && c->AudioTrackCount() > 0) { // if (which & INFO_AUDIO && c->AudioTrackCount() > 0) {
fLabelsView->Insert("Sound\n\n"); // fLabelsView->Insert("Sound\n\n");
BString s; // BString s;
media_format fmt; // media_format fmt;
media_raw_audio_format afmt; // media_raw_audio_format afmt;
err = c->fAudioTrack->EncodedFormat(&fmt); // err = c->fAudioTrack->EncodedFormat(&fmt);
//string_for_format(fmt, buf, sizeof(buf)); // //string_for_format(fmt, buf, sizeof(buf));
//printf("%s\n", buf); // //printf("%s\n", buf);
if (err < 0) { // if (err < 0) {
s << "(" << strerror(err) << ")"; // s << "(" << strerror(err) << ")";
} else if (fmt.type == B_MEDIA_ENCODED_AUDIO) { // } else if (fmt.type == B_MEDIA_ENCODED_AUDIO) {
afmt = fmt.u.encoded_audio.output; // afmt = fmt.u.encoded_audio.output;
media_codec_info mci; // media_codec_info mci;
err = c->fAudioTrack->GetCodecInfo(&mci); // err = c->fAudioTrack->GetCodecInfo(&mci);
if (err < 0) // if (err < 0)
s << "(" << strerror(err) << ")"; // s << "(" << strerror(err) << ")";
else // else
s << mci.pretty_name; //<< "(" << mci.short_name << ")"; // s << mci.pretty_name; //<< "(" << mci.short_name << ")";
} else if (fmt.type == B_MEDIA_RAW_AUDIO) { // } else if (fmt.type == B_MEDIA_RAW_AUDIO) {
afmt = fmt.u.raw_audio; // afmt = fmt.u.raw_audio;
s << "raw audio"; // s << "raw audio";
} else // } else
s << "unknown format"; // s << "unknown format";
s << "\n"; // s << "\n";
uint32 bitps = 8 * (afmt.format & media_raw_audio_format::B_AUDIO_SIZE_MASK); // uint32 bitps = 8 * (afmt.format & media_raw_audio_format::B_AUDIO_SIZE_MASK);
uint32 chans = afmt.channel_count; // uint32 chans = afmt.channel_count;
float sr = afmt.frame_rate; // float sr = afmt.frame_rate;
//
if (bitps) // if (bitps)
s << bitps << " Bit "; // s << bitps << " Bit ";
if (chans == 1) // if (chans == 1)
s << "Mono"; // s << "Mono";
else if (chans == 2) // else if (chans == 2)
s << "Stereo"; // s << "Stereo";
else // else
s << chans << "Channels"; // s << chans << "Channels";
s << ", "; // s << ", ";
if (sr) // if (sr)
s << sr/1000; // s << sr/1000;
else // else
s << "?"; // s << "?";
s<< " kHz"; // s<< " kHz";
s << "\n"; // s << "\n";
fContentsView->Insert(s.String()); // fContentsView->Insert(s.String());
} // }
if (which & INFO_STATS && fMainWin->fHasFile) { // if (which & INFO_STATS && fMainWin->fHasFile) {
// TODO: check for live streams (no duration) // // TODO: check for live streams (no duration)
fLabelsView->Insert("Duration\n"); // fLabelsView->Insert("Duration\n");
BString s; // BString s;
bigtime_t d = c->Duration(); // bigtime_t d = c->Duration();
bigtime_t v; // bigtime_t v;
//
//s << d << "µs; "; // //s << d << "µs; ";
//
d /= 1000; // d /= 1000;
//
v = d / (3600 * 1000); // v = d / (3600 * 1000);
d = d % (3600 * 1000); // d = d % (3600 * 1000);
if (v) // if (v)
s << v << ":"; // s << v << ":";
v = d / (60 * 1000); // v = d / (60 * 1000);
d = d % (60 * 1000); // d = d % (60 * 1000);
s << v << ":"; // s << v << ":";
v = d / 1000; // v = d / 1000;
d = d % 1000; // d = d % 1000;
s << v; // s << v;
if (d) // if (d)
s << "." << d / 10; // s << "." << d / 10;
s << "\n"; // s << "\n";
fContentsView->Insert(s.String()); // fContentsView->Insert(s.String());
// TODO: demux/video/audio/... perfs (Kb/s) // // TODO: demux/video/audio/... perfs (Kb/s)
} // }
if (which & INFO_TRANSPORT) { // if (which & INFO_TRANSPORT) {
} // }
if ((which & INFO_FILE) && fMainWin->fHasFile) { // if ((which & INFO_FILE) && fMainWin->fHasFile) {
media_file_format ff; // media_file_format ff;
if (mf && (mf->GetFileFormatInfo(&ff) == B_OK)) { // if (mf && (mf->GetFileFormatInfo(&ff) == B_OK)) {
fLabelsView->Insert("Container\n"); // fLabelsView->Insert("Container\n");
BString s; // BString s;
s << ff.pretty_name; // s << ff.pretty_name;
s << "\n"; // s << "\n";
fContentsView->Insert(s.String()); // fContentsView->Insert(s.String());
} // }
fLabelsView->Insert("Location\n"); // fLabelsView->Insert("Location\n");
// TODO: make Controller save the entry_ref (url actually). // // TODO: make Controller save the entry_ref (url actually).
fContentsView->Insert("file://\n"); // fContentsView->Insert("file://\n");
fFilenameView->SetText(c->fName.String()); // fFilenameView->SetText(c->fName.String());
} // }
if (which & INFO_COPYRIGHT && mf && mf->Copyright()) { // if (which & INFO_COPYRIGHT && mf && mf->Copyright()) {
//
fLabelsView->Insert("Copyright\n\n"); // fLabelsView->Insert("Copyright\n\n");
BString s; // BString s;
s << mf->Copyright(); // s << mf->Copyright();
s << "\n\n"; // s << "\n\n";
fContentsView->Insert(s.String()); // fContentsView->Insert(s.String());
} // }
//
// we can unlock the main window now and let it work // // we can unlock the main window now and let it work
fMainWin->Unlock(); // fMainWin->Unlock();
//
// now resize the window to the list view size... // // now resize the window to the list view size...
ResizeToPreferred(); // ResizeToPreferred();
if (IsHidden())
Show();
} }
@@ -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 void
InfoWin::Pulse() InfoWin::Pulse()
{ {
+25 -26
View File
@@ -24,46 +24,45 @@
#include <TextView.h> #include <TextView.h>
#include <StringView.h> #include <StringView.h>
class MainWin; class MainWin;
class Controller; class Controller;
class InfoView; class InfoView;
#define M_UPDATE_INFO 'upda' #define M_UPDATE_INFO 'upda'
#define INFO_STATS 0x00000001 #define INFO_STATS 0x00000001
#define INFO_TRANSPORT 0x00000002 #define INFO_TRANSPORT 0x00000002
#define INFO_FILE 0x00000004 #define INFO_FILE 0x00000004
#define INFO_AUDIO 0x00000008 #define INFO_AUDIO 0x00000008
#define INFO_VIDEO 0x00000010 #define INFO_VIDEO 0x00000010
#define INFO_COPYRIGHT 0x00000020 #define INFO_COPYRIGHT 0x00000020
#define INFO_ALL 0xffffffff #define INFO_ALL 0xffffffff
class InfoWin : public BWindow class InfoWin : public BWindow {
{
public: public:
InfoWin(MainWin *mainWin); InfoWin(BPoint leftTop,
~InfoWin(); Controller* controller);
virtual ~InfoWin();
void FrameResized(float new_width, float new_height); virtual void FrameResized(float newWidth, float newHeight);
void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage* message);
bool QuitRequested(); virtual bool QuitRequested();
virtual void Show(); virtual void Pulse();
virtual void Hide();
virtual void Pulse();
void ResizeToPreferred(); void ResizeToPreferred();
void Update(uint32 which=INFO_ALL); // threadsafe void Update(uint32 which=INFO_ALL); // threadsafe
MainWin * fMainWin; private:
Controller * fController; Controller* fController;
InfoView * fInfoView; InfoView* fInfoView;
BStringView * fFilenameView; BStringView* fFilenameView;
BTextView * fLabelsView; BTextView* fLabelsView;
BTextView * fContentsView; 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 int
main() main()
{ {
+1
View File
@@ -40,6 +40,7 @@ private:
void RefsReceived(BMessage *msg); void RefsReceived(BMessage *msg);
void ArgvReceived(int32 argc, char **argv); void ArgvReceived(int32 argc, char **argv);
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void AboutRequested();
private: private:
BWindow * fFirstWindow; BWindow * fFirstWindow;
File diff suppressed because it is too large Load Diff
+94 -89
View File
@@ -32,106 +32,111 @@
#include "VideoView.h" #include "VideoView.h"
#include "Playlist.h" #include "Playlist.h"
class ControllerObserver; class ControllerObserver;
class PlaylistObserver; class PlaylistObserver;
class PlaylistWindow; class PlaylistWindow;
class MainWin : public BWindow { class MainWin : public BWindow {
public: public:
MainWin(); MainWin();
~MainWin(); virtual ~MainWin();
void FrameResized(float new_width, float new_height); virtual void FrameResized(float newWidth, float newHeight);
void Zoom(BPoint rec_position, float rec_width, float rec_height); virtual void Zoom(BPoint rectPosition, float rectWidth,
void RefsReceived(BMessage *msg); float rectHeight);
void DispatchMessage(BMessage *message, BHandler *handler); virtual void DispatchMessage(BMessage* message,
void MessageReceived(BMessage *msg); BHandler* handler);
bool QuitRequested(); virtual void MessageReceived(BMessage* message);
virtual bool QuitRequested();
void MouseDown(BMessage *msg, BView* originalHandler); void OpenFile(const entry_ref& ref);
void MouseMoved(BMessage *msg, BView* originalHandler);
void MouseUp(BMessage *msg);
status_t KeyDown(BMessage *msg);
void CreateMenu(); void ShowFileInfo();
void SetupWindow(); void ShowPlaylistWindow();
void SetupTrackMenus();
void SetWindowSizeLimits();
void ResizeWindow(int percent);
void ResizeVideoView(int x, int y, int width, int height);
void ShowFileInfo(); void VideoFormatChange(int width, int height,
void ShowPlaylistWindow(); float widthScale, float heightScale);
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;
private: private:
void _AppendToPlaylist(const entry_ref& ref, void _RefsReceived(BMessage *message);
Playlist* playlist);
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 <debugger.h>
#include <new.h> #include <new.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <Path.h> #include <Path.h>
@@ -188,28 +189,6 @@ Playlist::GetRefAt(int32 index, entry_ref* _ref) const
// #pragma mark - // #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 void
Playlist::SetCurrentRefIndex(int32 index) Playlist::SetCurrentRefIndex(int32 index)
{ {
@@ -257,7 +236,7 @@ Playlist::RemoveListener(Listener* listener)
} }
// pragma mark - // #pragma mark -
int int
-4
View File
@@ -61,10 +61,6 @@ public:
// bool HasRef(const entry_ref& ref) const; // bool HasRef(const entry_ref& ref) const;
// navigating current ref // 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); void SetCurrentRefIndex(int32 index);
int32 CurrentRefIndex() const; int32 CurrentRefIndex() const;