• Skip to content
  • Skip to link menu
KDE 4.7 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->header()->hide();
00137 
00138   if ( !mimetypes.isEmpty() ) {
00139     RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter
00140       = new Akonadi::RecursiveCollectionFilterProxyModel( this );
00141     filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
00142     filterRecursiveCollectionFilter->setSourceModel( filterTreeViewModel );
00143     d->collectionView->setModel( filterRecursiveCollectionFilter );
00144   } else {
00145     d->collectionView->setModel( filterTreeViewModel );
00146   }
00147 
00148   QHBoxLayout *filterBarLayout = new QHBoxLayout;
00149 
00150   filterBarLayout->addWidget( new QLabel( i18n( "Search:" ) ) );
00151 
00152   KLineEdit *lineEdit = new KLineEdit( mainWidget );
00153   connect( lineEdit, SIGNAL( textChanged( const QString& ) ),
00154            filterTreeViewModel, SLOT( setFilterFixedString( const QString& ) ) );
00155   filterBarLayout->addWidget( lineEdit );
00156   mainLayout->addLayout( filterBarLayout );
00157   mainLayout->addWidget( d->collectionView );
00158 #else
00159 
00160   RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter
00161       = new Akonadi::RecursiveCollectionFilterProxyModel( this );
00162   if ( !mimetypes.isEmpty() )
00163     filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilters( mimetypes );
00164 
00165   filterRecursiveCollectionFilter->setSourceModel( d->model );
00166 
00167   KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
00168   flatModel->setDisplayAncestorData( true );
00169   flatModel->setAncestorSeparator( QLatin1String( "/" ) );
00170   flatModel->setSourceModel( filterRecursiveCollectionFilter );
00171 
00172   CheckableFilterProxyModel *checkableModel = new CheckableFilterProxyModel( this );
00173   checkableModel->setSourceModel( flatModel );
00174 
00175   d->collectionView = new QListView( mainWidget );
00176 
00177   d->collectionView->setModel( checkableModel );
00178   mainLayout->addWidget( d->collectionView );
00179 #endif
00180 
00181   connect( d->model, SIGNAL( loaded() ), SLOT( modelLoaded() ) );
00182   connect( this, SIGNAL( okClicked() ), SLOT( done() ) );
00183   connect( this, SIGNAL( cancelClicked() ), SLOT( deleteLater() ) );
00184   Control::widgetNeedsAkonadi( mainWidget );
00185 }
00186 
00187 SubscriptionDialog::~ SubscriptionDialog()
00188 {
00189   delete d;
00190 }
00191 
00192 #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
  • 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.5
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