• Skip to content
  • Skip to link menu
KDE 4.6 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 "subscriptionmodel_p.h"
00023 #include "subscriptionjob_p.h"
00024 #include "control.h"
00025 
00026 #include <kdebug.h>
00027 
00028 #include <QtGui/QBoxLayout>
00029 
00030 #include <klocale.h>
00031 
00032 #ifndef KDEPIM_MOBILE_UI
00033 #include <krecursivefilterproxymodel.h>
00034 #include <recursivecollectionfilterproxymodel.h>
00035 #include <QtGui/QHeaderView>
00036 #include <QtGui/QLabel>
00037 #include <QtGui/QTreeView>
00038 #include <klineedit.h>
00039 #else
00040 #include <QtGui/QListView>
00041 #include <QtGui/QSortFilterProxyModel>
00042 #include "kdescendantsproxymodel_p.h"
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();
00109 }
00110 
00111 SubscriptionDialog::SubscriptionDialog(const QString& mimetype, QWidget * parent) :
00112     KDialog( parent ),
00113     d( new Private( this ) )
00114 {
00115   init( mimetype );
00116 }
00117 
00118 void SubscriptionDialog::init( const QString& mimetype )
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   RecursiveCollectionFilterProxyModel *filterRecursiveCollectionFilter
00136       = new Akonadi::RecursiveCollectionFilterProxyModel( this );
00137   if ( !mimetype.isEmpty() )
00138     filterRecursiveCollectionFilter->addContentMimeTypeInclusionFilter( mimetype );
00139 
00140   filterRecursiveCollectionFilter->setSourceModel( filterTreeViewModel );
00141 
00142   QHBoxLayout *filterBarLayout = new QHBoxLayout;
00143 
00144   filterBarLayout->addWidget( new QLabel( i18n( "Search:" ) ) );
00145 
00146   KLineEdit *lineEdit = new KLineEdit( mainWidget );
00147   connect( lineEdit, SIGNAL( textChanged( const QString& ) ),
00148            filterTreeViewModel, SLOT( setFilterFixedString( const QString& ) ) );
00149   filterBarLayout->addWidget( lineEdit );
00150   mainLayout->addLayout( filterBarLayout );
00151 
00152   d->collectionView = new QTreeView( mainWidget );
00153   d->collectionView->header()->hide();
00154   d->collectionView->setModel( filterRecursiveCollectionFilter );
00155   mainLayout->addWidget( d->collectionView );
00156 #else
00157   KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
00158   flatModel->setDisplayAncestorData( true );
00159   flatModel->setAncestorSeparator( QLatin1String( "/" ) );
00160   flatModel->setSourceModel( d->model );
00161 
00162   CheckableFilterProxyModel *checkableModel = new CheckableFilterProxyModel( this );
00163   checkableModel->setSourceModel( flatModel );
00164 
00165   d->collectionView = new QListView( mainWidget );
00166 
00167   d->collectionView->setModel( checkableModel );
00168   mainLayout->addWidget( d->collectionView );
00169 #endif
00170 
00171   connect( d->model, SIGNAL( loaded() ), SLOT( modelLoaded() ) );
00172   connect( this, SIGNAL( okClicked() ), SLOT( done() ) );
00173   connect( this, SIGNAL( cancelClicked() ), SLOT( deleteLater() ) );
00174   Control::widgetNeedsAkonadi( mainWidget );
00175 }
00176 
00177 SubscriptionDialog::~ SubscriptionDialog()
00178 {
00179   delete d;
00180 }
00181 
00182 #include "subscriptiondialog_p.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
  • 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.3
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