1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef CMDLINEPARSER_H |
5 | #define CMDLINEPARSER_H |
6 | |
7 | #include <QtCore/QCoreApplication> |
8 | #include <QtCore/QStringList> |
9 | #include <QtCore/QUrl> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | class CmdLineParser |
14 | { |
15 | Q_DECLARE_TR_FUNCTIONS(CmdLineParser) |
16 | public: |
17 | enum Result {Ok, Help, Error}; |
18 | enum ShowState {Untouched, Show, Hide, Activate}; |
19 | enum RegisterState {None, Register, Unregister}; |
20 | |
21 | CmdLineParser(const QStringList &arguments); |
22 | Result parse(); |
23 | |
24 | void setCollectionFile(const QString &file); |
25 | QString collectionFile() const; |
26 | bool collectionFileGiven() const; |
27 | QString cloneFile() const; |
28 | QUrl url() const; |
29 | bool enableRemoteControl() const; |
30 | ShowState contents() const; |
31 | ShowState index() const; |
32 | ShowState bookmarks() const; |
33 | ShowState search() const; |
34 | QString currentFilter() const; |
35 | bool removeSearchIndex() const; |
36 | bool rebuildSearchIndex() const; |
37 | RegisterState registerRequest() const; |
38 | QString helpFile() const; |
39 | |
40 | void showMessage(const QString &msg, bool error); |
41 | |
42 | private: |
43 | QString getFileName(const QString &fileName); |
44 | bool hasMoreArgs() const; |
45 | const QString &nextArg(); |
46 | void handleCollectionFileOption(); |
47 | void handleShowUrlOption(); |
48 | void handleShowOption(); |
49 | void handleHideOption(); |
50 | void handleActivateOption(); |
51 | void handleShowOrHideOrActivateOption(ShowState state); |
52 | void handleRegisterOption(); |
53 | void handleUnregisterOption(); |
54 | void handleRegisterOrUnregisterOption(RegisterState state); |
55 | void handleSetCurrentFilterOption(); |
56 | |
57 | QStringList m_arguments; |
58 | int m_pos; |
59 | QString m_collectionFile; |
60 | QString m_cloneFile; |
61 | QString m_helpFile; |
62 | QUrl m_url; |
63 | bool m_enableRemoteControl; |
64 | |
65 | ShowState m_contents; |
66 | ShowState m_index; |
67 | ShowState m_bookmarks; |
68 | ShowState m_search; |
69 | RegisterState m_register; |
70 | QString m_currentFilter; |
71 | bool m_removeSearchIndex; |
72 | bool m_quiet; |
73 | QString m_error; |
74 | }; |
75 | |
76 | QT_END_NAMESPACE |
77 | |
78 | #endif |
79 | |