• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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 <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  void setCurrentPage( const QString &name )
68  {
69  for ( int i = 0; i < mTabWidget->count(); ++i ) {
70  QWidget *w = mTabWidget->widget( i );
71  if ( w->objectName() == name ) {
72  mTabWidget->setCurrentIndex( i );
73  break;
74  }
75  }
76  }
77 
78  CollectionPropertiesDialog *q;
79  Collection mCollection;
80  QStringList mPageNames;
81  KTabWidget* mTabWidget;
82 };
83 
84 typedef QList<CollectionPropertiesPageFactory*> CollectionPropertiesPageFactoryList;
85 
86 K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages )
87 
88 static bool s_defaultPage = true;
89 
90 CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *qq, const Akonadi::Collection &collection, const QStringList &pageNames )
91  : q( qq ),
92  mCollection( collection ),
93  mPageNames( pageNames ),
94  mTabWidget( 0 )
95 {
96  if ( s_defaultPage ) {
97  registerBuiltinPages();
98  }
99 }
100 
101 void CollectionPropertiesDialog::Private::registerBuiltinPages()
102 {
103  static bool registered = false;
104 
105  if ( registered ) {
106  return;
107  }
108 
109  s_pages->append( new CollectionGeneralPropertiesPageFactory() );
110  s_pages->append( new CachePolicyPageFactory() );
111 
112  registered = true;
113 }
114 
115 void CollectionPropertiesDialog::Private::init()
116 {
117  QBoxLayout *layout = new QHBoxLayout( q->mainWidget() );
118  layout->setMargin( 0 );
119  mTabWidget = new KTabWidget( q->mainWidget() );
120  layout->addWidget( mTabWidget );
121 
122  if ( mPageNames.isEmpty() ) { // default loading
123  foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
124  CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
125  if ( page->canHandle( mCollection ) ) {
126  mTabWidget->addTab( page, page->pageTitle() );
127  page->load( mCollection );
128  } else {
129  delete page;
130  }
131  }
132  } else { // custom loading
133  QHash<QString, CollectionPropertiesPage*> pages;
134 
135  foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
136  CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
137  const QString pageName = page->objectName();
138 
139  if ( page->canHandle( mCollection ) && mPageNames.contains( pageName ) && !pages.contains( pageName ) ) {
140  pages.insert( page->objectName(), page );
141  } else {
142  delete page;
143  }
144  }
145 
146  foreach ( const QString &pageName, mPageNames ) {
147  CollectionPropertiesPage *page = pages.value( pageName );
148  if ( page ) {
149  mTabWidget->addTab( page, page->pageTitle() );
150  page->load( mCollection );
151  }
152  }
153  }
154 
155  q->connect( q, SIGNAL(okClicked()), SLOT(save()) );
156  q->connect( q, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
157 
158  KConfigGroup group( KGlobal::config(), "CollectionPropertiesDialog" );
159  const QSize size = group.readEntry( "Size", QSize() );
160  if ( size.isValid() ) {
161  q->resize( size );
162  } else {
163  q->resize( q->sizeHint().width(), q->sizeHint().height() );
164  }
165 
166 }
167 
168 
169 CollectionPropertiesDialog::CollectionPropertiesDialog( const Collection &collection, QWidget *parent )
170  : KDialog( parent ),
171  d( new Private( this, collection, QStringList() ) )
172 {
173  d->init();
174 }
175 
176 CollectionPropertiesDialog::CollectionPropertiesDialog( const Collection &collection, const QStringList &pages, QWidget *parent )
177  : KDialog( parent ),
178  d( new Private( this, collection, pages ) )
179 {
180  d->init();
181 }
182 
183 CollectionPropertiesDialog::~CollectionPropertiesDialog()
184 {
185  KConfigGroup group( KGlobal::config(), "CollectionPropertiesDialog" );
186  group.writeEntry( "Size", size() );
187  delete d;
188 }
189 
190 void CollectionPropertiesDialog::registerPage( CollectionPropertiesPageFactory *factory )
191 {
192  if ( s_pages->isEmpty() && s_defaultPage ) {
193  Private::registerBuiltinPages();
194  }
195  s_pages->append( factory );
196 }
197 
198 void CollectionPropertiesDialog::useDefaultPage( bool defaultPage )
199 {
200  s_defaultPage = defaultPage;
201 }
202 
203 QString CollectionPropertiesDialog::defaultPageObjectName( DefaultPage page )
204 {
205  switch ( page ) {
206  case GeneralPage:
207  return QLatin1String( "Akonadi::CollectionGeneralPropertiesPage" );
208  case CachePage:
209  return QLatin1String( "Akonadi::CachePolicyPage" );
210  }
211 
212  return QString();
213 }
214 
215 void CollectionPropertiesDialog::setCurrentPage( const QString &name )
216 {
217  d->setCurrentPage( name );
218 }
219 
220 #include "moc_collectionpropertiesdialog.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:33 by doxygen 1.8.3.1 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.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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