KContacts

phonenumber.h
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2001 Cornelius Schumacher <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KCONTACTS_PHONENUMBER_H
9 #define KCONTACTS_PHONENUMBER_H
10 
11 #include "kcontacts_export.h"
12 
13 #include <QMap>
14 #include <QMetaType>
15 #include <QSharedDataPointer>
16 #include <QString>
17 #include <QVector>
18 
19 namespace KContacts
20 {
21 /**
22  * @short Phonenumber information.
23  *
24  * This class provides phone number information. A phone number is classified by
25  * a type. The following types are available, it's possible to use multiple types
26  * Types for a number by combining them through a logical or.
27  */
28 class KCONTACTS_EXPORT PhoneNumber
29 {
30  friend KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &, const PhoneNumber &);
31  friend KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &, PhoneNumber &);
32 
33  Q_GADGET
34  Q_PROPERTY(QString id READ id WRITE setId)
35  Q_PROPERTY(QString number READ number WRITE setNumber)
36  Q_PROPERTY(QString normalizedNumber READ normalizedNumber)
37  Q_PROPERTY(Type type READ type WRITE setType)
38  Q_PROPERTY(QString typeLabel READ typeLabel)
39  Q_PROPERTY(bool isEmpty READ isEmpty)
40  Q_PROPERTY(bool isPreferred READ isPreferred)
41  Q_PROPERTY(bool supportsSms READ supportsSms)
42 
43 public:
44  /**
45  Phone number types.
46  @see Type
47  */
48  enum TypeFlag {
49  Home = 1, /**< Home number */
50  Work = 2, /**< Office number */
51  Msg = 4, /**< Messaging */
52  Pref = 8, /**< Preferred number */
53  Voice = 16, /**< Voice */
54  Fax = 32, /**< Fax machine */
55  Cell = 64, /**< Cell phone */
56  Video = 128, /**< Video phone */
57  Bbs = 256, /**< Mailbox */
58  Modem = 512, /**< Modem */
59  Car = 1024, /**< Car phone */
60  Isdn = 2048, /**< ISDN connection */
61  Pcs = 4096, /**< Personal Communication Service*/
62  Pager = 8192, /**< Pager */
63  // TODO add Text and textphone support vcard4
64  Undefined = 16384, /** Undefined number type */
65  };
66 
67  /**
68  * Stores a combination of #TypeFlag values.
69  */
70  Q_DECLARE_FLAGS(Type, TypeFlag)
71  Q_FLAG(Type)
72 
73  /**
74  * List of phone number types.
75  */
77 
78  /**
79  * List of phone numbers.
80  */
82 
83  /**
84  * Creates an empty phone number object.
85  */
86  PhoneNumber();
87 
88  /**
89  * Creates a phone number object.
90  *
91  * @param number Number
92  * @param type Type as defined in enum. Multiple types can be
93  * specified by combining them by a logical or.
94  */
95  PhoneNumber(const QString &number, Type type = Home); // krazy:exclude=explicit
96 
97  /**
98  * Copy constructor.
99  *
100  * Fast operation, PhoneNumber's data is implicitly shared.
101  *
102  * @param other The PhoneNumber object to copy from
103  */
104  PhoneNumber(const PhoneNumber &other);
105 
106  /**
107  * Destroys the phone number.
108  */
109  ~PhoneNumber();
110 
111  /**
112  * Equality operator.
113  *
114  * @return @c true if number, type and identifier are equal,
115  * otherwise @c false
116  */
117  Q_REQUIRED_RESULT bool operator==(const PhoneNumber &other) const;
118 
119  /**
120  * Not-Equal operator.
121  */
122  Q_REQUIRED_RESULT bool operator!=(const PhoneNumber &other) const;
123 
124  /**
125  * Assignment operator.
126  *
127  * Fast operation, PhoneNumber's data is implicitly shared.
128  *
129  * @param other The PhoneNumber object to asssign to @c this
130  */
131  PhoneNumber &operator=(const PhoneNumber &other);
132 
133  /**
134  * Returns true, if the phone number is empty.
135  */
136  Q_REQUIRED_RESULT bool isEmpty() const;
137 
138  /**
139  * Sets the unique @p identifier.
140  */
141  void setId(const QString &identifier);
142 
143  /**
144  * Returns the unique identifier.
145  */
146  Q_REQUIRED_RESULT QString id() const;
147 
148  /**
149  * Sets the phone @p number.
150  */
151  void setNumber(const QString &number);
152 
153  /**
154  * Returns the phone number.
155  * This is the number as entered/stored with all formatting preserved. Preferred for display.
156  * @see normalizedNumber()
157  */
158  Q_REQUIRED_RESULT QString number() const;
159 
160  /**
161  * Returns the phone number normalized for dialing.
162  * This has all formatting stripped for passing to dialers or tel: URLs.
163  * @see number()
164  * @since 5.12
165  */
166  Q_REQUIRED_RESULT QString normalizedNumber() const;
167 
168  /**
169  * Sets the @p type.
170  * Multiple types can be specified by combining them by a logical or.
171  *
172  * @param type The #Type of the phone number
173  */
174  void setType(Type type);
175 
176  /**
177  * Returns the type. Can be a multiple types combined by a logical or.
178  *
179  * @see #TypeFlag
180  * @see typeLabel()
181  */
182  Q_REQUIRED_RESULT Type type() const;
183 
184  /**
185  * Returns a translated string of the address' type.
186  */
187  Q_REQUIRED_RESULT QString typeLabel() const;
188 
189  /**
190  * Returns a list of all available types
191  */
192  Q_REQUIRED_RESULT static TypeList typeList();
193 
194  /**
195  * Returns whether this phone number is marked as preferred.
196  * @since 5.12
197  */
198  Q_REQUIRED_RESULT bool isPreferred() const;
199  /**
200  * Returns whether this phone number is expected to support receiving SMS messages.
201  * @since 5.12
202  */
203  Q_REQUIRED_RESULT bool supportsSms() const;
204 
205  /**
206  * Returns the translated label for phone number @p type.
207  *
208  * In opposite to typeFlagLabel( TypeFlag type ), it returns all types
209  * of the phone number concatenated by '/'.
210  *
211  * @param type An OR'ed combination of #TypeFlag
212  *
213  * @see type()
214  */
215  static QString typeLabel(Type type);
216 
217  /**
218  * Returns the translated label for phone number @p type.
219  *
220  * @param type An OR'ed combination of #TypeFlag
221  *
222  * @see typeLabel()
223  * @since 4.5
224  */
225  Q_REQUIRED_RESULT static QString typeFlagLabel(TypeFlag type);
226 
227  /**
228  * Returns a string representation of the phone number.
229  */
230  QString toString() const;
231 
232  void setParameters(const QMap<QString, QStringList> &params);
233  Q_REQUIRED_RESULT QMap<QString, QStringList> parameters() const;
234 
235 private:
236  class Private;
237  QSharedDataPointer<Private> d;
238 };
239 
240 Q_DECLARE_OPERATORS_FOR_FLAGS(PhoneNumber::Type)
241 
242 /**
243  * Serializes the phone @p number object into the @p stream.
244  *
245  * @param stream The stream to write into
246  * @param number The phone number object to serialize
247  */
248 KCONTACTS_EXPORT QDataStream &operator<<(QDataStream &stream, const PhoneNumber &number);
249 
250 /**
251  * Initializes the phone @p number object from the @p stream.
252  *
253  * @param stream The stream to read from
254  * @param number The phone number object to deserialize into
255  */
256 KCONTACTS_EXPORT QDataStream &operator>>(QDataStream &stream, PhoneNumber &number);
257 }
258 Q_DECLARE_METATYPE(KContacts::PhoneNumber)
259 Q_DECLARE_TYPEINFO(KContacts::PhoneNumber, Q_MOVABLE_TYPE);
260 #endif
QDataStream & operator>>(QDataStream &in, KDateTime::Spec &spec)
TypeFlag
Phone number types.
Definition: phonenumber.h:48
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
Phonenumber information.
Definition: phonenumber.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Sep 23 2021 22:55:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.