summaryrefslogtreecommitdiffabout
path: root/kabc/phonenumber.cpp
Unidiff
Diffstat (limited to 'kabc/phonenumber.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/phonenumber.cpp31
1 files changed, 13 insertions, 18 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 3d82553..abb3b3b 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,205 +1,200 @@
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 QString Number; 92 PhoneNumber myself;
93 QString Num; 93 PhoneNumber other;
94 uint i; 94 myself = *this;
95 Number = mNumber.stripWhiteSpace (); 95 other = p;
96 Num = ""; 96 myself.simplifyNumber();
97 for ( i = 0; i < Number.length(); ++i) { 97 other.simplifyNumber();
98 if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) 98 if ( myself.number() != other.number ())
99 Num += Number.at(i); 99 return false;
100 } 100 myself.simplifyType();
101 QString NumberR; 101 other.simplifyType();
102 QString NumR; 102 if ( myself.type() == other.type())
103 NumberR = p.mNumber.stripWhiteSpace (); 103 return true;
104 NumR = ""; 104 return false;
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} 105}
111 106
112void PhoneNumber::setId( const QString &id ) 107void PhoneNumber::setId( const QString &id )
113{ 108{
114 mId = id; 109 mId = id;
115} 110}
116 111
117QString PhoneNumber::id() const 112QString PhoneNumber::id() const
118{ 113{
119 return mId; 114 return mId;
120} 115}
121 116
122void PhoneNumber::setNumber( const QString &number ) 117void PhoneNumber::setNumber( const QString &number )
123{ 118{
124 mNumber = number; 119 mNumber = number;
125} 120}
126 121
127QString PhoneNumber::number() const 122QString PhoneNumber::number() const
128{ 123{
129 return mNumber; 124 return mNumber;
130} 125}
131 126
132void PhoneNumber::setType( int type ) 127void PhoneNumber::setType( int type )
133{ 128{
134 mType = type; 129 mType = type;
135} 130}
136 131
137int PhoneNumber::type() const 132int PhoneNumber::type() const
138{ 133{
139 return mType; 134 return mType;
140} 135}
141 136
142QString PhoneNumber::typeLabel() const 137QString PhoneNumber::typeLabel() const
143{ 138{
144 QString label; 139 QString label;
145 bool first = true; 140 bool first = true;
146 141
147 TypeList list = typeList(); 142 TypeList list = typeList();
148 143
149 TypeList::Iterator it; 144 TypeList::Iterator it;
150 for ( it = list.begin(); it != list.end(); ++it ) { 145 for ( it = list.begin(); it != list.end(); ++it ) {
151 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 146 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
152 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 147 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
153 if ( first ) 148 if ( first )
154 first = false; 149 first = false;
155 } 150 }
156 } 151 }
157 152
158 return label; 153 return label;
159} 154}
160 155
161QString PhoneNumber::label() const 156QString PhoneNumber::label() const
162{ 157{
163 return typeLabel( type() ); 158 return typeLabel( type() );
164} 159}
165 160
166PhoneNumber::TypeList PhoneNumber::typeList() 161PhoneNumber::TypeList PhoneNumber::typeList()
167{ 162{
168 TypeList list; 163 TypeList list;
169 164
170 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 165 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
171 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; 166 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip;
172 167
173 return list; 168 return list;
174} 169}
175 170
176QString PhoneNumber::label( int type ) 171QString PhoneNumber::label( int type )
177{ 172{
178 return typeLabel( type ); 173 return typeLabel( type );
179} 174}
180 175
181QString PhoneNumber::typeLabel( int type ) 176QString PhoneNumber::typeLabel( int type )
182{ 177{
183 QString typeString; 178 QString typeString;
184 179
185 if ((type & Home) == Home) 180 if ((type & Home) == Home)
186 typeString += i18n("Home"); 181 typeString += i18n("Home");
187 else if ((type & Work) == Work) 182 else if ((type & Work) == Work)
188 typeString += i18n("Work"); 183 typeString += i18n("Work");
189 184
190 if (!typeString.isEmpty()) 185 if (!typeString.isEmpty())
191 typeString += " "; 186 typeString += " ";
192 187
193 if ((type & Cell) == Cell) 188 if ((type & Cell) == Cell)
194 typeString += i18n("Mobile"); 189 typeString += i18n("Mobile");
195 else if ((type & Fax) == Fax) 190 else if ((type & Fax) == Fax)
196 typeString += i18n("Fax"); 191 typeString += i18n("Fax");
197 else if ((type & Msg) == Msg) 192 else if ((type & Msg) == Msg)
198 typeString += i18n("Messenger"); 193 typeString += i18n("Messenger");
199 else if ((type & Voice) == Voice) { 194 else if ((type & Voice) == Voice) {
200// add nothing in case of the Voice flag 195// add nothing in case of the Voice flag
201// typeString += i18n("Voice"); 196// typeString += i18n("Voice");
202 } 197 }
203 else if ((type & Video) == Video) 198 else if ((type & Video) == Video)
204 typeString += i18n("Video"); 199 typeString += i18n("Video");
205 else if ((type & Bbs) == Bbs) 200 else if ((type & Bbs) == Bbs)