* 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
+163 -191
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->Insert("\n");
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);
// fContentsView->Insert("\n");
// lock the Main Window as we must access some fields there... //
if (fMainWin->LockWithTimeout(500000) < B_OK) // fLabelsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kRed);
return; // XXX: resend msg to ourselves ? // //fContentsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &vFgCol);
//
Controller *c = fMainWin->fController; // // lock the Main Window as we must access some fields there...
BMediaFile *mf = c->fMediaFile; // if (fMainWin->LockWithTimeout(500000) < B_OK)
// return; // XXX: resend msg to ourselves ?
if (which & INFO_VIDEO && c->VideoTrackCount() > 0) { //
fLabelsView->Insert("Video\n\n"); // Controller *c = fMainWin->fController;
BString s; // BMediaFile *mf = c->fMediaFile;
media_format fmt; //
media_raw_video_format vfmt; // if (which & INFO_VIDEO && c->VideoTrackCount() > 0) {
float fps; // fLabelsView->Insert("Video\n\n");
err = c->fVideoTrack->EncodedFormat(&fmt); // BString s;
//string_for_format(fmt, buf, sizeof(buf)); // media_format fmt;
//printf("%s\n", buf); // media_raw_video_format vfmt;
if (err < 0) { // float fps;
s << "(" << strerror(err) << ")"; // err = c->fVideoTrack->EncodedFormat(&fmt);
} else if (fmt.type == B_MEDIA_ENCODED_VIDEO) { // //string_for_format(fmt, buf, sizeof(buf));
vfmt = fmt.u.encoded_video.output; // //printf("%s\n", buf);
media_codec_info mci; // if (err < 0) {
err = c->fVideoTrack->GetCodecInfo(&mci); // s << "(" << strerror(err) << ")";
if (err < 0) // } else if (fmt.type == B_MEDIA_ENCODED_VIDEO) {
s << "(" << strerror(err) << ")"; // vfmt = fmt.u.encoded_video.output;
else // media_codec_info mci;
s << mci.pretty_name; //<< "(" << mci.short_name << ")"; // err = c->fVideoTrack->GetCodecInfo(&mci);
} else if (fmt.type == B_MEDIA_RAW_VIDEO) { // if (err < 0)
vfmt = fmt.u.raw_video; // s << "(" << strerror(err) << ")";
s << "raw video"; // else
} else // s << mci.pretty_name; //<< "(" << mci.short_name << ")";
s << "unknown format"; // } else if (fmt.type == B_MEDIA_RAW_VIDEO) {
s << "\n"; // vfmt = fmt.u.raw_video;
s << fmt.Width() << " x " << fmt.Height(); // s << "raw video";
// encoded has output as 1st field... // } else
fps = vfmt.field_rate; // s << "unknown format";
s << ", " << fps << " fps"; // s << "\n";
s << "\n"; // s << fmt.Width() << " x " << fmt.Height();
fContentsView->Insert(s.String()); // // encoded has output as 1st field...
} // fps = vfmt.field_rate;
if (which & INFO_AUDIO && c->AudioTrackCount() > 0) { // s << ", " << fps << " fps";
fLabelsView->Insert("Sound\n\n"); // s << "\n";
BString s; // fContentsView->Insert(s.String());
media_format fmt; // }
media_raw_audio_format afmt; // if (which & INFO_AUDIO && c->AudioTrackCount() > 0) {
err = c->fAudioTrack->EncodedFormat(&fmt); // fLabelsView->Insert("Sound\n\n");
//string_for_format(fmt, buf, sizeof(buf)); // BString s;
//printf("%s\n", buf); // media_format fmt;
if (err < 0) { // media_raw_audio_format afmt;
s << "(" << strerror(err) << ")"; // err = c->fAudioTrack->EncodedFormat(&fmt);
} else if (fmt.type == B_MEDIA_ENCODED_AUDIO) { // //string_for_format(fmt, buf, sizeof(buf));
afmt = fmt.u.encoded_audio.output; // //printf("%s\n", buf);
media_codec_info mci; // if (err < 0) {
err = c->fAudioTrack->GetCodecInfo(&mci); // s << "(" << strerror(err) << ")";
if (err < 0) // } else if (fmt.type == B_MEDIA_ENCODED_AUDIO) {
s << "(" << strerror(err) << ")"; // afmt = fmt.u.encoded_audio.output;
else // media_codec_info mci;
s << mci.pretty_name; //<< "(" << mci.short_name << ")"; // err = c->fAudioTrack->GetCodecInfo(&mci);
} else if (fmt.type == B_MEDIA_RAW_AUDIO) { // if (err < 0)
afmt = fmt.u.raw_audio; // s << "(" << strerror(err) << ")";
s << "raw audio"; // else
} else // s << mci.pretty_name; //<< "(" << mci.short_name << ")";
s << "unknown format"; // } else if (fmt.type == B_MEDIA_RAW_AUDIO) {
s << "\n"; // afmt = fmt.u.raw_audio;
uint32 bitps = 8 * (afmt.format & media_raw_audio_format::B_AUDIO_SIZE_MASK); // s << "raw audio";
uint32 chans = afmt.channel_count; // } else
float sr = afmt.frame_rate; // s << "unknown format";
// s << "\n";
if (bitps) // uint32 bitps = 8 * (afmt.format & media_raw_audio_format::B_AUDIO_SIZE_MASK);
s << bitps << " Bit "; // uint32 chans = afmt.channel_count;
if (chans == 1) // float sr = afmt.frame_rate;
s << "Mono"; //
else if (chans == 2) // if (bitps)
s << "Stereo"; // s << bitps << " Bit ";
else // if (chans == 1)
s << chans << "Channels"; // s << "Mono";
s << ", "; // else if (chans == 2)
if (sr) // s << "Stereo";
s << sr/1000; // else
else // s << chans << "Channels";
s << "?"; // s << ", ";
s<< " kHz"; // if (sr)
s << "\n"; // s << sr/1000;
fContentsView->Insert(s.String()); // else
} // s << "?";
if (which & INFO_STATS && fMainWin->fHasFile) { // s<< " kHz";
// TODO: check for live streams (no duration) // s << "\n";
fLabelsView->Insert("Duration\n"); // fContentsView->Insert(s.String());
BString s; // }
bigtime_t d = c->Duration(); // if (which & INFO_STATS && fMainWin->fHasFile) {
bigtime_t v; // // TODO: check for live streams (no duration)
// fLabelsView->Insert("Duration\n");
//s << d << "µs; "; // BString s;
// bigtime_t d = c->Duration();
d /= 1000; // bigtime_t v;
//
v = d / (3600 * 1000); // //s << d << "µs; ";
d = d % (3600 * 1000); //
if (v) // d /= 1000;
s << v << ":"; //
v = d / (60 * 1000); // v = d / (3600 * 1000);
d = d % (60 * 1000); // d = d % (3600 * 1000);
s << v << ":"; // if (v)
v = d / 1000; // s << v << ":";
d = d % 1000; // v = d / (60 * 1000);
s << v; // d = d % (60 * 1000);
if (d) // s << v << ":";
s << "." << d / 10; // v = d / 1000;
s << "\n"; // d = d % 1000;
fContentsView->Insert(s.String()); // s << v;
// TODO: demux/video/audio/... perfs (Kb/s) // if (d)
} // s << "." << d / 10;
if (which & INFO_TRANSPORT) { // s << "\n";
} // fContentsView->Insert(s.String());
if ((which & INFO_FILE) && fMainWin->fHasFile) { // // TODO: demux/video/audio/... perfs (Kb/s)
media_file_format ff; // }
if (mf && (mf->GetFileFormatInfo(&ff) == B_OK)) { // if (which & INFO_TRANSPORT) {
fLabelsView->Insert("Container\n"); // }
BString s; // if ((which & INFO_FILE) && fMainWin->fHasFile) {
s << ff.pretty_name; // media_file_format ff;
s << "\n"; // if (mf && (mf->GetFileFormatInfo(&ff) == B_OK)) {
fContentsView->Insert(s.String()); // fLabelsView->Insert("Container\n");
} // BString s;
fLabelsView->Insert("Location\n"); // s << ff.pretty_name;
// TODO: make Controller save the entry_ref (url actually). // s << "\n";
fContentsView->Insert("file://\n"); // fContentsView->Insert(s.String());
fFilenameView->SetText(c->fName.String()); // }
} // fLabelsView->Insert("Location\n");
if (which & INFO_COPYRIGHT && mf && mf->Copyright()) { // // TODO: make Controller save the entry_ref (url actually).
// fContentsView->Insert("file://\n");
fLabelsView->Insert("Copyright\n\n"); // fFilenameView->SetText(c->fName.String());
BString s; // }
s << mf->Copyright(); // if (which & INFO_COPYRIGHT && mf && mf->Copyright()) {
s << "\n\n"; //
fContentsView->Insert(s.String()); // fLabelsView->Insert("Copyright\n\n");
} // BString s;
// s << mf->Copyright();
// we can unlock the main window now and let it work // s << "\n\n";
fMainWin->Unlock(); // fContentsView->Insert(s.String());
// }
// now resize the window to the list view size... //
ResizeToPreferred(); // // we can unlock the main window now and let it work
// fMainWin->Unlock();
if (IsHidden()) //
Show(); // // 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 void
InfoWin::Pulse() InfoWin::Pulse()
{ {
+10 -11
View File
@@ -24,6 +24,7 @@
#include <TextView.h> #include <TextView.h>
#include <StringView.h> #include <StringView.h>
class MainWin; class MainWin;
class Controller; class Controller;
class InfoView; class InfoView;
@@ -40,23 +41,21 @@ class InfoView;
#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 Hide();
virtual void Pulse(); 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;
@@ -66,4 +65,4 @@ public:
}; };
#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
+45 -40
View File
@@ -32,6 +32,7 @@
#include "VideoView.h" #include "VideoView.h"
#include "Playlist.h" #include "Playlist.h"
class ControllerObserver; class ControllerObserver;
class PlaylistObserver; class PlaylistObserver;
class PlaylistWindow; class PlaylistWindow;
@@ -39,50 +40,59 @@ 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 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 OpenFile(const entry_ref& ref);
void VideoFormatChange(int width, int height, float width_scale, float height_scale); void ShowFileInfo();
void ShowPlaylistWindow();
void ToggleFullscreen(); void VideoFormatChange(int width, int height,
void ToggleKeepAspectRatio(); float widthScale, float heightScale);
void ToggleAlwaysOnTop();
void ToggleNoBorder();
void ToggleNoMenu();
void ToggleNoControls();
void ToggleNoBorderNoMenu();
void ShowContextMenu(const BPoint &screen_point); private:
void _RefsReceived(BMessage *message);
void UpdateControlsEnabledStatus(); 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 _UpdatePlaylistMenu();
void _AddPlaylistItem(const entry_ref& ref, int32 index); void _AddPlaylistItem(const entry_ref& ref,
int32 index);
void _RemovePlaylistItem(int32 index); void _RemovePlaylistItem(int32 index);
void _MarkPlaylistItem(int32 index); void _MarkPlaylistItem(int32 index);
void _AppendToPlaylist(const entry_ref& ref,
Playlist* playlist);
BMenuBar* fMenuBar; BMenuBar* fMenuBar;
BView* fBackground; BView* fBackground;
@@ -91,7 +101,6 @@ public:
ControllerView* fControls; ControllerView* fControls;
InfoWin* fInfoWin; InfoWin* fInfoWin;
PlaylistWindow* fPlaylistWindow; PlaylistWindow* fPlaylistWindow;
bool fInfoWinShowing;
BMenu* fFileMenu; BMenu* fFileMenu;
BMenu* fAudioMenu; BMenu* fAudioMenu;
@@ -128,10 +137,6 @@ public:
bool fMouseDownTracking; bool fMouseDownTracking;
BPoint fMouseDownMousePos; BPoint fMouseDownMousePos;
BPoint fMouseDownWindowPos; BPoint fMouseDownWindowPos;
private:
void _AppendToPlaylist(const entry_ref& ref,
Playlist* playlist);
}; };
#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;