• Skip to content
  • Skip to link menu
KDE 4.5 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 #include <KLineEdit>
00037 #include <KLocale>
00038 
00039 using namespace Akonadi;
00040 
00041 class CollectionDialog::Private
00042 {
00043   public:
00044     Private( QAbstractItemModel *customModel, CollectionDialog *parent )
00045       : mParent( parent ),
00046         mMonitor( 0 ),
00047         mModel( 0 )
00048     {
00049       // setup GUI
00050       QWidget *widget = mParent->mainWidget();
00051       QVBoxLayout *layout = new QVBoxLayout( widget );
00052 
00053       mTextLabel = new QLabel;
00054       layout->addWidget( mTextLabel );
00055       mTextLabel->hide();
00056 
00057       KLineEdit* filterCollectionLineEdit = new KLineEdit( widget );
00058       filterCollectionLineEdit->setClearButtonShown( true );
00059       filterCollectionLineEdit->setClickMessage( i18nc( "@info/plain Displayed grayed-out inside the "
00060                                                         "textbox, verb to search", "Search" ) );
00061       layout->addWidget( filterCollectionLineEdit );
00062 
00063       mView = new EntityTreeView;
00064       mView->setDragDropMode( QAbstractItemView::NoDragDrop );
00065       mView->header()->hide();
00066       layout->addWidget( mView );
00067 
00068 
00069       mParent->enableButton( KDialog::Ok, false );
00070 
00071       // setup models
00072       QAbstractItemModel *baseModel;
00073 
00074       if ( customModel ) {
00075         baseModel = customModel;
00076       } else {
00077         mMonitor = new Akonadi::ChangeRecorder( mParent );
00078         mMonitor->fetchCollection( true );
00079         mMonitor->setCollectionMonitored( Akonadi::Collection::root() );
00080 
00081         mModel = new EntityTreeModel( mMonitor, mParent );
00082         mModel->setItemPopulationStrategy( EntityTreeModel::NoItemPopulation );
00083         baseModel = mModel;
00084       }
00085 
00086       mMimeTypeFilterModel = new CollectionFilterProxyModel( mParent );
00087       mMimeTypeFilterModel->setSourceModel( baseModel );
00088 
00089       mRightsFilterModel = new EntityRightsFilterModel( mParent );
00090       mRightsFilterModel->setSourceModel( mMimeTypeFilterModel );
00091 
00092       mSelectionHandler = new AsyncSelectionHandler( mRightsFilterModel, mParent );
00093       mParent->connect( mSelectionHandler, SIGNAL( collectionAvailable( const QModelIndex& ) ),
00094                         mParent, SLOT( slotCollectionAvailable( const QModelIndex& ) ) );
00095 
00096       KRecursiveFilterProxyModel* filterCollection = new KRecursiveFilterProxyModel( mParent );
00097       filterCollection->setDynamicSortFilter( true );
00098       filterCollection->setSourceModel( mRightsFilterModel );
00099       filterCollection->setFilterCaseSensitivity( Qt::CaseInsensitive );
00100       mView->setModel( filterCollection );
00101 
00102       mParent->connect( filterCollectionLineEdit, SIGNAL( textChanged( const QString& ) ),
00103                         filterCollection, SLOT( setFilterFixedString( const QString& ) ) );
00104 
00105       mParent->connect( mView->selectionModel(), SIGNAL( selectionChanged( const QItemSelection&, const QItemSelection& ) ),
00106                         mParent, SLOT( slotSelectionChanged() ) );
00107 
00108       mParent->connect( mView, SIGNAL( doubleClicked( const QModelIndex& ) ),
00109                         mParent, SLOT( accept() ) );
00110     }
00111 
00112     ~Private()
00113     {
00114     }
00115 
00116     void slotCollectionAvailable( const QModelIndex &index )
00117     {
00118       mView->expandAll();
00119       mView->setCurrentIndex( index );
00120     }
00121 
00122     CollectionDialog *mParent;
00123 
00124     ChangeRecorder *mMonitor;
00125     EntityTreeModel *mModel;
00126     CollectionFilterProxyModel *mMimeTypeFilterModel;
00127     EntityRightsFilterModel *mRightsFilterModel;
00128     EntityTreeView *mView;
00129     AsyncSelectionHandler *mSelectionHandler;
00130     QLabel *mTextLabel;
00131 
00132     void slotSelectionChanged();
00133 };
00134 
00135 void CollectionDialog::Private::slotSelectionChanged()
00136 {
00137   mParent->enableButton( KDialog::Ok, mView->selectionModel()->selectedIndexes().count() > 0 );
00138 }
00139 
00140 CollectionDialog::CollectionDialog( QWidget *parent )
00141   : KDialog( parent ),
00142     d( new Private( 0, this ) )
00143 {
00144 }
00145 
00146 CollectionDialog::CollectionDialog( QAbstractItemModel *model, QWidget *parent )
00147   : KDialog( parent ),
00148     d( new Private( model, this ) )
00149 {
00150 }
00151 
00152 CollectionDialog::~CollectionDialog()
00153 {
00154   delete d;
00155 }
00156 
00157 Akonadi::Collection CollectionDialog::selectedCollection() const
00158 {
00159   if ( selectionMode() == QAbstractItemView::SingleSelection ) {
00160     const QModelIndex index = d->mView->currentIndex();
00161     if ( index.isValid() )
00162       return index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00163   }
00164 
00165   return Collection();
00166 }
00167 
00168 Akonadi::Collection::List CollectionDialog::selectedCollections() const
00169 {
00170   Collection::List collections;
00171   const QItemSelectionModel *selectionModel = d->mView->selectionModel();
00172   const QModelIndexList selectedIndexes = selectionModel->selectedIndexes();
00173   foreach ( const QModelIndex &index, selectedIndexes ) {
00174     if ( index.isValid() ) {
00175       const Collection collection = index.model()->data( index, EntityTreeModel::CollectionRole ).value<Collection>();
00176       if ( collection.isValid() )
00177         collections.append( collection );
00178     }
00179   }
00180 
00181   return collections;
00182 }
00183 
00184 void CollectionDialog::setMimeTypeFilter( const QStringList &mimeTypes )
00185 {
00186   d->mMimeTypeFilterModel->clearFilters();
00187   d->mMimeTypeFilterModel->addMimeTypeFilters( mimeTypes );
00188 
00189   if ( d->mMonitor )
00190     foreach ( const QString &mimetype, mimeTypes )
00191       d->mMonitor->setMimeTypeMonitored( mimetype );
00192 }
00193 
00194 QStringList CollectionDialog::mimeTypeFilter() const
00195 {
00196   return d->mMimeTypeFilterModel->mimeTypeFilters();
00197 }
00198 
00199 void CollectionDialog::setAccessRightsFilter( Collection::Rights rights )
00200 {
00201   d->mRightsFilterModel->setAccessRights( rights );
00202 }
00203 
00204 Collection::Rights CollectionDialog::accessRightsFilter() const
00205 {
00206   return d->mRightsFilterModel->accessRights();
00207 }
00208 
00209 void CollectionDialog::setDescription( const QString &text )
00210 {
00211   d->mTextLabel->setText( text );
00212   d->mTextLabel->show();
00213 }
00214 
00215 void CollectionDialog::setDefaultCollection( const Collection &collection )
00216 {
00217   d->mSelectionHandler->waitForCollection( collection );
00218 }
00219 
00220 void CollectionDialog::setSelectionMode( QAbstractItemView::SelectionMode mode )
00221 {
00222   d->mView->setSelectionMode( mode );
00223 }
00224 
00225 QAbstractItemView::SelectionMode CollectionDialog::selectionMode() const
00226 {
00227   return d->mView->selectionMode();
00228 }
00229 
00230 #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.7.1
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