• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi/contact

contactgroupviewer.cpp

00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "contactgroupviewer.h"
00023 
00024 #include "contactgroupexpandjob.h"
00025 #include "textbrowser_p.h"
00026 
00027 #include <akonadi/item.h>
00028 #include <akonadi/itemfetchjob.h>
00029 #include <akonadi/itemfetchscope.h>
00030 #include <kabc/addressee.h>
00031 #include <kabc/contactgroup.h>
00032 #include <kcolorscheme.h>
00033 #include <kglobal.h>
00034 #include <kicon.h>
00035 #include <klocale.h>
00036 #include <kstringhandler.h>
00037 
00038 #include <QtGui/QVBoxLayout>
00039 
00040 using namespace Akonadi;
00041 
00042 static QString contactsAsHtml( const QString &groupName, const KABC::Addressee::List &contacts );
00043 
00044 class ContactGroupViewer::Private
00045 {
00046   public:
00047     Private( ContactGroupViewer *parent )
00048       : mParent( parent ), mExpandJob( 0 )
00049     {
00050     }
00051 
00052     void slotMailClicked( const QString&, const QString &email )
00053     {
00054       QString name, address;
00055 
00056       // remove the 'mailto:' and split into name and email address
00057       KABC::Addressee::parseEmailAddress( email.mid( 7 ), name, address );
00058 
00059       emit mParent->emailClicked( name, address );
00060     }
00061 
00062     void _k_expandResult( KJob *job )
00063     {
00064       ContactGroupExpandJob *expandJob = qobject_cast<ContactGroupExpandJob*>( job );
00065 
00066       const KABC::Addressee::List contacts = expandJob->contacts();
00067 
00068       mBrowser->setHtml( contactsAsHtml( mGroupName, contacts ) );
00069 
00070       mExpandJob = 0;
00071     }
00072 
00073     ContactGroupViewer *mParent;
00074     TextBrowser *mBrowser;
00075     QString mGroupName;
00076     ContactGroupExpandJob *mExpandJob;
00077 };
00078 
00079 ContactGroupViewer::ContactGroupViewer( QWidget *parent )
00080   : QWidget( parent ), d( new Private( this ) )
00081 {
00082   QVBoxLayout *layout = new QVBoxLayout( this );
00083 
00084   d->mBrowser = new TextBrowser;
00085   d->mBrowser->setNotifyClick( true );
00086 
00087   connect( d->mBrowser, SIGNAL( mailClick( const QString&, const QString& ) ),
00088            this, SLOT( slotMailClicked( const QString&, const QString& ) ) );
00089 
00090   layout->addWidget( d->mBrowser );
00091 
00092   // always fetch full payload for contacts
00093   fetchScope().fetchFullPayload();
00094 }
00095 
00096 ContactGroupViewer::~ContactGroupViewer()
00097 {
00098   delete d;
00099 }
00100 
00101 Akonadi::Item ContactGroupViewer::contactGroup() const
00102 {
00103   return ItemMonitor::item();
00104 }
00105 
00106 void ContactGroupViewer::setContactGroup( const Akonadi::Item &group )
00107 {
00108   ItemMonitor::setItem( group );
00109 }
00110 
00111 void ContactGroupViewer::itemChanged( const Item &item )
00112 {
00113   if ( !item.hasPayload<KABC::ContactGroup>() )
00114     return;
00115 
00116   static QPixmap groupPixmap = KIcon( QLatin1String( "x-mail-distribution-list" ) ).pixmap( QSize( 100, 140 ) );
00117 
00118   const KABC::ContactGroup group = item.payload<KABC::ContactGroup>();
00119   d->mGroupName = group.name();
00120 
00121   setWindowTitle( i18n( "Contact Group %1", group.name() ) );
00122 
00123   d->mBrowser->document()->addResource( QTextDocument::ImageResource,
00124                                         QUrl( QLatin1String( "group_photo" ) ),
00125                                         groupPixmap );
00126 
00127   if ( d->mExpandJob ) {
00128     disconnect( d->mExpandJob, SIGNAL( result( KJob* ) ), this, SLOT( _k_expandResult( KJob* ) ) );
00129     d->mExpandJob->kill();
00130   }
00131 
00132   d->mExpandJob = new ContactGroupExpandJob( group );
00133   connect( d->mExpandJob, SIGNAL( result( KJob* ) ), SLOT( _k_expandResult( KJob* ) ) );
00134   d->mExpandJob->start();
00135 }
00136 
00137 void ContactGroupViewer::itemRemoved()
00138 {
00139   d->mBrowser->clear();
00140 }
00141 
00142 static QString contactsAsHtml( const QString &groupName, const KABC::Addressee::List &contacts )
00143 {
00144   // Assemble all parts
00145   QString strGroup = QString::fromLatin1(
00146     "<table cellpadding=\"1\" cellspacing=\"0\" width=\"100%\">"
00147     "<tr>"
00148     "<td align=\"right\" valign=\"top\" width=\"30%\">"
00149     "<img src=\"%1\" width=\"75\" height=\"105\" vspace=\"1\">" // image
00150     "</td>"
00151     "<td align=\"left\" width=\"70%\"><font size=\"+2\"><b>%2</b></font></td>" // name
00152     "</tr>"
00153     "</table>" )
00154       .arg( QLatin1String( "group_photo" ) )
00155       .arg( groupName );
00156 
00157   strGroup += QLatin1String( "<table width=\"100%\">" );
00158 
00159 
00160   foreach ( const KABC::Addressee &contact, contacts ) {
00161     if ( contact.preferredEmail().isEmpty() ) {
00162       strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font size=\"-1\" color=\"grey\">%1</font></b></td>"
00163                                             "<td width=\"50%\"></td></tr>" )
00164                      .arg( contact.realName() ) );
00165     } else {
00166       const QString fullEmail = QLatin1String( "<a href=\"mailto:" ) + QString::fromLatin1( KUrl::toPercentEncoding( contact.fullEmail() ) ) + QString::fromLatin1( "\">%1</a>" ).arg( contact.preferredEmail() );
00167 
00168       strGroup.append( QString::fromLatin1( "<tr><td align=\"right\" width=\"50%\"><b><font size=\"-1\" color=\"grey\">%1</font></b></td>"
00169                                             "<td valign=\"bottom\" align=\"left\" width=\"50%\"><font size=\"-1\">&lt;%2&gt;</font></td></tr>" )
00170                      .arg( contact.realName() )
00171                      .arg( fullEmail ) );
00172     }
00173   }
00174 
00175   strGroup.append( QString::fromLatin1( "</table>\n" ) );
00176 
00177   const QString document = QString::fromLatin1(
00178     "<html>"
00179     "<head>"
00180     " <style type=\"text/css\">"
00181     "  a {text-decoration:none; color:%1}"
00182     " </style>"
00183     "</head>"
00184     "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
00185     "%3" // contact part
00186     "</body>"
00187     "</html>" )
00188      .arg( KColorScheme( QPalette::Active, KColorScheme::View ).foreground().color().name() )
00189      .arg( KColorScheme( QPalette::Active, KColorScheme::View ).background().color().name() )
00190      .arg( strGroup );
00191 
00192   return document;
00193 }
00194 
00195 #include "contactgroupviewer.moc"

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal