Commit 8cf948c5 authored by Rafał Malinowski's avatar Rafał Malinowski

configuration: remove unused class PlainConfigFile

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent d3426c77
......@@ -45,181 +45,6 @@
static QMutex GlobalMutex;
PlainConfigFile::PlainConfigFile(const QString &filename, const QString &codec) : filename(filename), CodecName(codec), groups(), activeGroupName()
{
read();
}
PlainConfigFile::PlainConfigFile(const PlainConfigFile &c) : filename(c.filename), groups(c.groups), activeGroupName()
{
}
PlainConfigFile &PlainConfigFile::operator=(const PlainConfigFile &c)
{
filename = c.filename;
groups = c.groups;
activeGroupName.clear();;
return *this;
}
void PlainConfigFile::changeActiveGroup(const QString& newGroup)
{
if (!activeGroupName.isEmpty())
groups.insert(activeGroupName, activeGroup);
activeGroupName = newGroup;
if (!activeGroupName.isEmpty())
activeGroup = groups.value(activeGroupName);
}
void PlainConfigFile::read()
{
kdebugmf(KDEBUG_FUNCTION_START, "%s\n", qPrintable(filename));
QFile file(filename);
QString line;
if (file.open(QIODevice::ReadOnly))
{
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName(CodecName.toLocal8Bit().data()));
while (!stream.atEnd())
{
line = stream.readLine().trimmed();
if (line.startsWith('[') && line.endsWith(']'))
{
QString name=line.mid(1, line.length() - 2).trimmed();
if (activeGroupName!=name)
changeActiveGroup(name);
}
else if (activeGroupName.length())
{
QString name = line.section('=', 0, 0);
QString value = line.right(line.length()-name.length()-1).replace("\\n", "\n");
name = name.trimmed();
if (line.contains('=') && !name.isEmpty() && !value.isEmpty())
activeGroup.insert(name, value);
}
}
groups.insert(activeGroupName, activeGroup);
file.close();
}
kdebugf2();
}
//#include <sys/time.h>
void PlainConfigFile::write() const
{
kdebugf();
/* struct timeval t1,t2;
gettimeofday(&t1, NULL);
for(int j=0; j<100; ++j)
{*/
QFile file(filename);
QStringList out;
QString format1("[%1]\n");
QString format2("%1=%2\n");
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{
kdebugm(KDEBUG_INFO, "file opened '%s'\n", qPrintable(file.fileName()));
QTextStream stream(&file);
stream.setCodec(QTextCodec::codecForName("ISO8859-2"));
for (QMap<QString, QMap<QString, QString> >::const_iterator i = groups.constBegin(); i != groups.constEnd(); ++i)
{
// kdebugm(KDEBUG_DUMP, ">> %s\n", (i.key()));
out.append(format1.arg(i.key()));
for (QMap<QString, QString>::const_iterator j = i.value().constBegin(); j != i.value().constEnd(); ++j)
{
QString q = j.value();
out.append(format2.arg(j.key()).arg(q.replace('\n', "\\n")));
// kdebugm(KDEBUG_DUMP, ">>>>> %s %s\n", qPrintable(key()), qPrintable(q));
}
out.append("\n");
}
stream << out.join(QString());
file.close();
}
else
{
fprintf(stderr, "cannot open '%s': %s\n", qPrintable(file.fileName()), qPrintable(file.errorString()));
fflush(stderr);
}
/* }
gettimeofday(&t2, NULL);
kdebugm(KDEBUG_INFO, "czas: %ld\n", (t2.tv_usec-t1.tv_usec)+(t2.tv_sec*1000000)-(t1.tv_sec*1000000));
*/
kdebugf2();
}
QStringList PlainConfigFile::getGroupList() const
{
return QStringList(groups.keys());
}
void PlainConfigFile::sync()
{
if (!activeGroupName.isEmpty())
groups.insert(activeGroupName, activeGroup);
write();
}
QMap<QString, QString> & PlainConfigFile::getGroupSection(const QString& name)
{
kdebugf();
return groups[name];
}
bool PlainConfigFile::changeEntry(const QString &group, const QString &name, const QString &value)
{
// kdebugm(KDEBUG_FUNCTION_START, "PlainConfigFile::changeEntry(%s, %s, %s) %p\n", qPrintable(group), qPrintable(name), qPrintable(value), this);
if (activeGroupName!=group)
changeActiveGroup(group);
bool ret=activeGroup.contains(name);
activeGroup.insert(name, value);
//
return ret;
}
QString PlainConfigFile::getEntry(const QString &group, const QString &name, bool *ok)
{
// kdebugm(KDEBUG_FUNCTION_START, "PlainConfigFile::getEntry(%s, %s) %p\n", qPrintable(group), qPrintable(name), this);
if (activeGroupName!=group)
{
if (!groups.contains(group))
{
if (ok)
*ok=false;
return QString();
}
changeActiveGroup(group);
}
if (ok)
*ok=activeGroup.contains(name);
if (activeGroup.contains(name))
return activeGroup.value(name);
else
return QString();
}
void PlainConfigFile::writeEntry(const QString &group,const QString &name, const QString &value)
{
changeEntry(group, name, value);
}
QString PlainConfigFile::readEntry(const QString &group,const QString &name, const QString &def)
{
QString string = getEntry(group, name);
if (string.isNull())
return def;
return string;
}
ConfigFile::ConfigFile(const QString &filename) : filename(filename)
{
}
......
......@@ -40,39 +40,6 @@
#include "exports.h"
class KADUAPI PlainConfigFile
{
void write() const;
bool changeEntry(const QString &group, const QString &name, const QString &value);
QString getEntry(const QString &group, const QString &name, bool *ok = 0);
QString filename;
QString CodecName;
QMap<QString, QMap<QString, QString> > groups;
mutable QString activeGroupName;
mutable QMap<QString, QString> activeGroup;
PlainConfigFile(const PlainConfigFile &);
PlainConfigFile &operator = (const PlainConfigFile &);
void changeActiveGroup(const QString &newGroup);
public:
PlainConfigFile(const QString &filename, const QString &codec = "ISO8859-2");
void read();
void sync();
QMap<QString, QString> & getGroupSection(const QString &name);
QStringList getGroupList() const;
void writeEntry(const QString &group,const QString &name, const QString &value);
QString readEntry(const QString &group, const QString &name, const QString &def = QString());
};
class KADUAPI ConfigFile
{
bool changeEntry(const QString &group, const QString &name, const QString &value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment