summaryrefslogtreecommitdiffabout
path: root/kabc/phonenumber.cpp
Unidiff
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
@@ -20,134 +20,156 @@
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