• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
collectionpropertiesdialog.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <vkrause@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "collectionpropertiesdialog.h"
21 
22 #include "cachepolicy.h"
23 #include "cachepolicypage.h"
24 #include "collection.h"
25 #include "collectiongeneralpropertiespage_p.h"
26 #include "collectionmodifyjob.h"
27 
28 #include <kdebug.h>
29 #include <ktabwidget.h>
30 
31 #include <QtGui/QBoxLayout>
32 
33 using namespace Akonadi;
34 
38 class CollectionPropertiesDialog::Private
39 {
40  public:
41  Private( CollectionPropertiesDialog *parent, const Akonadi::Collection &collection, const QStringList &pageNames );
42 
43  void init();
44 
45  static void registerBuiltinPages();
46 
47  void save()
48  {
49  for ( int i = 0; i < mTabWidget->count(); ++i ) {
50  CollectionPropertiesPage *page = static_cast<CollectionPropertiesPage*>( mTabWidget->widget( i ) );
51  page->save( mCollection );
52  }
53 
54  CollectionModifyJob *job = new CollectionModifyJob( mCollection, q );
55  connect( job, SIGNAL(result(KJob*)), q, SLOT(saveResult(KJob*)) );
56  }
57 
58  void saveResult( KJob *job )
59  {
60  if ( job->error() ) {
61  // TODO
62  kWarning() << job->errorString();
63  }
64  q->deleteLater();
65  }
66 
67  CollectionPropertiesDialog *q;
68  Collection mCollection;
69  QStringList mPageNames;
70  KTabWidget* mTabWidget;
71 };
72 
73 typedef QList<CollectionPropertiesPageFactory*> CollectionPropertiesPageFactoryList;
74 
75 K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages )
76 
77 static bool s_defaultPage = true;
78 
79 CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *qq, const Akonadi::Collection &collection, const QStringList &pageNames )
80  : q( qq ),
81  mCollection( collection ),
82  mPageNames( pageNames )
83 {
84  if ( s_defaultPage )
85  registerBuiltinPages();
86 }
87 
88 void CollectionPropertiesDialog::Private::registerBuiltinPages()
89 {
90  static bool registered = false;
91 
92  if ( registered )
93  return;
94 
95  s_pages->append( new CollectionGeneralPropertiesPageFactory() );
96  s_pages->append( new CachePolicyPageFactory() );
97 
98  registered = true;
99 }
100 
101 void CollectionPropertiesDialog::Private::init()
102 {
103  QBoxLayout *layout = new QHBoxLayout( q->mainWidget() );
104  layout->setMargin( 0 );
105  mTabWidget = new KTabWidget( q->mainWidget() );
106  layout->addWidget( mTabWidget );
107 
108  if ( mPageNames.isEmpty() ) { // default loading
109  foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
110  CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
111  if ( page->canHandle( mCollection ) ) {
112  mTabWidget->addTab( page, page->pageTitle() );
113  page->load( mCollection );
114  } else {
115  delete page;
116  }
117  }
118  } else { // custom loading
119  QHash<QString, CollectionPropertiesPage*> pages;
120 
121  foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
122  CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
123  const QString pageName = page->objectName();
124 
125  if ( page->canHandle( mCollection ) && mPageNames.contains( pageName ) && !pages.contains( pageName ) ) {
126  pages.insert( page->objectName(), page );
127  } else {
128  delete page;
129  }
130  }
131 
132  foreach ( const QString &pageName, mPageNames ) {
133  CollectionPropertiesPage *page = pages.value( pageName );
134  if ( page ) {
135  mTabWidget->addTab( page, page->pageTitle() );
136  page->load( mCollection );
137  }
138  }
139  }
140 
141  q->connect( q, SIGNAL(okClicked()), SLOT(save()) );
142  q->connect( q, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
143 }
144 
145 
146 CollectionPropertiesDialog::CollectionPropertiesDialog( const Collection &collection, QWidget *parent )
147  : KDialog( parent ),
148  d( new Private( this, collection, QStringList() ) )
149 {
150  d->init();
151 }
152 
153 CollectionPropertiesDialog::CollectionPropertiesDialog( const Collection &collection, const QStringList &pages, QWidget *parent )
154  : KDialog( parent ),
155  d( new Private( this, collection, pages ) )
156 {
157  d->init();
158 }
159 
160 CollectionPropertiesDialog::~CollectionPropertiesDialog()
161 {
162  delete d;
163 }
164 
165 void CollectionPropertiesDialog::registerPage( CollectionPropertiesPageFactory *factory )
166 {
167  if ( s_pages->isEmpty() && s_defaultPage )
168  Private::registerBuiltinPages();
169  s_pages->append( factory );
170 }
171 
172 void CollectionPropertiesDialog::useDefaultPage( bool defaultPage )
173 {
174  s_defaultPage = defaultPage;
175 }
176 
177 QString CollectionPropertiesDialog::defaultPageObjectName( DefaultPage page )
178 {
179  switch ( page ) {
180  case GeneralPage:
181  return QLatin1String( "Akonadi::CollectionGeneralPropertiesPage" );
182  case CachePage:
183  return QLatin1String( "Akonadi::CachePolicyPage" );
184  }
185 
186  return QString();
187 }
188 
189 #include "collectionpropertiesdialog.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Nov 26 2012 16:48:18 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

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

kdepimlibs-4.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal