signature fix

now quits gracefully when no media roster is available


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13094 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2005-06-13 13:51:53 +00:00
parent 98f5c76b8f
commit 5fa7753230
5 changed files with 51 additions and 27 deletions

View File

@ -12,6 +12,7 @@
RecorderApp::RecorderApp(const char * signature) : RecorderApp::RecorderApp(const char * signature) :
BApplication(signature), fRecorderWin(NULL) BApplication(signature), fRecorderWin(NULL)
{ {
fRecorderWin = new RecorderWindow();
} }
RecorderApp::~RecorderApp() RecorderApp::~RecorderApp()
@ -19,12 +20,12 @@ RecorderApp::~RecorderApp()
} }
void status_t
RecorderApp::ReadyToRun() RecorderApp::InitCheck()
{ {
BApplication::ReadyToRun(); if (fRecorderWin)
fRecorderWin = new RecorderWindow(); return fRecorderWin->InitCheck();
fRecorderWin->Show(); return B_OK;
} }
@ -32,6 +33,7 @@ int
main() main()
{ {
RecorderApp app("application/x-vnd.Haiku-SoundRecorder"); RecorderApp app("application/x-vnd.Haiku-SoundRecorder");
app.Run(); if (app.InitCheck() == B_OK)
app.Run();
return 0; return 0;
} }

View File

@ -14,11 +14,9 @@ class RecorderWindow;
class RecorderApp : public BApplication { class RecorderApp : public BApplication {
public: public:
RecorderApp(const char * signature); RecorderApp(const char * signature);
virtual ~RecorderApp(); virtual ~RecorderApp();
status_t InitCheck();
virtual void ReadyToRun();
private: private:
RecorderWindow* fRecorderWin; RecorderWindow* fRecorderWin;
}; };

View File

