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 | /*! |
26 | * \class KContacts::ResourceLocatorUrl |
27 | * \inheaderfile KContacts/ResourceLocatorUrl |
28 | * \inmodule KContacts |
29 | * |
30 | * \brief Class that holds a Resource Locator. |
31 | * \since 5.0 |
32 | */ |
33 | class KCONTACTS_EXPORT ResourceLocatorUrl |
34 | { |
35 | friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const ResourceLocatorUrl &); |
36 | friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, ResourceLocatorUrl &); |
37 | friend class VCardTool; |
38 | friend class ::ResourceLocatorUrlTest; |
39 | |
40 | Q_GADGET |
41 | |
42 | /*! |
43 | * \property KContacts::ResourceLocatorUrl::url |
44 | */ |
45 | Q_PROPERTY(QUrl url READ url WRITE setUrl) |
46 | |
47 | /*! |
48 | * \property KContacts::ResourceLocatorUrl::isValid |
49 | */ |
50 | Q_PROPERTY(bool isValid READ isValid) |
51 | |
52 | /*! |
53 | * \property KContacts::ResourceLocatorUrl::type |
54 | */ |
55 | Q_PROPERTY(Type type READ type WRITE setType) |
56 | |
57 | /*! |
58 | * \property KContacts::ResourceLocatorUrl::isPreferred |
59 | */ |
60 | Q_PROPERTY(bool isPreferred READ isPreferred WRITE setPreferred) |
61 | |
62 | public: |
63 | /*! |
64 | */ |
65 | ResourceLocatorUrl(); |
66 | |
67 | ResourceLocatorUrl(const ResourceLocatorUrl &other); |
68 | |
69 | ~ResourceLocatorUrl(); |
70 | |
71 | /*! |
72 | */ |
73 | typedef QList<ResourceLocatorUrl> List; |
74 | |
75 | /*! |
76 | * URL types. |
77 | * \since 5.12 |
78 | * |
79 | * \value Unknown No or unknown URL type is set |
80 | * \value Home Personal website |
81 | * \value Work Work website |
82 | * \value Profile Profile website |
83 | * \value[since 6.0] Ftp Ftp website |
84 | * \value[since 6.0] Reservation Reservation website |
85 | * \value[since 6.0] AppInstallPage Application installation website |
86 | * \value Other Other website |
87 | */ |
88 | enum TypeFlag { |
89 | Unknown = 0, |
90 | Home = 1, |
91 | Work = 2, |
92 | Profile = 4, |
93 | Ftp = 8, |
94 | Reservation = 16, |
95 | AppInstallPage = 32, |
96 | Other = 64, |
97 | }; |
98 | |
99 | Q_DECLARE_FLAGS(Type, TypeFlag) |
100 | Q_FLAG(Type) |
101 | |
102 | /*! |
103 | */ |
104 | Q_REQUIRED_RESULT bool isValid() const; |
105 | |
106 | /*! |
107 | */ |
108 | void setUrl(const QUrl &url); |
109 | |
110 | /*! |
111 | */ |
112 | Q_REQUIRED_RESULT QUrl url() const; |
113 | |
114 | /*! |
115 | * Returns the type of the URL. |
116 | * \since 5.12 |
117 | */ |
118 | Type type() const; |
119 | |
120 | /*! |
121 | * Sets the URL type. |
122 | * \since 5.12 |
123 | */ |
124 | void setType(Type type); |
125 | |
126 | /*! |
127 | * Returns whether this is the preferred website. |
128 | * \since 5.12 |
129 | */ |
130 | bool isPreferred() const; |
131 | |
132 | /*! |
133 | * Sets that this is the preferred website. |
134 | * \since 5.12 |
135 | */ |
136 | void setPreferred(bool preferred); |
137 | |
138 | /*! |
139 | */ |
140 | Q_REQUIRED_RESULT bool operator==(const ResourceLocatorUrl &other) const; |
141 | |
142 | /*! |
143 | */ |
144 | Q_REQUIRED_RESULT bool operator!=(const ResourceLocatorUrl &other) const; |
145 | |
146 | ResourceLocatorUrl &operator=(const ResourceLocatorUrl &other); |
147 | |
148 | /*! |
149 | */ |
150 | Q_REQUIRED_RESULT QString toString() const; |
151 | |
152 | private: |
153 | // exported for ResourceLocatorUrlTest |
154 | void setParams(const ParameterMap ¶ms); |
155 | Q_REQUIRED_RESULT ParameterMap params() const; |
156 | |
157 | class Private; |
158 | QSharedDataPointer<Private> d; |
159 | }; |
160 | |
161 | Q_DECLARE_OPERATORS_FOR_FLAGS(ResourceLocatorUrl::Type) |
162 | |
163 | /*! |
164 | * \relates KContacts::ResourceLocatorUrl |
165 | */ |
166 | KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const ResourceLocatorUrl &object); |
167 | |
168 | /*! |
169 | * \relates KContacts::ResourceLocatorUrl |
170 | */ |
171 | KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, ResourceLocatorUrl &object); |
172 | } |
173 | |
174 | Q_DECLARE_TYPEINFO(KContacts::ResourceLocatorUrl, Q_RELOCATABLE_TYPE); |
175 | |
176 | #endif // RESOURCELOCATORURL_H |
177 | |