Akonadi

collectiongeneralpropertiespage.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "collectiongeneralpropertiespage_p.h"
8 
9 #include "collection.h"
10 #include "collectionstatistics.h"
11 #include "collectionutils.h"
12 #include "entitydisplayattribute.h"
13 
14 #include <KLocalizedString>
15 
16 #include <KIO/Global>
17 
18 using namespace Akonadi;
19 
20 /// @cond PRIVATE
21 
22 CollectionGeneralPropertiesPage::CollectionGeneralPropertiesPage(QWidget *parent)
23  : CollectionPropertiesPage(parent)
24 {
25  setObjectName(QStringLiteral("Akonadi::CollectionGeneralPropertiesPage"));
26 
27  setPageTitle(i18nc("@title:tab general properties page", "General"));
28  ui.setupUi(this);
29 }
30 
31 void CollectionGeneralPropertiesPage::load(const Collection &collection)
32 {
34  QString iconName;
35  if (collection.hasAttribute<EntityDisplayAttribute>()) {
37  iconName = collection.attribute<EntityDisplayAttribute>()->iconName();
38  }
39 
40  if (displayName.isEmpty()) {
41  ui.nameEdit->setText(collection.name());
42  } else {
43  ui.nameEdit->setText(displayName);
44  }
45 
46  if (iconName.isEmpty()) {
47  ui.customIcon->setIcon(CollectionUtils::defaultIconName(collection));
48  } else {
49  ui.customIcon->setIcon(iconName);
50  }
51  ui.customIconCheckbox->setChecked(!iconName.isEmpty());
52 
53  if (collection.statistics().count() >= 0) {
54  ui.countLabel->setText(i18ncp("@label", "One object", "%1 objects", collection.statistics().count()));
55  ui.sizeLabel->setText(KIO::convertSize(collection.statistics().size()));
56  } else {
57  ui.statsBox->hide();
58  }
59 }
60 
61 void CollectionGeneralPropertiesPage::save(Collection &collection)
62 {
64  collection.attribute<EntityDisplayAttribute>()->setDisplayName(ui.nameEdit->text());
65  } else {
66  collection.setName(ui.nameEdit->text());
67  }
68 
69  if (ui.customIconCheckbox->isChecked()) {
70  collection.attribute<EntityDisplayAttribute>(Collection::AddIfMissing)->setIconName(ui.customIcon->icon());
71  } else if (collection.hasAttribute<EntityDisplayAttribute>()) {
72  collection.attribute<EntityDisplayAttribute>()->setIconName(QString());
73  }
74 }
75 
76 /// @endcond
77 
78 #include "moc_collectiongeneralpropertiespage_p.cpp"
KIOCORE_EXPORT QString convertSize(KIO::filesize_t size)
Represents a collection of PIM items.
Definition: collection.h:61
Attribute that stores the properties that are used to display an entity.
qint64 size() const
Returns the total size of the items in this collection or -1 if this information is not available.
QString displayName() const
Returns the name that should be used for display.
qint64 count() const
Returns the number of items in this collection or -1 if this information is not available.
QString i18ncp(const char *context, const char *singular, const char *plural, const TYPE &arg...)
Attribute * attribute(const QByteArray &name)
Returns the attribute of the given type name if available, 0 otherwise.
Definition: collection.cpp:176
bool isEmpty() const const
bool hasAttribute(const QByteArray &name) const
Returns true if the collection has an attribute of the given type name, false otherwise.
Definition: collection.cpp:161
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
void setObjectName(const QString &name)
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:326
QString i18nc(const char *context, const char *text, const TYPE &arg...)
@ AddIfMissing
Creates the attribute if it is missing.
Definition: collection.h:281
A single page in a collection properties dialog.
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:221
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.