Remove grantlee_strings_extractor.pyc
[kdepim.git] / accountwizard / configfile.cpp
blobf34967018ad5780812411df5adf8cc452f0a0f27
1 /*
2 Copyright (c) 2010 Laurent Montel <montel@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
20 #include "configfile.h"
22 #include <KCMultiDialog>
23 #include <KConfig>
24 #include <KConfigGroup>
25 #include <KLocalizedString>
26 #include <KStringHandler>
28 ConfigFile::ConfigFile(const QString &configName, QObject *parent)
29 : SetupObject(parent)
30 , m_editMode(false)
32 m_name = configName;
33 m_config = new KConfig(configName);
36 ConfigFile::~ConfigFile()
38 delete m_config;
41 void ConfigFile::write()
43 create();
46 void ConfigFile::create()
48 Q_EMIT info(i18n("Writing config file for %1...", m_name));
50 foreach (const Config &c, m_configData) {
51 KConfigGroup grp = m_config->group(c.group);
52 if (c.obscure) {
53 grp.writeEntry(c.key, KStringHandler::obscure(c.value));
54 } else {
55 grp.writeEntry(c.key, c.value);
59 m_config->sync();
61 if (m_editMode) {
62 edit();
65 Q_EMIT finished(i18n("Config file for %1 is writing.", m_name));
68 void ConfigFile::destroy()
70 Q_EMIT info(i18n("Config file for %1 was not changed.", m_name));
73 void ConfigFile::setName(const QString &name)
75 m_name = name;
78 void ConfigFile::setConfig(const QString &group, const QString &key, const QString &value)
80 Config conf;
81 conf.group = group;
82 conf.key = key;
83 conf.value = value;
84 conf.obscure = false;
85 m_configData.append(conf);
88 void ConfigFile::setPassword(const QString &group, const QString &key, const QString &value)
90 Config conf;
91 conf.group = group;
92 conf.key = key;
93 conf.value = value;
94 conf.obscure = true;
95 m_configData.append(conf);
98 void ConfigFile::edit()
100 if (m_editName.isEmpty()) {
101 Q_EMIT error(i18n("No given name for the configuration."));
102 return;
105 if (m_editName == QLatin1String("freebusy")) {
106 KCMultiDialog *dialog = new KCMultiDialog();
107 dialog->addModule(QStringLiteral("korganizer_configfreebusy.desktop"));
108 dialog->show();
109 return;
112 Q_EMIT error(i18n("Unknown configuration name '%1'", m_editName));
115 void ConfigFile::setEditName(const QString &name)
117 m_editName = name;
120 void ConfigFile::setEditMode(const bool editMode)
122 m_editMode = editMode;