1 | /* |
2 | This file is part of the KContacts framework. |
3 | SPDX-FileCopyrightText: 2015-2019 Laurent Montel <montel@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef RESOURCELOCATORURL_H |
9 | #define RESOURCELOCATORURL_H |
10 | |
11 | #include "kcontacts_export.h" |
12 | |
13 | #include <QMap> |
14 | #include <QMetaType> |
15 | #include <QSharedDataPointer> |
16 | #include <QString> |
17 | #include <QUrl> |
18 | |
19 | class ResourceLocatorUrlTest; |
20 | |
21 | namespace KContacts |
22 | { |
23 | class ParameterMap; |
24 | |
25 | /** @short Class that holds a Resource Locator |
26 | * @since 5.0 |
27 | */ |
28 | class KCONTACTS_EXPORT ResourceLocatorUrl |
29 | { |
30 | friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const ResourceLocatorUrl &); |
31 | friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, ResourceLocatorUrl &); |
32 | friend class VCardTool; |
33 | friend class ::ResourceLocatorUrlTest; |
34 | |
35 | Q_GADGET |
36 | Q_PROPERTY(QUrl url READ url WRITE setUrl) |
37 | Q_PROPERTY(bool isValid READ isValid) |
38 | Q_PROPERTY(Type type READ type WRITE setType) |
39 | Q_PROPERTY(bool isPreferred READ isPreferred WRITE setPreferred) |
40 | |
41 | public: |
42 | ResourceLocatorUrl(); |
43 | ResourceLocatorUrl(const ResourceLocatorUrl &other); |
44 | |
45 | ~ResourceLocatorUrl(); |
46 | |
47 | typedef QList<ResourceLocatorUrl> List; |
48 | |
49 | /** URL types. |
50 | * @since 5.12 |
51 | * @see Type |
52 | */ |
53 | enum TypeFlag { |
54 | Unknown = 0, /**< No or unknown URL type is set. */ |
55 | Home = 1, /**< Personal website. */ |
56 | Work = 2, /**< Work website. */ |
57 | Profile = 4, /**< Profile website. */ |
58 | Ftp = 8, /**< Ftp website. @since 6.0 */ |
59 | Reservation = 16, /**< Reservation website. @since 6.0 */ |
60 | AppInstallPage = 32, /**< Application installation website. @sine 6.0 */ |
61 | Other = 64, /**< Other websie. */ |
62 | }; |
63 | |
64 | /** |
65 | * Stores a combination of #TypeFlag values. |
66 | */ |
67 | Q_DECLARE_FLAGS(Type, TypeFlag) |
68 | Q_FLAG(Type) |
69 | |
70 | Q_REQUIRED_RESULT bool isValid() const; |
71 | |
72 | void setUrl(const QUrl &url); |
73 | Q_REQUIRED_RESULT QUrl url() const; |
74 | |
75 | /** |
76 | * Returns the type of the URL. |
77 | * @since 5.12 |
78 | */ |
79 | Type type() const; |
80 | /** |
81 | * Sets the URL type. |
82 | * @since 5.12 |
83 | */ |
84 | void setType(Type type); |
85 | |
86 | /** |
87 | * Returns whether this is the preferred website. |
88 | * @since 5.12 |
89 | */ |
90 | bool isPreferred() const; |
91 | /** |
92 | * Sets that this is the preferred website. |
93 | * @since 5.12 |
94 | */ |
95 | void setPreferred(bool preferred); |
96 | |
97 | Q_REQUIRED_RESULT bool operator==(const ResourceLocatorUrl &other) const; |
98 | Q_REQUIRED_RESULT bool operator!=(const ResourceLocatorUrl &other) const; |
99 | |
100 | ResourceLocatorUrl &operator=(const ResourceLocatorUrl &other); |
101 | |
102 | Q_REQUIRED_RESULT QString toString() const; |
103 | |
104 | private: |
105 | // exported for ResourceLocatorUrlTest |
106 | void setParams(const ParameterMap ¶ms); |
107 | Q_REQUIRED_RESULT ParameterMap params() const; |
108 | |
109 | class Private; |
110 | QSharedDataPointer<Private> d; |
111 | }; |
112 | |
113 | Q_DECLARE_OPERATORS_FOR_FLAGS(ResourceLocatorUrl::Type) |
114 | |
115 | KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const ResourceLocatorUrl &object); |
116 | |
117 | KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, ResourceLocatorUrl &object); |
118 | } |
119 | |
120 | Q_DECLARE_TYPEINFO(KContacts::ResourceLocatorUrl, Q_RELOCATABLE_TYPE); |
121 | |
122 | #endif // RESOURCELOCATORURL_H |
123 | |