• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

collectioncombobox.cpp

00001 /*
00002     This file is part of Akonadi Contact.
00003 
00004     Copyright (c) 2007-2009 Tobias Koenig <tokoe@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or modify it
00007     under the terms of the GNU Library General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or (at your
00009     option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful, but WITHOUT
00012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014     License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to the
00018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00019     02110-1301, USA.
00020 */
00021 
00022 #include "collectioncombobox.h"
00023 
00024 #include "asyncselectionhandler_p.h"
00025 
00026 #include <akonadi/changerecorder.h>
00027 #include <akonadi/collectionfetchscope.h>
00028 #include <akonadi/collectionfilterproxymodel.h>
00029 #include <akonadi/entityrightsfiltermodel.h>
00030 #include <akonadi/entitytreemodel.h>
00031 #include <akonadi/session.h>
00032 
00033 #include "kdescendantsproxymodel_p.h"
00034 
00035 #include <QtCore/QAbstractItemModel>
00036 
00037 using namespace Akonadi;
00038 
00039 class CollectionComboBox::Private
00040 {
00041   public:
00042     Private( QAbstractItemModel *customModel, CollectionComboBox *parent )
00043       : mParent( parent ), mMonitor( 0 ), mModel( 0 )
00044     {
00045       QAbstractItemModel *baseModel;
00046 
00047       if ( customModel ) {
00048         baseModel = customModel;
00049       } else {
00050         mMonitor = new Akonadi::ChangeRecorder( mParent );
00051         mMonitor->fetchCollection( true );
00052         mMonitor->setCollectionMonitored( Akonadi::Collection::root() );
00053 
00054         mModel = new EntityTreeModel( mMonitor, mParent );
00055         mModel->setItemPopulationStrategy( EntityTreeModel::NoItemPopulation );
00056 
00057         KDescendantsProxyModel *proxyModel = new KDescendantsProxyModel( parent );
00058         proxyModel->setDisplayAncestorData( true );
00059         proxyModel->setSourceModel( mModel );
00060 
00061         baseModel = proxyModel;
00062       }
00063 
00064       mMimeTypeFilterModel = new CollectionFilterProxyModel( parent );
00065       mMimeTypeFilterModel->setSourceModel( baseModel );
00066 
00067       mRightsFilterModel = new EntityRightsFilterModel( parent );
00068       mRightsFilterModel->setSourceModel( mMimeTypeFilterModel );
00069 
00070       mParent->setModel( mRightsFilterModel );
00071 
00072       mSelectionHandler = new AsyncSelectionHandler( mRightsFilterModel, mParent );
00073       mParent->connect( mSelectionHandler, SIGNAL( collectionAvailable( const QModelIndex& ) ),
00074                         mParent, SLOT( activated( const QModelIndex& ) ) );
00075 
00076       mParent->connect( mParent, SIGNAL( activated( int ) ),
00077                         mParent, SLOT( activated( int ) ) );
00078     }
00079 
00080     ~Private()
00081     {
00082     }
00083 
00084     void activated( int index );
00085     void activated( const QModelIndex& index );
00086 
00087     CollectionComboBox *mParent;
00088 
00089     ChangeRecorder *mMonitor;
00090     EntityTreeModel *mModel;
00091     CollectionFilterProxyModel *mMimeTypeFilterModel;
00092     EntityRightsFilterModel *mRightsFilterModel;
00093     AsyncSelectionHandler *mSelectionHandler;
00094 };
00095 
00096 void CollectionComboBox::Private::activated( int index )
00097 {
00098   const QModelIndex modelIndex = mParent->model()->index( index, 0 );
00099   if ( modelIndex.isValid() )
00100     emit mParent->currentChanged( modelIndex.data( EntityTreeModel::CollectionRole).value<Collection>() );
00101 }
00102 
00103 void CollectionComboBox::Private::activated( const QModelIndex &index )
00104 {
00105   mParent->setCurrentIndex( index.row() );
00106 }
00107 
00108 
00109 CollectionComboBox::CollectionComboBox( QWidget *parent )
00110   : KComboBox( parent ), d( new Private( 0, this ) )
00111 {
00112 }
00113 
00114 CollectionComboBox::CollectionComboBox( QAbstractItemModel *model, QWidget *parent )
00115   : KComboBox( parent ), d( new Private( model, this ) )
00116 {
00117 }
00118 
00119 CollectionComboBox::~CollectionComboBox()
00120 {
00121   delete d;
00122 }
00123 
00124 void CollectionComboBox::setMimeTypeFilter( const QStringList &contentMimeTypes )
00125 {
00126   d->mMimeTypeFilterModel->clearFilters();
00127   d->mMimeTypeFilterModel->addMimeTypeFilters( contentMimeTypes );
00128 
00129   if ( d->mMonitor )
00130     foreach ( const QString &mimeType, contentMimeTypes )
00131       d->mMonitor->setMimeTypeMonitored( mimeType, true );
00132 }
00133 
00134 QStringList CollectionComboBox::mimeTypeFilter() const
00135 {
00136   return d->mMimeTypeFilterModel->mimeTypeFilters();
00137 }
00138 
00139 void CollectionComboBox::setAccessRightsFilter( Collection::Rights rights )
00140 {
00141   d->mRightsFilterModel->setAccessRights( rights );
00142 }
00143 
00144 Collection::Rights CollectionComboBox::accessRightsFilter() const
00145 {
00146   return d->mRightsFilterModel->accessRights();
00147 }
00148 
00149 void CollectionComboBox::setDefaultCollection( const Collection &collection )
00150 {
00151   d->mSelectionHandler->waitForCollection( collection );
00152 }
00153 
00154 Akonadi::Collection CollectionComboBox::currentCollection() const
00155 {
00156   const QModelIndex modelIndex = model()->index( currentIndex(), 0 );
00157   if ( modelIndex.isValid() )
00158     return modelIndex.data( Akonadi::EntityTreeModel::CollectionRole ).value<Collection>();
00159   else
00160     return Akonadi::Collection();
00161 }
00162 
00163 #include "collectioncombobox.moc"

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal