1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
|
/*
This file is part of libkdepim.
Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <tqbuffer.h>
#include <tqimage.h>
#include <tqpopupmenu.h>
#include <tqurl.h>
#include <kabc/address.h>
#include <kabc/addressee.h>
#include <kabc/phonenumber.h>
#include <kabc/resource.h>
#include <kactionclasses.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <kiconloader.h>
#include <kio/job.h>
#include <klocale.h>
#include <kmdcodec.h>
#include <kmessagebox.h>
#include <krun.h>
#include <kstringhandler.h>
#include <ktempfile.h>
#include <kdebug.h>
#include "addresseeview.h"
#include "sendsmsdialog.h"
#include "resourceabc.h"
using namespace KPIM;
AddresseeView::AddresseeView( TQWidget *parent, const char *name,
KConfig *config )
: KTextBrowser( parent, name ), mDefaultConfig( false ), mImageJob( 0 ),
mLinkMask( AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks | CustomFields )
{
setWrapPolicy( TQTextEdit::AtWordBoundary );
setLinkUnderline( false );
setVScrollBarMode( TQScrollView::AlwaysOff );
setHScrollBarMode( TQScrollView::AlwaysOff );
TQStyleSheet *sheet = styleSheet();
TQStyleSheetItem *link = sheet->item( "a" );
link->setColor( KGlobalSettings::linkColor() );
connect( this, TQT_SIGNAL( mailClick( const TQString&, const TQString& ) ),
this, TQT_SLOT( slotMailClicked( const TQString&, const TQString& ) ) );
connect( this, TQT_SIGNAL( urlClick( const TQString& ) ),
this, TQT_SLOT( slotUrlClicked( const TQString& ) ) );
connect( this, TQT_SIGNAL( highlighted( const TQString& ) ),
this, TQT_SLOT( slotHighlighted( const TQString& ) ) );
setNotifyClick( true );
mActionShowBirthday = new KToggleAction( i18n( "Show Birthday" ) );
mActionShowBirthday->setCheckedState( i18n( "Hide Birthday" ) );
mActionShowAddresses = new KToggleAction( i18n( "Show Postal Addresses" ) );
mActionShowAddresses->setCheckedState( i18n( "Hide Postal Addresses" ) );
mActionShowEmails = new KToggleAction( i18n( "Show Email Addresses" ) );
mActionShowEmails->setCheckedState( i18n( "Hide Email Addresses" ) );
mActionShowPhones = new KToggleAction( i18n( "Show Telephone Numbers" ) );
mActionShowPhones->setCheckedState( i18n( "Hide Telephone Numbers" ) );
mActionShowURLs = new KToggleAction( i18n( "Show Web Pages (URLs)" ) );
mActionShowURLs->setCheckedState( i18n( "Hide Web Pages (URLs)" ) );
mActionShowIMAddresses = new KToggleAction( i18n( "Show Instant Messaging Addresses" ) );
mActionShowIMAddresses->setCheckedState( i18n( "Hide Instant Messaging Addresses" ) );
mActionShowCustomFields = new KToggleAction( i18n( "Show Custom Fields" ) );
mActionShowCustomFields->setCheckedState( i18n( "Hide Custom Fields" ) );
connect( mActionShowBirthday, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) );
connect( mActionShowAddresses, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) );
connect( mActionShowEmails, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) );
connect( mActionShowPhones, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) );
connect( mActionShowURLs, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) );
connect( mActionShowIMAddresses, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) );
connect( mActionShowCustomFields, TQT_SIGNAL( toggled( bool ) ), TQT_SLOT( configChanged() ) );
if ( !config ) {
mConfig = new KConfig( "kaddressbookrc" );
mDefaultConfig = true;
} else
mConfig = config;
load();
// set up IMProxy to display contacts' IM presence and make connections to keep the display live
mKIMProxy = ::KIMProxy::instance( kapp->dcopClient() );
connect( mKIMProxy, TQT_SIGNAL( sigContactPresenceChanged( const TQString& ) ),
this, TQT_SLOT( slotPresenceChanged( const TQString& ) ) );
connect( mKIMProxy, TQT_SIGNAL( sigPresenceInfoExpired() ),
this, TQT_SLOT( slotPresenceInfoExpired() ) );
}
AddresseeView::~AddresseeView()
{
if ( mDefaultConfig )
delete mConfig;
mConfig = 0;
delete mActionShowBirthday;
delete mActionShowAddresses;
delete mActionShowEmails;
delete mActionShowPhones;
delete mActionShowURLs;
delete mActionShowIMAddresses;
delete mActionShowCustomFields;
mKIMProxy = 0;
}
void AddresseeView::setAddressee( const KABC::Addressee& addr )
{
mAddressee = addr;
if ( mImageJob ) {
mImageJob->kill();
mImageJob = 0;
}
mImageData.truncate( 0 );
updateView();
}
void AddresseeView::enableLinks( int linkMask )
{
mLinkMask = linkMask;
}
TQString AddresseeView::vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask,
bool internalLoading, FieldMask fieldMask )
{
TQString image = TQString( "contact_%1_image" ).arg( addr.uid() );
// Style strings from Gentix; this is just an initial version.
//
// These will be substituted into various HTML strings with .arg().
// Search for @STYLE@ to find where. Note how we use %1 as a
// placeholder where we fill in something else (in this case,
// the global background color).
//
TQString backgroundColor = KGlobalSettings::alternateBackgroundColor().name();
TQString cellStyle = TQString::fromLatin1(
"style=\""
"padding-right: 2px; "
"border-right: #000 dashed 1px; "
"background: %1;\"").arg(backgroundColor);
TQString backgroundColor2 = KGlobalSettings::baseColor().name();
TQString cellStyle2 = TQString::fromLatin1(
"style=\""
"padding-left: 2px; "
"background: %1;\"").arg(backgroundColor2);
TQString tableStyle = TQString::fromLatin1(
"style=\""
"border: solid 1px; "
"margin: 0em;\"");
// We'll be building a table to display the vCard in.
// Each row of the table will be built using this string for its HTML.
//
TQString rowFmtStr = TQString::fromLatin1(
"<tr>"
"<td align=\"right\" valign=\"top\" width=\"30%\" "); // Tag unclosed
rowFmtStr.append( cellStyle );
rowFmtStr.append( TQString::fromLatin1(
">" // Close tag
"<b>%1</b>"
"</td>"
"<td align=\"left\" valign=\"top\" width=\"70%\" ") ); // Tag unclosed
rowFmtStr.append( cellStyle2 );
rowFmtStr.append( TQString::fromLatin1(
">" // Close tag
"%2"
"</td>"
"</tr>\n"
) );
// Build the table's rows here
TQString dynamicPart;
if ( !internalLoading ) {
KABC::Picture pic = addr.photo();
if ( pic.isIntern() && !pic.data().isNull() ) {
image = pixmapAsDataUrl( pic.data() );
} else if ( !pic.url().isEmpty() ) {
image = (pic.url().startsWith( "http://" ) || pic.url().startsWith( "https://" ) ? pic.url() : "http://" + pic.url());
} else {
image = "file:" + KGlobal::iconLoader()->iconPath( "personal", KIcon::Desktop );
}
}
if ( fieldMask & BirthdayFields ) {
TQDate date = addr.birthday().date();
if ( date.isValid() )
dynamicPart += rowFmtStr
.arg( KABC::Addressee::birthdayLabel() )
.arg( KGlobal::locale()->formatDate( date, true ) );
}
if ( fieldMask & PhoneFields ) {
KABC::PhoneNumber::List phones = addr.phoneNumbers();
KABC::PhoneNumber::List::ConstIterator phoneIt;
for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
TQString number = TQStyleSheet::escape( (*phoneIt).number() );
TQString url;
if ( (*phoneIt).type() & KABC::PhoneNumber::Fax )
url = TQString::fromLatin1( "fax:" ) + number;
else
url = TQString::fromLatin1( "phone:" ) + number;
if ( linkMask & PhoneLinks ) {
TQString smsURL;
if ( (*phoneIt).type() & KABC::PhoneNumber::Cell )
smsURL = TQString(" (<a href=\"sms:%1\">%2</a>)" ).arg( number ).arg( i18n( "SMS") );
dynamicPart += rowFmtStr
.arg( (*phoneIt).typeLabel().replace( " ", " " ) )
.arg( TQString::fromLatin1( "<a href=\"%1\">%2</a>%3" ).arg( url ).arg( number ).arg( smsURL ) );
} else {
dynamicPart += rowFmtStr
.arg( (*phoneIt).typeLabel().replace( " ", " " ) )
.arg( number );
}
}
}
if ( fieldMask & EmailFields ) {
TQStringList emails = addr.emails();
TQStringList::ConstIterator emailIt;
TQString type = i18n( "Email" );
for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) {
TQString fullEmail = addr.fullEmail( *emailIt );
TQUrl::encode( fullEmail );
if ( linkMask & EmailLinks ) {
dynamicPart += rowFmtStr.arg( type )
.arg( TQString::fromLatin1( "<a href=\"mailto:%1\">%2</a>" )
.arg( fullEmail, TQStyleSheet::escape( *emailIt ) ) );
} else {
dynamicPart += rowFmtStr.arg( type ).arg( *emailIt );
}
}
}
if ( fieldMask & URLFields ) {
if ( !addr.url().url().isEmpty() ) {
TQString url;
if ( linkMask & URLLinks ) {
url = (addr.url().url().startsWith( "http://" ) || addr.url().url().startsWith( "https://" ) ? addr.url().prettyURL() :
"http://" + addr.url().prettyURL());
url = KStringHandler::tagURLs( url );
} else {
url = addr.url().prettyURL();
}
dynamicPart += rowFmtStr.arg( i18n("Homepage") ).arg( url );
}
TQString blog = addr.custom( "KADDRESSBOOK", "BlogFeed" );
if ( !blog.isEmpty() ) {
if ( linkMask & URLLinks ) {
blog = KStringHandler::tagURLs( blog );
}
dynamicPart += rowFmtStr.arg( i18n("Blog Feed") ).arg( blog );
}
}
if ( fieldMask & AddressFields ) {
KABC::Address::List addresses = addr.addresses();
KABC::Address::List::ConstIterator addrIt;
for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
if ( (*addrIt).label().isEmpty() ) {
TQString formattedAddress;
formattedAddress = TQStyleSheet::escape( (*addrIt).formattedAddress().stripWhiteSpace() );
formattedAddress = formattedAddress.replace( '\n', "<br>" );
TQString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
formattedAddress + "</a>";
if ( linkMask & AddressLinks ) {
dynamicPart += rowFmtStr
.arg( KABC::Address::typeLabel( (*addrIt).type() ) )
.arg( link );
} else {
dynamicPart += rowFmtStr
.arg( KABC::Address::typeLabel( (*addrIt).type() ) )
.arg( formattedAddress );
}
} else {
TQString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
(*addrIt).label().replace( '\n', "<br>" ) + "</a>";
if ( linkMask & AddressLinks ) {
dynamicPart += rowFmtStr
.arg( KABC::Address::typeLabel( (*addrIt).type() ) )
.arg( link );
} else {
dynamicPart += rowFmtStr
.arg( KABC::Address::typeLabel( (*addrIt).type() ) )
.arg( (*addrIt).label().replace( '\n', "<br>" ) );
}
}
}
}
TQString notes;
if ( !addr.note().isEmpty() ) {
// @STYLE@ - substitute the cell style in first, and append
// the data afterwards (keeps us safe from possible % signs
// in either one).
notes = TQStyleSheet::escape( addr.note() );
notes = rowFmtStr.arg( i18n( "Notes" ) ).arg( notes.replace( '\n', "<br>" ) ) ;
}
TQString customData;
if ( fieldMask & CustomFields ) {
static TQMap<TQString, TQString> titleMap;
if ( titleMap.isEmpty() ) {
titleMap.insert( "Department", i18n( "Department" ) );
titleMap.insert( "Profession", i18n( "Profession" ) );
titleMap.insert( "AssistantsName", i18n( "Assistant's Name" ) );
titleMap.insert( "ManagersName", i18n( "Manager's Name" ) );
titleMap.insert( "SpousesName", i18n( "Partner's Name" ) );
titleMap.insert( "Office", i18n( "Office" ) );
titleMap.insert( "Anniversary", i18n( "Anniversary" ) );
}
if ( !addr.customs().empty() ) {
TQStringList customs = addr.customs();
TQStringList::Iterator it( customs.begin() );
const TQStringList::Iterator endIt( customs.end() );
for ( ; it != endIt; ++it ) {
TQString customEntry = *it;
if ( customEntry.startsWith ( "KADDRESSBOOK-" ) ) {
customEntry.remove( "KADDRESSBOOK-X-" );
customEntry.remove( "KADDRESSBOOK-" );
int pos = customEntry.find( ':' );
TQString key = customEntry.left( pos );
const TQString value = customEntry.mid( pos + 1 );
// blog and im address is handled separated
if ( key == "BlogFeed" || key == "IMAddress" )
continue;
const TQMap<TQString, TQString>::ConstIterator keyIt = titleMap.find( key );
if ( keyIt != titleMap.end() )
key = keyIt.data();
customData += rowFmtStr.arg( key ).arg( TQStyleSheet::escape( value ) ) ;
}
}
}
}
TQString name( TQStyleSheet::escape( addr.realName() ) );
TQString role( TQStyleSheet::escape( addr.role() ) );
TQString organization( TQStyleSheet::escape( addr.organization() ) );
if ( fieldMask & IMFields ) {
const TQString imAddress = addr.custom( "KADDRESSBOOK", "X-IMAddress" );
if ( !imAddress.isEmpty() ) {
customData += rowFmtStr.arg( i18n( "IM Address" ) ).arg( TQStyleSheet::escape( imAddress ) ) ;
}
if ( proxy ) {
if ( proxy->isPresent( addr.uid() ) && proxy->presenceNumeric( addr.uid() ) > 0 ) {
// set image source to either a TQMimeSourceFactory key or a data:/ URL
TQString imgSrc;
if ( internalLoading ) {
imgSrc = TQString::fromLatin1( "im_status_%1_image").arg( addr.uid() );
TQMimeSourceFactory::defaultFactory()->setPixmap( imgSrc, proxy->presenceIcon( addr.uid() ) );
} else
imgSrc = pixmapAsDataUrl( proxy->presenceIcon( addr.uid() ) );
// make the status a link, if required
TQString imStatus;
if ( linkMask & IMLinks )
imStatus = TQString::fromLatin1( "<a href=\"im:\"><img src=\"%1\"> (%2)</a>" );
else
imStatus = TQString::fromLatin1( "<img src=\"%1\"> (%2)" );
// append our status to the rest of the dynamic part of the addressee
dynamicPart += rowFmtStr
.arg( i18n( "Presence" ) )
.arg( imStatus
.arg( imgSrc )
.arg( proxy->presenceString( addr.uid() ) )
);
}
}
}
// @STYLE@ - construct the string by parts, substituting in
// the styles first. There are lots of appends, but we need to
// do it this way to avoid cases where the substituted string
// contains %1 and the like.
//
TQString strAddr = TQString::fromLatin1(
"<div align=\"center\">"
"<table cellpadding=\"1\" cellspacing=\"0\" %1>"
"<tr>").arg(tableStyle);
strAddr.append( TQString::fromLatin1(
"<td align=\"right\" valign=\"top\" width=\"30%\" rowspan=\"3\" %2>")
.arg( cellStyle ) );
strAddr.append( TQString::fromLatin1(
"<img src=\"%1\" width=\"50\" vspace=\"1\">" // image
"</td>")
.arg( image ) );
strAddr.append( TQString::fromLatin1(
"<td align=\"left\" width=\"70%\" %2>")
.arg( cellStyle2 ) );
strAddr.append( TQString::fromLatin1(
"<font size=\"+2\"><b>%2</b></font></td>" // name
"</tr>")
.arg( name ) );
strAddr.append( TQString::fromLatin1(
"<tr>"
"<td align=\"left\" width=\"70%\" %2>")
.arg( cellStyle2 ) );
strAddr.append( TQString::fromLatin1(
"%3</td>" // role
"</tr>")
.arg( role ) );
strAddr.append( TQString::fromLatin1(
"<tr>"
"<td align=\"left\" width=\"70%\" %2>")
.arg( cellStyle2 ) );
strAddr.append( TQString::fromLatin1(
"%4</td>" // organization
"</tr>")
.arg( organization ) );
strAddr.append( TQString::fromLatin1(
"<tr><td %2>")
.arg( cellStyle ) );
strAddr.append( TQString::fromLatin1(
" </td><td %2> </td></tr>")
.arg( cellStyle2 ) );
strAddr.append( dynamicPart );
strAddr.append( notes );
strAddr.append( customData );
strAddr.append( TQString::fromLatin1( "</table></div>\n" ) );
if ( addr.resource() ) {
TQString addrBookName = addr.resource()->resourceName();
ResourceABC *r = dynamic_cast<ResourceABC*>( addr.resource() );
if ( r && !r->subresources().isEmpty() ) {
const TQString subRes = r->uidToResourceMap()[ addr.uid() ];
const TQString label = r->subresourceLabel( subRes );
if ( !label.isEmpty() )
addrBookName = label;
}
strAddr.append( i18n( "<p><b>Address book</b>: %1</p>" ).arg( addrBookName ) );
}
return strAddr;
}
TQString AddresseeView::pixmapAsDataUrl( const TQPixmap& pixmap )
{
TQByteArray ba;
TQBuffer buffer( ba );
buffer.open( IO_WriteOnly );
pixmap.save( &buffer, "PNG" );
TQString encoded( "data:image/png;base64," );
encoded.append( KCodecs::base64Encode( ba ) );
return encoded;
}
void AddresseeView::updateView()
{
// clear view
setText( TQString::null );
if ( mAddressee.isEmpty() )
return;
if ( mImageJob ) {
mImageJob->kill();
mImageJob = 0;
mImageData.truncate( 0 );
}
int fieldMask = NoFields;
if ( mActionShowBirthday->isChecked() )
fieldMask |= ( FieldMask )BirthdayFields;
if ( mActionShowAddresses->isChecked() )
fieldMask |= AddressFields;
if ( mActionShowEmails->isChecked() )
fieldMask |= EmailFields;
if ( mActionShowPhones->isChecked() )
fieldMask |= PhoneFields;
if ( mActionShowURLs->isChecked() )
fieldMask |= URLFields;
if ( mActionShowIMAddresses->isChecked() )
fieldMask |= IMFields;
if ( mActionShowCustomFields->isChecked() )
fieldMask |= CustomFields;
TQString strAddr = vCardAsHTML( mAddressee, mKIMProxy, (LinkMask)mLinkMask,
true, (FieldMask)fieldMask );
strAddr = TQString::fromLatin1(
"<html>"
"<body text=\"%1\" bgcolor=\"%2\">" // text and background color
"%3" // dynamic part
"</body>"
"</html>" )
.arg( KGlobalSettings::textColor().name() )
.arg( KGlobalSettings::baseColor().name() )
.arg( strAddr );
TQString imageURL = TQString( "contact_%1_image" ).arg( mAddressee.uid() );
KABC::Picture picture = mAddressee.photo();
if ( picture.isIntern() && !picture.data().isNull() )
TQMimeSourceFactory::defaultFactory()->setImage( imageURL, picture.data() );
else {
if ( !picture.url().isEmpty() ) {
if ( mImageData.count() > 0 )
TQMimeSourceFactory::defaultFactory()->setImage( imageURL, mImageData );
else {
mImageJob = KIO::get( KURL( picture.url() ), false, false );
connect( mImageJob, TQT_SIGNAL( data( KIO::Job*, const TQByteArray& ) ),
this, TQT_SLOT( data( KIO::Job*, const TQByteArray& ) ) );
connect( mImageJob, TQT_SIGNAL( result( KIO::Job* ) ),
this, TQT_SLOT( result( KIO::Job* ) ) );
}
} else {
TQMimeSourceFactory::defaultFactory()->setPixmap( imageURL,
KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 128 ) );
}
}
// at last display it...
setText( strAddr );
}
KABC::Addressee AddresseeView::addressee() const
{
return mAddressee;
}
void AddresseeView::urlClicked( const TQString &url )
{
kapp->invokeBrowser( url );
}
void AddresseeView::emailClicked( const TQString &email )
{
if ( email.startsWith( "mailto:" ) )
kapp->invokeMailer( email.mid( 7 ), TQString::null );
else
kapp->invokeMailer( email, TQString::null );
}
void AddresseeView::phoneNumberClicked( const TQString &number )
{
KConfig config( "kaddressbookrc" );
config.setGroup( "General" );
TQString commandLine = config.readEntry( "PhoneHookApplication" );
if ( commandLine.isEmpty() ) {
KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
return;
}
commandLine.replace( "%N", number );
KRun::runCommand( commandLine );
}
void AddresseeView::smsTextClicked( const TQString &number )
{
KConfig config( "kaddressbookrc" );
config.setGroup( "General" );
TQString commandLine = config.readEntry( "SMSHookApplication" );
if ( commandLine.isEmpty() ) {
KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
return;
}
SendSMSDialog dlg( mAddressee.realName(), this );
if ( dlg.exec() )
sendSMS ( number, dlg.text() );
}
void AddresseeView::sendSMS( const TQString &number, const TQString &text )
{
KConfig config( "kaddressbookrc" );
config.setGroup( "General" );
TQString commandLine = config.readEntry( "SMSHookApplication" );
KTempFile file ;
TQTextStream* stream = file.textStream();
*stream << text;
file.close();
commandLine.replace( "%N", number );
commandLine.replace( "%F", file.name() );
KRun::runCommand( commandLine );
}
void AddresseeView::faxNumberClicked( const TQString &number )
{
KConfig config( "kaddressbookrc" );
config.setGroup( "General" );
TQString commandLine = config.readEntry( "FaxHookApplication", "kdeprintfax --phone %N" );
if ( commandLine.isEmpty() ) {
KMessageBox::sorry( this, i18n( "There is no application set which could be executed. Please go to the settings dialog and configure one." ) );
return;
}
commandLine.replace( "%N", number );
KRun::runCommand( commandLine );
}
void AddresseeView::imAddressClicked()
{
mKIMProxy->chatWithContact( mAddressee.uid() );
}
TQPopupMenu *AddresseeView::createPopupMenu( const TQPoint& )
{
TQPopupMenu *menu = new TQPopupMenu( this );
mActionShowBirthday->plug( menu );
mActionShowAddresses->plug( menu );
mActionShowEmails->plug( menu );
mActionShowPhones->plug( menu );
mActionShowURLs->plug( menu );
mActionShowIMAddresses->plug( menu );
mActionShowCustomFields->plug( menu );
return menu;
}
void AddresseeView::slotMailClicked( const TQString&, const TQString &email )
{
emailClicked( email );
}
void AddresseeView::slotUrlClicked( const TQString &url )
{
if ( url.startsWith( "phone:" ) )
phoneNumberClicked( strippedNumber( url.mid( 8 ) ) );
else if ( url.startsWith( "sms:" ) )
smsTextClicked( strippedNumber( url.mid( 6 ) ) );
else if ( url.startsWith( "fax:" ) )
faxNumberClicked( strippedNumber( url.mid( 6 ) ) );
else if ( url.startsWith( "addr:" ) )
emit addressClicked( url.mid( 7 ) );
else if ( url.startsWith( "im:" ) )
imAddressClicked();
else
urlClicked( url );
}
void AddresseeView::slotHighlighted( const TQString &link )
{
if ( link.startsWith( "mailto:" ) ) {
TQString email = link.mid( 7 );
emit emailHighlighted( email );
emit highlightedMessage( i18n( "Send mail to '%1'" ).arg( email ) );
} else if ( link.startsWith( "phone:" ) ) {
TQString number = link.mid( 8 );
emit phoneNumberHighlighted( strippedNumber( number ) );
emit highlightedMessage( i18n( "Call number %1" ).arg( number ) );
} else if ( link.startsWith( "fax:" ) ) {
TQString number = link.mid( 6 );
emit faxNumberHighlighted( strippedNumber( number ) );
emit highlightedMessage( i18n( "Send fax to %1" ).arg( number ) );
} else if ( link.startsWith( "addr:" ) ) {
emit highlightedMessage( i18n( "Show address on map" ) );
} else if ( link.startsWith( "sms:" ) ) {
TQString number = link.mid( 6 );
emit highlightedMessage( i18n( "Send SMS to %1" ).arg( number ) );
} else if ( link.startsWith( "http:" ) || link.startsWith( "https:" ) ) {
emit urlHighlighted( link );
emit highlightedMessage( i18n( "Open URL %1" ).arg( link ) );
} else if ( link.startsWith( "im:" ) ) {
emit highlightedMessage( i18n( "Chat with %1" ).arg( mAddressee.realName() ) );
} else
emit highlightedMessage( "" );
}
void AddresseeView::slotPresenceChanged( const TQString &uid )
{
kdDebug() << k_funcinfo << " uid is: " << uid << " mAddressee is: " << mAddressee.uid() << endl;
if ( uid == mAddressee.uid() )
updateView();
}
void AddresseeView::slotPresenceInfoExpired()
{
updateView();
}
void AddresseeView::configChanged()
{
save();
updateView();
}
void AddresseeView::data( KIO::Job*, const TQByteArray &d )
{
unsigned int oldSize = mImageData.size();
mImageData.resize( oldSize + d.size() );
memcpy( mImageData.data() + oldSize, d.data(), d.size() );
}
void AddresseeView::result( KIO::Job *job )
{
mImageJob = 0;
if ( job->error() )
mImageData.truncate( 0 );
else
updateView();
}
void AddresseeView::load()
{
mConfig->setGroup( "AddresseeViewSettings" );
mActionShowBirthday->setChecked( mConfig->readBoolEntry( "ShowBirthday", false ) );
mActionShowAddresses->setChecked( mConfig->readBoolEntry( "ShowAddresses", true ) );
mActionShowEmails->setChecked( mConfig->readBoolEntry( "ShowEmails", true ) );
mActionShowPhones->setChecked( mConfig->readBoolEntry( "ShowPhones", true ) );
mActionShowURLs->setChecked( mConfig->readBoolEntry( "ShowURLs", true ) );
mActionShowIMAddresses->setChecked( mConfig->readBoolEntry( "ShowIMAddresses", false ) );
mActionShowCustomFields->setChecked( mConfig->readBoolEntry( "ShowCustomFields", false ) );
}
void AddresseeView::save()
{
mConfig->setGroup( "AddresseeViewSettings" );
mConfig->writeEntry( "ShowBirthday", mActionShowBirthday->isChecked() );
mConfig->writeEntry( "ShowAddresses", mActionShowAddresses->isChecked() );
mConfig->writeEntry( "ShowEmails", mActionShowEmails->isChecked() );
mConfig->writeEntry( "ShowPhones", mActionShowPhones->isChecked() );
mConfig->writeEntry( "ShowURLs", mActionShowURLs->isChecked() );
mConfig->writeEntry( "ShowIMAddresses", mActionShowIMAddresses->isChecked() );
mConfig->writeEntry( "ShowCustomFields", mActionShowCustomFields->isChecked() );
mConfig->sync();
}
TQString AddresseeView::strippedNumber( const TQString &number )
{
TQString retval;
for ( uint i = 0; i < number.length(); ++i ) {
TQChar c = number[ i ];
if ( c.isDigit() || c == '*' || c == '#' || c == '+' && i == 0 )
retval.append( c );
}
return retval;
}
#include "addresseeview.moc"
|