1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the Qt Assistant of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 #ifndef CMDLINEPARSER_H 30 #define CMDLINEPARSER_H 31 32 #include <QtCore/QCoreApplication> 33 #include <QtCore/QStringList> 34 #include <QtCore/QUrl> 35 36 QT_BEGIN_NAMESPACE 37 38 class CmdLineParser 39 { 40 Q_DECLARE_TR_FUNCTIONS(CmdLineParser) 41 public: 42 enum Result {Ok, Help, Error}; 43 enum ShowState {Untouched, Show, Hide, Activate}; 44 enum RegisterState {None, Register, Unregister}; 45 46 CmdLineParser(const QStringList &arguments); 47 Result parse(); 48 49 void setCollectionFile(const QString &file); 50 QString collectionFile() const; 51 bool collectionFileGiven() const; 52 QString cloneFile() const; 53 QUrl url() const; 54 bool enableRemoteControl() const; 55 ShowState contents() const; 56 ShowState index() const; 57 ShowState bookmarks() const; 58 ShowState search() const; 59 QString currentFilter() const; 60 bool removeSearchIndex() const; 61 bool rebuildSearchIndex() const; 62 RegisterState registerRequest() const; 63 QString helpFile() const; 64 65 void showMessage(const QString &msg, bool error); 66 67 private: 68 QString getFileName(const QString &fileName); 69 bool hasMoreArgs() const; 70 const QString &nextArg(); 71 void handleCollectionFileOption(); 72 void handleShowUrlOption(); 73 void handleShowOption(); 74 void handleHideOption(); 75 void handleActivateOption(); 76 void handleShowOrHideOrActivateOption(ShowState state); 77 void handleRegisterOption(); 78 void handleUnregisterOption(); 79 void handleRegisterOrUnregisterOption(RegisterState state); 80 void handleSetCurrentFilterOption(); 81 82 QStringList m_arguments; 83 int m_pos; 84 QString m_collectionFile; 85 QString m_cloneFile; 86 QString m_helpFile; 87 QUrl m_url; 88 bool m_enableRemoteControl; 89 90 ShowState m_contents; 91 ShowState m_index; 92 ShowState m_bookmarks; 93 ShowState m_search; 94 RegisterState m_register; 95 QString m_currentFilter; 96 bool m_removeSearchIndex; 97 bool m_quiet; 98 QString m_error; 99 }; 100 101 QT_END_NAMESPACE 102 103 #endif 104