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

0001 /*
0002     This file is part of the KContacts framework.
0003     SPDX-FileCopyrightText: 2015-2019 Laurent Montel <montel@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef RESOURCELOCATORURL_H
0009 #define RESOURCELOCATORURL_H
0010 
0011 #include "kcontacts_export.h"
0012 
0013 #include <QMap>
0014 #include <QMetaType>
0015 #include <QSharedDataPointer>
0016 #include <QString>
0017 #include <QUrl>
0018 
0019 class ResourceLocatorUrlTest;
0020 
0021 namespace KContacts
0022 {
0023 class ParameterMap;
0024 
0025 /** @short Class that holds a Resource Locator
0026  *  @since 5.0
0027  */
0028 class KCONTACTS_EXPORT ResourceLocatorUrl
0029 {
0030     friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const ResourceLocatorUrl &);
0031     friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, ResourceLocatorUrl &);
0032     friend class VCardTool;
0033     friend class ::ResourceLocatorUrlTest;
0034 
0035     Q_GADGET
0036     Q_PROPERTY(QUrl url READ url WRITE setUrl)
0037     Q_PROPERTY(bool isValid READ isValid)
0038     Q_PROPERTY(Type type READ type WRITE setType)
0039     Q_PROPERTY(bool isPreferred READ isPreferred WRITE setPreferred)
0040 
0041 public:
0042     ResourceLocatorUrl();
0043     ResourceLocatorUrl(const ResourceLocatorUrl &other);
0044 
0045     ~ResourceLocatorUrl();
0046 
0047     typedef QVector<ResourceLocatorUrl> List;
0048 
0049     /** URL types.
0050      *  @since 5.12
0051      *  @see Type
0052      */
0053     enum TypeFlag {
0054         Unknown = 0, /**< No or unknown URL type is set. */
0055         Home = 1, /**< Personal website. */
0056         Work = 2, /**< Work website. */
0057         Profile = 4, /**< Profile website. */
0058         Other = 8, /**< Other websie. */
0059     };
0060 
0061     /**
0062      * Stores a combination of #TypeFlag values.
0063      */
0064     Q_DECLARE_FLAGS(Type, TypeFlag)
0065     Q_FLAG(Type)
0066 
0067     Q_REQUIRED_RESULT bool isValid() const;
0068 
0069     void setUrl(const QUrl &url);
0070     Q_REQUIRED_RESULT QUrl url() const;
0071 
0072     /**
0073      * Returns the type of the URL.
0074      * @since 5.12
0075      */
0076     Type type() const;
0077     /**
0078      * Sets the URL type.
0079      * @since 5.12
0080      */
0081     void setType(Type type);
0082 
0083     /**
0084      * Returns whether this is the preferred website.
0085      * @since 5.12
0086      */
0087     bool isPreferred() const;
0088     /**
0089      * Sets that this is the preferred website.
0090      * @since 5.12
0091      */
0092     void setPreferred(bool preferred);
0093 
0094 #if KCONTACTS_ENABLE_DEPRECATED_SINCE(5, 88)
0095     /**
0096      * @deprecated Since 5.88 for lack of usage
0097      */
0098     KCONTACTS_DEPRECATED_VERSION(5, 88, "For lack of usage.")
0099     void setParameters(const QMap<QString, QStringList> &params);
0100 #endif
0101 
0102 #if KCONTACTS_ENABLE_DEPRECATED_SINCE(5, 88)
0103     /**
0104      * @deprecated Since 5.88 for lack of usage
0105      */
0106     Q_REQUIRED_RESULT
0107     KCONTACTS_DEPRECATED_VERSION(5, 88, "For lack of usage.")
0108     QMap<QString, QStringList> parameters() const;
0109 #endif
0110 
0111     Q_REQUIRED_RESULT bool operator==(const ResourceLocatorUrl &other) const;
0112     Q_REQUIRED_RESULT bool operator!=(const ResourceLocatorUrl &other) const;
0113 
0114     ResourceLocatorUrl &operator=(const ResourceLocatorUrl &other);
0115 
0116     Q_REQUIRED_RESULT QString toString() const;
0117 
0118 private:
0119     // exported for ResourceLocatorUrlTest
0120     void setParams(const ParameterMap &params);
0121     Q_REQUIRED_RESULT ParameterMap params() const;
0122 
0123     class Private;
0124     QSharedDataPointer<Private> d;
0125 };
0126 
0127 Q_DECLARE_OPERATORS_FOR_FLAGS(ResourceLocatorUrl::Type)
0128 
0129 KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const ResourceLocatorUrl &object);
0130 
0131 KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, ResourceLocatorUrl &object);
0132 }
0133 Q_DECLARE_METATYPE(KContacts::ResourceLocatorUrl)
0134 Q_DECLARE_TYPEINFO(KContacts::ResourceLocatorUrl, Q_MOVABLE_TYPE);
0135 
0136 #endif // RESOURCELOCATORURL_H