diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-04 16:40:28 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-04 16:40:28 +0100 |
commit | 46570dd9684990846cfd4c3dc5be71498c5a6278 (patch) | |
tree | 3dc2369059f795f4be2ff6e2bca84db0c5bde749 | |
parent | 983af5f1442ff27dc14da6fdac28f51a38184f0a (diff) | |
download | sink-46570dd9684990846cfd4c3dc5be71498c5a6278.tar.gz sink-46570dd9684990846cfd4c3dc5be71498c5a6278.zip |
example client and properties
-rw-r--r-- | common/domain/mail.cpp | 10 | ||||
-rw-r--r-- | common/propertymapper.cpp | 20 | ||||
-rw-r--r-- | common/propertymapper.h | 10 | ||||
-rw-r--r-- | examples/client/main.cpp | 14 | ||||
-rw-r--r-- | 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<ReadPropertyMapper<TypeImplementation<Mail>::Buffer> > TypeImplem | |||
73 | propertyMapper->addMapping<QString, Buffer>("sender", &Buffer::sender); | 73 | propertyMapper->addMapping<QString, Buffer>("sender", &Buffer::sender); |
74 | propertyMapper->addMapping<QString, Buffer>("senderName", &Buffer::senderName); | 74 | propertyMapper->addMapping<QString, Buffer>("senderName", &Buffer::senderName); |
75 | propertyMapper->addMapping<QString, Buffer>("subject", &Buffer::subject); | 75 | propertyMapper->addMapping<QString, Buffer>("subject", &Buffer::subject); |
76 | propertyMapper->addMapping<QString, Buffer>("date", &Buffer::date); | 76 | propertyMapper->addMapping<QDateTime, Buffer>("date", &Buffer::date); |
77 | propertyMapper->addMapping<bool, Buffer>("unread", &Buffer::unread); | 77 | propertyMapper->addMapping<bool, Buffer>("unread", &Buffer::unread); |
78 | propertyMapper->addMapping<bool, Buffer>("important", &Buffer::important); | 78 | propertyMapper->addMapping<bool, Buffer>("important", &Buffer::important); |
79 | propertyMapper->addMapping<QString, Buffer>("folder", &Buffer::folder); | 79 | propertyMapper->addMapping<QByteArray, Buffer>("folder", &Buffer::folder); |
80 | return propertyMapper; | 80 | return propertyMapper; |
81 | } | 81 | } |
82 | 82 | ||
@@ -87,9 +87,9 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Mail>::BufferBuilder> > Ty | |||
87 | propertyMapper->addMapping<QString>("sender", &BufferBuilder::add_sender); | 87 | propertyMapper->addMapping<QString>("sender", &BufferBuilder::add_sender); |
88 | propertyMapper->addMapping<QString>("senderName", &BufferBuilder::add_senderName); | 88 | propertyMapper->addMapping<QString>("senderName", &BufferBuilder::add_senderName); |
89 | propertyMapper->addMapping<QString>("subject", &BufferBuilder::add_subject); | 89 | propertyMapper->addMapping<QString>("subject", &BufferBuilder::add_subject); |
90 | propertyMapper->addMapping<QString>("date", &BufferBuilder::add_date); | 90 | propertyMapper->addMapping<QDateTime>("date", &BufferBuilder::add_date); |
91 | // propertyMapper->addMapping<bool>("unread", &BufferBuilder::add_unread); | 91 | propertyMapper->addMapping<bool>("unread", &BufferBuilder::add_unread); |
92 | // propertyMapper->addMapping<bool>("important", &BufferBuilder::add_important); | 92 | propertyMapper->addMapping<bool>("important", &BufferBuilder::add_important); |
93 | propertyMapper->addMapping<QString>("folder", &BufferBuilder::add_folder); | 93 | propertyMapper->addMapping<QString>("folder", &BufferBuilder::add_folder); |
94 | return propertyMapper; | 94 | return propertyMapper; |
95 | } | 95 | } |
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 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include "propertymapper.h" | 20 | #include "propertymapper.h" |
21 | #include <QDateTime> | ||
21 | 22 | ||
22 | template <> | 23 | template <> |
23 | flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | 24 | flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) |
@@ -38,6 +39,15 @@ flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, f | |||
38 | } | 39 | } |
39 | 40 | ||
40 | template <> | 41 | template <> |
42 | flatbuffers::uoffset_t variantToProperty<QDateTime>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | ||
43 | { | ||
44 | if (property.isValid()) { | ||
45 | return fbb.CreateString(property.toDateTime().toString().toStdString()).o; | ||
46 | } | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | template <> | ||
41 | QVariant propertyToVariant<QString>(const flatbuffers::String *property) | 51 | QVariant propertyToVariant<QString>(const flatbuffers::String *property) |
42 | { | 52 | { |
43 | if (property) { | 53 | if (property) { |
@@ -62,3 +72,13 @@ QVariant propertyToVariant<bool>(uint8_t property) | |||
62 | { | 72 | { |
63 | return static_cast<bool>(property); | 73 | return static_cast<bool>(property); |
64 | } | 74 | } |
75 | |||
76 | template <> | ||
77 | QVariant propertyToVariant<QDateTime>(const flatbuffers::String *property) | ||
78 | { | ||
79 | if (property) { | ||
80 | //We have to copy the memory, otherwise it would become eventually invalid | ||
81 | return QDateTime::fromString(QString::fromStdString(property->c_str())); | ||
82 | } | ||
83 | return QVariant(); | ||
84 | } | ||
diff --git a/common/propertymapper.h b/common/propertymapper.h index 98ad397..fbde2d9 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -100,6 +100,16 @@ public: | |||
100 | } | 100 | } |
101 | 101 | ||
102 | template <typename T> | 102 | template <typename T> |
103 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(uint8_t)) | ||
104 | { | ||
105 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | ||
106 | return [value, f](BufferBuilder &builder) { | ||
107 | (builder.*f)(value.value<T>()); | ||
108 | }; | ||
109 | }); | ||
110 | } | ||
111 | |||
112 | template <typename T> | ||
103 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::String>)) | 113 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::String>)) |
104 | { | 114 | { |
105 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | 115 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { |
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<QAbstractItemModel> loadModel(const QString &type, Akonadi | |||
115 | query.requestedProperties << "name" << "parent"; | 115 | query.requestedProperties << "name" << "parent"; |
116 | model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | 116 | model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); |
117 | } else if (type == "mail") { | 117 | } else if (type == "mail") { |
118 | query.requestedProperties << "subject" << "folder"; | 118 | query.requestedProperties << "subject" << "folder" << "date"; |
119 | model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); | 119 | model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); |
120 | } else if (type == "event") { | 120 | } else if (type == "event") { |
121 | query.requestedProperties << "summary"; | 121 | query.requestedProperties << "summary"; |
@@ -133,15 +133,19 @@ int main(int argc, char *argv[]) | |||
133 | QCommandLineParser cliOptions; | 133 | QCommandLineParser cliOptions; |
134 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), | 134 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), |
135 | QObject::tr("A resource to connect to")); | 135 | QObject::tr("A resource to connect to")); |
136 | cliOptions.addPositionalArgument(QObject::tr("[type]"), | ||
137 | QObject::tr("A type to work with")); | ||
136 | cliOptions.addOption(QCommandLineOption("clear")); | 138 | cliOptions.addOption(QCommandLineOption("clear")); |
137 | cliOptions.addOption(QCommandLineOption("debuglevel")); | 139 | cliOptions.addOption(QCommandLineOption("debuglevel")); |
138 | cliOptions.addOption(QCommandLineOption("type", "type to list", "type")); | 140 | // cliOptions.addOption(QCommandLineOption("type", "type to list", "type")); |
139 | cliOptions.addOption(QCommandLineOption("list")); | 141 | cliOptions.addOption(QCommandLineOption("list")); |
140 | cliOptions.addOption(QCommandLineOption("count")); | 142 | cliOptions.addOption(QCommandLineOption("count")); |
141 | cliOptions.addOption(QCommandLineOption("synchronize")); | 143 | cliOptions.addOption(QCommandLineOption("synchronize")); |
142 | cliOptions.addHelpOption(); | 144 | cliOptions.addHelpOption(); |
143 | cliOptions.process(app); | 145 | cliOptions.process(app); |
144 | QStringList resources = cliOptions.positionalArguments(); | 146 | QStringList args = cliOptions.positionalArguments(); |
147 | auto type = args.takeLast(); | ||
148 | auto resources = args; | ||
145 | if (resources.isEmpty()) { | 149 | if (resources.isEmpty()) { |
146 | resources << "org.kde.dummy.instance1"; | 150 | resources << "org.kde.dummy.instance1"; |
147 | } | 151 | } |
@@ -172,7 +176,6 @@ int main(int argc, char *argv[]) | |||
172 | query.processAll = false; | 176 | query.processAll = false; |
173 | query.liveQuery = true; | 177 | query.liveQuery = true; |
174 | 178 | ||
175 | const auto type = cliOptions.value("type"); | ||
176 | qDebug() << "Type: " << type; | 179 | qDebug() << "Type: " << type; |
177 | 180 | ||
178 | if (cliOptions.isSet("list")) { | 181 | if (cliOptions.isSet("list")) { |
@@ -181,8 +184,9 @@ int main(int argc, char *argv[]) | |||
181 | qDebug() << "Listing"; | 184 | qDebug() << "Listing"; |
182 | std::cout << "\tColumn\t "; | 185 | std::cout << "\tColumn\t "; |
183 | for (int i = 0; i < model->columnCount(QModelIndex()); i++) { | 186 | for (int i = 0; i < model->columnCount(QModelIndex()); i++) { |
184 | std::cout << "\t" << model->headerData(i, Qt::Horizontal).toString().toStdString() << std::endl; | 187 | std::cout << "\t" << model->headerData(i, Qt::Horizontal).toString().toStdString(); |
185 | } | 188 | } |
189 | std::cout << std::endl; | ||
186 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | 190 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { |
187 | for (int i = start; i <= end; i++) { | 191 | for (int i = start; i <= end; i++) { |
188 | std::cout << "\tRow " << model->rowCount() << ":\t "; | 192 | 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<QString, | |||
179 | auto subject = m_fbb.CreateString(data.value("subject").toString().toStdString()); | 179 | auto subject = m_fbb.CreateString(data.value("subject").toString().toStdString()); |
180 | auto sender = m_fbb.CreateString(data.value("senderEmail").toString().toStdString()); | 180 | auto sender = m_fbb.CreateString(data.value("senderEmail").toString().toStdString()); |
181 | auto senderName = m_fbb.CreateString(data.value("senderName").toString().toStdString()); | 181 | auto senderName = m_fbb.CreateString(data.value("senderName").toString().toStdString()); |
182 | auto date = m_fbb.CreateString(data.value("date").toDate().toString().toStdString()); | 182 | auto date = m_fbb.CreateString(data.value("date").toDateTime().toString().toStdString()); |
183 | auto folder = m_fbb.CreateString(resolveRemoteId(ENTITY_TYPE_MAIL, data.value("parentFolder").toString(), transaction).toStdString()); | 183 | auto folder = m_fbb.CreateString(resolveRemoteId(ENTITY_TYPE_MAIL, data.value("parentFolder").toString(), transaction).toStdString()); |
184 | 184 | ||
185 | auto builder = Akonadi2::ApplicationDomain::Buffer::MailBuilder(m_fbb); | 185 | auto builder = Akonadi2::ApplicationDomain::Buffer::MailBuilder(m_fbb); |