KConfig

kemailsettings.cpp
1 /*
2  SPDX-FileCopyrightText: 2000 Alex Zepeda <[email protected]>
3 
4  SPDX-License-Identifier: BSD-2-Clause
5 */
6 
7 #include "kemailsettings.h"
8 
9 #include <kconfig.h>
10 #include <kconfiggroup.h>
11 
12 class KEMailSettingsPrivate
13 {
14 public:
15  KEMailSettingsPrivate() : m_pConfig(nullptr) {}
16  ~KEMailSettingsPrivate()
17  {
18  delete m_pConfig;
19  }
20  KConfig *m_pConfig;
21  QStringList profiles;
22  QString m_sDefaultProfile, m_sCurrentProfile;
23 };
24 
26 {
27  return p->m_sDefaultProfile;
28 }
29 
31 {
32  KConfigGroup cg(p->m_pConfig, QLatin1String("PROFILE_") + p->m_sCurrentProfile);
33  switch (s) {
34  case ClientProgram: {
35  return cg.readEntry("EmailClient");
36  }
37  case ClientTerminal: {
38  return cg.readEntry("TerminalClient", QVariant(false)).toString();
39  }
40  case RealName: {
41  return cg.readEntry("FullName");
42  }
43  case EmailAddress: {
44  return cg.readEntry("EmailAddress");
45  }
46  case ReplyToAddress: {
47  return cg.readEntry("ReplyAddr");
48  }
49  case Organization: {
50  return cg.readEntry("Organization");
51  }
52  case OutServer: {
53  return cg.readEntry("OutgoingServer");
54  }
55  case OutServerLogin: {
56  return cg.readEntry("OutgoingUserName");
57  }
58  case OutServerPass: {
59  return cg.readEntry("OutgoingPassword");
60  }
61 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
62  case OutServerType: {
63  return cg.readEntry("OutgoingServerType");
64  }
65  case OutServerCommand: {
66  return cg.readEntry("OutgoingCommand");
67  }
68  case OutServerTLS: {
69  return cg.readEntry("OutgoingServerTLS", QVariant(false)).toString();
70  }
71 #else
72  case OutServerType_DEPRECATED_DO_NOT_USE:
73  case OutServerCommand_DEPRECATED_DO_NOT_USE:
74  case OutServerTLS_DEPRECATED_DO_NOT_USE:
75  break;
76 #endif
77  case InServer: {
78  return cg.readEntry("IncomingServer");
79  }
80  case InServerLogin: {
81  return cg.readEntry("IncomingUserName");
82  }
83  case InServerPass: {
84  return cg.readEntry("IncomingPassword");
85  }
86 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
87  case InServerType: {
88  return cg.readEntry("IncomingServerType");
89  }
90  case InServerMBXType: {
91  return cg.readEntry("IncomingServerMBXType");
92  }
93  case InServerTLS: {
94  return cg.readEntry("IncomingServerTLS", QVariant(false)).toString();
95  }
96 #endif
97  };
98  return QString();
99 }
101 {
102  KConfigGroup cg(p->m_pConfig, QLatin1String("PROFILE_") + p->m_sCurrentProfile);
103  switch (s) {
104  case ClientProgram: {
105  cg.writePathEntry("EmailClient", v);
106  break;
107  }
108  case ClientTerminal: {
109  cg.writeEntry("TerminalClient", (v == QLatin1String("true")));
110  break;
111  }
112  case RealName: {
113  cg.writeEntry("FullName", v);
114  break;
115  }
116  case EmailAddress: {
117  cg.writeEntry("EmailAddress", v);
118  break;
119  }
120  case ReplyToAddress: {
121  cg.writeEntry("ReplyAddr", v);
122  break;
123  }
124  case Organization: {
125  cg.writeEntry("Organization", v);
126  break;
127  }
128  case OutServer: {
129  cg.writeEntry("OutgoingServer", v);
130  break;
131  }
132  case OutServerLogin: {
133  cg.writeEntry("OutgoingUserName", v);
134  break;
135  }
136  case OutServerPass: {
137  cg.writeEntry("OutgoingPassword", v);
138  break;
139  }
140 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
141  case OutServerType: {
142  cg.writeEntry("OutgoingServerType", v);
143  break;
144  }
145  case OutServerCommand: {
146  cg.writeEntry("OutgoingCommand", v);
147  break;
148  }
149  case OutServerTLS: {
150  cg.writeEntry("OutgoingServerTLS", (v == QLatin1String("true")));
151  break;
152  }
153 #else
154  case OutServerType_DEPRECATED_DO_NOT_USE:
155  case OutServerCommand_DEPRECATED_DO_NOT_USE:
156  case OutServerTLS_DEPRECATED_DO_NOT_USE:
157  break;
158 #endif
159  case InServer: {
160  cg.writeEntry("IncomingServer", v);
161  break;
162  }
163  case InServerLogin: {
164  cg.writeEntry("IncomingUserName", v);
165  break;
166  }
167  case InServerPass: {
168  cg.writeEntry("IncomingPassword", v);
169  break;
170  }
171 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
172  case InServerType: {
173  cg.writeEntry("IncomingServerType", v);
174  break;
175  }
176  case InServerMBXType: {
177  cg.writeEntry("IncomingServerMBXType", v);
178  break;
179  }
180  case InServerTLS: {
181  cg.writeEntry("IncomingServerTLS", (v == QLatin1String("true")));
182  break;
183  }
184 #endif
185  };
186  cg.sync();
187 }
188 
190 {
191  p->m_pConfig->group("Defaults").writeEntry("Profile", s);
192  p->m_pConfig->sync();
193  p->m_sDefaultProfile = s;
194 
195 }
196 
198 {
199  const QString groupname = QLatin1String("PROFILE_") + s;
200  p->m_sCurrentProfile = s;
201  if (!p->m_pConfig->hasGroup(groupname)) { // Create a group if it doesn't exist
202  KConfigGroup cg(p->m_pConfig, groupname);
203  cg.writeEntry("ServerType", QString());
204  p->profiles += s;
205  }
206 }
207 
208 #if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 0)
210 {
211  return p->m_sCurrentProfile;
212 }
213 #endif
214 
216 {
217  return p->profiles;
218 }
219 
221  : p(new KEMailSettingsPrivate())
222 {
223  p->m_sCurrentProfile.clear();
224 
225  p->m_pConfig = new KConfig(QStringLiteral("emaildefaults"));
226 
227  const QStringList groups = p->m_pConfig->groupList();
228  for (QStringList::ConstIterator it = groups.begin(); it != groups.end(); ++it) {
229  if ((*it).startsWith(QLatin1String("PROFILE_"))) {
230  p->profiles += (*it).mid(8, (*it).length());
231  }
232  }
233 
234  KConfigGroup cg(p->m_pConfig, "Defaults");
235  p->m_sDefaultProfile = cg.readEntry("Profile", tr("Default"));
236  if (!p->m_sDefaultProfile.isNull()) {
237  if (!p->m_pConfig->hasGroup(QLatin1String("PROFILE_") + p->m_sDefaultProfile)) {
238  setDefault(tr("Default"));
239  } else {
240  setDefault(p->m_sDefaultProfile);
241  }
242  } else {
243  if (!p->profiles.isEmpty()) {
244  setDefault(p->profiles[0]);
245  } else {
246  setDefault(tr("Default"));
247  }
248  }
250 }
251 
253 {
254  delete p;
255 }
~KEMailSettings()
Default destructor, nothing to see here.
bool sync() override
void writePathEntry(const QString &pKey, const QString &path, WriteConfigFlags pFlags=Normal)
Writes a file path to the configuration.
QStringList profiles() const
List of profiles available.
Organization
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
void setSetting(KEMailSettings::Setting s, const QString &v)
Set one of the predefined "basic" settings.
Setting
The list of settings that I thought of when I wrote this class.
QString defaultProfileName() const
Returns the name of the default profile.
void setProfile(const QString &s)
Change the current profile.
QList::iterator end()
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:38
The central class of the KDE configuration data system.
Definition: kconfig.h:56
void setDefault(const QString &def)
Sets a new default.
KEMailSettings()
Default constructor, just sets things up and sets the default profile as the current profile...
typedef ConstIterator
QString currentProfileName() const
Returns the name of the current profile.
QString getSetting(KEMailSettings::Setting s) const
Get one of the predefined "basic" settings.
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:250
QList::iterator begin()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Nov 27 2020 22:49:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.