2
Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3
a KDAB Group company, info@kdab.net,
4
author Stephen Kelly <stephen@kdab.com>
6
This library is free software; you can redistribute it and/or modify it
7
under the terms of the GNU Library General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This library is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14
License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
// READ THE README FILE
24
#include "unreadmailswidget.h"
27
#include <QHBoxLayout>
30
#include <kselectionproxymodel.h>
32
#include <akonadi/entitytreemodel.h>
33
#include <akonadi/entitymimetypefiltermodel.h>
34
#include <akonadi/collection.h>
35
#include <akonadi/collectionstatistics.h>
37
#include "entitytreewidget.h"
38
#include "itemviewerwidget.h"
40
using namespace Akonadi;
42
UnreadMailsTree::UnreadMailsTree(QObject* parent)
43
: KRecursiveFilterProxyModel(parent)
48
bool UnreadMailsTree::acceptRow(int sourceRow, const QModelIndex& sourceParent) const
50
QModelIndex idx = sourceModel()->index(sourceRow, 0, sourceParent);
51
Collection col = idx.data(EntityTreeModel::CollectionRole).value<Collection>();
52
kDebug() << sourceRow << sourceParent << col.statistics().unreadCount() << idx.data().toString();
53
return col.statistics().unreadCount() > 0;
57
class UnreadMailsTreeWidget : public EntityTreeWidget
60
UnreadMailsTreeWidget(QWidget* parent = 0)
61
: EntityTreeWidget(parent)
65
/* reimp */ void connectTreeToModel(QTreeView* tree, Akonadi::EntityTreeModel* model)
67
m_collectionFilter = new Akonadi::EntityMimeTypeFilterModel(this);
68
m_collectionFilter->addMimeTypeInclusionFilter(Akonadi::Collection::mimeType());
69
m_collectionFilter->setSourceModel(model);
70
m_collectionFilter->setHeaderGroup(Akonadi::EntityTreeModel::CollectionTreeHeaders);
72
m_unreadFilter = new UnreadMailsTree(this);
73
m_unreadFilter->setSourceModel( m_collectionFilter );
75
tree->setModel(m_unreadFilter);
78
/* reimp */ QModelIndex mapToSource(const QModelIndex &idx)
80
return m_collectionFilter->mapToSource(m_unreadFilter->mapToSource(idx));
84
Akonadi::EntityMimeTypeFilterModel *m_collectionFilter;
85
UnreadMailsTree *m_unreadFilter;
89
UnreadMailsWidget::UnreadMailsWidget(QWidget* parent, Qt::WindowFlags f)
93
QHBoxLayout *layout = new QHBoxLayout(this);
94
QSplitter *splitter = new QSplitter(this);
95
layout->addWidget(splitter);
97
m_etw = new UnreadMailsTreeWidget(splitter);
100
QSplitter *rhsContainer = new QSplitter( Qt::Vertical, splitter);
102
m_itemView = new QTreeView(rhsContainer);
104
KSelectionProxyModel *selectionProxy = new KSelectionProxyModel(m_etw->view()->selectionModel(), this);
105
selectionProxy->setFilterBehavior(KSelectionProxyModel::ChildrenOfExactSelection);
106
selectionProxy->setSourceModel(m_etw->model());
108
Akonadi::EntityMimeTypeFilterModel *itemFilter = new Akonadi::EntityMimeTypeFilterModel(this);
109
itemFilter->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
110
itemFilter->addMimeTypeExclusionFilter(Akonadi::Collection::mimeType());
111
itemFilter->setSourceModel(selectionProxy);
113
m_itemView->setModel(itemFilter);
115
ItemViewerWidget *viewerWidget = new ItemViewerWidget(m_itemView->selectionModel(), rhsContainer);