00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qbuffer.h>
00023 #include <qimage.h>
00024 #include <qpopupmenu.h>
00025 #include <qurl.h>
00026
00027 #include <kabc/address.h>
00028 #include <kabc/addressee.h>
00029 #include <kabc/phonenumber.h>
00030 #include <kactionclasses.h>
00031 #include <kapplication.h>
00032 #include <kconfig.h>
00033 #include <kglobal.h>
00034 #include <kglobalsettings.h>
00035 #include <kiconloader.h>
00036 #include <kio/job.h>
00037 #include <klocale.h>
00038 #include <kmdcodec.h>
00039 #include <kmessagebox.h>
00040 #include <krun.h>
00041 #include <kstringhandler.h>
00042 #include <ktempfile.h>
00043
00044 #include <kdebug.h>
00045
00046 #include "addresseeview.h"
00047 #include "sendsmsdialog.h"
00048
00049 using namespace KPIM;
00050
00051 AddresseeView::AddresseeView( QWidget *parent, const char *name,
00052 KConfig *config )
00053 : KTextBrowser( parent, name ), mDefaultConfig( false ), mImageJob( 0 ),
00054 mLinkMask( AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks | CustomFields )
00055 {
00056 setWrapPolicy( QTextEdit::AtWordBoundary );
00057 setLinkUnderline( false );
00058 setVScrollBarMode( QScrollView::AlwaysOff );
00059 setHScrollBarMode( QScrollView::AlwaysOff );
00060
00061 QStyleSheet *sheet = styleSheet();
00062 QStyleSheetItem *link = sheet->item( "a" );
00063 link->setColor( KGlobalSettings::linkColor() );
00064
00065 connect( this, SIGNAL( mailClick( const QString&, const QString& ) ),
00066 this, SLOT( slotMailClicked( const QString&, const QString& ) ) );
00067 connect( this, SIGNAL( urlClick( const QString& ) ),
00068 this, SLOT( slotUrlClicked( const QString& ) ) );
00069 connect( this, SIGNAL( highlighted( const QString& ) ),
00070 this, SLOT( slotHighlighted( const QString& ) ) );
00071
00072 setNotifyClick( true );
00073
00074 mActionShowBirthday = new KToggleAction( i18n( "Show Birthday" ) );
00075 mActionShowBirthday->setCheckedState( i18n( "Hide Birthday" ) );
00076 mActionShowAddresses = new KToggleAction( i18n( "Show Postal Addresses" ) );
00077 mActionShowAddresses->setCheckedState( i18n( "Hide Postal Addresses" ) );
00078 mActionShowEmails = new KToggleAction( i18n( "Show Email Addresses" ) );
00079 mActionShowEmails->setCheckedState( i18n( "Hide Email Addresses" ) );
00080 mActionShowPhones = new KToggleAction( i18n( "Show Telephone Numbers" ) );
00081 mActionShowPhones->setCheckedState( i18n( "Hide Telephone Numbers" ) );
00082 mActionShowURLs = new KToggleAction( i18n( "Show Web Pages (URLs)" ) );
00083 mActionShowURLs->setCheckedState( i18n( "Hide Web Pages (URLs)" ) );
00084 mActionShowIMAddresses = new KToggleAction( i18n( "Show Instant Messaging Addresses" ) );
00085 mActionShowIMAddresses->setCheckedState( i18n( "Hide Instant Messaging Addresses" ) );
00086 mActionShowCustomFields = new KToggleAction( i18n( "Show Custom Fields" ) );
00087 mActionShowCustomFields->setCheckedState( i18n( "Hide Custom Fields" ) );
00088
00089 connect( mActionShowBirthday, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00090 connect( mActionShowAddresses, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00091 connect( mActionShowEmails, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00092 connect( mActionShowPhones, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00093 connect( mActionShowURLs, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00094 connect( mActionShowIMAddresses, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00095 connect( mActionShowCustomFields, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00096
00097 if ( !config ) {
00098 mConfig = new KConfig( "kaddressbookrc" );
00099 mDefaultConfig = true;
00100 } else
00101 mConfig = config;
00102
00103 load();
00104
00105
00106 mKIMProxy = ::KIMProxy::instance( kapp->dcopClient() );
00107 connect( mKIMProxy, SIGNAL( sigContactPresenceChanged( const QString& ) ),
00108 this, SLOT( slotPresenceChanged( const QString& ) ) );
00109 connect( mKIMProxy, SIGNAL( sigPresenceInfoExpired() ),
00110 this, SLOT( slotPresenceInfoExpired() ) );
00111 }
00112
00113 AddresseeView::~AddresseeView()
00114 {
00115 if ( mDefaultConfig )
00116 delete mConfig;
00117 mConfig = 0;
00118
00119 delete mActionShowBirthday;
00120 delete mActionShowAddresses;
00121 delete mActionShowEmails;
00122 delete mActionShowPhones;
00123 delete mActionShowURLs;
00124 delete mActionShowIMAddresses;
00125 delete mActionShowCustomFields;
00126
00127 mKIMProxy = 0;
00128 }
00129
00130 void AddresseeView::setAddressee( const KABC::Addressee& addr )
00131 {
00132 mAddressee = addr;
00133
00134 if ( mImageJob ) {
00135 mImageJob->kill();
00136 mImageJob = 0;
00137 }
00138
00139 mImageData.truncate( 0 );
00140
00141 updateView();
00142 }
00143
00144 void AddresseeView::enableLinks( int linkMask )
00145 {
00146 mLinkMask = linkMask;
00147 }
00148
00149 QString AddresseeView::vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask,
00150 bool internalLoading, FieldMask fieldMask )
00151 {
00152 QString image = QString( "contact_%1_image" ).arg( addr.uid() );
00153
00154
00155
00156
00157
00158
00159
00160
00161 QString backgroundColor = KGlobalSettings::alternateBackgroundColor().name();
00162 QString cellStyle = QString::fromLatin1(
00163 "style=\""
00164 "padding-right: 2px; "
00165 "border-right: #000 dashed 1px; "
00166 "background: %1;\"").arg(backgroundColor);
00167 QString backgroundColor2 = KGlobalSettings::baseColor().name();
00168 QString cellStyle2 = QString::fromLatin1(
00169 "style=\""
00170 "padding-left: 2px; "
00171 "background: %1;\"").arg(backgroundColor2);
00172 QString tableStyle = QString::fromLatin1(
00173 "style=\""
00174 "border: solid 1px; "
00175 "margin: 0em;\"");
00176
00177
00178
00179
00180 QString rowFmtStr = QString::fromLatin1(
00181 "<tr>"
00182 "<td align=\"right\" valign=\"top\" width=\"30%\" ");
00183 rowFmtStr.append( cellStyle );
00184 rowFmtStr.append( QString::fromLatin1(
00185 ">"
00186 "<b>%1</b>"
00187 "</td>"
00188 "<td align=\"left\" valign=\"top\" width=\"70%\" ") );
00189 rowFmtStr.append( cellStyle2 );
00190 rowFmtStr.append( QString::fromLatin1(
00191 ">"
00192 "%2"
00193 "</td>"
00194 "</tr>\n"
00195 ) );
00196
00197
00198 QString dynamicPart;
00199
00200
00201 if ( !internalLoading ) {
00202 KABC::Picture pic = addr.photo();
00203 if ( pic.isIntern() && !pic.data().isNull() ) {
00204 image = pixmapAsDataUrl( pic.data() );
00205 } else if ( !pic.url().isEmpty() ) {
00206 image = (pic.url().startsWith( "http://" ) || pic.url().startsWith( "https://" ) ? pic.url() : "http://" + pic.url());
00207 } else {
00208 image = "file:" + KGlobal::iconLoader()->iconPath( "personal", KIcon::Desktop );
00209 }
00210 }
00211
00212 if ( fieldMask & BirthdayFields ) {
00213 QDate date = addr.birthday().date();
00214
00215 if ( date.isValid() )
00216 dynamicPart += rowFmtStr
00217 .arg( KABC::Addressee::birthdayLabel() )
00218 .arg( KGlobal::locale()->formatDate( date, true ) );
00219 }
00220
00221 if ( fieldMask & PhoneFields ) {
00222 KABC::PhoneNumber::List phones = addr.phoneNumbers();
00223 KABC::PhoneNumber::List::ConstIterator phoneIt;
00224 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
00225 QString number = (*phoneIt).number();
00226
00227 QString url;
00228 if ( (*phoneIt).type() & KABC::PhoneNumber::Fax )
00229 url = QString::fromLatin1( "fax:" ) + number;
00230 else
00231 url = QString::fromLatin1( "phone:" ) + number;
00232
00233 if ( linkMask & PhoneLinks ) {
00234 QString smsURL;
00235 if ( (*phoneIt).type() & KABC::PhoneNumber::Cell )
00236 smsURL = QString(" (<a href=\"sms:%1\">%2</a>)" ).arg( number ).arg( i18n( "SMS") );
00237
00238 dynamicPart += rowFmtStr
00239 .arg( KABC::PhoneNumber::typeLabel( (*phoneIt).type() ).replace( " ", " " ) )
00240 .arg( QString::fromLatin1( "<a href=\"%1\">%2</a>%3" ).arg( url ).arg( number ).arg( smsURL ) );
00241 } else {
00242 dynamicPart += rowFmtStr
00243 .arg( KABC::PhoneNumber::typeLabel( (*phoneIt).type() ).replace( " ", " " ) )
00244 .arg( number );
00245 }
00246 }
00247 }
00248
00249 if ( fieldMask & EmailFields ) {
00250 QStringList emails = addr.emails();
00251 QStringList::ConstIterator emailIt;
00252 QString type = i18n( "Email" );
00253 for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) {
00254 QString fullEmail = addr.fullEmail( *emailIt );
00255 QUrl::encode( fullEmail );
00256
00257 if ( linkMask & EmailLinks ) {
00258 dynamicPart += rowFmtStr.arg( type )
00259 .arg( QString::fromLatin1( "<a href=\"mailto:%1\">%2</a>" )
00260 .arg( fullEmail, *emailIt ) );
00261 } else {
00262 dynamicPart += rowFmtStr.arg( type ).arg( *emailIt );
00263 }
00264 }
00265 }
00266
00267 if ( fieldMask & URLFields ) {
00268 if ( !addr.url().url().isEmpty() ) {
00269 QString url;
00270 if ( linkMask & URLLinks ) {
00271 url = (addr.url().url().startsWith( "http://" ) || addr.url().url().startsWith( "https://" ) ? addr.url().url() :
00272 "http://" + addr.url().url());
00273 url = KStringHandler::tagURLs( url );
00274 } else {
00275 url = addr.url().url();
00276 }
00277 dynamicPart += rowFmtStr.arg( i18n("Homepage") ).arg( url );
00278 }
00279
00280 QString blog = addr.custom( "KADDRESSBOOK", "BlogFeed" );
00281 if ( !blog.isEmpty() ) {
00282 if ( linkMask & URLLinks ) {
00283 blog = KStringHandler::tagURLs( blog );
00284 }
00285 dynamicPart += rowFmtStr.arg( i18n("Blog Feed") ).arg( blog );
00286 }
00287 }
00288
00289 if ( fieldMask & AddressFields ) {
00290 KABC::Address::List addresses = addr.addresses();
00291 KABC::Address::List::ConstIterator addrIt;
00292 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
00293 if ( (*addrIt).label().isEmpty() ) {
00294 QString formattedAddress;
00295
00296 #if KDE_IS_VERSION(3,1,90)
00297 formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace();
00298 #else
00299 if ( !(*addrIt).street().isEmpty() )
00300 formattedAddress += (*addrIt).street() + "\n";
00301
00302 if ( !(*addrIt).postOfficeBox().isEmpty() )
00303 formattedAddress += (*addrIt).postOfficeBox() + "\n";
00304
00305 formattedAddress += (*addrIt).locality() + QString::fromLatin1(" ") + (*addrIt).region();
00306
00307 if ( !(*addrIt).postalCode().isEmpty() )
00308 formattedAddress += QString::fromLatin1(", ") + (*addrIt).postalCode();
00309
00310 formattedAddress += "\n";
00311
00312 if ( !(*addrIt).country().isEmpty() )
00313 formattedAddress += (*addrIt).country() + "\n";
00314
00315 formattedAddress += (*addrIt).extended();
00316 #endif
00317
00318 formattedAddress = formattedAddress.replace( '\n', "<br>" );
00319
00320 QString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
00321 formattedAddress + "</a>";
00322
00323 if ( linkMask & AddressLinks ) {
00324 dynamicPart += rowFmtStr
00325 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00326 .arg( link );
00327 } else {
00328 dynamicPart += rowFmtStr
00329 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00330 .arg( formattedAddress );
00331 }
00332 } else {
00333 QString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
00334 (*addrIt).label().replace( '\n', "<br>" ) + "</a>";
00335
00336 if ( linkMask & AddressLinks ) {
00337 dynamicPart += rowFmtStr
00338 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00339 .arg( link );
00340 } else {
00341 dynamicPart += rowFmtStr
00342 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00343 .arg( (*addrIt).label().replace( '\n', "<br>" ) );
00344 }
00345 }
00346 }
00347 }
00348
00349 QString notes;
00350 if ( !addr.note().isEmpty() ) {
00351
00352
00353
00354 notes = rowFmtStr.arg( i18n( "Notes" ) ).arg( addr.note().replace( '\n', "<br>" ) ) ;
00355 }
00356
00357 QString customData;
00358 if ( fieldMask & CustomFields ) {
00359 static QMap<QString, QString> titleMap;
00360 if ( titleMap.isEmpty() ) {
00361 titleMap.insert( "Department", i18n( "Department" ) );
00362 titleMap.insert( "Profession", i18n( "Profession" ) );
00363 titleMap.insert( "AssistantsName", i18n( "Assistant's Name" ) );
00364 titleMap.insert( "ManagersName", i18n( "Manager's Name" ) );
00365 titleMap.insert( "SpousesName", i18n( "Partner's Name" ) );
00366 titleMap.insert( "Office", i18n( "Office" ) );
00367 titleMap.insert( "IMAddress", i18n( "IM Address" ) );
00368 titleMap.insert( "Anniversary", i18n( "Anniversary" ) );
00369 }
00370
00371 if ( !addr.customs().empty() ) {
00372 QStringList customs = addr.customs();
00373 QStringList::Iterator it( customs.begin() );
00374 const QStringList::Iterator endIt( customs.end() );
00375 for ( ; it != endIt; ++it ) {
00376 QString customEntry = *it;
00377 if ( customEntry.startsWith ( "KADDRESSBOOK-" ) ) {
00378 customEntry.remove( "KADDRESSBOOK-X-" );
00379 customEntry.remove( "KADDRESSBOOK-" );
00380
00381 int pos = customEntry.find( ':' );
00382 QString key = customEntry.left( pos );
00383 const QString value = customEntry.mid( pos + 1 );
00384
00385
00386 if ( key == "BlogFeed" )
00387 continue;
00388
00389 const QMap<QString, QString>::ConstIterator keyIt = titleMap.find( key );
00390 if ( keyIt != titleMap.end() )
00391 key = keyIt.data();
00392
00393 customData += rowFmtStr.arg( key ).arg( value ) ;
00394 }
00395 }
00396 }
00397 }
00398
00399 QString name( addr.realName() );
00400 QString role( addr.role() );
00401 QString organization( addr.organization() );
00402
00403 if ( proxy && (fieldMask & IMFields) ) {
00404 if ( proxy->isPresent( addr.uid() ) && proxy->presenceNumeric( addr.uid() ) > 0 ) {
00405
00406 QString imgSrc;
00407 if ( internalLoading ) {
00408 imgSrc = QString::fromLatin1( "im_status_%1_image").arg( addr.uid() );
00409 QMimeSourceFactory::defaultFactory()->setPixmap( imgSrc, proxy->presenceIcon( addr.uid() ) );
00410 } else
00411 imgSrc = pixmapAsDataUrl( proxy->presenceIcon( addr.uid() ) );
00412
00413
00414 QString imStatus;
00415 if ( linkMask & IMLinks )
00416 imStatus = QString::fromLatin1( "<a href=\"im:\"><img src=\"%1\"> (%2)</a>" );
00417 else
00418 imStatus = QString::fromLatin1( "<img src=\"%1\"> (%2)" );
00419
00420
00421 dynamicPart += rowFmtStr
00422 .arg( i18n( "Presence" ) )
00423 .arg( imStatus
00424 .arg( imgSrc )
00425 .arg( proxy->presenceString( addr.uid() ) )
00426 );
00427 }
00428 }
00429
00430
00431
00432
00433
00434
00435 QString strAddr = QString::fromLatin1(
00436 "<div align=\"center\">"
00437 "<table cellpadding=\"1\" cellspacing=\"0\" %1>"
00438 "<tr>").arg(tableStyle);
00439
00440 strAddr.append( QString::fromLatin1(
00441 "<td align=\"right\" valign=\"top\" width=\"30%\" rowspan=\"3\" %2>")
00442 .arg( cellStyle ) );
00443 strAddr.append( QString::fromLatin1(
00444 "<img src=\"%1\" width=\"50\" vspace=\"1\">"
00445 "</td>")
00446 .arg( image ) );
00447 strAddr.append( QString::fromLatin1(
00448 "<td align=\"left\" width=\"70%\" %2>")
00449 .arg( cellStyle2 ) );
00450 strAddr.append( QString::fromLatin1(
00451 "<font size=\"+2\"><b>%2</b></font></td>"
00452 "</tr>")
00453 .arg( name ) );
00454 strAddr.append( QString::fromLatin1(
00455 "<tr>"
00456 "<td align=\"left\" width=\"70%\" %2>")
00457 .arg( cellStyle2 ) );
00458 strAddr.append( QString::fromLatin1(
00459 "%3</td>"
00460 "</tr>")
00461 .arg( role ) );
00462 strAddr.append( QString::fromLatin1(
00463 "<tr>"
00464 "<td align=\"left\" width=\"70%\" %2>")
00465 .arg( cellStyle2 ) );
00466 strAddr.append( QString::fromLatin1(
00467 "%4</td>"
00468 "</tr>")
00469 .arg( organization ) );
00470 strAddr.append( QString::fromLatin1(
00471 "<tr><td %2>")
00472 .arg( cellStyle ) );
00473 strAddr.append( QString::fromLatin1(
00474 " </td><td %2> </td></tr>")
00475 .arg( cellStyle2 ) );
00476 strAddr.append( dynamicPart );
00477 strAddr.append( notes );
00478 strAddr.append( customData );
00479 strAddr.append( QString::fromLatin1( "</table></div>\n" ) );
00480
00481 return strAddr;
00482 }
00483
00484 QString AddresseeView::pixmapAsDataUrl( const QPixmap& pixmap )
00485 {
00486 QByteArray ba;
00487 QBuffer buffer( ba );
00488 buffer.open( IO_WriteOnly );
00489 pixmap.save( &buffer, "PNG" );
00490 QString encoded( "data:image/png;base64," );
00491 encoded.append( KCodecs::base64Encode( ba ) );
00492 return encoded;
00493 }
00494
00495 void AddresseeView::updateView()
00496 {
00497
00498 setText( QString::null );
00499
00500 if ( mAddressee.isEmpty() )
00501 return;
00502
00503 if ( mImageJob ) {
00504 mImageJob->kill();
00505 mImageJob = 0;
00506
00507 mImageData.truncate( 0 );
00508 }
00509
00510 int fieldMask = NoFields;
00511 if ( mActionShowBirthday->isChecked() )
00512 fieldMask |= ( FieldMask )BirthdayFields;
00513 if ( mActionShowAddresses->isChecked() )
00514 fieldMask |= AddressFields;
00515 if ( mActionShowEmails->isChecked() )
00516 fieldMask |= EmailFields;
00517 if ( mActionShowPhones->isChecked() )
00518 fieldMask |= PhoneFields;
00519 if ( mActionShowURLs->isChecked() )
00520 fieldMask |= URLFields;
00521 if ( mActionShowIMAddresses->isChecked() )
00522 fieldMask |= IMFields;
00523 if ( mActionShowCustomFields->isChecked() )
00524 fieldMask |= CustomFields;
00525
00526 QString strAddr = vCardAsHTML( mAddressee, mKIMProxy, (LinkMask)mLinkMask,
00527 true, (FieldMask)fieldMask );
00528
00529 strAddr = QString::fromLatin1(
00530 "<html>"
00531 "<body text=\"%1\" bgcolor=\"%2\">"
00532 "%3"
00533 "</body>"
00534 "</html>" )
00535 .arg( KGlobalSettings::textColor().name() )
00536 .arg( KGlobalSettings::baseColor().name() )
00537 .arg( strAddr );
00538
00539 QString imageURL = QString( "contact_%1_image" ).arg( mAddressee.uid() );
00540
00541 KABC::Picture picture = mAddressee.photo();
00542 if ( picture.isIntern() && !picture.data().isNull() )
00543 QMimeSourceFactory::defaultFactory()->setImage( imageURL, picture.data() );
00544 else {
00545 if ( !picture.url().isEmpty() ) {
00546 if ( mImageData.count() > 0 )
00547 QMimeSourceFactory::defaultFactory()->setImage( imageURL, mImageData );
00548 else {
00549 mImageJob = KIO::get( KURL( picture.url() ), false, false );
00550 connect( mImageJob, SIGNAL( data( KIO::Job*, const QByteArray& ) ),
00551 this, SLOT( data( KIO::Job*, const QByteArray& ) ) );
00552 connect( mImageJob, SIGNAL( result( KIO::Job* ) ),
00553 this, SLOT( result( KIO::Job* ) ) );
00554 }
00555 } else {
00556 QMimeSourceFactory::defaultFactory()->setPixmap( imageURL,
00557 KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 128 ) );
00558 }
00559 }
00560
00561
00562 setText( strAddr );
00563 }
00564
00565 KABC::Addressee AddresseeView::addressee() const
00566 {
00567 return mAddressee;
00568 }
00569
00570 void AddresseeView::urlClicked( const QString &url )
00571 {
00572 kapp->invokeBrowser( url );
00573 }
00574
00575 void AddresseeView::emailClicked( const QString &email )
00576 {
00577 if ( email.startsWith( "mailto:" ) )
00578 kapp->invokeMailer( email.mid( 7 ), QString::null );
00579 else
00580 kapp->invokeMailer( email, QString::null );
00581 }
00582
00583 void AddresseeView::phoneNumberClicked( const QString &number )
00584 {
00585 KConfig config( "kaddressbookrc" );
00586 config.setGroup( "General" );
00587 QString commandLine = config.readEntry( "PhoneHookApplication" );
00588
00589 if ( commandLine.isEmpty() ) {
00590 KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
00591 return;
00592 }
00593
00594 commandLine.replace( "%N", number );
00595 KRun::runCommand( commandLine );
00596 }
00597
00598 void AddresseeView::smsTextClicked( const QString &number )
00599 {
00600 KConfig config( "kaddressbookrc" );
00601 config.setGroup( "General" );
00602 QString commandLine = config.readEntry( "SMSHookApplication" );
00603
00604 if ( commandLine.isEmpty() ) {
00605 KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
00606 return;
00607 }
00608
00609 SendSMSDialog dlg( mAddressee.realName(), this );
00610
00611 if ( dlg.exec() )
00612 sendSMS ( number, dlg.text() );
00613 }
00614
00615 void AddresseeView::sendSMS( const QString &number, const QString &text )
00616 {
00617 KConfig config( "kaddressbookrc" );
00618 config.setGroup( "General" );
00619 QString commandLine = config.readEntry( "SMSHookApplication" );
00620
00621 KTempFile file ;
00622 QTextStream* stream = file.textStream();
00623 *stream << text;
00624 file.close();
00625
00626 commandLine.replace( "%N", number );
00627 commandLine.replace( "%F", file.name() );
00628
00629 KRun::runCommand( commandLine );
00630 }
00631
00632 void AddresseeView::faxNumberClicked( const QString &number )
00633 {
00634 KConfig config( "kaddressbookrc" );
00635 config.setGroup( "General" );
00636 QString commandLine = config.readEntry( "FaxHookApplication", "kdeprintfax --phone %N" );
00637
00638 if ( commandLine.isEmpty() ) {
00639 KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
00640 return;
00641 }
00642
00643 commandLine.replace( "%N", number );
00644 KRun::runCommand( commandLine );
00645 }
00646
00647 void AddresseeView::imAddressClicked()
00648 {
00649 mKIMProxy->chatWithContact( mAddressee.uid() );
00650 }
00651
00652 QPopupMenu *AddresseeView::createPopupMenu( const QPoint& )
00653 {
00654 QPopupMenu *menu = new QPopupMenu( this );
00655 mActionShowBirthday->plug( menu );
00656 mActionShowAddresses->plug( menu );
00657 mActionShowEmails->plug( menu );
00658 mActionShowPhones->plug( menu );
00659 mActionShowURLs->plug( menu );
00660 mActionShowIMAddresses->plug( menu );
00661 mActionShowCustomFields->plug( menu );
00662
00663 return menu;
00664 }
00665
00666 void AddresseeView::slotMailClicked( const QString&, const QString &email )
00667 {
00668 emailClicked( email );
00669 }
00670
00671 void AddresseeView::slotUrlClicked( const QString &url )
00672 {
00673 if ( url.startsWith( "phone:" ) )
00674 phoneNumberClicked( strippedNumber( url.mid( 8 ) ) );
00675 else if ( url.startsWith( "sms:" ) )
00676 smsTextClicked( strippedNumber( url.mid( 6 ) ) );
00677 else if ( url.startsWith( "fax:" ) )
00678 faxNumberClicked( strippedNumber( url.mid( 6 ) ) );
00679 else if ( url.startsWith( "addr:" ) )
00680 emit addressClicked( url.mid( 7 ) );
00681 else if ( url.startsWith( "im:" ) )
00682 imAddressClicked();
00683 else
00684 urlClicked( url );
00685 }
00686
00687 void AddresseeView::slotHighlighted( const QString &link )
00688 {
00689 if ( link.startsWith( "mailto:" ) ) {
00690 QString email = link.mid( 7 );
00691
00692 emit emailHighlighted( email );
00693 emit highlightedMessage( i18n( "Send mail to '%1'" ).arg( email ) );
00694 } else if ( link.startsWith( "phone:" ) ) {
00695 QString number = link.mid( 8 );
00696
00697 emit phoneNumberHighlighted( strippedNumber( number ) );
00698 emit highlightedMessage( i18n( "Call number %1" ).arg( number ) );
00699 } else if ( link.startsWith( "fax:" ) ) {
00700 QString number = link.mid( 6 );
00701
00702 emit faxNumberHighlighted( strippedNumber( number ) );
00703 emit highlightedMessage( i18n( "Send fax to %1" ).arg( number ) );
00704 } else if ( link.startsWith( "addr:" ) ) {
00705 emit highlightedMessage( i18n( "Show address on map" ) );
00706 } else if ( link.startsWith( "sms:" ) ) {
00707 QString number = link.mid( 6 );
00708 emit highlightedMessage( i18n( "Send SMS to %1" ).arg( number ) );
00709 } else if ( link.startsWith( "http:" ) || link.startsWith( "https:" ) ) {
00710 emit urlHighlighted( link );
00711 emit highlightedMessage( i18n( "Open URL %1" ).arg( link ) );
00712 } else if ( link.startsWith( "im:" ) ) {
00713 emit highlightedMessage( i18n( "Chat with %1" ).arg( mAddressee.realName() ) );
00714 } else
00715 emit highlightedMessage( "" );
00716 }
00717
00718 void AddresseeView::slotPresenceChanged( const QString &uid )
00719 {
00720 kdDebug() << k_funcinfo << " uid is: " << uid << " mAddressee is: " << mAddressee.uid() << endl;
00721 if ( uid == mAddressee.uid() )
00722 updateView();
00723 }
00724
00725
00726 void AddresseeView::slotPresenceInfoExpired()
00727 {
00728 updateView();
00729 }
00730
00731 void AddresseeView::configChanged()
00732 {
00733 save();
00734 updateView();
00735 }
00736
00737 void AddresseeView::data( KIO::Job*, const QByteArray &d )
00738 {
00739 unsigned int oldSize = mImageData.size();
00740 mImageData.resize( oldSize + d.size() );
00741 memcpy( mImageData.data() + oldSize, d.data(), d.size() );
00742 }
00743
00744 void AddresseeView::result( KIO::Job *job )
00745 {
00746 mImageJob = 0;
00747
00748 if ( job->error() )
00749 mImageData.truncate( 0 );
00750 else
00751 updateView();
00752 }
00753
00754 void AddresseeView::load()
00755 {
00756 mConfig->setGroup( "AddresseeViewSettings" );
00757 mActionShowBirthday->setChecked( mConfig->readBoolEntry( "ShowBirthday", false ) );
00758 mActionShowAddresses->setChecked( mConfig->readBoolEntry( "ShowAddresses", true ) );
00759 mActionShowEmails->setChecked( mConfig->readBoolEntry( "ShowEmails", true ) );
00760 mActionShowPhones->setChecked( mConfig->readBoolEntry( "ShowPhones", true ) );
00761 mActionShowURLs->setChecked( mConfig->readBoolEntry( "ShowURLs", true ) );
00762 mActionShowIMAddresses->setChecked( mConfig->readBoolEntry( "ShowIMAddresses", false ) );
00763 mActionShowCustomFields->setChecked( mConfig->readBoolEntry( "ShowCustomFields", false ) );
00764 }
00765
00766 void AddresseeView::save()
00767 {
00768 mConfig->setGroup( "AddresseeViewSettings" );
00769 mConfig->writeEntry( "ShowBirthday", mActionShowBirthday->isChecked() );
00770 mConfig->writeEntry( "ShowAddresses", mActionShowAddresses->isChecked() );
00771 mConfig->writeEntry( "ShowEmails", mActionShowEmails->isChecked() );
00772 mConfig->writeEntry( "ShowPhones", mActionShowPhones->isChecked() );
00773 mConfig->writeEntry( "ShowURLs", mActionShowURLs->isChecked() );
00774 mConfig->writeEntry( "ShowIMAddresses", mActionShowIMAddresses->isChecked() );
00775 mConfig->writeEntry( "ShowCustomFields", mActionShowCustomFields->isChecked() );
00776 mConfig->sync();
00777 }
00778
00779 QString AddresseeView::strippedNumber( const QString &number )
00780 {
00781 QString retval;
00782
00783 for ( uint i = 0; i < number.length(); ++i ) {
00784 QChar c = number[ i ];
00785 if ( c.isDigit() || c == '*' || c == '#' || c == '+' && i == 0 )
00786 retval.append( c );
00787 }
00788
00789 return retval;
00790 }
00791
00792 #include "addresseeview.moc"