~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/clients/akonamail/mainwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2009-07-10 06:34:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20090710063450-neojgew2fh0n3y0u
Tags: 4:4.2.96-0ubuntu1
* New upstream release
* Bump kde build-deps to 4.2.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
3
 
 
4
 
    This library is free software; you can redistribute it and/or modify it
5
 
    under the terms of the GNU Library General Public License as published by
6
 
    the Free Software Foundation; either version 2 of the License, or (at your
7
 
    option) any later version.
8
 
 
9
 
    This library is distributed in the hope that it will be useful, but WITHOUT
10
 
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
12
 
    License for more details.
13
 
 
14
 
    You should have received a copy of the GNU Library General Public License
15
 
    along with this library; see the file COPYING.LIB.  If not, write to the
16
 
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
 
    02110-1301, USA.
18
 
*/
19
 
 
20
 
#include "mainwidget.h"
21
 
#include "mainwindow.h"
22
 
 
23
 
#include <akonadi/collection.h>
24
 
#include <akonadi/collectionview.h>
25
 
#include <akonadi/collectionfilterproxymodel.h>
26
 
#include <akonadi/collectionstatisticsmodel.h>
27
 
#include <akonadi/collectionstatisticsdelegate.h>
28
 
#include <akonadi/itemfetchjob.h>
29
 
#include <akonadi/itemfetchscope.h>
30
 
#include <akonadi/collectionmodifyjob.h>
31
 
#include <akonadi/kmime/messagemodel.h>
32
 
#include <akonadi/kmime/messagethreaderproxymodel.h>
33
 
 
34
 
#include <QtCore/QDebug>
35
 
#include <QVBoxLayout>
36
 
#include <QSplitter>
37
 
#include <QTextEdit>
38
 
#include <QtGui/QSortFilterProxyModel>
39
 
 
40
 
using namespace Akonadi;
41
 
 
42
 
MainWidget::MainWidget( MainWindow * parent) :
43
 
  QWidget( parent ), mMainWindow( parent )
44
 
{
45
 
  connect( mMainWindow, SIGNAL( threadCollection() ),
46
 
           this, SLOT( threadCollection() ) );
47
 
 
48
 
  QHBoxLayout *layout = new QHBoxLayout( this );
49
 
 
50
 
  QSplitter *splitter = new QSplitter( Qt::Horizontal, this );
51
 
  layout->addWidget( splitter );
52
 
 
53
 
  // Left part, collection view
54
 
  mCollectionList = new Akonadi::CollectionView();
55
 
  connect( mCollectionList, SIGNAL(clicked(const Akonadi::Collection &)),
56
 
           SLOT(collectionClicked(const Akonadi::Collection &)) );
57
 
  CollectionStatisticsDelegate *collectionDelegate =
58
 
                           new CollectionStatisticsDelegate( mCollectionList );
59
 
  collectionDelegate->setUnreadCountShown( true ); //For testing, should be toggleable columns eventually
60
 
  mCollectionList->setItemDelegate( collectionDelegate );
61
 
  splitter->addWidget( mCollectionList );
62
 
  // Filter the collection to only show the emails
63
 
  mCollectionModel = new Akonadi::CollectionStatisticsModel( this );
64
 
  mCollectionProxyModel = new Akonadi::CollectionFilterProxyModel(  this );
65
 
  mCollectionProxyModel->setSourceModel( mCollectionModel );
66
 
  mCollectionProxyModel->addMimeTypeFilter( QString::fromLatin1( "message/rfc822" ) );
67
 
 
68
 
  // display collections sorted
69
 
  QSortFilterProxyModel *sortModel = new QSortFilterProxyModel( this );
70
 
  sortModel->setDynamicSortFilter( true );
71
 
  sortModel->setSortCaseSensitivity( Qt::CaseInsensitive );
72
 
  sortModel->setSourceModel( mCollectionProxyModel );
73
 
 
74
 
  // Right part, message list + message viewer
75
 
  QSplitter *rightSplitter = new QSplitter( Qt::Vertical, this );
76
 
  splitter->addWidget( rightSplitter );
77
 
  mMessageList = new QTreeView( this );
78
 
  mMessageList->setDragEnabled( true );
79
 
  mMessageList->setSelectionMode( QAbstractItemView::ExtendedSelection );
80
 
  connect( mMessageList, SIGNAL(clicked(QModelIndex)), SLOT(itemActivated(QModelIndex)) );
81
 
  rightSplitter->addWidget( mMessageList );
82
 
 
83
 
  mCollectionList->setModel( sortModel );
84
 
  mMessageModel = new Akonadi::MessageModel( this );
85
 
  mMessageProxyModel = new Akonadi::MessageThreaderProxyModel( this );
86
 
  mMessageProxyModel->setSourceModel( mMessageModel );
87
 
  mMessageList->setModel( mMessageProxyModel );
88
 
 
89
 
  mMessageView = new QTextEdit( this );
90
 
  rightSplitter->addWidget( mMessageView );
91
 
 
92
 
 
93
 
  splitter->setSizes( QList<int>() << 200 << 500 );
94
 
  rightSplitter->setSizes( QList<int>() << 300 << 200 );
95
 
}
96
 
 
97
 
void MainWidget::collectionClicked(const Akonadi::Collection & collection)
98
 
{
99
 
  mCurrentCollection = collection;
100
 
  mMessageModel->setCollection( Collection( mCurrentCollection ) );
101
 
}
102
 
 
103
 
void MainWidget::itemActivated(const QModelIndex & index)
104
 
{
105
 
  const Item item = mMessageModel->itemForIndex(  mMessageProxyModel->mapToSource( index ) );
106
 
 
107
 
  if ( !item.isValid() )
108
 
    return;
109
 
 
110
 
  ItemFetchJob *job = new ItemFetchJob( item, this );
111
 
  job->fetchScope().fetchFullPayload();
112
 
  connect( job, SIGNAL( result(KJob*) ), SLOT( itemFetchDone(KJob*) ) );
113
 
  job->start();
114
 
}
115
 
 
116
 
void MainWidget::itemFetchDone(KJob * job)
117
 
{
118
 
  ItemFetchJob *fetch = static_cast<ItemFetchJob*>( job );
119
 
  if ( job->error() ) {
120
 
    qWarning() << "Mail fetch failed: " << job->errorString();
121
 
  } else if ( fetch->items().isEmpty() ) {
122
 
    qWarning() << "No mail found!";
123
 
  } else {
124
 
    const Item item = fetch->items().first();
125
 
    mMessageView->setPlainText( item.payloadData() );
126
 
  }
127
 
}
128
 
 
129
 
void MainWidget::threadCollection()
130
 
{
131
 
  /*MailThreaderAttribute *a = mCurrentCollection.attribute<MailThreaderAttribute>( Collection::AddIfMissing );
132
 
  a->deserialize( QByteArray( "sort" ) );
133
 
  CollectionModifyJob *job = new CollectionModifyJob( mCurrentCollection );
134
 
  if ( !job->exec() )
135
 
    qDebug() << "Unable to modify collection";*/
136
 
}
137
 
 
138