~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to examples/etm_usage/unreadmailswidget.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2010 Klarälvdalens Datakonsult AB,
 
3
        a KDAB Group company, info@kdab.net,
 
4
        author Stephen Kelly <stephen@kdab.com>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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
 
19
    02110-1301, USA.
 
20
*/
 
21
 
 
22
// READ THE README FILE
 
23
 
 
24
#include "unreadmailswidget.h"
 
25
 
 
26
#include <QTreeView>
 
27
#include <QHBoxLayout>
 
28
#include <QSplitter>
 
29
 
 
30
#include <kselectionproxymodel.h>
 
31
 
 
32
#include <akonadi/entitytreemodel.h>
 
33
#include <akonadi/entitymimetypefiltermodel.h>
 
34
#include <akonadi/collection.h>
 
35
#include <akonadi/collectionstatistics.h>
 
36
 
 
37
#include "entitytreewidget.h"
 
38
#include "itemviewerwidget.h"
 
39
 
 
40
using namespace Akonadi;
 
41
 
 
42
UnreadMailsTree::UnreadMailsTree(QObject* parent)
 
43
  : KRecursiveFilterProxyModel(parent)
 
44
{
 
45
 
 
46
}
 
47
 
 
48
bool UnreadMailsTree::acceptRow(int sourceRow, const QModelIndex& sourceParent) const
 
49
{
 
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;
 
54
}
 
55
 
 
56
 
 
57
class UnreadMailsTreeWidget : public EntityTreeWidget
 
58
{
 
59
public:
 
60
  UnreadMailsTreeWidget(QWidget* parent = 0)
 
61
    : EntityTreeWidget(parent)
 
62
  {
 
63
  }
 
64
 
 
65
  /* reimp */ void connectTreeToModel(QTreeView* tree, Akonadi::EntityTreeModel* model)
 
66
  {
 
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);
 
71
 
 
72
    m_unreadFilter = new UnreadMailsTree(this);
 
73
    m_unreadFilter->setSourceModel( m_collectionFilter );
 
74
 
 
75
    tree->setModel(m_unreadFilter);
 
76
  }
 
77
 
 
78
  /* reimp */ QModelIndex mapToSource(const QModelIndex &idx)
 
79
  {
 
80
    return m_collectionFilter->mapToSource(m_unreadFilter->mapToSource(idx));
 
81
  }
 
82
 
 
83
private:
 
84
  Akonadi::EntityMimeTypeFilterModel *m_collectionFilter;
 
85
  UnreadMailsTree *m_unreadFilter;
 
86
 
 
87
};
 
88
 
 
89
UnreadMailsWidget::UnreadMailsWidget(QWidget* parent, Qt::WindowFlags f)
 
90
  : QWidget(parent, f)
 
91
{
 
92
 
 
93
  QHBoxLayout *layout = new QHBoxLayout(this);
 
94
  QSplitter *splitter = new QSplitter(this);
 
95
  layout->addWidget(splitter);
 
96
 
 
97
  m_etw = new UnreadMailsTreeWidget(splitter);
 
98
  m_etw->init();
 
99
 
 
100
  QSplitter *rhsContainer = new QSplitter( Qt::Vertical, splitter);
 
101
 
 
102
  m_itemView = new QTreeView(rhsContainer);
 
103
 
 
104
  KSelectionProxyModel *selectionProxy = new KSelectionProxyModel(m_etw->view()->selectionModel(), this);
 
105
  selectionProxy->setFilterBehavior(KSelectionProxyModel::ChildrenOfExactSelection);
 
106
  selectionProxy->setSourceModel(m_etw->model());
 
107
 
 
108
  Akonadi::EntityMimeTypeFilterModel *itemFilter = new Akonadi::EntityMimeTypeFilterModel(this);
 
109
  itemFilter->setHeaderGroup( Akonadi::EntityTreeModel::ItemListHeaders );
 
110
  itemFilter->addMimeTypeExclusionFilter(Akonadi::Collection::mimeType());
 
111
  itemFilter->setSourceModel(selectionProxy);
 
112
 
 
113
  m_itemView->setModel(itemFilter);
 
114
 
 
115
  ItemViewerWidget *viewerWidget = new ItemViewerWidget(m_itemView->selectionModel(), rhsContainer);
 
116
 
 
117
}