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