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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 <kglobal.h>
30 #include <ktabwidget.h>
31 
32 #include <QBoxLayout>
33 
34 using namespace Akonadi;
35 
39 class CollectionPropertiesDialog::Private
40 {
41  public:
42  Private( CollectionPropertiesDialog *parent, const Akonadi::Collection &collection, const QStringList &pageNames );
43 
44  void init();
45 
46  static void registerBuiltinPages();
47 
48  void save()
49  {
50  for ( int i = 0; i < mTabWidget->count(); ++i ) {
51  CollectionPropertiesPage *page = static_cast<CollectionPropertiesPage*>( mTabWidget->widget( i ) );
52  page->save( mCollection );
53  }
54 
55  CollectionModifyJob *job = new CollectionModifyJob( mCollection, q );
56  connect( job, SIGNAL(result(KJob*)), q, SLOT(saveResult(KJob*)) );
57  }
58 
59  void saveResult( KJob *job )
60  {
61  if ( job->error() ) {
62  // TODO
63  kWarning() << job->errorString();
64  }
65  q->deleteLater();
66  }
67 
68  void setCurrentPage( const QString &name )
69  {
70  for ( int i = 0; i < mTabWidget->count(); ++i ) {
71  QWidget *w = mTabWidget->widget( i );
72  if ( w->objectName() == name ) {
73  mTabWidget->setCurrentIndex( i );
74  break;
75  }
76  }
77  }
78 
79  CollectionPropertiesDialog *q;
80  Collection mCollection;
81  QStringList mPageNames;
82  KTabWidget* mTabWidget;
83 };
84 
85 typedef QList<CollectionPropertiesPageFactory*> CollectionPropertiesPageFactoryList;
86 
87 K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages )
88 
89 static bool s_defaultPage = true;
90 
91 CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *qq, const Akonadi::Collection &collection, const QStringList &pageNames )
92  : q( qq ),
93  mCollection( collection ),
94  mPageNames( pageNames ),
95  mTabWidget( 0 )
96 {
97  if ( s_defaultPage ) {
98  registerBuiltinPages();
99  }
100 }
101 
102 void CollectionPropertiesDialog::Private::registerBuiltinPages()
103 {
104  static bool registered = false;
105 
106  if ( registered ) {
107  return;
108  }
109 
110  s_pages->append( new CollectionGeneralPropertiesPageFactory() );
111  s_pages->append( new CachePolicyPageFactory() );
112 
113  registered = true;
114 }
115 
116 void CollectionPropertiesDialog::Private::init()
117 {
118  QBoxLayout *layout = new QHBoxLayout( q->mainWidget() );
119  layout->setMargin( 0 );
120  mTabWidget = new KTabWidget( q->mainWidget() );
121  layout->addWidget( mTabWidget );
122 
123  if ( mPageNames.isEmpty() ) { // default loading
124  foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
125  CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
126  if ( page->canHandle( mCollection ) ) {
127  mTabWidget->addTab( page, page->pageTitle() );
128  page->load( mCollection );
129  } else {
130  delete page;
131  }
132  }
133  } else { // custom loading
134  QHash<QString, CollectionPropertiesPage*> pages;
135 
136  foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) {
137  CollectionPropertiesPage *page = factory->createWidget( mTabWidget );
138  const QString pageName = page->objectName();
139 
140  if ( page->canHandle( mCollection ) && mPageNames.contains( pageName ) && !pages.contains( pageName ) ) {
141  pages.insert( page->objectName(), page );
142  } else {
143  delete page;
144  }
145  }
146 
147  foreach ( const QString &pageName, mPageNames ) {
148  CollectionPropertiesPage *page = pages.value( pageName );
149  if ( page ) {
150  mTabWidget->addTab( page, page->pageTitle() );
151  page->load( mCollection );
152  }
153  }
154  }
155 
156  q->connect( q, SIGNAL(okClicked()), SLOT(save()) );
157  q->connect( q, SIGNAL(cancelClicked()), SLOT(deleteLater()) );
158 
159  KConfigGroup group( KGlobal::config(), "CollectionPropertiesDialog" );
160  const QSize size = group.readEntry( "Size", QSize() );
161  if ( size.isValid() ) {
162  q->resize( size );
163  } else {
164  q->resize( q->sizeHint().width(), q->sizeHint().height() );
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"
Akonadi::CollectionModifyJob
Job that modifies a collection in the Akonadi storage.
Definition: collectionmodifyjob.h:82
Akonadi::CollectionPropertiesPageFactory
A factory class for collection properties dialog pages.
Definition: collectionpropertiespage.h:168
Akonadi::CollectionPropertiesPage::save
virtual void save(Collection &collection)=0
Saves page content to the given collection.
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::CollectionPropertiesDialog::defaultPageObjectName
static QString defaultPageObjectName(DefaultPage page)
Returns the object name of one of the dialog's registered default pages.
Definition: collectionpropertiesdialog.cpp:203
Akonadi::CollectionPropertiesPage
A single page in a collection properties dialog.
Definition: collectionpropertiespage.h:99
Akonadi::CollectionPropertiesPage::load
virtual void load(const Collection &collection)=0
Loads the page content from the given collection.
Akonadi::CollectionPropertiesDialog::~CollectionPropertiesDialog
~CollectionPropertiesDialog()
Destroys the collection properties dialog.
Definition: collectionpropertiesdialog.cpp:183
Akonadi::CollectionPropertiesDialog::registerPage
static void registerPage(CollectionPropertiesPageFactory *factory)
Register custom pages for the collection properties dialog.
Definition: collectionpropertiesdialog.cpp:190
Akonadi::CollectionPropertiesDialog::setCurrentPage
void setCurrentPage(const QString &name)
Sets the page to be shown in the tab widget.
Definition: collectionpropertiesdialog.cpp:215
Akonadi::CollectionPropertiesDialog::GeneralPage
General properties page.
Definition: collectionpropertiesdialog.h:64
Akonadi::CollectionPropertiesPage::canHandle
virtual bool canHandle(const Collection &collection) const
Checks if this page can actually handle the given collection.
Akonadi::CollectionPropertiesPage::pageTitle
QString pageTitle() const
Returns the page title.
Akonadi::CollectionPropertiesDialog::useDefaultPage
static void useDefaultPage(bool use)
Sets whether to use default page or not.
Definition: collectionpropertiesdialog.cpp:198
Akonadi::CollectionPropertiesDialog::DefaultPage
DefaultPage
Enumerates the registered default pages which can be displayed.
Definition: collectionpropertiesdialog.h:63
Akonadi::CollectionPropertiesPageFactory::createWidget
virtual CollectionPropertiesPage * createWidget(QWidget *parent=0) const =0
Returns the actual page widget.
Akonadi::CollectionPropertiesDialog::CachePage
Cache properties page.
Definition: collectionpropertiesdialog.h:65
Akonadi::CollectionPropertiesDialog::CollectionPropertiesDialog
CollectionPropertiesDialog(const Collection &collection, QWidget *parent=0)
Creates a new collection properties dialog.
Definition: collectionpropertiesdialog.cpp:169
Akonadi::CollectionPropertiesDialog
A generic and extensible dialog for collection properties.
Definition: collectionpropertiesdialog.h:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:26 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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