diff --git a/akonadi/contact/contactgroupviewer.cpp b/akonadi/contact/contactgroupviewer.cpp index 349d8ff66..580cf562d 100644 --- a/akonadi/contact/contactgroupviewer.cpp +++ b/akonadi/contact/contactgroupviewer.cpp @@ -1,155 +1,163 @@ /* This file is part of Akonadi Contact. Copyright (c) 2009 Tobias Koenig 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 "contactgroupviewer.h" #include "contactgroupexpandjob.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace Akonadi; static QString contactsAsHtml( const QString &groupName, const KABC::Addressee::List &contacts ); class ContactGroupViewer::Private { public: Private( ContactGroupViewer *parent ) - : mParent( parent ) + : mParent( parent ), mExpandJob( 0 ) { } void _k_expandResult( KJob *job ) { ContactGroupExpandJob *expandJob = qobject_cast( job ); const KABC::Addressee::List contacts = expandJob->contacts(); mBrowser->setHtml( contactsAsHtml( mGroupName, contacts ) ); + + mExpandJob = 0; } ContactGroupViewer *mParent; KTextBrowser *mBrowser; QString mGroupName; + ContactGroupExpandJob *mExpandJob; }; ContactGroupViewer::ContactGroupViewer( QWidget *parent ) : QWidget( parent ), d( new Private( this ) ) { QVBoxLayout *layout = new QVBoxLayout( this ); d->mBrowser = new KTextBrowser; layout->addWidget( d->mBrowser ); // always fetch full payload for contacts fetchScope().fetchFullPayload(); } ContactGroupViewer::~ContactGroupViewer() { delete d; } Akonadi::Item ContactGroupViewer::contactGroup() const { return ItemMonitor::item(); } void ContactGroupViewer::setContactGroup( const Akonadi::Item &group ) { ItemMonitor::setItem( group ); } void ContactGroupViewer::itemChanged( const Item &item ) { static QPixmap defaultPixmap = KIcon( QLatin1String( "x-mail-distribution-list" ) ).pixmap( QSize( 100, 140 ) ); const KABC::ContactGroup group = item.payload(); d->mGroupName = group.name(); setWindowTitle( i18n( "Contact Group %1", group.name() ) ); d->mBrowser->document()->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "group_photo" ) ), defaultPixmap ); - ContactGroupExpandJob *job = new ContactGroupExpandJob( group ); - connect( job, SIGNAL( result( KJob* ) ), SLOT( _k_expandResult( KJob* ) ) ); - job->start(); + if ( d->mExpandJob ) { + disconnect( d->mExpandJob, SIGNAL( result( KJob* ) ), this, SLOT( _k_expandResult( KJob* ) ) ); + d->mExpandJob->kill(); + } + + d->mExpandJob = new ContactGroupExpandJob( group ); + connect( d->mExpandJob, SIGNAL( result( KJob* ) ), SLOT( _k_expandResult( KJob* ) ) ); + d->mExpandJob->start(); } void ContactGroupViewer::itemRemoved() { d->mBrowser->clear(); } static QString contactsAsHtml( const QString &groupName, const KABC::Addressee::List &contacts ) { // Assemble all parts QString strGroup = QString::fromLatin1( "
" "" "" "" "" // name "" ) .arg( QLatin1String( "group_photo" ) ) .arg( groupName ); foreach ( const KABC::Addressee &contact, contacts ) { const QString entry = QString::fromLatin1( "•%1 <%2>" ) .arg( contact.formattedName() ) .arg( contact.preferredEmail() ); strGroup.append( QString::fromLatin1( "" ).arg( entry ) ); } strGroup.append( QString::fromLatin1( "
" "" // image "%2
%1
\n" ) ); const QString document = QString::fromLatin1( "" "" // text and background color "%3" // contact part "" "" ) .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() ) .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() ) .arg( strGroup ); return document; } #include "contactgroupviewer.moc"