aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAleix Pol <aleixpol@kde.org>2014-02-21 17:43:48 +0100
committerAleix Pol <aleixpol@kde.org>2014-04-26 14:11:15 +0200
commitc5dfe84ea63a3cc903f2417a1f86b34f36b956ba (patch)
tree0665959c4782270f4a819c44b2a4e6a963981236 /src
parent54c4b7239a37484c9f1e124568a82589ac58e139 (diff)
downloadkconfig-c5dfe84ea63a3cc903f2417a1f86b34f36b956ba.tar.gz
kconfig-c5dfe84ea63a3cc903f2417a1f86b34f36b956ba.tar.bz2
Port kwriteconfig to KF5
Diffstat (limited to 'src')
-rw-r--r--src/kreadconfig/CMakeLists.txt29
-rw-r--r--src/kreadconfig/kwriteconfig.cpp74
2 files changed, 45 insertions, 58 deletions
diff --git a/src/kreadconfig/CMakeLists.txt b/src/kreadconfig/CMakeLists.txt
index c73c9ac7..7e1edfe1 100644
--- a/src/kreadconfig/CMakeLists.txt
+++ b/src/kreadconfig/CMakeLists.txt
@@ -1,26 +1,15 @@
-
-
-
+# add_executable(kreadconfig kreadconfig.cpp)
+# ecm_mark_nongui_executable(kreadconfig)
+#
+# target_link_libraries(kreadconfig KF5::CoreAddons KF5::KI18n KF5::Config)
+#
+# install(TARGETS kreadconfig ${INSTALL_TARGETS_DEFAULT_ARGS})
########### next target ###############
-set(kreadconfig_SRCS kreadconfig.cpp )
-
-
-kde4_add_executable(kreadconfig NOGUI ${kreadconfig_SRCS})
-
-target_link_libraries(kreadconfig ${KDE4_KDECORE_LIBS} )
-
-install(TARGETS kreadconfig ${INSTALL_TARGETS_DEFAULT_ARGS})
-
-
-########### next target ###############
-
-set(kwriteconfig_SRCS kwriteconfig.cpp )
-
-
-kde4_add_executable(kwriteconfig NOGUI ${kwriteconfig_SRCS})
+kde4_add_executable(kwriteconfig kwriteconfig.cpp)
+ecm_mark_nongui_executable(kwriteconfig)
-target_link_libraries(kwriteconfig ${KDE4_KDECORE_LIBS} )
+target_link_libraries(kwriteconfig KF5::CoreAddons KF5::I18n KF5::ConfigCore)
install(TARGETS kwriteconfig ${INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/src/kreadconfig/kwriteconfig.cpp b/src/kreadconfig/kwriteconfig.cpp
index 67b28b42..250a6e36 100644
--- a/src/kreadconfig/kwriteconfig.cpp
+++ b/src/kreadconfig/kwriteconfig.cpp
@@ -20,61 +20,59 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <kconfig.h>
-#include <kconfiggroup.h>
-#include <kglobal.h>
-#include <kapplication.h>
-#include <kcmdlineargs.h>
-#include <klocale.h>
-#include <kaboutdata.h>
+#include <KConfig>
+#include <KConfigGroup>
#include <stdio.h>
-//Added by qt3to4:
+#include <KAboutData>
+#include <KLocalizedString>
+#include <QCoreApplication>
+#include <QCommandLineParser>
int main(int argc, char **argv)
{
- KAboutData aboutData("kwriteconfig", 0, ki18n("KWriteConfig"),
+ KAboutData aboutData("kwriteconfig", 0, i18n("KWriteConfig"),
"1.0.0",
- ki18n("Write KConfig entries - for use in shell scripts"),
+ i18n("Write KConfig entries - for use in shell scripts"),
KAboutData::License_GPL,
- ki18n("(c) 2001 Red Hat, Inc. & Luís Pedro Coelho"));
- aboutData.addAuthor(ki18n("Luís Pedro Coelho"), KLocalizedString(), "luis_pedro@netcabo.pt");
- aboutData.addAuthor(ki18n("Bernhard Rosenkraenzer"), ki18n("Wrote kreadconfig on which this is based"), "bero@redhat.com");
- KCmdLineArgs::init(argc, argv, &aboutData);
+ 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");
QCoreApplication app(argc, argv);
+ KAboutData::setApplicationData(aboutData);
- KCmdLineOptions options;
- options.add("file <file>", ki18n("Use <file> instead of global config"));
- options.add("group <group>", ki18n("Group to look in. Use repeatedly for nested groups."), "KDE");
- options.add("key <key>", ki18n("Key to look for"));
- options.add("type <type>", ki18n("Type of variable. Use \"bool\" for a boolean, otherwise it is treated as a string"));
- options.add("+value", ki18n( "The value to write. Mandatory, on a shell use '' for empty" ));
- KCmdLineArgs::addCmdLineOptions(options);
- KCmdLineArgs *args=KCmdLineArgs::parsedArgs();
+ 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" ));
- QStringList groups=args->getOptionList("group");
- QString key=args->getOption("key");
- QString file=args->getOption("file");
- QString type=args->getOption("type").toLower();
+ 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 (key.isNull() || !args->count()) {
- KCmdLineArgs::usage();
- return 1;
- }
- QByteArray value = args->arg( 0 ).toLocal8Bit();
- KComponentData inst(&aboutData);
+ 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 );
+ konfig = new KConfig(QString::fromLatin1( "kdeglobals"), KConfig::NoGlobals );
else
- konfig = new KConfig( file, KConfig::NoGlobals );
+ konfig = new KConfig( file, KConfig::NoGlobals );
- KConfigGroup cfgGroup = konfig->group("");
- foreach (const QString &grp, groups)
- cfgGroup = cfgGroup.group(grp);
+ 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") {
@@ -87,7 +85,7 @@ int main(int argc, char **argv)
cfgGroup.writeEntry( key, QString::fromLocal8Bit( value ) );
}
konfig->sync();
- delete konfig;
+ delete konfig;
return 0;
}