summaryrefslogtreecommitdiffabout
path: root/kabc/phonenumber.cpp
Unidiff
Diffstat (limited to 'kabc/phonenumber.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/phonenumber.cpp112
1 files changed, 110 insertions, 2 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 4c6231d..0d46ba7 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,235 +1,343 @@
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()
69{
70 mType = getCompatType( mType );
71}
72int PhoneNumber::getCompatType( int type )
73{
74
75 if ((type & Cell) == Cell) {
76 if ((type & Work) == Work)
77 return Car;
78 return Cell;
79 }
80 if ((type & Home) == Home) {
81 if ((type & Pref) == Pref)
82 return (Home | Pref);
83 if ((type & Fax) == Fax)
84 return (Home | Fax);
85 return (Home);
86 }
87 if ((type & Work) == Work) {
88 if ((type & Pref) == Pref)
89 return (Work| Pref);
90 if ((type & Fax) == Fax)
91 return (Fax |Work);
92 if ((type & Msg) == Msg) {
93 if ((type & Voice) == Voice)
94 return ( Msg | Voice |Work);
95 return ( Msg | Work);
96 }
97 return Work;
98 }
99 if ((type & Pcs) == Pcs) {
100 if ((type & Pref) == Pref)
101 return Pcs | Pref;
102 return Pcs;
103 }
104 if ((type & Car) == Car)
105 return Car;
106 if ((type & Pager) == Pager)
107 return Pager;
108 if ((type & Isdn) == Isdn)
109 return Isdn;
110 if ((type & Video) == Video)
111 return Video;
112
113 if ((type & Msg) == Msg)
114 return Msg;
115 if ((type & Fax) == Fax)
116 return Fax;
117
118 if ((type & Pref) == Pref)
119 return Pref;
68 120
121 return Voice;
122
123}
69bool PhoneNumber::simplifyNumber() 124bool PhoneNumber::simplifyNumber()
70{ 125{
71 QString Number; 126 QString Number;
72 int i; 127 int i;
73 Number = mNumber.stripWhiteSpace (); 128 Number = mNumber.stripWhiteSpace ();
74 mNumber = ""; 129 mNumber = "";
75 for ( i = 0; i < Number.length(); ++i) { 130 for ( i = 0; i < Number.length(); ++i) {
76 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) 131 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
77 mNumber += Number.at(i); 132 mNumber += Number.at(i);
78 } 133 }
79 return ( mNumber.length() > 0 ); 134 return ( mNumber.length() > 0 );
80} 135}
81// make cellphone compatible 136// make cellphone compatible
82void PhoneNumber::simplifyType() 137void PhoneNumber::simplifyType()
83{ 138{
84 if ( mType & Fax ) mType = Fax; 139 if ( mType & Fax ) mType = Fax;
85 else if ( mType & Cell ) mType = Cell; 140 else if ( mType & Cell ) mType = Cell;
86 else if ( mType & Work ) mType = Work ; 141 else if ( mType & Work ) mType = Work ;
87 else if ( mType & Home ) mType = Home; 142 else if ( mType & Home ) mType = Home;
88 else mType = Pref; 143 else mType = Pref;
89} 144}
90bool PhoneNumber::contains( const PhoneNumber &p ) 145bool PhoneNumber::contains( const PhoneNumber &p )
91{ 146{
92 PhoneNumber myself; 147 PhoneNumber myself;
93 PhoneNumber other; 148 PhoneNumber other;
94 myself = *this; 149 myself = *this;
95 other = p; 150 other = p;
96 myself.simplifyNumber(); 151 myself.simplifyNumber();
97 other.simplifyNumber(); 152 other.simplifyNumber();
98 if ( myself.number() != other.number ()) 153 if ( myself.number() != other.number ())
99 return false; 154 return false;
100 myself.simplifyType(); 155 myself.simplifyType();
101 other.simplifyType(); 156 other.simplifyType();
102 if ( myself.type() == other.type()) 157 if ( myself.type() == other.type())
103 return true; 158 return true;
104 return false; 159 return false;
105} 160}
106 161
107void PhoneNumber::setId( const QString &id ) 162void PhoneNumber::setId( const QString &id )
108{ 163{
109 mId = id; 164 mId = id;
110} 165}
111 166
112QString PhoneNumber::id() const 167QString PhoneNumber::id() const
113{ 168{
114 return mId; 169 return mId;
115} 170}
116 171
117void PhoneNumber::setNumber( const QString &number ) 172void PhoneNumber::setNumber( const QString &number )
118{ 173{
119 mNumber = number; 174 mNumber = number;
120} 175}
121 176
122QString PhoneNumber::number() const 177QString PhoneNumber::number() const
123{ 178{
124 return mNumber; 179 return mNumber;
125} 180}
126 181
127void PhoneNumber::setType( int type ) 182void PhoneNumber::setType( int type )
128{ 183{
129 mType = type; 184 mType = type;
130} 185}
131 186
132int PhoneNumber::type() const 187int PhoneNumber::type() const
133{ 188{
134 return mType; 189 return mType;
135} 190}
136 191
137QString PhoneNumber::typeLabel() const 192QString PhoneNumber::typeLabel() const
138{ 193{
139 QString label; 194 QString label;
140 bool first = true; 195 bool first = true;
141 196
142 TypeList list = typeList(); 197 TypeList list = typeList();
143 198
144 TypeList::Iterator it; 199 TypeList::Iterator it;
145 for ( it = list.begin(); it != list.end(); ++it ) { 200 for ( it = list.begin(); it != list.end(); ++it ) {
146 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 201 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
147 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 202 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
148 if ( first ) 203 if ( first )
149 first = false; 204 first = false;
150 } 205 }
151 } 206 }
152 207
153 return label; 208 return label;
154} 209}
155 210
156QString PhoneNumber::label() const 211QString PhoneNumber::label() const
157{ 212{
158 return typeLabel( type() ); 213 return typeLabel( type() );
159} 214}
160 215
161PhoneNumber::TypeList PhoneNumber::typeList() 216PhoneNumber::TypeList PhoneNumber::typeList()
162{ 217{
163 TypeList list; 218 TypeList list;
164 219
165 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 220 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
166 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; 221 << Bbs << Modem << Car << Isdn << Pcs << Pager;
167 222
168 return list; 223 return list;
169} 224}
170 225
171QString PhoneNumber::label( int type ) 226QString PhoneNumber::label( int type )
172{ 227{
173 return typeLabel( type ); 228 return typeLabel( type );
174} 229}
175 230
176QString PhoneNumber::typeLabel( int type ) 231QString PhoneNumber::typeLabel( int type )
177{ 232{
178 QString typeString; 233 if ((type & Cell) == Cell)
234 return i18n("Mobile");
235 if ((type & Home) == Home) {
236 if ((type & Pref) == Pref)
237 return i18n("Home");
238 if ((type & Fax) == Fax)
239 return i18n("Fax (Home)");
240 return i18n("Home2");
241 }
179 242
243 if ((type & Work) == Work) {
244 if ((type & Pref) == Pref)
245 return i18n("Work");
246 if ((type & Fax) == Fax)
247 return i18n("Fax (Work)");
248 if ((type & Msg) == Msg) {
249 if ((type & Voice) == Voice)
250 return i18n("Assistent");
251 return i18n("Company");
252 }
253 return i18n("Work2");
254 }
255 if ((type & Pcs) == Pcs) {
256 if ((type & Pref) == Pref)
257 return i18n("SIP");
258 return i18n("VoIP");
259 }
260 if ((type & Car) == Car)
261 return i18n("Mobile2 (Work)");
262 if ((type & Pager) == Pager)
263 return i18n("Pager");
264 if ((type & Isdn) == Isdn)
265 return i18n("ISDN");
266 if ((type & Video) == Video)
267 return i18n("Video");
268
269 if ((type & Msg) == Msg)
270 return i18n("Callback");
271 if ((type & Fax) == Fax)
272 return i18n("Fax (Other)");
273
274 if ((type & Pref) == Pref)
275 return i18n("Primary");
276
277
278 return i18n("Other");
279
280
281#if 0
282
283
284
285 QString typeString;
286
180 287
181 if ((type & Cell) == Cell) 288 if ((type & Cell) == Cell)
182 typeString += i18n("Mobile") +" "; 289 typeString += i18n("Mobile") +" ";
183 if ((type & Home) == Home) 290 if ((type & Home) == Home)
184 typeString += i18n("Home")+" "; 291 typeString += i18n("Home")+" ";
185 else if ((type & Work) == Work) 292 else if ((type & Work) == Work)
186 typeString += i18n("Work")+" "; 293 typeString += i18n("Work")+" ";
187 294
188 if ((type & Sip) == Sip) 295 if ((type & Sip) == Sip)
189 typeString += i18n("SIP")+" "; 296 typeString += i18n("SIP")+" ";
190 if ((type & Car) == Car) 297 if ((type & Car) == Car)
191 typeString += i18n("Car")+" "; 298 typeString += i18n("Car")+" ";
192 299
193 if ((type & Fax) == Fax) 300 if ((type & Fax) == Fax)
194 typeString += i18n("Fax"); 301 typeString += i18n("Fax");
195 else if ((type & Msg) == Msg) 302 else if ((type & Msg) == Msg)
196 typeString += i18n("Messenger"); 303 typeString += i18n("Messenger");
197 else if ((type & Video) == Video) 304 else if ((type & Video) == Video)
198 typeString += i18n("Video"); 305 typeString += i18n("Video");
199 else if ((type & Bbs) == Bbs) 306 else if ((type & Bbs) == Bbs)
200 typeString += i18n("Mailbox"); 307 typeString += i18n("Mailbox");
201 else if ((type & Modem) == Modem) 308 else if ((type & Modem) == Modem)
202 typeString += i18n("Modem"); 309 typeString += i18n("Modem");
203 else if ((type & Isdn) == Isdn) 310 else if ((type & Isdn) == Isdn)
204 typeString += i18n("ISDN"); 311 typeString += i18n("ISDN");
205 else if ((type & Pcs) == Pcs) 312 else if ((type & Pcs) == Pcs)
206 typeString += i18n("PCS"); 313 typeString += i18n("PCS");
207 else if ((type & Pager) == Pager) 314 else if ((type & Pager) == Pager)
208 typeString += i18n("Pager"); 315 typeString += i18n("Pager");
209 // add the prefered flag 316 // add the prefered flag
210 /* 317 /*
211 if ((type & Pref) == Pref) 318 if ((type & Pref) == Pref)
212 typeString += i18n("(p)"); 319 typeString += i18n("(p)");
213 */ 320 */
214 //if we still have no match, return "other" 321 //if we still have no match, return "other"
215 if (typeString.isEmpty()) { 322 if (typeString.isEmpty()) {
216 if ((type & Voice) == Voice) 323 if ((type & Voice) == Voice)
217 return i18n("Voice"); 324 return i18n("Voice");
218 else 325 else
219 return i18n("Other"); 326 return i18n("Other");
220 } 327 }
221 328
222 return typeString.stripWhiteSpace(); 329 return typeString.stripWhiteSpace();
330#endif
223} 331}
224 332
225QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) 333QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
226{ 334{
227 return s << phone.mId << phone.mType << phone.mNumber; 335 return s << phone.mId << phone.mType << phone.mNumber;
228} 336}
229 337
230QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) 338QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
231{ 339{
232 s >> phone.mId >> phone.mType >> phone.mNumber; 340 s >> phone.mId >> phone.mType >> phone.mNumber;
233 341
234 return s; 342 return s;
235} 343}