You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
793 lines
27 KiB
793 lines
27 KiB
15 years ago
|
/*
|
||
13 years ago
|
This file is part of libtdepim.
|
||
15 years ago
|
|
||
|
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.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqbuffer.h>
|
||
|
#include <tqimage.h>
|
||
|
#include <tqpopupmenu.h>
|
||
|
#include <tqurl.h>
|
||
15 years ago
|
|
||
|
#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;
|
||
|
|
||
14 years ago
|
AddresseeView::AddresseeView( TQWidget *parent, const char *name,
|
||
15 years ago
|
KConfig *config )
|
||
14 years ago
|
: KTextBrowser( parent, name ), mDefaultConfig( false ), mImageJob( 0 ),
|
||
15 years ago
|
mLinkMask( AddressLinks | EmailLinks | PhoneLinks | URLLinks | IMLinks | CustomFields )
|
||
|
{
|
||
15 years ago
|
setWrapPolicy( TQTextEdit::AtWordBoundary );
|
||
15 years ago
|
setLinkUnderline( false );
|
||
15 years ago
|
setVScrollBarMode( TQScrollView::AlwaysOff );
|
||
|
setHScrollBarMode( TQScrollView::AlwaysOff );
|
||
15 years ago
|
|
||
15 years ago
|
TQStyleSheet *sheet = styleSheet();
|
||
|
TQStyleSheetItem *link = sheet->item( "a" );
|
||
15 years ago
|
link->setColor( KGlobalSettings::linkColor() );
|
||
|
|
||
15 years ago
|
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& ) ) );
|
||
15 years ago
|
|
||
|
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" ) );
|
||
|
|
||
15 years ago
|
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() ) );
|
||
15 years ago
|
|
||
|
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() );
|
||
15 years ago
|
connect( mKIMProxy, TQT_SIGNAL( sigContactPresenceChanged( const TQString& ) ),
|
||
|
this, TQT_SLOT( slotPresenceChanged( const TQString& ) ) );
|
||
|
connect( mKIMProxy, TQT_SIGNAL( sigPresenceInfoExpired() ),
|
||
|
this, TQT_SLOT( slotPresenceInfoExpired() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeView::vCardAsHTML( const KABC::Addressee& addr, ::KIMProxy *proxy, LinkMask linkMask,
|
||
15 years ago
|
bool internalLoading, FieldMask fieldMask )
|
||
|
{
|
||
14 years ago
|
TQString image = TQString( "contact_%1_image" ).tqarg( addr.uid() );
|
||
15 years ago
|
|
||
|
// Style strings from Gentix; this is just an initial version.
|
||
|
//
|
||
14 years ago
|
// These will be substituted into various HTML strings with .tqarg().
|
||
15 years ago
|
// 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).
|
||
|
//
|
||
15 years ago
|
TQString backgroundColor = KGlobalSettings::alternateBackgroundColor().name();
|
||
14 years ago
|
TQString cellStyle = TQString::tqfromLatin1(
|
||
15 years ago
|
"style=\""
|
||
|
"padding-right: 2px; "
|
||
|
"border-right: #000 dashed 1px; "
|
||
14 years ago
|
"background: %1;\"").tqarg(backgroundColor);
|
||
15 years ago
|
TQString backgroundColor2 = KGlobalSettings::baseColor().name();
|
||
14 years ago
|
TQString cellStyle2 = TQString::tqfromLatin1(
|
||
15 years ago
|
"style=\""
|
||
|
"padding-left: 2px; "
|
||
14 years ago
|
"background: %1;\"").tqarg(backgroundColor2);
|
||
14 years ago
|
TQString tableStyle = TQString::tqfromLatin1(
|
||
15 years ago
|
"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.
|
||
|
//
|
||
14 years ago
|
TQString rowFmtStr = TQString::tqfromLatin1(
|
||
15 years ago
|
"<tr>"
|
||
|
"<td align=\"right\" valign=\"top\" width=\"30%\" "); // Tag unclosed
|
||
|
rowFmtStr.append( cellStyle );
|
||
14 years ago
|
rowFmtStr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
">" // Close tag
|
||
|
"<b>%1</b>"
|
||
|
"</td>"
|
||
|
"<td align=\"left\" valign=\"top\" width=\"70%\" ") ); // Tag unclosed
|
||
|
rowFmtStr.append( cellStyle2 );
|
||
14 years ago
|
rowFmtStr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
">" // Close tag
|
||
|
"%2"
|
||
|
"</td>"
|
||
|
"</tr>\n"
|
||
|
) );
|
||
|
|
||
|
// Build the table's rows here
|
||
15 years ago
|
TQString dynamicPart;
|
||
15 years ago
|
|
||
|
|
||
|
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 ) {
|
||
15 years ago
|
TQDate date = addr.birthday().date();
|
||
15 years ago
|
|
||
|
if ( date.isValid() )
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( KABC::Addressee::birthdayLabel() )
|
||
|
.tqarg( KGlobal::locale()->formatDate( date, true ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( fieldMask & PhoneFields ) {
|
||
|
KABC::PhoneNumber::List phones = addr.phoneNumbers();
|
||
|
KABC::PhoneNumber::List::ConstIterator phoneIt;
|
||
|
for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
|
||
15 years ago
|
TQString number = TQStyleSheet::escape( (*phoneIt).number() );
|
||
15 years ago
|
|
||
15 years ago
|
TQString url;
|
||
15 years ago
|
if ( (*phoneIt).type() & KABC::PhoneNumber::Fax )
|
||
14 years ago
|
url = TQString::tqfromLatin1( "fax:" ) + number;
|
||
15 years ago
|
else
|
||
14 years ago
|
url = TQString::tqfromLatin1( "phone:" ) + number;
|
||
15 years ago
|
|
||
|
if ( linkMask & PhoneLinks ) {
|
||
15 years ago
|
TQString smsURL;
|
||
15 years ago
|
if ( (*phoneIt).type() & KABC::PhoneNumber::Cell )
|
||
14 years ago
|
smsURL = TQString(" (<a href=\"sms:%1\">%2</a>)" ).tqarg( number ).tqarg( i18n( "SMS") );
|
||
15 years ago
|
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( (*phoneIt).typeLabel().replace( " ", " " ) )
|
||
14 years ago
|
.tqarg( TQString::tqfromLatin1( "<a href=\"%1\">%2</a>%3" ).tqarg( url ).tqarg( number ).tqarg( smsURL ) );
|
||
15 years ago
|
} else {
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( (*phoneIt).typeLabel().replace( " ", " " ) )
|
||
14 years ago
|
.tqarg( number );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( fieldMask & EmailFields ) {
|
||
15 years ago
|
TQStringList emails = addr.emails();
|
||
|
TQStringList::ConstIterator emailIt;
|
||
|
TQString type = i18n( "Email" );
|
||
15 years ago
|
for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) {
|
||
15 years ago
|
TQString fullEmail = addr.fullEmail( *emailIt );
|
||
|
TQUrl::encode( fullEmail );
|
||
15 years ago
|
|
||
|
if ( linkMask & EmailLinks ) {
|
||
14 years ago
|
dynamicPart += rowFmtStr.tqarg( type )
|
||
|
.tqarg( TQString::tqfromLatin1( "<a href=\"mailto:%1\">%2</a>" )
|
||
|
.tqarg( fullEmail, TQStyleSheet::escape( *emailIt ) ) );
|
||
15 years ago
|
} else {
|
||
14 years ago
|
dynamicPart += rowFmtStr.tqarg( type ).tqarg( *emailIt );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( fieldMask & URLFields ) {
|
||
|
if ( !addr.url().url().isEmpty() ) {
|
||
15 years ago
|
TQString url;
|
||
15 years ago
|
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();
|
||
|
}
|
||
14 years ago
|
dynamicPart += rowFmtStr.tqarg( i18n("Homepage") ).tqarg( url );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString blog = addr.custom( "KADDRESSBOOK", "BlogFeed" );
|
||
15 years ago
|
if ( !blog.isEmpty() ) {
|
||
|
if ( linkMask & URLLinks ) {
|
||
|
blog = KStringHandler::tagURLs( blog );
|
||
|
}
|
||
14 years ago
|
dynamicPart += rowFmtStr.tqarg( i18n("Blog Feed") ).tqarg( blog );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
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() ) {
|
||
15 years ago
|
TQString formattedAddress;
|
||
15 years ago
|
|
||
15 years ago
|
formattedAddress = TQStyleSheet::escape( (*addrIt).formattedAddress().stripWhiteSpace() );
|
||
14 years ago
|
formattedAddress = formattedAddress.replace( '\n', "<br>" );
|
||
15 years ago
|
|
||
15 years ago
|
TQString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
|
||
15 years ago
|
formattedAddress + "</a>";
|
||
|
|
||
|
if ( linkMask & AddressLinks ) {
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( KABC::Address::typeLabel( (*addrIt).type() ) )
|
||
|
.tqarg( link );
|
||
15 years ago
|
} else {
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( KABC::Address::typeLabel( (*addrIt).type() ) )
|
||
|
.tqarg( formattedAddress );
|
||
15 years ago
|
}
|
||
|
} else {
|
||
15 years ago
|
TQString link = "<a href=\"addr:" + (*addrIt).id() + "\">" +
|
||
14 years ago
|
(*addrIt).label().replace( '\n', "<br>" ) + "</a>";
|
||
15 years ago
|
|
||
|
if ( linkMask & AddressLinks ) {
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( KABC::Address::typeLabel( (*addrIt).type() ) )
|
||
|
.tqarg( link );
|
||
15 years ago
|
} else {
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( KABC::Address::typeLabel( (*addrIt).type() ) )
|
||
14 years ago
|
.tqarg( (*addrIt).label().replace( '\n', "<br>" ) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString notes;
|
||
15 years ago
|
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).
|
||
15 years ago
|
notes = TQStyleSheet::escape( addr.note() );
|
||
14 years ago
|
notes = rowFmtStr.tqarg( i18n( "Notes" ) ).tqarg( notes.replace( '\n', "<br>" ) ) ;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString customData;
|
||
15 years ago
|
if ( fieldMask & CustomFields ) {
|
||
15 years ago
|
static TQMap<TQString, TQString> titleMap;
|
||
15 years ago
|
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() ) {
|
||
15 years ago
|
TQStringList customs = addr.customs();
|
||
|
TQStringList::Iterator it( customs.begin() );
|
||
|
const TQStringList::Iterator endIt( customs.end() );
|
||
15 years ago
|
for ( ; it != endIt; ++it ) {
|
||
15 years ago
|
TQString customEntry = *it;
|
||
15 years ago
|
if ( customEntry.startsWith ( "KADDRESSBOOK-" ) ) {
|
||
|
customEntry.remove( "KADDRESSBOOK-X-" );
|
||
|
customEntry.remove( "KADDRESSBOOK-" );
|
||
|
|
||
14 years ago
|
int pos = customEntry.find( ':' );
|
||
15 years ago
|
TQString key = customEntry.left( pos );
|
||
|
const TQString value = customEntry.mid( pos + 1 );
|
||
15 years ago
|
|
||
|
// blog and im address is handled separated
|
||
|
if ( key == "BlogFeed" || key == "IMAddress" )
|
||
|
continue;
|
||
|
|
||
14 years ago
|
const TQMap<TQString, TQString>::ConstIterator keyIt = titleMap.find( key );
|
||
15 years ago
|
if ( keyIt != titleMap.end() )
|
||
|
key = keyIt.data();
|
||
|
|
||
14 years ago
|
customData += rowFmtStr.tqarg( key ).tqarg( TQStyleSheet::escape( value ) ) ;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString name( TQStyleSheet::escape( addr.realName() ) );
|
||
|
TQString role( TQStyleSheet::escape( addr.role() ) );
|
||
|
TQString organization( TQStyleSheet::escape( addr.organization() ) );
|
||
15 years ago
|
|
||
|
if ( fieldMask & IMFields ) {
|
||
|
|
||
15 years ago
|
const TQString imAddress = addr.custom( "KADDRESSBOOK", "X-IMAddress" );
|
||
15 years ago
|
if ( !imAddress.isEmpty() ) {
|
||
14 years ago
|
customData += rowFmtStr.tqarg( i18n( "IM Address" ) ).tqarg( TQStyleSheet::escape( imAddress ) ) ;
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( proxy ) {
|
||
|
if ( proxy->isPresent( addr.uid() ) && proxy->presenceNumeric( addr.uid() ) > 0 ) {
|
||
15 years ago
|
// set image source to either a TQMimeSourceFactory key or a data:/ URL
|
||
|
TQString imgSrc;
|
||
15 years ago
|
if ( internalLoading ) {
|
||
14 years ago
|
imgSrc = TQString::tqfromLatin1( "im_status_%1_image").tqarg( addr.uid() );
|
||
15 years ago
|
TQMimeSourceFactory::defaultFactory()->setPixmap( imgSrc, proxy->presenceIcon( addr.uid() ) );
|
||
15 years ago
|
} else
|
||
|
imgSrc = pixmapAsDataUrl( proxy->presenceIcon( addr.uid() ) );
|
||
|
|
||
|
// make the status a link, if required
|
||
14 years ago
|
TQString imtqStatus;
|
||
15 years ago
|
if ( linkMask & IMLinks )
|
||
14 years ago
|
imtqStatus = TQString::tqfromLatin1( "<a href=\"im:\"><img src=\"%1\"> (%2)</a>" );
|
||
15 years ago
|
else
|
||
14 years ago
|
imtqStatus = TQString::tqfromLatin1( "<img src=\"%1\"> (%2)" );
|
||
15 years ago
|
|
||
|
// append our status to the rest of the dynamic part of the addressee
|
||
|
dynamicPart += rowFmtStr
|
||
14 years ago
|
.tqarg( i18n( "Presence" ) )
|
||
|
.tqarg( imtqStatus
|
||
|
.tqarg( imgSrc )
|
||
|
.tqarg( proxy->presenceString( addr.uid() ) )
|
||
15 years ago
|
);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// @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
|
||
14 years ago
|
// contains %1 and the like.
|
||
15 years ago
|
//
|
||
14 years ago
|
TQString strAddr = TQString::tqfromLatin1(
|
||
15 years ago
|
"<div align=\"center\">"
|
||
|
"<table cellpadding=\"1\" cellspacing=\"0\" %1>"
|
||
14 years ago
|
"<tr>").tqarg(tableStyle);
|
||
15 years ago
|
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"<td align=\"right\" valign=\"top\" width=\"30%\" rowspan=\"3\" %2>")
|
||
14 years ago
|
.tqarg( cellStyle ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"<img src=\"%1\" width=\"50\" vspace=\"1\">" // image
|
||
|
"</td>")
|
||
14 years ago
|
.tqarg( image ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"<td align=\"left\" width=\"70%\" %2>")
|
||
14 years ago
|
.tqarg( cellStyle2 ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"<font size=\"+2\"><b>%2</b></font></td>" // name
|
||
|
"</tr>")
|
||
14 years ago
|
.tqarg( name ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"<tr>"
|
||
|
"<td align=\"left\" width=\"70%\" %2>")
|
||
14 years ago
|
.tqarg( cellStyle2 ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"%3</td>" // role
|
||
|
"</tr>")
|
||
14 years ago
|
.tqarg( role ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"<tr>"
|
||
|
"<td align=\"left\" width=\"70%\" %2>")
|
||
14 years ago
|
.tqarg( cellStyle2 ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"%4</td>" // organization
|
||
|
"</tr>")
|
||
14 years ago
|
.tqarg( organization ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
"<tr><td %2>")
|
||
14 years ago
|
.tqarg( cellStyle ) );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1(
|
||
15 years ago
|
" </td><td %2> </td></tr>")
|
||
14 years ago
|
.tqarg( cellStyle2 ) );
|
||
15 years ago
|
strAddr.append( dynamicPart );
|
||
|
strAddr.append( notes );
|
||
|
strAddr.append( customData );
|
||
14 years ago
|
strAddr.append( TQString::tqfromLatin1( "</table></div>\n" ) );
|
||
15 years ago
|
|
||
|
if ( addr.resource() ) {
|
||
15 years ago
|
TQString addrBookName = addr.resource()->resourceName();
|
||
15 years ago
|
ResourceABC *r = dynamic_cast<ResourceABC*>( addr.resource() );
|
||
|
if ( r && !r->subresources().isEmpty() ) {
|
||
15 years ago
|
const TQString subRes = r->uidToResourceMap()[ addr.uid() ];
|
||
|
const TQString label = r->subresourceLabel( subRes );
|
||
15 years ago
|
if ( !label.isEmpty() )
|
||
|
addrBookName = label;
|
||
|
}
|
||
14 years ago
|
strAddr.append( i18n( "<p><b>Address book</b>: %1</p>" ).tqarg( addrBookName ) );
|
||
15 years ago
|
}
|
||
|
return strAddr;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeView::pixmapAsDataUrl( const TQPixmap& pixmap )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQByteArray ba;
|
||
|
TQBuffer buffer( ba );
|
||
15 years ago
|
buffer.open( IO_WriteOnly );
|
||
|
pixmap.save( &buffer, "PNG" );
|
||
15 years ago
|
TQString encoded( "data:image/png;base64," );
|
||
15 years ago
|
encoded.append( KCodecs::base64Encode( ba ) );
|
||
|
return encoded;
|
||
|
}
|
||
|
|
||
|
void AddresseeView::updateView()
|
||
|
{
|
||
|
// clear view
|
||
14 years ago
|
setText( TQString() );
|
||
15 years ago
|
|
||
|
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;
|
||
|
|
||
15 years ago
|
TQString strAddr = vCardAsHTML( mAddressee, mKIMProxy, (LinkMask)mLinkMask,
|
||
15 years ago
|
true, (FieldMask)fieldMask );
|
||
|
|
||
14 years ago
|
strAddr = TQString::tqfromLatin1(
|
||
15 years ago
|
"<html>"
|
||
|
"<body text=\"%1\" bgcolor=\"%2\">" // text and background color
|
||
|
"%3" // dynamic part
|
||
|
"</body>"
|
||
|
"</html>" )
|
||
14 years ago
|
.tqarg( KGlobalSettings::textColor().name() )
|
||
|
.tqarg( KGlobalSettings::baseColor().name() )
|
||
|
.tqarg( strAddr );
|
||
15 years ago
|
|
||
14 years ago
|
TQString imageURL = TQString( "contact_%1_image" ).tqarg( mAddressee.uid() );
|
||
15 years ago
|
|
||
|
KABC::Picture picture = mAddressee.photo();
|
||
|
if ( picture.isIntern() && !picture.data().isNull() )
|
||
15 years ago
|
TQMimeSourceFactory::defaultFactory()->setImage( imageURL, picture.data() );
|
||
15 years ago
|
else {
|
||
|
if ( !picture.url().isEmpty() ) {
|
||
|
if ( mImageData.count() > 0 )
|
||
14 years ago
|
TQMimeSourceFactory::defaultFactory()->setImage( imageURL, TQImage(mImageData) );
|
||
15 years ago
|
else {
|
||
|
mImageJob = KIO::get( KURL( picture.url() ), false, false );
|
||
15 years ago
|
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* ) ) );
|
||
15 years ago
|
}
|
||
|
} else {
|
||
15 years ago
|
TQMimeSourceFactory::defaultFactory()->setPixmap( imageURL,
|
||
15 years ago
|
KGlobal::iconLoader()->loadIcon( "personal", KIcon::Desktop, 128 ) );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// at last display it...
|
||
|
setText( strAddr );
|
||
|
}
|
||
|
|
||
|
KABC::Addressee AddresseeView::addressee() const
|
||
|
{
|
||
|
return mAddressee;
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::urlClicked( const TQString &url )
|
||
15 years ago
|
{
|
||
|
kapp->invokeBrowser( url );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::emailClicked( const TQString &email )
|
||
15 years ago
|
{
|
||
|
if ( email.startsWith( "mailto:" ) )
|
||
14 years ago
|
kapp->invokeMailer( email.mid( 7 ), TQString() );
|
||
15 years ago
|
else
|
||
14 years ago
|
kapp->invokeMailer( email, TQString() );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::phoneNumberClicked( const TQString &number )
|
||
15 years ago
|
{
|
||
|
KConfig config( "kaddressbookrc" );
|
||
|
config.setGroup( "General" );
|
||
15 years ago
|
TQString commandLine = config.readEntry( "PhoneHookApplication" );
|
||
15 years ago
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
14 years ago
|
commandLine.replace( "%N", number );
|
||
15 years ago
|
KRun::runCommand( commandLine );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::smsTextClicked( const TQString &number )
|
||
15 years ago
|
{
|
||
|
KConfig config( "kaddressbookrc" );
|
||
|
config.setGroup( "General" );
|
||
15 years ago
|
TQString commandLine = config.readEntry( "SMSHookApplication" );
|
||
15 years ago
|
|
||
|
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() );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::sendSMS( const TQString &number, const TQString &text )
|
||
15 years ago
|
{
|
||
|
KConfig config( "kaddressbookrc" );
|
||
|
config.setGroup( "General" );
|
||
15 years ago
|
TQString commandLine = config.readEntry( "SMSHookApplication" );
|
||
15 years ago
|
|
||
|
KTempFile file ;
|
||
15 years ago
|
TQTextStream* stream = file.textStream();
|
||
15 years ago
|
*stream << text;
|
||
|
file.close();
|
||
|
|
||
14 years ago
|
commandLine.replace( "%N", number );
|
||
|
commandLine.replace( "%F", file.name() );
|
||
15 years ago
|
|
||
|
KRun::runCommand( commandLine );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::faxNumberClicked( const TQString &number )
|
||
15 years ago
|
{
|
||
|
KConfig config( "kaddressbookrc" );
|
||
|
config.setGroup( "General" );
|
||
13 years ago
|
TQString commandLine = config.readEntry( "FaxHookApplication", "tdeprintfax --phone %N" );
|
||
15 years ago
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
14 years ago
|
commandLine.replace( "%N", number );
|
||
15 years ago
|
KRun::runCommand( commandLine );
|
||
|
}
|
||
|
|
||
|
void AddresseeView::imAddressClicked()
|
||
|
{
|
||
|
mKIMProxy->chatWithContact( mAddressee.uid() );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQPopupMenu *AddresseeView::createPopupMenu( const TQPoint& )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPopupMenu *menu = new TQPopupMenu( this );
|
||
15 years ago
|
mActionShowBirthday->plug( menu );
|
||
|
mActionShowAddresses->plug( menu );
|
||
|
mActionShowEmails->plug( menu );
|
||
|
mActionShowPhones->plug( menu );
|
||
|
mActionShowURLs->plug( menu );
|
||
|
mActionShowIMAddresses->plug( menu );
|
||
|
mActionShowCustomFields->plug( menu );
|
||
|
|
||
|
return menu;
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::slotMailClicked( const TQString&, const TQString &email )
|
||
15 years ago
|
{
|
||
|
emailClicked( email );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::slotUrlClicked( const TQString &url )
|
||
15 years ago
|
{
|
||
|
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 );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::slotHighlighted( const TQString &link )
|
||
15 years ago
|
{
|
||
|
if ( link.startsWith( "mailto:" ) ) {
|
||
15 years ago
|
TQString email = link.mid( 7 );
|
||
15 years ago
|
|
||
|
emit emailHighlighted( email );
|
||
14 years ago
|
emit highlightedMessage( i18n( "Send mail to '%1'" ).tqarg( email ) );
|
||
15 years ago
|
} else if ( link.startsWith( "phone:" ) ) {
|
||
15 years ago
|
TQString number = link.mid( 8 );
|
||
15 years ago
|
|
||
|
emit phoneNumberHighlighted( strippedNumber( number ) );
|
||
14 years ago
|
emit highlightedMessage( i18n( "Call number %1" ).tqarg( number ) );
|
||
15 years ago
|
} else if ( link.startsWith( "fax:" ) ) {
|
||
15 years ago
|
TQString number = link.mid( 6 );
|
||
15 years ago
|
|
||
|
emit faxNumberHighlighted( strippedNumber( number ) );
|
||
14 years ago
|
emit highlightedMessage( i18n( "Send fax to %1" ).tqarg( number ) );
|
||
15 years ago
|
} else if ( link.startsWith( "addr:" ) ) {
|
||
|
emit highlightedMessage( i18n( "Show address on map" ) );
|
||
|
} else if ( link.startsWith( "sms:" ) ) {
|
||
15 years ago
|
TQString number = link.mid( 6 );
|
||
14 years ago
|
emit highlightedMessage( i18n( "Send SMS to %1" ).tqarg( number ) );
|
||
15 years ago
|
} else if ( link.startsWith( "http:" ) || link.startsWith( "https:" ) ) {
|
||
|
emit urlHighlighted( link );
|
||
14 years ago
|
emit highlightedMessage( i18n( "Open URL %1" ).tqarg( link ) );
|
||
15 years ago
|
} else if ( link.startsWith( "im:" ) ) {
|
||
14 years ago
|
emit highlightedMessage( i18n( "Chat with %1" ).tqarg( mAddressee.realName() ) );
|
||
15 years ago
|
} else
|
||
|
emit highlightedMessage( "" );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::slotPresenceChanged( const TQString &uid )
|
||
15 years ago
|
{
|
||
|
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();
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddresseeView::data( KIO::Job*, const TQByteArray &d )
|
||
15 years ago
|
{
|
||
|
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();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString AddresseeView::strippedNumber( const TQString &number )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString retval;
|
||
15 years ago
|
|
||
|
for ( uint i = 0; i < number.length(); ++i ) {
|
||
15 years ago
|
TQChar c = number[ i ];
|
||
14 years ago
|
if ( c.isDigit() || (((c == '*') || (c == '#') || (c == '+')) && (i == 0)) )
|
||
15 years ago
|
retval.append( c );
|
||
|
}
|
||
|
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
#include "addresseeview.moc"
|