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 <kabc/resource.h>
00031 #include <kactionclasses.h>
00032 #include <kapplication.h>
00033 #include <kconfig.h>
00034 #include <kglobal.h>
00035 #include <kglobalsettings.h>
00036 #include <kiconloader.h>
00037 #include <kio/job.h>
00038 #include <klocale.h>
00039 #include <kmdcodec.h>
00040 #include <kmessagebox.h>
00041 #include <krun.h>
00042 #include <kstringhandler.h>
00043 #include <ktempfile.h>
00044
00045 #include <kdebug.h>
00046
00047 #include "addresseeview.h"
00048 #include "sendsmsdialog.h"
00049 #include "resourceabc.h"
00050
00051 using namespace KPIM;
00052
00053 AddresseeView::AddresseeView( QWidget *parent, const char *name,
00054 KConfig *config )
00055 : KTextBrowser( parent, name ), mDefaultConfig( false ), mImageJob( 0 ),
00056 mLinkMask( AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks | CustomFields )
00057 {
00058 setWrapPolicy( QTextEdit::AtWordBoundary );
00059 setLinkUnderline( false );
00060 setVScrollBarMode( QScrollView::AlwaysOff );
00061 setHScrollBarMode( QScrollView::AlwaysOff );
00062
00063 QStyleSheet *sheet = styleSheet();
00064 QStyleSheetItem *link = sheet->item( "a" );
00065 link->setColor( KGlobalSettings::linkColor() );
00066
00067 connect( this, SIGNAL( mailClick( const QString&, const QString& ) ),
00068 this, SLOT( slotMailClicked( const QString&, const QString& ) ) );
00069 connect( this, SIGNAL( urlClick( const QString& ) ),
00070 this, SLOT( slotUrlClicked( const QString& ) ) );
00071 connect( this, SIGNAL( highlighted( const QString& ) ),
00072 this, SLOT( slotHighlighted( const QString& ) ) );
00073
00074 setNotifyClick( true );
00075
00076 mActionShowBirthday = new KToggleAction( i18n( "Show Birthday" ) );
00077 mActionShowBirthday->setCheckedState( i18n( "Hide Birthday" ) );
00078 mActionShowAddresses = new KToggleAction( i18n( "Show Postal Addresses" ) );
00079 mActionShowAddresses->setCheckedState( i18n( "Hide Postal Addresses" ) );
00080 mActionShowEmails = new KToggleAction( i18n( "Show Email Addresses" ) );
00081 mActionShowEmails->setCheckedState( i18n( "Hide Email Addresses" ) );
00082 mActionShowPhones = new KToggleAction( i18n( "Show Telephone Numbers" ) );
00083 mActionShowPhones->setCheckedState( i18n( "Hide Telephone Numbers" ) );
00084 mActionShowURLs = new KToggleAction( i18n( "Show Web Pages (URLs)" ) );
00085 mActionShowURLs->setCheckedState( i18n( "Hide Web Pages (URLs)" ) );
00086 mActionShowIMAddresses = new KToggleAction( i18n( "Show Instant Messaging Addresses" ) );
00087 mActionShowIMAddresses->setCheckedState( i18n( "Hide Instant Messaging Addresses" ) );
00088 mActionShowCustomFields = new KToggleAction( i18n( "Show Custom Fields" ) );
00089 mActionShowCustomFields->setCheckedState( i18n( "Hide Custom Fields" ) );
00090
00091 connect( mActionShowBirthday, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00092 connect( mActionShowAddresses, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00093 connect( mActionShowEmails, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00094 connect( mActionShowPhones, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00095 connect( mActionShowURLs, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00096 connect( mActionShowIMAddresses, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00097 connect( mActionShowCustomFields, SIGNAL( toggled( bool ) ), SLOT( configChanged() ) );
00098
00099 if ( !config ) {
00100 mConfig = new KConfig( "kaddressbookrc" );
00101 mDefaultConfig = true;
00102 } else
00103 mConfig = config;
00104
00105 load();
00106
00107
00108 mKIMProxy = ::KIMProxy::instance( kapp->dcopClient() );
00109 connect( mKIMProxy, SIGNAL( sigContactPresenceChanged( const QString& ) ),
00110 this, SLOT( slotPresenceChanged( const QString& ) ) );
00111 connect( mKIMProxy, SIGNAL( sigPresenceInfoExpired() ),
00112 this, SLOT( slotPresenceInfoExpired() ) );
00113 }
00114
00115 AddresseeView::~AddresseeView()
00116 {
00117 if ( mDefaultConfig )
00118 delete mConfig;
00119 mConfig = 0;
00120
00121 delete mActionShowBirthday;
00122 delete mActionShowAddresses;
00123 delete mActionShowEmails;
00124 delete mActionShowPhones;
00125 delete mActionShowURLs;
00126 delete mActionShowIMAddresses;
00127 delete mActionShowCustomFields;
00128
00129 mKIMProxy = 0;
00130 }
00131
00132 void AddresseeView::setAddressee( const KABC::Addressee& addr )
00133 {
00134 mAddressee = addr;
00135
00136 if ( mImageJob ) {
00137 mImageJob->kill();
00138 mImageJob = 0;
00139 }
00140
00141 mImageData.truncate( 0 );
00142
00143 updateView();
00144 }
00145
00146 void AddresseeView::enableLinks( int linkMask )
00147 {
00148 mLinkMask = linkMask;
00149 }
00150
00151 QString AddresseeView::vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask,
00152 bool internalLoading, FieldMask fieldMask )
00153 {
00154 QString image = QString( "contact_%1_image" ).arg( addr.uid() );
00155
00156
00157
00158
00159
00160
00161
00162
00163 QString backgroundColor = KGlobalSettings::alternateBackgroundColor().name();
00164 QString cellStyle = QString::fromLatin1(
00165 "style=\""
00166 "padding-right: 2px; "
00167 "border-right: #000 dashed 1px; "
00168 "background: %1;\"").arg(backgroundColor);
00169 QString backgroundColor2 = KGlobalSettings::baseColor().name();
00170 QString cellStyle2 = QString::fromLatin1(
00171 "style=\""
00172 "padding-left: 2px; "
00173 "background: %1;\"").arg(backgroundColor2);
00174 QString tableStyle = QString::fromLatin1(
00175 "style=\""
00176 "border: solid 1px; "
00177 "margin: 0em;\"");
00178
00179
00180
00181
00182 QString rowFmtStr = QString::fromLatin1(
00183 "<tr>"
00184 "<td align=\"right\" valign=\"top\" width=\"30%\" ");
00185 rowFmtStr.append( cellStyle );
00186 rowFmtStr.append( QString::fromLatin1(
00187 ">"
00188 "<b>%1</b>"
00189 "</td>"
00190 "<td align=\"left\" valign=\"top\" width=\"70%\" ") );
00191 rowFmtStr.append( cellStyle2 );
00192 rowFmtStr.append( QString::fromLatin1(
00193 ">"
00194 "%2"
00195 "</td>"
00196 "</tr>\n"
00197 ) );
00198
00199
00200 QString dynamicPart;
00201
00202
00203 if ( !internalLoading ) {
00204 KABC::Picture pic = addr.photo();
00205 if ( pic.isIntern() && !pic.data().isNull() ) {
00206 image = pixmapAsDataUrl( pic.data() );
00207 } else if ( !pic.url().isEmpty() ) {
00208 image = (pic.url().startsWith( "http://" ) || pic.url().startsWith( "https://" ) ? pic.url() : "http://" + pic.url());
00209 } else {
00210 image = "file:" + KGlobal::iconLoader()->iconPath( "personal", KIcon::Desktop );
00211 }
00212 }
00213
00214 if ( fieldMask & BirthdayFields ) {
00215 QDate date = addr.birthday().date();
00216
00217 if ( date.isValid() )
00218 dynamicPart += rowFmtStr
00219 .arg( KABC::Addressee::birthdayLabel() )
00220 .arg( KGlobal::locale()->formatDate( date, true ) );
00221 }
00222
00223 if ( fieldMask & PhoneFields ) {
00224 KABC::PhoneNumber::List phones = addr.phoneNumbers();
00225 KABC::PhoneNumber::List::ConstIterator phoneIt;
00226 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
00227 QString number = QStyleSheet::escape( (*phoneIt).number() );
00228
00229 QString url;
00230 if ( (*phoneIt).type() & KABC::PhoneNumber::Fax )
00231 url = QString::fromLatin1( "fax:" ) + number;
00232 else
00233 url = QString::fromLatin1( "phone:" ) + number;
00234
00235 if ( linkMask & PhoneLinks ) {
00236 QString smsURL;
00237 if ( (*phoneIt).type() & KABC::PhoneNumber::Cell )
00238 smsURL = QString(" (<a href=\"sms:%1\">%2</a>)" ).arg( number ).arg( i18n( "SMS") );
00239
00240 dynamicPart += rowFmtStr
00241 .arg( (*phoneIt).typeLabel().replace( " ", " " ) )
00242 .arg( QString::fromLatin1( "<a href=\"%1\">%2</a>%3" ).arg( url ).arg( number ).arg( smsURL ) );
00243 } else {
00244 dynamicPart += rowFmtStr
00245 .arg( (*phoneIt).typeLabel().replace( " ", " " ) )
00246 .arg( number );
00247 }
00248 }
00249 }
00250
00251 if ( fieldMask & EmailFields ) {
00252 QStringList emails = addr.emails();
00253 QStringList::ConstIterator emailIt;
00254 QString type = i18n( "Email" );
00255 for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) {
00256 QString fullEmail = addr.fullEmail( *emailIt );
00257 QUrl::encode( fullEmail );
00258
00259 if ( linkMask & EmailLinks ) {
00260 dynamicPart += rowFmtStr.arg( type )
00261 .arg( QString::fromLatin1( "<a href=\"mailto:%1\">%2</a>" )
00262 .arg( fullEmail, QStyleSheet::escape( *emailIt ) ) );
00263 } else {
00264 dynamicPart += rowFmtStr.arg( type ).arg( *emailIt );
00265 }
00266 }
00267 }
00268
00269 if ( fieldMask & URLFields ) {
00270 if ( !addr.url().url().isEmpty() ) {
00271 QString url;
00272 if ( linkMask & URLLinks ) {
00273 url = (addr.url().url().startsWith( "http://" ) || addr.url().url().startsWith( "https://" ) ? addr.url().prettyURL() :
00274 "http://" + addr.url().prettyURL());
00275 url = KStringHandler::tagURLs( url );
00276 } else {
00277 url = addr.url().prettyURL();
00278 }
00279 dynamicPart += rowFmtStr.arg( i18n("Homepage") ).arg( url );
00280 }
00281
00282 QString blog = addr.custom( "KADDRESSBOOK", "BlogFeed" );
00283 if ( !blog.isEmpty() ) {
00284 if ( linkMask & URLLinks ) {
00285 blog = KStringHandler::tagURLs( blog );
00286 }
00287 dynamicPart += rowFmtStr.arg( i18n("Blog Feed") ).arg( blog );
00288 }
00289 }
00290
00291 if ( fieldMask & AddressFields ) {
00292 KABC::Address::List addresses = addr.addresses();
00293 KABC::Address::List::ConstIterator addrIt;
00294 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
00295 if ( (*addrIt).label().isEmpty() ) {
00296 QString formattedAddress;
00297
00298 formattedAddress = QStyleSheet::escape( (*addrIt).formattedAddress().stripWhiteSpace() );
00299 formattedAddress = formattedAddress.replace( '\n', "<br>" );
00300
00301 QString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
00302 formattedAddress + "</a>";
00303
00304 if ( linkMask & AddressLinks ) {
00305 dynamicPart += rowFmtStr
00306 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00307 .arg( link );
00308 } else {
00309 dynamicPart += rowFmtStr
00310 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00311 .arg( formattedAddress );
00312 }
00313 } else {
00314 QString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
00315 (*addrIt).label().replace( '\n', "<br>" ) + "</a>";
00316
00317 if ( linkMask & AddressLinks ) {
00318 dynamicPart += rowFmtStr
00319 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00320 .arg( link );
00321 } else {
00322 dynamicPart += rowFmtStr
00323 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
00324 .arg( (*addrIt).label().replace( '\n', "<br>" ) );
00325 }
00326 }
00327 }
00328 }
00329
00330 QString notes;
00331 if ( !addr.note().isEmpty() ) {
00332
00333
00334
00335 notes = QStyleSheet::escape( addr.note() );
00336 notes = rowFmtStr.arg( i18n( "Notes" ) ).arg( notes.replace( '\n', "<br>" ) ) ;
00337 }
00338
00339 QString customData;
00340 if ( fieldMask & CustomFields ) {
00341 static QMap<QString, QString> titleMap;
00342 if ( titleMap.isEmpty() ) {
00343 titleMap.insert( "Department", i18n( "Department" ) );
00344 titleMap.insert( "Profession", i18n( "Profession" ) );
00345 titleMap.insert( "AssistantsName", i18n( "Assistant's Name" ) );
00346 titleMap.insert( "ManagersName", i18n( "Manager's Name" ) );
00347 titleMap.insert( "SpousesName", i18n( "Partner's Name" ) );
00348 titleMap.insert( "Office", i18n( "Office" ) );
00349 titleMap.insert( "Anniversary", i18n( "Anniversary" ) );
00350 }
00351
00352 if ( !addr.customs().empty() ) {
00353 QStringList customs = addr.customs();
00354 QStringList::Iterator it( customs.begin() );
00355 const QStringList::Iterator endIt( customs.end() );
00356 for ( ; it != endIt; ++it ) {
00357 QString customEntry = *it;
00358 if ( customEntry.startsWith ( "KADDRESSBOOK-" ) ) {
00359 customEntry.remove( "KADDRESSBOOK-X-" );
00360 customEntry.remove( "KADDRESSBOOK-" );
00361
00362 int pos = customEntry.find( ':' );
00363 QString key = customEntry.left( pos );
00364 const QString value = customEntry.mid( pos + 1 );
00365
00366
00367 if ( key == "BlogFeed" || key == "IMAddress" )
00368 continue;
00369
00370 const QMap<QString, QString>::ConstIterator keyIt = titleMap.find( key );
00371 if ( keyIt != titleMap.end() )
00372 key = keyIt.data();
00373
00374 customData += rowFmtStr.arg( key ).arg( QStyleSheet::escape( value ) ) ;
00375 }
00376 }
00377 }
00378 }
00379
00380 QString name( QStyleSheet::escape( addr.realName() ) );
00381 QString role( QStyleSheet::escape( addr.role() ) );
00382 QString organization( QStyleSheet::escape( addr.organization() ) );
00383
00384 if ( fieldMask & IMFields ) {
00385
00386 const QString imAddress = addr.custom( "KADDRESSBOOK", "X-IMAddress" );
00387 if ( !imAddress.isEmpty() ) {
00388 customData += rowFmtStr.arg( i18n( "IM Address" ) ).arg( QStyleSheet::escape( imAddress ) ) ;
00389 }
00390
00391 if ( proxy ) {
00392 if ( proxy->isPresent( addr.uid() ) && proxy->presenceNumeric( addr.uid() ) > 0 ) {
00393
00394 QString imgSrc;
00395 if ( internalLoading ) {
00396 imgSrc = QString::fromLatin1( "im_status_%1_image").arg( addr.uid() );
00397 QMimeSourceFactory::defaultFactory()->setPixmap( imgSrc, proxy->presenceIcon( addr.uid() ) );
00398 } else
00399 imgSrc = pixmapAsDataUrl( proxy->presenceIcon( addr.uid() ) );
00400
00401
00402 QString imStatus;
00403 if ( linkMask & IMLinks )
00404 imStatus = QString::fromLatin1( "<a href=\"im:\"><img src=\"%1\"> (%2)</a>" );
00405 else
00406 imStatus = QString::fromLatin1( "<img src=\"%1\"> (%2)" );
00407
00408
00409 dynamicPart += rowFmtStr
00410 .arg( i18n( "Presence" ) )
00411 .arg( imStatus
00412 .arg( imgSrc )
00413 .arg( proxy->presenceString( addr.uid() ) )
00414 );
00415 }
00416 }
00417 }
00418
00419
00420
00421
00422
00423
00424 QString strAddr = QString::fromLatin1(
00425 "<div align=\"center\">"
00426 "<table cellpadding=\"1\" cellspacing=\"0\" %1>"
00427 "<tr>").arg(tableStyle);
00428
00429 strAddr.append( QString::fromLatin1(
00430 "<td align=\"right\" valign=\"top\" width=\"30%\" rowspan=\"3\" %2>")
00431 .arg( cellStyle ) );
00432 strAddr.append( QString::fromLatin1(
00433 "<img src=\"%1\" width=\"50\" vspace=\"1\">"
00434 "</td>")
00435 .arg( image ) );
00436 strAddr.append( QString::fromLatin1(
00437 "<td align=\"left\" width=\"70%\" %2>")
00438 .arg( cellStyle2 ) );
00439 strAddr.append( QString::fromLatin1(
00440 "<font size=\"+2\"><b>%2</b></font></td>"
00441 "</tr>")
00442 .arg( name ) );
00443 strAddr.append( QString::fromLatin1(
00444 "<tr>"
00445 "<td align=\"left\" width=\"70%\" %2>")
00446 .arg( cellStyle2 ) );
00447 strAddr.append( QString::fromLatin1(
00448 "%3</td>"
00449 "</tr>")
00450 .arg( role ) );
00451 strAddr.append( QString::fromLatin1(
00452 "<tr>"
00453 "<td align=\"left\" width=\"70%\" %2>")
00454 .arg( cellStyle2 ) );
00455 strAddr.append( QString::fromLatin1(
00456 "%4</td>"
00457 "</tr>")
00458 .arg( organization ) );
00459 strAddr.append( QString::fromLatin1(
00460 "<tr><td %2>")
00461 .arg( cellStyle ) );
00462 strAddr.append( QString::fromLatin1(
00463 " </td><td %2> </td></tr>")
00464 .arg( cellStyle2 ) );
00465 strAddr.append( dynamicPart );
00466 strAddr.append( notes );
00467 strAddr.append( customData );
00468 strAddr.append( QString::fromLatin1( "</table></div>\n" ) );
00469
00470 if ( addr.resource() ) {
00471 QString addrBookName = addr.resource()->resourceName();
00472 ResourceABC *r = dynamic_cast<ResourceABC*>( addr.resource() );
00473 if ( r && !r->subresources().isEmpty() ) {
00474 const QString subRes = r->uidToResourceMap()[ addr.uid() ];
00475 const QString label = r->subresourceLabel( subRes );
00476 if ( !label.isEmpty() )
00477 addrBookName = label;
00478 }
00479 strAddr.append( i18n( "<p><b>Address book</b>: %1</p>" ).arg( addrBookName ) );
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"