• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi

subscriptiondialog.cpp
00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@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 "subscriptiondialog_p.h"
00021 
00022 #include "control.h"
00023 #include "recursivecollectionfilterproxymodel.h"
00024 #include "subscriptionjob_p.h"
00025 #include "subscriptionmodel_p.h"
00026 
00027 #include <kdebug.h>
00028 
00029 #include <QtGui/QBoxLayout>
00030 
00031 #include <klocale.h>
00032 
00033 #ifndef KDEPIM_MOBILE_UI
00034 #include <klineedit.h>
00035 #include <krecursivefilterproxymodel.h>
00036 #include <QtGui/QHeaderView>
00037 #include <QtGui/QLabel>
00038 #include <QtGui/QTreeView>
00039 #else
00040 #include <kdescendantsproxymodel.h>
00041 #include <QtGui/QListView>
00042 #include <QtGui/QSortFilterProxyModel>
00043 
00044 class CheckableFilterProxyModel : public QSortFilterProxyModel
00045 {
00046 public:
00047   CheckableFilterProxyModel( QObject *parent = 0 )
00048     : QSortFilterProxyModel( parent ) { }
00049 
00050 protected:
00051   /*reimp*/ bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
00052   {
00053     QModelIndex sourceIndex = sourceModel()->index( sourceRow, 0, sourceParent );
00054     return sourceModel()->flags( sourceIndex ) & Qt::ItemIsUserCheckable;
00055   }
00056 };
00057 #endif
00058 
00059 using namespace Akonadi;
00060 
00064 class SubscriptionDialog::Private
00065 {
00066   public:
00067     Private( SubscriptionDialog *parent ) : q( parent ) {}
00068 
00069     void done()
00070     {
00071       SubscriptionJob *job = new SubscriptionJob( q );
00072       job->subscribe( model->subscribed() );
00073       job->unsubscribe( model->unsubscribed() );
00074       connect( job, SIGNAL(result(KJob*)), q, SLOT(subscriptionResult(KJob*)) );
00075     }
00076 
00077     void subscriptionResult( KJob *job )
00078     {
00079       if ( job->error() ) {
00080         // TODO
00081         kWarning() << job->errorString();
00082       }
00083       q->deleteLater();
00084     }
00085 
00086     void modelLoaded()
00087     {
00088       collectionView->setEnabled( true );
00089 #ifndef KDEPIM_MOBILE_UI
00090       collectionView->expandAll();
00091 #endif
00092       q->enableButtonOk( true );
00093     }
00094     void slotSetPattern(const QString &text)
00095     {
00096       filterRecursiveCollectionFilter->setSearchPattern( text );
00097     }
00098     SubscriptionDialog* q;
00099 #ifndef KDEPIM_MOBILE_UI
00100     QTreeView *collectionView;
00101 #else
00102     QListView *collectionView;
00103 #endif
00104     SubscriptionModel* model;
00105     RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter;
00106 
00107 };
00108 
00109 SubscriptionDialog::SubscriptionDialog(QWidget * parent) :
00110     KDialog( parent ),
00111     d( new Private( this ) )
00112 {
00113   init( QStringList() );
00114 }
00115 
00116 SubscriptionDialog::SubscriptionDialog(const QStringList& mimetypes, QWidget * parent) :
00117     KDialog( parent ),
00118     d( new Private( this ) )
00119 {
00120   init( mimetypes );
00121 }
00122 
00123 void SubscriptionDialog::init( const QStringList &mimetypes )
00124 {
00125   enableButtonOk( false );
00126   setCaption( i18n( "Local Subscriptions" ) );
00127   QWidget *mainWidget = new QWidget( this );
00128   QVBoxLayout *mainLayout = new QVBoxLayout;
00129   mainWidget->setLayout( mainLayout );
00130   setMainWidget( mainWidget );
00131 
00132   d->model = new SubscriptionModel( this );
00133 
00134 #ifndef KDEPIM_MOBILE_UI
00135   d->filterRecursiveCollectionFilter
00136       = new Akonadi::RecursiveCollectionFilterProxyModel( this );
00137   d->filterRecursiveCollectionFilter->setDynamicSortFilter( true );
00138   d->filterRecursiveCollectionFilter->setSourceModel( d->model );
00139   d->filterRecursiveCollectionFilter->setFilterCaseSensitivity( Qt::CaseInsensitive );
00140   if ( !mimetypes.isEmpty() ) {
00141     d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
00142   }
00143 
00144   d->collectionView = new QTreeView( mainWidget );
00145   d->collectionView->setEditTriggers( QAbstractItemView::NoEditTriggers );
00146   d->collectionView->header()->hide();
00147   d->collectionView->setModel( d->filterRecursiveCollectionFilter );
00148 
00149 
00150   QHBoxLayout *filterBarLayout = new QHBoxLayout;
00151 
00152   filterBarLayout->addWidget( new QLabel( i18n( "Search:" ) ) );
00153 
00154   KLineEdit *lineEdit = new KLineEdit( mainWidget );
00155   lineEdit->setClearButtonShown(true);
00156   lineEdit->setFocus();
00157   connect( lineEdit, SIGNAL(textChanged(QString)),
00158            this, SLOT(slotSetPattern(QString)) );
00159   filterBarLayout->addWidget( lineEdit );
00160   mainLayout->addLayout( filterBarLayout );
00161   mainLayout->addWidget( d->collectionView );
00162 #else
00163 
00164   d->filterRecursiveCollectionFilter
00165       = new Akonadi::RecursiveCollectionFilterProxyModel( this );
00166   if ( !mimetypes.isEmpty() )
00167     d->filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
00168 
00169   d->filterRecursiveCollectionFilter->setSourceModel( d->model );
00170 
00171   KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
00172   flatModel->setDisplayAncestorData( true );
00173   flatModel->setAncestorSeparator( QLatin1String( "/" ) );
00174   flatModel->setSourceModel( d->filterRecursiveCollectionFilter );
00175 
00176   CheckableFilterProxyModel *checkableModel = new CheckableFilterProxyModel( this );
00177   checkableModel->setSourceModel( flatModel );
00178 
00179   d->collectionView = new QListView( mainWidget );
00180 
00181   d->collectionView->setModel( checkableModel );
00182   mainLayout->addWidget( d->collectionView );
00183 #endif
00184 
00185   connect( d->model, SIGNAL(loaded()), SLOT(modelLoaded()) );
00186   connect( this, SIGNAL(okClicked()), SLOT(done()) );
00187   connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
00188   Control::widgetNeedsAkonadi( mainWidget );
00189 }
00190 
00191 SubscriptionDialog::~ SubscriptionDialog()
00192 {
00193   delete d;
00194 }
00195 
00196 
00197 #include "subscriptiondialog_p.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:16 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

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

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal