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 "collectiongeneralpropertiespage_p.h"
21
22#include "collection.h"
23#include "entitydisplayattribute.h"
24#include "collectionstatistics.h"
25#include "collectionutils_p.h"
26
27#include <klocale.h>
28#include <klocalizedstring.h>
29#include <kglobal.h>
30
31using namespace Akonadi;
32
33//@cond PRIVATE
34
35CollectionGeneralPropertiesPage::CollectionGeneralPropertiesPage(QWidget *parent)
36 : CollectionPropertiesPage(parent)
37{
38 setObjectName(QLatin1String("Akonadi::CollectionGeneralPropertiesPage"));
39
40 setPageTitle(i18nc("@title:tab general properties page", "General"));
41 ui.setupUi(this);
42}
43
44void 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#ifndef KDEPIM_MOBILE_UI
60 if (iconName.isEmpty()) {
61 ui.customIcon->setIcon(CollectionUtils::defaultIconName(collection));
62 } else {
63 ui.customIcon->setIcon(iconName);
64 }
65 ui.customIconCheckbox->setChecked(!iconName.isEmpty());
66#endif
67
68 if (collection.statistics().count() >= 0) {
69 ui.countLabel->setText(i18ncp("@label", "One object", "%1 objects",
70 collection.statistics().count()));
71 ui.sizeLabel->setText(KGlobal::locale()->formatByteSize(collection.statistics().size()));
72 } else {
73 ui.statsBox->hide();
74 }
75}
76
77void CollectionGeneralPropertiesPage::save(Collection &collection)
78{
79 if (collection.hasAttribute<EntityDisplayAttribute>() &&
80 !collection.attribute<EntityDisplayAttribute>()->displayName().isEmpty()) {
81 collection.attribute<EntityDisplayAttribute>()->setDisplayName(ui.nameEdit->text());
82 } else {
83 collection.setName(ui.nameEdit->text());
84 }
85
86#ifndef KDEPIM_MOBILE_UI
87 if (ui.customIconCheckbox->isChecked()) {
88 collection.attribute<EntityDisplayAttribute>(Collection::AddIfMissing)->setIconName(ui.customIcon->icon());
89 } else if (collection.hasAttribute<EntityDisplayAttribute>()) {
90 collection.attribute<EntityDisplayAttribute>()->setIconName(QString());
91 }
92#endif
93}
94
95//@endcond
96
97#include "moc_collectiongeneralpropertiespage_p.cpp"
98