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

akonadi

  • sources
  • kde-4.14
  • 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 <ksharedconfig.h>
31 #include <ktabwidget.h>
32 
33 #include <QBoxLayout>
34 
35 using namespace Akonadi;
36 
40 class CollectionPropertiesDialog::Private
41 {
42 public:
43  Private(CollectionPropertiesDialog *parent, const Akonadi::Collection &collection, const QStringList &pageNames);
44 
45  void init();
46 
47  static void registerBuiltinPages();
48 
49  void save()
50  {
51  for (int i = 0; i < mTabWidget->count(); ++i) {
52  CollectionPropertiesPage *page = static_cast<CollectionPropertiesPage *>(mTabWidget->widget(i));
53  page->save(mCollection);
54  }
55 
56  CollectionModifyJob *job = new CollectionModifyJob(mCollection, q);
57  connect(job, SIGNAL(result(KJob*)), q, SLOT(saveResult(KJob*)));
58  }
59 
60  void saveResult(KJob *job)
61  {
62  if (job->error()) {
63  // TODO
64  kWarning() << job->errorString();
65  }
66  q->deleteLater();
67  }
68 
69  void setCurrentPage(const QString &name)
70  {
71  for (int i = 0; i < mTabWidget->count(); ++i) {
72  QWidget *w = mTabWidget->widget(i);
73  if (w->objectName() == name) {
74  mTabWidget->setCurrentIndex(i);
75  break;
76  }
77  }
78  }
79 
80  CollectionPropertiesDialog *q;
81  Collection mCollection;
82  QStringList mPageNames;
83  KTabWidget *mTabWidget;
84 };
85 
86 typedef QList<CollectionPropertiesPageFactory *> CollectionPropertiesPageFactoryList;
87 
88 K_GLOBAL_STATIC(CollectionPropertiesPageFactoryList, s_pages)
89 
90 static bool s_defaultPage = true;
91 
92 CollectionPropertiesDialog::Private::Private(CollectionPropertiesDialog *qq, const Akonadi::Collection &collection, const QStringList &pageNames)
93  : q(qq)
94  , mCollection(collection)
95  , mPageNames(pageNames)
96  , mTabWidget(0)
97 {
98  if (s_defaultPage) {
99  registerBuiltinPages();
100  }
101 }
102 
103 void CollectionPropertiesDialog::Private::registerBuiltinPages()
104 {
105  static bool registered = false;
106 
107  if (registered) {
108  return;
109  }
110 
111  s_pages->append(new CollectionGeneralPropertiesPageFactory());
112  s_pages->append(new CachePolicyPageFactory());
113 
114  registered = true;
115 }
116 
117 void CollectionPropertiesDialog::Private::init()
118 {
119  QBoxLayout *layout = new QHBoxLayout(q->mainWidget());
120  layout->setMargin(0);
121  mTabWidget = new KTabWidget(q->mainWidget());
122  layout->addWidget(mTabWidget);
123 
124  if (mPageNames.isEmpty()) { // default loading
125  foreach (CollectionPropertiesPageFactory *factory, *s_pages) {
126  CollectionPropertiesPage *page = factory->createWidget(mTabWidget);
127  if (page->canHandle(mCollection)) {
128  mTabWidget->addTab(page, page->pageTitle());
129  page->load(mCollection);
130  } else {
131  delete page;
132  }
133  }
134  } else { // custom loading
135  QHash<QString, CollectionPropertiesPage *> pages;
136 
137  foreach (CollectionPropertiesPageFactory *factory, *s_pages) {
138  CollectionPropertiesPage *page = factory->createWidget(mTabWidget);
139  const QString pageName = page->objectName();
140 
141  if (page->canHandle(mCollection) && mPageNames.contains(pageName) && !pages.contains(pageName)) {
142  pages.insert(page->objectName(), page);
143  } else {
144  delete page;
145  }
146  }
147 
148  foreach (const QString &pageName, mPageNames) {
149  CollectionPropertiesPage *page = pages.value(pageName);
150  if (page) {
151  mTabWidget->addTab(page, page->pageTitle());
152  page->load(mCollection);
153  }
154  }
155  }
156 
157  q->connect(q, SIGNAL(okClicked()), SLOT(save()));
158  q->connect(q, SIGNAL(cancelClicked()), SLOT(deleteLater()));
159 
160  KConfigGroup group(KGlobal::config(), "CollectionPropertiesDialog");
161  const QSize size = group.readEntry("Size", QSize());
162  if (size.isValid()) {
163  q->resize(size);
164  } else {
165  q->resize(q->sizeHint().width(), q->sizeHint().height());
166  }
167 
168 }
169 
170 CollectionPropertiesDialog::CollectionPropertiesDialog(const Collection &collection, QWidget *parent)
171  : KDialog(parent)
172  , d(new Private(this, collection, QStringList()))
173 {
174  d->init();
175 }
176 
177 CollectionPropertiesDialog::CollectionPropertiesDialog(const Collection &collection, const QStringList &pages, QWidget *parent)
178  : KDialog(parent)
179  , d(new Private(this, collection, pages))
180 {
181  d->init();
182 }
183 
184 CollectionPropertiesDialog::~CollectionPropertiesDialog()
185 {
186  KConfigGroup group(KGlobal::config(), "CollectionPropertiesDialog");
187  group.writeEntry("Size", size());
188  delete d;
189 }
190 
191 void CollectionPropertiesDialog::registerPage(CollectionPropertiesPageFactory *factory)
192 {
193  if (s_pages->isEmpty() && s_defaultPage) {
194  Private::registerBuiltinPages();
195  }
196  s_pages->append(factory);
197 }
198 
199 void CollectionPropertiesDialog::useDefaultPage(bool defaultPage)
200 {
201  s_defaultPage = defaultPage;
202 }
203 
204 QString CollectionPropertiesDialog::defaultPageObjectName(DefaultPage page)
205 {
206  switch (page) {
207  case GeneralPage:
208  return QLatin1String("Akonadi::CollectionGeneralPropertiesPage");
209  case CachePage:
210  return QLatin1String("Akonadi::CachePolicyPage");
211  }
212 
213  return QString();
214 }
215 
216 void CollectionPropertiesDialog::setCurrentPage(const QString &name)
217 {
218  d->setCurrentPage(name);
219 }
220 
221 #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
QWidget
QSize::isValid
bool isValid() const
QHash::insert
iterator insert(const Key &key, const T &value)
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:204
QHBoxLayout
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:184
Akonadi::CollectionPropertiesDialog::registerPage
static void registerPage(CollectionPropertiesPageFactory *factory)
Register custom pages for the collection properties dialog.
Definition: collectionpropertiesdialog.cpp:191
Akonadi::CollectionPropertiesDialog::setCurrentPage
void setCurrentPage(const QString &name)
Sets the page to be shown in the tab widget.
Definition: collectionpropertiesdialog.cpp:216
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.
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QHash
Akonadi::CollectionPropertiesDialog::useDefaultPage
static void useDefaultPage(bool use)
Sets whether to use default page or not.
Definition: collectionpropertiesdialog.cpp:199
QObject::objectName
objectName
Akonadi::CollectionPropertiesDialog::DefaultPage
DefaultPage
Enumerates the registered default pages which can be displayed.
Definition: collectionpropertiesdialog.h:63
QString
QList
Akonadi::CollectionPropertiesPageFactory::createWidget
virtual CollectionPropertiesPage * createWidget(QWidget *parent=0) const =0
Returns the actual page widget.
QLayout::setMargin
void setMargin(int margin)
QStringList
Akonadi::CollectionPropertiesDialog::CachePage
Cache properties page.
Definition: collectionpropertiesdialog.h:65
QHash::value
const T value(const Key &key) const
QSize
QLatin1String
Akonadi::CollectionPropertiesDialog::CollectionPropertiesDialog
CollectionPropertiesDialog(const Collection &collection, QWidget *parent=0)
Creates a new collection properties dialog.
Definition: collectionpropertiesdialog.cpp:170
QHash::contains
bool contains(const Key &key) const
Akonadi::CollectionPropertiesDialog
A generic and extensible dialog for collection properties.
Definition: collectionpropertiesdialog.h:54
QBoxLayout
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:02 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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