aboutsummaryrefslogtreecommitdiff
path: root/src/kreadconfig/kwriteconfig.cpp
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2014-04-26 14:05:17 +0200
committerAleix Pol <aleixpol@kde.org>2014-04-26 14:11:15 +0200
commitb383ce66a8f3890daf8da1224aef0a34d4d99aa2 (patch)
treef1a9c1f25791b44a9ce6cf5ad14e8b633f014917 /src/kreadconfig/kwriteconfig.cpp
parent24b697b225f063476025dfba9d182f6e2d2adbcb (diff)
downloadkconfig-b383ce66a8f3890daf8da1224aef0a34d4d99aa2.tar.gz
kconfig-b383ce66a8f3890daf8da1224aef0a34d4d99aa2.tar.bz2
Adopt kreadconfig and kwriteconfig to kconfig
Drop KCoreAddons and KI18n dependency. Add a bunch of QStringLiteral()
Diffstat (limited to 'src/kreadconfig/kwriteconfig.cpp')
-rw-r--r--src/kreadconfig/kwriteconfig.cpp105
1 files changed, 46 insertions, 59 deletions
diff --git a/src/kreadconfig/kwriteconfig.cpp b/src/kreadconfig/kwriteconfig.cpp
index e5597d34..a852c286 100644
--- a/src/kreadconfig/kwriteconfig.cpp
+++ b/src/kreadconfig/kwriteconfig.cpp
@@ -23,69 +23,56 @@
#include <KConfig>
#include <KConfigGroup>
#include <stdio.h>
-#include <KAboutData>
-#include <KLocalizedString>
#include <QCoreApplication>
#include <QCommandLineParser>
int main(int argc, char **argv)
{
- QCoreApplication app(argc, argv);
- KAboutData aboutData("kwriteconfig", 0, i18n("KWriteConfig"),
- "1.0.0",
- i18n("Write KConfig entries - for use in shell scripts"),
- KAboutData::License_GPL,
- i18n("(c) 2001 Red Hat, Inc. & Luís Pedro Coelho"));
- aboutData.addAuthor("Luís Pedro Coelho", QString(), "luis_pedro@netcabo.pt");
- aboutData.addAuthor("Bernhard Rosenkraenzer", i18n("Wrote kreadconfig on which this is based"), "bero@redhat.com");
-
- KAboutData::setApplicationData(aboutData);
-
- QCommandLineParser parser;
- parser.addHelpOption();
- parser.addOption(QCommandLineOption("file", i18n("Use <file> instead of global config"), "file"));
- parser.addOption(QCommandLineOption("group", i18n("Group to look in. Use repeatedly for nested groups."), "group", "KDE"));
- parser.addOption(QCommandLineOption("key <key>", i18n("Key to look for")));
- parser.addOption(QCommandLineOption("type <type>", i18n("Type of variable. Use \"bool\" for a boolean, otherwise it is treated as a string")));
- parser.addPositionalArgument("value", i18n( "The value to write. Mandatory, on a shell use '' for empty" ));
-
- aboutData.setupCommandLine(&parser);
- parser.process(app);
- aboutData.processCommandLine(&parser);
-
- QStringList groups=parser.values("group");
- QString key=parser.value("key");
- QString file=parser.value("file");
- QString type=parser.value("type").toLower();
-
-
- if (parser.positionalArguments().isEmpty()) {
- parser.showHelp(1);
- }
- QByteArray value = parser.positionalArguments().first().toLocal8Bit();
-
- KConfig *konfig;
- if (file.isEmpty())
- konfig = new KConfig(QString::fromLatin1( "kdeglobals"), KConfig::NoGlobals );
- else
- konfig = new KConfig( file, KConfig::NoGlobals );
-
- KConfigGroup cfgGroup = konfig->group("");
- foreach (const QString &grp, groups)
- cfgGroup = cfgGroup.group(grp);
- if ( konfig->accessMode() != KConfig::ReadWrite || cfgGroup.isEntryImmutable( key ) ) return 2;
-
- if(type=="bool") {
- // For symmetry with kreadconfig we accept a wider range of values as true than Qt
- bool boolvalue=(value=="true" || value=="on" || value=="yes" || value=="1");
- cfgGroup.writeEntry( key, boolvalue );
- } else if (type=="path") {
- cfgGroup.writePathEntry( key, QString::fromLocal8Bit( value ) );
- } else {
- cfgGroup.writeEntry( key, QString::fromLocal8Bit( value ) );
- }
- konfig->sync();
- delete konfig;
- return 0;
+ QCoreApplication app(argc, argv);
+
+ QCommandLineParser parser;
+ parser.addHelpOption();
+ parser.addOption(QCommandLineOption(QStringLiteral("file"), QCoreApplication::translate("main", "Use <file> instead of global config"), QStringLiteral("file")));
+ parser.addOption(QCommandLineOption(QStringLiteral("group"), QCoreApplication::translate("main", "Group to look in. Use repeatedly for nested groups."), QStringLiteral("group"), QStringLiteral("KDE")));
+ parser.addOption(QCommandLineOption(QStringLiteral("key"), QCoreApplication::translate("main", "Key to look for"), QStringLiteral("key")));
+ parser.addOption(QCommandLineOption(QStringLiteral("type"), QCoreApplication::translate("main", "Type of variable. Use \"bool\" for a boolean, otherwise it is treated as a string"), QStringLiteral("type")));
+ parser.addPositionalArgument(QStringLiteral("value"), QCoreApplication::translate("main", "The value to write. Mandatory, on a shell use '' for empty" ));
+
+ parser.process(app);
+
+ QStringList groups=parser.values(QStringLiteral("group"));
+ QString key=parser.value(QStringLiteral("key"));
+ QString file=parser.value(QStringLiteral("file"));
+ QString type=parser.value(QStringLiteral("type")).toLower();
+
+
+ if (parser.positionalArguments().isEmpty()) {
+ parser.showHelp(1);
+ }
+ QString value = parser.positionalArguments().first();
+
+ KConfig *konfig;
+ if (file.isEmpty())
+ konfig = new KConfig(QStringLiteral( "kdeglobals"), KConfig::NoGlobals );
+ else
+ konfig = new KConfig( file, KConfig::NoGlobals );
+
+ KConfigGroup cfgGroup = konfig->group(QString());
+ foreach (const QString &grp, groups)
+ cfgGroup = cfgGroup.group(grp);
+ if ( konfig->accessMode() != KConfig::ReadWrite || cfgGroup.isEntryImmutable( key ) ) return 2;
+
+ if(type==QStringLiteral("bool")) {
+ // For symmetry with kreadconfig we accept a wider range of values as true than Qt
+ bool boolvalue=(value==QStringLiteral("true") || value==QStringLiteral("on") || value==QStringLiteral("yes") || value==QStringLiteral("1"));
+ cfgGroup.writeEntry( key, boolvalue );
+ } else if (type==QStringLiteral("path")) {
+ cfgGroup.writePathEntry( key, value );
+ } else {
+ cfgGroup.writeEntry( key, value );
+ }
+ konfig->sync();
+ delete konfig;
+ return 0;
}