• Skip to content
  • Skip to link menu
KDE 4.8 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • 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 
00095     SubscriptionDialog* q;
00096 #ifndef KDEPIM_MOBILE_UI
00097     QTreeView *collectionView;
00098 #else
00099     QListView *collectionView;
00100 #endif
00101     SubscriptionModel* model;
00102 };
00103 
00104 SubscriptionDialog::SubscriptionDialog(QWidget * parent) :
00105     KDialog( parent ),
00106     d( new Private( this ) )
00107 {
00108   init( QStringList() );
00109 }
00110 
00111 SubscriptionDialog::SubscriptionDialog(const QStringList& mimetypes, QWidget * parent) :
00112     KDialog( parent ),
00113     d( new Private( this ) )
00114 {
00115   init( mimetypes );
00116 }
00117 
00118 void SubscriptionDialog::init( const QStringList &mimetypes )
00119 {
00120   enableButtonOk( false );
00121   setCaption( i18n( "Local Subscriptions" ) );
00122   QWidget *mainWidget = new QWidget( this );
00123   QVBoxLayout *mainLayout = new QVBoxLayout;
00124   mainWidget->setLayout( mainLayout );
00125   setMainWidget( mainWidget );
00126 
00127   d->model = new SubscriptionModel( this );
00128 
00129 #ifndef KDEPIM_MOBILE_UI
00130   KRecursiveFilterProxyModel *filterTreeViewModel = new KRecursiveFilterProxyModel( this );
00131   filterTreeViewModel->setDynamicSortFilter( true );
00132   filterTreeViewModel->setSourceModel( d->model );
00133   filterTreeViewModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
00134 
00135   d->collectionView = new QTreeView( mainWidget );
00136   d->collectionView->setEditTriggers( QAbstractItemView::NoEditTriggers );
00137   d->collectionView->header()->hide();
00138 
00139   if ( !mimetypes.isEmpty() ) {
00140     RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter
00141       = new Akonadi::RecursiveCollectionFilterProxyModel( this );
00142     filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
00143     filterRecursiveCollectionFilter->setSourceModel( filterTreeViewModel );
00144     d->collectionView->setModel( filterRecursiveCollectionFilter );
00145   } else {
00146     d->collectionView->setModel( filterTreeViewModel );
00147   }
00148 
00149   QHBoxLayout *filterBarLayout = new QHBoxLayout;
00150 
00151   filterBarLayout->addWidget( new QLabel( i18n( "Search:" ) ) );
00152 
00153   KLineEdit *lineEdit = new KLineEdit( mainWidget );
00154   connect( lineEdit, SIGNAL(textChanged(QString)),
00155            filterTreeViewModel, SLOT(setFilterFixedString(QString)) );
00156   filterBarLayout->addWidget( lineEdit );
00157   mainLayout->addLayout( filterBarLayout );
00158   mainLayout->addWidget( d->collectionView );
00159 #else
00160 
00161   RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter
00162       = new Akonadi::RecursiveCollectionFilterProxyModel( this );
00163   if ( !mimetypes.isEmpty() )
00164     filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
00165 
00166   filterRecursiveCollectionFilter->setSourceModel( d->model );
00167 
00168   KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
00169   flatModel->setDisplayAncestorData( true );
00170   flatModel->setAncestorSeparator( QLatin1String( "/" ) );
00171   flatModel->setSourceModel( filterRecursiveCollectionFilter );
00172 
00173   CheckableFilterProxyModel *checkableModel = new CheckableFilterProxyModel( this );
00174   checkableModel->setSourceModel( flatModel );
00175 
00176   d->collectionView = new QListView( mainWidget );
00177 
00178   d->collectionView->setModel( checkableModel );
00179   mainLayout->addWidget( d->collectionView );
00180 #endif
00181 
00182   connect( d->model, SIGNAL(loaded()), SLOT(modelLoaded()) );
00183   connect( this, SIGNAL(okClicked()), SLOT(done()) );
00184   connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
00185   Control::widgetNeedsAkonadi( mainWidget );
00186 }
00187 
00188 SubscriptionDialog::~ SubscriptionDialog()
00189 {
00190   delete d;
00191 }
00192 
00193 #include "subscriptiondialog_p.moc"

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • 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
Generated for KDE-PIM Libraries by doxygen 1.7.6.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