File indexing completed on 2024-04-21 03:53:33

0001 /*
0002     This file is part of the KContacts framework.
0003     SPDX-FileCopyrightText: 2008 Tobias Koenig <tokoe@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KCONTACTS_CONTACTGROUP_H
0009 #define KCONTACTS_CONTACTGROUP_H
0010 
0011 #include <QList>
0012 #include <QMetaType>
0013 #include <QSharedDataPointer>
0014 
0015 #include "kcontacts_export.h"
0016 
0017 class QString;
0018 
0019 namespace KContacts
0020 {
0021 /**
0022  * @short This class represents a group of contacts.
0023  *
0024  * It can contain two types of contacts, either a reference
0025  * or data.
0026  * The reference entry is just an unique identifier which
0027  * identifies the real contact in the system.
0028  * The data entry contains a name and an email address.
0029  *
0030  * @author Tobias Koenig <tokoe@kde.org>
0031  * @since 4.3
0032  */
0033 class KCONTACTS_EXPORT ContactGroup
0034 {
0035 public:
0036     /**
0037      * This class represents a contact reference
0038      */
0039     class KCONTACTS_EXPORT ContactReference
0040     {
0041     public:
0042         /**
0043          * A list of contact references.
0044          */
0045         typedef QList<ContactReference> List;
0046 
0047         /**
0048          * Creates an empty contact reference.
0049          */
0050         ContactReference();
0051 
0052         /**
0053          * Creates a contact reference from an @p other reference.
0054          */
0055         ContactReference(const ContactReference &other);
0056 
0057         /**
0058          * Creates a contact reference for the given contact @p uid.
0059          */
0060         ContactReference(const QString &uid);
0061 
0062         /**
0063          * Destroys the contact reference.
0064          */
0065         ~ContactReference();
0066 
0067         /**
0068          * Sets the contact uid of the contact reference.
0069          * @param uid identifier of the contact to reference
0070          * @note That is the Akonadi Item ID of the contact that
0071          *       is referenced here.
0072          */
0073         void setUid(const QString &uid);
0074 
0075         /**
0076          * Returns the contact uid of the contact reference.
0077          *
0078          * @note That is the Akonadi Item ID of the contact that
0079          *       is referenced here.
0080          */
0081         Q_REQUIRED_RESULT QString uid() const;
0082 
0083         /**
0084          * Sets the contact gid of the contact reference.
0085          * @param gid globally unique identifier of the contact to reference
0086          * @since 4.12
0087          */
0088         void setGid(const QString &gid);
0089 
0090         /**
0091          * Returns the contact GID of the contact reference.
0092          * @since 4.12
0093          */
0094         Q_REQUIRED_RESULT QString gid() const;
0095 
0096         /**
0097          * Sets the preferred email address.
0098          */
0099         void setPreferredEmail(const QString &email);
0100 
0101         /**
0102          * Returns the preferred email address, or an empty string
0103          * if no preferred email address is set.
0104          */
0105         Q_REQUIRED_RESULT QString preferredEmail() const;
0106 
0107         /**
0108          * Inserts a custom entry.
0109          * If an entry with the same @p key already exists, it is
0110          * overwritten.
0111          *
0112          * @param key The unique key.
0113          * @param value The value.
0114          */
0115         void insertCustom(const QString &key, const QString &value);
0116 
0117         /**
0118          * Removes the custom entry with the given @p key.
0119          */
0120         void removeCustom(const QString &key);
0121 
0122         /**
0123          * Returns the value for the given @p key, or an empty string
0124          * if the entry for that key does not exists.
0125          */
0126         Q_REQUIRED_RESULT QString custom(const QString &key) const;
0127 
0128         /**
0129          * @internal
0130          */
0131         ContactReference &operator=(const ContactReference &other);
0132 
0133         /**
0134          * @internal
0135          */
0136         Q_REQUIRED_RESULT bool operator==(const ContactReference &other) const;
0137 
0138     private:
0139         class ContactReferencePrivate;
0140         QSharedDataPointer<ContactReferencePrivate> d;
0141     };
0142 
0143     /**
0144      * This class represents a contact group reference
0145      */
0146     class KCONTACTS_EXPORT ContactGroupReference
0147     {
0148     public:
0149         /**
0150          * A list of contact group references.
0151          */
0152         typedef QList<ContactGroupReference> List;
0153 
0154         /**
0155          * Creates an empty contact group reference.
0156          */
0157         ContactGroupReference();
0158 
0159         /**
0160          * Creates a contact group reference from an @p other reference.
0161          */
0162         ContactGroupReference(const ContactGroupReference &other);
0163 
0164         /**
0165          * Creates a contact group reference for the given contact group @p uid.
0166          */
0167         ContactGroupReference(const QString &uid);
0168 
0169         /**
0170          * Destroys the contact group reference.
0171          */
0172         ~ContactGroupReference();
0173 
0174         /**
0175          * Sets the contact group uid of the contact group reference.
0176          */
0177         void setUid(const QString &uid);
0178 
0179         /**
0180          * Returns the contact group uid of the contact group reference.
0181          */
0182         QString uid() const;
0183 
0184         /**
0185          * Inserts a custom entry.
0186          * If an entry with the same @p key already exists, it is
0187          * overwritten.
0188          *
0189          * @param key The unique key.
0190          * @param value The value.
0191          */
0192         void insertCustom(const QString &key, const QString &value);
0193 
0194         /**
0195          * Removes the custom entry with the given @p key.
0196          */
0197         void removeCustom(const QString &key);
0198 
0199         /**
0200          * Returns the value for the given @p key, or an empty string
0201          * if the entry for that key does not exists.
0202          */
0203         QString custom(const QString &key) const;
0204 
0205         /**
0206          * @internal
0207          */
0208         ContactGroupReference &operator=(const ContactGroupReference &other);
0209 
0210         /**
0211          * @internal
0212          */
0213         bool operator==(const ContactGroupReference &other) const;
0214 
0215     private:
0216         class ContactGroupReferencePrivate;
0217         QSharedDataPointer<ContactGroupReferencePrivate> d;
0218     };
0219 
0220     /**
0221      * This class represents a contact data object
0222      */
0223     class KCONTACTS_EXPORT Data
0224     {
0225     public:
0226         /**
0227          * A list of contact data.
0228          */
0229         typedef QList<Data> List;
0230 
0231         /**
0232          * Creates an empty contact data object.
0233          */
0234         Data();
0235 
0236         /**
0237          * Creates a contact data object from an @p other data object.
0238          */
0239         Data(const Data &other);
0240 
0241         /**
0242          * Creates a contact data object with the given @p name and @p email address.
0243          */
0244         Data(const QString &name, const QString &email);
0245 
0246         /**
0247          * Destroys the contact data object.
0248          */
0249         ~Data();
0250 
0251         /**
0252          * Sets the @p name of the contact data object.
0253          */
0254         void setName(const QString &name);
0255 
0256         /**
0257          * Returns the name of the contact data object.
0258          */
0259         Q_REQUIRED_RESULT QString name() const;
0260 
0261         /**
0262          * Sets the @p email address of the contact data object.
0263          */
0264         void setEmail(const QString &email);
0265 
0266         /**
0267          * Returns the email address of the contact data object.
0268          */
0269         Q_REQUIRED_RESULT QString email() const;
0270 
0271         /**
0272          * Inserts a custom entry.
0273          * If an entry with the same @p key already exists, it is
0274          * overwritten.
0275          *
0276          * @param key The unique key.
0277          * @param value The value.
0278          */
0279         void insertCustom(const QString &key, const QString &value);
0280 
0281         /**
0282          * Removes the custom entry with the given @p key.
0283          */
0284         void removeCustom(const QString &key);
0285 
0286         /**
0287          * Returns the value for the given @p key, or an empty string
0288          * if the entry for that key does not exists.
0289          */
0290         Q_REQUIRED_RESULT QString custom(const QString &key) const;
0291 
0292         /**
0293          * @internal
0294          */
0295         Data &operator=(const Data &other);
0296 
0297         /**
0298          * @internal
0299          */
0300         Q_REQUIRED_RESULT bool operator==(const Data &other) const;
0301 
0302     private:
0303         class DataPrivate;
0304         QSharedDataPointer<DataPrivate> d;
0305     };
0306 
0307     /**
0308      * A list of contact groups.
0309      */
0310     typedef QList<ContactGroup> List;
0311 
0312     /**
0313      * Creates an empty contact group.
0314      */
0315     ContactGroup();
0316 
0317     /**
0318      * Creates a contact group from an @p other group.
0319      */
0320     ContactGroup(const ContactGroup &other);
0321 
0322     /**
0323      * Creates a contact group with the given name.
0324      */
0325     ContactGroup(const QString &name);
0326 
0327     /**
0328      * Destroys the contact group.
0329      */
0330     ~ContactGroup();
0331 
0332     /**
0333      * Sets the unique @p id of the contact group.
0334      */
0335     void setId(const QString &id);
0336 
0337     /**
0338      * Returns the unique id of the contact group.
0339      */
0340     Q_REQUIRED_RESULT QString id() const;
0341 
0342     /**
0343      * Sets the i18n'd @p name of the contact group.
0344      */
0345     void setName(const QString &name);
0346 
0347     /**
0348      * Returns the i18n'd name of the contact group.
0349      */
0350     Q_REQUIRED_RESULT QString name() const;
0351 
0352     /**
0353      * Returns the number of contacts in this group.
0354      * That includes the contact references and contact data.
0355      */
0356     Q_REQUIRED_RESULT int count() const;
0357 
0358     /**
0359      * Returns the number of contact references in this group.
0360      */
0361     Q_REQUIRED_RESULT int contactReferenceCount() const;
0362 
0363     /**
0364      * Returns the number of group references in this group.
0365      */
0366     Q_REQUIRED_RESULT int contactGroupReferenceCount() const;
0367 
0368     /**
0369      * Returns the number of contact data objects in this group.
0370      */
0371     Q_REQUIRED_RESULT int dataCount() const;
0372 
0373     /**
0374      * Returns the contact reference at the given @p index.
0375      */
0376     Q_REQUIRED_RESULT ContactReference &contactReference(int index);
0377 
0378     /**
0379      * Returns the contact reference at the given @p index.
0380      */
0381     const ContactReference &contactReference(int index) const;
0382 
0383     /**
0384      * Returns the contact group reference at the given @p index.
0385      */
0386     ContactGroupReference &contactGroupReference(int index);
0387 
0388     /**
0389      * Returns the contact group reference at the given @p index.
0390      */
0391     const ContactGroupReference &contactGroupReference(int index) const;
0392 
0393     /**
0394      * Returns the contact data object at the given @p index.
0395      */
0396     Data &data(int index);
0397 
0398     /**
0399      * Returns the contact data object at the given @p index.
0400      */
0401     const Data &data(int index) const;
0402 
0403     /**
0404      * Appends a new contact @p reference to the contact group.
0405      */
0406     void append(const ContactReference &reference);
0407 
0408     /**
0409      * Appends a new contact group @p reference to the contact group.
0410      */
0411     void append(const ContactGroupReference &reference);
0412 
0413     /**
0414      * Appends a new contact @p data object to the contact group.
0415      */
0416     void append(const Data &data);
0417 
0418     /**
0419      * Removes the given contact @p reference from the contact group.
0420      */
0421     void remove(const ContactReference &reference);
0422 
0423     /**
0424      * Removes the given contact group @p reference from the contact group.
0425      */
0426     void remove(const ContactGroupReference &reference);
0427 
0428     /**
0429      * Removes the given contact @p data object from the contact group.
0430      */
0431     void remove(const Data &data);
0432 
0433     /**
0434      * Removes all contact references from the contact group.
0435      */
0436     void removeAllContactReferences();
0437 
0438     /**
0439      * Removes all contact group references from the contact group.
0440      */
0441     void removeAllContactGroupReferences();
0442 
0443     /**
0444      * Removes all contact data from the contact group.
0445      */
0446     void removeAllContactData();
0447 
0448     /**
0449      * @internal
0450      */
0451     ContactGroup &operator=(const ContactGroup &other);
0452 
0453     /**
0454      * @internal
0455      */
0456     Q_REQUIRED_RESULT bool operator==(const ContactGroup &other) const;
0457 
0458     /**
0459      * Returns the MIME type used for Contact Groups
0460      */
0461     static QString mimeType();
0462 
0463 private:
0464     class Private;
0465     QSharedDataPointer<Private> d;
0466 };
0467 }
0468 Q_DECLARE_TYPEINFO(KContacts::ContactGroup::ContactGroupReference, Q_RELOCATABLE_TYPE);
0469 Q_DECLARE_TYPEINFO(KContacts::ContactGroup::ContactReference, Q_RELOCATABLE_TYPE);
0470 
0471 #define KCONTACTS_CONTACTGROUP_METATYPE_DEFINED
0472 Q_DECLARE_METATYPE(KContacts::ContactGroup)
0473 
0474 #endif