*Update MediaConverter to use the Layout API
*Replace StatusView class with BStringView *Rename some variables (fBox1 -> fSourcesBox, for example) *Create MediaFileInfo struct to cache strings for media files, these were previously created on each call to MediaFileInfoView::Draw() *Update MediaFileInfoView class for layout-friendliness and hopefully better performance. *Update other classes for layout-friendliness as well (just remove BRect and resizeFlags params) *Add keyboard accels for Open and Quit items in menuBar *closes #4197 *fixes CIDs 1545 and 1455 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38346 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
424f57123c
commit
dd55ed1aef
@ -6,9 +6,9 @@ Application MediaConverter :
|
|||||||
MediaConverterApp.cpp
|
MediaConverterApp.cpp
|
||||||
MediaConverterWindow.cpp
|
MediaConverterWindow.cpp
|
||||||
MediaEncoderWindow.cpp
|
MediaEncoderWindow.cpp
|
||||||
|
MediaFileInfo.cpp
|
||||||
MediaFileInfoView.cpp
|
MediaFileInfoView.cpp
|
||||||
MediaFileListView.cpp
|
MediaFileListView.cpp
|
||||||
StatusView.cpp
|
|
||||||
|
|
||||||
: be media tracker $(TARGET_LIBSTDC++)
|
: be media tracker $(TARGET_LIBSTDC++)
|
||||||
: MediaConverter.rdef
|
: MediaConverter.rdef
|
||||||
|
@ -93,8 +93,9 @@ MediaConverterApp::ReadyToRun()
|
|||||||
fWin->PostMessage(INIT_FORMAT_MENUS);
|
fWin->PostMessage(INIT_FORMAT_MENUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaConverterApp::RefsReceived(BMessage *msg)
|
MediaConverterApp::RefsReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
@ -124,7 +125,7 @@ MediaConverterApp::RefsReceived(BMessage *msg)
|
|||||||
alertText << errors << ((errors > 1) ? FILES : FILE)
|
alertText << errors << ((errors > 1) ? FILES : FILE)
|
||||||
<< NOTRECOGNIZE << "\n";
|
<< NOTRECOGNIZE << "\n";
|
||||||
alertText << errorFiles;
|
alertText << errorFiles;
|
||||||
BAlert *alert = new BAlert(ERROR_LOAD_STRING, alertText.String(),
|
BAlert* alert = new BAlert(ERROR_LOAD_STRING, alertText.String(),
|
||||||
CONTINUE_STRING , NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
CONTINUE_STRING , NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
}
|
}
|
||||||
@ -163,7 +164,7 @@ MediaConverterApp::StartConverting()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaConverterApp::SetStatusMessage(const char *message)
|
MediaConverterApp::SetStatusMessage(const char* message)
|
||||||
{
|
{
|
||||||
if (fWin != NULL && fWin->Lock()) {
|
if (fWin != NULL && fWin->Lock()) {
|
||||||
fWin->SetStatusMessage(message);
|
fWin->SetStatusMessage(message);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright 1999, Be Incorporated. All Rights Reserved.
|
// Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||||
// Copyright 2000-2004, Jun Suzuki. All Rights Reserved.
|
// Copyright 2000-2004, Jun Suzuki. All Rights Reserved.
|
||||||
// Copyright 2007, Stephan Aßmus. All Rights Reserved.
|
// Copyright 2007, Stephan Aßmus. All Rights Reserved.
|
||||||
|
// Copyright 2010, Haiku, Inc. All Rights Reserved.
|
||||||
// This file may be used under the terms of the Be Sample Code License.
|
// This file may be used under the terms of the Be Sample Code License.
|
||||||
#include "MediaConverterWindow.h"
|
#include "MediaConverterWindow.h"
|
||||||
|
|
||||||
@ -11,7 +12,9 @@
|
|||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
|
#include <ControlLook.h>
|
||||||
#include <FilePanel.h>
|
#include <FilePanel.h>
|
||||||
|
#include <LayoutBuilder.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <MenuField.h>
|
#include <MenuField.h>
|
||||||
@ -28,7 +31,6 @@
|
|||||||
#include "MediaFileInfoView.h"
|
#include "MediaFileInfoView.h"
|
||||||
#include "MediaFileListView.h"
|
#include "MediaFileListView.h"
|
||||||
#include "MessageConstants.h"
|
#include "MessageConstants.h"
|
||||||
#include "StatusView.h"
|
|
||||||
#include "Strings.h"
|
#include "Strings.h"
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +61,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
FileFormatMenuItem::FileFormatMenuItem(media_file_format *format)
|
FileFormatMenuItem::FileFormatMenuItem(media_file_format *format)
|
||||||
: BMenuItem(format->pretty_name, new BMessage(FORMAT_SELECT_MESSAGE))
|
:
|
||||||
|
BMenuItem(format->pretty_name, new BMessage(FORMAT_SELECT_MESSAGE))
|
||||||
{
|
{
|
||||||
memcpy(&fFileFormat, format, sizeof(fFileFormat));
|
memcpy(&fFileFormat, format, sizeof(fFileFormat));
|
||||||
}
|
}
|
||||||
@ -83,7 +86,8 @@ class CodecMenuItem : public BMenuItem {
|
|||||||
|
|
||||||
|
|
||||||
CodecMenuItem::CodecMenuItem(media_codec_info *ci, uint32 msg_type)
|
CodecMenuItem::CodecMenuItem(media_codec_info *ci, uint32 msg_type)
|
||||||
: BMenuItem(ci->pretty_name, new BMessage(msg_type))
|
:
|
||||||
|
BMenuItem(ci->pretty_name, new BMessage(msg_type))
|
||||||
{
|
{
|
||||||
memcpy(&fCodecInfo, ci, sizeof(fCodecInfo));
|
memcpy(&fCodecInfo, ci, sizeof(fCodecInfo));
|
||||||
}
|
}
|
||||||
@ -98,20 +102,17 @@ CodecMenuItem::~CodecMenuItem()
|
|||||||
|
|
||||||
|
|
||||||
MediaConverterWindow::MediaConverterWindow(BRect frame)
|
MediaConverterWindow::MediaConverterWindow(BRect frame)
|
||||||
: BWindow(frame, "MediaConverter", B_TITLED_WINDOW_LOOK,
|
:
|
||||||
B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
|
BWindow(frame, "MediaConverter", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
|
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
|
||||||
, fVideoQuality(75)
|
fVideoQuality(75),
|
||||||
, fAudioQuality(75)
|
fAudioQuality(75),
|
||||||
|
fSaveFilePanel(NULL),
|
||||||
, fSaveFilePanel(NULL)
|
fOpenFilePanel(NULL),
|
||||||
, fOpenFilePanel(NULL)
|
fOutputDirSpecified(false),
|
||||||
|
fEnabled(true),
|
||||||
, fOutputDirSpecified(false)
|
fConverting(false),
|
||||||
|
fCancelling(false)
|
||||||
, fEnabled(true)
|
|
||||||
, fConverting(false)
|
|
||||||
, fCancelling(false)
|
|
||||||
{
|
{
|
||||||
char defaultdirectory[] = "/boot/home";
|
char defaultdirectory[] = "/boot/home";
|
||||||
fOutputDir.SetTo(defaultdirectory);
|
fOutputDir.SetTo(defaultdirectory);
|
||||||
@ -132,177 +133,109 @@ MediaConverterWindow::MediaConverterWindow(BRect frame)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BRect dummyRect(0, 0, 10, 10);
|
fMenuBar = new BMenuBar("menubar");
|
||||||
fMenuBar = new BMenuBar(dummyRect, "menubar");
|
|
||||||
_CreateMenu();
|
_CreateMenu();
|
||||||
AddChild(fMenuBar);
|
|
||||||
|
|
||||||
// background
|
fListView = new MediaFileListView();
|
||||||
BRect r(frame);
|
fListView->SetExplicitMinSize(BSize(100, B_SIZE_UNSET));
|
||||||
r.OffsetTo(0, 0);
|
BScrollView* scroller = new BScrollView(NULL, fListView, 0, false, true);
|
||||||
BView *background = new BView(r, NULL, B_FOLLOW_ALL_SIDES, 0);
|
|
||||||
rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR);
|
|
||||||
background->SetViewColor(c);
|
|
||||||
background->SetLowColor(c);
|
|
||||||
r.InsetBy(5, 25);
|
|
||||||
|
|
||||||
// file list view box
|
// file list view box
|
||||||
BRect r2(r);
|
fSourcesBox = new BBox(B_FANCY_BORDER, scroller);
|
||||||
r2.bottom = r2.top + 420;
|
fSourcesBox->SetLayout(new BGroupLayout(B_HORIZONTAL, 0));
|
||||||
r2.right = r2.left + 150;
|
// We give fSourcesBox a layout to provide insets for the sources list
|
||||||
fBox1 = new BBox(r2, NULL, B_FOLLOW_ALL);
|
// said insets are adjusted in _UpdateLabels
|
||||||
|
|
||||||
BRect r3(r2);
|
fInfoView = new MediaFileInfoView();
|
||||||
r3.OffsetTo(0, 0);
|
fInfoBox = new BBox(B_FANCY_BORDER, fInfoView);
|
||||||
r3.InsetBy(8, 8);
|
fInfoBox->SetExplicitAlignment(BAlignment(B_ALIGN_USE_FULL_WIDTH,
|
||||||
r3.top += be_bold_font->Size() - 3;
|
B_ALIGN_USE_FULL_HEIGHT));
|
||||||
bool useHorizontalScrollBar = false;
|
|
||||||
if (useHorizontalScrollBar)
|
|
||||||
r3.bottom -= B_H_SCROLL_BAR_HEIGHT;
|
|
||||||
r3.right -= B_V_SCROLL_BAR_WIDTH;
|
|
||||||
fListView = new MediaFileListView(r3, B_FOLLOW_ALL);
|
|
||||||
BScrollView *scroller = new BScrollView(NULL, fListView,
|
|
||||||
B_FOLLOW_ALL, 0, useHorizontalScrollBar, true);
|
|
||||||
fBox1->AddChild(scroller);
|
|
||||||
background->AddChild(fBox1);
|
|
||||||
|
|
||||||
// info box
|
// Output format box
|
||||||
r2.left = r2.right + 5;
|
fOutputBox = new BBox(B_FANCY_BORDER, NULL);
|
||||||
r2.right = r.right - 5;
|
float padding = be_control_look->DefaultItemSpacing();
|
||||||
r2.bottom = r2.top + 120;
|
BGridLayout* ouputGrid = new BGridLayout(padding, padding);
|
||||||
fBox2 = new BBox(r2, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP);
|
fOutputBox->SetLayout(ouputGrid);
|
||||||
|
// fOutputBox's layout is also adjusted in _UpdateLabels
|
||||||
|
|
||||||
r3 = r2;
|
|
||||||
r3.OffsetTo(0, 0);
|
|
||||||
r3.InsetBy(5, 5);
|
|
||||||
r3.top += 12;
|
|
||||||
fInfoView = new MediaFileInfoView(r3, B_FOLLOW_ALL);
|
|
||||||
fBox2->AddChild(fInfoView);
|
|
||||||
background->AddChild(fBox2);
|
|
||||||
|
|
||||||
r2.top = r2.bottom + 5;
|
|
||||||
r2.bottom = r2.top + 295;
|
|
||||||
fBox3 = new BBox(r2, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP_BOTTOM);
|
|
||||||
|
|
||||||
r3 = r2;
|
|
||||||
r3.OffsetTo(0, 0);
|
|
||||||
r3.InsetBy(8, 8);
|
|
||||||
r3.top += be_bold_font->Size() - 3;
|
|
||||||
|
|
||||||
BRect r4(r3);
|
|
||||||
r4.bottom = r4.top + 20;
|
|
||||||
BPopUpMenu* popmenu = new BPopUpMenu("");
|
BPopUpMenu* popmenu = new BPopUpMenu("");
|
||||||
fFormatMenu = new BMenuField(r4, NULL, FORMAT_LABEL, popmenu,
|
fFormatMenu = new BMenuField(NULL, FORMAT_LABEL, popmenu);
|
||||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
|
||||||
fBox3->AddChild(fFormatMenu);
|
|
||||||
|
|
||||||
r4.top = r4.bottom + 5;
|
|
||||||
r4.bottom = r4.top + 20;
|
|
||||||
popmenu = new BPopUpMenu("");
|
popmenu = new BPopUpMenu("");
|
||||||
fAudioMenu = new BMenuField(r4, NULL, AUDIO_LABEL, popmenu,
|
fAudioMenu = new BMenuField(NULL, AUDIO_LABEL, popmenu);
|
||||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
|
||||||
fBox3->AddChild(fAudioMenu);
|
|
||||||
|
|
||||||
r4.top = r4.bottom + 5;
|
|
||||||
r4.bottom = r4.top + 20;
|
|
||||||
popmenu = new BPopUpMenu("");
|
popmenu = new BPopUpMenu("");
|
||||||
fVideoMenu = new BMenuField(r4, NULL, VIDEO_LABEL, popmenu,
|
fVideoMenu = new BMenuField(NULL, VIDEO_LABEL, popmenu);
|
||||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
|
||||||
fBox3->AddChild(fVideoMenu);
|
|
||||||
|
|
||||||
// output folder
|
// output folder
|
||||||
r4.top = r4.bottom + 5;
|
fDestButton = new BButton(OUTPUT_FOLDER_LABEL,
|
||||||
r4.bottom = r4.top + 20;
|
new BMessage(OUTPUT_FOLDER_MESSAGE));
|
||||||
r4.right = 80;
|
BAlignment labelAlignment(be_control_look->DefaultLabelAlignment());
|
||||||
fDestButton = new BButton(r4, NULL, OUTPUT_FOLDER_LABEL,
|
fOutputFolder = new BStringView(NULL, defaultdirectory);
|
||||||
new BMessage(OUTPUT_FOLDER_MESSAGE),
|
fOutputFolder->SetExplicitAlignment(labelAlignment);
|
||||||
B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
|
||||||
fBox3->AddChild(fDestButton);
|
|
||||||
fDestButton->ResizeToPreferred();
|
|
||||||
BRect buttonFrame2(fDestButton->Frame());
|
|
||||||
buttonFrame2.OffsetTo(r.right - buttonFrame2.Width(),
|
|
||||||
r.bottom - buttonFrame2.Height());
|
|
||||||
|
|
||||||
fOutputFolder = new BStringView(r4, NULL, defaultdirectory,
|
|
||||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW);
|
|
||||||
fBox3->AddChild(fOutputFolder);
|
|
||||||
fOutputFolder->MoveBy(buttonFrame2.Width() + 10, 5);
|
|
||||||
fOutputFolder->ResizeToPreferred();
|
|
||||||
|
|
||||||
// start/end duration
|
// start/end duration
|
||||||
r4.top = r4.bottom + 10;
|
fStartDurationTC = new BTextControl(NULL, NULL, NULL);
|
||||||
r4.bottom = r4.top + 20;
|
|
||||||
r4.right = r3.right;
|
|
||||||
fStartDurationTC = new BTextControl(r4, NULL, "", "0", NULL,
|
|
||||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
|
||||||
fBox3->AddChild(fStartDurationTC);
|
|
||||||
fStartDurationTC->SetText("0");
|
fStartDurationTC->SetText("0");
|
||||||
|
|
||||||
r4.top = r4.bottom + 5;
|
fEndDurationTC = new BTextControl(NULL, NULL, NULL);
|
||||||
r4.bottom = r4.top + 20;
|
|
||||||
fEndDurationTC = new BTextControl(r4, NULL, "", "0", NULL,
|
|
||||||
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
|
||||||
fBox3->AddChild(fEndDurationTC);
|
|
||||||
fEndDurationTC->SetText("0");
|
fEndDurationTC->SetText("0");
|
||||||
|
|
||||||
r4.top = r4.bottom + 5;
|
|
||||||
r4.bottom = r4.top + 50;
|
|
||||||
|
|
||||||
// Video Quality
|
// Video Quality
|
||||||
fVideoQualitySlider = new BSlider(r4, "VSlider", "" ,
|
fVideoQualitySlider = new BSlider("VSlider", "" ,
|
||||||
new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL,
|
new BMessage(VIDEO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL);
|
||||||
B_BLOCK_THUMB, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
|
||||||
fVideoQualitySlider->SetValue(fVideoQuality);
|
fVideoQualitySlider->SetValue(fVideoQuality);
|
||||||
fVideoQualitySlider->SetEnabled(false);
|
fVideoQualitySlider->SetEnabled(false);
|
||||||
fBox3->AddChild(fVideoQualitySlider);
|
|
||||||
|
|
||||||
r4.top = r4.bottom + 5;
|
|
||||||
r4.bottom = r4.top + 50;
|
|
||||||
|
|
||||||
// Audio Quality
|
// Audio Quality
|
||||||
fAudioQualitySlider = new BSlider(r4,"ASlider", "" ,
|
fAudioQualitySlider = new BSlider("ASlider", "" ,
|
||||||
new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL,
|
new BMessage(AUDIO_QUALITY_CHANGED_MESSAGE), 1, 100, B_HORIZONTAL);
|
||||||
B_BLOCK_THUMB, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
|
||||||
fAudioQualitySlider->SetValue(fAudioQuality);
|
fAudioQualitySlider->SetValue(fAudioQuality);
|
||||||
fAudioQualitySlider->SetEnabled(false);
|
fAudioQualitySlider->SetEnabled(false);
|
||||||
fBox3->AddChild(fAudioQualitySlider);
|
|
||||||
background->AddChild(fBox3);
|
BLayoutBuilder::Grid<>(ouputGrid)
|
||||||
|
.SetInsets(padding, padding, padding, padding)
|
||||||
|
.AddMenuField(fFormatMenu, 0, 0)
|
||||||
|
.AddMenuField(fAudioMenu, 0, 1)
|
||||||
|
.AddMenuField(fVideoMenu, 0, 2)
|
||||||
|
.Add(fDestButton, 0, 3)
|
||||||
|
.Add(fOutputFolder, 1, 3)
|
||||||
|
.AddTextControl(fStartDurationTC, 0, 4)
|
||||||
|
.AddTextControl(fEndDurationTC, 0, 5)
|
||||||
|
.Add(fVideoQualitySlider, 0, 6, 2, 1)
|
||||||
|
.Add(fAudioQualitySlider, 0, 7, 2, 1);
|
||||||
|
|
||||||
// buttons
|
// buttons
|
||||||
r2.top = r2.bottom + 15;
|
fPreviewButton = new BButton(PREVIEW_BUTTON_LABEL,
|
||||||
r2.bottom = r2.top + 20;
|
new BMessage(PREVIEW_MESSAGE));
|
||||||
r2.left = r.left - 120;
|
|
||||||
r2.right = r.right;
|
|
||||||
|
|
||||||
fPreviewButton = new BButton(r2, NULL, PREVIEW_BUTTON_LABEL,
|
|
||||||
new BMessage(PREVIEW_MESSAGE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
|
||||||
background->AddChild(fPreviewButton);
|
|
||||||
fPreviewButton->SetEnabled(false);
|
fPreviewButton->SetEnabled(false);
|
||||||
|
|
||||||
fConvertButton = new BButton(r2, NULL, CONVERT_LABEL,
|
fConvertButton = new BButton(CONVERT_LABEL,
|
||||||
new BMessage(CONVERT_BUTTON_MESSAGE),
|
new BMessage(CONVERT_BUTTON_MESSAGE));
|
||||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
|
||||||
background->AddChild(fConvertButton);
|
|
||||||
|
|
||||||
// Status view
|
// Status views
|
||||||
r2.bottom = r2.top + 20;
|
fStatus = new BStringView(NULL, NULL);
|
||||||
r2.left = r.left;
|
fStatus->SetExplicitAlignment(labelAlignment);
|
||||||
r2.right = r.right;
|
fFileStatus= new BStringView(NULL, NULL);
|
||||||
|
fFileStatus->SetExplicitAlignment(labelAlignment);
|
||||||
fStatusView2 = new StatusView(r2, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
|
|
||||||
background->AddChild(fStatusView2);
|
|
||||||
|
|
||||||
r2.top += 15;
|
|
||||||
r2.bottom += 20;
|
|
||||||
|
|
||||||
fStatusView = new StatusView(r2, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
|
|
||||||
background->AddChild(fStatusView);
|
|
||||||
AddChild(background);
|
|
||||||
|
|
||||||
SetStatusMessage("");
|
SetStatusMessage("");
|
||||||
_UpdateLabels();
|
_UpdateLabels();
|
||||||
|
|
||||||
SetSizeLimits(frame.Width(), 32000, frame.Height(), 32000);
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||||
|
.SetInsets(0, 0, 0, 0)
|
||||||
|
.Add(fMenuBar)
|
||||||
|
.AddGrid(padding, padding)
|
||||||
|
.SetInsets(padding, padding, padding, padding)
|
||||||
|
.Add(fSourcesBox, 0, 0, 1, 2)
|
||||||
|
.Add(fInfoBox, 1, 0, 1, 1)
|
||||||
|
.Add(fOutputBox, 1, 1, 1, 1)
|
||||||
|
.AddGrid(padding, padding, 0, 2, 2, 1)
|
||||||
|
.SetInsets(0, 0, 0, 0)
|
||||||
|
.Add(fStatus, 0, 0)
|
||||||
|
.Add(fFileStatus, 0, 1)
|
||||||
|
.Add(fPreviewButton, 2, 0)
|
||||||
|
.Add(fConvertButton, 3, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -335,7 +268,7 @@ MediaConverterWindow::DispatchMessage(BMessage *msg, BHandler *handler)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaConverterWindow::MessageReceived(BMessage *msg)
|
MediaConverterWindow::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
status_t status;
|
status_t status;
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
@ -487,7 +420,8 @@ MediaConverterWindow::MessageReceived(BMessage *msg)
|
|||||||
VERSION"\n"
|
VERSION"\n"
|
||||||
B_UTF8_COPYRIGHT" 1999, Be Incorporated.\n"
|
B_UTF8_COPYRIGHT" 1999, Be Incorporated.\n"
|
||||||
B_UTF8_COPYRIGHT" 2000-2004 Jun Suzuki\n"
|
B_UTF8_COPYRIGHT" 2000-2004 Jun Suzuki\n"
|
||||||
B_UTF8_COPYRIGHT" 2007 Stephan Aßmus",
|
B_UTF8_COPYRIGHT" 2007 Stephan Aßmus\n",
|
||||||
|
B_UTF8_COPYRIGHT" 2010 Haiku, Inc.",
|
||||||
OK_LABEL))->Go();
|
OK_LABEL))->Go();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -737,16 +671,18 @@ MediaConverterWindow::BuildFormatMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaConverterWindow::SetFileMessage(const char *message)
|
MediaConverterWindow::SetFileMessage(const char *message)
|
||||||
{
|
{
|
||||||
fStatusView->SetStatus(message);
|
fFileStatus->SetText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaConverterWindow::SetStatusMessage(const char *message)
|
MediaConverterWindow::SetStatusMessage(const char *message)
|
||||||
{
|
{
|
||||||
fStatusView2->SetStatus(message);
|
fStatus->SetText(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -902,110 +838,76 @@ MediaConverterWindow::SetVideoQualityLabel(const char* label)
|
|||||||
void
|
void
|
||||||
MediaConverterWindow::_UpdateLabels()
|
MediaConverterWindow::_UpdateLabels()
|
||||||
{
|
{
|
||||||
char buffer[255];
|
if (fSourcesBox != NULL) {
|
||||||
|
fSourcesBox->SetLabel(SOURCE_BOX_LABEL);
|
||||||
|
_UpdateBBoxLayoutInsets(fSourcesBox);
|
||||||
|
}
|
||||||
|
|
||||||
if (fBox1 != NULL)
|
if (fInfoBox != NULL)
|
||||||
fBox1->SetLabel(SOURCE_BOX_LABEL);
|
fInfoBox->SetLabel(INFO_BOX_LABEL);
|
||||||
if (fBox2 != NULL)
|
|
||||||
fBox2->SetLabel(INFO_BOX_LABEL);
|
|
||||||
if (fBox3 != NULL)
|
|
||||||
fBox3->SetLabel(OUTPUT_BOX_LABEL);
|
|
||||||
|
|
||||||
BRect r(Bounds());
|
if (fOutputBox != NULL) {
|
||||||
float w = 0;
|
fOutputBox->SetLabel(OUTPUT_BOX_LABEL);
|
||||||
|
_UpdateBBoxLayoutInsets(fOutputBox);
|
||||||
|
}
|
||||||
|
|
||||||
if (fConvertButton != NULL) {
|
if (fConvertButton != NULL)
|
||||||
fConvertButton->SetLabel(CONVERT_LABEL);
|
fConvertButton->SetLabel(CONVERT_LABEL);
|
||||||
fConvertButton->ResizeToPreferred();
|
|
||||||
BRect buttonFrame(fConvertButton->Frame());
|
|
||||||
w = buttonFrame.Width();
|
|
||||||
buttonFrame.OffsetTo(r.right - w - 10, r.bottom - buttonFrame.Height() - 25);
|
|
||||||
fConvertButton->MoveTo(buttonFrame.LeftTop());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fPreviewButton != NULL) {
|
if (fPreviewButton != NULL)
|
||||||
fPreviewButton->SetLabel(PREVIEW_BUTTON_LABEL);
|
fPreviewButton->SetLabel(PREVIEW_BUTTON_LABEL);
|
||||||
fPreviewButton->ResizeToPreferred();
|
|
||||||
BRect buttonFrame(fPreviewButton->Frame());
|
|
||||||
w = buttonFrame.Width();
|
|
||||||
buttonFrame.OffsetTo(r.right - w - buttonFrame.Width() - 40,
|
|
||||||
r.bottom - buttonFrame.Height() - 25);
|
|
||||||
fPreviewButton->MoveTo(buttonFrame.LeftTop());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fDestButton != NULL) {
|
if (fDestButton != NULL)
|
||||||
fDestButton->SetLabel(OUTPUT_FOLDER_LABEL);
|
fDestButton->SetLabel(OUTPUT_FOLDER_LABEL);
|
||||||
fDestButton->ResizeToPreferred();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fOutputFolder != NULL) {
|
|
||||||
BRect destrect;
|
|
||||||
destrect = fDestButton->Frame();
|
|
||||||
fOutputFolder->MoveTo(destrect.right + 10, destrect.top + 5);
|
|
||||||
fOutputFolder->ResizeToPreferred();
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(buffer, VIDEO_QUALITY_LABEL, (int8)fVideoQuality);
|
|
||||||
if (fVideoQualitySlider != NULL) {
|
if (fVideoQualitySlider != NULL) {
|
||||||
|
char buffer[40];
|
||||||
|
sprintf(buffer, VIDEO_QUALITY_LABEL, (int8)fVideoQuality);
|
||||||
fVideoQualitySlider->SetLabel(buffer);
|
fVideoQualitySlider->SetLabel(buffer);
|
||||||
fVideoQualitySlider->SetLimitLabels(SLIDER_LOW_LABEL,
|
fVideoQualitySlider->SetLimitLabels(SLIDER_LOW_LABEL,
|
||||||
SLIDER_HIGH_LABEL);
|
SLIDER_HIGH_LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buffer, AUDIO_QUALITY_LABEL, (int8)fAudioQuality);
|
|
||||||
|
|
||||||
if (fAudioQualitySlider != NULL) {
|
if (fAudioQualitySlider != NULL) {
|
||||||
|
char buffer[40];
|
||||||
|
sprintf(buffer, AUDIO_QUALITY_LABEL, (int8)fAudioQuality);
|
||||||
fAudioQualitySlider->SetLabel(buffer);
|
fAudioQualitySlider->SetLabel(buffer);
|
||||||
fAudioQualitySlider->SetLimitLabels(SLIDER_LOW_LABEL,
|
fAudioQualitySlider->SetLimitLabels(SLIDER_LOW_LABEL,
|
||||||
SLIDER_HIGH_LABEL);
|
SLIDER_HIGH_LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
float maxLabelLen = 0;
|
if (fStartDurationTC != NULL)
|
||||||
if (fStartDurationTC != NULL) {
|
|
||||||
fStartDurationTC->SetLabel(START_LABEL);
|
fStartDurationTC->SetLabel(START_LABEL);
|
||||||
maxLabelLen = fStartDurationTC->StringWidth(START_LABEL);
|
|
||||||
}
|
if (fEndDurationTC != NULL)
|
||||||
if (fEndDurationTC != NULL) {
|
|
||||||
fEndDurationTC->SetLabel(END_LABEL);
|
fEndDurationTC->SetLabel(END_LABEL);
|
||||||
maxLabelLen = MAX(maxLabelLen, fEndDurationTC->StringWidth(END_LABEL));
|
|
||||||
}
|
|
||||||
if (fStartDurationTC != NULL)
|
|
||||||
fStartDurationTC->SetDivider(maxLabelLen + 5);
|
|
||||||
if (fEndDurationTC != NULL)
|
|
||||||
fEndDurationTC->SetDivider(maxLabelLen + 5);
|
|
||||||
|
|
||||||
if (fFormatMenu != NULL) {
|
|
||||||
fFormatMenu->SetLabel(FORMAT_LABEL);
|
|
||||||
maxLabelLen = MAX(maxLabelLen, fFormatMenu->StringWidth(
|
|
||||||
fFormatMenu->Label()));
|
|
||||||
}
|
|
||||||
if (fAudioMenu != NULL) {
|
|
||||||
fAudioMenu->SetLabel(AUDIO_LABEL);
|
|
||||||
maxLabelLen = MAX(maxLabelLen, fAudioMenu->StringWidth(
|
|
||||||
fAudioMenu->Label()));
|
|
||||||
}
|
|
||||||
if (fVideoMenu != NULL) {
|
|
||||||
fVideoMenu->SetLabel(VIDEO_LABEL);
|
|
||||||
maxLabelLen = MAX(maxLabelLen, fVideoMenu->StringWidth(
|
|
||||||
fVideoMenu->Label()));
|
|
||||||
}
|
|
||||||
maxLabelLen += 10;
|
|
||||||
|
|
||||||
if (fStartDurationTC != NULL)
|
|
||||||
fStartDurationTC->SetDivider(maxLabelLen);
|
|
||||||
if (fEndDurationTC != NULL)
|
|
||||||
fEndDurationTC->SetDivider(maxLabelLen);
|
|
||||||
if (fFormatMenu != NULL)
|
if (fFormatMenu != NULL)
|
||||||
fFormatMenu->SetDivider(maxLabelLen + 3);
|
fFormatMenu->SetLabel(FORMAT_LABEL);
|
||||||
|
|
||||||
if (fAudioMenu != NULL)
|
if (fAudioMenu != NULL)
|
||||||
fAudioMenu->SetDivider(maxLabelLen + 3);
|
fAudioMenu->SetLabel(AUDIO_LABEL);
|
||||||
|
|
||||||
if (fVideoMenu != NULL)
|
if (fVideoMenu != NULL)
|
||||||
fVideoMenu->SetDivider(maxLabelLen + 3);
|
fVideoMenu->SetLabel(VIDEO_LABEL);
|
||||||
|
|
||||||
SetFileMessage(DROP_MEDIA_FILE_LABEL);
|
SetFileMessage(DROP_MEDIA_FILE_LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MediaConverterWindow::_UpdateBBoxLayoutInsets(BBox* box)
|
||||||
|
{
|
||||||
|
BTwoDimensionalLayout* layout
|
||||||
|
= dynamic_cast<BTwoDimensionalLayout*>(box->GetLayout());
|
||||||
|
if (layout) {
|
||||||
|
float padding = be_control_look->DefaultItemSpacing();
|
||||||
|
layout->SetInsets(padding, box->TopBorderOffset() + padding, padding,
|
||||||
|
padding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaConverterWindow::_DestroyMenu()
|
MediaConverterWindow::_DestroyMenu()
|
||||||
{
|
{
|
||||||
@ -1026,14 +928,15 @@ MediaConverterWindow::_CreateMenu()
|
|||||||
|
|
||||||
menu = new BMenu(FILE_MENU_LABEL);
|
menu = new BMenu(FILE_MENU_LABEL);
|
||||||
item = new BMenuItem(OPEN_MENU_LABEL B_UTF8_ELLIPSIS,
|
item = new BMenuItem(OPEN_MENU_LABEL B_UTF8_ELLIPSIS,
|
||||||
new BMessage(OPEN_FILE_MESSAGE));
|
new BMessage(OPEN_FILE_MESSAGE), 'O');
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
|
|
||||||
item = new BMenuItem(ABOUT_MENU_LABEL B_UTF8_ELLIPSIS,
|
item = new BMenuItem(ABOUT_MENU_LABEL B_UTF8_ELLIPSIS,
|
||||||
new BMessage(DISP_ABOUT_MESSAGE));
|
new BMessage(DISP_ABOUT_MESSAGE));
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
menu->AddSeparatorItem();
|
menu->AddSeparatorItem();
|
||||||
item = new BMenuItem(QUIT_MENU_LABEL, new BMessage(QUIT_MESSAGE));
|
item = new BMenuItem(QUIT_MENU_LABEL, new BMessage(QUIT_MESSAGE), 'Q');
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
fMenuBar->AddItem(menu);
|
fMenuBar->AddItem(menu);
|
||||||
|
@ -75,25 +75,25 @@ class MediaConverterWindow : public BWindow {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void _UpdateLabels();
|
void _UpdateLabels();
|
||||||
|
void _UpdateBBoxLayoutInsets(BBox* box);
|
||||||
void _CreateMenu();
|
void _CreateMenu();
|
||||||
void _DestroyMenu();
|
void _DestroyMenu();
|
||||||
void _SetOutputFolder(BEntry entry);
|
void _SetOutputFolder(BEntry entry);
|
||||||
|
|
||||||
media_format fDummyFormat;
|
|
||||||
BButton* fConvertButton;
|
BButton* fConvertButton;
|
||||||
|
|
||||||
BButton* fDestButton;
|
BButton* fDestButton;
|
||||||
BButton* fPreviewButton;
|
BButton* fPreviewButton;
|
||||||
BBox* fBox1;
|
BBox* fSourcesBox;
|
||||||
BBox* fBox2;
|
BBox* fInfoBox;
|
||||||
BBox* fBox3;
|
BBox* fOutputBox;
|
||||||
|
|
||||||
BMenuBar* fMenuBar;
|
BMenuBar* fMenuBar;
|
||||||
BMenuField* fFormatMenu;
|
BMenuField* fFormatMenu;
|
||||||
BMenuField* fVideoMenu;
|
BMenuField* fVideoMenu;
|
||||||
BMenuField* fAudioMenu;
|
BMenuField* fAudioMenu;
|
||||||
StatusView* fStatusView;
|
BStringView* fFileStatus;
|
||||||
StatusView* fStatusView2;
|
BStringView* fStatus;
|
||||||
MediaFileListView* fListView;
|
MediaFileListView* fListView;
|
||||||
MediaFileInfoView* fInfoView;
|
MediaFileInfoView* fInfoView;
|
||||||
BStringView* fOutputFolder;
|
BStringView* fOutputFolder;
|
||||||
|
108
src/apps/mediaconverter/MediaFileInfo.cpp
Normal file
108
src/apps/mediaconverter/MediaFileInfo.cpp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
// Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||||
|
// Copyright 2000-2004, Jun Suzuki. All Rights Reserved.
|
||||||
|
// Copyright 2007, Stephan Aßmus. All Rights Reserved.
|
||||||
|
// Copyright 2010, Haiku, Inc. All Rights Reserved.
|
||||||
|
// This file may be used under the terms of the Be Sample Code License.
|
||||||
|
|
||||||
|
|
||||||
|
#include "MediaFileInfo.h"
|
||||||
|
|
||||||
|
#include <MediaTrack.h>
|
||||||
|
|
||||||
|
|
||||||
|
MediaFileInfo::MediaFileInfo(BMediaFile* file)
|
||||||
|
{
|
||||||
|
LoadInfo(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MediaFileInfo::LoadInfo(BMediaFile* file)
|
||||||
|
{
|
||||||
|
_Reset();
|
||||||
|
if (!file)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BMediaTrack* track;
|
||||||
|
media_format format;
|
||||||
|
memset(&format, 0, sizeof(format));
|
||||||
|
media_codec_info codecInfo;
|
||||||
|
bool audioDone(false), videoDone(false);
|
||||||
|
bigtime_t audioDuration = 0;
|
||||||
|
bigtime_t videoDuration = 0;
|
||||||
|
int32 tracks = file->CountTracks();
|
||||||
|
int64 videoFrames = 0;
|
||||||
|
int64 audioFrames = 0;
|
||||||
|
for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
|
||||||
|
track = file->TrackAt(i);
|
||||||
|
if (track != NULL) {
|
||||||
|
track->EncodedFormat(&format);
|
||||||
|
if (format.IsVideo()) {
|
||||||
|
memset(&format, 0, sizeof(format));
|
||||||
|
format.type = B_MEDIA_RAW_VIDEO;
|
||||||
|
track->DecodedFormat(&format);
|
||||||
|
media_raw_video_format *rvf = &(format.u.raw_video);
|
||||||
|
|
||||||
|
track->GetCodecInfo(&codecInfo);
|
||||||
|
video.format << codecInfo.pretty_name;
|
||||||
|
videoDuration = track->Duration();
|
||||||
|
videoFrames = track->CountFrames();
|
||||||
|
|
||||||
|
video.details << (int32)format.Width() << "x"
|
||||||
|
<< (int32)format.Height() << " "
|
||||||
|
<< (int32)(rvf->field_rate / rvf->interlace)
|
||||||
|
<< " fps / " << videoFrames << " frames";
|
||||||
|
|
||||||
|
videoDone = true;
|
||||||
|
|
||||||
|
} else if (format.IsAudio()) {
|
||||||
|
memset(&format, 0, sizeof(format));
|
||||||
|
format.type = B_MEDIA_RAW_AUDIO;
|
||||||
|
track->DecodedFormat(&format);
|
||||||
|
media_raw_audio_format *raf = &(format.u.raw_audio);
|
||||||
|
char bytesPerSample = (char)(raf->format & 0xf);
|
||||||
|
if (bytesPerSample == 1) {
|
||||||
|
audio.details << "8 bit ";
|
||||||
|
} else if (bytesPerSample == 2) {
|
||||||
|
audio.details << "16 bit ";
|
||||||
|
} else {
|
||||||
|
audio.details << bytesPerSample << "byte ";
|
||||||
|
}
|
||||||
|
|
||||||
|
track->GetCodecInfo(&codecInfo);
|
||||||
|
audio.format << codecInfo.pretty_name;
|
||||||
|
audioDuration = track->Duration();
|
||||||
|
audioFrames = track->CountFrames();
|
||||||
|
|
||||||
|
audio.details << (float)(raf->frame_rate / 1000.0f) << " kHz";
|
||||||
|
if (raf->channel_count == 1) {
|
||||||
|
audio.details << " mono / ";
|
||||||
|
} else if (raf->channel_count == 2) {
|
||||||
|
audio.details << " stereo / ";
|
||||||
|
} else {
|
||||||
|
audio.details << (int32)raf->channel_count
|
||||||
|
<< " channel / " ;
|
||||||
|
}
|
||||||
|
audio.details << audioFrames << " frames";
|
||||||
|
audioDone = true;
|
||||||
|
}
|
||||||
|
file->ReleaseTrack(track);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useconds = MAX(audioDuration, videoDuration);
|
||||||
|
duration << (int32)(useconds / 1000000)
|
||||||
|
<< " seconds";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MediaFileInfo::_Reset()
|
||||||
|
{
|
||||||
|
audio.details.SetTo("");
|
||||||
|
audio.format.SetTo("");
|
||||||
|
video.details.SetTo("");
|
||||||
|
video.format.SetTo("");
|
||||||
|
useconds = 0;
|
||||||
|
duration.SetTo("");
|
||||||
|
}
|
32
src/apps/mediaconverter/MediaFileInfo.h
Normal file
32
src/apps/mediaconverter/MediaFileInfo.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2010, Haiku, Inc. All Rights Reserved.
|
||||||
|
This file may be used under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef MEDIA_FILE_INFO_H
|
||||||
|
#define MEDIA_FILE_INFO_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <MediaFile.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct MediaInfo {
|
||||||
|
BString format;
|
||||||
|
BString details;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct MediaFileInfo {
|
||||||
|
MediaFileInfo(BMediaFile* file = NULL);
|
||||||
|
void LoadInfo(BMediaFile* file);
|
||||||
|
|
||||||
|
MediaInfo audio;
|
||||||
|
MediaInfo video;
|
||||||
|
BString duration;
|
||||||
|
bigtime_t useconds;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _Reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MEDIA_FILE_INFO_H
|
@ -4,8 +4,7 @@
|
|||||||
// This file may be used under the terms of the Be Sample Code License.
|
// This file may be used under the terms of the Be Sample Code License.
|
||||||
#include "MediaFileInfoView.h"
|
#include "MediaFileInfoView.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <ControlLook.h>
|
||||||
|
|
||||||
#include <MediaFile.h>
|
#include <MediaFile.h>
|
||||||
#include <MediaTrack.h>
|
#include <MediaTrack.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
@ -13,13 +12,17 @@
|
|||||||
#include "Strings.h"
|
#include "Strings.h"
|
||||||
|
|
||||||
|
|
||||||
MediaFileInfoView::MediaFileInfoView(BRect frame, uint32 resizingMode)
|
const float kSpacing = 5.0f;
|
||||||
: BView(frame, "MediaFileInfoView", resizingMode,
|
|
||||||
B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW)
|
|
||||||
, fRef()
|
MediaFileInfoView::MediaFileInfoView()
|
||||||
, fMediaFile(NULL)
|
:
|
||||||
, fDuration(0)
|
BView("MediaFileInfoView", B_WILL_DRAW | B_SUPPORTS_LAYOUT),
|
||||||
|
fMinMaxValid(false),
|
||||||
|
fRef(),
|
||||||
|
fMediaFile(NULL)
|
||||||
{
|
{
|
||||||
|
SetFont(be_plain_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -31,57 +34,102 @@ MediaFileInfoView::~MediaFileInfoView()
|
|||||||
void
|
void
|
||||||
MediaFileInfoView::Draw(BRect /*update*/)
|
MediaFileInfoView::Draw(BRect /*update*/)
|
||||||
{
|
{
|
||||||
|
_ValidateMinMax();
|
||||||
|
|
||||||
|
_SetFontFace(B_BOLD_FACE);
|
||||||
|
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
BPoint p(2, fh.ascent + fh.leading);
|
BPoint labelStart(kSpacing, fh.ascent + fh.leading + 1);
|
||||||
BFont font;
|
|
||||||
GetFont(&font);
|
|
||||||
font.SetFace(B_BOLD_FACE);
|
|
||||||
font.SetSize(12);
|
|
||||||
SetFont(&font);
|
|
||||||
|
|
||||||
if (fMediaFile == NULL) {
|
if (fMediaFile == NULL) {
|
||||||
DrawString(NO_FILE_LABEL, p);
|
DrawString(NO_FILE_LABEL, labelStart);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BString aFmt, vFmt, aDetails, vDetails, duration;
|
|
||||||
_GetFileInfo(&aFmt, &vFmt, &aDetails, &vDetails, &duration);
|
|
||||||
|
|
||||||
// draw filename
|
// draw filename
|
||||||
DrawString(fRef.name, p);
|
DrawString(fRef.name, labelStart);
|
||||||
float lineHeight = fh.ascent + fh.descent + fh.leading;
|
labelStart.y += fLineHeight + kSpacing;
|
||||||
p.y += (float)ceil(lineHeight * 1.5);
|
BPoint infoStart(labelStart.x + fMaxLabelWidth + kSpacing, labelStart.y);
|
||||||
|
|
||||||
float durLen = StringWidth(DURATION_LABEL) + 5;
|
|
||||||
float audLen = StringWidth(AUDIO_INFO_LABEL) + 5;
|
|
||||||
float vidLen = StringWidth(VIDEO_INFO_LABEL) + 5;
|
|
||||||
float maxLen = MAX(durLen, audLen);
|
|
||||||
maxLen = MAX(maxLen, vidLen);
|
|
||||||
|
|
||||||
// draw labels
|
// draw labels
|
||||||
DrawString(AUDIO_INFO_LABEL, p + BPoint(maxLen - audLen, 0));
|
DrawString(AUDIO_INFO_LABEL, labelStart);
|
||||||
BPoint p2 = p;
|
labelStart.y += fLineHeight * 2;
|
||||||
p2.x += maxLen + 4;
|
|
||||||
p.y += lineHeight * 2;
|
DrawString(VIDEO_INFO_LABEL, labelStart);
|
||||||
DrawString(VIDEO_INFO_LABEL, p + BPoint(maxLen - vidLen, 0));
|
labelStart.y += fLineHeight * 2;
|
||||||
p.y += lineHeight * 2;
|
|
||||||
DrawString(DURATION_LABEL, p + BPoint(maxLen - durLen, 0));
|
DrawString(DURATION_LABEL, labelStart);
|
||||||
|
labelStart.y += fLineHeight * 2;
|
||||||
|
|
||||||
// draw audio/video/duration info
|
// draw audio/video/duration info
|
||||||
font.SetFace(B_REGULAR_FACE);
|
_SetFontFace(B_REGULAR_FACE);
|
||||||
font.SetSize(10);
|
|
||||||
SetFont(&font);
|
|
||||||
|
|
||||||
DrawString(aFmt.String(), p2);
|
BString* infoStrings[5] = {&fInfo.audio.format, &fInfo.audio.details,
|
||||||
p2.y += lineHeight;
|
&fInfo.video.format, &fInfo.video.details, &fInfo.duration};
|
||||||
DrawString(aDetails.String(), p2);
|
for (int32 i = 0; i < 5; i++) {
|
||||||
p2.y += lineHeight;
|
DrawString(*infoStrings[i], infoStart);
|
||||||
DrawString(vFmt.String(), p2);
|
infoStart.y += fLineHeight;
|
||||||
p2.y += lineHeight;
|
}
|
||||||
DrawString(vDetails.String(), p2);
|
}
|
||||||
p2.y += lineHeight;
|
|
||||||
DrawString(duration.String(), p2);
|
|
||||||
|
BSize
|
||||||
|
MediaFileInfoView::MinSize()
|
||||||
|
{
|
||||||
|
_ValidateMinMax();
|
||||||
|
return fMinSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
MediaFileInfoView::MaxSize()
|
||||||
|
{
|
||||||
|
return fMinSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
MediaFileInfoView::PreferredSize()
|
||||||
|
{
|
||||||
|
_ValidateMinMax();
|
||||||
|
return fMinSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BAlignment
|
||||||
|
MediaFileInfoView::LayoutAlignment()
|
||||||
|
{
|
||||||
|
return BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MediaFileInfoView::InvalidateLayout(bool /*children*/)
|
||||||
|
{
|
||||||
|
fMinMaxValid = false;
|
||||||
|
BView::InvalidateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MediaFileInfoView::SetFont(const BFont* font, uint32 mask)
|
||||||
|
{
|
||||||
|
BView::SetFont(font, mask);
|
||||||
|
if (mask == B_FONT_FACE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fLineHeight = _LineHeight();
|
||||||
|
BFont bold(font);
|
||||||
|
bold.SetFace(B_BOLD_FACE);
|
||||||
|
fMaxLabelWidth = 0;
|
||||||
|
|
||||||
|
BString labels[] = {VIDEO_INFO_LABEL, DURATION_LABEL, AUDIO_INFO_LABEL};
|
||||||
|
int32 labelCount = sizeof(labels) / sizeof(BString);
|
||||||
|
fMaxLabelWidth = _MaxLineWidth(labels, labelCount, bold);
|
||||||
|
|
||||||
|
fNoFileLabelWidth = ceilf(bold.StringWidth(NO_FILE_LABEL));
|
||||||
|
InvalidateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -107,89 +155,77 @@ MediaFileInfoView::Update(BMediaFile* file, entry_ref* ref)
|
|||||||
else
|
else
|
||||||
fRef = entry_ref();
|
fRef = entry_ref();
|
||||||
|
|
||||||
|
fInfo.LoadInfo(file);
|
||||||
|
|
||||||
|
InvalidateLayout();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
float
|
||||||
|
MediaFileInfoView::_LineHeight()
|
||||||
|
|
||||||
void
|
|
||||||
MediaFileInfoView::_GetFileInfo(BString* audioFormat, BString* videoFormat,
|
|
||||||
BString* audioDetails, BString* videoDetails, BString* duration)
|
|
||||||
{
|
{
|
||||||
fDuration = 0;
|
font_height fontHeight;
|
||||||
if (fMediaFile == NULL)
|
GetFontHeight(&fontHeight);
|
||||||
return;
|
return ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading);
|
||||||
|
|
||||||
BMediaTrack* track;
|
|
||||||
media_format format;
|
|
||||||
memset(&format, 0, sizeof(format));
|
|
||||||
media_codec_info codecInfo;
|
|
||||||
bool audioDone(false), videoDone(false);
|
|
||||||
bigtime_t audioDuration = 0;
|
|
||||||
bigtime_t videoDuration = 0;
|
|
||||||
int32 tracks = fMediaFile->CountTracks();
|
|
||||||
int64 videoFrames = 0;
|
|
||||||
int64 audioFrames = 0;
|
|
||||||
for (int32 i = 0; i < tracks && (!audioDone || !videoDone); i++) {
|
|
||||||
track = fMediaFile->TrackAt(i);
|
|
||||||
if (track != NULL) {
|
|
||||||
track->EncodedFormat(&format);
|
|
||||||
if (format.IsVideo()) {
|
|
||||||
memset(&format, 0, sizeof(format));
|
|
||||||
format.type = B_MEDIA_RAW_VIDEO;
|
|
||||||
track->DecodedFormat(&format);
|
|
||||||
media_raw_video_format *rvf = &(format.u.raw_video);
|
|
||||||
|
|
||||||
track->GetCodecInfo(&codecInfo);
|
|
||||||
*videoFormat << codecInfo.pretty_name;
|
|
||||||
videoDuration = track->Duration();
|
|
||||||
videoFrames = track->CountFrames();
|
|
||||||
|
|
||||||
*videoDetails << (int32)format.Width() << "x" << (int32)format.Height()
|
|
||||||
<< " " << (int32)(rvf->field_rate / rvf->interlace)
|
|
||||||
<< " fps / " << videoFrames << " frames";
|
|
||||||
|
|
||||||
videoDone = true;
|
|
||||||
|
|
||||||
} else if (format.IsAudio()) {
|
|
||||||
memset(&format, 0, sizeof(format));
|
|
||||||
format.type = B_MEDIA_RAW_AUDIO;
|
|
||||||
track->DecodedFormat(&format);
|
|
||||||
media_raw_audio_format *raf = &(format.u.raw_audio);
|
|
||||||
char bytesPerSample = (char)(raf->format & 0xf);
|
|
||||||
if (bytesPerSample == 1) {
|
|
||||||
*audioDetails << "8 bit ";
|
|
||||||
} else if (bytesPerSample == 2) {
|
|
||||||
*audioDetails << "16 bit ";
|
|
||||||
} else {
|
|
||||||
*audioDetails << bytesPerSample << "byte ";
|
|
||||||
}
|
|
||||||
|
|
||||||
track->GetCodecInfo(&codecInfo);
|
|
||||||
*audioFormat << codecInfo.pretty_name;
|
|
||||||
audioDuration = track->Duration();
|
|
||||||
audioFrames = track->CountFrames();
|
|
||||||
|
|
||||||
*audioDetails << (float)(raf->frame_rate / 1000.0f) << " kHz";
|
|
||||||
if (raf->channel_count == 1) {
|
|
||||||
*audioDetails << " mono / ";
|
|
||||||
} else if (raf->channel_count == 2) {
|
|
||||||
*audioDetails << " stereo / ";
|
|
||||||
} else {
|
|
||||||
*audioDetails << (int32)raf->channel_count << " channel / " ;
|
|
||||||
}
|
|
||||||
*audioDetails << audioFrames << " frames";
|
|
||||||
audioDone = true;
|
|
||||||
}
|
|
||||||
fMediaFile->ReleaseTrack(track);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fDuration = MAX(audioDuration, videoDuration);
|
|
||||||
*duration << (int32)(fDuration / 1000000)
|
|
||||||
<< " seconds";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float
|
||||||
|
MediaFileInfoView::_MaxLineWidth(BString* strings, int32 count,
|
||||||
|
const BFont& font)
|
||||||
|
{
|
||||||
|
float width = 0;
|
||||||
|
for (int32 i = 0; i < count; i++)
|
||||||
|
width = max_c(font.StringWidth(strings[i]), width);
|
||||||
|
|
||||||
|
return ceilf(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MediaFileInfoView::_ValidateMinMax()
|
||||||
|
{
|
||||||
|
if (fMinMaxValid)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BFont font;
|
||||||
|
GetFont(&font);
|
||||||
|
|
||||||
|
BFont bold(font);
|
||||||
|
bold.SetFace(B_BOLD_FACE);
|
||||||
|
fMinSize.Set(0, 0);
|
||||||
|
|
||||||
|
if (fMediaFile == NULL) {
|
||||||
|
fMinSize.width = fNoFileLabelWidth + kSpacing * 2;
|
||||||
|
fMinSize.height = fLineHeight + kSpacing;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fMinSize.height += fLineHeight + kSpacing + 1;
|
||||||
|
fMinSize.width = ceilf(bold.StringWidth(fRef.name));
|
||||||
|
|
||||||
|
BString strings[5] = {fInfo.audio.format, fInfo.audio.details,
|
||||||
|
fInfo.video.format, fInfo.video.details, fInfo.duration};
|
||||||
|
float maxInfoWidth = _MaxLineWidth(strings, 5, font);
|
||||||
|
|
||||||
|
fMinSize.width = max_c(fMinSize.width, fMaxLabelWidth
|
||||||
|
+ maxInfoWidth + kSpacing);
|
||||||
|
fMinSize.width += kSpacing;
|
||||||
|
|
||||||
|
fMinSize.height += fLineHeight * 5 + 2 * kSpacing;
|
||||||
|
// 5 lines of info, w/ spacing above and below (not between lines)
|
||||||
|
|
||||||
|
ResetLayoutInvalidation();
|
||||||
|
fMinMaxValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MediaFileInfoView::_SetFontFace(uint16 face)
|
||||||
|
{
|
||||||
|
BFont font;
|
||||||
|
font.SetFace(face);
|
||||||
|
SetFont(&font, B_FONT_FACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -9,16 +9,26 @@
|
|||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
#include "MediaFileInfo.h"
|
||||||
|
|
||||||
|
|
||||||
class BMediaFile;
|
class BMediaFile;
|
||||||
class BString;
|
class BString;
|
||||||
|
|
||||||
class MediaFileInfoView : public BView {
|
class MediaFileInfoView : public BView {
|
||||||
public:
|
public:
|
||||||
MediaFileInfoView(BRect frame,
|
MediaFileInfoView();
|
||||||
uint32 resizingMode);
|
|
||||||
virtual ~MediaFileInfoView();
|
virtual ~MediaFileInfoView();
|
||||||
|
|
||||||
|
virtual BSize MinSize();
|
||||||
|
virtual BSize MaxSize();
|
||||||
|
virtual BSize PreferredSize();
|
||||||
|
virtual BAlignment LayoutAlignment();
|
||||||
|
virtual void InvalidateLayout(bool children = false);
|
||||||
|
|
||||||
|
virtual void SetFont(const BFont* font,
|
||||||
|
uint32 mask = B_FONT_ALL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
@ -26,18 +36,23 @@ class MediaFileInfoView : public BView {
|
|||||||
public:
|
public:
|
||||||
void Update(BMediaFile* file, entry_ref* ref);
|
void Update(BMediaFile* file, entry_ref* ref);
|
||||||
bigtime_t Duration() const
|
bigtime_t Duration() const
|
||||||
{ return fDuration; }
|
{ return fInfo.useconds; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _GetFileInfo(BString* audioFormat,
|
void _ValidateMinMax();
|
||||||
BString* videoFormat,
|
float _MaxLineWidth(BString* strings,
|
||||||
BString* audioDetails,
|
int32 stringCount, const BFont& font);
|
||||||
BString* videoDetails,
|
float _LineHeight();
|
||||||
BString* duration);
|
void _SetFontFace(uint16 face);
|
||||||
|
|
||||||
|
bool fMinMaxValid;
|
||||||
|
BSize fMinSize;
|
||||||
|
float fMaxLabelWidth;
|
||||||
|
float fNoFileLabelWidth;
|
||||||
|
float fLineHeight;
|
||||||
entry_ref fRef;
|
entry_ref fRef;
|
||||||
BMediaFile* fMediaFile;
|
BMediaFile* fMediaFile;
|
||||||
bigtime_t fDuration;
|
MediaFileInfo fInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MEDIA_FILE_INFO_VIEW_H
|
#endif // MEDIA_FILE_INFO_VIEW_H
|
||||||
|
@ -37,9 +37,10 @@ MediaFileListItem::~MediaFileListItem()
|
|||||||
// #pragma mark - MediaFileListView
|
// #pragma mark - MediaFileListView
|
||||||
|
|
||||||
|
|
||||||
MediaFileListView::MediaFileListView(BRect frame, uint32 resizingMode)
|
MediaFileListView::MediaFileListView()
|
||||||
: BListView(frame, "MediaFileListView", B_SINGLE_SELECTION_LIST, resizingMode,
|
:
|
||||||
B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS)
|
BListView("MediaFileListView", B_SINGLE_SELECTION_LIST, B_WILL_DRAW
|
||||||
|
| B_NAVIGABLE | B_FRAME_EVENTS)
|
||||||
{
|
{
|
||||||
fEnabled = true;
|
fEnabled = true;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,7 @@ public:
|
|||||||
|
|
||||||
class MediaFileListView : public BListView {
|
class MediaFileListView : public BListView {
|
||||||
public:
|
public:
|
||||||
MediaFileListView(BRect frame,
|
MediaFileListView();
|
||||||
uint32 resizingMode);
|
|
||||||
virtual ~MediaFileListView();
|
virtual ~MediaFileListView();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
// Copyright 1999, Be Incorporated. All Rights Reserved.
|
|
||||||
// Copyright 2000-2004, Jun Suzuki. All Rights Reserved.
|
|
||||||
// Copyright 2007, Stephan Aßmus. All Rights Reserved.
|
|
||||||
// This file may be used under the terms of the Be Sample Code License.
|
|
||||||
#include "StatusView.h"
|
|
||||||
|
|
||||||
|
|
||||||
StatusView::StatusView(BRect frame, uint32 resizingMode)
|
|
||||||
: BView(frame, "StatusView", resizingMode,
|
|
||||||
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
|
|
||||||
, fStatusString(B_EMPTY_STRING)
|
|
||||||
{
|
|
||||||
frame.OffsetTo(0, 0);
|
|
||||||
fStatusRect = frame;
|
|
||||||
|
|
||||||
// TODO: bad!
|
|
||||||
BFont font;
|
|
||||||
GetFont(&font);
|
|
||||||
font.SetSize(12);
|
|
||||||
SetFont(&font);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
StatusView::~StatusView()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
StatusView::AttachedToWindow()
|
|
||||||
{
|
|
||||||
rgb_color c = Parent()->LowColor();
|
|
||||||
SetViewColor(c);
|
|
||||||
SetLowColor(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
StatusView::Draw(BRect /*update*/)
|
|
||||||
{
|
|
||||||
// TODO: placement information should be cached here
|
|
||||||
// for better performance
|
|
||||||
font_height fh;
|
|
||||||
GetFontHeight(&fh);
|
|
||||||
DrawString(fStatusString.String(),
|
|
||||||
fStatusRect.LeftBottom() + BPoint(1, -fh.descent));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
StatusView::MessageReceived(BMessage* message)
|
|
||||||
{
|
|
||||||
BView::MessageReceived(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
StatusView::SetStatus(const char* text)
|
|
||||||
{
|
|
||||||
fStatusString.SetTo(text);
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const char*
|
|
||||||
StatusView::Status()
|
|
||||||
{
|
|
||||||
return fStatusString.String();
|
|
||||||
}
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
|||||||
// Copyright 1999, Be Incorporated. All Rights Reserved.
|
|
||||||
// Copyright 2000-2004, Jun Suzuki. All Rights Reserved.
|
|
||||||
// Copyright 2007, Stephan Aßmus. All Rights Reserved.
|
|
||||||
// This file may be used under the terms of the Be Sample Code License.
|
|
||||||
#ifndef STATUS_VIEW_H
|
|
||||||
#define STATUS_VIEW_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <String.h>
|
|
||||||
#include <View.h>
|
|
||||||
|
|
||||||
|
|
||||||
class StatusView : public BView {
|
|
||||||
public:
|
|
||||||
StatusView(BRect frame,
|
|
||||||
uint32 resizingMode);
|
|
||||||
virtual ~StatusView();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void AttachedToWindow();
|
|
||||||
virtual void Draw(BRect update);
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
|
||||||
|
|
||||||
public:
|
|
||||||
void SetStatus(const char* text);
|
|
||||||
const char* Status();
|
|
||||||
|
|
||||||
private:
|
|
||||||
BRect fStatusRect;
|
|
||||||
BString fStatusString;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // STATUS_VIEW_H
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user