Akonadi

collectiongeneralpropertiespage.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
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 <KFormat>
17
18using namespace Akonadi;
19
20/// @cond PRIVATE
21
22CollectionGeneralPropertiesPage::CollectionGeneralPropertiesPage(QWidget *parent)
24{
25 setObjectName(QLatin1StringView("Akonadi::CollectionGeneralPropertiesPage"));
26
27 setPageTitle(i18nc("@title:tab general properties page", "General"));
28 ui.setupUi(this);
29}
30
31void 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 KFormat format;
56 ui.sizeLabel->setText(format.formatByteSize(collection.statistics().size()));
57 } else {
58 ui.statsBox->hide();
59 }
60}
61
62void CollectionGeneralPropertiesPage::save(Collection &collection)
63{
65 collection.attribute<EntityDisplayAttribute>()->setDisplayName(ui.nameEdit->text());
66 } else {
67 collection.setName(ui.nameEdit->text());
68 }
69
70 if (ui.customIconCheckbox->isChecked()) {
71 collection.attribute<EntityDisplayAttribute>(Collection::AddIfMissing)->setIconName(ui.customIcon->icon());
72 } else if (collection.hasAttribute<EntityDisplayAttribute>()) {
73 collection.attribute<EntityDisplayAttribute>()->setIconName(QString());
74 }
75}
76
77/// @endcond
78
79#include "moc_collectiongeneralpropertiespage_p.cpp"
A single page in a collection properties dialog.
qint64 count() const
Returns the number of items in this collection or -1 if this information is not available.
qint64 size() const
Returns the total size of the items in this collection or -1 if this information is not available.
Represents a collection of PIM items.
Definition collection.h:62
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
bool hasAttribute(const QByteArray &name) const
Returns true if the collection has an attribute of the given type name, false otherwise.
void setName(const QString &name)
Sets the i18n'ed name of the collection.
@ AddIfMissing
Creates the attribute if it is missing.
Definition collection.h:281
Attribute * attribute(const QByteArray &name)
Returns the attribute of the given type name if available, 0 otherwise.
Attribute that stores the properties that are used to display an entity.
QString displayName() const
Returns the name that should be used for display.
QString formatByteSize(double size, int precision=1, KFormat::BinaryUnitDialect dialect=KFormat::DefaultBinaryDialect, KFormat::BinarySizeUnits units=KFormat::DefaultBinaryUnits) const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18ncp(const char *context, const char *singular, const char *plural, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
Helper integration between Akonadi and Qt.
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.