summaryrefslogtreecommitdiffabout
path: root/kabc/phonenumber.cpp
authorzautrix <zautrix>2004-10-13 12:38:18 (UTC)
committer zautrix <zautrix>2004-10-13 12:38:18 (UTC)
commitefdd0735bda81dcd82dfb6d6dc0d0c143f249336 (patch) (unidiff)
tree8d67e4b51fbc3e8c48e1656c78054cfe6d2ead66 /kabc/phonenumber.cpp
parentf22ee1ec902fe2fc610786f39049fb84542b8726 (diff)
downloadkdepimpi-efdd0735bda81dcd82dfb6d6dc0d0c143f249336.zip
kdepimpi-efdd0735bda81dcd82dfb6d6dc0d0c143f249336.tar.gz
kdepimpi-efdd0735bda81dcd82dfb6d6dc0d0c143f249336.tar.bz2
mege contact fixes
Diffstat (limited to 'kabc/phonenumber.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/phonenumber.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index d7e3925..3d82553 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,223 +1,245 @@
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}
68 68
69bool PhoneNumber::simplifyNumber() 69bool PhoneNumber::simplifyNumber()
70{ 70{
71 QString Number; 71 QString Number;
72 int i; 72 int i;
73 Number = mNumber.stripWhiteSpace (); 73 Number = mNumber.stripWhiteSpace ();
74 mNumber = ""; 74 mNumber = "";
75 for ( i = 0; i < Number.length(); ++i) { 75 for ( i = 0; i < Number.length(); ++i) {
76 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) 76 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
77 mNumber += Number.at(i); 77 mNumber += Number.at(i);
78 } 78 }
79 return ( mNumber.length() > 0 ); 79 return ( mNumber.length() > 0 );
80} 80}
81// make cellphone compatible 81// make cellphone compatible
82void PhoneNumber::simplifyType() 82void PhoneNumber::simplifyType()
83{ 83{
84 if ( mType & Fax ) mType = Fax; 84 if ( mType & Fax ) mType = Fax;
85 else if ( mType & Cell ) mType = Cell; 85 else if ( mType & Cell ) mType = Cell;
86 else if ( mType & Work ) mType = Work ; 86 else if ( mType & Work ) mType = Work ;
87 else if ( mType & Home ) mType = Home; 87 else if ( mType & Home ) mType = Home;
88 else mType = Pref; 88 else mType = Pref;
89} 89}
90bool PhoneNumber::contains( const PhoneNumber &p )
91{
92 QString Number;
93 QString Num;
94 uint i;
95 Number = mNumber.stripWhiteSpace ();
96 Num = "";
97 for ( i = 0; i < Number.length(); ++i) {
98 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' )
99 Num += Number.at(i);
100 }
101 QString NumberR;
102 QString NumR;
103 NumberR = p.mNumber.stripWhiteSpace ();
104 NumR = "";
105 for ( i = 0; i < NumberR.length(); ++i) {
106 if ( NumberR.at(i).isDigit() || NumberR.at(i) == '+'|| NumberR.at(i) == '*'|| NumberR.at(i) == '#' )
107 NumR += NumberR.at(i);
108 }
109 return (Num == NumR);
110}
111
90void PhoneNumber::setId( const QString &id ) 112void PhoneNumber::setId( const QString &id )
91{ 113{
92 mId = id; 114 mId = id;
93} 115}
94 116
95QString PhoneNumber::id() const 117QString PhoneNumber::id() const
96{ 118{
97 return mId; 119 return mId;
98} 120}
99 121
100void PhoneNumber::setNumber( const QString &number ) 122void PhoneNumber::setNumber( const QString &number )
101{ 123{
102 mNumber = number; 124 mNumber = number;
103} 125}
104 126
105QString PhoneNumber::number() const 127QString PhoneNumber::number() const
106{ 128{
107 return mNumber; 129 return mNumber;
108} 130}
109 131
110void PhoneNumber::setType( int type ) 132void PhoneNumber::setType( int type )
111{ 133{
112 mType = type; 134 mType = type;
113} 135}
114 136
115int PhoneNumber::type() const 137int PhoneNumber::type() const
116{ 138{
117 return mType; 139 return mType;
118} 140}
119 141
120QString PhoneNumber::typeLabel() const 142QString PhoneNumber::typeLabel() const
121{ 143{
122 QString label; 144 QString label;
123 bool first = true; 145 bool first = true;
124 146
125 TypeList list = typeList(); 147 TypeList list = typeList();
126 148
127 TypeList::Iterator it; 149 TypeList::Iterator it;
128 for ( it = list.begin(); it != list.end(); ++it ) { 150 for ( it = list.begin(); it != list.end(); ++it ) {
129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 151 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 152 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
131 if ( first ) 153 if ( first )
132 first = false; 154 first = false;
133 } 155 }
134 } 156 }
135 157
136 return label; 158 return label;
137} 159}
138 160
139QString PhoneNumber::label() const 161QString PhoneNumber::label() const
140{ 162{
141 return typeLabel( type() ); 163 return typeLabel( type() );
142} 164}
143 165
144PhoneNumber::TypeList PhoneNumber::typeList() 166PhoneNumber::TypeList PhoneNumber::typeList()
145{ 167{
146 TypeList list; 168 TypeList list;
147 169
148 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 170 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
149 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; 171 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip;
150 172
151 return list; 173 return list;
152} 174}
153 175
154QString PhoneNumber::label( int type ) 176QString PhoneNumber::label( int type )
155{ 177{
156 return typeLabel( type ); 178 return typeLabel( type );
157} 179}
158 180
159QString PhoneNumber::typeLabel( int type ) 181QString PhoneNumber::typeLabel( int type )
160{ 182{
161 QString typeString; 183 QString typeString;
162 184
163 if ((type & Home) == Home) 185 if ((type & Home) == Home)
164 typeString += i18n("Home"); 186 typeString += i18n("Home");
165 else if ((type & Work) == Work) 187 else if ((type & Work) == Work)
166 typeString += i18n("Work"); 188 typeString += i18n("Work");
167 189
168 if (!typeString.isEmpty()) 190 if (!typeString.isEmpty())
169 typeString += " "; 191 typeString += " ";
170 192
171 if ((type & Cell) == Cell) 193 if ((type & Cell) == Cell)
172 typeString += i18n("Mobile"); 194 typeString += i18n("Mobile");
173 else if ((type & Fax) == Fax) 195 else if ((type & Fax) == Fax)
174 typeString += i18n("Fax"); 196 typeString += i18n("Fax");
175 else if ((type & Msg) == Msg) 197 else if ((type & Msg) == Msg)
176 typeString += i18n("Messenger"); 198 typeString += i18n("Messenger");
177 else if ((type & Voice) == Voice) { 199 else if ((type & Voice) == Voice) {
178// add nothing in case of the Voice flag 200// add nothing in case of the Voice flag
179// typeString += i18n("Voice"); 201// typeString += i18n("Voice");
180 } 202 }
181 else if ((type & Video) == Video) 203 else if ((type & Video) == Video)
182 typeString += i18n("Video"); 204 typeString += i18n("Video");
183 else if ((type & Bbs) == Bbs) 205 else if ((type & Bbs) == Bbs)
184 typeString += i18n("Mailbox"); 206 typeString += i18n("Mailbox");
185 else if ((type & Modem) == Modem) 207 else if ((type & Modem) == Modem)
186 typeString += i18n("Modem"); 208 typeString += i18n("Modem");
187 else if ((type & Car) == Car) 209 else if ((type & Car) == Car)
188 typeString += i18n("Car"); 210 typeString += i18n("Car");
189 else if ((type & Isdn) == Isdn) 211 else if ((type & Isdn) == Isdn)
190 typeString += i18n("ISDN"); 212 typeString += i18n("ISDN");
191 else if ((type & Pcs) == Pcs) 213 else if ((type & Pcs) == Pcs)
192 typeString += i18n("PCS"); 214 typeString += i18n("PCS");
193 else if ((type & Pager) == Pager) 215 else if ((type & Pager) == Pager)
194 typeString += i18n("Pager"); 216 typeString += i18n("Pager");
195 else if ((type & Sip) == Sip) 217 else if ((type & Sip) == Sip)
196 typeString += i18n("SIP"); 218 typeString += i18n("SIP");
197 219
198 // add the prefered flag 220 // add the prefered flag
199 if (!typeString.isEmpty()) 221 if (!typeString.isEmpty())
200 typeString += " "; 222 typeString += " ";
201 /* 223 /*
202 if ((type & Pref) == Pref) 224 if ((type & Pref) == Pref)
203 typeString += i18n("(p)"); 225 typeString += i18n("(p)");
204 */ 226 */
205 //if we still have no match, return "other" 227 //if we still have no match, return "other"
206 if (typeString.isEmpty()) 228 if (typeString.isEmpty())
207 return i18n("Other"); 229 return i18n("Other");
208 230
209 231
210 return typeString; 232 return typeString;
211} 233}
212 234
213QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) 235QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
214{ 236{
215 return s << phone.mId << phone.mType << phone.mNumber; 237 return s << phone.mId << phone.mType << phone.mNumber;
216} 238}
217 239
218QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) 240QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
219{ 241{
220 s >> phone.mId >> phone.mType >> phone.mNumber; 242 s >> phone.mId >> phone.mType >> phone.mNumber;
221 243
222 return s; 244 return s;
223} 245}