File indexing completed on 2024-12-22 05:01:00
0001 /* 0002 SPDX-FileCopyrightText: 2009-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "collectionviewpage.h" 0008 #include <MailCommon/MailKernel> 0009 0010 #include <Akonadi/EntityDisplayAttribute> 0011 #include <Akonadi/MessageFolderAttribute> 0012 0013 #include <KIconButton> 0014 #include <KLocalizedString> 0015 #include <QCheckBox> 0016 #include <QFormLayout> 0017 #include <QHBoxLayout> 0018 #include <QLabel> 0019 #include <QVBoxLayout> 0020 0021 #include <MessageList/AggregationComboBox> 0022 #include <MessageList/AggregationConfigButton> 0023 #include <MessageList/ThemeComboBox> 0024 #include <MessageList/ThemeConfigButton> 0025 0026 #include <MailCommon/CollectionViewWidget> 0027 0028 using namespace MailCommon; 0029 0030 CollectionViewPage::CollectionViewPage(QWidget *parent) 0031 : CollectionPropertiesPage(parent) 0032 { 0033 setObjectName(QLatin1StringView("KMail::CollectionViewPage")); 0034 setPageTitle(i18nc("@title:tab View settings for a folder.", "View")); 0035 } 0036 0037 CollectionViewPage::~CollectionViewPage() = default; 0038 0039 void CollectionViewPage::init(const Akonadi::Collection &col) 0040 { 0041 mFolderCollection = FolderSettings::forCollection(col); 0042 mIsLocalSystemFolder = CommonKernel->isSystemFolderCollection(col) || mFolderCollection->isStructural() || Kernel::folderIsInbox(col); 0043 0044 auto topLayout = new QVBoxLayout(this); 0045 0046 mCollectionViewWidget = new MailCommon::CollectionViewWidget(this); 0047 topLayout->addWidget(mCollectionViewWidget); 0048 0049 // Musn't be able to edit details for non-resource, system folder. 0050 if (!mIsLocalSystemFolder) { 0051 auto innerLayout = qobject_cast<QFormLayout *>(mCollectionViewWidget->layout()); 0052 Q_ASSERT(innerLayout != nullptr); 0053 0054 // icons 0055 mIconsCheckBox = new QCheckBox(i18n("Use custom &icons"), this); 0056 mIconsCheckBox->setChecked(false); 0057 innerLayout->insertRow(0, QString(), mIconsCheckBox); 0058 0059 mNormalIconLabel = new QLabel(i18nc("Icon used for folders with no unread messages.", "&Normal:"), this); 0060 mNormalIconLabel->setEnabled(false); 0061 0062 mNormalIconButton = new KIconButton(this); 0063 mNormalIconLabel->setBuddy(mNormalIconButton); 0064 mNormalIconButton->setIconType(KIconLoader::NoGroup, KIconLoader::Place, false); 0065 mNormalIconButton->setIconSize(16); 0066 mNormalIconButton->setFixedSize(28, 28); 0067 // Can't use iconset here. 0068 mNormalIconButton->setIcon(QStringLiteral("folder")); 0069 mNormalIconButton->setEnabled(false); 0070 0071 mUnreadIconLabel = new QLabel(i18nc("Icon used for folders which do have unread messages.", "&Unread:"), this); 0072 mUnreadIconLabel->setEnabled(false); 0073 0074 mUnreadIconButton = new KIconButton(this); 0075 mUnreadIconLabel->setBuddy(mUnreadIconButton); 0076 mUnreadIconButton->setIconType(KIconLoader::NoGroup, KIconLoader::Place, false); 0077 mUnreadIconButton->setIconSize(16); 0078 mUnreadIconButton->setFixedSize(28, 28); 0079 // Can't use iconset here. 0080 mUnreadIconButton->setIcon(QStringLiteral("folder-open")); 0081 mUnreadIconButton->setEnabled(false); 0082 0083 auto iconHLayout = new QHBoxLayout(); 0084 iconHLayout->addWidget(mNormalIconLabel); 0085 iconHLayout->addWidget(mNormalIconButton); 0086 iconHLayout->addWidget(mUnreadIconLabel); 0087 iconHLayout->addWidget(mUnreadIconButton); 0088 iconHLayout->addStretch(1); 0089 innerLayout->insertRow(1, QString(), iconHLayout); 0090 0091 connect(mIconsCheckBox, &QCheckBox::toggled, mNormalIconLabel, &QLabel::setEnabled); 0092 connect(mIconsCheckBox, &QCheckBox::toggled, mNormalIconButton, &KIconButton::setEnabled); 0093 connect(mIconsCheckBox, &QCheckBox::toggled, mUnreadIconButton, &KIconButton::setEnabled); 0094 connect(mIconsCheckBox, &QCheckBox::toggled, mUnreadIconLabel, &QLabel::setEnabled); 0095 0096 connect(mNormalIconButton, &KIconButton::iconChanged, this, &CollectionViewPage::slotChangeIcon); 0097 } 0098 0099 topLayout->addStretch(100); 0100 } 0101 0102 void CollectionViewPage::slotChangeIcon(const QString &icon) 0103 { 0104 mUnreadIconButton->setIcon(icon); 0105 } 0106 0107 void CollectionViewPage::load(const Akonadi::Collection &col) 0108 { 0109 init(col); 0110 if (!mIsLocalSystemFolder) { 0111 QString iconName; 0112 QString unreadIconName; 0113 bool iconWasEmpty = false; 0114 if (col.hasAttribute<Akonadi::EntityDisplayAttribute>()) { 0115 iconName = col.attribute<Akonadi::EntityDisplayAttribute>()->iconName(); 0116 unreadIconName = col.attribute<Akonadi::EntityDisplayAttribute>()->activeIconName(); 0117 } 0118 0119 if (iconName.isEmpty()) { 0120 iconName = QStringLiteral("folder"); 0121 iconWasEmpty = true; 0122 } 0123 mNormalIconButton->setIcon(iconName); 0124 0125 if (unreadIconName.isEmpty()) { 0126 mUnreadIconButton->setIcon(iconName); 0127 } else { 0128 mUnreadIconButton->setIcon(unreadIconName); 0129 } 0130 0131 mIconsCheckBox->setChecked(!iconWasEmpty); 0132 } 0133 mCollectionViewWidget->load(col); 0134 } 0135 0136 void CollectionViewPage::save(Akonadi::Collection &col) 0137 { 0138 if (!mIsLocalSystemFolder) { 0139 if (mIconsCheckBox->isChecked()) { 0140 col.attribute<Akonadi::EntityDisplayAttribute>(Akonadi::Collection::AddIfMissing)->setIconName(mNormalIconButton->icon()); 0141 col.attribute<Akonadi::EntityDisplayAttribute>(Akonadi::Collection::AddIfMissing)->setActiveIconName(mUnreadIconButton->icon()); 0142 } else if (col.hasAttribute<Akonadi::EntityDisplayAttribute>()) { 0143 col.attribute<Akonadi::EntityDisplayAttribute>()->setIconName(QString()); 0144 col.attribute<Akonadi::EntityDisplayAttribute>()->setActiveIconName(QString()); 0145 } 0146 } 0147 mCollectionViewWidget->save(col); 0148 } 0149 0150 #include "moc_collectionviewpage.cpp"