X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9b10161eb6fcd0188cb635c45a3e4ddfa4636292..89b3361ec25cf1e6d255b14c7633d8375646e4fb:/samples/mediaplayer/mediaplayer.cpp diff --git a/samples/mediaplayer/mediaplayer.cpp b/samples/mediaplayer/mediaplayer.cpp index 037f2fd8aa..b4207c0c46 100644 --- a/samples/mediaplayer/mediaplayer.cpp +++ b/samples/mediaplayer/mediaplayer.cpp @@ -66,19 +66,20 @@ #include "wx/dnd.h" // drag and drop for the playlist #include "wx/filename.h" // For wxFileName::GetName() #include "wx/config.h" // for native wxConfig +#include "wx/vector.h" // Under MSW we have several different backends but when linking statically // they may be discarded by the linker (this definitely happens with MSVC) so // force linking them. You don't have to do this in your code if you don't plan // to use them, of course. -#ifdef __WXMSW__ +#if defined(__WXMSW__) && !defined(WXUSINGDLL) #include "wx/link.h" wxFORCE_LINK_MODULE(wxmediabackend_am) wxFORCE_LINK_MODULE(wxmediabackend_qt) wxFORCE_LINK_MODULE(wxmediabackend_wmp10) -#endif // __WXMSW__ +#endif // static wxMSW build -#ifndef __WXMSW__ +#ifndef wxHAS_IMAGES_IN_RESOURCES #include "../sample.xpm" #endif @@ -143,9 +144,17 @@ class wxMediaPlayerApp : public wxApp { public: #ifdef __WXMAC__ - virtual void MacOpenFile(const wxString & fileName ); + virtual void MacOpenFiles(const wxArrayString & fileNames ); #endif +#if wxUSE_CMDLINE_PARSER + virtual void OnInitCmdLine(wxCmdLineParser& parser); + virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + + // Files specified on the command line, if any. + wxVector m_params; +#endif // wxUSE_CMDLINE_PARSER + virtual bool OnInit(); protected: @@ -404,10 +413,38 @@ const wxChar* wxGetMediaStateText(int nState) // // IMPLEMENT_APP does this, and also implements the platform-specific entry // routine, such as main or WinMain(). Use IMPLEMENT_APP_NO_MAIN if you do -// not desire this behavior. +// not desire this behaviour. // ---------------------------------------------------------------------------- IMPLEMENT_APP(wxMediaPlayerApp) +// ---------------------------------------------------------------------------- +// wxMediaPlayerApp command line parsing +// ---------------------------------------------------------------------------- + +#if wxUSE_CMDLINE_PARSER + +void wxMediaPlayerApp::OnInitCmdLine(wxCmdLineParser& parser) +{ + wxApp::OnInitCmdLine(parser); + + parser.AddParam("input files", + wxCMD_LINE_VAL_STRING, + wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE); +} + +bool wxMediaPlayerApp::OnCmdLineParsed(wxCmdLineParser& parser) +{ + if ( !wxApp::OnCmdLineParsed(parser) ) + return false; + + for (size_t paramNr=0; paramNr < parser.GetParamCount(); ++paramNr) + m_params.push_back(parser.GetParam(paramNr)); + + return true; +} + +#endif // wxUSE_CMDLINE_PARSER + // ---------------------------------------------------------------------------- // wxMediaPlayerApp::OnInit // @@ -429,44 +466,25 @@ bool wxMediaPlayerApp::OnInit() frame->Show(true); #if wxUSE_CMDLINE_PARSER - // - // What this does is get all the command line arguments - // and treat each one as a file to put to the initial playlist - // - wxCmdLineEntryDesc cmdLineDesc[2]; - cmdLineDesc[0].kind = wxCMD_LINE_PARAM; - cmdLineDesc[0].shortName = NULL; - cmdLineDesc[0].longName = NULL; - cmdLineDesc[0].description = "input files"; - cmdLineDesc[0].type = wxCMD_LINE_VAL_STRING; - cmdLineDesc[0].flags = wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE; - - cmdLineDesc[1].kind = wxCMD_LINE_NONE; - - // gets the passed media files from cmd line - wxCmdLineParser parser (cmdLineDesc, argc, argv); - - // get filenames from the commandline - if (parser.Parse() == 0) + if ( !m_params.empty() ) { - for (size_t paramNr=0; paramNr < parser.GetParamCount(); ++paramNr) - { - frame->AddToPlayList((parser.GetParam (paramNr))); - } + for ( size_t n = 0; n < m_params.size(); n++ ) + frame->AddToPlayList(m_params[n]); + wxCommandEvent theEvent(wxEVT_COMMAND_MENU_SELECTED, wxID_NEXT); frame->AddPendingEvent(theEvent); } -#endif +#endif // wxUSE_CMDLINE_PARSER return true; } #ifdef __WXMAC__ -void wxMediaPlayerApp::MacOpenFile(const wxString & fileName ) +void wxMediaPlayerApp::MacOpenFiles(const wxArrayString & fileNames ) { - // Called when a user drags a file over our app - m_frame->DoOpenFile(fileName, true /* new page */); + // Called when a user drags files over our app + m_frame->DoOpenFile(fileNames[0], true /* new page */); } #endif // __WXMAC__ @@ -535,7 +553,7 @@ wxMediaPlayerFrame::wxMediaPlayerFrame(const wxString& title) wxT("Select a backend manually")); helpMenu->Append(wxID_ABOUT, - wxT("&About...\tF1"), + wxT("&About\tF1"), wxT("Show about dialog")); @@ -702,24 +720,34 @@ wxMediaPlayerFrame::wxMediaPlayerFrame(const wxString& title) wxT(""), true); - // - // Here we load the our configuration - - // in our case we load all the files that were left in - // the playlist the last time the user closed our application - // - // As an exercise to the reader try modifying it so that - // it properly loads the playlist for each page without - // conflicting (loading the same data) with the other ones. - // - wxConfig conf; - wxString key, outstring; - for(int i = 0; ; ++i) + + // Don't load previous files if we have some specified on the command line, + // we wouldn't play them otherwise (they'd have to be inserted into the + // play list at the beginning instead of being appended but we don't + // support this). +#if wxUSE_CMDLINE_PARSER + if ( wxGetApp().m_params.empty() ) +#endif // wxUSE_CMDLINE_PARSER { - key.clear(); - key << i; - if(!conf.Read(key, &outstring)) - break; - page->m_playlist->AddToPlayList(outstring); + // + // Here we load the our configuration - + // in our case we load all the files that were left in + // the playlist the last time the user closed our application + // + // As an exercise to the reader try modifying it so that + // it properly loads the playlist for each page without + // conflicting (loading the same data) with the other ones. + // + wxConfig conf; + wxString key, outstring; + for(int i = 0; ; ++i) + { + key.clear(); + key << i; + if(!conf.Read(key, &outstring)) + break; + page->m_playlist->AddToPlayList(outstring); + } } // @@ -1645,7 +1673,7 @@ wxMediaPlayerNotebookPage::wxMediaPlayerNotebookPage(wxMediaPlayerFrame* parentF // m_slider = new wxSlider(this, wxID_SLIDER, 0, // init 0, // start - 0, // end + 1, // end, dummy but must be greater than start wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL ); sizer->Add(m_slider, 0, wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND , 5);