Messagelib

themecombobox.cpp
1/* SPDX-FileCopyrightText: 2009 James Bendig <james@imptalk.com>
2
3 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
4*/
5#include "themecombobox.h"
6
7#include "utils/themecombobox.h"
8#include "utils/themecombobox_p.h"
9
10#include "core/manager.h"
11#include "core/theme.h"
12#include "messagelistsettings.h"
13#include "storagemodel.h"
14
15using namespace MessageList::Core;
16using namespace MessageList::Utils;
17
18ThemeComboBox::ThemeComboBox(QWidget *parent)
19 : QComboBox(parent)
20 , d(new ThemeComboBoxPrivate(this))
21{
22 if (Manager::instance()) {
23 d->slotLoadThemes();
24 } else {
25 setEnabled(false);
26 }
27}
28
29ThemeComboBox::~ThemeComboBox() = default;
30
31QString ThemeComboBox::currentTheme() const
32{
33 return itemData(currentIndex()).toString();
34}
35
36void ThemeComboBox::writeDefaultConfig() const
37{
38 KConfigGroup group(MessageListSettings::self()->config(), QStringLiteral("MessageListView::StorageModelThemes"));
39
40 const QString themeID = currentTheme();
41 group.writeEntry(QStringLiteral("DefaultSet"), themeID);
42 if (Manager::instance()) {
43 Manager::instance()->themesConfigurationCompleted();
44 }
45}
46
47void ThemeComboBox::writeStorageModelConfig(MessageList::Core::StorageModel *storageModel, bool isPrivateSetting) const
48{
49 writeStorageModelConfig(storageModel->id(), isPrivateSetting);
50}
51
52void ThemeComboBox::writeStorageModelConfig(const QString &id, bool isPrivateSetting) const
53{
54 if (Manager::instance()) {
55 QString themeID;
56 if (isPrivateSetting) {
57 themeID = currentTheme();
58 } else { // explicitly use default theme id when using default theme.
59 themeID = Manager::instance()->defaultTheme()->id();
60 }
61 Manager::instance()->saveThemeForStorageModel(id, themeID, isPrivateSetting);
62 Manager::instance()->themesConfigurationCompleted();
63 }
64}
65
66void ThemeComboBox::readStorageModelConfig(const Akonadi::Collection &col, bool &isPrivateSetting)
67{
68 if (Manager::instance()) {
69 const Theme *theme = Manager::instance()->themeForStorageModel(col, &isPrivateSetting);
70 d->setCurrentTheme(theme);
71 }
72}
73
74void ThemeComboBox::readStorageModelConfig(MessageList::Core::StorageModel *storageModel, bool &isPrivateSetting)
75{
76 if (Manager::instance()) {
77 const Theme *theme = Manager::instance()->themeForStorageModel(storageModel, &isPrivateSetting);
78 d->setCurrentTheme(theme);
79 }
80}
81
82void ThemeComboBox::selectDefault()
83{
84 if (Manager::instance()) {
85 const Theme *defaultTheme = Manager::instance()->defaultTheme();
86 d->setCurrentTheme(defaultTheme);
87 }
88}
89
90void ThemeComboBox::slotLoadThemes()
91{
92 d->slotLoadThemes();
93}
94
95void ThemeComboBoxPrivate::slotLoadThemes()
96{
97 if (!Manager::instance()) {
98 return;
99 }
100 q->clear();
101
102 // Get all message list themes and sort them into alphabetical order.
103 QList<Theme *> themes = Manager::instance()->themes().values();
104 std::sort(themes.begin(), themes.end(), MessageList::Core::Theme::compareName);
105
106 for (const Theme *theme : std::as_const(themes)) {
107 q->addItem(theme->name(), QVariant(theme->id()));
108 }
109}
110
111void ThemeComboBoxPrivate::setCurrentTheme(const Theme *theme)
112{
113 Q_ASSERT(theme != nullptr);
114
115 const QString themeID = theme->id();
116 const int themeIndex = q->findData(QVariant(themeID));
117 q->setCurrentIndex(themeIndex);
118}
119
120#include "moc_themecombobox.cpp"
const QString & id() const
Returns the unique id of this OptionSet.
Definition optionset.h:51
const QString & name() const
Returns the name of this OptionSet.
Definition optionset.h:59
The QAbstractItemModel based interface that you need to provide for your storage to work with Message...
virtual QString id() const =0
Returns an unique id for this Storage collection.
The Theme class defines the visual appearance of the MessageList.
Definition theme.h:48
The implementation independent part of the MessageList library.
Definition aggregation.h:22
QVariant itemData(int index, int role) const const
iterator begin()
iterator end()
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.