• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

collectionpropertiesdialog.cpp

00001 /*
00002     Copyright (c) 2008 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 "collectionpropertiesdialog.h"
00021 
00022 #include "cachepolicy.h"
00023 #include "cachepolicypage_p.h"
00024 #include "collection.h"
00025 #include "collectiongeneralpropertiespage_p.h"
00026 #include "collectionmodifyjob.h"
00027 
00028 #include <kdebug.h>
00029 #include <ktabwidget.h>
00030 
00031 #include <QtGui/QBoxLayout>
00032 
00033 using namespace Akonadi;
00034 
00035 AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY(CollectionGeneralPropertiesPageFactory, CollectionGeneralPropertiesPage)
00036 
00037 
00040 class CollectionPropertiesDialog::Private
00041 {
00042   public:
00043     Private( CollectionPropertiesDialog *parent );
00044 
00045     static void registerBuiltinPages();
00046 
00047     void save()
00048     {
00049       for ( int i = 0; i < tabWidget->count(); ++i ) {
00050         CollectionPropertiesPage *page = static_cast<CollectionPropertiesPage*>( tabWidget->widget( i ) );
00051         page->save( collection );
00052       }
00053 
00054       CollectionModifyJob *job = new CollectionModifyJob( collection, q );
00055       connect( job, SIGNAL(result(KJob*)), q, SLOT(saveResult(KJob*)) );
00056     }
00057 
00058     void saveResult( KJob *job )
00059     {
00060       if ( job->error() ) {
00061         // TODO
00062         kWarning() << job->errorString();
00063       }
00064       q->deleteLater();
00065     }
00066 
00067     Collection collection;
00068     KTabWidget* tabWidget;
00069     CollectionPropertiesDialog *q;
00070 };
00071 
00072 typedef QList<CollectionPropertiesPageFactory*> CollectionPropertiesPageFactoryList;
00073 
00074 K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages )
00075 
00076 CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *parent ) : q( parent )
00077 {
00078   if ( s_pages->isEmpty() )
00079     registerBuiltinPages();
00080 }
00081 
00082 void CollectionPropertiesDialog::Private::registerBuiltinPages()
00083 {
00084   s_pages->append( new CollectionGeneralPropertiesPageFactory() );
00085   s_pages->append( new CachePolicyPageFactory() );
00086 }
00087 
00088 
00089 CollectionPropertiesDialog::CollectionPropertiesDialog(const Collection & collection, QWidget * parent) :
00090     KDialog( parent ),
00091     d( new Private( this ) )
00092 {
00093   d->collection = collection;
00094 
00095   QBoxLayout *layout = new QHBoxLayout( mainWidget() );
00096   layout->setMargin( 0 );
00097   d->tabWidget = new KTabWidget( mainWidget() );
00098   layout->addWidget( d->tabWidget );
00099 
00100   foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
00101     CollectionPropertiesPage *page = factory->createWidget( d->tabWidget );
00102     if ( page->canHandle( d->collection ) ) {
00103       d->tabWidget->addTab( page, page->pageTitle() );
00104       page->load( d->collection );
00105     } else {
00106       delete page;
00107     }
00108   }
00109 
00110   connect( this, SIGNAL(okClicked()), SLOT(save()) );
00111   connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
00112 }
00113 
00114 CollectionPropertiesDialog::~CollectionPropertiesDialog()
00115 {
00116   delete d;
00117 }
00118 
00119 void CollectionPropertiesDialog::registerPage(CollectionPropertiesPageFactory * factory)
00120 {
00121   if ( s_pages->isEmpty() )
00122     Private::registerBuiltinPages();
00123   s_pages->append( factory );
00124 }
00125 
00126 #include "collectionpropertiesdialog.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
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.9
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