| 48 | } |
| 49 | |
| 50 | bool CliRemoteController::execute(QCommandLineParser &parser) |
| 51 | { |
| 52 | attachClient(); |
| 53 | |
| 54 | const QMetaObject* meta = metaObject(); |
| 55 | for (int i = meta->methodOffset(); i < meta->methodCount(); ++i) { |
| 56 | QMetaMethod method = meta->method(i); |
| 57 | |
| 58 | QMetaProperty prop = meta->property(metaObject()->indexOfProperty(QString::fromLocal8Bit(method.name()).prepend('_').toLocal8Bit().constData())); |
| 59 | QCommandLineOption* opt = prop.read(this).value<QCommandLineOption*>(); |
| 60 | |
| 61 | if(!prop.isValid()) { |
| 62 | Log::error(QString("Bug: Method '%1' has no corresponding property assigned").arg(QString::fromLocal8Bit(method.name()))); |
| 63 | continue; |
| 64 | } |
| 65 | |
| 66 | bool result = false; |
| 67 | if(parser.isSet(*opt)) { |
| 68 | // Argument without parameter |
| 69 | if(method.parameterCount() < 1) { |
| 70 | method.invoke(this, Q_RETURN_ARG(bool, result)); |
| 71 | return result; |
| 72 | } |
| 73 | // Argument with parameter |
| 74 | else if(method.parameterCount() == 1 && method.parameterType(0) == QMetaType::QString) { |
| 75 | QString inputValue = parser.value(*opt); |
| 76 | if(!inputValue.isEmpty()) { |
| 77 | method.invoke(this, Q_RETURN_ARG(bool, result), Q_ARG(QString, inputValue)); |
| 78 | return result; |
| 79 | } |
| 80 | } |
| 81 | else { |
| 82 | Log::error(QString("Bug: Invokable method '%1' has wrong function signature for property '%2'").arg(QString::fromLocal8Bit(method.name())).arg(prop.name())); |
| 83 | continue; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | template<typename T> |
| 92 | std::optional<T> handleReply(QDBusPendingReply<T>& reply) { |