File indexing completed on 2025-01-05 04:47:07
0001 /* 0002 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "collectiongeneralpropertiespage_p.h" 0008 0009 #include "collection.h" 0010 #include "collectionstatistics.h" 0011 #include "collectionutils.h" 0012 #include "entitydisplayattribute.h" 0013 0014 #include <KLocalizedString> 0015 0016 #include <KIO/Global> 0017 0018 using namespace Akonadi; 0019 0020 /// @cond PRIVATE 0021 0022 CollectionGeneralPropertiesPage::CollectionGeneralPropertiesPage(QWidget *parent) 0023 : CollectionPropertiesPage(parent) 0024 { 0025 setObjectName(QLatin1StringView("Akonadi::CollectionGeneralPropertiesPage")); 0026 0027 setPageTitle(i18nc("@title:tab general properties page", "General")); 0028 ui.setupUi(this); 0029 } 0030 0031 void CollectionGeneralPropertiesPage::load(const Collection &collection) 0032 { 0033 QString displayName; 0034 QString iconName; 0035 if (collection.hasAttribute<EntityDisplayAttribute>()) { 0036 displayName = collection.attribute<EntityDisplayAttribute>()->displayName(); 0037 iconName = collection.attribute<EntityDisplayAttribute>()->iconName(); 0038 } 0039 0040 if (displayName.isEmpty()) { 0041 ui.nameEdit->setText(collection.name()); 0042 } else { 0043 ui.nameEdit->setText(displayName); 0044 } 0045 0046 if (iconName.isEmpty()) { 0047 ui.customIcon->setIcon(CollectionUtils::defaultIconName(collection)); 0048 } else { 0049 ui.customIcon->setIcon(iconName); 0050 } 0051 ui.customIconCheckbox->setChecked(!iconName.isEmpty()); 0052 0053 if (collection.statistics().count() >= 0) { 0054 ui.countLabel->setText(i18ncp("@label", "One object", "%1 objects", collection.statistics().count())); 0055 ui.sizeLabel->setText(KIO::convertSize(collection.statistics().size())); 0056 } else { 0057 ui.statsBox->hide(); 0058 } 0059 } 0060 0061 void CollectionGeneralPropertiesPage::save(Collection &collection) 0062 { 0063 if (collection.hasAttribute<EntityDisplayAttribute>() && !collection.attribute<EntityDisplayAttribute>()->displayName().isEmpty()) { 0064 collection.attribute<EntityDisplayAttribute>()->setDisplayName(ui.nameEdit->text()); 0065 } else { 0066 collection.setName(ui.nameEdit->text()); 0067 } 0068 0069 if (ui.customIconCheckbox->isChecked()) { 0070 collection.attribute<EntityDisplayAttribute>(Collection::AddIfMissing)->setIconName(ui.customIcon->icon()); 0071 } else if (collection.hasAttribute<EntityDisplayAttribute>()) { 0072 collection.attribute<EntityDisplayAttribute>()->setIconName(QString()); 0073 } 0074 } 0075 0076 /// @endcond 0077 0078 #include "moc_collectiongeneralpropertiespage_p.cpp"