1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2015-2025 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
19class ResourceLocatorUrlTest;
20
21namespace KContacts
22{
23class 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 */
33class 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 /*!
63 * \property KContacts::Impp::resourceLabel
64 */
65 Q_PROPERTY(QString resourceLabel READ resourceLabel)
66
67public:
68 /*!
69 */
70 ResourceLocatorUrl();
71
72 ResourceLocatorUrl(const ResourceLocatorUrl &other);
73
74 ~ResourceLocatorUrl();
75
76 /*!
77 */
78 typedef QList<ResourceLocatorUrl> List;
79
80 /*!
81 * URL types.
82 * \since 5.12
83 *
84 * \value Unknown No or unknown URL type is set
85 * \value Home Personal website
86 * \value Work Work website
87 * \value Profile Profile website
88 * \value[since 6.0] Ftp Ftp website
89 * \value[since 6.0] Reservation Reservation website
90 * \value[since 6.0] AppInstallPage Application installation website
91 * \value Other Other website
92 */
93 enum TypeFlag {
94 Unknown = 0,
95 Home = 1,
96 Work = 2,
97 Profile = 4,
98 Ftp = 8,
99 Reservation = 16,
100 AppInstallPage = 32,
101 Other = 64,
102 };
103
104 Q_DECLARE_FLAGS(Type, TypeFlag)
105 Q_FLAG(Type)
106
107 /*!
108 */
109 [[nodiscard]] bool isValid() const;
110
111 /*!
112 */
113 void setUrl(const QUrl &url);
114
115 /*!
116 */
117 [[nodiscard]] QUrl url() const;
118
119 /*!
120 * Returns the type of the URL.
121 * \since 5.12
122 */
123 [[nodiscard]] Type type() const;
124
125 /*!
126 * Sets the URL type.
127 * \since 5.12
128 */
129 void setType(Type type);
130
131 /*!
132 * Returns whether this is the preferred website.
133 * \since 5.12
134 */
135 [[nodiscard]] bool isPreferred() const;
136
137 /*!
138 * Sets that this is the preferred website.
139 * \since 5.12
140 */
141 void setPreferred(bool preferred);
142
143 /*!
144 */
145 [[nodiscard]] bool operator==(const ResourceLocatorUrl &other) const;
146
147 /*!
148 */
149 [[nodiscard]] bool operator!=(const ResourceLocatorUrl &other) const;
150
151 ResourceLocatorUrl &operator=(const ResourceLocatorUrl &other);
152
153 /*!
154 */
155 [[nodiscard]] QString toString() const;
156
157 /*!
158 * Returns a translated label for the type.
159 * \since 6.20
160 */
161 [[nodiscard]] QString resourceLabel() const;
162
163private:
164 // exported for ResourceLocatorUrlTest
165 void setParams(const ParameterMap &params);
166 [[nodiscard]] ParameterMap params() const;
167
168 class Private;
169 QSharedDataPointer<Private> d;
170};
171
172Q_DECLARE_OPERATORS_FOR_FLAGS(ResourceLocatorUrl::Type)
173
174/*!
175 * \relates KContacts::ResourceLocatorUrl
176 */
177KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const ResourceLocatorUrl &object);
178
179/*!
180 * \relates KContacts::ResourceLocatorUrl
181 */
182KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, ResourceLocatorUrl &object);
183}
184
185Q_DECLARE_TYPEINFO(KContacts::ResourceLocatorUrl, Q_RELOCATABLE_TYPE);
186
187#endif // RESOURCELOCATORURL_H
188

source code of kcontacts/src/resourcelocatorurl.h