summaryrefslogtreecommitdiffabout
path: root/kabc/phonenumber.cpp
Unidiff
Diffstat (limited to 'kabc/phonenumber.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/phonenumber.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 041effc..4c6231d 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,236 +1,235 @@
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 ) 90bool PhoneNumber::contains( const PhoneNumber &p )
91{ 91{
92 PhoneNumber myself; 92 PhoneNumber myself;
93 PhoneNumber other; 93 PhoneNumber other;
94 myself = *this; 94 myself = *this;
95 other = p; 95 other = p;
96 myself.simplifyNumber(); 96 myself.simplifyNumber();
97 other.simplifyNumber(); 97 other.simplifyNumber();
98 if ( myself.number() != other.number ()) 98 if ( myself.number() != other.number ())
99 return false; 99 return false;
100 myself.simplifyType(); 100 myself.simplifyType();
101 other.simplifyType(); 101 other.simplifyType();
102 if ( myself.type() == other.type()) 102 if ( myself.type() == other.type())
103 return true; 103 return true;
104 return false; 104 return false;
105} 105}
106 106
107void PhoneNumber::setId( const QString &id ) 107void PhoneNumber::setId( const QString &id )
108{ 108{
109 mId = id; 109 mId = id;
110} 110}
111 111
112QString PhoneNumber::id() const 112QString PhoneNumber::id() const
113{ 113{
114 return mId; 114 return mId;
115} 115}
116 116
117void PhoneNumber::setNumber( const QString &number ) 117void PhoneNumber::setNumber( const QString &number )
118{ 118{
119 mNumber = number; 119 mNumber = number;
120} 120}
121 121
122QString PhoneNumber::number() const 122QString PhoneNumber::number() const
123{ 123{
124 return mNumber; 124 return mNumber;
125} 125}
126 126
127void PhoneNumber::setType( int type ) 127void PhoneNumber::setType( int type )
128{ 128{
129 mType = type; 129 mType = type;
130} 130}
131 131
132int PhoneNumber::type() const 132int PhoneNumber::type() const
133{ 133{
134 return mType; 134 return mType;
135} 135}
136 136
137QString PhoneNumber::typeLabel() const 137QString PhoneNumber::typeLabel() const
138{ 138{
139 QString label; 139 QString label;
140 bool first = true; 140 bool first = true;
141 141
142 TypeList list = typeList(); 142 TypeList list = typeList();
143 143
144 TypeList::Iterator it; 144 TypeList::Iterator it;
145 for ( it = list.begin(); it != list.end(); ++it ) { 145 for ( it = list.begin(); it != list.end(); ++it ) {
146 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 146 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
147 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 147 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
148 if ( first ) 148 if ( first )
149 first = false; 149 first = false;
150 } 150 }
151 } 151 }
152 152
153 return label; 153 return label;
154} 154}
155 155
156QString PhoneNumber::label() const 156QString PhoneNumber::label() const
157{ 157{
158 return typeLabel( type() ); 158 return typeLabel( type() );
159} 159}
160 160
161PhoneNumber::TypeList PhoneNumber::typeList() 161PhoneNumber::TypeList PhoneNumber::typeList()
162{ 162{
163 TypeList list; 163 TypeList list;
164 164
165 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 165 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
166 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; 166 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip;
167 167
168 return list; 168 return list;
169} 169}
170 170
171QString PhoneNumber::label( int type ) 171QString PhoneNumber::label( int type )
172{ 172{
173 return typeLabel( type ); 173 return typeLabel( type );
174} 174}
175 175
176QString PhoneNumber::typeLabel( int type ) 176QString PhoneNumber::typeLabel( int type )
177{ 177{
178 QString typeString; 178 QString typeString;
179 179
180
181 if ((type & Cell) == Cell)
182 typeString += i18n("Mobile") +" ";
180 if ((type & Home) == Home) 183 if ((type & Home) == Home)
181 typeString += i18n("Home"); 184 typeString += i18n("Home")+" ";
182 else if ((type & Work) == Work) 185 else if ((type & Work) == Work)
183 typeString += i18n("Work"); 186 typeString += i18n("Work")+" ";
184 187
185 if (!typeString.isEmpty()) 188 if ((type & Sip) == Sip)
186 typeString += " ";
187 if ((type & Cell) == Cell)
188 typeString += i18n("Mobile") +" ";
189 if ((type & Sip) == Sip)
190 typeString += i18n("SIP")+" "; 189 typeString += i18n("SIP")+" ";
191 if ((type & Car) == Car) 190 if ((type & Car) == Car)
192 typeString += i18n("Car")+" "; 191 typeString += i18n("Car")+" ";
193 192
194 if ((type & Fax) == Fax) 193 if ((type & Fax) == Fax)
195 typeString += i18n("Fax"); 194 typeString += i18n("Fax");
196 else if ((type & Msg) == Msg) 195 else if ((type & Msg) == Msg)
197 typeString += i18n("Messenger"); 196 typeString += i18n("Messenger");
198 else if ((type & Video) == Video) 197 else if ((type & Video) == Video)
199 typeString += i18n("Video"); 198 typeString += i18n("Video");
200 else if ((type & Bbs) == Bbs) 199 else if ((type & Bbs) == Bbs)
201 typeString += i18n("Mailbox"); 200 typeString += i18n("Mailbox");
202 else if ((type & Modem) == Modem) 201 else if ((type & Modem) == Modem)
203 typeString += i18n("Modem"); 202 typeString += i18n("Modem");
204 else if ((type & Isdn) == Isdn) 203 else if ((type & Isdn) == Isdn)
205 typeString += i18n("ISDN"); 204 typeString += i18n("ISDN");
206 else if ((type & Pcs) == Pcs) 205 else if ((type & Pcs) == Pcs)
207 typeString += i18n("PCS"); 206 typeString += i18n("PCS");
208 else if ((type & Pager) == Pager) 207 else if ((type & Pager) == Pager)
209 typeString += i18n("Pager"); 208 typeString += i18n("Pager");
210 // add the prefered flag 209 // add the prefered flag
211 /* 210 /*
212 if ((type & Pref) == Pref) 211 if ((type & Pref) == Pref)
213 typeString += i18n("(p)"); 212 typeString += i18n("(p)");
214 */ 213 */
215 //if we still have no match, return "other" 214 //if we still have no match, return "other"
216 if (typeString.isEmpty()) { 215 if (typeString.isEmpty()) {
217 if ((type & Voice) == Voice) 216 if ((type & Voice) == Voice)
218 return i18n("Voice"); 217 return i18n("Voice");
219 else 218 else
220 return i18n("Other"); 219 return i18n("Other");
221 } 220 }
222 221
223 return typeString.stripWhiteSpace(); 222 return typeString.stripWhiteSpace();
224} 223}
225 224
226QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) 225QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
227{ 226{
228 return s << phone.mId << phone.mType << phone.mNumber; 227 return s << phone.mId << phone.mType << phone.mNumber;
229} 228}
230 229
231QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) 230QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
232{ 231{
233 s >> phone.mId >> phone.mType >> phone.mNumber; 232 s >> phone.mId >> phone.mType >> phone.mNumber;
234 233
235 return s; 234 return s;
236} 235}