• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

akonadi/clients

mainwidget.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "mainwidget.h"
00021 #include "mainwindow.h"
00022 
00023 #include <akonadi/collection.h>
00024 #include <akonadi/collectionview.h>
00025 #include <akonadi/collectionfilterproxymodel.h>
00026 #include <akonadi/collectionstatisticsmodel.h>
00027 #include <akonadi/collectionstatisticsdelegate.h>
00028 #include <akonadi/itemfetchjob.h>
00029 #include <akonadi/itemfetchscope.h>
00030 #include <akonadi/collectionmodifyjob.h>
00031 #include <akonadi/kmime/messagemodel.h>
00032 #include <akonadi/kmime/messagethreaderproxymodel.h>
00033 #include <agents/mailthreader/mailthreaderagent.h>
00034 
00035 #include <QtCore/QDebug>
00036 #include <QVBoxLayout>
00037 #include <QSplitter>
00038 #include <QTextEdit>
00039 #include <QtGui/QSortFilterProxyModel>
00040 
00041 using namespace Akonadi;
00042 
00043 MainWidget::MainWidget( MainWindow * parent) :
00044   QWidget( parent ), mMainWindow( parent )
00045 {
00046   connect( mMainWindow, SIGNAL( threadCollection() ),
00047            this, SLOT( threadCollection() ) );
00048 
00049   QHBoxLayout *layout = new QHBoxLayout( this );
00050 
00051   QSplitter *splitter = new QSplitter( Qt::Horizontal, this );
00052   layout->addWidget( splitter );
00053 
00054   // Left part, collection view
00055   mCollectionList = new Akonadi::CollectionView();
00056   connect( mCollectionList, SIGNAL(clicked(const Akonadi::Collection &)),
00057            SLOT(collectionClicked(const Akonadi::Collection &)) );
00058   CollectionStatisticsDelegate *collectionDelegate =
00059                            new CollectionStatisticsDelegate( mCollectionList );
00060   collectionDelegate->setUnreadCountShown( true ); //For testing, should be toggleable columns eventually
00061   mCollectionList->setItemDelegate( collectionDelegate );
00062   splitter->addWidget( mCollectionList );
00063   // Filter the collection to only show the emails
00064   mCollectionModel = new Akonadi::CollectionStatisticsModel( this );
00065   mCollectionProxyModel = new Akonadi::CollectionFilterProxyModel(  this );
00066   mCollectionProxyModel->setSourceModel( mCollectionModel );
00067   mCollectionProxyModel->addMimeTypeFilter( QString::fromLatin1( "message/rfc822" ) );
00068 
00069   // display collections sorted
00070   QSortFilterProxyModel *sortModel = new QSortFilterProxyModel( this );
00071   sortModel->setDynamicSortFilter( true );
00072   sortModel->setSortCaseSensitivity( Qt::CaseInsensitive );
00073   sortModel->setSourceModel( mCollectionProxyModel );
00074 
00075   // Right part, message list + message viewer
00076   QSplitter *rightSplitter = new QSplitter( Qt::Vertical, this );
00077   splitter->addWidget( rightSplitter );
00078   mMessageList = new QTreeView( this );
00079   mMessageList->setDragEnabled( true );
00080   mMessageList->setSelectionMode( QAbstractItemView::ExtendedSelection );
00081   connect( mMessageList, SIGNAL(clicked(QModelIndex)), SLOT(itemActivated(QModelIndex)) );
00082   rightSplitter->addWidget( mMessageList );
00083 
00084   mCollectionList->setModel( sortModel );
00085   mMessageModel = new Akonadi::MessageModel( this );
00086   mMessageProxyModel = new Akonadi::MessageThreaderProxyModel( this );
00087   mMessageProxyModel->setSourceModel( mMessageModel );
00088   mMessageList->setModel( mMessageProxyModel );
00089 
00090   mMessageView = new QTextEdit( this );
00091   rightSplitter->addWidget( mMessageView );
00092 
00093 
00094   splitter->setSizes( QList<int>() << 200 << 500 );
00095   rightSplitter->setSizes( QList<int>() << 300 << 200 );
00096 }
00097 
00098 void MainWidget::collectionClicked(const Akonadi::Collection & collection)
00099 {
00100   mCurrentCollection = collection;
00101   mMessageModel->setCollection( Collection( mCurrentCollection ) );
00102 }
00103 
00104 void MainWidget::itemActivated(const QModelIndex & index)
00105 {
00106   const Item item = mMessageModel->itemForIndex(  mMessageProxyModel->mapToSource( index ) );
00107 
00108   if ( !item.isValid() )
00109     return;
00110 
00111   ItemFetchJob *job = new ItemFetchJob( item, this );
00112   job->fetchScope().fetchFullPayload();
00113   connect( job, SIGNAL( result(KJob*) ), SLOT( itemFetchDone(KJob*) ) );
00114   job->start();
00115 }
00116 
00117 void MainWidget::itemFetchDone(KJob * job)
00118 {
00119   ItemFetchJob *fetch = static_cast<ItemFetchJob*>( job );
00120   if ( job->error() ) {
00121     qWarning() << "Mail fetch failed: " << job->errorString();
00122   } else if ( fetch->items().isEmpty() ) {
00123     qWarning() << "No mail found!";
00124   } else {
00125     const Item item = fetch->items().first();
00126     mMessageView->setPlainText( item.payloadData() );
00127   }
00128 }
00129 
00130 void MainWidget::threadCollection()
00131 {
00132   MailThreaderAttribute *a = mCurrentCollection.attribute<MailThreaderAttribute>( Collection::AddIfMissing );
00133   a->deserialize( QByteArray( "sort" ) );
00134   CollectionModifyJob *job = new CollectionModifyJob( mCurrentCollection );
00135   if ( !job->exec() )
00136     qDebug() << "Unable to modify collection";
00137 }
00138 
00139 

akonadi/clients

Skip menu "akonadi/clients"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
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