-rw-r--r-- | kabc/phonenumber.cpp | 23 |
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 | |||
@@ -21,96 +21,119 @@ | |||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (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 | ||
33 | using namespace KABC; | 33 | using namespace KABC; |
34 | 34 | ||
35 | PhoneNumber::PhoneNumber() : | 35 | PhoneNumber::PhoneNumber() : |
36 | mType( Home ) | 36 | mType( Home ) |
37 | { | 37 | { |
38 | init(); | 38 | init(); |
39 | } | 39 | } |
40 | 40 | ||
41 | PhoneNumber::PhoneNumber( const QString &number, int type ) : | 41 | PhoneNumber::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 | ||
47 | PhoneNumber::~PhoneNumber() | 47 | PhoneNumber::~PhoneNumber() |
48 | { | 48 | { |
49 | } | 49 | } |
50 | 50 | ||
51 | void PhoneNumber::init() | 51 | void PhoneNumber::init() |
52 | { | 52 | { |
53 | mId = KApplication::randomString( 8 ); | 53 | mId = KApplication::randomString( 8 ); |
54 | } | 54 | } |
55 | 55 | ||
56 | bool PhoneNumber::operator==( const PhoneNumber &p ) const | 56 | bool 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 | ||
64 | bool PhoneNumber::operator!=( const PhoneNumber &p ) const | 64 | bool PhoneNumber::operator!=( const PhoneNumber &p ) const |
65 | { | 65 | { |
66 | return !( p == *this ); | 66 | return !( p == *this ); |
67 | } | 67 | } |
68 | 68 | ||
69 | bool 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 | ||
84 | void 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 | } | ||
69 | void PhoneNumber::setId( const QString &id ) | 92 | void PhoneNumber::setId( const QString &id ) |
70 | { | 93 | { |
71 | mId = id; | 94 | mId = id; |
72 | } | 95 | } |
73 | 96 | ||
74 | QString PhoneNumber::id() const | 97 | QString PhoneNumber::id() const |
75 | { | 98 | { |
76 | return mId; | 99 | return mId; |
77 | } | 100 | } |
78 | 101 | ||
79 | void PhoneNumber::setNumber( const QString &number ) | 102 | void PhoneNumber::setNumber( const QString &number ) |
80 | { | 103 | { |
81 | mNumber = number; | 104 | mNumber = number; |
82 | } | 105 | } |
83 | 106 | ||
84 | QString PhoneNumber::number() const | 107 | QString PhoneNumber::number() const |
85 | { | 108 | { |
86 | return mNumber; | 109 | return mNumber; |
87 | } | 110 | } |
88 | 111 | ||
89 | void PhoneNumber::setType( int type ) | 112 | void PhoneNumber::setType( int type ) |
90 | { | 113 | { |
91 | mType = type; | 114 | mType = type; |
92 | } | 115 | } |
93 | 116 | ||
94 | int PhoneNumber::type() const | 117 | int PhoneNumber::type() const |
95 | { | 118 | { |
96 | return mType; | 119 | return mType; |
97 | } | 120 | } |
98 | 121 | ||
99 | QString PhoneNumber::typeLabel() const | 122 | QString 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 | } |