File indexing completed on 2024-09-29 12:03:22

0001 /*
0002     This file is part of libkabc.
0003     SPDX-FileCopyrightText: 2015-2019 Laurent Montel <montel@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef IMPP_H
0009 #define IMPP_H
0010 
0011 #include "kcontacts_export.h"
0012 
0013 #include <QMap>
0014 #include <QMetaType>
0015 #include <QSharedDataPointer>
0016 #include <QString>
0017 
0018 class ImppTest;
0019 
0020 namespace KContacts
0021 {
0022 class ParameterMap;
0023 
0024 /** @short Class that holds a IMPP for a contact.
0025  *
0026  *  IMPP stands for "Instant Messaging and Presence Protocol". This field is defined
0027  *  in the vCard 3.0 extension RFC 4770 and is part of vCard 4.0 (RFC 6350).
0028  *
0029  *  @since 4.14.5
0030  */
0031 class KCONTACTS_EXPORT Impp
0032 {
0033     Q_GADGET
0034     Q_PROPERTY(bool isValid READ isValid)
0035     Q_PROPERTY(QUrl address READ address WRITE setAddress)
0036     Q_PROPERTY(bool isPreferred READ isPreferred WRITE setPreferred)
0037     Q_PROPERTY(QString serviceType READ serviceType)
0038     Q_PROPERTY(QString serviceLabel READ serviceLabel)
0039     Q_PROPERTY(QString serviceIcon READ serviceIcon)
0040 
0041     friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const Impp &);
0042     friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, Impp &);
0043     friend class VCardTool;
0044     friend class ::ImppTest;
0045 
0046 public:
0047     Impp();
0048     Impp(const Impp &other);
0049     Impp(const QUrl &address);
0050 
0051     ~Impp();
0052 
0053     typedef QVector<Impp> List;
0054     Q_REQUIRED_RESULT bool isValid() const;
0055 
0056     void setAddress(const QUrl &address);
0057     Q_REQUIRED_RESULT QUrl address() const;
0058 
0059     /**
0060      * Returns the messaging service this address is for.
0061      * This is equivalent to address().scheme().
0062      * @since 5.12
0063      */
0064     QString serviceType() const;
0065     /**
0066      * Returns a translated label for the service type.
0067      * @since 5.12
0068      */
0069     QString serviceLabel() const;
0070     /**
0071      * Returns the name of an icon representing the service type.
0072      * @since 5.12
0073      */
0074     QString serviceIcon() const;
0075 
0076     /**
0077      * Returns whether this is the preferred messaging address.
0078      * @since 5.12
0079      */
0080     bool isPreferred() const;
0081     /**
0082      * Sets that this is the preferred messaging address.
0083      * @since 5.12
0084      */
0085     void setPreferred(bool preferred);
0086 
0087 #if KCONTACTS_ENABLE_DEPRECATED_SINCE(5, 88)
0088     /**
0089      * @deprecated Since 5.88 for lack of usage
0090      */
0091     KCONTACTS_DEPRECATED_VERSION(5, 88, "For lack of usage.")
0092     void setParameters(const QMap<QString, QStringList> &params);
0093 #endif
0094 
0095 #if KCONTACTS_ENABLE_DEPRECATED_SINCE(5, 88)
0096     /**
0097      * @deprecated Since 5.88 for lack of usage
0098      */
0099     Q_REQUIRED_RESULT
0100     KCONTACTS_DEPRECATED_VERSION(5, 88, "For lack of usage.")
0101     QMap<QString, QStringList> parameters() const;
0102 #endif
0103 
0104     Q_REQUIRED_RESULT bool operator==(const Impp &other) const;
0105     Q_REQUIRED_RESULT bool operator!=(const Impp &other) const;
0106 
0107     Impp &operator=(const Impp &other);
0108 
0109     Q_REQUIRED_RESULT QString toString() const;
0110 
0111     /**
0112      * Returns a translated name of the given IM service.
0113      * @since 5.12
0114      */
0115     static QString serviceLabel(const QString &serviceType);
0116     /**
0117      * Returns an icon name representing the given IM service.
0118      * @since 5.12
0119      */
0120     static QString serviceIcon(const QString &serviceType);
0121     /**
0122      * List all known service types.
0123      * Don't use these strings directly for display, instead use serviceLabel and serviceIcon.
0124      * @since 5.12
0125      */
0126     static QVector<QString> serviceTypes();
0127 
0128 private:
0129     // exported for ImppTest
0130     void setParams(const ParameterMap &params);
0131     Q_REQUIRED_RESULT ParameterMap params() const;
0132 
0133     class Private;
0134     QSharedDataPointer<Private> d;
0135 };
0136 
0137 KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const Impp &object);
0138 
0139 KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, Impp &object);
0140 }
0141 
0142 Q_DECLARE_METATYPE(KContacts::Impp)
0143 Q_DECLARE_TYPEINFO(KContacts::Impp, Q_MOVABLE_TYPE);
0144 #endif // IMPP_H