Akonadi

collection.h
1 /*
2  Copyright (c) 2006 - 2007 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef AKONADI_COLLECTION_H
8 #define AKONADI_COLLECTION_H
9 
10 #include "akonadicore_export.h"
11 #include "attribute.h"
12 
13 #include <QMetaType>
14 #include <QSharedDataPointer>
15 #include <QDebug>
16 
17 class QUrl;
18 
19 namespace Akonadi
20 {
21 
22 class CachePolicy;
23 class CollectionPrivate;
24 class CollectionStatistics;
25 
63 class AKONADICORE_EXPORT Collection
64 {
65 public:
69  typedef qint64 Id;
70 
75 
79  enum Right {
80  ReadOnly = 0x0,
81  CanChangeItem = 0x1,
82  CanCreateItem = 0x2,
83  CanDeleteItem = 0x4,
84  CanChangeCollection = 0x8,
85  CanCreateCollection = 0x10,
86  CanDeleteCollection = 0x20,
87  CanLinkItem = 0x40,
88  CanUnlinkItem = 0x80,
89  AllRights = (CanChangeItem | CanCreateItem | CanDeleteItem |
90  CanChangeCollection | CanCreateCollection | CanDeleteCollection)
91  };
92  Q_DECLARE_FLAGS(Rights, Right)
93 
94 
97  Collection();
98 
104  explicit Collection(Id id);
105 
109  ~Collection();
110 
114  Collection(const Collection &other);
115 
119  Collection(Collection &&other) noexcept;
120 
124  static Collection fromUrl(const QUrl &url);
125 
129  void setId(Id identifier);
130 
134  Q_REQUIRED_RESULT Id id() const;
135 
139  void setRemoteId(const QString &id);
140 
144  Q_REQUIRED_RESULT QString remoteId() const;
145 
155  void setRemoteRevision(const QString &revision);
156 
163  Q_REQUIRED_RESULT QString remoteRevision() const;
164 
168  Q_REQUIRED_RESULT bool isValid() const;
169 
174  Q_REQUIRED_RESULT bool operator==(const Collection &other) const;
175 
180  Q_REQUIRED_RESULT bool operator!=(const Collection &other) const;
181 
187  Collection &operator=(const Collection &other);
188 
194  Q_REQUIRED_RESULT bool operator<(const Collection &other) const;
195 
202  Q_REQUIRED_RESULT Collection parentCollection() const;
203 
210  Q_REQUIRED_RESULT Collection &parentCollection();
211 
221  void setParentCollection(const Collection &parent);
222 
233  void addAttribute(Attribute *attribute);
234 
238  void removeAttribute(const QByteArray &name);
239 
244  bool hasAttribute(const QByteArray &name) const;
245 
253  Q_REQUIRED_RESULT Attribute::List attributes() const;
254 
258  void clearAttributes();
259 
263  Attribute *attribute(const QByteArray &name);
264  const Attribute *attribute(const QByteArray &name) const;
265 
271  DontCreate
272  };
273 
281  template <typename T>
282  inline T *attribute(CreateOption option = DontCreate);
283 
287  template <typename T>
288  inline const T *attribute() const;
289 
293  template <typename T>
294  inline void removeAttribute();
295 
299  template <typename T>
300  inline bool hasAttribute() const;
301 
305  Q_REQUIRED_RESULT QString name() const;
306 
314  Q_REQUIRED_RESULT QString displayName() const;
315 
321  void setName(const QString &name);
322 
326  Q_REQUIRED_RESULT Rights rights() const;
327 
331  void setRights(Rights rights);
332 
338  Q_REQUIRED_RESULT QStringList contentMimeTypes() const;
339 
343  void setContentMimeTypes(const QStringList &types);
344 
348  Q_REQUIRED_RESULT static Collection root();
349 
353  Q_REQUIRED_RESULT static QString mimeType();
354 
360  Q_REQUIRED_RESULT static QString virtualMimeType();
361 
365  Q_REQUIRED_RESULT QString resource() const;
366 
370  void setResource(const QString &identifier);
371 
375  Q_REQUIRED_RESULT CachePolicy cachePolicy() const;
376 
380  void setCachePolicy(const CachePolicy &policy);
381 
385  Q_REQUIRED_RESULT CollectionStatistics statistics() const;
386 
390  void setStatistics(const CollectionStatistics &statistics);
391 
397  enum UrlType {
398  UrlShort = 0,
399  UrlWithName = 1
400  };
401 
407  Q_REQUIRED_RESULT QUrl url(UrlType type = UrlShort) const;
408 
414  Q_REQUIRED_RESULT bool isVirtual() const;
415 
422  void setVirtual(bool isVirtual);
423 
443  void setEnabled(bool enabled);
444 
450  Q_REQUIRED_RESULT bool enabled() const;
451 
460  ListDefault
461  };
462 
468  enum ListPurpose {
471  ListIndex
472  };
473 
485  void setLocalListPreference(ListPurpose purpose, ListPreference preference);
486 
492  Q_REQUIRED_RESULT ListPreference localListPreference(ListPurpose purpose) const;
493 
501  Q_REQUIRED_RESULT bool shouldList(ListPurpose purpose) const;
502 
513  void setShouldList(ListPurpose purpose, bool shouldList);
514 
519  void setKeepLocalChanges(const QSet<QByteArray> &parts);
520 
524  QSet<QByteArray> keepLocalChanges() const;
525 
526 private:
527  friend class CollectionCreateJob;
528  friend class CollectionFetchJob;
529  friend class CollectionModifyJob;
530  friend class ProtocolHelper;
531 
532  void markAttributeModified(const QByteArray &type);
533 
534  //@cond PRIVATE
536  friend class CollectionPrivate;
537  //@endcond
538 };
539 
540 AKONADICORE_EXPORT uint qHash(const Akonadi::Collection &collection);
541 
542 template <typename T>
544 {
545  const QByteArray type = T().type();
546  markAttributeModified(type); // do this first in case it detaches
547  if (hasAttribute(type)) {
548  if (T *attr = dynamic_cast<T *>(attribute(type))) {
549  return attr;
550  }
551  qWarning() << "Found attribute of unknown type" << type
552  << ". Did you forget to call AttributeFactory::registerAttribute()?";
553  } else if (option == AddIfMissing) {
554  T *attr = new T();
555  addAttribute(attr);
556  return attr;
557  }
558 
559  return nullptr;
560 }
561 
562 template <typename T>
563 inline const T *Akonadi::Collection::attribute() const
564 {
565  const QByteArray type = T().type();
566  if (hasAttribute(type)) {
567  if (const T *attr = dynamic_cast<const T *>(attribute(type))) {
568  return attr;
569  }
570  qWarning() << "Found attribute of unknown type" << type
571  << ". Did you forget to call AttributeFactory::registerAttribute()?";
572  }
573 
574  return nullptr;
575 }
576 
577 template <typename T>
579 {
580  removeAttribute(T().type());
581 }
582 
583 template <typename T>
585 {
586  return hasAttribute(T().type());
587 }
588 
589 } // namespace Akonadi
590 
594 AKONADICORE_EXPORT QDebug operator<<(QDebug d, const Akonadi::Collection &collection);
595 
596 Q_DECLARE_METATYPE(Akonadi::Collection)
597 Q_DECLARE_METATYPE(Akonadi::Collection::List)
598 Q_DECLARE_OPERATORS_FOR_FLAGS(Akonadi::Collection::Rights)
599 Q_DECLARE_TYPEINFO(Akonadi::Collection, Q_MOVABLE_TYPE);
600 
601 #endif
Job that modifies a collection in the Akonadi storage.
ListPreference
Describes the list preference value.
Definition: collection.h:457
void removeAttribute()
Removes and deletes the attribute of the requested type.
Definition: collection.h:578
Provides statistics information of a Collection.
Represents a collection of PIM items.
Definition: collection.h:63
qint64 Id
Describes the unique id type.
Definition: collection.h:69
Job that fetches collections from the Akonadi storage.
CreateOption
Describes the options that can be passed to access attributes.
Definition: collection.h:269
Listing for display to the user.
Definition: collection.h:470
Creates the attribute if it is missing.
Definition: collection.h:270
Provides interface for custom attributes for Entity.
Definition: attribute.h:126
QVector< Collection > List
Describes a list of collections.
Definition: collection.h:74
Disable collection for specified purpose.
Definition: collection.h:459
bool hasAttribute() const
Returns whether the collection has an attribute of the requested type.
Definition: collection.h:584
Enable collection for specified purpose.
Definition: collection.h:458
ListPurpose
Describes the purpose of the listing.
Definition: collection.h:468
UrlType
Describes the type of url which is returned in url().
Definition: collection.h:397
Represents the caching policy for a collection.
Definition: cachepolicy.h:59
KCALENDARCORE_EXPORT uint qHash(const KCalendarCore::Period &key)
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Right
Describes rights of a collection.
Definition: collection.h:79
Helper integration between Akonadi and Qt.
const T * attribute() const
Returns the attribute of the requested type or 0 if it is not available.
Definition: collection.h:563
Job that creates a new collection in the Akonadi storage.
Listing for synchronization.
Definition: collection.h:469
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 3 2020 23:15:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.