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