summaryrefslogtreecommitdiffabout
path: root/kabc/phonenumber.cpp
Unidiff
Diffstat (limited to 'kabc/phonenumber.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/phonenumber.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 12b9b09..1752745 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,374 +1,398 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <kapplication.h> 28#include <kapplication.h>
29#include <klocale.h> 29#include <klocale.h>
30 30
31#include "phonenumber.h" 31#include "phonenumber.h"
32 32
33using namespace KABC; 33using namespace KABC;
34 34
35PhoneNumber::PhoneNumber() : 35PhoneNumber::PhoneNumber() :
36 mType( Home ) 36 mType( Home )
37{ 37{
38 init(); 38 init();
39} 39}
40 40
41PhoneNumber::PhoneNumber( const QString &number, int type ) : 41PhoneNumber::PhoneNumber( const QString &number, int type ) :
42 mType( type ), mNumber( number ) 42 mType( type ), mNumber( number )
43{ 43{
44 init(); 44 init();
45} 45}
46 46
47PhoneNumber::~PhoneNumber() 47PhoneNumber::~PhoneNumber()
48{ 48{
49} 49}
50 50
51void PhoneNumber::init() 51void PhoneNumber::init()
52{ 52{
53 mId = KApplication::randomString( 8 ); 53 mId = KApplication::randomString( 8 );
54} 54}
55 55
56bool PhoneNumber::operator==( const PhoneNumber &p ) const 56bool PhoneNumber::operator==( const PhoneNumber &p ) const
57{ 57{
58 if ( mNumber != p.mNumber ) return false; 58 if ( mNumber != p.mNumber ) return false;
59 if ( mType != p.mType ) return false; 59 if ( mType != p.mType ) return false;
60 60
61 return true; 61 return true;
62} 62}
63 63
64bool PhoneNumber::operator!=( const PhoneNumber &p ) const 64bool PhoneNumber::operator!=( const PhoneNumber &p ) const
65{ 65{
66 return !( p == *this ); 66 return !( p == *this );
67} 67}
68void PhoneNumber::makeCompat() 68void PhoneNumber::makeCompat()
69{ 69{
70 mType = getCompatType( mType ); 70 mType = getCompatType( mType );
71} 71}
72int PhoneNumber::getCompatType( int type ) 72int PhoneNumber::getCompatType( int type )
73{ 73{
74 74
75 if ((type & Cell) == Cell) { 75 if ((type & Cell) == Cell) {
76 if ((type & Work) == Work) 76 if ((type & Work) == Work)
77 return Car; 77 return Car;
78 return Cell; 78 return Cell;
79 } 79 }
80 if ((type & Home) == Home) { 80 if ((type & Home) == Home) {
81 if ((type & Pref) == Pref) 81 if ((type & Pref) == Pref)
82 return (Home | Pref); 82 return (Home | Pref);
83 if ((type & Fax) == Fax) 83 if ((type & Fax) == Fax)
84 return (Home | Fax); 84 return (Home | Fax);
85 return (Home); 85 return (Home);
86 } 86 }
87 if ((type & Work) == Work) { 87 if ((type & Work) == Work) {
88 if ((type & Pref) == Pref) 88 if ((type & Pref) == Pref)
89 return (Work| Pref); 89 return (Work| Pref);
90 if ((type & Fax) == Fax) 90 if ((type & Fax) == Fax)
91 return (Fax |Work); 91 return (Fax |Work);
92 if ((type & Msg) == Msg) { 92 if ((type & Msg) == Msg) {
93 if ((type & Voice) == Voice) 93 if ((type & Voice) == Voice)
94 return ( Msg | Voice |Work); 94 return ( Msg | Voice |Work);
95 return ( Msg | Work); 95 return ( Msg | Work);
96 } 96 }
97 return Work; 97 return Work;
98 } 98 }
99 if ((type & Pcs) == Pcs) { 99 if ((type & Pcs) == Pcs) {
100 if ((type & Pref) == Pref) 100 if ((type & Pref) == Pref)
101 return Pcs | Pref; 101 return Pcs | Pref;
102 if ((type & Voice) == Voice) 102 if ((type & Voice) == Voice)
103 return Pcs | Voice; 103 return Pcs | Voice;
104 return Pcs; 104 return Pcs;
105 } 105 }
106 if ((type & Car) == Car) 106 if ((type & Car) == Car)
107 return Car; 107 return Car;
108 if ((type & Pager) == Pager) 108 if ((type & Pager) == Pager)
109 return Pager; 109 return Pager;
110 if ((type & Isdn) == Isdn) 110 if ((type & Isdn) == Isdn)
111 return Isdn; 111 return Isdn;
112#if 0 112#if 0
113 if ((type & Video) == Video) 113 if ((type & Video) == Video)
114 return Video; 114 return Video;
115#endif 115#endif
116 if ((type & Msg) == Msg) 116 if ((type & Msg) == Msg)
117 return Msg; 117 return Msg;
118 if ((type & Fax) == Fax) 118 if ((type & Fax) == Fax)
119 return Fax; 119 return Fax;
120 120
121 if ((type & Pref) == Pref) 121 if ((type & Pref) == Pref)
122 return Pref; 122 return Pref;
123 123
124 return Voice; 124 return Voice;
125 125
126} 126}
127bool PhoneNumber::simplifyNumber() 127bool PhoneNumber::simplifyNumber()
128{ 128{
129 QString Number; 129 QString Number;
130 int i; 130 int i;
131 Number = mNumber.stripWhiteSpace (); 131 Number = mNumber.stripWhiteSpace ();
132 mNumber = ""; 132 mNumber = "";
133 for ( i = 0; i < Number.length(); ++i) { 133 for ( i = 0; i < Number.length(); ++i) {
134 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) 134 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
135 mNumber += Number.at(i); 135 mNumber += Number.at(i);
136 } 136 }
137 return ( mNumber.length() > 0 ); 137 return ( mNumber.length() > 0 );
138} 138}
139// make cellphone compatible 139// make cellphone compatible
140void PhoneNumber::simplifyType() 140void PhoneNumber::simplifyType()
141{ 141{
142 if ( mType & Fax ) mType = Fax; 142 if ( mType & Fax ) mType = Fax;
143 else if ( mType & Cell ) mType = Cell; 143 else if ( mType & Cell ) mType = Cell;
144 else if ( mType & Work ) mType = Work ; 144 else if ( mType & Work ) mType = Work ;
145 else if ( mType & Home ) mType = Home; 145 else if ( mType & Home ) mType = Home;
146 else mType = Pref; 146 else mType = Pref;
147} 147}
148bool PhoneNumber::contains( const PhoneNumber &p ) 148bool PhoneNumber::contains( const PhoneNumber &p )
149{ 149{
150 PhoneNumber myself; 150 PhoneNumber myself;
151 PhoneNumber other; 151 PhoneNumber other;
152 myself = *this; 152 myself = *this;
153 other = p; 153 other = p;
154 myself.simplifyNumber(); 154 myself.simplifyNumber();
155 other.simplifyNumber(); 155 other.simplifyNumber();
156 if ( myself.number() != other.number ()) 156 if ( myself.number() != other.number ())
157 return false; 157 return false;
158 myself.simplifyType(); 158 myself.simplifyType();
159 other.simplifyType(); 159 other.simplifyType();
160 if ( myself.type() == other.type()) 160 if ( myself.type() == other.type())
161 return true; 161 return true;
162 return false; 162 return false;
163} 163}
164 164
165void PhoneNumber::setId( const QString &id ) 165void PhoneNumber::setId( const QString &id )
166{ 166{
167 mId = id; 167 mId = id;
168} 168}
169 169
170QString PhoneNumber::id() const 170QString PhoneNumber::id() const
171{ 171{
172 return mId; 172 return mId;
173} 173}
174 174
175void PhoneNumber::setNumber( const QString &number ) 175void PhoneNumber::setNumber( const QString &number )
176{ 176{
177 mNumber = number; 177 mNumber = number;
178} 178}
179 179
180QString PhoneNumber::number() const 180QString PhoneNumber::number() const
181{ 181{
182 return mNumber; 182 return mNumber;
183} 183}
184 184
185void PhoneNumber::setType( int type ) 185void PhoneNumber::setType( int type )
186{ 186{
187 mType = type; 187 mType = type;
188} 188}
189 189
190int PhoneNumber::type() const 190int PhoneNumber::type() const
191{ 191{
192 return mType; 192 return mType;
193} 193}
194 194
195QString PhoneNumber::typeLabel() const 195QString PhoneNumber::typeLabel() const
196{ 196{
197 QString label; 197 QString label;
198 bool first = true; 198 bool first = true;
199 199
200 TypeList list = typeList(); 200 TypeList list = typeList();
201 201
202 TypeList::Iterator it; 202 TypeList::Iterator it;
203 for ( it = list.begin(); it != list.end(); ++it ) { 203 for ( it = list.begin(); it != list.end(); ++it ) {
204 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 204 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
205 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 205 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
206 if ( first ) 206 if ( first )
207 first = false; 207 first = false;
208 } 208 }
209 } 209 }
210 210
211 return label; 211 return label;
212} 212}
213 213
214QString PhoneNumber::label() const 214QString PhoneNumber::label() const
215{ 215{
216 return typeLabel( type() ); 216 return typeLabel( type() );
217} 217}
218 218
219PhoneNumber::TypeList PhoneNumber::typeList() 219PhoneNumber::TypeList PhoneNumber::typeList()
220{ 220{
221 TypeList list; 221 TypeList list;
222 222
223 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 223 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
224 << Bbs << Modem << Car << Isdn << Pcs << Pager; 224 << Bbs << Modem << Car << Isdn << Pcs << Pager;
225 225
226 return list; 226 return list;
227} 227}
228PhoneNumber::TypeList PhoneNumber::supportedTypeList() 228PhoneNumber::TypeList PhoneNumber::supportedTypeList()
229{ 229{
230 static TypeList list; 230 static TypeList list;
231 if ( list.count() == 0 ) 231 if ( list.count() == 0 )
232 list << (Home| Pref) << (Work| Pref) << Cell <<(Pcs|Pref)<< (Pcs|Voice)<< Home << Work << Car << Pcs <<(Work| Msg | Voice) << (Work| Msg) << (Home | Fax) << (Work| Fax) << Fax<< Pager << Isdn << Msg << Pref << Voice; 232 list << (Home| Pref) << (Work| Pref) << Cell <<(Pcs|Pref)<< (Pcs|Voice)<< Home << Work << Car << Pcs <<(Work| Msg | Voice) << (Work| Msg) << (Home | Fax) << (Work| Fax) << Fax<< Pager << Isdn << Msg << Pref << Voice;
233 return list; 233 return list;
234} 234}
235
236#if 0
237Home| Pref i18n("Home") Home
238Work| Pref i18n("Work") Business
239Cell i18n("Mobile") Mobile
240Pcs|Pref i18n("SiP") Radio
241Pcs|Voice i18n("VoIP") TTY/TTD
242Home i18n("Home2") Home 2
243Work i18n("Work2") Business 2
244Car i18n("Mobile2") Car
245Pcs i18n("SiP2") Telex
246Work| Msg | Voice i18n("Assistent") Assistent
247Work| Msg i18n("Company") Company
248Home | Fax i18n("Fax (Home)") Home Fax
249Work| Fax i18n("Fax (Work)") Business Fax
250Fax i18n("Fax (Other)") Other Fax
251Pager i18n("Pager") Pager
252Isdn i18n("ISDN") Isdn
253Msg i18n("Callback") Callback
254Pref i18n("Primary") Primary
255Voice; i18n("Other") Other
256
257#endif
258
235QStringList PhoneNumber::supportedTypeListNames() 259QStringList PhoneNumber::supportedTypeListNames()
236{ 260{
237 static QStringList list; 261 static QStringList list;
238 if ( list.count() == 0 ) 262 if ( list.count() == 0 )
239 list << i18n("Home") << i18n("Work") << i18n("Mobile") << i18n("SiP") << i18n("VoIP") <<i18n("Home2")<< i18n("Work2") << i18n("Mobile2") << i18n("SiP2") << i18n("Assistent") << i18n("Company") << i18n("Fax (Home)") << i18n("Fax (Work)") << i18n("Fax (Other)") << i18n("Pager") << i18n("ISDN") << i18n("Callback") << i18n("Primary")<< i18n("Other"); 263 list << i18n("Home") << i18n("Work") << i18n("Mobile") << i18n("SiP") << i18n("VoIP") <<i18n("Home2")<< i18n("Work2") << i18n("Mobile2") << i18n("SiP2") << i18n("Assistent") << i18n("Company") << i18n("Fax (Home)") << i18n("Fax (Work)") << i18n("Fax (Other)") << i18n("Pager") << i18n("ISDN") << i18n("Callback") << i18n("Primary")<< i18n("Other");
240 return list; 264 return list;
241} 265}
242 266
243int PhoneNumber::typeListIndex4Type(int type ) 267int PhoneNumber::typeListIndex4Type(int type )
244{ 268{
245 TypeList list = supportedTypeList(); 269 TypeList list = supportedTypeList();
246 int i = 0; 270 int i = 0;
247 while ( i < list.count() ) { 271 while ( i < list.count() ) {
248 if ( list [i] == type ) 272 if ( list [i] == type )
249 return i; 273 return i;
250 ++i; 274 ++i;
251 } 275 }
252 return list.count()-1; 276 return list.count()-1;
253} 277}
254 278
255QString PhoneNumber::label( int type ) 279QString PhoneNumber::label( int type )
256{ 280{
257 return typeLabel( type ); 281 return typeLabel( type );
258} 282}
259 283
260QString PhoneNumber::typeLabel( int type ) 284QString PhoneNumber::typeLabel( int type )
261{ 285{
262 if ((type & Cell) == Cell) 286 if ((type & Cell) == Cell)
263 return i18n("Mobile"); 287 return i18n("Mobile");
264 if ((type & Home) == Home) { 288 if ((type & Home) == Home) {
265 if ((type & Pref) == Pref) 289 if ((type & Pref) == Pref)
266 return i18n("Home"); 290 return i18n("Home");
267 if ((type & Fax) == Fax) 291 if ((type & Fax) == Fax)
268 return i18n("Fax (Home)"); 292 return i18n("Fax (Home)");
269 return i18n("Home2"); 293 return i18n("Home2");
270 } 294 }
271 295
272 if ((type & Work) == Work) { 296 if ((type & Work) == Work) {
273 if ((type & Pref) == Pref) 297 if ((type & Pref) == Pref)
274 return i18n("Work"); 298 return i18n("Work");
275 if ((type & Fax) == Fax) 299 if ((type & Fax) == Fax)
276 return i18n("Fax (Work)"); 300 return i18n("Fax (Work)");
277 if ((type & Msg) == Msg) { 301 if ((type & Msg) == Msg) {
278 if ((type & Voice) == Voice) 302 if ((type & Voice) == Voice)
279 return i18n("Assistent"); 303 return i18n("Assistent");
280 return i18n("Company"); 304 return i18n("Company");
281 } 305 }
282 return i18n("Work2"); 306 return i18n("Work2");
283 } 307 }
284 if ((type & Pcs) == Pcs) { 308 if ((type & Pcs) == Pcs) {
285 if ((type & Pref) == Pref) 309 if ((type & Pref) == Pref)
286 return i18n("SiP"); 310 return i18n("SiP");
287 if ((type & Voice) == Voice) 311 if ((type & Voice) == Voice)
288 return i18n("VoIP"); 312 return i18n("VoIP");
289 return i18n("SiP2"); 313 return i18n("SiP2");
290 } 314 }
291 if ((type & Car) == Car) 315 if ((type & Car) == Car)
292 return i18n("Mobile2"); 316 return i18n("Mobile2");
293 if ((type & Pager) == Pager) 317 if ((type & Pager) == Pager)
294 return i18n("Pager"); 318 return i18n("Pager");
295 if ((type & Isdn) == Isdn) 319 if ((type & Isdn) == Isdn)
296 return i18n("ISDN"); 320 return i18n("ISDN");
297 if ((type & Video) == Video) 321 if ((type & Video) == Video)
298 return i18n("Video"); 322 return i18n("Video");
299 323
300 if ((type & Msg) == Msg) 324 if ((type & Msg) == Msg)
301 return i18n("Callback"); 325 return i18n("Callback");
302 if ((type & Fax) == Fax) 326 if ((type & Fax) == Fax)
303 return i18n("Fax (Other)"); 327 return i18n("Fax (Other)");
304 328
305 if ((type & Pref) == Pref) 329 if ((type & Pref) == Pref)
306 return i18n("Primary"); 330 return i18n("Primary");
307 331
308 332
309 return i18n("Other"); 333 return i18n("Other");
310 334
311 335
312#if 0 336#if 0
313 337
314 338
315 339
316 QString typeString; 340 QString typeString;
317 341
318 342
319 if ((type & Cell) == Cell) 343 if ((type & Cell) == Cell)
320 typeString += i18n("Mobile") +" "; 344 typeString += i18n("Mobile") +" ";
321 if ((type & Home) == Home) 345 if ((type & Home) == Home)
322 typeString += i18n("Home")+" "; 346 typeString += i18n("Home")+" ";
323 else if ((type & Work) == Work) 347 else if ((type & Work) == Work)
324 typeString += i18n("Work")+" "; 348 typeString += i18n("Work")+" ";
325 349
326 if ((type & Sip) == Sip) 350 if ((type & Sip) == Sip)
327 typeString += i18n("SIP")+" "; 351 typeString += i18n("SIP")+" ";
328 if ((type & Car) == Car) 352 if ((type & Car) == Car)
329 typeString += i18n("Car")+" "; 353 typeString += i18n("Car")+" ";
330 354
331 if ((type & Fax) == Fax) 355 if ((type & Fax) == Fax)
332 typeString += i18n("Fax"); 356 typeString += i18n("Fax");
333 else if ((type & Msg) == Msg) 357 else if ((type & Msg) == Msg)
334 typeString += i18n("Messenger"); 358 typeString += i18n("Messenger");
335 else if ((type & Video) == Video) 359 else if ((type & Video) == Video)
336 typeString += i18n("Video"); 360 typeString += i18n("Video");
337 else if ((type & Bbs) == Bbs) 361 else if ((type & Bbs) == Bbs)
338 typeString += i18n("Mailbox"); 362 typeString += i18n("Mailbox");
339 else if ((type & Modem) == Modem) 363 else if ((type & Modem) == Modem)
340 typeString += i18n("Modem"); 364 typeString += i18n("Modem");
341 else if ((type & Isdn) == Isdn) 365 else if ((type & Isdn) == Isdn)
342 typeString += i18n("ISDN"); 366 typeString += i18n("ISDN");
343 else if ((type & Pcs) == Pcs) 367 else if ((type & Pcs) == Pcs)
344 typeString += i18n("PCS"); 368 typeString += i18n("PCS");
345 else if ((type & Pager) == Pager) 369 else if ((type & Pager) == Pager)
346 typeString += i18n("Pager"); 370 typeString += i18n("Pager");
347 // add the prefered flag 371 // add the prefered flag
348 /* 372 /*
349 if ((type & Pref) == Pref) 373 if ((type & Pref) == Pref)
350 typeString += i18n("(p)"); 374 typeString += i18n("(p)");
351 */ 375 */
352 //if we still have no match, return "other" 376 //if we still have no match, return "other"
353 if (typeString.isEmpty()) { 377 if (typeString.isEmpty()) {
354 if ((type & Voice) == Voice) 378 if ((type & Voice) == Voice)
355 return i18n("Voice"); 379 return i18n("Voice");
356 else 380 else
357 return i18n("Other"); 381 return i18n("Other");
358 } 382 }
359 383
360 return typeString.stripWhiteSpace(); 384 return typeString.stripWhiteSpace();
361#endif 385#endif
362} 386}
363 387
364QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) 388QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
365{ 389{
366 return s << phone.mId << phone.mType << phone.mNumber; 390 return s << phone.mId << phone.mType << phone.mNumber;
367} 391}
368 392
369QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) 393QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
370{ 394{
371 s >> phone.mId >> phone.mType >> phone.mNumber; 395 s >> phone.mId >> phone.mType >> phone.mNumber;
372 396
373 return s; 397 return s;
374} 398}