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

akonadi

collectiondialog.cpp

00001 /*
00002     Copyright 2008 Ingo Klöcker <kloecker@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "collectiondialog.h"
00021 
00022 #include "asyncselectionhandler_p.h"
00023 
00024 #include <akonadi/changerecorder.h>
00025 #include <akonadi/collectionfetchscope.h>
00026 #include <akonadi/collectionfilterproxymodel.h>
00027 #include <akonadi/entityrightsfiltermodel.h>
00028 #include <akonadi/entitytreemodel.h>
00029 #include <akonadi/entitytreeview.h>
00030 #include <akonadi/session.h>
00031 
00032 #include <QtGui/QHeaderView>
00033 #include <QtGui/QLabel>
00034 #include <QtGui/QVBoxLayout>
00035 
00036 using namespace Akonadi;
00037 
00038 class CollectionDialog::Private
00039 {
00040   public:
00041     Private( QAbstractItemModel *customModel, CollectionDialog *parent )
00042       : mParent( parent ),
00043         mMonitor( 0 ),
00044         mModel( 0 )
00045     {
00046       // setup GUI
00047       QWidget *widget = mParent->mainWidget();
00048       QVBoxLayout *layout = new QVBoxLayout( widget );
00049 
00050       mTextLabel = new QLabel;
00051       layout->addWidget( mTextLabel );
00052       mTextLabel->hide();
00053 
00054       mView = new EntityTreeView;
00055       mView->header()->hide();
00056       layout->addWidget( mView );
00057 
00058 
00059       mParent->enableButton( KDialog::Ok, false );
00060 
00061       // setup models
00062       QAbstractItemModel *baseModel;
00063 
00064       if ( customModel ) {
00065         baseModel = customModel;
00066       } else {
00067         mMonitor = new Akonadi::ChangeRecorder( mParent );
00068         mMonitor->fetchCollection( true );
00069         mMonitor->setCollectionMonitored( Akonadi::Collection::root() );
00070 
00071         mModel = new EntityTreeModel( mMonitor, mParent );
00072         mModel->setItemPopulationStrategy( EntityTreeModel::NoItemPopulation );
00073         baseModel = mModel;
00074       }
00075 
00076       mMimeTypeFilterModel = new CollectionFilterProxyModel( mParent );
00077       mMimeTypeFilterModel->setSourceModel( baseModel );
00078 
00079       mRightsFilterModel = new EntityRightsFilterModel( mParent );
00080       mRightsFilterModel->setSourceModel( mMimeTypeFilterModel );
00081 
00082       mSelectionHandler = new AsyncSelectionHandler( mRightsFilterModel, mParent );
00083       mParent->connect( mSelectionHandler, SIGNAL( collectionAvailable( const QModelIndex& ) ),
00084                         mParent, SLOT( slotCollectionAvailable( const QModelIndex& ) ) );
00085       mView->setModel( mRightsFilterModel );
00086 
00087       mParent->connect( mView->selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ),
00088                         mParent, SLOT( slotSelectionChanged() ) );
00089     }
00090 
00091     ~Private()
00092     {
00093     }
00094 
00095     void slotCollectionAvailable( const QModelIndex &index )
00096     {
00097       mView->expandAll();
00098       mView->setCurrentIndex( index );
00099     }
00100 
00101     CollectionDialog *mParent;
00102 
00103     ChangeRecorder *mMonitor;
00104     EntityTreeModel *mModel;
00105     CollectionFilterProxyModel *mMimeTypeFilterModel;
00106     EntityRightsFilterModel *mRightsFilterModel;
00107     EntityTreeView *mView;
00108     AsyncSelectionHandler *mSelectionHandler;
00109     QLabel *mTextLabel;
00110 
00111     void slotSelectionChanged();
00112 };
00113 
00114 void CollectionDialog::Private::slotSelectionChanged()
00115 {
00116   mParent->enableButton( KDialog::Ok, mView->selectionModel()->selectedIndexes().count() > 0 );
00117 }
00118 
00119 CollectionDialog::CollectionDialog( QWidget *parent )
00120   : KDialog( parent ),
00121     d( new Private( 0, this ) )
00122 {
00123 }
00124 
00125 CollectionDialog::CollectionDialog( QAbstractItemModel *model, QWidget *parent )
00126   : KDialog( parent ),
00127     d( new Private( model, this ) )
00128 {
00129 }
00130 
00131 CollectionDialog::~CollectionDialog()
00132 {
00133   delete d;
00134 }
00135 
00136 Akonadi::Collection CollectionDialog::selectedCollection() const
00137 {
00138   if ( selectionMode() == QAbstractItemView::SingleSelection ) {
00139     const QModelIndex index = d->mView->currentIndex();
00140     if ( index.isValid() )
00141       return index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00142   }
00143 
00144   return Collection();
00145 }
00146 
00147 Akonadi::Collection::List CollectionDialog::selectedCollections() const
00148 {
00149   Collection::List collections;
00150   const QItemSelectionModel *selectionModel = d->mView->selectionModel();
00151   const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
00152   foreach ( const QModelIndex &index, selectedIndexes ) {
00153     if ( index.isValid() ) {
00154       const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00155       if ( collection.isValid() )
00156         collections.append( collection );
00157     }
00158   }
00159 
00160   return collections;
00161 }
00162 
00163 void CollectionDialog::setMimeTypeFilter( const QStringList &mimeTypes )
00164 {
00165   d->mMimeTypeFilterModel->clearFilters();
00166   d->mMimeTypeFilterModel->addMimeTypeFilters( mimeTypes );
00167 
00168   if ( d->mMonitor )
00169     foreach( const QString &mimetype, mimeTypes )
00170       d->mMonitor->setMimeTypeMonitored( mimetype );
00171 }
00172 
00173 QStringList CollectionDialog::mimeTypeFilter() const
00174 {
00175   return d->mMimeTypeFilterModel->mimeTypeFilters();
00176 }
00177 
00178 void CollectionDialog::setAccessRightsFilter( Collection::Rights rights )
00179 {
00180   d->mRightsFilterModel->setAccessRights( rights );
00181 }
00182 
00183 Collection::Rights CollectionDialog::accessRightsFilter() const
00184 {
00185   return d->mRightsFilterModel->accessRights();
00186 }
00187 
00188 void CollectionDialog::setDescription( const QString &text )
00189 {
00190   d->mTextLabel->setText( text );
00191   d->mTextLabel->show();
00192 }
00193 
00194 void CollectionDialog::setDefaultCollection( const Collection &collection )
00195 {
00196   d->mSelectionHandler->waitForCollection( collection );
00197 }
00198 
00199 void CollectionDialog::setSelectionMode( QAbstractItemView::SelectionMode mode )
00200 {
00201   d->mView->setSelectionMode( mode );
00202 }
00203 
00204 QAbstractItemView::SelectionMode CollectionDialog::selectionMode() const
00205 {
00206   return d->mView->selectionMode();
00207 }
00208 
00209 #include "collectiondialog.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