author | zautrix <zautrix> | 2005-10-28 03:24:50 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-10-28 03:24:50 (UTC) |
commit | f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e (patch) (unidiff) | |
tree | 969e6cf85499e3b1dcaa4dc24c972b65c906cfa9 /kabc/phonenumber.cpp | |
parent | cbda16d4966c7483d20d1b6b5a64c8af367ea732 (diff) | |
download | kdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.zip kdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.tar.gz kdepimpi-f83a59cf4f9d0cff4111b6f5c88e88e6dc96e79e.tar.bz2 |
many new bugs...
-rw-r--r-- | kabc/phonenumber.cpp | 112 |
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 | |||
@@ -36,65 +36,120 @@ PhoneNumber::PhoneNumber() : | |||
36 | mType( Home ) | 36 | mType( Home ) |
37 | { | 37 | { |
38 | init(); | 38 | init(); |
39 | } | 39 | } |
40 | 40 | ||
41 | PhoneNumber::PhoneNumber( const QString &number, int type ) : | 41 | PhoneNumber::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 | ||
47 | PhoneNumber::~PhoneNumber() | 47 | PhoneNumber::~PhoneNumber() |
48 | { | 48 | { |
49 | } | 49 | } |
50 | 50 | ||
51 | void PhoneNumber::init() | 51 | void PhoneNumber::init() |
52 | { | 52 | { |
53 | mId = KApplication::randomString( 8 ); | 53 | mId = KApplication::randomString( 8 ); |
54 | } | 54 | } |
55 | 55 | ||
56 | bool PhoneNumber::operator==( const PhoneNumber &p ) const | 56 | bool 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 | ||
64 | bool PhoneNumber::operator!=( const PhoneNumber &p ) const | 64 | bool PhoneNumber::operator!=( const PhoneNumber &p ) const |
65 | { | 65 | { |
66 | return !( p == *this ); | 66 | return !( p == *this ); |
67 | } | 67 | } |
68 | void PhoneNumber::makeCompat() | ||
69 | { | ||
70 | mType = getCompatType( mType ); | ||
71 | } | ||
72 | int 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 | } | ||
69 | bool PhoneNumber::simplifyNumber() | 124 | bool 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 |
82 | void PhoneNumber::simplifyType() | 137 | void 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 | } |
90 | bool PhoneNumber::contains( const PhoneNumber &p ) | 145 | bool 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(); |
@@ -134,102 +189,155 @@ int PhoneNumber::type() const | |||
134 | return mType; | 189 | return mType; |
135 | } | 190 | } |
136 | 191 | ||
137 | QString PhoneNumber::typeLabel() const | 192 | QString 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 | ||
156 | QString PhoneNumber::label() const | 211 | QString PhoneNumber::label() const |
157 | { | 212 | { |
158 | return typeLabel( type() ); | 213 | return typeLabel( type() ); |
159 | } | 214 | } |
160 | 215 | ||
161 | PhoneNumber::TypeList PhoneNumber::typeList() | 216 | PhoneNumber::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 | ||
171 | QString PhoneNumber::label( int type ) | 226 | QString PhoneNumber::label( int type ) |
172 | { | 227 | { |
173 | return typeLabel( type ); | 228 | return typeLabel( type ); |
174 | } | 229 | } |
175 | 230 | ||
176 | QString PhoneNumber::typeLabel( int type ) | 231 | QString 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 | ||
225 | QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) | 333 | QDataStream &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 | ||
230 | QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) | 338 | QDataStream &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 | } |