File indexing completed on 2024-04-21 15:02:48

0001 /*
0002     KPeople
0003     SPDX-FileCopyrightText: 2013 David Edmundson (davidedmundson@kde.org)
0004 
0005     SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #ifndef PERSONDATA_H
0009 #define PERSONDATA_H
0010 
0011 #include <kpeople/kpeople_export.h>
0012 
0013 #include <QObject>
0014 #include <QPixmap>
0015 
0016 #include "global.h"
0017 
0018 namespace KPeople
0019 {
0020 class PersonDataPrivate;
0021 
0022 class PersonData;
0023 
0024 /**
0025  * @brief Allows to query the information about a given person
0026  *
0027  * PersonData exposes the information of a given person (in contrast to everyone
0028  * available, which is done by PersonsModel).
0029  * This class will provide comfortable interfaces so it can be easily adopted
0030  * in any application.
0031  *
0032  * @since 5.8
0033  */
0034 class KPEOPLE_EXPORT PersonData : public QObject
0035 {
0036     Q_OBJECT
0037     Q_PROPERTY(QString name READ name NOTIFY dataChanged)
0038     Q_PROPERTY(QPixmap photo READ photo NOTIFY dataChanged)
0039     Q_PROPERTY(QString presenceIconName READ presenceIconName NOTIFY dataChanged)
0040 
0041     /**
0042      * @returns whether setContactCustomProperty can be called on this contact
0043      *
0044      * @since 5.62
0045      */
0046     Q_PROPERTY(bool isEditable READ isEditable CONSTANT)
0047 
0048 public:
0049     /** Creates a Person object from a given ID.
0050      * The ID can be either a local application specific ID (such as akonadi://?item=15)
0051      * or a kpeople ID in the form kpeople://15
0052      */
0053     PersonData(const QString &id, QObject *parent = nullptr);
0054 
0055     ~PersonData() override;
0056 
0057     /**
0058      * Returns true if this PersonData is mapped to some existing contact
0059      * @since 5.22
0060      */
0061     bool isValid() const;
0062 
0063     /** Returns the person's id */
0064     QString personUri() const;
0065 
0066     /**
0067      * Returns a list of contact ids that identify the PersonData instance.
0068      */
0069     QStringList contactUris() const;
0070 
0071     /**
0072      * @returns the name of the person
0073      */
0074     QString name() const;
0075 
0076     /**
0077      * @returns an icon name that represents the IM status of the person
0078      */
0079     QString presenceIconName() const;
0080 
0081     /**
0082      * @returns a pixmap with the photo of the person, or a default one if not available
0083      */
0084     QPixmap photo() const;
0085 
0086     /**
0087      * @returns the property for a said @p key.
0088      */
0089     Q_SCRIPTABLE QVariant contactCustomProperty(const QString &key) const;
0090 
0091     /**
0092      * Sends a desired @p value for the contact according to the @p key.
0093      * It's not necessarily implemented. The back-end gets to decide whether a property
0094      * can be set or not.
0095      *
0096      * @returns whether the property value was changed
0097      *
0098      * @since 5.62
0099      */
0100     Q_SCRIPTABLE bool setContactCustomProperty(const QString &key, const QVariant &value);
0101 
0102     /**
0103      * Returns the contact's online presence.
0104      */
0105     QString presence() const;
0106 
0107     /**
0108      * Returns the contact's preferred email address.
0109      */
0110     QString email() const;
0111 
0112     /**
0113      * Returns a the url of the picture that represents the contact.
0114      */
0115     QUrl pictureUrl() const;
0116 
0117     /** Returns all groups the person is in. */
0118     QStringList groups() const;
0119 
0120     /** Returns all e-mail addresses from the person. */
0121     QStringList allEmails() const;
0122 
0123     /**
0124      * @returns whether the contact can be edited.
0125      *
0126      * @since 5.62
0127      */
0128     bool isEditable() const;
0129 
0130     //     struct PhoneNumber {
0131     //         QString name;
0132     //         QString number;
0133     //     };
0134     //     QVector<PhoneNumber> phoneNumbers() const { createPhoneNumbers(customProperty("phoneNumbers")); };
0135 
0136 Q_SIGNALS:
0137     /**
0138      * One of the contact sources has changed
0139      */
0140     void dataChanged();
0141 
0142 private Q_SLOTS:
0143     KPEOPLE_NO_EXPORT void onContactChanged();
0144 
0145 private:
0146     Q_DISABLE_COPY(PersonData)
0147     Q_DECLARE_PRIVATE(PersonData)
0148     PersonDataPrivate *d_ptr;
0149 };
0150 }
0151 
0152 #endif // PERSONDATA_H