Akonadi

collectiongeneralpropertiespage.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <[email protected]>
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 "collectiongeneralpropertiespage_p.h"
21 
22 #include "collection.h"
23 #include "entitydisplayattribute.h"
24 #include "collectionstatistics.h"
25 #include "collectionutils.h"
26 
27 #include <KLocalizedString>
28 
29 #include <KFormat>
30 
31 using namespace Akonadi;
32 
33 //@cond PRIVATE
34 
35 CollectionGeneralPropertiesPage::CollectionGeneralPropertiesPage(QWidget *parent)
36  : CollectionPropertiesPage(parent)
37 {
38  setObjectName(QStringLiteral("Akonadi::CollectionGeneralPropertiesPage"));
39 
40  setPageTitle(i18nc("@title:tab general properties page", "General"));
41  ui.setupUi(this);
42 }
43 
44 void CollectionGeneralPropertiesPage::load(const Collection &collection)
45 {
46  QString displayName;
47  QString iconName;
48  if (collection.hasAttribute<EntityDisplayAttribute>()) {
49  displayName = collection.attribute<EntityDisplayAttribute>()->displayName();
50  iconName = collection.attribute<EntityDisplayAttribute>()->iconName();
51  }
52 
53  if (displayName.isEmpty()) {
54  ui.nameEdit->setText(collection.name());
55  } else {
56  ui.nameEdit->setText(displayName);
57  }
58 
59  if (iconName.isEmpty()) {
60  ui.customIcon->setIcon(CollectionUtils::defaultIconName(collection));
61  } else {
62  ui.customIcon->setIcon(iconName);
63  }
64  ui.customIconCheckbox->setChecked(!iconName.isEmpty());
65 
66  if (collection.statistics().count() >= 0) {
67  ui.countLabel->setText(i18ncp("@label", "One object", "%1 objects",
68  collection.statistics().count()));
69  ui.sizeLabel->setText(KFormat().formatByteSize(collection.statistics().size()));
70  } else {
71  ui.statsBox->hide();
72  }
73 }
74 
75 void CollectionGeneralPropertiesPage::save(Collection &collection)
76 {
77  if (collection.hasAttribute<EntityDisplayAttribute>() &&
79  collection.attribute<EntityDisplayAttribute>()->setDisplayName(ui.nameEdit->text());
80  } else {
81  collection.setName(ui.nameEdit->text());
82  }
83 
84  if (ui.customIconCheckbox->isChecked()) {
85  collection.attribute<EntityDisplayAttribute>(Collection::AddIfMissing)->setIconName(ui.customIcon->icon());
86  } else if (collection.hasAttribute<EntityDisplayAttribute>()) {
87  collection.attribute<EntityDisplayAttribute>()->setIconName(QString());
88  }
89 }
90 
91 //@endcond
92 
93 #include "moc_collectiongeneralpropertiespage_p.cpp"
qint64 count() const
Returns the number of items in this collection or -1 if this information is not available.
QString name() const
Returns the i18n&#39;ed name of the collection.
Definition: collection.cpp:225
QString displayName() const
Returns the name that should be used for display.
Represents a collection of PIM items.
Definition: collection.h:76
A single page in a collection properties dialog.
Creates the attribute if it is missing.
Definition: collection.h:283
void setName(const QString &name)
Sets the i18n&#39;ed name of the collection.
Definition: collection.cpp:237
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setObjectName(const QString &name)
bool isEmpty() const const
Attribute * attribute(const QByteArray &name)
Returns the attribute of the given type name if available, 0 otherwise.
Definition: collection.cpp:192
QString i18ncp(const char *context, const char *singular, const char *plural, const TYPE &arg...)
bool hasAttribute(const QByteArray &name) const
Returns true if the collection has an attribute of the given type name, false otherwise.
Definition: collection.cpp:177
Helper integration between Akonadi and Qt.
CollectionStatistics statistics() const
Returns the collection statistics of the collection.
Definition: collection.cpp:343
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...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:54 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.