From cf44101e03eb33caa7c37fbd8023c2948b7f0249 Mon Sep 17 00:00:00 2001 From: ck Date: Fri, 13 Nov 2009 16:25:37 +0100 Subject: Assistant: Refactor command line parser. Reviewed-by: kh1 --- tools/assistant/tools/assistant/cmdlineparser.cpp | 302 +++++++++++----------- tools/assistant/tools/assistant/cmdlineparser.h | 26 +- tools/assistant/tools/assistant/main.cpp | 4 +- 3 files changed, 173 insertions(+), 159 deletions(-) diff --git a/tools/assistant/tools/assistant/cmdlineparser.cpp b/tools/assistant/tools/assistant/cmdlineparser.cpp index 1245d7c..b17909c 100644 --- a/tools/assistant/tools/assistant/cmdlineparser.cpp +++ b/tools/assistant/tools/assistant/cmdlineparser.cpp @@ -46,21 +46,7 @@ QT_BEGIN_NAMESPACE -#define CHECK_NEXT_ARG \ - ++i < arguments.count() && !arguments.at(i).startsWith(QLatin1String("-")) - -CmdLineParser::CmdLineParser() - : m_enableRemoteControl(false), - m_contents(Untouched), - m_index(Untouched), - m_bookmarks(Untouched), - m_search(Untouched), - m_register(None), - m_removeSearchIndex(false), - m_copy(false), - m_quiet(false) -{ - m_helpMessage = QLatin1String( +const QString CmdLineParser::m_helpMessage = QLatin1String( "Usage: assistant [Options]\n\n" "-collectionFile file Uses the specified collection\n" " file instead of the default one\n" @@ -89,152 +75,62 @@ CmdLineParser::CmdLineParser() " status message.\n" "-help Displays this help.\n" ); -} -CmdLineParser::Result CmdLineParser::parse(const QStringList &arguments) -{ - QString error; - bool showHelp = false; - for (int j=1; j #include #include @@ -49,13 +50,14 @@ QT_BEGIN_NAMESPACE class CmdLineParser { + Q_DECLARE_TR_FUNCTIONS(CmdLineParser) public: enum Result {Ok, Help, Error}; enum ShowState {Untouched, Show, Hide, Activate}; enum RegisterState {None, Register, Unregister}; - CmdLineParser(); - Result parse(const QStringList &arguments); + CmdLineParser(const QStringList &arguments); + Result parse(); void setCollectionFile(const QString &file); QString collectionFile() const; @@ -71,14 +73,26 @@ public: RegisterState registerRequest() const; QString helpFile() const; - bool copy() const { return m_copy; } - void showMessage(const QString &msg, bool error); private: QString getFileName(const QString &fileName); + bool hasMoreArgs() const; + const QString &nextArg(); + void handleCollectionFileOption(); + void handleShowUrlOption(); + void handleShowOption(); + void handleHideOption(); + void handleActivateOption(); + void handleShowOrHideOrActivateOption(ShowState state); + void handleRegisterOption(); + void handleUnregisterOption(); + void handleRegisterOrUnregisterOption(RegisterState state); + void handleSetCurrentFilterOption(); - QString m_helpMessage; + QStringList m_arguments; + int m_pos; + static const QString m_helpMessage; QString m_collectionFile; QString m_cloneFile; QString m_helpFile; @@ -92,8 +106,8 @@ private: RegisterState m_register; QString m_currentFilter; bool m_removeSearchIndex; - bool m_copy; bool m_quiet; + QString m_error; }; QT_END_NAMESPACE diff --git a/tools/assistant/tools/assistant/main.cpp b/tools/assistant/tools/assistant/main.cpp index 2df7a6b..1b3a5f9 100644 --- a/tools/assistant/tools/assistant/main.cpp +++ b/tools/assistant/tools/assistant/main.cpp @@ -210,8 +210,8 @@ int main(int argc, char *argv[]) QApplication a(argc, argv, useGui); a.addLibraryPath(a.applicationDirPath() + QLatin1String("/plugins")); - CmdLineParser cmd; - CmdLineParser::Result res = cmd.parse(a.arguments()); + CmdLineParser cmd(a.arguments()); + CmdLineParser::Result res = cmd.parse(); if (res == CmdLineParser::Help) return 0; else if (res == CmdLineParser::Error) -- cgit v0.12