summaryrefslogtreecommitdiffstats
path: root/common/clientapi.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-09 14:00:26 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-09 14:00:26 +0200
commit3062983d075761c457249b8c3c1248aa0d45e46a (patch)
tree9ff6d0956d3ad77a53f465eb7897e500edad2b8a /common/clientapi.h
parentf10d223559b16c576093eea080dc0d5638ab3323 (diff)
downloadsink-3062983d075761c457249b8c3c1248aa0d45e46a.tar.gz
sink-3062983d075761c457249b8c3c1248aa0d45e46a.zip
Use QByteArray instead of QString
All identifiers should be latin1 and we make this explicit by using QByteArray. QString is reserved for strings that can be UTF-8 or alike.
Diffstat (limited to 'common/clientapi.h')
-rw-r--r--common/clientapi.h66
1 files changed, 33 insertions, 33 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index 0ee934c..37fb185 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -180,9 +180,9 @@ namespace Domain {
180class BufferAdaptor { 180class BufferAdaptor {
181public: 181public:
182 virtual ~BufferAdaptor() {} 182 virtual ~BufferAdaptor() {}
183 virtual QVariant getProperty(const QString &key) const { return QVariant(); } 183 virtual QVariant getProperty(const QByteArray &key) const { return QVariant(); }
184 virtual void setProperty(const QString &key, const QVariant &value) {} 184 virtual void setProperty(const QByteArray &key, const QVariant &value) {}
185 virtual QStringList availableProperties() const { return QStringList(); } 185 virtual QList<QByteArray> availableProperties() const { return QList<QByteArray>(); }
186}; 186};
187 187
188class MemoryBufferAdaptor : public BufferAdaptor { 188class MemoryBufferAdaptor : public BufferAdaptor {
@@ -202,12 +202,12 @@ public:
202 202
203 virtual ~MemoryBufferAdaptor() {} 203 virtual ~MemoryBufferAdaptor() {}
204 204
205 virtual QVariant getProperty(const QString &key) const { return mValues.value(key); } 205 virtual QVariant getProperty(const QByteArray &key) const { return mValues.value(key); }
206 virtual void setProperty(const QString &key, const QVariant &value) { mValues.insert(key, value); } 206 virtual void setProperty(const QByteArray &key, const QVariant &value) { mValues.insert(key, value); }
207 virtual QStringList availableProperties() const { return mValues.keys(); } 207 virtual QByteArrayList availableProperties() const { return mValues.keys(); }
208 208
209private: 209private:
210 QHash<QString, QVariant> mValues; 210 QHash<QByteArray, QVariant> mValues;
211}; 211};
212 212
213/** 213/**
@@ -222,7 +222,7 @@ public:
222 { 222 {
223 223
224 } 224 }
225 AkonadiDomainType(const QString &resourceName, const QString &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor) 225 AkonadiDomainType(const QByteArray &resourceName, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor)
226 : mAdaptor(adaptor), 226 : mAdaptor(adaptor),
227 mResourceName(resourceName), 227 mResourceName(resourceName),
228 mIdentifier(identifier), 228 mIdentifier(identifier),
@@ -232,17 +232,17 @@ public:
232 232
233 virtual ~AkonadiDomainType() {} 233 virtual ~AkonadiDomainType() {}
234 234
235 virtual QVariant getProperty(const QString &key) const { return mAdaptor->getProperty(key); } 235 virtual QVariant getProperty(const QByteArray &key) const { return mAdaptor->getProperty(key); }
236 virtual void setProperty(const QString &key, const QVariant &value){ mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); } 236 virtual void setProperty(const QByteArray &key, const QVariant &value){ mChangeSet.insert(key, value); mAdaptor->setProperty(key, value); }
237 237
238private: 238private:
239 QSharedPointer<BufferAdaptor> mAdaptor; 239 QSharedPointer<BufferAdaptor> mAdaptor;
240 QHash<QString, QVariant> mChangeSet; 240 QHash<QByteArray, QVariant> mChangeSet;
241 /* 241 /*
242 * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. 242 * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location.
243 */ 243 */
244 QString mResourceName; 244 QString mResourceName;
245 QString mIdentifier; 245 QByteArray mIdentifier;
246 qint64 mRevision; 246 qint64 mRevision;
247}; 247};
248 248
@@ -274,13 +274,13 @@ class Folder : public AkonadiDomainType {
274 */ 274 */
275 275
276template<class DomainType> 276template<class DomainType>
277QString getTypeName(); 277QByteArray getTypeName();
278 278
279template<> 279template<>
280QString getTypeName<Event>(); 280QByteArray getTypeName<Event>();
281 281
282template<> 282template<>
283QString getTypeName<Todo>(); 283QByteArray getTypeName<Todo>();
284 284
285} 285}
286 286
@@ -307,13 +307,13 @@ class Query
307public: 307public:
308 Query() : syncOnDemand(true), processAll(false) {} 308 Query() : syncOnDemand(true), processAll(false) {}
309 //Could also be a propertyFilter 309 //Could also be a propertyFilter
310 QStringList resources; 310 QByteArrayList resources;
311 //Could also be a propertyFilter 311 //Could also be a propertyFilter
312 QStringList ids; 312 QByteArrayList ids;
313 //Filters to apply 313 //Filters to apply
314 QHash<QString, QVariant> propertyFilter; 314 QHash<QByteArray, QVariant> propertyFilter;
315 //Properties to retrieve 315 //Properties to retrieve
316 QSet<QString> requestedProperties; 316 QSet<QByteArray> requestedProperties;
317 bool syncOnDemand; 317 bool syncOnDemand;
318 bool processAll; 318 bool processAll;
319}; 319};
@@ -331,7 +331,7 @@ template<class DomainType>
331class StoreFacade { 331class StoreFacade {
332public: 332public:
333 virtual ~StoreFacade(){}; 333 virtual ~StoreFacade(){};
334 QString type() const { return Domain::getTypeName<DomainType>(); } 334 QByteArray type() const { return Domain::getTypeName<DomainType>(); }
335 virtual Async::Job<void> create(const DomainType &domainObject) = 0; 335 virtual Async::Job<void> create(const DomainType &domainObject) = 0;
336 virtual Async::Job<void> modify(const DomainType &domainObject) = 0; 336 virtual Async::Job<void> modify(const DomainType &domainObject) = 0;
337 virtual Async::Job<void> remove(const DomainType &domainObject) = 0; 337 virtual Async::Job<void> remove(const DomainType &domainObject) = 0;
@@ -354,15 +354,15 @@ public:
354 return factory; 354 return factory;
355 } 355 }
356 356
357 static QString key(const QString &resource, const QString &type) 357 static QByteArray key(const QByteArray &resource, const QByteArray &type)
358 { 358 {
359 return resource + type; 359 return resource + type;
360 } 360 }
361 361
362 template<class DomainType, class Facade> 362 template<class DomainType, class Facade>
363 void registerFacade(const QString &resource) 363 void registerFacade(const QByteArray &resource)
364 { 364 {
365 const QString typeName = Domain::getTypeName<DomainType>(); 365 const QByteArray typeName = Domain::getTypeName<DomainType>();
366 mFacadeRegistry.insert(key(resource, typeName), [](){ return new Facade; }); 366 mFacadeRegistry.insert(key(resource, typeName), [](){ return new Facade; });
367 } 367 }
368 368
@@ -376,16 +376,16 @@ public:
376 * FIXME the factory function should really be returning QSharedPointer<void>, which doesn't work (std::shared_pointer<void> would though). That way i.e. a test could keep the object alive until it's done. 376 * FIXME the factory function should really be returning QSharedPointer<void>, which doesn't work (std::shared_pointer<void> would though). That way i.e. a test could keep the object alive until it's done.
377 */ 377 */
378 template<class DomainType, class Facade> 378 template<class DomainType, class Facade>
379 void registerFacade(const QString &resource, const std::function<void*(void)> &customFactoryFunction) 379 void registerFacade(const QByteArray &resource, const std::function<void*(void)> &customFactoryFunction)
380 { 380 {
381 const QString typeName = Domain::getTypeName<DomainType>(); 381 const QByteArray typeName = Domain::getTypeName<DomainType>();
382 mFacadeRegistry.insert(key(resource, typeName), customFactoryFunction); 382 mFacadeRegistry.insert(key(resource, typeName), customFactoryFunction);
383 } 383 }
384 384
385 template<class DomainType> 385 template<class DomainType>
386 QSharedPointer<StoreFacade<DomainType> > getFacade(const QString &resource) 386 QSharedPointer<StoreFacade<DomainType> > getFacade(const QByteArray &resource)
387 { 387 {
388 const QString typeName = Domain::getTypeName<DomainType>(); 388 const QByteArray typeName = Domain::getTypeName<DomainType>();
389 auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); 389 auto factoryFunction = mFacadeRegistry.value(key(resource, typeName));
390 if (factoryFunction) { 390 if (factoryFunction) {
391 return QSharedPointer<StoreFacade<DomainType> >(static_cast<StoreFacade<DomainType>* >(factoryFunction())); 391 return QSharedPointer<StoreFacade<DomainType> >(static_cast<StoreFacade<DomainType>* >(factoryFunction()));
@@ -395,7 +395,7 @@ public:
395 } 395 }
396 396
397private: 397private:
398 QHash<QString, std::function<void*(void)> > mFacadeRegistry; 398 QHash<QByteArray, std::function<void*(void)> > mFacadeRegistry;
399}; 399};
400 400
401/** 401/**
@@ -424,7 +424,7 @@ public:
424 // query tells us in which resources we're interested 424 // query tells us in which resources we're interested
425 // TODO: queries to individual resources could be parallelized 425 // TODO: queries to individual resources could be parallelized
426 Async::Job<void> job = Async::null<void>(); 426 Async::Job<void> job = Async::null<void>();
427 for(const QString &resource : query.resources) { 427 for(const QByteArray &resource : query.resources) {
428 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); 428 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource);
429 //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive. 429 //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive.
430 std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); 430 std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1);
@@ -463,7 +463,7 @@ public:
463 */ 463 */
464 //TODO return job that tracks progress until resource has stored the message in it's queue? 464 //TODO return job that tracks progress until resource has stored the message in it's queue?
465 template <class DomainType> 465 template <class DomainType>
466 static void create(const DomainType &domainObject, const QString &resourceIdentifier) { 466 static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
467 //Potentially move to separate thread as well 467 //Potentially move to separate thread as well
468 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); 468 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier);
469 auto job = facade->create(domainObject); 469 auto job = facade->create(domainObject);
@@ -478,7 +478,7 @@ public:
478 * This includes moving etc. since these are also simple settings on a property. 478 * This includes moving etc. since these are also simple settings on a property.
479 */ 479 */
480 template <class DomainType> 480 template <class DomainType>
481 static void modify(const DomainType &domainObject, const QString &resourceIdentifier) { 481 static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
482 //Potentially move to separate thread as well 482 //Potentially move to separate thread as well
483 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); 483 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier);
484 facade.modify(domainObject); 484 facade.modify(domainObject);
@@ -488,13 +488,13 @@ public:
488 * Remove an entity. 488 * Remove an entity.
489 */ 489 */
490 template <class DomainType> 490 template <class DomainType>
491 static void remove(const DomainType &domainObject, const QString &resourceIdentifier) { 491 static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
492 //Potentially move to separate thread as well 492 //Potentially move to separate thread as well
493 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); 493 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier);
494 facade.remove(domainObject); 494 facade.remove(domainObject);
495 } 495 }
496 496
497 static void shutdown(const QString &resourceIdentifier); 497 static void shutdown(const QByteArray &resourceIdentifier);
498}; 498};
499 499
500} 500}