• Skip to content
  • Skip to link menu
KDE 4.8 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • 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.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 
00038 class CollectionPropertiesDialog::Private
00039 {
00040   public:
00041     Private( CollectionPropertiesDialog *parent, const Akonadi::Collection &collection, const QStringList &pageNames );
00042 
00043     void init();
00044 
00045     static void registerBuiltinPages();
00046 
00047     void save()
00048     {
00049       for ( int i = 0; i < mTabWidget->count(); ++i ) {
00050         CollectionPropertiesPage *page = static_cast<CollectionPropertiesPage*>( mTabWidget->widget( i ) );
00051         page->save( mCollection );
00052       }
00053 
00054       CollectionModifyJob *job = new CollectionModifyJob( mCollection, 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     CollectionPropertiesDialog *q;
00068     Collection mCollection;
00069     QStringList mPageNames;
00070     KTabWidget* mTabWidget;
00071 };
00072 
00073 typedef QList<CollectionPropertiesPageFactory*> CollectionPropertiesPageFactoryList;
00074 
00075 K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages )
00076 
00077 static bool s_defaultPage = true;
00078 
00079 CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *qq, const Akonadi::Collection &collection, const QStringList &pageNames )
00080   : q( qq ),
00081     mCollection( collection ),
00082     mPageNames( pageNames )
00083 {
00084   if ( s_defaultPage )
00085     registerBuiltinPages();
00086 }
00087 
00088 void CollectionPropertiesDialog::Private::registerBuiltinPages()
00089 {
00090   static bool registered = false;
00091 
00092   if ( registered )
00093     return;
00094 
00095   s_pages->append( new CollectionGeneralPropertiesPageFactory() );
00096   s_pages->append( new CachePolicyPageFactory() );
00097 
00098   registered = true;
00099 }
00100 
00101 void CollectionPropertiesDialog::Private::init()
00102 {
00103   QBoxLayout *layout = new QHBoxLayout( q->mainWidget() );
00104   layout->setMargin( 0 );
00105   mTabWidget = new KTabWidget( q->mainWidget() );
00106   layout->addWidget( mTabWidget );
00107 
00108   if ( mPageNames.isEmpty() ) { // default loading
00109     foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
00110       CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
00111       if ( page->canHandle( mCollection ) ) {
00112         mTabWidget->addTab( page, page->pageTitle() );
00113         page->load( mCollection );
00114       } else {
00115         delete page;
00116       }
00117     }
00118   } else { // custom loading
00119     QHash<QString, CollectionPropertiesPage*> pages;
00120 
00121     foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
00122       CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
00123       const QString pageName = page->objectName();
00124 
00125       if ( page->canHandle( mCollection ) && mPageNames.contains( pageName ) && !pages.contains( pageName ) ) {
00126         pages.insert( page->objectName(), page );
00127       } else {
00128         delete page;
00129       }
00130     }
00131 
00132     foreach ( const QString &pageName, mPageNames ) {
00133       CollectionPropertiesPage *page = pages.value( pageName );
00134       if ( page ) {
00135         mTabWidget->addTab( page, page->pageTitle() );
00136         page->load( mCollection );
00137       }
00138     }
00139   }
00140 
00141   q->connect( q, SIGNAL(okClicked()), SLOT(save()) );
00142   q->connect( q, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
00143 }
00144 
00145 
00146 CollectionPropertiesDialog::CollectionPropertiesDialog( const Collection &collection, QWidget *parent )
00147   : KDialog( parent ),
00148     d( new Private( this, collection, QStringList() ) )
00149 {
00150   d->init();
00151 }
00152 
00153 CollectionPropertiesDialog::CollectionPropertiesDialog( const Collection &collection, const QStringList &pages, QWidget *parent )
00154   : KDialog( parent ),
00155     d( new Private( this, collection, pages ) )
00156 {
00157   d->init();
00158 }
00159 
00160 CollectionPropertiesDialog::~CollectionPropertiesDialog()
00161 {
00162   delete d;
00163 }
00164 
00165 void CollectionPropertiesDialog::registerPage( CollectionPropertiesPageFactory *factory )
00166 {
00167   if ( s_pages->isEmpty() && s_defaultPage )
00168     Private::registerBuiltinPages();
00169   s_pages->append( factory );
00170 }
00171 
00172 void CollectionPropertiesDialog::useDefaultPage( bool defaultPage )
00173 {
00174   s_defaultPage = defaultPage;
00175 }
00176 
00177 QString CollectionPropertiesDialog::defaultPageObjectName( DefaultPage page )
00178 {
00179   switch ( page ) {
00180     case GeneralPage:
00181       return QLatin1String( "Akonadi::CollectionGeneralPropertiesPage" );
00182     case CachePage:
00183       return QLatin1String( "Akonadi::CachePolicyPage" );
00184   }
00185 
00186   return QString();
00187 }
00188 
00189 #include "collectionpropertiesdialog.moc"

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • 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.6.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