/* * Copyright 2013 Canonical Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * * Author: Florian Boucault */ #ifndef UCARGUMENTS_P_H #define UCARGUMENTS_P_H #include #include #include #include #include #include #include #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include #else #include #endif UT_NAMESPACE_BEGIN class LOMIRITOOLKIT_EXPORT UCArguments : public QObject, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(UT_PREPEND_NAMESPACE(UCArgument)* defaultArgument READ defaultArgument WRITE setDefaultArgument NOTIFY defaultArgumentChanged) Q_PROPERTY(QQmlListProperty arguments READ arguments) Q_CLASSINFO("DefaultProperty", "arguments") Q_PROPERTY(QQmlPropertyMap* values READ values CONSTANT) Q_PROPERTY(bool error READ error NOTIFY errorChanged) Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged) public: explicit UCArguments(QObject *parent = 0); UCArgument* defaultArgument() const; void setDefaultArgument(UCArgument* argument); QQmlPropertyMap* values() const; bool error() const; QString errorMessage() const; Q_INVOKABLE void printUsage(); Q_INVOKABLE void quitWithError(const QString& errorMessage = QString()); // inherited from QQmlParserStatus void classBegin() override; void componentComplete() override; // methods necessary for implementing property QQmlListProperty arguments void appendArguments(UCArgument* argument); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) UCArgument* atArguments(qsizetype index); qsizetype countArguments(); #else UCArgument* atArguments(int index); int countArguments(); #endif void clearArguments(); QQmlListProperty arguments(); Q_SIGNALS: void defaultArgumentChanged(); void errorChanged(); void errorMessageChanged(); protected: void parseAndExposeArguments(); void setValuesOnArguments(const QHash& argumentsValues); QHash buildExpectedArguments(const QList& declaredArguments); QHash parseRawArguments(const QStringList& rawArguments, const QHash& expectedArguments); QStringList collectArgumentValues(QStringList::const_iterator& i, QStringList::const_iterator end, int nValues); bool usageRequested(const QStringList& argumentNames); bool requiredArgumentsProvided(const QHash& argumentsValues, QString& error); bool requiredDefaultArgumentProvided(const QHash& argumentsValues, QString& error); void exposeArgumentsAsProperties(const QHash& argumentsValues); QString usage(); void setErrorMessage(const QString& errorMessage); void quitApplication(); protected Q_SLOTS: void warningArgumentPropertyChanged(); private: bool m_completed; UCArgument* m_defaultArgument; QList m_arguments; QStringList m_rawArguments; QString m_applicationBinary; QQmlPropertyMap* m_values; bool m_error; QString m_errorMessage; }; UT_NAMESPACE_END #endif // UCARGUMENTS_H