~ubuntu-branches/ubuntu/lucid/kdepim-runtime/lucid

« back to all changes in this revision

Viewing changes to clients/akonablog/akonaditabbar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-12-03 15:38:40 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20091203153840-x5fxfsfby0czyqu6
Tags: 4:4.3.80-0ubuntu1
* New upstream beta release:
  - Refresh all patches
  - Bump build-depend versions
  - Remove build-depend on libknotificationitem-dev, it's part of
    kdelibs5-dev now
  - Add build-depend on shared-desktop-ontologies for nepomuk support
  - Add build-depend on libstreamanalyzer-dev for strigi support
  - Add build-depend on libx11-dev to prevent FTBFS
  - Update various .install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    Copyright (C) 2009 Omat Holding B.V. <info@omat.nl>
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 "akonaditabbar.h"
21
 
#include <kdebug.h>
22
 
 
23
 
#include <KTabBar>
24
 
#include <akonadi/collection.h>
25
 
#include <akonadi/collectionfetchjob.h>
26
 
 
27
 
using namespace Akonadi;
28
 
 
29
 
class AkonadiTabBar::Private
30
 
{
31
 
public:
32
 
    Private( AkonadiTabBar* parent );
33
 
    QHash<int,Collection> tabs;
34
 
    AkonadiTabBar* q;
35
 
 
36
 
public slots:
37
 
    void slotCurrentChanged( int );
38
 
};
39
 
 
40
 
AkonadiTabBar::Private::Private( AkonadiTabBar* parent ) : q( parent )
41
 
{
42
 
}
43
 
 
44
 
void AkonadiTabBar::Private::slotCurrentChanged( int index )
45
 
{
46
 
    q->emit currentChanged( tabs.value( index ) );
47
 
}
48
 
 
49
 
AkonadiTabBar::AkonadiTabBar( QWidget* parent )
50
 
        :  KTabBar( parent ), d( new Private( this ) )
51
 
{
52
 
    connect( this, SIGNAL( currentChanged( int ) ),
53
 
             SLOT( slotCurrentChanged( int ) ) );
54
 
}
55
 
 
56
 
AkonadiTabBar::~AkonadiTabBar()
57
 
{
58
 
    delete d;
59
 
}
60
 
 
61
 
void AkonadiTabBar::setResource( const QString &resource )
62
 
{
63
 
    // save it for later.
64
 
    int pastIndex = currentIndex();
65
 
 
66
 
    // remote old tabs.
67
 
    while ( count() > 0 )
68
 
        removeTab( 0 );
69
 
    d->tabs.clear();
70
 
 
71
 
    // fetching all collections recursive, starting at the root collection
72
 
    Collection col;
73
 
    CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive );
74
 
    job->setResource( resource );
75
 
    if ( job->exec() ) {
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;
81
 
            }
82
 
        }
83
 
    }
84
 
 
85
 
    // setCurrent would not result in the emission of the signal, as that is already the current one.
86
 
    if ( pastIndex <= 0 )
87
 
        emit currentChanged( d->tabs.value( 0 ) );
88
 
    else
89
 
        setCurrentIndex( pastIndex );
90
 
}
91
 
 
92
 
 
93
 
#include "akonaditabbar.moc"