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
@@ -52,33 +52,88 @@ void 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;
@@ -150,46 +205,98 @@ QString PhoneNumber::typeLabel() const
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)
@@ -207,29 +314,30 @@ QString PhoneNumber::typeLabel( int type )
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}