File indexing completed on 2024-09-15 03:37:17
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 QList<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 Ftp = 8, /**< Ftp website. @since 6.0 */ 0059 Reservation = 16, /**< Reservation website. @since 6.0 */ 0060 AppInstallPage = 32, /**< Application installation website. @sine 6.0 */ 0061 Other = 64, /**< Other websie. */ 0062 }; 0063 0064 /** 0065 * Stores a combination of #TypeFlag values. 0066 */ 0067 Q_DECLARE_FLAGS(Type, TypeFlag) 0068 Q_FLAG(Type) 0069 0070 Q_REQUIRED_RESULT bool isValid() const; 0071 0072 void setUrl(const QUrl &url); 0073 Q_REQUIRED_RESULT QUrl url() const; 0074 0075 /** 0076 * Returns the type of the URL. 0077 * @since 5.12 0078 */ 0079 Type type() const; 0080 /** 0081 * Sets the URL type. 0082 * @since 5.12 0083 */ 0084 void setType(Type type); 0085 0086 /** 0087 * Returns whether this is the preferred website. 0088 * @since 5.12 0089 */ 0090 bool isPreferred() const; 0091 /** 0092 * Sets that this is the preferred website. 0093 * @since 5.12 0094 */ 0095 void setPreferred(bool preferred); 0096 0097 Q_REQUIRED_RESULT bool operator==(const ResourceLocatorUrl &other) const; 0098 Q_REQUIRED_RESULT bool operator!=(const ResourceLocatorUrl &other) const; 0099 0100 ResourceLocatorUrl &operator=(const ResourceLocatorUrl &other); 0101 0102 Q_REQUIRED_RESULT QString toString() const; 0103 0104 private: 0105 // exported for ResourceLocatorUrlTest 0106 void setParams(const ParameterMap ¶ms); 0107 Q_REQUIRED_RESULT ParameterMap params() const; 0108 0109 class Private; 0110 QSharedDataPointer<Private> d; 0111 }; 0112 0113 Q_DECLARE_OPERATORS_FOR_FLAGS(ResourceLocatorUrl::Type) 0114 0115 KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const ResourceLocatorUrl &object); 0116 0117 KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, ResourceLocatorUrl &object); 0118 } 0119 0120 Q_DECLARE_TYPEINFO(KContacts::ResourceLocatorUrl, Q_RELOCATABLE_TYPE); 0121 0122 #endif // RESOURCELOCATORURL_H