• Skip to content
  • Skip to link menu
KDE 4.2 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 <akonadi/collectionfilterproxymodel.h>
00023 #include <akonadi/collectionmodel.h>
00024 #include <akonadi/collectionview.h>
00025 
00026 #include <QtGui/QVBoxLayout>
00027 
00028 using namespace Akonadi;
00029 
00030 class CollectionDialog::Private
00031 {
00032   public:
00033     Private();
00034 
00035     CollectionModel *collectionModel;
00036     CollectionFilterProxyModel *filterModel;
00037     CollectionView *collectionView;
00038 };
00039 
00040 CollectionDialog::Private::Private()
00041   : collectionModel( 0 ),
00042     filterModel( 0 ),
00043     collectionView( 0 )
00044 {
00045 }
00046 
00047 
00048 CollectionDialog::CollectionDialog( QWidget *parent )
00049   : KDialog( parent ),
00050     d( new Private )
00051 {
00052   QWidget *widget = mainWidget();
00053   QVBoxLayout *layout = new QVBoxLayout( widget );
00054 
00055   d->collectionModel = new CollectionModel( this );
00056 
00057   d->filterModel = new CollectionFilterProxyModel( this );
00058   d->filterModel->setDynamicSortFilter( true );
00059   d->filterModel->setSortCaseSensitivity( Qt::CaseInsensitive );
00060   d->filterModel->setSourceModel( d->collectionModel );
00061 
00062   d->collectionView = new CollectionView( widget );
00063   d->collectionView->setModel( d->filterModel );
00064   layout->addWidget( d->collectionView );
00065 }
00066 
00067 CollectionDialog::~CollectionDialog()
00068 {
00069   delete d;
00070 }
00071 
00072 Akonadi::Collection CollectionDialog::selectedCollection() const
00073 {
00074   if ( selectionMode() == QAbstractItemView::SingleSelection ) {
00075     const QModelIndex index = d->collectionView->currentIndex();
00076     if ( index.isValid() )
00077       return index.model()->data( index, CollectionModel::CollectionRole ).value<Collection>();
00078   }
00079 
00080   return Collection();
00081 }
00082 
00083 Akonadi::Collection::List CollectionDialog::selectedCollections() const
00084 {
00085   Collection::List collections;
00086   const QItemSelectionModel *selectionModel = d->collectionView->selectionModel();
00087   const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
00088   foreach ( const QModelIndex &index, selectedIndexes ) {
00089     if ( index.isValid() ) {
00090       const Collection collection = index.model()->data( index, CollectionModel::CollectionRole ).value<Collection>();
00091       if ( collection.isValid() )
00092         collections.append( collection );
00093     }
00094   }
00095 
00096   return collections;
00097 }
00098 
00099 void CollectionDialog::setMimeTypeFilter( const QStringList &mimeTypes )
00100 {
00101   d->filterModel->clearFilters();
00102   d->filterModel->addMimeTypeFilters( mimeTypes );
00103 }
00104 
00105 QStringList CollectionDialog::mimeTypeFilter() const
00106 {
00107   return d->filterModel->mimeTypeFilters();
00108 }
00109 
00110 void CollectionDialog::setSelectionMode( QAbstractItemView::SelectionMode mode )
00111 {
00112   d->collectionView->setSelectionMode( mode );
00113 }
00114 
00115 QAbstractItemView::SelectionMode CollectionDialog::selectionMode() const
00116 {
00117   return d->collectionView->selectionMode();
00118 }
00119 
00120 #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
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7
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