2
Copyright (C) 2009 Omat Holding B.V. <info@omat.nl>
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.
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.
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
20
#include "akonaditabbar.h"
24
#include <akonadi/collection.h>
25
#include <akonadi/collectionfetchjob.h>
27
using namespace Akonadi;
29
class AkonadiTabBar::Private
32
Private( AkonadiTabBar* parent );
33
QHash<int,Collection> tabs;
37
void slotCurrentChanged( int );
40
AkonadiTabBar::Private::Private( AkonadiTabBar* parent ) : q( parent )
44
void AkonadiTabBar::Private::slotCurrentChanged( int index )
46
q->emit currentChanged( tabs.value( index ) );
49
AkonadiTabBar::AkonadiTabBar( QWidget* parent )
50
: KTabBar( parent ), d( new Private( this ) )
52
connect( this, SIGNAL( currentChanged( int ) ),
53
SLOT( slotCurrentChanged( int ) ) );
56
AkonadiTabBar::~AkonadiTabBar()
61
void AkonadiTabBar::setResource( const QString &resource )
64
int pastIndex = currentIndex();
71
// fetching all collections recursive, starting at the root collection
73
CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive );
74
job->setResource( resource );
76
Collection::List collections = job->collections();
77
foreach( const Collection &collection, collections ) {
78
if ( collection.parent() != Collection::root().id() ) {
79
int tab = addTab( collection.name() );
80
d->tabs[ tab ] = collection;
85
// setCurrent would not result in the emission of the signal, as that is already the current one.
87
emit currentChanged( d->tabs.value( 0 ) );
89
setCurrentIndex( pastIndex );
93
#include "akonaditabbar.moc"