File indexing completed on 2024-04-21 14:56:11

0001 #include <kcmdlineargs.h>
0002 #include <QCoreApplication>
0003 #include <QUrl>
0004 
0005 #include <stdio.h>
0006 #include <assert.h>
0007 #include <QDir>
0008 #include <QDebug>
0009 
0010 #if 1
0011 int
0012 main(int argc, char *argv[])
0013 {
0014     KCmdLineOptions options;
0015     options.add("test", ki18n("do a short test only, note that\n"
0016                               "this is rather long comment"));
0017     options.add("b");
0018     options.add("baud <baudrate>", ki18n("set baudrate"), "9600");
0019     options.add("+file(s)", ki18n("Files to load"));
0020 
0021     KCmdLineArgs::init(argc, argv, "testapp", nullptr,
0022                        ki18n("TestApp"), "v0.0.2",
0023                        ki18n("This is a test program.\n"
0024                              "1999 (c) Waldo Bastian"));
0025 
0026     KCmdLineArgs::addCmdLineOptions(options);   // Add my own options.
0027 
0028     // MyWidget::addCmdLineOptions();
0029 
0030     QCoreApplication app(KCmdLineArgs::qtArgc(), KCmdLineArgs::qtArgv());
0031 
0032     // Get application specific arguments
0033     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
0034     // Check if an option is set
0035     if (args->isSet("test")) {
0036         // Do stuff
0037         printf("Option 'test' is set.\n");
0038     }
0039 
0040     if (args->isSet("baud")) {
0041         // Do stuff
0042         printf("Option 'baud' is set.\n");
0043     }
0044 
0045     qDebug() << "allArguments:" << KCmdLineArgs::allArguments();
0046 
0047     // Read the value of an option.
0048     QString baudrate = args->getOption("baud"); // 9600 is the default value.
0049 
0050     printf("Baudrate = %s\n", baudrate.toLocal8Bit().data());
0051 
0052     printf("Full list of baudrates:\n");
0053     QStringList result = args->getOptionList("baud");
0054     Q_FOREACH (const QString &it, result) {
0055         printf("Baudrate = %s\n", it.toLocal8Bit().data());
0056     }
0057     printf("End of list\n");
0058 
0059     for (int i = 0; i < args->count(); i++) {
0060         printf("%d: %s\n", i, args->arg(i).toLocal8Bit().data());
0061         printf("%d: %s\n", i, args->url(i).toEncoded().data());
0062     }
0063 
0064     args->clear(); // Free up memory.
0065 
0066 //   return app.exec();
0067     return 0;
0068 }
0069 #else
0070 int
0071 main(int argc, char *argv[])
0072 {
0073     KCmdLineArgs::init(argc, argv, "testapp", description, version);
0074 
0075     QApplication app(KCmdLineArgs::qtArgc(), KCmdLineArgs::qtArgv(), false);
0076 
0077     return app.exec();
0078 }
0079 #endif
0080