File indexing completed on 2024-12-22 05:01:00
0001 /* 0002 This file is part of KMail, the KDE mail client. 0003 SPDX-FileCopyrightText: 2004 Till Adam <adam@kde.org> 0004 SPDX-FileCopyrightText: 2013 Jonathan Marten <jjm@keelhaul.me.uk> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 #include "collectionshortcutpage.h" 0010 #include "foldershortcutactionmanager.h" 0011 #include "kmkernel.h" 0012 #include "kmmainwidget.h" 0013 0014 #include <QLabel> 0015 #include <QSpacerItem> 0016 #include <QVBoxLayout> 0017 0018 #include <KKeySequenceWidget> 0019 #include <KLocalizedString> 0020 #include <QHBoxLayout> 0021 0022 using namespace MailCommon; 0023 0024 CollectionShortcutPage::CollectionShortcutPage(QWidget *parent) 0025 : CollectionPropertiesPage(parent) 0026 , mKeySeqWidget(new KKeySequenceWidget(this)) 0027 { 0028 setObjectName(QLatin1StringView("KMail::CollectionShortcutPage")); 0029 setPageTitle(i18nc("@title:tab Shortcut settings for a folder.", "Shortcut")); 0030 } 0031 0032 CollectionShortcutPage::~CollectionShortcutPage() = default; 0033 0034 void CollectionShortcutPage::init(const Akonadi::Collection &col) 0035 { 0036 mCurrentCollection = col; 0037 mFolder = FolderSettings::forCollection(col, false); 0038 0039 auto topLayout = new QVBoxLayout(this); 0040 0041 auto label = new QLabel(i18n("<qt>To choose a key or a combination " 0042 "of keys which select the current folder, " 0043 "click the button below and then press the key(s) " 0044 "you wish to associate with this folder.</qt>"), 0045 this); 0046 label->setWordWrap(true); 0047 topLayout->addWidget(label); 0048 0049 auto hbHBoxLayout = new QHBoxLayout; 0050 0051 hbHBoxLayout->addWidget(mKeySeqWidget); 0052 mKeySeqWidget->setObjectName(QLatin1StringView("FolderShortcutSelector")); 0053 connect(mKeySeqWidget, &KKeySequenceWidget::keySequenceChanged, this, &CollectionShortcutPage::slotShortcutChanged); 0054 0055 topLayout->addItem(new QSpacerItem(0, 10)); 0056 topLayout->addLayout(hbHBoxLayout); 0057 topLayout->addStretch(1); 0058 0059 mKeySeqWidget->setCheckActionCollections(KMKernel::self()->getKMMainWidget()->actionCollections()); 0060 } 0061 0062 void CollectionShortcutPage::load(const Akonadi::Collection &col) 0063 { 0064 init(col); 0065 if (mFolder) { 0066 mKeySeqWidget->setKeySequence(mFolder->shortcut(), KKeySequenceWidget::NoValidate); 0067 mShortcutChanged = false; 0068 } 0069 } 0070 0071 void CollectionShortcutPage::save(Akonadi::Collection & /*col*/) 0072 { 0073 if (mFolder) { 0074 if (mShortcutChanged) { 0075 mKeySeqWidget->applyStealShortcut(); 0076 mFolder->setShortcut(mKeySeqWidget->keySequence()); 0077 KMKernel::self()->getKMMainWidget()->folderShortcutActionManager()->shortcutChanged(mCurrentCollection); 0078 } 0079 } 0080 } 0081 0082 void CollectionShortcutPage::slotShortcutChanged() 0083 { 0084 mShortcutChanged = true; 0085 } 0086 0087 #include "moc_collectionshortcutpage.cpp"