akonadi
collectionpropertiesdialog.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00038 class CollectionPropertiesDialog::Private
00039 {
00040 public:
00041 Private( CollectionPropertiesDialog *parent );
00042
00043 static void registerBuiltinPages();
00044
00045 void save()
00046 {
00047 for ( int i = 0; i < tabWidget->count(); ++i ) {
00048 CollectionPropertiesPage *page = static_cast<CollectionPropertiesPage*>( tabWidget->widget( i ) );
00049 page->save( collection );
00050 }
00051
00052 CollectionModifyJob *job = new CollectionModifyJob( collection, q );
00053 connect( job, SIGNAL(result(KJob*)), q, SLOT(saveResult(KJob*)) );
00054 }
00055
00056 void saveResult( KJob *job )
00057 {
00058 if ( job->error() ) {
00059
00060 kWarning() << job->errorString();
00061 }
00062 q->deleteLater();
00063 }
00064
00065 Collection collection;
00066 KTabWidget* tabWidget;
00067 CollectionPropertiesDialog *q;
00068 };
00069
00070 typedef QList<CollectionPropertiesPageFactory*> CollectionPropertiesPageFactoryList;
00071
00072 K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages )
00073
00074 K_GLOBAL_STATIC_WITH_ARGS( bool, s_defaultPage,( "true" ) )
00075
00076 CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *parent ) : q( parent )
00077 {
00078 if ( s_pages->isEmpty() && *s_defaultPage)
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() && *s_defaultPage)
00122 Private::registerBuiltinPages();
00123 s_pages->append( factory );
00124 }
00125
00126 void CollectionPropertiesDialog::useDefaultPage( bool defaultPage )
00127 {
00128 *s_defaultPage = defaultPage;
00129 }
00130
00131 #include "collectionpropertiesdialog.moc"