5#include "themecombobox.h"
7#include "utils/themecombobox.h"
8#include "utils/themecombobox_p.h"
10#include "core/manager.h"
11#include "core/theme.h"
12#include "messagelistsettings.h"
13#include "storagemodel.h"
16using namespace MessageList::Utils;
18ThemeComboBox::ThemeComboBox(
QWidget *parent)
20 , d(new ThemeComboBoxPrivate(this))
22 if (Manager::instance()) {
29ThemeComboBox::~ThemeComboBox() =
default;
31QString ThemeComboBox::currentTheme()
const
36void ThemeComboBox::writeDefaultConfig()
const
38 KConfigGroup group(MessageListSettings::self()->config(), QStringLiteral(
"MessageListView::StorageModelThemes"));
40 const QString themeID = currentTheme();
41 group.writeEntry(QStringLiteral(
"DefaultSet"), themeID);
42 if (Manager::instance()) {
43 Manager::instance()->themesConfigurationCompleted();
47void ThemeComboBox::writeStorageModelConfig(MessageList::Core::StorageModel *storageModel,
bool isPrivateSetting)
const
49 writeStorageModelConfig(storageModel->
id(), isPrivateSetting);
52void ThemeComboBox::writeStorageModelConfig(
const QString &
id,
bool isPrivateSetting)
const
54 if (Manager::instance()) {
56 if (isPrivateSetting) {
57 themeID = currentTheme();
59 themeID = Manager::instance()->defaultTheme()->id();
61 Manager::instance()->saveThemeForStorageModel(
id, themeID, isPrivateSetting);
62 Manager::instance()->themesConfigurationCompleted();
66void ThemeComboBox::readStorageModelConfig(
const Akonadi::Collection &col,
bool &isPrivateSetting)
68 if (Manager::instance()) {
69 const Theme *theme = Manager::instance()->themeForStorageModel(col, &isPrivateSetting);
70 d->setCurrentTheme(theme);
74void ThemeComboBox::readStorageModelConfig(MessageList::Core::StorageModel *storageModel,
bool &isPrivateSetting)
76 if (Manager::instance()) {
77 const Theme *theme = Manager::instance()->themeForStorageModel(storageModel, &isPrivateSetting);
78 d->setCurrentTheme(theme);
82void ThemeComboBox::selectDefault()
84 if (Manager::instance()) {
85 const Theme *defaultTheme = Manager::instance()->defaultTheme();
86 d->setCurrentTheme(defaultTheme);
90void ThemeComboBox::slotLoadThemes()
95void ThemeComboBoxPrivate::slotLoadThemes()
97 if (!Manager::instance()) {
103 QList<Theme *> themes = Manager::instance()->themes().values();
104 std::sort(themes.
begin(), themes.
end(), MessageList::Core::Theme::compareName);
106 for (
const Theme *theme : std::as_const(themes)) {
107 q->addItem(theme->
name(), QVariant(theme->
id()));
111void ThemeComboBoxPrivate::setCurrentTheme(
const Theme *theme)
113 Q_ASSERT(theme !=
nullptr);
115 const QString themeID = theme->
id();
116 const int themeIndex = q->findData(QVariant(themeID));
117 q->setCurrentIndex(themeIndex);
120#include "moc_themecombobox.cpp"
const QString & id() const
Returns the unique id of this OptionSet.
const QString & name() const
Returns the name of this OptionSet.
virtual QString id() const =0
Returns an unique id for this Storage collection.
The implementation independent part of the MessageList library.
QVariant itemData(int index, int role) const const
QString toString() const const