• Skip to content
  • Skip to link menu
KDE 4.1 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.h"
00021 #include "ui_subscriptiondialog.h"
00022 #include "subscriptionmodel.h"
00023 #include "subscriptionjob.h"
00024 #include "subscriptionchangeproxymodel.h"
00025 #include "flatcollectionproxymodel.h"
00026 
00027 #include <kdebug.h>
00028 
00029 using namespace Akonadi;
00030 
00034 class SubscriptionDialog::Private
00035 {
00036   public:
00037     Private( SubscriptionDialog *parent ) : q( parent ) {}
00038 
00039     void setupChangeView( QTreeView *view, bool subscribe )
00040     {
00041       FlatCollectionProxyModel *flatProxy = new FlatCollectionProxyModel( q );
00042       flatProxy->setSourceModel( model );
00043       SubscriptionChangeProxyModel *subProxy = new SubscriptionChangeProxyModel( subscribe, q );
00044       subProxy->setSourceModel( flatProxy );
00045       view->setModel( subProxy );
00046     }
00047 
00048     void done()
00049     {
00050       SubscriptionJob *job = new SubscriptionJob( q );
00051       job->subscribe( model->subscribed() );
00052       job->unsubscribe( model->unsubscribed() );
00053       connect( job, SIGNAL(result(KJob*)), q, SLOT(subscriptionResult(KJob*)) );
00054     }
00055 
00056     void subscriptionResult( KJob *job )
00057     {
00058       if ( job->error() ) {
00059         // TODO
00060         kWarning() << job->errorString();
00061       }
00062       q->deleteLater();
00063     }
00064 
00065     void subscribeClicked()
00066     {
00067       foreach( const QModelIndex &index, ui.collectionView->selectionModel()->selectedIndexes() )
00068         model->setData( index, Qt::Checked, Qt::CheckStateRole );
00069     }
00070 
00071     void unsubscribeClicked()
00072     {
00073       foreach( const QModelIndex &index, ui.collectionView->selectionModel()->selectedIndexes() )
00074         model->setData( index, Qt::Unchecked, Qt::CheckStateRole );
00075     }
00076 
00077     void modelLoaded()
00078     {
00079       ui.collectionView->setEnabled( true );
00080       ui.subscribeButton->setEnabled( true );
00081       ui.unsubscribeButton->setEnabled( true );
00082       ui.subscribeView->setEnabled( true );
00083       ui.unsubscribeView->setEnabled( true );
00084       q->enableButtonOk( true );
00085     }
00086 
00087     SubscriptionDialog* q;
00088     Ui::SubscriptionDialog ui;
00089     SubscriptionModel* model;
00090 };
00091 
00092 SubscriptionDialog::SubscriptionDialog(QWidget * parent) :
00093     KDialog( parent ),
00094     d( new Private( this ) )
00095 {
00096   enableButtonOk( false );
00097   d->ui.setupUi( mainWidget() );
00098   KIcon icon;
00099   if ( QApplication::isLeftToRight() )
00100     icon = KIcon( QLatin1String("go-next") );
00101   else
00102     icon = KIcon( QLatin1String("go-previous") );
00103   d->ui.subscribeButton->setIcon( icon );
00104   d->ui.unsubscribeButton->setIcon( icon );
00105 
00106   d->model = new SubscriptionModel( this );
00107   d->ui.collectionView->setModel( d->model );
00108 
00109   d->setupChangeView( d->ui.subscribeView, true );
00110   d->setupChangeView( d->ui.unsubscribeView, false );
00111 
00112   connect( d->model, SIGNAL(loaded()), SLOT(modelLoaded()) );
00113   connect( d->ui.subscribeButton, SIGNAL(clicked()), SLOT(subscribeClicked()) );
00114   connect( d->ui.unsubscribeButton, SIGNAL(clicked()), SLOT(unsubscribeClicked()) );
00115   connect( this, SIGNAL(okClicked()), SLOT(done()) );
00116   connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
00117 }
00118 
00119 SubscriptionDialog::~ SubscriptionDialog()
00120 {
00121   delete d;
00122 }
00123 
00124 #include "subscriptiondialog.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
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.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