french -> French
[kdepim.git] / examples / akonablog / mainwidget.cpp
blob070af94f0916ee900c3f7cb336c9fe812010664b
1 /*
2 Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
3 Copyright (c) 2009 Omat Holding B.V. <info@omat.nl>
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
21 #include "mainwidget.h"
22 #include "mainwindow.h"
23 #include "blogmodel.h"
24 #include "microblogdelegate.h"
25 #include "akonaditabbar.h"
27 #include <akonadi/agentinstancemodel.h>
28 #include <akonadi/agentfilterproxymodel.h>
29 #include <akonadi/collectionfetchjob.h>
31 #include <QVBoxLayout>
32 #include <QSplitter>
33 #include <QListView>
34 #include <QTreeView>
36 #include <KVBox>
37 #include <KTabBar>
38 #include <KDebug>
39 #include <KLocale>
41 using namespace Akonadi;
43 MainWidget::MainWidget( MainWindow * parent ) :
44 QWidget( parent ), mMainWindow( parent )
46 QVBoxLayout *layout = new QVBoxLayout( this );
48 QSplitter *splitter = new QSplitter( Qt::Vertical, this );
49 layout->addWidget( splitter );
52 // Accounts
53 Akonadi::AgentInstanceModel *model = new Akonadi::AgentInstanceModel( this );
54 m_resourcesView = new QListView( splitter );
55 m_resourcesView->setModel( model );
56 connect( m_resourcesView, SIGNAL(clicked(QModelIndex)),
57 SLOT(slotCurrentResourceChanged(QModelIndex)) );
58 splitter->addWidget( m_resourcesView );
60 // Filter the collection to only show the blogs
61 Akonadi::AgentFilterProxyModel* proxy = new Akonadi::AgentFilterProxyModel( this );
62 proxy->addMimeTypeFilter( QLatin1String("application/x-vnd.kde.microblog") );
63 proxy->setSourceModel( model );
64 m_resourcesView->setModel( proxy );
66 // Bottom part
67 KVBox* box = new KVBox( splitter );
69 // Folders
70 m_tabBar = new AkonadiTabBar( box );
71 connect( m_tabBar, SIGNAL(currentChanged(Akonadi::Collection)),
72 SLOT(slotCurrentTabChanged(Akonadi::Collection)) );
74 mMessageList = new QTreeView( box );
75 mMessageList->setRootIsDecorated( false );
76 mMessageList->setDragEnabled( false );
77 mMessageList->setSelectionMode( QAbstractItemView::ExtendedSelection );
78 mMessageList->setSortingEnabled( true );
80 MicroblogDelegate *delegate = new MicroblogDelegate( mMessageList, this );
81 mMessageList->setItemDelegate( delegate );
83 mMessageModel = new BlogModel( this );
85 QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel( this );
86 proxyModel->setSortRole( Qt::EditRole );
87 proxyModel->setDynamicSortFilter( true );
88 proxyModel->setSourceModel( mMessageModel );
90 mMessageList->setModel( proxyModel );
91 splitter->addWidget( box );
93 splitter->setSizes( QList<int>() << 30 << 470 );
96 void MainWidget::slotCurrentResourceChanged( const QModelIndex &index )
98 const Akonadi::AgentInstanceModel *model = static_cast<const AgentInstanceModel*>( m_resourcesView->model() );
99 const QString identifier = model->data( index, AgentInstanceModel::InstanceIdentifierRole ).toString();
100 m_tabBar->setResource( identifier );
103 void MainWidget::slotCurrentTabChanged( const Akonadi::Collection& col )
105 mMessageModel->setCollection( col );