• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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 "ui_subscriptiondialog.h"
00023 #include "subscriptionmodel_p.h"
00024 #include "subscriptionjob_p.h"
00025 #include "subscriptionchangeproxymodel_p.h"
00026 #include "flatcollectionproxymodel_p.h"
00027 #include "control.h"
00028 #include "krecursivefilterproxymodel.h"
00029 
00030 #include <kdebug.h>
00031 
00032 using namespace Akonadi;
00033 
00037 class SubscriptionDialog::Private
00038 {
00039   public:
00040     Private( SubscriptionDialog *parent ) : q( parent ) {}
00041 
00042     void setupChangeView( QTreeView *view, bool subscribe )
00043     {
00044       FlatCollectionProxyModel *flatProxy = new FlatCollectionProxyModel( q );
00045       flatProxy->setSourceModel( model );
00046       SubscriptionChangeProxyModel *subProxy = new SubscriptionChangeProxyModel( subscribe, q );
00047       subProxy->setSourceModel( flatProxy );
00048       view->setModel( subProxy );
00049     }
00050 
00051     void done()
00052     {
00053       SubscriptionJob *job = new SubscriptionJob( q );
00054       job->subscribe( model->subscribed() );
00055       job->unsubscribe( model->unsubscribed() );
00056       connect( job, SIGNAL( result( KJob* ) ), q, SLOT( subscriptionResult( KJob* ) ) );
00057     }
00058 
00059     void subscriptionResult( KJob *job )
00060     {
00061       if ( job->error() ) {
00062         // TODO
00063         kWarning() << job->errorString();
00064       }
00065       q->deleteLater();
00066     }
00067 
00068     void subscribeClicked()
00069     {
00070       foreach ( const QModelIndex &index, ui.collectionView->selectionModel()->selectedIndexes() )
00071         model->setData( index, Qt::Checked, Qt::CheckStateRole );
00072     }
00073 
00074     void unsubscribeClicked()
00075     {
00076       foreach ( const QModelIndex &index, ui.collectionView->selectionModel()->selectedIndexes() )
00077         model->setData( index, Qt::Unchecked, Qt::CheckStateRole );
00078     }
00079 
00080     void modelLoaded()
00081     {
00082       ui.collectionView->setEnabled( true );
00083       ui.subscribeButton->setEnabled( true );
00084       ui.unsubscribeButton->setEnabled( true );
00085       ui.subscribeView->setEnabled( true );
00086       ui.unsubscribeView->setEnabled( true );
00087       ui.collectionView->expandAll();
00088       q->enableButtonOk( true );
00089     }
00090 
00091     SubscriptionDialog* q;
00092     Ui::SubscriptionDialog ui;
00093     SubscriptionModel* model;
00094     KRecursiveFilterProxyModel *filterTreeViewModel;
00095 };
00096 
00097 SubscriptionDialog::SubscriptionDialog(QWidget * parent) :
00098     KDialog( parent ),
00099     d( new Private( this ) )
00100 {
00101   enableButtonOk( false );
00102   d->ui.setupUi( mainWidget() );
00103   KIcon icon;
00104   if ( QApplication::isLeftToRight() )
00105     icon = KIcon( QLatin1String( "go-next" ) );
00106   else
00107     icon = KIcon( QLatin1String( "go-previous" ) );
00108   d->ui.subscribeButton->setIcon( icon );
00109   d->ui.unsubscribeButton->setIcon( icon );
00110 
00111   d->model = new SubscriptionModel( this );
00112 
00113   d->filterTreeViewModel = new KRecursiveFilterProxyModel( this );
00114   d->filterTreeViewModel->setDynamicSortFilter( true );
00115   d->filterTreeViewModel->setSourceModel( d->model );
00116   d->filterTreeViewModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
00117   d->ui.collectionView->setModel( d->filterTreeViewModel );
00118 
00119   d->setupChangeView( d->ui.subscribeView, true );
00120   d->setupChangeView( d->ui.unsubscribeView, false );
00121 
00122   connect( d->model, SIGNAL( loaded() ), SLOT( modelLoaded() ) );
00123   connect( d->ui.subscribeButton, SIGNAL( clicked() ), SLOT( subscribeClicked() ) );
00124   connect( d->ui.unsubscribeButton, SIGNAL( clicked() ), SLOT( unsubscribeClicked() ) );
00125   connect( this, SIGNAL( okClicked() ), SLOT( done() ) );
00126   connect( this, SIGNAL( cancelClicked() ), SLOT( deleteLater() ) );
00127   connect( d->ui.klineedit, SIGNAL( textChanged( const QString& ) ),
00128            d->filterTreeViewModel, SLOT( setFilterFixedString( const QString& ) ) );
00129   Control::widgetNeedsAkonadi( mainWidget() );
00130 }
00131 
00132 SubscriptionDialog::~ SubscriptionDialog()
00133 {
00134   delete d;
00135 }
00136 
00137 #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
  • 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