@ -101,9 +101,11 @@ RecorderWindow::RecorderWindow() :
BWindow(BRect(XPOS,YPOS,XPOS+MIN_WIDTH,YPOS+MIN_HEIGHT), "Sound Recorder", B_TITLED_WINDOW, BWindow(BRect(XPOS,YPOS,XPOS+MIN_WIDTH,YPOS+MIN_HEIGHT), "Sound Recorder", B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE), B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE),
fPlayer(NULL), fPlayer(NULL),
fSoundList(NULL),
fPlayFile(NULL), fPlayFile(NULL),
fPlayTrack(NULL), fPlayTrack(NULL),
fSavePanel(B_SAVE_PANEL) fSavePanel(NULL),
fInitCheck(B_OK)
{ {
fRoster = NULL; fRoster = NULL;
fRecordButton = NULL; fRecordButton = NULL;
@ -119,12 +121,16 @@ RecorderWindow::RecorderWindow() :
CalcSizes(MIN_WIDTH, MIN_HEIGHT); CalcSizes(MIN_WIDTH, MIN_HEIGHT);
InitWindow(); fInitCheck = InitWindow();
if (fInitCheck != B_OK) {
ErrorAlert("connect to media server", fInitCheck);
PostMessage(B_QUIT_REQUESTED);
} else
Show();
} }
RecorderWindow::~RecorderWindow() RecorderWindow::~RecorderWindow()
{ {
DEATH((stderr, "RecorderWindow::~RecorderWindow()\n"));
// The sound consumer and producer are Nodes; it has to be Release()d and the Roster // The sound consumer and producer are Nodes; it has to be Release()d and the Roster
// will reap it when it's done. // will reap it when it's done.
if (fRecordNode) { if (fRecordNode) {
@ -154,6 +160,13 @@ RecorderWindow::~RecorderWindow()
} }
status_t
RecorderWindow::InitCheck()
{
return fInitCheck;
}
void void
RecorderWindow::CalcSizes(float min_wid, float min_hei) RecorderWindow::CalcSizes(float min_wid, float min_hei)
{ {
@ -441,7 +454,8 @@ RecorderWindow::InitWindow()
popup->Superitem()->SetLabel(selected_name); popup->Superitem()->SetLabel(selected_name);
// Make sure the save panel is happy. // Make sure the save panel is happy.
fSavePanel.SetTarget(this); fSavePanel = new BFilePanel(B_SAVE_PANEL);
fSavePanel->SetTarget(this);
} }
catch (...) { catch (...) {
goto bad_mojo; goto bad_mojo;
@ -713,9 +727,9 @@ RecorderWindow::Save(BMessage * message)
pItem->Entry().GetRef(&ref); pItem->Entry().GetRef(&ref);
saveMsg.AddPointer("sound list item", pItem); saveMsg.AddPointer("sound list item", pItem);
fSavePanel.SetSaveText(filename); fSavePanel->SetSaveText(filename);
fSavePanel.SetMessage(&saveMsg); fSavePanel->SetMessage(&saveMsg);
fSavePanel.Show(); fSavePanel->Show();
} }
void void
@ -1009,6 +1023,9 @@ RecorderWindow::UpdateButtons()
fInputField->SetEnabled(fButtonState != btnRecording); fInputField->SetEnabled(fButtonState != btnRecording);
} }
#ifndef __HAIKU__
extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *self, media_format *inout_format);
#endif
void void
RecorderWindow::UpdatePlayFile() RecorderWindow::UpdatePlayFile()
@ -1036,7 +1053,12 @@ RecorderWindow::UpdatePlayFile()
for (int ix=0; ix<fPlayFile->CountTracks(); ix++) { for (int ix=0; ix<fPlayFile->CountTracks(); ix++) {
BMediaTrack * track = fPlayFile->TrackAt(ix); BMediaTrack * track = fPlayFile->TrackAt(ix);
fPlayFormat.type = B_MEDIA_RAW_AUDIO; fPlayFormat.type = B_MEDIA_RAW_AUDIO;
if ((track->DecodedFormat(&fPlayFormat) == B_OK) && (fPlayFormat.type == B_MEDIA_RAW_AUDIO)) { #ifdef __HAIKU__
if ((track->DecodedFormat(&fPlayFormat) == B_OK)
#else
if ((DecodedFormat__11BMediaTrackP12media_format(track, &fPlayFormat) == B_OK)
#endif
&& (fPlayFormat.type == B_MEDIA_RAW_AUDIO)) {
fPlayTrack = track; fPlayTrack = track;
break; break;
} }
@ -1096,7 +1118,7 @@ void
RecorderWindow::ErrorAlert(const char * action, status_t err) RecorderWindow::ErrorAlert(const char * action, status_t err)
{ {
char msg[300]; char msg[300];
sprintf(msg, "Cannot %s: %s.\n[%lx]", action, strerror(err), (int32) err); sprintf(msg, "Cannot %s: %s. [%lx]", action, strerror(err), (int32) err);
(new BAlert("", msg, "Stop"))->Go(); (new BAlert("", msg, "Stop"))->Go();
} }
@ -1230,4 +1252,4 @@ RecorderWindow::RefsReceived(BMessage *msg)
} }
} }
} }

View File

@ -40,11 +40,12 @@ class BStringView;
class RecorderWindow : public BWindow { class RecorderWindow : public BWindow {
public: public:
RecorderWindow(); RecorderWindow();
virtual ~RecorderWindow(); virtual ~RecorderWindow();
status_t InitCheck();
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void MessageReceived(BMessage * message); virtual void MessageReceived(BMessage * message);
enum { enum {
RECORD = 'cw00', // command messages RECORD = 'cw00', // command messages
@ -123,7 +124,8 @@ private:
media_node fAudioMixerNode; media_node fAudioMixerNode;
BFilePanel fSavePanel; BFilePanel *fSavePanel;
status_t fInitCheck;
status_t InitWindow(); status_t InitWindow();

View File

@ -1,5 +1,5 @@
resource app_signature "application/x-vnd.haiku.SoundRecorder"; resource app_signature "application/x-vnd.Haiku-SoundRecorder";
resource app_flags B_SINGLE_LAUNCH; resource app_flags B_SINGLE_LAUNCH;