File indexing completed on 2025-01-19 04:46:52
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "folderconfiguresettingswidget.h" 0008 #include "folderconfiguresettingspagewidget.h" 0009 #include "folderconfiguretreewidget.h" 0010 #include <KConfigGroup> 0011 #include <KSharedConfig> 0012 #include <QHBoxLayout> 0013 #include <QSplitter> 0014 namespace 0015 { 0016 static const char myFolderConfigureSettingsWidgetGroupName[] = "FolderConfigureSettingsWidget"; 0017 } 0018 FolderConfigureSettingsWidget::FolderConfigureSettingsWidget(QWidget *parent) 0019 : QWidget(parent) 0020 , mFolderConfigureTreeWidget(new FolderConfigureTreeWidget(this)) 0021 , mFolderConfigureSettingsPageWidget(new FolderConfigureSettingsPageWidget(this)) 0022 , mSplitter(new QSplitter(this)) 0023 { 0024 auto mainLayout = new QHBoxLayout(this); 0025 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0026 mainLayout->setContentsMargins({}); 0027 0028 // TODO add label ? 0029 0030 mSplitter->setObjectName(QLatin1StringView("splitter")); 0031 mSplitter->setChildrenCollapsible(false); 0032 mainLayout->addWidget(mSplitter); 0033 0034 mFolderConfigureTreeWidget->setObjectName(QLatin1StringView("mFolderConfigureTreeWidget")); 0035 mSplitter->addWidget(mFolderConfigureTreeWidget); 0036 0037 mFolderConfigureSettingsPageWidget->setObjectName(QLatin1StringView("mFolderConfigureSettingsPageWidget")); 0038 mSplitter->addWidget(mFolderConfigureSettingsPageWidget); 0039 readConfig(); 0040 } 0041 0042 FolderConfigureSettingsWidget::~FolderConfigureSettingsWidget() 0043 { 0044 saveConfig(); 0045 } 0046 0047 void FolderConfigureSettingsWidget::save() 0048 { 0049 const Akonadi::Collection::List collections = mFolderConfigureTreeWidget->listCollections(); 0050 mFolderConfigureSettingsPageWidget->save(collections); 0051 } 0052 0053 void FolderConfigureSettingsWidget::readConfig() 0054 { 0055 KConfigGroup grp(KSharedConfig::openStateConfig(), QLatin1StringView(myFolderConfigureSettingsWidgetGroupName)); 0056 const QList<int> defaultSizes{200, 400}; 0057 const QList<int> sizes = grp.readEntry("SplitterSize", defaultSizes); 0058 mSplitter->setSizes(sizes); 0059 } 0060 0061 void FolderConfigureSettingsWidget::saveConfig() 0062 { 0063 const QList<int> sizes = mSplitter->sizes(); 0064 KConfigGroup grp(KSharedConfig::openStateConfig(), QLatin1StringView(myFolderConfigureSettingsWidgetGroupName)); 0065 grp.writeEntry("SplitterSize", sizes); 0066 } 0067 0068 #include "moc_folderconfiguresettingswidget.cpp"