From 57e69e63075944a8df4b5595168abb31ea6abbca Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 21 Mar 2015 03:28:30 +0000 Subject: [PATCH] Add command line args to playuver --- app/PlaYUVerApp.cpp | 48 ++++++++++++++++++++++++++++++------- app/PlaYUVerApp.h | 5 ++-- app/main.cpp | 44 ++++++++++++++++++---------------- lib/PlaYUVerCmdParser.cpp | 9 +++++-- lib/PlaYUVerCmdParser.h | 12 ++++++++-- tools/CommandLineHandle.cpp | 3 ++- 6 files changed, 84 insertions(+), 37 deletions(-) diff --git a/app/PlaYUVerApp.cpp b/app/PlaYUVerApp.cpp index 7b8147d..40276f4 100644 --- a/app/PlaYUVerApp.cpp +++ b/app/PlaYUVerApp.cpp @@ -27,11 +27,11 @@ #ifdef USE_FERVOR #include "fvupdater.h" #endif +#include "lib/PlaYUVerCmdParser.h" #include "PlaYUVerSubWindowHandle.h" #include "VideoHandle.h" #include "QualityHandle.h" #include "ModulesHandle.h" - #include "DialogSubWindowSelector.h" #define SYNCHRONISED_ZOON 1 @@ -83,17 +83,47 @@ plaYUVerApp::plaYUVerApp() m_pcCurrentVideoSubWindow = NULL; } -Void plaYUVerApp::parseArgs( Int argc, Char *argv[] ) +Bool plaYUVerApp::parseArgs( Int argc, Char *argv[] ) { - if( argc >= 2 ) + Bool bRet = false; + m_pcCmdParser = new PlaYUVerCmdParser(); + m_pcCmdParser->config( argc, argv ); + + std::vector m_apcInputs; + std::string strResolution( "" ); + std::string strPelFmt( "" ); + + m_pcCmdParser->Opts().addOptions()/**/ + ( "input,i", m_apcInputs, "input file" ) /**/ + ( "size,s", strResolution, "size (WxH)" ) /**/ + ( "pel_fmt", strPelFmt, "pixel format" ); + + if( !m_pcCmdParser->parse() ) { - for( Int i = 1; i < argc; i++ ) - { - loadFile( argv[i] ); - } - m_pcWindowHandle->tileSubWindows(); - zoomToFitAll(); + bRet |= true; } + + if( m_pcCmdParser->Opts()["help"]->count() ) + { + printf( "Usage: %s [options] input_file[s]\n", argv[0] ); + doHelp( std::cout, m_pcCmdParser->Opts() ); + bRet |= true; + } + if( m_pcCmdParser->Opts()["input"]->count() ) + { + for( UInt i = 1; i < m_apcInputs.size(); i++ ) + { + loadFile( QString::fromStdString( m_apcInputs[i] ) ); + } + } + std::list& argv_unhandled = m_pcCmdParser->getNoArgs(); + for( std::list::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++ ) + { + loadFile( QString::fromStdString( *it ) ); + } + m_pcWindowHandle->tileSubWindows(); + zoomToFitAll(); + return bRet; } Void plaYUVerApp::about() diff --git a/app/PlaYUVerApp.h b/app/PlaYUVerApp.h index 995f904..c980297 100644 --- a/app/PlaYUVerApp.h +++ b/app/PlaYUVerApp.h @@ -55,6 +55,7 @@ namespace plaYUVer { +class PlaYUVerCmdParser; class PlaYUVerStream; class PlaYUVerSubWindowHandle; class VideoHandle; @@ -68,7 +69,7 @@ Q_OBJECT public: plaYUVerApp(); - Void parseArgs( Int argc, Char *argv[] ); + Bool parseArgs( Int argc, Char *argv[] ); Void loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo = NULL ); protected: @@ -113,7 +114,7 @@ private Q_SLOTS: private: PlaYUVerAppAdaptor* m_pDBusAdaptor; - + PlaYUVerCmdParser* m_pcCmdParser; /** * Save the current subwindow for every category */ diff --git a/app/main.cpp b/app/main.cpp index f3d35e2..abc4855 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -93,33 +93,32 @@ int main( int argc, char *argv[] ) QStringList tokens; // open given files... - foreach(const QString & file, filenameList) + foreach(const QString & file, filenameList){ + QDBusMessage m = QDBusMessage::createMethodCall(PLAYUVER_DBUS_SESSION_NAME, + QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); + + QList dbusargs; + dbusargs.append( file ); + m.setArguments(dbusargs); + + QDBusMessage res = QDBusConnection::sessionBus().call(m); + if (res.type() == QDBusMessage::ReplyMessage) { - QDBusMessage m = QDBusMessage::createMethodCall(PLAYUVER_DBUS_SESSION_NAME, - QStringLiteral(PLAYUVER_DBUS_PATH), QStringLiteral(PLAYUVER_DBUS_SESSION_NAME), QStringLiteral("loadFile")); - - QList dbusargs; - dbusargs.append( file ); - m.setArguments(dbusargs); - - QDBusMessage res = QDBusConnection::sessionBus().call(m); - if (res.type() == QDBusMessage::ReplyMessage) + if (res.arguments().count() == 1) { - if (res.arguments().count() == 1) + QVariant v = res.arguments()[0]; + if (v.isValid()) { - QVariant v = res.arguments()[0]; - if (v.isValid()) + QString s = v.toString(); + if ((!s.isEmpty()) && (s != QStringLiteral("ERROR"))) { - QString s = v.toString(); - if ((!s.isEmpty()) && (s != QStringLiteral("ERROR"))) - { - tokens << s; - } + tokens << s; } } } } - // this will wait until exiting is emitted by the used instance, if wanted... + } + // this will wait until exiting is emitted by the used instance, if wanted... return needToBlock ? application.exec() : 0; } } @@ -131,10 +130,13 @@ int main( int argc, char *argv[] ) #endif plaYUVerApp mainwindow; mainwindow.show(); - mainwindow.parseArgs( argc, argv ); + if( mainwindow.parseArgs( argc, argv ) ) + { + return 0; + } #ifdef USE_FERVOR - FvUpdater::sharedUpdater()->SetFeedURL("http://192.168.96.201/share/PlaYUVerProject/PlaYUVerUpdate-" UPDATE_CHANNEL ".xml"); + FvUpdater::sharedUpdater()->SetFeedURL("http://192.168.96.201/share/PlaYUVerProject/PlaYUVerUpdate-" UPDATE_CHANNEL ".xml"); FvUpdater::sharedUpdater()->SetDependencies("ALL"); #endif diff --git a/lib/PlaYUVerCmdParser.cpp b/lib/PlaYUVerCmdParser.cpp index 6dbd779..f8ec2cc 100644 --- a/lib/PlaYUVerCmdParser.cpp +++ b/lib/PlaYUVerCmdParser.cpp @@ -55,12 +55,17 @@ Options& PlaYUVerCmdParser::Opts() return m_cParserOptions; } -Bool PlaYUVerCmdParser::parse( Int argc, Char *argv[] ) +std::list& PlaYUVerCmdParser::getNoArgs() +{ + return m_aUnhandledArgs; +} + +Bool PlaYUVerCmdParser::parse() { try { // m_cParserOptions.setDefaults(); - const std::list& argv_unhandled = scanArgv( m_cParserOptions, argc, ( const Char** )argv ); + m_aUnhandledArgs = scanArgv( m_cParserOptions, m_iArgc, ( const Char** )m_ppArgv ); // for( std::list::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++ ) // { diff --git a/lib/PlaYUVerCmdParser.h b/lib/PlaYUVerCmdParser.h index 22a08f4..8468c0c 100644 --- a/lib/PlaYUVerCmdParser.h +++ b/lib/PlaYUVerCmdParser.h @@ -25,7 +25,6 @@ #include "PlaYUVerDefs.h" #include "ProgramOptions.h" - namespace plaYUVer { @@ -35,10 +34,19 @@ public: PlaYUVerCmdParser(); ~PlaYUVerCmdParser(); - Bool parse( Int argc, Char *argv[] ); + Void config( Int argc, Char *argv[] ) + { + m_iArgc = argc; + m_ppArgv = argv; + } + Bool parse(); + std::list& getNoArgs(); Options& Opts(); private: + Int m_iArgc; + Char** m_ppArgv; Options m_cParserOptions; + std::list m_aUnhandledArgs; Bool checkListingOpts(); Void listModules(); diff --git a/tools/CommandLineHandle.cpp b/tools/CommandLineHandle.cpp index abcfbcc..ba07d58 100644 --- a/tools/CommandLineHandle.cpp +++ b/tools/CommandLineHandle.cpp @@ -76,7 +76,8 @@ Int CommandLineHandle::parseToolsArgs( Int argc, Char *argv[] ) ( "quality", m_strQualityMetric, "select a quality metric" ) /**/ ( "module", m_strModule, "select a module (use internal name)" ); - if( !parse( argc, argv ) ) + config( argc, argv ); + if( !parse() ) { iRet = 1; }