-rw-r--r-- | kabc/phonenumber.cpp | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp new file mode 100644 index 0000000..ad3e65b --- a/dev/null +++ b/kabc/phonenumber.cpp | |||
@@ -0,0 +1,204 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
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 | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <kapplication.h> | ||
29 | #include <klocale.h> | ||
30 | |||
31 | #include "phonenumber.h" | ||
32 | |||
33 | using namespace KABC; | ||
34 | |||
35 | PhoneNumber::PhoneNumber() : | ||
36 | mType( Home ) | ||
37 | { | ||
38 | init(); | ||
39 | } | ||
40 | |||
41 | PhoneNumber::PhoneNumber( const QString &number, int type ) : | ||
42 | mType( type ), mNumber( number ) | ||
43 | { | ||
44 | init(); | ||
45 | } | ||
46 | |||
47 | PhoneNumber::~PhoneNumber() | ||
48 | { | ||
49 | } | ||
50 | |||
51 | void PhoneNumber::init() | ||
52 | { | ||
53 | mId = KApplication::randomString( 8 ); | ||
54 | } | ||
55 | |||
56 | bool PhoneNumber::operator==( const PhoneNumber &p ) const | ||
57 | { | ||
58 | if ( mNumber != p.mNumber ) return false; | ||
59 | if ( mType != p.mType ) return false; | ||
60 | |||
61 | return true; | ||
62 | } | ||
63 | |||
64 | bool PhoneNumber::operator!=( const PhoneNumber &p ) const | ||
65 | { | ||
66 | return !( p == *this ); | ||
67 | } | ||
68 | |||
69 | void PhoneNumber::setId( const QString &id ) | ||
70 | { | ||
71 | mId = id; | ||
72 | } | ||
73 | |||
74 | QString PhoneNumber::id() const | ||
75 | { | ||
76 | return mId; | ||
77 | } | ||
78 | |||
79 | void PhoneNumber::setNumber( const QString &number ) | ||
80 | { | ||
81 | mNumber = number; | ||
82 | } | ||
83 | |||
84 | QString PhoneNumber::number() const | ||
85 | { | ||
86 | return mNumber; | ||
87 | } | ||
88 | |||
89 | void PhoneNumber::setType( int type ) | ||
90 | { | ||
91 | mType = type; | ||
92 | } | ||
93 | |||
94 | int PhoneNumber::type() const | ||
95 | { | ||
96 | return mType; | ||
97 | } | ||
98 | |||
99 | QString PhoneNumber::typeLabel() const | ||
100 | { | ||
101 | QString label; | ||
102 | bool first = true; | ||
103 | |||
104 | TypeList list = typeList(); | ||
105 | |||
106 | TypeList::Iterator it; | ||
107 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
108 | if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { | ||
109 | label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); | ||
110 | if ( first ) | ||
111 | first = false; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | return label; | ||
116 | } | ||
117 | |||
118 | QString PhoneNumber::label() const | ||
119 | { | ||
120 | return typeLabel( type() ); | ||
121 | } | ||
122 | |||
123 | PhoneNumber::TypeList PhoneNumber::typeList() | ||
124 | { | ||
125 | TypeList list; | ||
126 | |||
127 | list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video | ||
128 | << Bbs << Modem << Car << Isdn << Pcs << Pager; | ||
129 | |||
130 | return list; | ||
131 | } | ||
132 | |||
133 | QString PhoneNumber::label( int type ) | ||
134 | { | ||
135 | return typeLabel( type ); | ||
136 | } | ||
137 | |||
138 | QString PhoneNumber::typeLabel( int type ) | ||
139 | { | ||
140 | switch ( type ) { | ||
141 | case Home: | ||
142 | return i18n("Home phone", "Home"); | ||
143 | break; | ||
144 | case Work: | ||
145 | return i18n("Work phone", "Work"); | ||
146 | break; | ||
147 | case Msg: | ||
148 | return i18n("Messenger"); | ||
149 | break; | ||
150 | case Pref: | ||
151 | return i18n("Preferred Number"); | ||
152 | break; | ||
153 | case Voice: | ||
154 | return i18n("Voice"); | ||
155 | break; | ||
156 | case Fax: | ||
157 | return i18n("Fax"); | ||
158 | break; | ||
159 | case Cell: | ||
160 | return i18n("Mobile Phone", "Mobile" ); | ||
161 | break; | ||
162 | case Video: | ||
163 | return i18n("Video"); | ||
164 | break; | ||
165 | case Bbs: | ||
166 | return i18n("Mailbox"); | ||
167 | break; | ||
168 | case Modem: | ||
169 | return i18n("Modem"); | ||
170 | break; | ||
171 | case Car: | ||
172 | return i18n("Car Phone", "Car" ); | ||
173 | break; | ||
174 | case Isdn: | ||
175 | return i18n("ISDN"); | ||
176 | break; | ||
177 | case Pcs: | ||
178 | return i18n("PCS"); | ||
179 | break; | ||
180 | case Pager: | ||
181 | return i18n("Pager"); | ||
182 | break; | ||
183 | case Home | Fax: | ||
184 | return i18n("Home Fax"); | ||
185 | break; | ||
186 | case Work | Fax: | ||
187 | return i18n("Work Fax"); | ||
188 | break; | ||
189 | default: | ||
190 | return i18n("Other"); | ||
191 | } | ||
192 | } | ||
193 | |||
194 | QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) | ||
195 | { | ||
196 | return s << phone.mId << phone.mType << phone.mNumber; | ||
197 | } | ||
198 | |||
199 | QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) | ||
200 | { | ||
201 | s >> phone.mId >> phone.mType >> phone.mNumber; | ||
202 | |||
203 | return s; | ||
204 | } | ||