summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-12 20:14:39 (UTC)
committer zautrix <zautrix>2004-10-12 20:14:39 (UTC)
commit77e3a7bc670f4c9b7eb5a5d6652a7986ea196533 (patch) (unidiff)
tree963c068c7648899a4c3ac26542605f05492019c5
parentd3759373291c08d2cde93d85a76d190dc8a33830 (diff)
downloadkdepimpi-77e3a7bc670f4c9b7eb5a5d6652a7986ea196533.zip
kdepimpi-77e3a7bc670f4c9b7eb5a5d6652a7986ea196533.tar.gz
kdepimpi-77e3a7bc670f4c9b7eb5a5d6652a7986ea196533.tar.bz2
Changed phone number sorting in details view
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseeview.cpp135
-rw-r--r--kabc/addresseeview.h1
-rw-r--r--kabc/phonenumber.cpp4
-rw-r--r--kaddressbook/phoneeditwidget.cpp6
4 files changed, 78 insertions, 68 deletions
diff --git a/kabc/addresseeview.cpp b/kabc/addresseeview.cpp
index 2dda968..af149a0 100644
--- a/kabc/addresseeview.cpp
+++ b/kabc/addresseeview.cpp
@@ -1,464 +1,475 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 3
4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <kabc/address.h> 22#include <kabc/address.h>
23#include <kabc/addressee.h> 23#include <kabc/addressee.h>
24#include <kabc/phonenumber.h> 24#include <kabc/phonenumber.h>
25#include <kglobal.h> 25#include <kglobal.h>
26//US#include <kglobalsettings.h> 26//US#include <kglobalsettings.h>
27#include <kiconloader.h> 27#include <kiconloader.h>
28#include <klocale.h> 28#include <klocale.h>
29//US #include <kstringhandler.h> 29//US #include <kstringhandler.h>
30#include <qscrollview.h> 30#include <qscrollview.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qfile.h> 32#include <qfile.h>
33#include <qvbox.h> 33#include <qvbox.h>
34#include <qlabel.h> 34#include <qlabel.h>
35#include <qwidget.h> 35#include <qwidget.h>
36#include <qlayout.h> 36#include <qlayout.h>
37#include <qapplication.h> 37#include <qapplication.h>
38#include <qpushbutton.h> 38#include <qpushbutton.h>
39 39
40 40
41#include "externalapphandler.h" 41#include "externalapphandler.h"
42#include "addresseeview.h" 42#include "addresseeview.h"
43 43
44 44
45//US #ifndef DESKTOP_VERSION 45//US #ifndef DESKTOP_VERSION
46//US #include <qtopia/qcopenvelope_qws.h> 46//US #include <qtopia/qcopenvelope_qws.h>
47//US #include <qpe/qpeapplication.h> 47//US #include <qpe/qpeapplication.h>
48//US #endif 48//US #endif
49 49
50//US static int kphoneInstalled = 0; 50//US static int kphoneInstalled = 0;
51 51
52using namespace KPIM; 52using namespace KPIM;
53 53
54AddresseeView::AddresseeView( QWidget *parent, const char *name ) 54AddresseeView::AddresseeView( QWidget *parent, const char *name )
55//US : KTextBrowser( parent, name ) 55//US : KTextBrowser( parent, name )
56 : QTextBrowser( parent, name ) 56 : QTextBrowser( parent, name )
57 57
58 58
59{ 59{
60//US setWrapPolicy( QTextEdit::AtWordBoundary ); 60//US setWrapPolicy( QTextEdit::AtWordBoundary );
61 setLinkUnderline( false ); 61 setLinkUnderline( false );
62 // setVScrollBarMode( QScrollView::AlwaysOff ); 62 // setVScrollBarMode( QScrollView::AlwaysOff );
63 //setHScrollBarMode( QScrollView::AlwaysOff ); 63 //setHScrollBarMode( QScrollView::AlwaysOff );
64 64
65//US QStyleSheet *sheet = styleSheet(); 65//US QStyleSheet *sheet = styleSheet();
66//US QStyleSheetItem *link = sheet->item( "a" ); 66//US QStyleSheetItem *link = sheet->item( "a" );
67//US link->setColor( KGlobalSettings::linkColor() ); 67//US link->setColor( KGlobalSettings::linkColor() );
68 68
69} 69}
70 70
71void AddresseeView::setSource(const QString& n) 71void AddresseeView::setSource(const QString& n)
72{ 72{
73 //qDebug("********AddresseeView::setSource %s", n.latin1()); 73 //qDebug("********AddresseeView::setSource %s", n.latin1());
74 74
75 if ( n.left( 6 ) == "mailto" ) 75 if ( n.left( 6 ) == "mailto" )
76 ExternalAppHandler::instance()->mailToOneContact( n.mid(7) ); 76 ExternalAppHandler::instance()->mailToOneContact( n.mid(7) );
77 else if ( n.left( 7 ) == "phoneto" ) 77 else if ( n.left( 7 ) == "phoneto" )
78 ExternalAppHandler::instance()->callByPhone( n.mid(8) ); 78 ExternalAppHandler::instance()->callByPhone( n.mid(8) );
79 else if ( n.left( 5 ) == "faxto" ) 79 else if ( n.left( 5 ) == "faxto" )
80 ExternalAppHandler::instance()->callByFax( n.mid(6) ); 80 ExternalAppHandler::instance()->callByFax( n.mid(6) );
81 else if ( n.left( 5 ) == "smsto" ) 81 else if ( n.left( 5 ) == "smsto" )
82 ExternalAppHandler::instance()->callBySMS( n.mid(6) ); 82 ExternalAppHandler::instance()->callBySMS( n.mid(6) );
83 else if ( n.left( 7 ) == "pagerto" ) 83 else if ( n.left( 7 ) == "pagerto" )
84 ExternalAppHandler::instance()->callByPager( n.mid(8) ); 84 ExternalAppHandler::instance()->callByPager( n.mid(8) );
85 else if ( n.left( 5 ) == "sipto" ) 85 else if ( n.left( 5 ) == "sipto" )
86 ExternalAppHandler::instance()->callBySIP( n.mid(6) ); 86 ExternalAppHandler::instance()->callBySIP( n.mid(6) );
87 87
88} 88}
89void AddresseeView::setAddressee( const KABC::Addressee& addr ) 89void AddresseeView::setAddressee( const KABC::Addressee& addr )
90{ 90{
91 ExternalAppHandler* eah = ExternalAppHandler::instance(); 91 ExternalAppHandler* eah = ExternalAppHandler::instance();
92 bool kemailAvail = eah->isEmailAppAvailable(); 92 bool kemailAvail = eah->isEmailAppAvailable();
93 bool kphoneAvail = eah->isPhoneAppAvailable(); 93
94 bool kfaxAvail = eah->isFaxAppAvailable();
95 bool ksmsAvail = eah->isSMSAppAvailable();
96 bool kpagerAvail = eah->isPagerAppAvailable();
97 bool ksipAvail = eah->isSIPAppAvailable();
98 94
99 95
100 mAddressee = addr; 96 mAddressee = addr;
101 // clear view 97 // clear view
102 setText( QString::null ); 98 setText( QString::null );
103 99
104 if ( mAddressee.isEmpty() ) 100 if ( mAddressee.isEmpty() )
105 return; 101 return;
106 102
107 QString name = ( mAddressee.assembledName().isEmpty() ? 103 QString name = ( mAddressee.assembledName().isEmpty() ?
108 mAddressee.formattedName() : mAddressee.assembledName() ); 104 mAddressee.formattedName() : mAddressee.assembledName() );
109 105
110 QString dynamicPart; 106 QString dynamicPart;
111 107
108 dynamicPart += getPhoneNumbers( true );
109 qDebug("dynamic preferred %s ",dynamicPart.latin1() );
112 QStringList emails = mAddressee.emails(); 110 QStringList emails = mAddressee.emails();
113 QStringList::ConstIterator emailIt; 111 QStringList::ConstIterator emailIt;
114 QString type = i18n( "Email" ); 112 QString type = i18n( "Email" );
115 emailIt = emails.begin(); 113 emailIt = emails.begin();
116 if ( emailIt != emails.end() ) { 114 if ( emailIt != emails.end() ) {
117 if ( kemailAvail ) { 115 if ( kemailAvail ) {
118 dynamicPart += QString( 116 dynamicPart += QString(
119 "<tr><td align=\"right\"><b>%1</b></td>" 117 "<tr><td align=\"right\"><b>%1</b></td>"
120 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) 118 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" )
121 .arg( type ) 119 .arg( type )
122 .arg( name ) 120 .arg( name )
123 .arg( *emailIt ) 121 .arg( *emailIt )
124 .arg( *emailIt ); 122 .arg( *emailIt );
125 ++emailIt; 123 ++emailIt;
126 } else { 124 } else {
127 dynamicPart += QString( 125 dynamicPart += QString(
128 "<tr><td align=\"right\"><b>%1</b></td>" 126 "<tr><td align=\"right\"><b>%1</b></td>"
129 "<td align=\"left\">%2</td></tr>" ) 127 "<td align=\"left\">%2</td></tr>" )
130 .arg( type ) 128 .arg( type )
131 .arg( *emailIt ); 129 .arg( *emailIt );
132 ++emailIt; 130 ++emailIt;
133 } 131 }
134 } 132 }
135 if ( mAddressee.birthday().date().isValid() ) { 133 if ( mAddressee.birthday().date().isValid() ) {
136 dynamicPart += QString( 134 dynamicPart += QString(
137 "<tr><td align=\"right\"><b>%1</b></td>" 135 "<tr><td align=\"right\"><b>%1</b></td>"
138 "<td align=\"left\">%2</td></tr>" ) 136 "<td align=\"left\">%2</td></tr>" )
139 .arg( i18n ("Birthday") ) 137 .arg( i18n ("Birthday") )
140 .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) ); 138 .arg( KGlobal::locale()->formatDate( mAddressee.birthday().date() ,true) );
141 } 139 }
142 KABC::PhoneNumber::List phones = mAddressee.phoneNumbers(); 140 dynamicPart += getPhoneNumbers( false );
143 KABC::PhoneNumber::List::ConstIterator phoneIt;
144 QString extension;
145 int phonetype;
146 QString sms;
147 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
148 phonetype = (*phoneIt).type();
149 if (ksmsAvail &&
150 (
151 ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) ||
152 ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell)
153 )
154 )
155 {
156 sms = QString("<a href=\"smsto:%1 \">(sms)</a>" )
157 .arg( (*phoneIt).number() );
158
159 }
160 else
161 sms = "";
162
163 extension = QString::null;
164 if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) {
165 if (kfaxAvail) extension = "faxto:";
166 }
167 else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) {
168 if (kpagerAvail) extension = "pagerto:";
169 }
170 else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) {
171 if (ksipAvail) extension = "sipto:";
172 }
173 else if (kphoneAvail) {
174 extension = "phoneto:";
175 }
176 else
177 extension = QString::null;
178
179 if ( !extension.isEmpty() ) {
180 dynamicPart += QString(
181 "<tr><td align=\"right\"><b>%1</b></td>"
182 "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" )
183 .arg( KABC::PhoneNumber::typeLabel( phonetype ) )
184 .arg( extension )
185 .arg( (*phoneIt).number() )
186 .arg( (*phoneIt).number() )
187 .arg( sms );
188
189 } else {
190 dynamicPart += QString(
191 "<tr><td align=\"right\"><b>%1</b></td>"
192 "<td align=\"left\">%2 %3</td></tr>" )
193 .arg( KABC::PhoneNumber::typeLabel( phonetype ) )
194 .arg( (*phoneIt).number() )
195 .arg( sms );
196 }
197 }
198
199 141
200 for ( ; emailIt != emails.end(); ++emailIt ) { 142 for ( ; emailIt != emails.end(); ++emailIt ) {
201 if ( kemailAvail ) { 143 if ( kemailAvail ) {
202 dynamicPart += QString( 144 dynamicPart += QString(
203 "<tr><td align=\"right\"><b>%1</b></td>" 145 "<tr><td align=\"right\"><b>%1</b></td>"
204 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" ) 146 "<td align=\"left\"><a href=\"mailto:%2 <%3> \">%4</a></td></tr>" )
205 .arg( type ) 147 .arg( type )
206 .arg( name ) 148 .arg( name )
207 .arg( *emailIt ) 149 .arg( *emailIt )
208 .arg( *emailIt ); 150 .arg( *emailIt );
209 } else { 151 } else {
210 dynamicPart += QString( 152 dynamicPart += QString(
211 "<tr><td align=\"right\"><b>%1</b></td>" 153 "<tr><td align=\"right\"><b>%1</b></td>"
212 "<td align=\"left\">%2</td></tr>" ) 154 "<td align=\"left\">%2</td></tr>" )
213 .arg( type ) 155 .arg( type )
214 .arg( *emailIt ); 156 .arg( *emailIt );
215 } 157 }
216 } 158 }
217 159
218 if ( !mAddressee.url().url().isEmpty() ) { 160 if ( !mAddressee.url().url().isEmpty() ) {
219 dynamicPart += QString( 161 dynamicPart += QString(
220 "<tr><td align=\"right\"><b>%1</b></td>" 162 "<tr><td align=\"right\"><b>%1</b></td>"
221 "<td align=\"left\">%2</td></tr>" ) 163 "<td align=\"left\">%2</td></tr>" )
222 .arg( i18n( "Homepage" ) ) 164 .arg( i18n( "Homepage" ) )
223//US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) ); 165//US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) );
224 .arg( mAddressee.url().url() ); 166 .arg( mAddressee.url().url() );
225 //qDebug("AddresseeView::setAddressee has to be verified."); 167 //qDebug("AddresseeView::setAddressee has to be verified.");
226 } 168 }
227 169
228 KABC::Address::List addresses = mAddressee.addresses(); 170 KABC::Address::List addresses = mAddressee.addresses();
229 KABC::Address::List::ConstIterator addrIt; 171 KABC::Address::List::ConstIterator addrIt;
230 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) { 172 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
231 if ( true /*(*addrIt).label().isEmpty()*/ ) { 173 if ( true /*(*addrIt).label().isEmpty()*/ ) {
232 QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace(); 174 QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace();
233//US formattedAddress = formattedAddress.replace( '\n', "<br>" ); 175//US formattedAddress = formattedAddress.replace( '\n', "<br>" );
234 //qDebug("adresss %s ",formattedAddress.latin1() ); 176 //qDebug("adresss %s ",formattedAddress.latin1() );
235 formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" ); 177 formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" );
236 //qDebug("AddresseeView::setAddressee has to be verified."); 178 //qDebug("AddresseeView::setAddressee has to be verified.");
237 179
238 dynamicPart += QString( 180 dynamicPart += QString(
239 "<tr><td align=\"right\"><b>%1</b></td>" 181 "<tr><td align=\"right\"><b>%1</b></td>"
240 "<td align=\"left\">%2</td></tr>" ) 182 "<td align=\"left\">%2</td></tr>" )
241 .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) 183 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
242 .arg( formattedAddress ); 184 .arg( formattedAddress );
243 } else { 185 } else {
244 186
245 dynamicPart += QString( 187 dynamicPart += QString(
246 "<tr><td align=\"right\"><b>%1</b></td>" 188 "<tr><td align=\"right\"><b>%1</b></td>"
247 "<td align=\"left\">%2</td></tr>" ) 189 "<td align=\"left\">%2</td></tr>" )
248 .arg( KABC::Address::typeLabel( (*addrIt).type() ) ) 190 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
249//US .arg( (*addrIt).label().replace( '\n', "<br>" ) ); 191//US .arg( (*addrIt).label().replace( '\n', "<br>" ) );
250 .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ ); 192 .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ );
251 193
252 } 194 }
253 } 195 }
254 196
255 QString notes; 197 QString notes;
256 if ( !mAddressee.note().isEmpty() ) { 198 if ( !mAddressee.note().isEmpty() ) {
257 notes = QString( 199 notes = QString(
258 "<tr>" 200 "<tr>"
259 "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label 201 "<td align=\"right\" valign=\"top\"><b>%1</b></td>" // note label
260 "<td align=\"left\">%2</td>" // note 202 "<td align=\"left\">%2</td>" // note
261 "</tr>" ).arg( i18n( "Notes" ) ) 203 "</tr>" ).arg( i18n( "Notes" ) )
262//US .arg( mAddressee.note().replace( '\n', "<br>" ) ); 204//US .arg( mAddressee.note().replace( '\n', "<br>" ) );
263 .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) ); 205 .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) );
264 //qDebug("AddresseeView::setAddressee has to be verified."); 206 //qDebug("AddresseeView::setAddressee has to be verified.");
265 } 207 }
266 208
267 QString aRole = ""; 209 QString aRole = "";
268 QString aOrga = ""; 210 QString aOrga = "";
269 if ( true /*!mAddressee.role().isEmpty()*/ ) { 211 if ( true /*!mAddressee.role().isEmpty()*/ ) {
270 aRole = "<tr>" 212 aRole = "<tr>"
271 "<td align=\"left\">" + mAddressee.role() + "</td>" 213 "<td align=\"left\">" + mAddressee.role() + "</td>"
272 "</tr>"; 214 "</tr>";
273 } 215 }
274 if ( true /*!mAddressee.organization().isEmpty()*/ ) { 216 if ( true /*!mAddressee.organization().isEmpty()*/ ) {
275 aOrga = "<tr>" 217 aOrga = "<tr>"
276 "<td align=\"left\">" + mAddressee.organization() + "</td>" ; 218 "<td align=\"left\">" + mAddressee.organization() + "</td>" ;
277 "</tr>"; 219 "</tr>";
278 } 220 }
279 mText = ""; 221 mText = "";
280 QString picString = ""; 222 QString picString = "";
281 KABC::Picture picture = mAddressee.photo(); 223 KABC::Picture picture = mAddressee.photo();
282 bool picAvailintern = false; 224 bool picAvailintern = false;
283 bool picAvailUrl = false; 225 bool picAvailUrl = false;
284 if (! picture.undefined() ) { 226 if (! picture.undefined() ) {
285 picAvailintern = (picture.isIntern() && !picture.data().isNull()); 227 picAvailintern = (picture.isIntern() && !picture.data().isNull());
286 picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() ); 228 picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() );
287 } 229 }
288 if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) { 230 if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) {
289 if ( picAvailintern ) { 231 if ( picAvailintern ) {
290 QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() ); 232 QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() );
291 } else { 233 } else {
292 if ( picAvailUrl ) { 234 if ( picAvailUrl ) {
293 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() )); 235 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() ));
294 } else { 236 } else {
295 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) ); 237 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) );
296 } 238 }
297 } 239 }
298 picString = "<img src=\"myimage\" width=\"50\" height=\"70\">"; 240 picString = "<img src=\"myimage\" width=\"50\" height=\"70\">";
299 mText = QString::fromLatin1( 241 mText = QString::fromLatin1(
300 "<html>" 242 "<html>"
301 "<body text=\"%1\" bgcolor=\"%2\">" // text and background color 243 "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
302 "<table>" 244 "<table>"
303 "<tr>" 245 "<tr>"
304 "<td rowspan=\"3\" align=\"right\" valign=\"top\">" 246 "<td rowspan=\"3\" align=\"right\" valign=\"top\">"
305 "%3" 247 "%3"
306 "</td>" 248 "</td>"
307 "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name 249 "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name
308 "</tr>" 250 "</tr>"
309 "%5" // role 251 "%5" // role
310 "%6" // organization 252 "%6" // organization
311 "<td colspan=\"2\">&nbsp;</td>" 253 "<td colspan=\"2\">&nbsp;</td>"
312 "%7" // dynamic part 254 "%7" // dynamic part
313 "%8" // notes 255 "%8" // notes
314 "</table>" 256 "</table>"
315 "</body>" 257 "</body>"
316 "</html>") 258 "</html>")
317//US 259//US
318 .arg( /*KGlobalSettings::textColor().name()*/ "black" ) 260 .arg( /*KGlobalSettings::textColor().name()*/ "black" )
319//US 261//US
320 .arg( /*KGlobalSettings::baseColor().name()*/ "white" ) 262 .arg( /*KGlobalSettings::baseColor().name()*/ "white" )
321 .arg( picString ) 263 .arg( picString )
322 .arg( name ) 264 .arg( name )
323 .arg( aRole ) 265 .arg( aRole )
324 .arg( aOrga ) 266 .arg( aOrga )
325 .arg( dynamicPart ) 267 .arg( dynamicPart )
326 .arg( notes ); 268 .arg( notes );
327 269
328 } else { // no picture! 270 } else { // no picture!
329 271
330mText = "<table width=\"100%\">\n"; 272mText = "<table width=\"100%\">\n";
331 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>"; 273 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
332#ifdef DESKTOP_VERSION 274#ifdef DESKTOP_VERSION
333 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>"; 275 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>";
334#else 276#else
335 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>"; 277 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>";
336#endif 278#endif
337 279
338#ifdef DESKTOP_VERSION 280#ifdef DESKTOP_VERSION
339 mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>"; 281 mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>";
340#else 282#else
341 mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>"; 283 mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>";
342#endif 284#endif
343 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>"; 285 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
344 286
345 mText += "<table><td colspan=\"2\">&nbsp;</td>"; 287 mText += "<table><td colspan=\"2\">&nbsp;</td>";
346 /* 288 /*
347 mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>" 289 mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>"
348 "<td align=\"left\"><b>%2</b></td></tr>" ) 290 "<td align=\"left\"><b>%2</b></td></tr>" )
349 .arg( i18n(" ") ) 291 .arg( i18n(" ") )
350 .arg( name ); 292 .arg( name );
351 */ 293 */
352 if ( ! mAddressee.role().isEmpty() ) 294 if ( ! mAddressee.role().isEmpty() )
353 mText += QString("<tr><td align=\"right\"><b>%1</b></td>" 295 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
354 "<td align=\"left\">%2</td></tr>" ) 296 "<td align=\"left\">%2</td></tr>" )
355 .arg( i18n(" ") ) 297 .arg( i18n(" ") )
356 .arg( mAddressee.role()); 298 .arg( mAddressee.role());
357 if ( ! mAddressee.organization().isEmpty() ) 299 if ( ! mAddressee.organization().isEmpty() )
358 mText += QString("<tr><td align=\"right\"><b>%1</b></td>" 300 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
359 "<td align=\"left\">%2</td></tr>" ) 301 "<td align=\"left\">%2</td></tr>" )
360 .arg( i18n(" ") ) 302 .arg( i18n(" ") )
361 .arg( mAddressee.organization()); 303 .arg( mAddressee.organization());
362 mText += dynamicPart; 304 mText += dynamicPart;
363 mText += notes; 305 mText += notes;
364 mText += "</table>"; 306 mText += "</table>";
365 307
366 } 308 }
367 309
368 // at last display it... 310 // at last display it...
369 setText( mText ); 311 setText( mText );
370 312
371} 313}
372 314
315QString AddresseeView::getPhoneNumbers( bool preferred )
316{
317 ExternalAppHandler* eah = ExternalAppHandler::instance();
318 bool kphoneAvail = eah->isPhoneAppAvailable();
319 bool kfaxAvail = eah->isFaxAppAvailable();
320 bool ksmsAvail = eah->isSMSAppAvailable();
321 bool kpagerAvail = eah->isPagerAppAvailable();
322 bool ksipAvail = eah->isSIPAppAvailable();
323 QString dynamicPart;
324 KABC::PhoneNumber::List phones = mAddressee.phoneNumbers();
325 KABC::PhoneNumber::List::ConstIterator phoneIt;
326 QString extension;
327 int phonetype;
328 QString sms;
329 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
330 phonetype = (*phoneIt).type();
331 if ( ((phonetype & KABC::PhoneNumber::Pref) == 0 ) == preferred )
332 continue;
333 if (ksmsAvail &&
334 (
335 ((phonetype & KABC::PhoneNumber::Car) == KABC::PhoneNumber::Car) ||
336 ((phonetype & KABC::PhoneNumber::Cell) == KABC::PhoneNumber::Cell)
337 )
338 )
339 {
340 sms = QString("<a href=\"smsto:%1 \">(sms)</a>" )
341 .arg( (*phoneIt).number() );
342
343 }
344 else
345 sms = "";
346
347 extension = QString::null;
348 if ((phonetype & KABC::PhoneNumber::Fax) == KABC::PhoneNumber::Fax) {
349 if (kfaxAvail) extension = "faxto:";
350 }
351 else if ((phonetype & KABC::PhoneNumber::Pager) == KABC::PhoneNumber::Pager) {
352 if (kpagerAvail) extension = "pagerto:";
353 }
354 else if ((phonetype & KABC::PhoneNumber::Sip) == KABC::PhoneNumber::Sip) {
355 if (ksipAvail) extension = "sipto:";
356 }
357 else if (kphoneAvail) {
358 extension = "phoneto:";
359 }
360 else
361 extension = QString::null;
362
363 if ( !extension.isEmpty() ) {
364 dynamicPart += QString(
365 "<tr><td align=\"right\"><b>%1</b></td>"
366 "<td align=\"left\"><a href=\"%2%3 \">%4</a> %5</td></tr>" )
367 .arg( KABC::PhoneNumber::typeLabel( phonetype ) )
368 .arg( extension )
369 .arg( (*phoneIt).number() )
370 .arg( (*phoneIt).number() )
371 .arg( sms );
372
373 } else {
374 dynamicPart += QString(
375 "<tr><td align=\"right\"><b>%1</b></td>"
376 "<td align=\"left\">%2 %3</td></tr>" )
377 .arg( KABC::PhoneNumber::typeLabel( phonetype ) )
378 .arg( (*phoneIt).number() )
379 .arg( sms );
380 }
381 }
382 return dynamicPart;
383}
373KABC::Addressee AddresseeView::addressee() const 384KABC::Addressee AddresseeView::addressee() const
374{ 385{
375 return mAddressee; 386 return mAddressee;
376} 387}
377void AddresseeView::addTag(const QString & tag,const QString & text) 388void AddresseeView::addTag(const QString & tag,const QString & text)
378{ 389{
379 if ( text.isEmpty() ) 390 if ( text.isEmpty() )
380 return; 391 return;
381 int number=text.contains("\n"); 392 int number=text.contains("\n");
382 QString str = "<" + tag + ">"; 393 QString str = "<" + tag + ">";
383 QString tmpText=text; 394 QString tmpText=text;
384 QString tmpStr=str; 395 QString tmpStr=str;
385 if(number !=-1) 396 if(number !=-1)
386 { 397 {
387 if (number > 0) { 398 if (number > 0) {
388 int pos=0; 399 int pos=0;
389 QString tmp; 400 QString tmp;
390 for(int i=0;i<=number;i++) { 401 for(int i=0;i<=number;i++) {
391 pos=tmpText.find("\n"); 402 pos=tmpText.find("\n");
392 tmp=tmpText.left(pos); 403 tmp=tmpText.left(pos);
393 tmpText=tmpText.right(tmpText.length()-pos-1); 404 tmpText=tmpText.right(tmpText.length()-pos-1);
394 tmpStr+=tmp+"<br>"; 405 tmpStr+=tmp+"<br>";
395 } 406 }
396 } 407 }
397 else tmpStr += tmpText; 408 else tmpStr += tmpText;
398 tmpStr+="</" + tag + ">"; 409 tmpStr+="</" + tag + ">";
399 mText.append(tmpStr); 410 mText.append(tmpStr);
400 } 411 }
401 else 412 else
402 { 413 {
403 str += text + "</" + tag + ">"; 414 str += text + "</" + tag + ">";
404 mText.append(str); 415 mText.append(str);
405 } 416 }
406} 417}
407 418
408AddresseeChooser::AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name, 419AddresseeChooser::AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent, const char *name ) : KDialogBase(parent,name,
409 true ,i18n("Conflict! Please choose Adressee!"),Ok|User1|Close,Close, false) 420 true ,i18n("Conflict! Please choose Adressee!"),Ok|User1|Close,Close, false)
410{ 421{
411 findButton( Close )->setText( i18n("Cancel Sync")); 422 findButton( Close )->setText( i18n("Cancel Sync"));
412 findButton( Ok )->setText( i18n("Remote")); 423 findButton( Ok )->setText( i18n("Remote"));
413 findButton( User1 )->setText( i18n("Local")); 424 findButton( User1 )->setText( i18n("Local"));
414 QWidget* topframe = new QWidget( this ); 425 QWidget* topframe = new QWidget( this );
415 setMainWidget( topframe ); 426 setMainWidget( topframe );
416 QBoxLayout* bl; 427 QBoxLayout* bl;
417 if ( QApplication::desktop()->width() < 640 ) { 428 if ( QApplication::desktop()->width() < 640 ) {
418 bl = new QVBoxLayout( topframe ); 429 bl = new QVBoxLayout( topframe );
419 } else { 430 } else {
420 bl = new QHBoxLayout( topframe ); 431 bl = new QHBoxLayout( topframe );
421 } 432 }
422 QVBox* subframe = new QVBox( topframe ); 433 QVBox* subframe = new QVBox( topframe );
423 bl->addWidget(subframe ); 434 bl->addWidget(subframe );
424 QLabel* lab = new QLabel( i18n("Local Addressee"), subframe ); 435 QLabel* lab = new QLabel( i18n("Local Addressee"), subframe );
425 if ( takeloc ) 436 if ( takeloc )
426 lab->setBackgroundColor(Qt::green.light() ); 437 lab->setBackgroundColor(Qt::green.light() );
427 AddresseeView * av = new AddresseeView( subframe ); 438 AddresseeView * av = new AddresseeView( subframe );
428 av->setAddressee( loc ); 439 av->setAddressee( loc );
429 subframe = new QVBox( topframe ); 440 subframe = new QVBox( topframe );
430 bl->addWidget(subframe ); 441 bl->addWidget(subframe );
431 lab = new QLabel( i18n("Remote Addressee"), subframe ); 442 lab = new QLabel( i18n("Remote Addressee"), subframe );
432 if ( !takeloc ) 443 if ( !takeloc )
433 lab->setBackgroundColor(Qt::green.light() ); 444 lab->setBackgroundColor(Qt::green.light() );
434 av = new AddresseeView( subframe ); 445 av = new AddresseeView( subframe );
435 av->setAddressee( rem ); 446 av->setAddressee( rem );
436 QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote())); 447 QObject::connect(findButton( Ok ),SIGNAL(clicked()),this, SLOT(slot_remote()));
437 QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local())); 448 QObject::connect(this,SIGNAL(user1Clicked()),this, SLOT(slot_local()));
438#ifndef DESKTOP_VERSION 449#ifndef DESKTOP_VERSION
439 showMaximized(); 450 showMaximized();
440#else 451#else
441 resize ( 640, 400 ); 452 resize ( 640, 400 );
442#endif 453#endif
443} 454}
444 455
445int AddresseeChooser::executeD( bool local ) 456int AddresseeChooser::executeD( bool local )
446{ 457{
447 mSyncResult = 3; 458 mSyncResult = 3;
448 if ( local ) 459 if ( local )
449 findButton( User1 )->setFocus(); 460 findButton( User1 )->setFocus();
450 else 461 else
451 findButton( Ok )->setFocus(); 462 findButton( Ok )->setFocus();
452 exec(); 463 exec();
453 return mSyncResult; 464 return mSyncResult;
454} 465}
455void AddresseeChooser::slot_remote() 466void AddresseeChooser::slot_remote()
456{ 467{
457 mSyncResult = 2; 468 mSyncResult = 2;
458 accept(); 469 accept();
459} 470}
460void AddresseeChooser::slot_local() 471void AddresseeChooser::slot_local()
461{ 472{
462 mSyncResult = 1; 473 mSyncResult = 1;
463 accept(); 474 accept();
464} 475}
diff --git a/kabc/addresseeview.h b/kabc/addresseeview.h
index 689d997..d8a13ee 100644
--- a/kabc/addresseeview.h
+++ b/kabc/addresseeview.h
@@ -1,78 +1,79 @@
1/* 1/*
2 This file is part of libkdepim. 2 This file is part of libkdepim.
3 3
4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef KPIM_ADDRESSEEVIEW_H 22#ifndef KPIM_ADDRESSEEVIEW_H
23#define KPIM_ADDRESSEEVIEW_H 23#define KPIM_ADDRESSEEVIEW_H
24 24
25#include <kabc/addressee.h> 25#include <kabc/addressee.h>
26#include <kdialogbase.h> 26#include <kdialogbase.h>
27 27
28//US #include <ktextbrowser.h> 28//US #include <ktextbrowser.h>
29#include <qtextbrowser.h> 29#include <qtextbrowser.h>
30 30
31namespace KPIM { 31namespace KPIM {
32 32
33//US class AddresseeView : public KTextBrowser 33//US class AddresseeView : public KTextBrowser
34class AddresseeView : public QTextBrowser 34class AddresseeView : public QTextBrowser
35{ 35{
36 public: 36 public:
37 AddresseeView( QWidget *parent = 0, const char *name = 0 ); 37 AddresseeView( QWidget *parent = 0, const char *name = 0 );
38 38
39 /** 39 /**
40 Sets the addressee object. The addressee is displayed immediately. 40 Sets the addressee object. The addressee is displayed immediately.
41 41
42 @param addr The addressee object. 42 @param addr The addressee object.
43 */ 43 */
44 void setAddressee( const KABC::Addressee& addr ); 44 void setAddressee( const KABC::Addressee& addr );
45 void setSource(const QString& n); 45 void setSource(const QString& n);
46 /** 46 /**
47 Returns the current addressee object. 47 Returns the current addressee object.
48 */ 48 */
49 KABC::Addressee addressee() const; 49 KABC::Addressee addressee() const;
50 50
51 private: 51 private:
52 KABC::Addressee mAddressee; 52 KABC::Addressee mAddressee;
53 QString mText; 53 QString mText;
54 QString getPhoneNumbers( bool preferred );
54 void addTag(const QString & tag,const QString & text); 55 void addTag(const QString & tag,const QString & text);
55 class AddresseeViewPrivate; 56 class AddresseeViewPrivate;
56 AddresseeViewPrivate *d; 57 AddresseeViewPrivate *d;
57}; 58};
58class AddresseeChooser : public KDialogBase 59class AddresseeChooser : public KDialogBase
59{ 60{
60 Q_OBJECT 61 Q_OBJECT
61 62
62 public: 63 public:
63 AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent = 0, const char *name = 0 ); 64 AddresseeChooser( KABC::Addressee loc, KABC::Addressee rem, bool takeloc, QWidget *parent = 0, const char *name = 0 );
64 65
65 int executeD( bool local ); 66 int executeD( bool local );
66 67
67 private: 68 private:
68 int mSyncResult; 69 int mSyncResult;
69 70
70 private slots: 71 private slots:
71 void slot_remote(); 72 void slot_remote();
72 void slot_local(); 73 void slot_local();
73 74
74}; 75};
75 76
76} 77}
77 78
78#endif 79#endif
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index 6e94c7e..d7e3925 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -1,223 +1,223 @@
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() 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}
90void PhoneNumber::setId( const QString &id ) 90void PhoneNumber::setId( const QString &id )
91{ 91{
92 mId = id; 92 mId = id;
93} 93}
94 94
95QString PhoneNumber::id() const 95QString PhoneNumber::id() const
96{ 96{
97 return mId; 97 return mId;
98} 98}
99 99
100void PhoneNumber::setNumber( const QString &number ) 100void PhoneNumber::setNumber( const QString &number )
101{ 101{
102 mNumber = number; 102 mNumber = number;
103} 103}
104 104
105QString PhoneNumber::number() const 105QString PhoneNumber::number() const
106{ 106{
107 return mNumber; 107 return mNumber;
108} 108}
109 109
110void PhoneNumber::setType( int type ) 110void PhoneNumber::setType( int type )
111{ 111{
112 mType = type; 112 mType = type;
113} 113}
114 114
115int PhoneNumber::type() const 115int PhoneNumber::type() const
116{ 116{
117 return mType; 117 return mType;
118} 118}
119 119
120QString PhoneNumber::typeLabel() const 120QString PhoneNumber::typeLabel() const
121{ 121{
122 QString label; 122 QString label;
123 bool first = true; 123 bool first = true;
124 124
125 TypeList list = typeList(); 125 TypeList list = typeList();
126 126
127 TypeList::Iterator it; 127 TypeList::Iterator it;
128 for ( it = list.begin(); it != list.end(); ++it ) { 128 for ( it = list.begin(); it != list.end(); ++it ) {
129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
131 if ( first ) 131 if ( first )
132 first = false; 132 first = false;
133 } 133 }
134 } 134 }
135 135
136 return label; 136 return label;
137} 137}
138 138
139QString PhoneNumber::label() const 139QString PhoneNumber::label() const
140{ 140{
141 return typeLabel( type() ); 141 return typeLabel( type() );
142} 142}
143 143
144PhoneNumber::TypeList PhoneNumber::typeList() 144PhoneNumber::TypeList PhoneNumber::typeList()
145{ 145{
146 TypeList list; 146 TypeList list;
147 147
148 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video 148 list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
149 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; 149 << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip;
150 150
151 return list; 151 return list;
152} 152}
153 153
154QString PhoneNumber::label( int type ) 154QString PhoneNumber::label( int type )
155{ 155{
156 return typeLabel( type ); 156 return typeLabel( type );
157} 157}
158 158
159QString PhoneNumber::typeLabel( int type ) 159QString PhoneNumber::typeLabel( int type )
160{ 160{
161 QString typeString; 161 QString typeString;
162 162
163 if ((type & Home) == Home) 163 if ((type & Home) == Home)
164 typeString += i18n("Home"); 164 typeString += i18n("Home");
165 else if ((type & Work) == Work) 165 else if ((type & Work) == Work)
166 typeString += i18n("Work"); 166 typeString += i18n("Work");
167 167
168 if (!typeString.isEmpty()) 168 if (!typeString.isEmpty())
169 typeString += " "; 169 typeString += " ";
170 170
171 if ((type & Cell) == Cell) 171 if ((type & Cell) == Cell)
172 typeString += i18n("Mobile"); 172 typeString += i18n("Mobile");
173 else if ((type & Fax) == Fax) 173 else if ((type & Fax) == Fax)
174 typeString += i18n("Fax"); 174 typeString += i18n("Fax");
175 else if ((type & Msg) == Msg) 175 else if ((type & Msg) == Msg)
176 typeString += i18n("Messenger"); 176 typeString += i18n("Messenger");
177 else if ((type & Voice) == Voice) { 177 else if ((type & Voice) == Voice) {
178// add nothing in case of the Voice flag 178// add nothing in case of the Voice flag
179// typeString += i18n("Voice"); 179// typeString += i18n("Voice");
180 } 180 }
181 else if ((type & Video) == Video) 181 else if ((type & Video) == Video)
182 typeString += i18n("Video"); 182 typeString += i18n("Video");
183 else if ((type & Bbs) == Bbs) 183 else if ((type & Bbs) == Bbs)
184 typeString += i18n("Mailbox"); 184 typeString += i18n("Mailbox");
185 else if ((type & Modem) == Modem) 185 else if ((type & Modem) == Modem)
186 typeString += i18n("Modem"); 186 typeString += i18n("Modem");
187 else if ((type & Car) == Car) 187 else if ((type & Car) == Car)
188 typeString += i18n("Car"); 188 typeString += i18n("Car");
189 else if ((type & Isdn) == Isdn) 189 else if ((type & Isdn) == Isdn)
190 typeString += i18n("ISDN"); 190 typeString += i18n("ISDN");
191 else if ((type & Pcs) == Pcs) 191 else if ((type & Pcs) == Pcs)
192 typeString += i18n("PCS"); 192 typeString += i18n("PCS");
193 else if ((type & Pager) == Pager) 193 else if ((type & Pager) == Pager)
194 typeString += i18n("Pager"); 194 typeString += i18n("Pager");
195 else if ((type & Sip) == Sip) 195 else if ((type & Sip) == Sip)
196 typeString += i18n("SIP"); 196 typeString += i18n("SIP");
197 197
198 // add the prefered flag 198 // add the prefered flag
199 if (!typeString.isEmpty()) 199 if (!typeString.isEmpty())
200 typeString += " "; 200 typeString += " ";
201 201 /*
202 if ((type & Pref) == Pref) 202 if ((type & Pref) == Pref)
203 typeString += i18n("(p)"); 203 typeString += i18n("(p)");
204 204 */
205 //if we still have no match, return "other" 205 //if we still have no match, return "other"
206 if (typeString.isEmpty()) 206 if (typeString.isEmpty())
207 return i18n("Other"); 207 return i18n("Other");
208 208
209 209
210 return typeString; 210 return typeString;
211} 211}
212 212
213QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone ) 213QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
214{ 214{
215 return s << phone.mId << phone.mType << phone.mNumber; 215 return s << phone.mId << phone.mType << phone.mNumber;
216} 216}
217 217
218QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone ) 218QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
219{ 219{
220 s >> phone.mId >> phone.mType >> phone.mNumber; 220 s >> phone.mId >> phone.mType >> phone.mNumber;
221 221
222 return s; 222 return s;
223} 223}
diff --git a/kaddressbook/phoneeditwidget.cpp b/kaddressbook/phoneeditwidget.cpp
index 78b9941..19bb676 100644
--- a/kaddressbook/phoneeditwidget.cpp
+++ b/kaddressbook/phoneeditwidget.cpp
@@ -1,532 +1,530 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program 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 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qlabel.h> 25#include <qlabel.h>
26#include <qtooltip.h> 26#include <qtooltip.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28#include <qcheckbox.h> 28#include <qcheckbox.h>
29#include <qstring.h> 29#include <qstring.h>
30#include <qlistbox.h> 30#include <qlistbox.h>
31#include <qlistview.h> 31#include <qlistview.h>
32#include <qbuttongroup.h> 32#include <qbuttongroup.h>
33 33
34#include <kbuttonbox.h> 34#include <kbuttonbox.h>
35#include <klistview.h> 35#include <klistview.h>
36#include <kapplication.h> 36#include <kapplication.h>
37#include <qapplication.h> 37#include <qapplication.h>
38#include <kconfig.h> 38#include <kconfig.h>
39#include <klineedit.h> 39#include <klineedit.h>
40#include <kcombobox.h> 40#include <kcombobox.h>
41#include <klocale.h> 41#include <klocale.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kglobal.h> 43#include <kglobal.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45 45
46#include <kabc/phonenumber.h> 46#include <kabc/phonenumber.h>
47 47
48#include "typecombo.h" 48#include "typecombo.h"
49 49
50#include "phoneeditwidget.h" 50#include "phoneeditwidget.h"
51 51
52PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name ) 52PhoneEditWidget::PhoneEditWidget( QWidget *parent, const char *name )
53 : QWidget( parent, name ) 53 : QWidget( parent, name )
54{ 54{
55 QGridLayout *layout = new QGridLayout( this, 4, 1 ); 55 QGridLayout *layout = new QGridLayout( this, 4, 1 );
56//US layout->setSpacing( KDialog::spacingHint() ); 56//US layout->setSpacing( KDialog::spacingHint() );
57 layout->setSpacing( KDialogBase::spacingHintSmall() ); 57 layout->setSpacing( KDialogBase::spacingHintSmall() );
58 58
59 59
60 60
61 QLabel* label = new QLabel( this ); 61 QLabel* label = new QLabel( this );
62//US loadIcon call is ambiguous. Add one more parameter 62//US loadIcon call is ambiguous. Add one more parameter
63//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) ); 63//US label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop ) );
64 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) ); 64 label->setPixmap( KGlobal::iconLoader()->loadIcon( "kaddressbook", KIcon::Desktop, 0 ) );
65 label->setAlignment( AlignCenter ); 65 label->setAlignment( AlignCenter );
66//US layout->addMultiCellWidget( label, 0, 1, 3, 3 ); 66//US layout->addMultiCellWidget( label, 0, 1, 3, 3 );
67 layout->addWidget( label, 0, 0 ); 67 layout->addWidget( label, 0, 0 );
68 68
69 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ), 69 QPushButton *editButton = new QPushButton( i18n( "Edit Phone Numbers..." ),
70 this ); 70 this );
71 if ( QApplication::desktop()->width() < 640 ) 71 if ( QApplication::desktop()->width() < 640 )
72 layout->addWidget( editButton, 0, 1 ); 72 layout->addWidget( editButton, 0, 1 );
73 else 73 else
74 layout->addMultiCellWidget( editButton, 0, 0, 1, 3); 74 layout->addMultiCellWidget( editButton, 0, 0, 1, 3);
75 75
76 mPrefCombo = new PhoneTypeCombo( mPhoneList, this ); 76 mPrefCombo = new PhoneTypeCombo( mPhoneList, this );
77 mPrefEdit = new KLineEdit( this ); 77 mPrefEdit = new KLineEdit( this );
78 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) ); 78 //mPrefEdit->setMinimumWidth( int(mPrefEdit->sizeHint().width() * 1.5) );
79 mPrefCombo->setLineEdit( mPrefEdit ); 79 mPrefCombo->setLineEdit( mPrefEdit );
80 layout->addWidget( mPrefCombo, 1, 0 ); 80 layout->addWidget( mPrefCombo, 1, 0 );
81 layout->addWidget( mPrefEdit, 1, 1 ); 81 layout->addWidget( mPrefEdit, 1, 1 );
82 int x = 1, y = 2; 82 int x = 1, y = 2;
83 if ( QApplication::desktop()->width() < 640 ) { 83 if ( QApplication::desktop()->width() < 640 ) {
84 ++x; 84 ++x;
85 y = 0; 85 y = 0;
86 } 86 }
87 mSecondCombo = new PhoneTypeCombo( mPhoneList, this ); 87 mSecondCombo = new PhoneTypeCombo( mPhoneList, this );
88 mSecondEdit = new KLineEdit( this ); 88 mSecondEdit = new KLineEdit( this );
89 mSecondCombo->setLineEdit( mSecondEdit ); 89 mSecondCombo->setLineEdit( mSecondEdit );
90 layout->addWidget( mSecondCombo, x, y++ ); 90 layout->addWidget( mSecondCombo, x, y++ );
91 layout->addWidget( mSecondEdit, x, y++ ); 91 layout->addWidget( mSecondEdit, x, y++ );
92 92
93 y = 0; 93 y = 0;
94 ++x; 94 ++x;
95 mThirdCombo = new PhoneTypeCombo( mPhoneList, this ); 95 mThirdCombo = new PhoneTypeCombo( mPhoneList, this );
96 mThirdEdit = new KLineEdit( this ); 96 mThirdEdit = new KLineEdit( this );
97 mThirdCombo->setLineEdit( mThirdEdit ); 97 mThirdCombo->setLineEdit( mThirdEdit );
98 layout->addWidget( mThirdCombo, x, y++ ); 98 layout->addWidget( mThirdCombo, x, y++ );
99 layout->addWidget( mThirdEdit, x, y++ ); 99 layout->addWidget( mThirdEdit, x, y++ );
100 if ( QApplication::desktop()->width() < 640 ) { 100 if ( QApplication::desktop()->width() < 640 ) {
101 ++x; 101 ++x;
102 y = 0; 102 y = 0;
103 } 103 }
104 mFourthCombo = new PhoneTypeCombo( mPhoneList, this ); 104 mFourthCombo = new PhoneTypeCombo( mPhoneList, this );
105 mFourthEdit = new KLineEdit( this ); 105 mFourthEdit = new KLineEdit( this );
106 mFourthCombo->setLineEdit( mFourthEdit ); 106 mFourthCombo->setLineEdit( mFourthEdit );
107 layout->addWidget( mFourthCombo, x, y++ ); 107 layout->addWidget( mFourthCombo, x, y++ );
108 layout->addWidget( mFourthEdit, x, y++ ); 108 layout->addWidget( mFourthEdit, x, y++ );
109 109
110 // Four numbers don't fit in the current dialog 110 // Four numbers don't fit in the current dialog
111 if ( QApplication::desktop()->width() < 640 ) { 111 if ( QApplication::desktop()->width() < 640 ) {
112 mFourthCombo->hide(); 112 mFourthCombo->hide();
113 mFourthEdit->hide(); 113 mFourthEdit->hide();
114 } else { 114 } else {
115 QFontMetrics fm ( font () ) ; 115 QFontMetrics fm ( font () ) ;
116 int wid = fm.width( "Messenger" ) +60; 116 int wid = fm.width( "Messenger" ) +60;
117 mPrefCombo->setMaximumWidth( wid ); 117 mPrefCombo->setMaximumWidth( wid );
118 mSecondCombo->setMaximumWidth( wid ); 118 mSecondCombo->setMaximumWidth( wid );
119 mThirdCombo->setMaximumWidth( wid ); 119 mThirdCombo->setMaximumWidth( wid );
120 mFourthCombo->setMaximumWidth( wid ); 120 mFourthCombo->setMaximumWidth( wid );
121 } 121 }
122 122
123 123
124 connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ), 124 connect( mPrefEdit, SIGNAL( textChanged( const QString& ) ),
125 SLOT( slotPrefEditChanged() ) ); 125 SLOT( slotPrefEditChanged() ) );
126 connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ), 126 connect( mSecondEdit, SIGNAL( textChanged( const QString& ) ),
127 SLOT( slotSecondEditChanged() ) ); 127 SLOT( slotSecondEditChanged() ) );
128 connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ), 128 connect( mThirdEdit, SIGNAL( textChanged( const QString& ) ),
129 SLOT( slotThirdEditChanged() ) ); 129 SLOT( slotThirdEditChanged() ) );
130 connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ), 130 connect( mFourthEdit, SIGNAL( textChanged( const QString& ) ),
131 SLOT( slotFourthEditChanged() ) ); 131 SLOT( slotFourthEditChanged() ) );
132 132
133 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) ); 133 connect( editButton, SIGNAL( clicked() ), SLOT( edit() ) );
134 134
135 connect( mPrefCombo, SIGNAL( activated( int ) ), 135 connect( mPrefCombo, SIGNAL( activated( int ) ),
136 SLOT( updatePrefEdit() ) ); 136 SLOT( updatePrefEdit() ) );
137 connect( mSecondCombo, SIGNAL( activated( int ) ), 137 connect( mSecondCombo, SIGNAL( activated( int ) ),
138 SLOT( updateSecondEdit() ) ); 138 SLOT( updateSecondEdit() ) );
139 connect( mThirdCombo, SIGNAL( activated( int ) ), 139 connect( mThirdCombo, SIGNAL( activated( int ) ),
140 SLOT( updateThirdEdit() ) ); 140 SLOT( updateThirdEdit() ) );
141 connect( mFourthCombo, SIGNAL( activated( int ) ), 141 connect( mFourthCombo, SIGNAL( activated( int ) ),
142 SLOT( updateFourthEdit() ) ); 142 SLOT( updateFourthEdit() ) );
143} 143}
144 144
145PhoneEditWidget::~PhoneEditWidget() 145PhoneEditWidget::~PhoneEditWidget()
146{ 146{
147} 147}
148 148
149void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list ) 149void PhoneEditWidget::setPhoneNumbers( const KABC::PhoneNumber::List &list )
150{ 150{
151 mPhoneList.clear(); 151 mPhoneList.clear();
152 152
153 // Insert types for existing numbers. 153 // Insert types for existing numbers.
154 mPrefCombo->insertTypeList( list ); 154 mPrefCombo->insertTypeList( list );
155 155
156 QValueList<int> defaultTypes; 156 QValueList<int> defaultTypes;
157 defaultTypes << KABC::PhoneNumber::Home; 157 defaultTypes << KABC::PhoneNumber::Home;
158 defaultTypes << KABC::PhoneNumber::Work; 158 defaultTypes << KABC::PhoneNumber::Work;
159 defaultTypes << KABC::PhoneNumber::Cell; 159 defaultTypes << KABC::PhoneNumber::Cell;
160 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax ); 160 defaultTypes << ( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
161 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax ); 161 defaultTypes << ( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
162 162
163 // Insert default types. 163 // Insert default types.
164 // Doing this for mPrefCombo is enough because the list is shared by all 164 // Doing this for mPrefCombo is enough because the list is shared by all
165 // combos. 165 // combos.
166 QValueList<int>::ConstIterator it; 166 QValueList<int>::ConstIterator it;
167 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) { 167 for( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
168 if ( !mPrefCombo->hasType( *it ) ) 168 if ( !mPrefCombo->hasType( *it ) )
169 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) ); 169 mPrefCombo->insertType( list, *it, PhoneNumber( "", *it ) );
170 } 170 }
171 171
172 updateCombos(); 172 updateCombos();
173 173
174 mPrefCombo->selectType( defaultTypes[ 0 ] ); 174 mPrefCombo->selectType( defaultTypes[ 0 ] );
175 mSecondCombo->selectType( defaultTypes[ 1 ] ); 175 mSecondCombo->selectType( defaultTypes[ 1 ] );
176 mThirdCombo->selectType( defaultTypes[ 2 ] ); 176 mThirdCombo->selectType( defaultTypes[ 2 ] );
177 mFourthCombo->selectType( defaultTypes[ 3 ] ); 177 mFourthCombo->selectType( defaultTypes[ 3 ] );
178 178
179 updateLineEdits(); 179 updateLineEdits();
180} 180}
181 181
182void PhoneEditWidget::updateLineEdits() 182void PhoneEditWidget::updateLineEdits()
183{ 183{
184 updatePrefEdit(); 184 updatePrefEdit();
185 updateSecondEdit(); 185 updateSecondEdit();
186 updateThirdEdit(); 186 updateThirdEdit();
187 updateFourthEdit(); 187 updateFourthEdit();
188} 188}
189 189
190void PhoneEditWidget::updateCombos() 190void PhoneEditWidget::updateCombos()
191{ 191{
192 mPrefCombo->updateTypes(); 192 mPrefCombo->updateTypes();
193 mSecondCombo->updateTypes(); 193 mSecondCombo->updateTypes();
194 mThirdCombo->updateTypes(); 194 mThirdCombo->updateTypes();
195 mFourthCombo->updateTypes(); 195 mFourthCombo->updateTypes();
196} 196}
197 197
198KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers() 198KABC::PhoneNumber::List PhoneEditWidget::phoneNumbers()
199{ 199{
200 KABC::PhoneNumber::List retList; 200 KABC::PhoneNumber::List retList;
201 201
202 KABC::PhoneNumber::List::Iterator it; 202 KABC::PhoneNumber::List::Iterator it;
203 for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it ) 203 for ( it = mPhoneList.begin(); it != mPhoneList.end(); ++it )
204 if ( !(*it).number().isEmpty() ) 204 if ( !(*it).number().isEmpty() )
205 retList.append( *it ); 205 retList.append( *it );
206 206
207 return retList; 207 return retList;
208} 208}
209 209
210void PhoneEditWidget::edit() 210void PhoneEditWidget::edit()
211{ 211{
212 PhoneEditDialog dlg( mPhoneList, this ); 212 PhoneEditDialog dlg( mPhoneList, this );
213 213
214 if ( dlg.exec() ) { 214 if ( dlg.exec() ) {
215 if ( dlg.changed() ) { 215 if ( dlg.changed() ) {
216 mPhoneList = dlg.phoneNumbers(); 216 mPhoneList = dlg.phoneNumbers();
217 updateCombos(); 217 updateCombos();
218 updateLineEdits();
218 emit modified(); 219 emit modified();
219 } 220 }
220 } 221 }
221} 222}
222 223
223void PhoneEditWidget::updatePrefEdit() 224void PhoneEditWidget::updatePrefEdit()
224{ 225{
225 updateEdit( mPrefCombo ); 226 updateEdit( mPrefCombo );
226} 227}
227 228
228void PhoneEditWidget::updateSecondEdit() 229void PhoneEditWidget::updateSecondEdit()
229{ 230{
230 updateEdit( mSecondCombo ); 231 updateEdit( mSecondCombo );
231} 232}
232 233
233void PhoneEditWidget::updateThirdEdit() 234void PhoneEditWidget::updateThirdEdit()
234{ 235{
235 updateEdit( mThirdCombo ); 236 updateEdit( mThirdCombo );
236} 237}
237 238
238void PhoneEditWidget::updateFourthEdit() 239void PhoneEditWidget::updateFourthEdit()
239{ 240{
240 updateEdit( mFourthCombo ); 241 updateEdit( mFourthCombo );
241} 242}
242 243
243void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo ) 244void PhoneEditWidget::updateEdit( PhoneTypeCombo *combo )
244{ 245{
245 QLineEdit *edit = combo->lineEdit(); 246 QLineEdit *edit = combo->lineEdit();
246 if ( !edit ) 247 if ( !edit )
247 return; 248 return;
248 249
249#if 0 250#if 0
250 if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl; 251 if ( edit == mPrefEdit ) kdDebug(5720) << " prefEdit" << endl;
251 if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl; 252 if ( edit == mSecondEdit ) kdDebug(5720) << " secondEdit" << endl;
252 if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl; 253 if ( edit == mThirdEdit ) kdDebug(5720) << " thirdEdit" << endl;
253 if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl; 254 if ( edit == mFourthEdit ) kdDebug(5720) << " fourthEdit" << endl;
254#endif 255#endif
255 256
256 PhoneNumber::List::Iterator it = combo->selectedElement(); 257 PhoneNumber::List::Iterator it = combo->selectedElement();
257 if ( it != mPhoneList.end() ) { 258 if ( it != mPhoneList.end() ) {
258 edit->setText( (*it).number() ); 259 edit->setText( (*it).number() );
259 } else { 260 } else {
260 kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl; 261 kdDebug(5720) << "PhoneEditWidget::updateEdit(): no selected element" << endl;
261 } 262 }
262} 263}
263 264
264void PhoneEditWidget::slotPrefEditChanged() 265void PhoneEditWidget::slotPrefEditChanged()
265{ 266{
266 updatePhoneNumber( mPrefCombo ); 267 updatePhoneNumber( mPrefCombo );
267} 268}
268 269
269void PhoneEditWidget::slotSecondEditChanged() 270void PhoneEditWidget::slotSecondEditChanged()
270{ 271{
271 updatePhoneNumber( mSecondCombo ); 272 updatePhoneNumber( mSecondCombo );
272} 273}
273 274
274void PhoneEditWidget::slotThirdEditChanged() 275void PhoneEditWidget::slotThirdEditChanged()
275{ 276{
276 updatePhoneNumber( mThirdCombo ); 277 updatePhoneNumber( mThirdCombo );
277} 278}
278 279
279void PhoneEditWidget::slotFourthEditChanged() 280void PhoneEditWidget::slotFourthEditChanged()
280{ 281{
281 updatePhoneNumber( mFourthCombo ); 282 updatePhoneNumber( mFourthCombo );
282} 283}
283 284
284void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo ) 285void PhoneEditWidget::updatePhoneNumber( PhoneTypeCombo *combo )
285{ 286{
286 QLineEdit *edit = combo->lineEdit(); 287 QLineEdit *edit = combo->lineEdit();
287 if ( !edit ) return; 288 if ( !edit ) return;
288 289
289 PhoneNumber::List::Iterator it = combo->selectedElement(); 290 PhoneNumber::List::Iterator it = combo->selectedElement();
290 if ( it != mPhoneList.end() ) { 291 if ( it != mPhoneList.end() ) {
291 (*it).setNumber( edit->text() ); 292 (*it).setNumber( edit->text() );
292 } else { 293 }
293 kdDebug(5720) << "PhoneEditWidget::updatePhoneNumber(): no selected element"
294 << endl;
295 }
296 294
297 updateOtherEdit( combo, mPrefCombo ); 295 updateOtherEdit( combo, mPrefCombo );
298 updateOtherEdit( combo, mSecondCombo ); 296 updateOtherEdit( combo, mSecondCombo );
299 updateOtherEdit( combo, mThirdCombo ); 297 updateOtherEdit( combo, mThirdCombo );
300 updateOtherEdit( combo, mFourthCombo ); 298 updateOtherEdit( combo, mFourthCombo );
301 299
302 emit modified(); 300 emit modified();
303} 301}
304 302
305void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo ) 303void PhoneEditWidget::updateOtherEdit( PhoneTypeCombo *combo, PhoneTypeCombo *otherCombo )
306{ 304{
307 if ( combo == otherCombo ) return; 305 if ( combo == otherCombo ) return;
308 306
309 if ( combo->currentItem() == otherCombo->currentItem() ) { 307 if ( combo->currentItem() == otherCombo->currentItem() ) {
310 updateEdit( otherCombo ); 308 updateEdit( otherCombo );
311 } 309 }
312} 310}
313 311
314/////////////////////////////////////////// 312///////////////////////////////////////////
315// PhoneEditDialog 313// PhoneEditDialog
316 314
317class PhoneViewItem : public QListViewItem 315class PhoneViewItem : public QListViewItem
318{ 316{
319public: 317public:
320 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ); 318 PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number );
321 319
322 void setPhoneNumber( const KABC::PhoneNumber &number ) 320 void setPhoneNumber( const KABC::PhoneNumber &number )
323 { 321 {
324 mPhoneNumber = number; 322 mPhoneNumber = number;
325 makeText(); 323 makeText();
326 } 324 }
327 325
328 QString key() { return mPhoneNumber.id(); } 326 QString key() { return mPhoneNumber.id(); }
329 QString country() { return ""; } 327 QString country() { return ""; }
330 QString region() { return ""; } 328 QString region() { return ""; }
331 QString number() { return ""; } 329 QString number() { return ""; }
332 330
333 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; } 331 KABC::PhoneNumber phoneNumber() { return mPhoneNumber; }
334 332
335private: 333private:
336 void makeText(); 334 void makeText();
337 335
338 KABC::PhoneNumber mPhoneNumber; 336 KABC::PhoneNumber mPhoneNumber;
339}; 337};
340 338
341PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number ) 339PhoneViewItem::PhoneViewItem( QListView *parent, const KABC::PhoneNumber &number )
342 : QListViewItem( parent ), mPhoneNumber( number ) 340 : QListViewItem( parent ), mPhoneNumber( number )
343{ 341{
344 makeText(); 342 makeText();
345} 343}
346 344
347void PhoneViewItem::makeText() 345void PhoneViewItem::makeText()
348{ 346{
349 /** 347 /**
350 * Will be used in future versions of kaddressbook/libkabc 348 * Will be used in future versions of kaddressbook/libkabc
351 349
352 setText( 0, mPhoneNumber.country() ); 350 setText( 0, mPhoneNumber.country() );
353 setText( 1, mPhoneNumber.region() ); 351 setText( 1, mPhoneNumber.region() );
354 setText( 2, mPhoneNumber.number() ); 352 setText( 2, mPhoneNumber.number() );
355 setText( 3, mPhoneNumber.typeLabel() ); 353 setText( 3, mPhoneNumber.typeLabel() );
356 */ 354 */
357 355
358 setText( 0, mPhoneNumber.number() ); 356 setText( 0, mPhoneNumber.number() );
359 setText( 1, mPhoneNumber.typeLabel() ); 357 setText( 1, mPhoneNumber.typeLabel() );
360} 358}
361 359
362PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name ) 360PhoneEditDialog::PhoneEditDialog( const KABC::PhoneNumber::List &list, QWidget *parent, const char *name )
363 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ), 361 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Numbers" ),
364 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, 362 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
365 parent, name, true) 363 parent, name, true)
366{ 364{
367 mPhoneNumberList = list; 365 mPhoneNumberList = list;
368 366
369 QWidget *page = plainPage(); 367 QWidget *page = plainPage();
370 368
371 QGridLayout *layout = new QGridLayout( page, 1, 2 ); 369 QGridLayout *layout = new QGridLayout( page, 1, 2 );
372 layout->setSpacing( spacingHint() ); 370 layout->setSpacing( spacingHint() );
373 371
374 mListView = new KListView( page ); 372 mListView = new KListView( page );
375 mListView->setAllColumnsShowFocus( true ); 373 mListView->setAllColumnsShowFocus( true );
376 mListView->addColumn( i18n( "Number" ) ); 374 mListView->addColumn( i18n( "Number" ) );
377 mListView->addColumn( i18n( "Type" ) ); 375 mListView->addColumn( i18n( "Type" ) );
378 376
379 KButtonBox *buttonBox = new KButtonBox( page, Vertical ); 377 KButtonBox *buttonBox = new KButtonBox( page, Vertical );
380 378
381 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) ); 379 buttonBox->addButton( i18n( "&Add..." ), this, SLOT( slotAddPhoneNumber() ) );
382 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) ); 380 mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT( slotEditPhoneNumber() ) );
383 mEditButton->setEnabled( false ); 381 mEditButton->setEnabled( false );
384 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) ); 382 mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT( slotRemovePhoneNumber() ) );
385 mRemoveButton->setEnabled( false ); 383 mRemoveButton->setEnabled( false );
386 buttonBox->layout(); 384 buttonBox->layout();
387 385
388 layout->addWidget( mListView, 0, 0 ); 386 layout->addWidget( mListView, 0, 0 );
389 layout->addWidget( buttonBox, 0, 1 ); 387 layout->addWidget( buttonBox, 0, 1 );
390 388
391 connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) ); 389 connect( mListView, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()) );
392 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber())); 390 connect( mListView, SIGNAL(doubleClicked( QListViewItem *, const QPoint &, int )), this, SLOT( slotEditPhoneNumber()));
393 391
394 KABC::PhoneNumber::List::Iterator it; 392 KABC::PhoneNumber::List::Iterator it;
395 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it ) 393 for ( it = mPhoneNumberList.begin(); it != mPhoneNumberList.end(); ++it )
396 new PhoneViewItem( mListView, *it ); 394 new PhoneViewItem( mListView, *it );
397 395
398 mChanged = false; 396 mChanged = false;
399} 397}
400 398
401PhoneEditDialog::~PhoneEditDialog() 399PhoneEditDialog::~PhoneEditDialog()
402{ 400{
403} 401}
404 402
405void PhoneEditDialog::slotAddPhoneNumber() 403void PhoneEditDialog::slotAddPhoneNumber()
406{ 404{
407 KABC::PhoneNumber tmp( "", 0 ); 405 KABC::PhoneNumber tmp( "", 0 );
408 PhoneTypeDialog dlg( tmp, this ); 406 PhoneTypeDialog dlg( tmp, this );
409 407
410 if ( dlg.exec() ) { 408 if ( dlg.exec() ) {
411 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 409 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
412 mPhoneNumberList.append( phoneNumber ); 410 mPhoneNumberList.append( phoneNumber );
413 new PhoneViewItem( mListView, phoneNumber ); 411 new PhoneViewItem( mListView, phoneNumber );
414 412
415 mChanged = true; 413 mChanged = true;
416 } 414 }
417} 415}
418 416
419void PhoneEditDialog::slotRemovePhoneNumber() 417void PhoneEditDialog::slotRemovePhoneNumber()
420{ 418{
421 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 419 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
422 if ( !item ) 420 if ( !item )
423 return; 421 return;
424 422
425 mPhoneNumberList.remove( item->phoneNumber() ); 423 mPhoneNumberList.remove( item->phoneNumber() );
426 QListViewItem *currItem = mListView->currentItem(); 424 QListViewItem *currItem = mListView->currentItem();
427 mListView->takeItem( currItem ); 425 mListView->takeItem( currItem );
428 delete currItem; 426 delete currItem;
429 427
430 mChanged = true; 428 mChanged = true;
431} 429}
432 430
433void PhoneEditDialog::slotEditPhoneNumber() 431void PhoneEditDialog::slotEditPhoneNumber()
434{ 432{
435 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() ); 433 PhoneViewItem *item = static_cast<PhoneViewItem*>( mListView->currentItem() );
436 if ( !item ) 434 if ( !item )
437 return; 435 return;
438 436
439 PhoneTypeDialog dlg( item->phoneNumber(), this ); 437 PhoneTypeDialog dlg( item->phoneNumber(), this );
440 438
441 if ( dlg.exec() ) { 439 if ( dlg.exec() ) {
442 slotRemovePhoneNumber(); 440 slotRemovePhoneNumber();
443 KABC::PhoneNumber phoneNumber = dlg.phoneNumber(); 441 KABC::PhoneNumber phoneNumber = dlg.phoneNumber();
444 mPhoneNumberList.append( phoneNumber ); 442 mPhoneNumberList.append( phoneNumber );
445 new PhoneViewItem( mListView, phoneNumber ); 443 new PhoneViewItem( mListView, phoneNumber );
446 444
447 mChanged = true; 445 mChanged = true;
448 } 446 }
449} 447}
450 448
451void PhoneEditDialog::slotSelectionChanged() 449void PhoneEditDialog::slotSelectionChanged()
452{ 450{
453 bool state = ( mListView->currentItem() != 0 ); 451 bool state = ( mListView->currentItem() != 0 );
454 452
455 mRemoveButton->setEnabled( state ); 453 mRemoveButton->setEnabled( state );
456 mEditButton->setEnabled( state ); 454 mEditButton->setEnabled( state );
457} 455}
458 456
459const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers() 457const KABC::PhoneNumber::List &PhoneEditDialog::phoneNumbers()
460{ 458{
461 return mPhoneNumberList; 459 return mPhoneNumberList;
462} 460}
463 461
464bool PhoneEditDialog::changed() const 462bool PhoneEditDialog::changed() const
465{ 463{
466 return mChanged; 464 return mChanged;
467} 465}
468 466
469/////////////////////////////////////////// 467///////////////////////////////////////////
470// PhoneTypeDialog 468// PhoneTypeDialog
471PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber, 469PhoneTypeDialog::PhoneTypeDialog( const KABC::PhoneNumber &phoneNumber,
472 QWidget *parent, const char *name) 470 QWidget *parent, const char *name)
473 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ), 471 : KDialogBase( KDialogBase::Plain, i18n( "Edit Phone Number" ),
474 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, 472 KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok,
475 parent, name, true), mPhoneNumber( phoneNumber ) 473 parent, name, true), mPhoneNumber( phoneNumber )
476{ 474{
477 QWidget *page = plainPage(); 475 QWidget *page = plainPage();
478 QLabel *label = 0; 476 QLabel *label = 0;
479 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() ); 477 QGridLayout *layout = new QGridLayout( page, 3, 2, marginHint(), spacingHint() );
480 478
481 label = new QLabel( i18n( "Number:" ), page ); 479 label = new QLabel( i18n( "Number:" ), page );
482 layout->addWidget( label, 0, 0 ); 480 layout->addWidget( label, 0, 0 );
483 mNumber = new KLineEdit( page ); 481 mNumber = new KLineEdit( page );
484 layout->addWidget( mNumber, 0, 1 ); 482 layout->addWidget( mNumber, 0, 1 );
485 483
486 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page ); 484 mPreferredBox = new QCheckBox( i18n( "This is the preferred phone number" ), page );
487 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 ); 485 layout->addMultiCellWidget( mPreferredBox, 1, 1, 0, 1 );
488 486
489 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page ); 487 mGroup = new QButtonGroup( 2, Horizontal, i18n( "Types" ), page );
490 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 ); 488 layout->addMultiCellWidget( mGroup, 2, 2, 0, 1 );
491 489
492 // fill widgets 490 // fill widgets
493 mNumber->setText( mPhoneNumber.number() ); 491 mNumber->setText( mPhoneNumber.number() );
494 492
495 mTypeList = KABC::PhoneNumber::typeList(); 493 mTypeList = KABC::PhoneNumber::typeList();
496 mTypeList.remove( KABC::PhoneNumber::Pref ); 494 mTypeList.remove( KABC::PhoneNumber::Pref );
497 495
498 KABC::PhoneNumber::TypeList::Iterator it; 496 KABC::PhoneNumber::TypeList::Iterator it;
499 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it ) 497 for ( it = mTypeList.begin(); it != mTypeList.end(); ++it )
500 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup ); 498 new QCheckBox( KABC::PhoneNumber::typeLabel( *it ), mGroup );
501 499
502 for ( int i = 0; i < mGroup->count(); ++i ) { 500 for ( int i = 0; i < mGroup->count(); ++i ) {
503 int type = mPhoneNumber.type(); 501 int type = mPhoneNumber.type();
504 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 502 QCheckBox *box = (QCheckBox*)mGroup->find( i );
505 box->setChecked( type & mTypeList[ i ] ); 503 box->setChecked( type & mTypeList[ i ] );
506 } 504 }
507 505
508 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref ); 506 mPreferredBox->setChecked( mPhoneNumber.type() & KABC::PhoneNumber::Pref );
509} 507}
510 508
511KABC::PhoneNumber PhoneTypeDialog::phoneNumber() 509KABC::PhoneNumber PhoneTypeDialog::phoneNumber()
512{ 510{
513 mPhoneNumber.setNumber( mNumber->text() ); 511 mPhoneNumber.setNumber( mNumber->text() );
514 512
515 int type = 0; 513 int type = 0;
516 for ( int i = 0; i < mGroup->count(); ++i ) { 514 for ( int i = 0; i < mGroup->count(); ++i ) {
517 QCheckBox *box = (QCheckBox*)mGroup->find( i ); 515 QCheckBox *box = (QCheckBox*)mGroup->find( i );
518 if ( box->isChecked() ) 516 if ( box->isChecked() )
519 type += mTypeList[ i ]; 517 type += mTypeList[ i ];
520 } 518 }
521 519
522 if ( mPreferredBox->isChecked() ) 520 if ( mPreferredBox->isChecked() )
523 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref ); 521 mPhoneNumber.setType( type | KABC::PhoneNumber::Pref );
524 else 522 else
525 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref ); 523 mPhoneNumber.setType( type & ~KABC::PhoneNumber::Pref );
526 524
527 return mPhoneNumber; 525 return mPhoneNumber;
528} 526}
529 527
530#ifndef KAB_EMBEDDED 528#ifndef KAB_EMBEDDED
531#include "phoneeditwidget.moc" 529#include "phoneeditwidget.moc"
532#endif //KAB_EMBEDDED 530#endif //KAB_EMBEDDED