From kde-commits Sat Oct 17 19:11:00 2009 From: Tom Albers Date: Sat, 17 Oct 2009 19:11:00 +0000 To: kde-commits Subject: extragear/pim/mailody/src Message-Id: <1255806660.390778.7730.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=125580666717260 SVN commit 1036771 by toma: Add support for contact groups in Mailody. Yay! M +22 -1 composer.cpp M +1 -0 composer.h M +1 -1 contactcreation.cpp M +21 -4 contacttooltipproxymodel.cpp M +2 -0 contacttooltipproxymodel.h M +26 -14 contacttreemodel.cpp --- trunk/extragear/pim/mailody/src/composer.cpp #1036770:1036771 @@ -37,11 +37,14 @@ #include // KDEPIM +#include +#include #include #include #include #include #include +#include #include #include #include @@ -665,9 +668,27 @@ void Composer::slotAddAddressFromAddressBook( const QModelIndex& index ) { - m_recipientWidget->slotAddAddress( index.data( ContactTreeModel::AddressRole ).toString() ); + Akonadi::Item item = index.data( ContactTreeModel::ItemRole ).value(); + if ( item.mimeType() == "text/directory") { + m_recipientWidget->slotAddAddress( index.data( ContactTreeModel::AddressRole ).toString() ); + } else if ( item.mimeType() == "application/x-vnd.kde.contactgroup") { + const KABC::ContactGroup group = item.payload(); + Akonadi::ContactGroupExpandJob *job = new Akonadi::ContactGroupExpandJob( group ); + connect( job, SIGNAL( result( KJob* ) ), this, SLOT( expandResult( KJob* ) ) ); + job->start(); + } } +void Composer::expandResult( KJob *job ) + { + Akonadi::ContactGroupExpandJob *expandJob = qobject_cast( job ); + const KABC::Addressee::List contacts = expandJob->contacts(); + foreach ( const KABC::Addressee &contact, contacts ) { + m_recipientWidget->slotAddAddress( contact.fullEmail() ); + } +} + + void Composer::slotContextMenuAddressBook() { const QModelIndex lvi = m_addressbookView->currentIndex(); --- trunk/extragear/pim/mailody/src/composer.h #1036770:1036771 @@ -213,6 +213,7 @@ void slotAddAddressFromAddressBook( const QModelIndex& ); void slotContextMenuAddressBook(); void slotContextMenuAddressList(); + void expandResult( KJob *job ); void slotAddAddressFromRecentBook( const QModelIndex& ); void slotContextMenuRecentBook(); --- trunk/extragear/pim/mailody/src/contactcreation.cpp #1036770:1036771 @@ -38,7 +38,7 @@ QString email, name; bool ok = KPIMUtils::extractEmailAddressAndName( address, email, name ); if ( !ok ) { - kDebug() << "splitting name and mail failed"; + kDebug() << "splitting name and mail failed for:" << address; return; } kDebug() << name << email; --- trunk/extragear/pim/mailody/src/contacttooltipproxymodel.cpp #1036770:1036771 @@ -22,6 +22,8 @@ //KDE #include #include +#include +#include #include using namespace Mailody; @@ -35,11 +37,18 @@ SIGNAL( emailClicked( const QString&, const QString& ) ), SLOT( slotMailClicked( const QString&, const QString& ) ) ); m_contactViewer->hide(); + + m_contactGroupViewer = new Akonadi::ContactGroupViewerDialog( 0 ); + connect( m_contactGroupViewer->viewer(), + SIGNAL( emailClicked( const QString&, const QString& ) ), + SLOT( slotMailClicked( const QString&, const QString& ) ) ); + m_contactGroupViewer->hide(); } ContactToolTipProxyModel::~ContactToolTipProxyModel() { delete m_contactViewer; + delete m_contactGroupViewer; } QVariant ContactToolTipProxyModel::data( const QModelIndex & index, int role ) const @@ -59,10 +68,18 @@ if ( item == m_contactViewer->contact() ) return QVariant(); - m_contactViewer->setContact( item ); - m_contactViewer->move( QCursor::pos() ); - m_contactViewer->resize( QSize( 400, 400 ) ); - m_contactViewer->show(); + if ( item.mimeType() == "text/directory") { + m_contactViewer->setContact( item ); + m_contactViewer->move( QCursor::pos() ); + m_contactViewer->resize( QSize( 400, 400 ) ); + m_contactViewer->show(); + } else if ( item.mimeType() == "application/x-vnd.kde.contactgroup") { + m_contactGroupViewer->setContactGroup( item ); + m_contactGroupViewer->move( QCursor::pos() ); + m_contactGroupViewer->resize( QSize( 400, 400 ) ); + m_contactGroupViewer->show(); + } + return QVariant(); } --- trunk/extragear/pim/mailody/src/contacttooltipproxymodel.h #1036770:1036771 @@ -25,6 +25,7 @@ //KDE #include #include +#include #include namespace Mailody @@ -47,6 +48,7 @@ private: Akonadi::ContactViewerDialog *m_contactViewer; + Akonadi::ContactGroupViewerDialog *m_contactGroupViewer; }; } --- trunk/extragear/pim/mailody/src/contacttreemodel.cpp #1036770:1036771 @@ -22,6 +22,7 @@ //KDE #include #include +#include #include #include @@ -42,23 +43,34 @@ if ( !item.isValid() ) return Akonadi::EntityTreeModel::data( index, role ); - if ( !item.hasPayload() ) { - kDebug() << "No payload?"; - return Akonadi::EntityTreeModel::data( index, role ); - } + if ( item.mimeType() == "text/directory") { + if ( !item.hasPayload() ) { + kDebug() << "No payload?"; + return Akonadi::EntityTreeModel::data( index, role ); + } - const KABC::Addressee addr = item.payload(); + const KABC::Addressee addr = item.payload(); - if ( role == Qt::DisplayRole ) { - return i18nc( "fullname (emailaddress)","%1 (%2)", - addr.formattedName(), addr.preferredEmail() ); - } else if ( role == AddressRole ) { - KMime::Types::Mailbox mb; - mb.setAddress( addr.preferredEmail().toLocal8Bit() ); - mb.setName( addr.formattedName().toLocal8Bit() ); - kDebug() << mb.address(); - return mb.prettyAddress(); + if ( role == Qt::DisplayRole ) { + return i18nc( "fullname (emailaddress)","%1 (%2)", + addr.formattedName(), addr.preferredEmail() ); + } else if ( role == AddressRole ) { + KMime::Types::Mailbox mb; + mb.setAddress( addr.preferredEmail().toLocal8Bit() ); + mb.setName( addr.formattedName().toLocal8Bit() ); + kDebug() << mb.address(); + return mb.prettyAddress(); + } + } else if ( item.mimeType() == "application/x-vnd.kde.contactgroup") { + if ( !item.hasPayload() ) { + kDebug() << "No payload?"; + return Akonadi::EntityTreeModel::data( index, role ); + } + + const KABC::ContactGroup group = item.payload(); + return group.name(); } + return QVariant(); }