summaryrefslogtreecommitdiffabout
path: root/kabc/phonenumber.cpp
authorzautrix <zautrix>2004-10-08 20:03:23 (UTC)
committer zautrix <zautrix>2004-10-08 20:03:23 (UTC)
commit10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34 (patch) (unidiff)
tree3105b985a9dbedd31dff52e14fe667eeff4f9ff4 /kabc/phonenumber.cpp
parent13bd085e06b76228321f5a004759fcdf19cca711 (diff)
downloadkdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.zip
kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.tar.gz
kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.tar.bz2
added contact phone support
Diffstat (limited to 'kabc/phonenumber.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/phonenumber.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 7aeb2ee..e5abc0e 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,164 +1,187 @@
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()
70{
71 QString Number;
72 int i;
73 Number = mNumber.stripWhiteSpace ();
74 mNumber = "";
75 if ( Number.at(0) == '+' )
76 mNumber += "+";
77 for ( i = 0; i < Number.length(); ++i) {
78 if ( Number.at(i).isDigit() )
79 mNumber += Number.at(i);
80 }
81 return ( mNumber.length() > 0 );
82}
83// make cellphone compatible
84void PhoneNumber::simplifyType()
85{
86 if ( mType & Fax ) mType = Fax;
87 else if ( mType & Cell ) mType = Cell;
88 else if ( mType & Work ) mType = Work ;
89 else if ( mType & Home ) mType = Home;
90 else mType = Pref;
91}
69void PhoneNumber::setId( const QString &id ) 92void PhoneNumber::setId( const QString &id )
70{ 93{
71 mId = id; 94 mId = id;
72} 95}
73 96
74QString PhoneNumber::id() const 97QString PhoneNumber::id() const
75{ 98{
76 return mId; 99 return mId;
77} 100}
78 101
79void PhoneNumber::setNumber( const QString &number ) 102void PhoneNumber::setNumber( const QString &number )
80{ 103{
81 mNumber = number; 104 mNumber = number;
82} 105}
83 106
84QString PhoneNumber::number() const 107QString PhoneNumber::number() const
85{ 108{
86 return mNumber; 109 return mNumber;
87} 110}
88 111
89void PhoneNumber::setType( int type ) 112void PhoneNumber::setType( int type )
90{ 113{
91 mType = type; 114 mType = type;
92} 115}
93 116
94int PhoneNumber::type() const 117int PhoneNumber::type() const
95{ 118{
96 return mType; 119 return mType;
97} 120}
98 121
99QString PhoneNumber::typeLabel() const 122QString PhoneNumber::typeLabel() const
100{ 123{
101 QString label; 124 QString label;
102 bool first = true; 125 bool first = true;
103 126
104 TypeList list = typeList(); 127 TypeList list = typeList();
105 128
106 TypeList::Iterator it; 129 TypeList::Iterator it;
107 for ( it = list.begin(); it != list.end(); ++it ) { 130 for ( it = list.begin(); it != list.end(); ++it ) {
108 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 131 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
109 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 132 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
110 if ( first ) 133 if ( first )
111 first = false; 134 first = false;
112 } 135 }
113 } 136 }
114 137
115 return label; 138 return label;
116} 139}
117 140
118QString PhoneNumber::label() const 141QString PhoneNumber::label() const
119{ 142{
120 return typeLabel( type() ); 143 return typeLabel( type() );
121} 144}
122 145
123PhoneNumber::TypeList PhoneNumber::typeList() 146PhoneNumber::TypeList PhoneNumber::typeList()
124{ 147{
125 TypeList list; 148 TypeList list;
126 149
127 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 150 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
128 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; 151 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip;
129 152
130 return list; 153 return list;
131} 154}
132 155
133QString PhoneNumber::label( int type ) 156QString PhoneNumber::label( int type )
134{ 157{
135 return typeLabel( type ); 158 return typeLabel( type );
136} 159}
137 160
138QString PhoneNumber::typeLabel( int type ) 161QString PhoneNumber::typeLabel( int type )
139{ 162{
140 QString typeString; 163 QString typeString;
141 164
142 if ((type & Home) == Home) 165 if ((type & Home) == Home)
143 typeString += i18n("Home"); 166 typeString += i18n("Home");
144 else if ((type & Work) == Work) 167 else if ((type & Work) == Work)
145 typeString += i18n("Work"); 168 typeString += i18n("Work");
146 169
147 if (!typeString.isEmpty()) 170 if (!typeString.isEmpty())
148 typeString += " "; 171 typeString += " ";
149 172
150 if ((type & Cell) == Cell) 173 if ((type & Cell) == Cell)
151 typeString += i18n("Mobile"); 174 typeString += i18n("Mobile");
152 else if ((type & Fax) == Fax) 175 else if ((type & Fax) == Fax)
153 typeString += i18n("Fax"); 176 typeString += i18n("Fax");
154 else if ((type & Msg) == Msg) 177 else if ((type & Msg) == Msg)
155 typeString += i18n("Messenger"); 178 typeString += i18n("Messenger");
156 else if ((type & Voice) == Voice) { 179 else if ((type & Voice) == Voice) {
157// add nothing in case of the Voice flag 180// add nothing in case of the Voice flag
158// typeString += i18n("Voice"); 181// typeString += i18n("Voice");
159 } 182 }
160 else if ((type & Video) == Video) 183 else if ((type & Video) == Video)
161 typeString += i18n("Video"); 184 typeString += i18n("Video");
162 else if ((type & Bbs) == Bbs) 185 else if ((type & Bbs) == Bbs)
163 typeString += i18n("Mailbox"); 186 typeString += i18n("Mailbox");
164 else if ((type & Modem) == Modem) 187 else if ((type & Modem) == Modem)