KConfig

kemailsettings.cpp
1/*
2 SPDX-FileCopyrightText: 2000 Alex Zepeda <zipzippy@sonic.net>
3
4 SPDX-License-Identifier: BSD-2-Clause
5*/
6
7#include "kemailsettings.h"
8
9#include <kconfig.h>
10#include <kconfiggroup.h>
11
12class KEMailSettingsPrivate
13{
14public:
15 KEMailSettingsPrivate()
16 : m_pConfig(nullptr)
17 {
18 }
19 ~KEMailSettingsPrivate()
20 {
21 delete m_pConfig;
22 }
23 KConfig *m_pConfig;
24 QStringList profiles;
25 QString m_sDefaultProfile, m_sCurrentProfile;
26};
27
29{
30 return p->m_sDefaultProfile;
31}
32
34{
35 KConfigGroup cg(p->m_pConfig, QLatin1String("PROFILE_") + p->m_sCurrentProfile);
36 switch (s) {
37 case ClientProgram: {
38 return cg.readEntry("EmailClient");
39 }
40 case ClientTerminal: {
41 return cg.readEntry("TerminalClient", QVariant(false)).toString();
42 }
43 case RealName: {
44 return cg.readEntry("FullName");
45 }
46 case EmailAddress: {
47 return cg.readEntry("EmailAddress");
48 }
49 case ReplyToAddress: {
50 return cg.readEntry("ReplyAddr");
51 }
52 case Organization: {
53 return cg.readEntry("Organization");
54 }
55 };
56 return QString();
57}
59{
60 KConfigGroup cg(p->m_pConfig, QLatin1String("PROFILE_") + p->m_sCurrentProfile);
61 switch (s) {
62 case ClientProgram: {
63 cg.writePathEntry("EmailClient", v);
64 break;
65 }
66 case ClientTerminal: {
67 cg.writeEntry("TerminalClient", (v == QLatin1String("true")));
68 break;
69 }
70 case RealName: {
71 cg.writeEntry("FullName", v);
72 break;
73 }
74 case EmailAddress: {
75 cg.writeEntry("EmailAddress", v);
76 break;
77 }
78 case ReplyToAddress: {
79 cg.writeEntry("ReplyAddr", v);
80 break;
81 }
82 case Organization: {
83 cg.writeEntry("Organization", v);
84 break;
85 }
86 };
87 cg.sync();
88}
89
91{
92 p->m_pConfig->group(QStringLiteral("Defaults")).writeEntry("Profile", s);
93 p->m_pConfig->sync();
94 p->m_sDefaultProfile = s;
95}
96
98{
99 const QString groupname = QLatin1String("PROFILE_") + s;
100 p->m_sCurrentProfile = s;
101 if (!p->m_pConfig->hasGroup(groupname)) { // Create a group if it doesn't exist
102 KConfigGroup cg(p->m_pConfig, groupname);
103 cg.writeEntry("ServerType", QString());
104 p->profiles += s;
105 }
106}
107
109{
110 return p->profiles;
111}
112
114 : p(new KEMailSettingsPrivate())
115{
116 p->m_sCurrentProfile.clear();
117
118 p->m_pConfig = new KConfig(QStringLiteral("emaildefaults"));
119
120 const QStringList groups = p->m_pConfig->groupList();
121 for (const auto &grp : groups) {
122 if (grp.startsWith(QLatin1String("PROFILE_"))) {
123 p->profiles += grp.mid(8 /* length of "PROFILE_" */);
124 }
125 }
126
127 KConfigGroup cg(p->m_pConfig, QStringLiteral("Defaults"));
128 p->m_sDefaultProfile = cg.readEntry("Profile", tr("Default"));
129 if (!p->m_sDefaultProfile.isNull()) {
130 if (!p->m_pConfig->hasGroup(QLatin1String("PROFILE_") + p->m_sDefaultProfile)) {
131 setDefault(tr("Default"));
132 } else {
133 setDefault(p->m_sDefaultProfile);
134 }
135 } else {
136 if (!p->profiles.isEmpty()) {
137 setDefault(p->profiles[0]);
138 } else {
139 setDefault(tr("Default"));
140 }
141 }
143}
144
146{
147 delete p;
148}
bool hasGroup(const QString &group) const
Returns true if the specified group is known about.
KConfigGroup group(const QString &group)
Returns an object for the named subgroup.
A class for one specific group in a KConfig object.
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
Writes a file path to the configuration.
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
bool sync() override
The central class of the KDE configuration data system.
Definition kconfig.h:56
bool sync() override
Definition kconfig.cpp:407
QStringList groupList() const override
Definition kconfig.cpp:300
QString getSetting(KEMailSettings::Setting s) const
Get one of the predefined "basic" settings.
void setProfile(const QString &s)
Change the current profile.
void setSetting(KEMailSettings::Setting s, const QString &v)
Set one of the predefined "basic" settings.
QString defaultProfileName() const
Returns the name of the default profile.
KEMailSettings()
Default constructor, just sets things up and sets the default profile as the current profile.
QStringList profiles() const
List of profiles available.
~KEMailSettings()
Default destructor, nothing to see here.
Setting
The list of settings that I thought of when I wrote this class.
void setDefault(const QString &def)
Sets a new default.
bool isEmpty() const const
QList< T > mid(qsizetype pos, qsizetype length) const const
void clear()
bool isNull() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:17:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.