From f7a42de9bfd6e34f1dc46da433d3f45976b1cd0e Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 15 Feb 2017 16:21:06 +0100 Subject: PropertyParser to properly parse different property types. --- common/CMakeLists.txt | 2 ++ common/domain/applicationdomaintype.cpp | 1 + common/propertyparser.cpp | 29 +++++++++++++++++++++++++++++ common/propertyparser.h | 33 +++++++++++++++++++++++++++++++++ sinksh/syntax_modules/sink_create.cpp | 6 +++--- sinksh/syntax_modules/sink_list.cpp | 6 +++--- sinksh/syntax_modules/sink_modify.cpp | 9 +++++---- 7 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 common/propertyparser.cpp create mode 100644 common/propertyparser.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 92da470..ec437ed 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -60,6 +60,7 @@ set(command_SRCS resourceconfig.cpp configstore.cpp resultset.cpp + domain/propertyregistry.cpp domain/applicationdomaintype.cpp domain/contact.cpp domain/event.cpp @@ -81,6 +82,7 @@ set(command_SRCS notification.cpp commandprocessor.cpp inspector.cpp + propertyparser.cpp ${storage_SRCS}) add_library(${PROJECT_NAME} SHARED ${command_SRCS}) diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 4bd17fe..49bfb5f 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -62,6 +62,7 @@ SINK_REGISTER_PROPERTY(Folder, Name); SINK_REGISTER_PROPERTY(Folder, Icon); SINK_REGISTER_PROPERTY(Folder, SpecialPurpose); SINK_REGISTER_PROPERTY(Folder, Enabled); +SINK_REGISTER_PROPERTY(Folder, Parent); static const int foo = [] { QMetaType::registerEqualsComparator(); diff --git a/common/propertyparser.cpp b/common/propertyparser.cpp new file mode 100644 index 0000000..c638594 --- /dev/null +++ b/common/propertyparser.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2017 Christian Mollekopf + * + * This library 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; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library 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 library. If not, see . + */ +#include "propertyparser.h" + +#include "domain/propertyregistry.h" + +using namespace Sink; + +QVariant PropertyParser::parse(const QByteArray &type, const QByteArray &property, const QString &value) +{ + return Private::PropertyRegistry::instance().parse(type, property, value); +} diff --git a/common/propertyparser.h b/common/propertyparser.h new file mode 100644 index 0000000..f5bda85 --- /dev/null +++ b/common/propertyparser.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2017 Christian Mollekopf + * + * This library 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; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library 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 library. If not, see . + */ +#pragma once + +#include "sink_export.h" +#include + +namespace Sink { + +class SINK_EXPORT PropertyParser { +public: + static QVariant parse(const QByteArray &type, const QByteArray &property, const QString &value); +}; + +} + diff --git a/sinksh/syntax_modules/sink_create.cpp b/sinksh/syntax_modules/sink_create.cpp index 9f5d010..f18a990 100644 --- a/sinksh/syntax_modules/sink_create.cpp +++ b/sinksh/syntax_modules/sink_create.cpp @@ -25,12 +25,11 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" #include "common/definitions.h" +#include "common/propertyparser.h" #include "sinksh_utils.h" #include "state.h" @@ -62,7 +61,8 @@ bool create(const QStringList &allArgs, State &state) auto map = SinkshUtils::keyValueMapFromArgs(args); for (auto i = map.begin(); i != map.end(); ++i) { - object->setProperty(i.key().toLatin1(), i.value()); + const auto property = i.key().toLatin1(); + object->setProperty(property, Sink::PropertyParser::parse(type.toLatin1(), property, i.value())); } auto result = store.create(*object).exec(); diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index 837f60d..d63749b 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp @@ -25,13 +25,12 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" #include "common/definitions.h" #include "common/store.h" +#include "common/propertyparser.h" #include "sinksh_utils.h" #include "state.h" @@ -109,7 +108,8 @@ bool list(const QStringList &args_, State &state) if (options.options.contains("filter")) { for (const auto &f : options.options.value("filter")) { auto filter = f.split("="); - query.filter(filter.at(0).toLatin1(), QVariant::fromValue(Sink::ApplicationDomain::Reference{filter.at(1).toLatin1()})); + const auto property = filter.value(0).toLatin1(); + query.filter(property, Sink::PropertyParser::parse(type.toLatin1(), property, filter.value(1))); } } if (options.options.contains("id")) { diff --git a/sinksh/syntax_modules/sink_modify.cpp b/sinksh/syntax_modules/sink_modify.cpp index 4d637d8..2579550 100644 --- a/sinksh/syntax_modules/sink_modify.cpp +++ b/sinksh/syntax_modules/sink_modify.cpp @@ -25,12 +25,11 @@ #include "common/resource.h" #include "common/storage.h" -#include "common/domain/event.h" -#include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" #include "common/storage.h" #include "common/definitions.h" +#include "common/propertyparser.h" #include "sinksh_utils.h" #include "state.h" @@ -65,7 +64,8 @@ bool modify(const QStringList &args, State &state) auto map = SinkshUtils::keyValueMapFromArgs(args); for (auto i = map.begin(); i != map.end(); ++i) { - object->setProperty(i.key().toLatin1(), i.value()); + const auto property = i.key().toLatin1(); + object->setProperty(property, Sink::PropertyParser::parse(type.toLatin1(), property, i.value())); } auto result = store.modify(*object).exec(); @@ -91,7 +91,8 @@ bool resource(const QStringList &args, State &state) auto map = SinkshUtils::keyValueMapFromArgs(args); for (auto i = map.begin(); i != map.end(); ++i) { - object->setProperty(i.key().toLatin1(), i.value()); + const auto property = i.key().toLatin1(); + object->setProperty(property, Sink::PropertyParser::parse("resource", property, i.value())); } auto result = store.modify(*object).exec(); -- cgit v1.2.3