author | ulf69 <ulf69> | 2004-07-13 15:07:00 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-13 15:07:00 (UTC) |
commit | 02380b50374340283fe9dd0f804254ee17374347 (patch) (unidiff) | |
tree | 83928927651c22dd0231195f84b0614ba6442254 | |
parent | f88d48384d2c012fbaa3ffaa613d6eaa3694fab7 (diff) | |
download | kdepimpi-02380b50374340283fe9dd0f804254ee17374347.zip kdepimpi-02380b50374340283fe9dd0f804254ee17374347.tar.gz kdepimpi-02380b50374340283fe9dd0f804254ee17374347.tar.bz2 |
more changes to resolve the "other" problematic.
e.g. home+pref was shown as "other".
-rw-r--r-- | kabc/phonenumber.cpp | 107 |
1 files changed, 47 insertions, 60 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index 04b1168..3f641d1 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp | |||
@@ -1,213 +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 | /* |
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 | void PhoneNumber::setId( const QString &id ) | 69 | void PhoneNumber::setId( const QString &id ) |
70 | { | 70 | { |
71 | mId = id; | 71 | mId = id; |
72 | } | 72 | } |
73 | 73 | ||
74 | QString PhoneNumber::id() const | 74 | QString PhoneNumber::id() const |
75 | { | 75 | { |
76 | return mId; | 76 | return mId; |
77 | } | 77 | } |
78 | 78 | ||
79 | void PhoneNumber::setNumber( const QString &number ) | 79 | void PhoneNumber::setNumber( const QString &number ) |
80 | { | 80 | { |
81 | mNumber = number; | 81 | mNumber = number; |
82 | } | 82 | } |
83 | 83 | ||
84 | QString PhoneNumber::number() const | 84 | QString PhoneNumber::number() const |
85 | { | 85 | { |
86 | return mNumber; | 86 | return mNumber; |
87 | } | 87 | } |
88 | 88 | ||
89 | void PhoneNumber::setType( int type ) | 89 | void PhoneNumber::setType( int type ) |
90 | { | 90 | { |
91 | mType = type; | 91 | mType = type; |
92 | } | 92 | } |
93 | 93 | ||
94 | int PhoneNumber::type() const | 94 | int PhoneNumber::type() const |
95 | { | 95 | { |
96 | return mType; | 96 | return mType; |
97 | } | 97 | } |
98 | 98 | ||
99 | QString PhoneNumber::typeLabel() const | 99 | QString PhoneNumber::typeLabel() const |
100 | { | 100 | { |
101 | QString label; | 101 | QString label; |
102 | bool first = true; | 102 | bool first = true; |
103 | 103 | ||
104 | TypeList list = typeList(); | 104 | TypeList list = typeList(); |
105 | 105 | ||
106 | TypeList::Iterator it; | 106 | TypeList::Iterator it; |
107 | for ( it = list.begin(); it != list.end(); ++it ) { | 107 | for ( it = list.begin(); it != list.end(); ++it ) { |
108 | if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { | 108 | if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { |
109 | label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); | 109 | label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); |
110 | if ( first ) | 110 | if ( first ) |
111 | first = false; | 111 | first = false; |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | return label; | 115 | return label; |
116 | } | 116 | } |
117 | 117 | ||
118 | QString PhoneNumber::label() const | 118 | QString PhoneNumber::label() const |
119 | { | 119 | { |
120 | return typeLabel( type() ); | 120 | return typeLabel( type() ); |
121 | } | 121 | } |
122 | 122 | ||
123 | PhoneNumber::TypeList PhoneNumber::typeList() | 123 | PhoneNumber::TypeList PhoneNumber::typeList() |
124 | { | 124 | { |
125 | TypeList list; | 125 | TypeList list; |
126 | 126 | ||
127 | list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video | 127 | list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video |
128 | << Bbs << Modem << Car << Isdn << Pcs << Pager; | 128 | << Bbs << Modem << Car << Isdn << Pcs << Pager; |
129 | 129 | ||
130 | return list; | 130 | return list; |
131 | } | 131 | } |
132 | 132 | ||
133 | QString PhoneNumber::label( int type ) | 133 | QString PhoneNumber::label( int type ) |
134 | { | 134 | { |
135 | return typeLabel( type ); | 135 | return typeLabel( type ); |
136 | } | 136 | } |
137 | 137 | ||
138 | QString PhoneNumber::typeLabel( int type ) | 138 | QString PhoneNumber::typeLabel( int type ) |
139 | { | 139 | { |
140 | switch ( type ) { | 140 | QString typeString; |
141 | case Home: | 141 | |
142 | return i18n("Home phone", "Home"); | 142 | if ((type & Home) == Home) |
143 | break; | 143 | typeString += i18n("Home"); |
144 | case Work: | 144 | else if ((type & Work) == Work) |
145 | return i18n("Work phone", "Work"); | 145 | typeString += i18n("Work"); |
146 | break; | 146 | |
147 | case Msg: | 147 | if (!typeString.isEmpty()) |
148 | return i18n("Messenger"); | 148 | typeString += " "; |
149 | break; | 149 | |
150 | case Pref: | 150 | if ((type & Cell) == Cell) |
151 | return i18n("Preferred Number"); | 151 | typeString += i18n("Mobile"); |
152 | break; | 152 | else if ((type & Fax) == Fax) |
153 | case Voice: | 153 | typeString += i18n("Fax"); |
154 | return i18n("Voice"); | 154 | else if ((type & Msg) == Msg) |
155 | break; | 155 | typeString += i18n("Messenger"); |
156 | case Fax: | 156 | else if ((type & Voice) == Voice) { |
157 | return i18n("Fax"); | 157 | // add nothing in case of the Voice flag |
158 | break; | 158 | // typeString += i18n("Voice"); |
159 | case Cell: | ||
160 | return i18n("Mobile Phone" ); | ||
161 | break; | ||
162 | case Cell | Home: | ||
163 | return i18n("Home Mobile" ); | ||
164 | break; | ||
165 | case Cell | Work: | ||
166 | return i18n("Home Mobile" ); | ||
167 | break; | ||
168 | case Video: | ||
169 | return i18n("Video"); | ||
170 | break; | ||
171 | case Bbs: | ||
172 | return i18n("Mailbox"); | ||
173 | break; | ||
174 | case Modem: | ||
175 | return i18n("Modem"); | ||
176 | break; | ||
177 | case Car: | ||
178 | return i18n("Car Phone", "Car" ); | ||
179 | break; | ||
180 | case Isdn: | ||
181 | return i18n("ISDN"); | ||
182 | break; | ||
183 | case Pcs: | ||
184 | return i18n("PCS"); | ||
185 | break; | ||
186 | case Pager: | ||
187 | return i18n("Pager"); | ||
188 | break; | ||
189 | case Work | Pager: | ||
190 | return i18n("Work Pager"); | ||
191 | break; | ||
192 | case Home | Fax: | ||
193 | return i18n("Home Fax"); | ||
194 | break; | ||
195 | case Work | Fax: | ||
196 | return i18n("Work Fax"); | ||
197 | break; | ||
198 | default: | ||
199 | return i18n("Other"); | ||
200 | } | 159 | } |
160 | else if ((type & Video) == Video) | ||
161 | typeString += i18n("Video"); | ||
162 | else if ((type & Bbs) == Bbs) | ||
163 | typeString += i18n("Mailbox"); | ||
164 | else if ((type & Modem) == Modem) | ||
165 | typeString += i18n("Modem"); | ||
166 | else if ((type & Car) == Car) | ||
167 | typeString += i18n("Car"); | ||
168 | else if ((type & Isdn) == Isdn) | ||
169 | typeString += i18n("ISDN"); | ||
170 | else if ((type & Pcs) == Pcs) | ||
171 | typeString += i18n("PCS"); | ||
172 | else if ((type & Pager) == Pager) | ||
173 | typeString += i18n("Pager"); | ||
174 | |||
175 | // add the prefered flag | ||
176 | if (!typeString.isEmpty()) | ||
177 | typeString += " "; | ||
178 | |||
179 | if ((type & Pref) == Pref) | ||
180 | typeString += i18n("(Preferred)"); | ||
181 | |||
182 | //if we still have no match, return "other" | ||
183 | if (typeString.isEmpty()) | ||
184 | return i18n("Other"); | ||
185 | |||
186 | |||
187 | return typeString; | ||
201 | } | 188 | } |
202 | 189 | ||
203 | QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) | 190 | QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) |
204 | { | 191 | { |
205 | return s << phone.mId << phone.mType << phone.mNumber; | 192 | return s << phone.mId << phone.mType << phone.mNumber; |
206 | } | 193 | } |
207 | 194 | ||
208 | QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) | 195 | QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) |
209 | { | 196 | { |
210 | s >> phone.mId >> phone.mType >> phone.mNumber; | 197 | s >> phone.mId >> phone.mType >> phone.mNumber; |
211 | 198 | ||
212 | return s; | 199 | return s; |
213 | } | 200 | } |