* Applied patch from Barrett (ticket #6497) which fixes some issues
with the previous patch from him. * More cleanup by myself in MediaConverterWindow::MessageReceived(), no functional changes intended. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39853 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
|
#include <fs_attr.h>
|
||||||
#include <MediaFile.h>
|
#include <MediaFile.h>
|
||||||
#include <MediaTrack.h>
|
#include <MediaTrack.h>
|
||||||
#include <Mime.h>
|
#include <Mime.h>
|
||||||
@@ -105,8 +106,10 @@ MediaConverterApp::RefsReceived(BMessage* msg)
|
|||||||
// from Open dialog or drag & drop
|
// from Open dialog or drag & drop
|
||||||
|
|
||||||
while (msg->FindRef("refs", i++, &ref) == B_OK) {
|
while (msg->FindRef("refs", i++, &ref) == B_OK) {
|
||||||
|
|
||||||
uint32 flags = 0; // B_MEDIA_FILE_NO_READ_AHEAD
|
uint32 flags = 0; // B_MEDIA_FILE_NO_READ_AHEAD
|
||||||
BMediaFile* file = new(std::nothrow) BMediaFile(&ref, flags);
|
BMediaFile* file = new(std::nothrow) BMediaFile(&ref, flags);
|
||||||
|
|
||||||
if (file == NULL || file->InitCheck() != B_OK) {
|
if (file == NULL || file->InitCheck() != B_OK) {
|
||||||
errorFiles << ref.name << "\n";
|
errorFiles << ref.name << "\n";
|
||||||
errors++;
|
errors++;
|
||||||
@@ -122,7 +125,7 @@ MediaConverterApp::RefsReceived(BMessage* msg)
|
|||||||
|
|
||||||
if (errors) {
|
if (errors) {
|
||||||
BString alertText;
|
BString alertText;
|
||||||
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(),
|
||||||
@@ -175,7 +178,6 @@ MediaConverterApp::SetStatusMessage(const char* message)
|
|||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
BEntry
|
BEntry
|
||||||
MediaConverterApp::_CreateOutputFile(BDirectory directory,
|
MediaConverterApp::_CreateOutputFile(BDirectory directory,
|
||||||
entry_ref* ref, media_file_format* outputFormat)
|
entry_ref* ref, media_file_format* outputFormat)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class MediaConverterApp : public BApplication {
|
|||||||
BEntry _CreateOutputFile(BDirectory directory,
|
BEntry _CreateOutputFile(BDirectory directory,
|
||||||
entry_ref* ref,
|
entry_ref* ref,
|
||||||
media_file_format* outputFormat);
|
media_file_format* outputFormat);
|
||||||
|
|
||||||
static int32 _RunConvertEntry(void* castToMediaConverterApp);
|
static int32 _RunConvertEntry(void* castToMediaConverterApp);
|
||||||
void _RunConvert();
|
void _RunConvert();
|
||||||
status_t _ConvertFile(BMediaFile* inFile,
|
status_t _ConvertFile(BMediaFile* inFile,
|
||||||
|
|||||||
@@ -270,25 +270,10 @@ MediaConverterWindow::DispatchMessage(BMessage *msg, BHandler *handler)
|
|||||||
void
|
void
|
||||||
MediaConverterWindow::MessageReceived(BMessage* msg)
|
MediaConverterWindow::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
status_t status;
|
|
||||||
entry_ref ref;
|
|
||||||
entry_ref inRef;
|
entry_ref inRef;
|
||||||
|
|
||||||
BString string, string2;
|
|
||||||
|
|
||||||
// TODO: For preview, launch the default file app instead of hardcoded
|
|
||||||
// MediaPlayer
|
|
||||||
BEntry entry("/boot/system/apps/MediaPlayer", true);
|
|
||||||
char buffer[40];
|
char buffer[40];
|
||||||
char buffer2[B_PATH_NAME_LENGTH];
|
BEntry inEntry;
|
||||||
const char* argv[3];
|
|
||||||
argv[0] = "-pos";
|
|
||||||
BMediaFile *inFile(NULL);
|
|
||||||
int32 srcIndex = 0;
|
|
||||||
BPath name;
|
|
||||||
BEntry inentry;
|
|
||||||
int32 value;
|
|
||||||
BRect ButtonRect;
|
|
||||||
|
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
#if B_BEOS_VERSION <= B_BEOS_VERSION_6
|
#if B_BEOS_VERSION <= B_BEOS_VERSION_6
|
||||||
@@ -304,8 +289,7 @@ MediaConverterWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case B_SIMPLE_DATA:
|
case B_SIMPLE_DATA:
|
||||||
if (msg->WasDropped())
|
if (msg->WasDropped()) {
|
||||||
{
|
|
||||||
DetachCurrentMessage();
|
DetachCurrentMessage();
|
||||||
msg->what = B_REFS_RECEIVED;
|
msg->what = B_REFS_RECEIVED;
|
||||||
BMessenger(be_app).SendMessage(msg);
|
BMessenger(be_app).SendMessage(msg);
|
||||||
@@ -336,66 +320,66 @@ MediaConverterWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CONVERSION_DONE_MESSAGE:
|
case CONVERSION_DONE_MESSAGE:
|
||||||
SetStatusMessage(fCancelling ? CONV_CANCEL_LABEL : CONV_COMPLETE_LABEL);
|
{
|
||||||
|
SetStatusMessage(fCancelling ? CONV_CANCEL_LABEL
|
||||||
|
: CONV_COMPLETE_LABEL);
|
||||||
fConverting = false;
|
fConverting = false;
|
||||||
fCancelling = false;
|
fCancelling = false;
|
||||||
{
|
bool enable = CountSourceFiles() > 0;
|
||||||
bool enable = CountSourceFiles() > 0;
|
SetEnabled(enable, enable);
|
||||||
SetEnabled(enable, enable);
|
|
||||||
}
|
|
||||||
fConvertButton->SetLabel(CONVERT_LABEL);
|
fConvertButton->SetLabel(CONVERT_LABEL);
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case OUTPUT_FOLDER_MESSAGE:
|
case OUTPUT_FOLDER_MESSAGE:
|
||||||
// Execute Save Panel
|
// Execute Save Panel
|
||||||
if (!fSaveFilePanel) {
|
if (fSaveFilePanel == NULL) {
|
||||||
BButton *SelectThisDir;
|
BButton* selectThisDir;
|
||||||
|
|
||||||
BMessage message(FOLDER_SELECT_MESSAGE);
|
BMessage message(FOLDER_SELECT_MESSAGE);
|
||||||
fSaveFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
|
fSaveFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
|
||||||
B_DIRECTORY_NODE, true, &message, NULL, false, true);
|
B_DIRECTORY_NODE, true, &message, NULL, false, true);
|
||||||
fSaveFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, SELECT_LABEL);
|
fSaveFilePanel->SetButtonLabel(B_DEFAULT_BUTTON, SELECT_LABEL);
|
||||||
fSaveFilePanel->Window()->SetTitle(SAVE_DIR_LABEL);
|
|
||||||
fSaveFilePanel->SetTarget(this);
|
fSaveFilePanel->SetTarget(this);
|
||||||
|
|
||||||
fSaveFilePanel->Window()->Lock();
|
fSaveFilePanel->Window()->Lock();
|
||||||
ButtonRect = fSaveFilePanel->Window()->ChildAt(0)->FindView("cancel button")->Frame();
|
fSaveFilePanel->Window()->SetTitle(SAVE_DIR_LABEL);
|
||||||
ButtonRect.right = ButtonRect.left - 20;
|
BRect buttonRect
|
||||||
ButtonRect.left = ButtonRect.right - 130;
|
= fSaveFilePanel->Window()->ChildAt(0)->FindView(
|
||||||
SelectThisDir = new BButton(ButtonRect, NULL, SELECT_DIR_LABEL,
|
"cancel button")->Frame();
|
||||||
new BMessage(SELECT_THIS_DIR_MESSAGE), B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
|
buttonRect.right = buttonRect.left - 20;
|
||||||
SelectThisDir->SetTarget(this);
|
buttonRect.left = buttonRect.right - 130;
|
||||||
fSaveFilePanel->Window()->ChildAt(0)->AddChild(SelectThisDir);
|
selectThisDir = new BButton(buttonRect, NULL, SELECT_DIR_LABEL,
|
||||||
|
new BMessage(SELECT_THIS_DIR_MESSAGE),
|
||||||
|
B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
|
||||||
|
selectThisDir->SetTarget(this);
|
||||||
|
fSaveFilePanel->Window()->ChildAt(0)->AddChild(selectThisDir);
|
||||||
fSaveFilePanel->Window()->Unlock();
|
fSaveFilePanel->Window()->Unlock();
|
||||||
|
|
||||||
BRefFilter *filter;
|
fSaveFilePanel->SetRefFilter(new DirectoryFilter);
|
||||||
filter = new DirectoryFilter;
|
|
||||||
fSaveFilePanel->SetRefFilter(filter);
|
|
||||||
}
|
}
|
||||||
fSaveFilePanel->Show();
|
fSaveFilePanel->Show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FOLDER_SELECT_MESSAGE:
|
case FOLDER_SELECT_MESSAGE:
|
||||||
// "SELECT" Button at Save Panel Pushed
|
// "SELECT" Button at Save Panel Pushed
|
||||||
fSaveFilePanel->GetNextSelectedRef(&inRef);
|
fSaveFilePanel->GetNextSelectedRef(&inRef);
|
||||||
inentry.SetTo(&inRef, true);
|
inEntry.SetTo(&inRef, true);
|
||||||
_SetOutputFolder(inentry);
|
_SetOutputFolder(inEntry);
|
||||||
fOutputDirSpecified = true;
|
fOutputDirSpecified = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SELECT_THIS_DIR_MESSAGE:
|
case SELECT_THIS_DIR_MESSAGE:
|
||||||
// "THIS DIR" Button at Save Panel Pushed
|
// "THIS DIR" Button at Save Panel Pushed
|
||||||
fSaveFilePanel->GetPanelDirectory(&inRef);
|
fSaveFilePanel->GetPanelDirectory(&inRef);
|
||||||
fSaveFilePanel->Hide();
|
fSaveFilePanel->Hide();
|
||||||
inentry.SetTo(&inRef, true);
|
inEntry.SetTo(&inRef, true);
|
||||||
_SetOutputFolder(inentry);
|
_SetOutputFolder(inEntry);
|
||||||
fOutputDirSpecified = true;
|
fOutputDirSpecified = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPEN_FILE_MESSAGE:
|
case OPEN_FILE_MESSAGE:
|
||||||
// Execute Open Panel
|
// Execute Open Panel
|
||||||
if (!fOpenFilePanel) {
|
if (!fOpenFilePanel) {
|
||||||
fOpenFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
|
fOpenFilePanel = new BFilePanel(B_OPEN_PANEL, NULL, NULL,
|
||||||
B_FILE_NODE, true, NULL, NULL, false, true);
|
B_FILE_NODE, true, NULL, NULL, false, true);
|
||||||
@@ -405,7 +389,7 @@ MediaConverterWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case B_REFS_RECEIVED:
|
case B_REFS_RECEIVED:
|
||||||
// Media Files Seleced by Open Panel
|
// Media Files Seleced by Open Panel
|
||||||
DetachCurrentMessage();
|
DetachCurrentMessage();
|
||||||
msg->what = B_REFS_RECEIVED;
|
msg->what = B_REFS_RECEIVED;
|
||||||
BMessenger(be_app).SendMessage(msg);
|
BMessenger(be_app).SendMessage(msg);
|
||||||
@@ -414,7 +398,8 @@ MediaConverterWindow::MessageReceived(BMessage* msg)
|
|||||||
case B_CANCEL:
|
case B_CANCEL:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DISP_ABOUT_MESSAGE: {
|
case DISP_ABOUT_MESSAGE:
|
||||||
|
{
|
||||||
(new BAlert(ABOUT_TITLE_LABEL B_UTF8_ELLIPSIS,
|
(new BAlert(ABOUT_TITLE_LABEL B_UTF8_ELLIPSIS,
|
||||||
"MediaConverter\n"
|
"MediaConverter\n"
|
||||||
VERSION"\n"
|
VERSION"\n"
|
||||||
@@ -431,46 +416,67 @@ MediaConverterWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PREVIEW_MESSAGE:
|
case PREVIEW_MESSAGE:
|
||||||
entry.GetRef(&ref);
|
{
|
||||||
string = "";
|
// Build the command line to launch the preview application.
|
||||||
string << fStartDurationTC->Text();
|
// TODO: Launch the default app instead of hardcoded MediaPlayer!
|
||||||
string << "000";
|
int32 srcIndex = fListView->CurrentSelection();
|
||||||
|
BMediaFile* inFile = NULL;
|
||||||
|
status_t status = GetSourceFileAt(srcIndex, &inFile, &inRef);
|
||||||
|
|
||||||
|
const char* argv[3];
|
||||||
|
BString startPosString;
|
||||||
|
BPath path;
|
||||||
|
|
||||||
strcpy(buffer, string.String());
|
|
||||||
argv[1] = buffer;
|
|
||||||
srcIndex = fListView->CurrentSelection();
|
|
||||||
status = GetSourceFileAt(srcIndex, &inFile, &inRef);
|
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
inentry.SetTo(&inRef);
|
argv[0] = "-pos";
|
||||||
inentry.GetPath(&name);
|
// NOTE: -pos argument is currently not supported by Haiku
|
||||||
|
// MediaPlayer.
|
||||||
|
startPosString << fStartDurationTC->Text();
|
||||||
|
startPosString << "000";
|
||||||
|
argv[1] = startPosString.String();
|
||||||
|
|
||||||
strcpy(buffer, string.String());
|
status = inEntry.SetTo(&inRef);
|
||||||
|
|
||||||
strcpy(buffer2, name.Path());
|
|
||||||
argv[2] = buffer2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status = be_roster->Launch(&ref, 3, argv);
|
if (status == B_OK) {
|
||||||
|
status = inEntry.GetPath(&path);
|
||||||
|
if (status == B_OK)
|
||||||
|
argv[2] = path.Path();
|
||||||
|
}
|
||||||
|
|
||||||
if (status != B_OK) {
|
if (status == B_OK) {
|
||||||
string2 << LAUNCH_ERROR << strerror(status);
|
status = be_roster->Launch(
|
||||||
(new BAlert("", string2.String(), OK_LABEL))->Go();
|
"application/x-vnd.Haiku-MediaPlayer",
|
||||||
|
3, (char**)argv, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != B_OK && status != B_ALREADY_RUNNING) {
|
||||||
|
BString errorString;
|
||||||
|
errorString << LAUNCH_ERROR << strerror(status);
|
||||||
|
(new BAlert("", errorString.String(), OK_LABEL))->Go();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case VIDEO_QUALITY_CHANGED_MESSAGE:
|
case VIDEO_QUALITY_CHANGED_MESSAGE:
|
||||||
msg->FindInt32("be:value",&value);
|
{
|
||||||
sprintf(buffer, VIDEO_QUALITY_LABEL, (int8)value);
|
int32 value;
|
||||||
|
msg->FindInt32("be:value", &value);
|
||||||
|
snprintf(buffer, sizeof(buffer), VIDEO_QUALITY_LABEL, (int8)value);
|
||||||
fVideoQualitySlider->SetLabel(buffer);
|
fVideoQualitySlider->SetLabel(buffer);
|
||||||
fVideoQuality = value;
|
fVideoQuality = value;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case AUDIO_QUALITY_CHANGED_MESSAGE:
|
case AUDIO_QUALITY_CHANGED_MESSAGE:
|
||||||
msg->FindInt32("be:value",&value);
|
{
|
||||||
sprintf(buffer, AUDIO_QUALITY_LABEL, (int8)value);
|
int32 value;
|
||||||
|
msg->FindInt32("be:value", &value);
|
||||||
|
snprintf(buffer, sizeof(buffer), AUDIO_QUALITY_LABEL, (int8)value);
|
||||||
fAudioQualitySlider->SetLabel(buffer);
|
fAudioQualitySlider->SetLabel(buffer);
|
||||||
fAudioQuality = value;
|
fAudioQuality = value;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(msg);
|
BWindow::MessageReceived(msg);
|
||||||
@@ -756,7 +762,8 @@ MediaConverterWindow::SourceFileSelectionChanged()
|
|||||||
fStartDurationTC->SetEnabled(enabled);
|
fStartDurationTC->SetEnabled(enabled);
|
||||||
fEndDurationTC->SetEnabled(enabled);
|
fEndDurationTC->SetEnabled(enabled);
|
||||||
|
|
||||||
fInfoView->Update(file, _ref);
|
if (enabled)
|
||||||
|
fInfoView->Update(file, _ref);
|
||||||
|
|
||||||
// HACK: get the fInfoView to update the duration "synchronously"
|
// HACK: get the fInfoView to update the duration "synchronously"
|
||||||
UpdateIfNeeded();
|
UpdateIfNeeded();
|
||||||
@@ -862,7 +869,8 @@ MediaConverterWindow::_UpdateLabels()
|
|||||||
|
|
||||||
if (fVideoQualitySlider != NULL) {
|
if (fVideoQualitySlider != NULL) {
|
||||||
char buffer[40];
|
char buffer[40];
|
||||||
sprintf(buffer, VIDEO_QUALITY_LABEL, (int8)fVideoQuality);
|
snprintf(buffer, sizeof(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);
|
||||||
@@ -870,7 +878,8 @@ MediaConverterWindow::_UpdateLabels()
|
|||||||
|
|
||||||
if (fAudioQualitySlider != NULL) {
|
if (fAudioQualitySlider != NULL) {
|
||||||
char buffer[40];
|
char buffer[40];
|
||||||
sprintf(buffer, AUDIO_QUALITY_LABEL, (int8)fAudioQuality);
|
snprintf(buffer, sizeof(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);
|
||||||
|
|||||||
@@ -151,21 +151,20 @@ MediaFileInfoView::Update(BMediaFile* file, entry_ref* ref)
|
|||||||
|
|
||||||
fMediaFile = file;
|
fMediaFile = file;
|
||||||
|
|
||||||
if (file != NULL && ref != NULL)
|
if (file != NULL && ref != NULL) {
|
||||||
fRef = *ref;
|
fRef = *ref;
|
||||||
else
|
status_t ret = fInfo.LoadInfo(file);
|
||||||
|
if (ret != B_OK) {
|
||||||
|
BString error("An error has occurred reading the "
|
||||||
|
"file info.\n\nError : ");
|
||||||
|
error << strerror(ret);
|
||||||
|
BAlert* alert = new BAlert("File Error", error.String(),
|
||||||
|
"OK");
|
||||||
|
alert->Go(NULL);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
fRef = entry_ref();
|
fRef = entry_ref();
|
||||||
|
|
||||||
status_t ret = fInfo.LoadInfo(file);
|
|
||||||
if (ret != B_OK) {
|
|
||||||
BString error("An error has occurred reading the "
|
|
||||||
"file info.\n\nError : ");
|
|
||||||
error << strerror(ret);
|
|
||||||
BAlert* alert = new BAlert("File Error", error.String(),
|
|
||||||
"OK");
|
|
||||||
alert->Go(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InvalidateLayout();
|
InvalidateLayout();
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user