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