diff options
author | Aleix Pol <aleixpol@kde.org> | 2014-04-26 14:05:17 +0200 |
---|---|---|
committer | Aleix Pol <aleixpol@kde.org> | 2014-04-26 14:11:15 +0200 |
commit | b383ce66a8f3890daf8da1224aef0a34d4d99aa2 (patch) | |
tree | f1a9c1f25791b44a9ce6cf5ad14e8b633f014917 /src | |
parent | 24b697b225f063476025dfba9d182f6e2d2adbcb (diff) | |
download | kconfig-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')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/kreadconfig/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/kreadconfig/kreadconfig.cpp | 42 | ||||
-rw-r--r-- | src/kreadconfig/kwriteconfig.cpp | 105 |
4 files changed, 64 insertions, 88 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index caa7a43d..916d51fb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,3 +2,4 @@ add_subdirectory(core) add_subdirectory(gui) add_subdirectory(kconfig_compiler) add_subdirectory(kconf_update) +add_subdirectory(kreadconfig) diff --git a/src/kreadconfig/CMakeLists.txt b/src/kreadconfig/CMakeLists.txt index 4c263891..434f33a1 100644 --- a/src/kreadconfig/CMakeLists.txt +++ b/src/kreadconfig/CMakeLists.txt @@ -1,7 +1,7 @@ add_executable(kreadconfig kreadconfig.cpp) ecm_mark_nongui_executable(kreadconfig) -target_link_libraries(kreadconfig KF5::CoreAddons KF5::I18n KF5::ConfigCore) +target_link_libraries(kreadconfig KF5::ConfigCore) install(TARGETS kreadconfig ${INSTALL_TARGETS_DEFAULT_ARGS}) @@ -10,6 +10,6 @@ install(TARGETS kreadconfig ${INSTALL_TARGETS_DEFAULT_ARGS}) add_executable(kwriteconfig kwriteconfig.cpp) ecm_mark_nongui_executable(kwriteconfig) -target_link_libraries(kwriteconfig KF5::CoreAddons KF5::I18n KF5::ConfigCore) +target_link_libraries(kwriteconfig KF5::ConfigCore) install(TARGETS kwriteconfig ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/kreadconfig/kreadconfig.cpp b/src/kreadconfig/kreadconfig.cpp index 532d0771..3505ac3e 100644 --- a/src/kreadconfig/kreadconfig.cpp +++ b/src/kreadconfig/kreadconfig.cpp @@ -45,39 +45,27 @@ #include <KConfig> #include <KConfigGroup> #include <KSharedConfig> -#include <KAboutData> -#include <KLocalizedString> #include <QCommandLineParser> #include <stdio.h> int main(int argc, char **argv) { QCoreApplication app(argc, argv); - KAboutData aboutData("kreadconfig", 0, i18n("KReadConfig"), - "1.0.1", - i18n("Read KConfig entries - for use in shell scripts"), - KAboutData::License_GPL, - i18n("(c) 2001 Red Hat, Inc.")); - aboutData.addAuthor(i18n("Bernhard Rosenkraenzer"), QString(), "bero@redhat.com"); - - KAboutData::setApplicationData(aboutData); QCommandLineParser parser; - 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", i18n("Key to look for"), "key")); - parser.addOption(QCommandLineOption("default", i18n("Default value"), "value")); - parser.addOption(QCommandLineOption("type", i18n("Type of variable"), "type")); + 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("default"), QCoreApplication::translate("main", "Default value"), QStringLiteral("value"))); + parser.addOption(QCommandLineOption(QStringLiteral("type"), QCoreApplication::translate("main", "Type of variable"), QStringLiteral("type"))); - 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 dflt=parser.value("default"); - QString type=parser.value("type").toLower(); + QStringList groups=parser.values(QStringLiteral("group")); + QString key=parser.value(QStringLiteral("key")); + QString file=parser.value(QStringLiteral("file")); + QString dflt=parser.value(QStringLiteral("default")); + QString type=parser.value(QStringLiteral("type")).toLower(); if (parser.positionalArguments().isEmpty()) { parser.showHelp(1); @@ -94,22 +82,22 @@ int main(int argc, char **argv) konfig = new KConfig( file, KConfig::NoGlobals ); configMustDeleted=true; } - KConfigGroup cfgGroup = konfig->group(""); + KConfigGroup cfgGroup = konfig->group(QString()); foreach (const QString &grp, groups) cfgGroup = cfgGroup.group(grp); - if(type=="bool") { + if(type==QStringLiteral("bool")) { dflt=dflt.toLower(); - bool def=(dflt=="true" || dflt=="on" || dflt=="yes" || dflt=="1"); + bool def=(dflt==QStringLiteral("true") || dflt==QStringLiteral("on") || dflt==QStringLiteral("yes") || dflt==QStringLiteral("1")); bool retValue = !cfgGroup.readEntry(key, def); if ( configMustDeleted ) delete konfig; return retValue; - } else if((type=="num") || (type=="int")) { + } else if((type==QStringLiteral("num")) || (type==QStringLiteral("int"))) { int retValue = cfgGroup.readEntry(key, dflt.toInt()); if ( configMustDeleted ) delete konfig; return retValue; - } else if (type=="path"){ + } else if (type==QStringLiteral("path")){ fprintf(stdout, "%s\n", cfgGroup.readPathEntry(key, dflt).toLocal8Bit().data()); if ( configMustDeleted ) delete konfig; 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; } |