From 46570dd9684990846cfd4c3dc5be71498c5a6278 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 4 Dec 2015 16:40:28 +0100 Subject: example client and properties --- common/domain/mail.cpp | 10 +++++----- common/propertymapper.cpp | 20 ++++++++++++++++++++ common/propertymapper.h | 10 ++++++++++ examples/client/main.cpp | 14 +++++++++----- examples/dummyresource/resourcefactory.cpp | 2 +- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp index 59b75ea..0170357 100644 --- a/common/domain/mail.cpp +++ b/common/domain/mail.cpp @@ -73,10 +73,10 @@ QSharedPointer::Buffer> > TypeImplem propertyMapper->addMapping("sender", &Buffer::sender); propertyMapper->addMapping("senderName", &Buffer::senderName); propertyMapper->addMapping("subject", &Buffer::subject); - propertyMapper->addMapping("date", &Buffer::date); + propertyMapper->addMapping("date", &Buffer::date); propertyMapper->addMapping("unread", &Buffer::unread); propertyMapper->addMapping("important", &Buffer::important); - propertyMapper->addMapping("folder", &Buffer::folder); + propertyMapper->addMapping("folder", &Buffer::folder); return propertyMapper; } @@ -87,9 +87,9 @@ QSharedPointer::BufferBuilder> > Ty propertyMapper->addMapping("sender", &BufferBuilder::add_sender); propertyMapper->addMapping("senderName", &BufferBuilder::add_senderName); propertyMapper->addMapping("subject", &BufferBuilder::add_subject); - propertyMapper->addMapping("date", &BufferBuilder::add_date); - // propertyMapper->addMapping("unread", &BufferBuilder::add_unread); - // propertyMapper->addMapping("important", &BufferBuilder::add_important); + propertyMapper->addMapping("date", &BufferBuilder::add_date); + propertyMapper->addMapping("unread", &BufferBuilder::add_unread); + propertyMapper->addMapping("important", &BufferBuilder::add_important); propertyMapper->addMapping("folder", &BufferBuilder::add_folder); return propertyMapper; } diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index 60f7dd5..17a73cb 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp @@ -18,6 +18,7 @@ */ #include "propertymapper.h" +#include template <> flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) @@ -37,6 +38,15 @@ flatbuffers::uoffset_t variantToProperty(const QVariant &property, f return 0; } +template <> +flatbuffers::uoffset_t variantToProperty(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) +{ + if (property.isValid()) { + return fbb.CreateString(property.toDateTime().toString().toStdString()).o; + } + return 0; +} + template <> QVariant propertyToVariant(const flatbuffers::String *property) { @@ -62,3 +72,13 @@ QVariant propertyToVariant(uint8_t property) { return static_cast(property); } + +template <> +QVariant propertyToVariant(const flatbuffers::String *property) +{ + if (property) { + //We have to copy the memory, otherwise it would become eventually invalid + return QDateTime::fromString(QString::fromStdString(property->c_str())); + } + return QVariant(); +} diff --git a/common/propertymapper.h b/common/propertymapper.h index 98ad397..fbde2d9 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h @@ -99,6 +99,16 @@ public: mWriteAccessors.insert(property, mapping); } + template + void addMapping(const QByteArray &name, void (BufferBuilder::*f)(uint8_t)) + { + addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function { + return [value, f](BufferBuilder &builder) { + (builder.*f)(value.value()); + }; + }); + } + template void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset)) { diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 31947e8..8e1cc80 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -115,7 +115,7 @@ static QSharedPointer loadModel(const QString &type, Akonadi query.requestedProperties << "name" << "parent"; model = Akonadi2::Store::loadModel(query); } else if (type == "mail") { - query.requestedProperties << "subject" << "folder"; + query.requestedProperties << "subject" << "folder" << "date"; model = Akonadi2::Store::loadModel(query); } else if (type == "event") { query.requestedProperties << "summary"; @@ -133,15 +133,19 @@ int main(int argc, char *argv[]) QCommandLineParser cliOptions; cliOptions.addPositionalArgument(QObject::tr("[resource]"), QObject::tr("A resource to connect to")); + cliOptions.addPositionalArgument(QObject::tr("[type]"), + QObject::tr("A type to work with")); cliOptions.addOption(QCommandLineOption("clear")); cliOptions.addOption(QCommandLineOption("debuglevel")); - cliOptions.addOption(QCommandLineOption("type", "type to list", "type")); + // cliOptions.addOption(QCommandLineOption("type", "type to list", "type")); cliOptions.addOption(QCommandLineOption("list")); cliOptions.addOption(QCommandLineOption("count")); cliOptions.addOption(QCommandLineOption("synchronize")); cliOptions.addHelpOption(); cliOptions.process(app); - QStringList resources = cliOptions.positionalArguments(); + QStringList args = cliOptions.positionalArguments(); + auto type = args.takeLast(); + auto resources = args; if (resources.isEmpty()) { resources << "org.kde.dummy.instance1"; } @@ -172,7 +176,6 @@ int main(int argc, char *argv[]) query.processAll = false; query.liveQuery = true; - const auto type = cliOptions.value("type"); qDebug() << "Type: " << type; if (cliOptions.isSet("list")) { @@ -181,8 +184,9 @@ int main(int argc, char *argv[]) qDebug() << "Listing"; std::cout << "\tColumn\t "; for (int i = 0; i < model->columnCount(QModelIndex()); i++) { - std::cout << "\t" << model->headerData(i, Qt::Horizontal).toString().toStdString() << std::endl; + std::cout << "\t" << model->headerData(i, Qt::Horizontal).toString().toStdString(); } + std::cout << std::endl; QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { for (int i = start; i <= end; i++) { std::cout << "\tRow " << model->rowCount() << ":\t "; diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index a084c19..91a1229 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp @@ -179,7 +179,7 @@ void DummyResource::createMail(const QByteArray &ridBuffer, const QMap