24 #include <sys/param.h>
37 #include <QtCore/QDir>
38 #include <QtCore/QFile>
39 #include <QtCore/QHash>
40 #include <QtCore/QTextCodec>
44 #include "kdeversion.h"
75 #define DISPLAY "DISPLAY"
76 #elif defined(Q_WS_QWS)
77 #define DISPLAY "QWS_DISPLAY"
79 #define DISPLAY "NODISPLAY"
86 class KCmdLineParsedOptions :
public QHash<QByteArray,QByteArray>
89 KCmdLineParsedOptions() { }
92 class KCmdLineParsedArgs :
public QList<QByteArray>
95 KCmdLineParsedArgs() { }
99 class KCmdLineArgsList:
public QList<KCmdLineArgs*>
102 KCmdLineArgsList() { }
103 ~KCmdLineArgsList() {
113 class KCmdLineOptionsPrivate {
115 QList<QByteArray> names;
116 QList<KLocalizedString> descriptions;
121 : d(new KCmdLineOptionsPrivate)
130 : d(new KCmdLineOptionsPrivate(*(options.d)))
136 if (
this != &options) {
146 d->names.append(name);
147 d->descriptions.append(description);
148 d->defaults.append(QString::fromUtf8(defaultValue));
154 d->names += other.d->names;
155 d->descriptions += other.d->descriptions;
156 d->defaults += other.d->defaults;
164 class KCmdLineArgsStatic {
167 KCmdLineArgsList *argsList;
174 bool ignoreUnknown : 1;
176 KCmdLineArgs::StdCmdLineArgs mStdargs;
181 KCmdLineArgsStatic ();
183 ~KCmdLineArgsStatic ();
194 static QString decodeInput(
const QByteArray &rawstr);
203 static QByteArray encodeOutput(
const QString &str);
209 void printQ(
const QString &msg);
225 QByteArray &opt_name,
QString &def,
bool &enabled);
232 static void findOption(
const QByteArray &optv,
const QByteArray &_opt,
233 int &i,
bool _enabled,
bool &moreOptions);
241 static void parseAllArgs();
250 static void removeArgs(
const QByteArray &
id);
255 KCmdLineArgsStatic::KCmdLineArgsStatic () {
264 ignoreUnknown =
false;
268 codec = QTextCodec::codecForLocale();
273 qt_options.add(
"display <displayname>",
ki18n(
"Use the X-server display 'displayname'"));
274 #elif defined(Q_WS_QWS)
275 qt_options.add(
"display <displayname>",
ki18n(
"Use the QWS display 'displayname'"));
278 qt_options.add(
"session <sessionId>",
ki18n(
"Restore the application for the given 'sessionId'"));
279 qt_options.add(
"cmap",
ki18n(
"Causes the application to install a private color\nmap on an 8-bit display"));
280 qt_options.add(
"ncols <count>",
ki18n(
"Limits the number of colors allocated in the color\ncube on an 8-bit display, if the application is\nusing the QApplication::ManyColor color\nspecification"));
281 qt_options.add(
"nograb",
ki18n(
"tells Qt to never grab the mouse or the keyboard"));
282 qt_options.add(
"dograb",
ki18n(
"running under a debugger can cause an implicit\n-nograb, use -dograb to override"));
283 qt_options.add(
"sync",
ki18n(
"switches to synchronous mode for debugging"));
284 qt_options.add(
"fn");
285 qt_options.add(
"font <fontname>",
ki18n(
"defines the application font"));
286 qt_options.add(
"bg");
287 qt_options.add(
"background <color>",
ki18n(
"sets the default background color and an\napplication palette (light and dark shades are\ncalculated)"));
288 qt_options.add(
"fg");
289 qt_options.add(
"foreground <color>",
ki18n(
"sets the default foreground color"));
290 qt_options.add(
"btn");
291 qt_options.add(
"button <color>",
ki18n(
"sets the default button color"));
292 qt_options.add(
"name <name>",
ki18n(
"sets the application name"));
293 qt_options.add(
"title <title>",
ki18n(
"sets the application title (caption)"));
294 qt_options.add(
"testability",
ki18n(
"load the testability framework"));
296 qt_options.add(
"visual TrueColor",
ki18n(
"forces the application to use a TrueColor visual on\nan 8-bit display"));
297 qt_options.add(
"inputstyle <inputstyle>",
ki18n(
"sets XIM (X Input Method) input style. Possible\nvalues are onthespot, overthespot, offthespot and\nroot"));
298 qt_options.add(
"im <XIM server>",
ki18n(
"set XIM server"));
299 qt_options.add(
"noxim",
ki18n(
"disable XIM"));
302 qt_options.add(
"qws",
ki18n(
"forces the application to run as QWS Server"));
304 qt_options.add(
"reverse",
ki18n(
"mirrors the whole layout of widgets"));
305 qt_options.add(
"stylesheet <file.qss>",
ki18n(
"applies the Qt stylesheet to the application widgets"));
306 qt_options.add(
"graphicssystem <system>",
ki18n(
"use a different graphics system instead of the default one, options are raster and opengl (experimental)"));
308 kde_options.add(
"caption <caption>",
ki18n(
"Use 'caption' as name in the titlebar"));
309 kde_options.add(
"icon <icon>",
ki18n(
"Use 'icon' as the application icon"));
310 kde_options.add(
"config <filename>",
ki18n(
"Use alternative configuration file"));
311 kde_options.add(
"nocrashhandler",
ki18n(
"Disable crash handler, to get core dumps"));
313 kde_options.add(
"waitforwm",
ki18n(
"Waits for a WM_NET compatible windowmanager"));
315 kde_options.add(
"style <style>",
ki18n(
"sets the application GUI style"));
316 kde_options.add(
"geometry <geometry>",
ki18n(
"sets the client geometry of the main widget - see man X for the argument format (usually WidthxHeight+XPos+YPos)"));
318 kde_options.add(
"smkey <sessionKey>");
322 KCmdLineArgsStatic::~KCmdLineArgsStatic ()
333 class KCmdLineArgsPrivate
335 friend class KCmdLineArgsStatic;
341 , parsedOptionList(0)
346 ~KCmdLineArgsPrivate()
348 delete parsedOptionList;
349 delete parsedArgList;
354 KCmdLineParsedOptions *parsedOptionList;
355 KCmdLineParsedArgs *parsedArgList;
363 void setOption(
const QByteArray &option,
bool enabled);
370 void setOption(
const QByteArray &option,
const QByteArray &value);
377 void addArgument(
const QByteArray &argument);
384 void save( QDataStream &)
const;
391 void load( QDataStream &);
399 KCmdLineArgsStatic::decodeInput(
const QByteArray &rawstr)
401 return s->codec->toUnicode(rawstr);
405 KCmdLineArgsStatic::encodeOutput(
const QString &str)
407 return s->codec->fromUnicode(str);
411 KCmdLineArgsStatic::printQ(
const QString &msg)
413 fprintf(stdout,
"%s", encodeOutput(msg).data());
418 const QByteArray &_appname,
419 const QByteArray &_catalog,
421 const QByteArray &_version,
423 StdCmdLineArgs stdargs)
426 new KAboutData(_appname, _catalog, _programName, _version, _description),
431 KCmdLineArgs::initIgnore(
int _argc,
char **_argv,
const QByteArray &_appname )
435 s->ignoreUnknown =
true;
441 char **_argv = (
char **) malloc(
sizeof(
char *));
442 _argv[0] = (
char *) s->encodeOutput(ab->
appName()).data();
455 fprintf(stderr,
"\n\nFAILURE (KCmdLineArgs):\n");
456 fprintf(stderr,
"Passing null-pointer to 'argv' is not allowed.\n\n");
464 char *p = strrchr(s->all_argv[0], QDir::separator().toAscii());
468 s->appName = s->all_argv[0];
473 s->mCwd = QDir::currentPath().toLocal8Bit();
479 return QString::fromLocal8Bit(s->mCwd);
484 if (!s->appName)
return QString();
485 return s->decodeInput(s->appName);
498 s->mStdargs = stdargs;
503 const QByteArray &
id,
const QByteArray &afterId)
508 int pos = s->argsList->count();
510 if (pos > 0 && !
id.isEmpty() && s->argsList->last()->d->name.isEmpty())
513 KCmdLineArgsList::Iterator args;
515 for(args = s->argsList->begin(); args != s->argsList->end(); ++args, i++)
517 if (
id == (*args)->d->id) {
523 if (!afterId.isEmpty() && afterId == (*args)->d->id)
527 Q_ASSERT( s->parsed ==
false );
529 s->argsList->insert(pos,
new KCmdLineArgs(options, name,
id));
540 s->removeArgs(
"kde");
541 s->removeArgs(
"kuniqueapp");
545 uint
count = s->argsList ? s->argsList->count() : 0;
550 KCmdLineArgsList::Iterator args;
551 for(args = s->argsList->begin(); args != s->argsList->end(); ++args)
553 ds << (*args)->d->id;
554 (*args)->d->save(ds);
565 s->removeArgs(
"kde");
566 s->removeArgs(
"kuniqueapp");
568 KCmdLineArgsList::Iterator args;
570 for(args = s->argsList->begin(); args != s->argsList->end(); ++args)
591 Q_ASSERT( s->argsList );
593 for(args = s->argsList->begin(); args != s->argsList->end(); ++args)
595 if ((*args)->d->id ==
id)
597 (*args)->d->load(ds);
603 kWarning() <<
"Argument definitions for" <<
id <<
"not found!";
614 KCmdLineArgsList::Iterator args = s->argsList->begin();
615 while(args != s->argsList->end())
617 if ((*args)->d->id ==
id)
629 void KCmdLineArgsStatic::removeArgs(
const QByteArray &
id)
633 KCmdLineArgsList::Iterator args = s->argsList->begin();
634 while(args != s->argsList->end())
636 if ((*args)->d->id ==
id)
645 if (args != s->argsList->end()) {
647 s->argsList->erase(args);
653 KCmdLineArgsStatic::findOption(
const KCmdLineOptions &options, QByteArray &opt,
654 QByteArray &opt_name,
QString &def,
bool &enabled)
659 for (
int i = 0; i < options.d->names.size(); i++)
663 opt_name = options.d->names[i];
664 if (opt_name.startsWith(
':') || opt_name.isEmpty())
668 if (opt_name.startsWith(
'!'))
670 opt_name = opt_name.mid(1);
673 if (opt_name.startsWith(
"no") && !opt_name.contains(
'<'))
675 opt_name = opt_name.mid(2);
679 int len = opt.length();
680 if (opt == opt_name.left(len))
682 opt_name = opt_name.mid(len);
683 if (opt_name.isEmpty())
688 if (options.d->descriptions[i].isEmpty())
691 if (i >= options.d->names.size())
693 QByteArray nextOption = options.d->names[i];
694 int p = nextOption.indexOf(
' ');
696 nextOption = nextOption.left(p);
697 if (nextOption.startsWith(
'!'))
698 nextOption = nextOption.mid(1);
699 if (nextOption.startsWith(
"no") && !nextOption.contains(
'<'))
701 nextOption = nextOption.mid(2);
704 result = findOption(options, nextOption, opt_name, def, enabled);
712 if (opt_name.startsWith(
' '))
714 opt_name = opt_name.mid(1);
715 def = options.d->defaults[i];
724 KCmdLineArgsStatic::findOption(
const QByteArray &optv,
const QByteArray &_opt,
725 int &i,
bool _enabled,
bool &moreOptions)
727 KCmdLineArgsList::Iterator args = s->argsList->begin();
728 QByteArray opt = _opt;
732 int j = opt.indexOf(
'=');
735 argument = opt.mid(j+1);
741 while (args != s->argsList->end())
744 result = findOption((*args)->d->options, opt, opt_name, def, enabled);
748 if ((args == s->argsList->end()) &&
749 (optv.startsWith(
'-') && !optv.startsWith(
"--")))
756 QByteArray singleCharOption =
" ";
757 singleCharOption[0] = optv[p];
758 args = s->argsList->begin();
759 while (args != s->argsList->end())
762 result = findOption((*args)->d->options, singleCharOption,
763 opt_name, def, enabled);
767 if (args == s->argsList->end())
773 (*args)->d->setOption(singleCharOption, enabled);
774 if (p < optv.length())
779 else if (result == 3)
781 if (argument.isEmpty())
783 argument = optv.mid(p);
785 (*args)->d->setOption(singleCharOption, argument);
790 args = s->argsList->end();
794 if (args == s->argsList->end() || !result)
796 if (s->ignoreUnknown)
802 if ((result & 4) != 0)
812 if (s->ignoreUnknown)
817 if (argument.isEmpty())
820 if (i >= s->all_argc)
825 argument = s->all_argv[i];
827 (*args)->d->setOption(opt, argument);
831 (*args)->d->setOption(opt, enabled);
836 KCmdLineArgsStatic::parseAllArgs()
838 bool allowArgs =
false;
839 bool inOptions =
true;
840 bool everythingAfterArgIsArgs =
false;
842 if (appOptions->d->id.isEmpty())
844 foreach(
const QByteArray& name, appOptions->d->options.d->names)
846 everythingAfterArgIsArgs = everythingAfterArgIsArgs || name.startsWith(
"!+");
847 allowArgs = allowArgs || name.startsWith(
'+') || everythingAfterArgIsArgs;
850 for(
int i = 1; i < s->all_argc; i++)
855 if ((s->all_argv[i][0] ==
'-') && s->all_argv[i][1] && inOptions)
858 QByteArray orig = s->all_argv[i];
859 QByteArray option = orig.mid(1);
860 if (option.startsWith(
'-'))
862 option = option.mid(1);
863 if (option.isEmpty())
869 if (option ==
"help")
873 else if (option.startsWith(
"help-"))
879 else if (option.startsWith(
"psn_"))
884 else if ((option ==
"version") || (option ==
"v"))
887 s->printQ(
i18nc(
"@info:shell message on appcmd --version; do not translate 'Development Platform'"
888 "%3 application name, other %n version strings",
890 "KDE Development Platform: %2\n"
892 QString::fromLatin1(qVersion()),
894 s->about->programName(), s->about->version()));
896 }
else if (option ==
"license")
899 s->printQ(s->about->license());
900 s->printQ(QString::fromLatin1(
"\n"));
902 }
else if (option ==
"author") {
905 const QList<KAboutPerson> authors = s->about->authors();
906 if ( !authors.isEmpty() ) {
908 for (QList<KAboutPerson>::ConstIterator it = authors.begin(); it != authors.end(); ++it ) {
910 if ( !(*it).emailAddress().isEmpty() )
911 email = QString::fromLatin1(
" <") + (*it).emailAddress() + QLatin1String(
">");
912 authorlist += QString::fromLatin1(
" ") + (*it).name() + email + QLatin1Char(
'\n');
914 s->printQ(
i18nc(
"the 2nd argument is a list of name+address, one on each line",
"%1 was written by\n%2",
QString(s->about->programName()) , authorlist ) );
917 s->printQ(
i18n(
"This application was written by somebody who wants to remain anonymous.") );
921 if (!s->about->customAuthorTextEnabled ())
923 if (s->about->bugAddress().isEmpty() || s->about->bugAddress() == QLatin1String(
"submit@bugs.kde.org") )
924 s->printQ(
i18n(
"Please use http://bugs.kde.org to report bugs.\n" ) );
926 s->printQ(
i18n(
"Please report bugs to %1.\n" , s->about->bugAddress()) );
930 s->printQ(s->about->customAuthorPlainText()+QLatin1Char(
'\n'));
935 if (option.startsWith(
"no"))
937 bool noHasParameter=
false;
938 foreach(
const QByteArray& name, appOptions->d->options.d->names)
940 if (name.contains(option + QByteArray(
" ")) && name.contains(
'<'))
948 option = option.mid(2);
952 s->findOption(orig, option, i, enabled, inOptions);
960 if (s->ignoreUnknown)
967 appOptions->d->addArgument(s->all_argv[i]);
968 if (everythingAfterArgIsArgs)
981 static int qt_argc = -1;
995 fprintf(stderr,
"\n\nFAILURE (KCmdLineArgs):\n");
996 fprintf(stderr,
"Application has not called KCmdLineArgs::init(...).\n\n");
1002 Q_ASSERT(s->all_argc >= (args->
count()+1));
1003 qt_argc = args->
count() +1;
1015 if( s_qt_argv != NULL )
1020 s_qt_argv =
new char*[2];
1021 s_qt_argv[0] = qstrdup(s->all_argc?s->all_argv[0]:
"");
1030 fprintf(stderr,
"\n\nFAILURE (KCmdLineArgs):\n");
1031 fprintf(stderr,
"The \"qt\" options have not be added to KCmdLineArgs!\n\n");
1038 fprintf(stderr,
"\n\nFAILURE (KCmdLineArgs):\n");
1039 fprintf(stderr,
"Application has not called KCmdLineArgs::init(...).\n\n");
1046 s_qt_argv =
new char*[ count + 2 ];
1047 s_qt_argv[0] = qstrdup(s->all_argc?s->all_argv[0]:
"");
1049 for(; i <
count; i++)
1051 s_qt_argv[i+1] = qstrdup(args->d->parsedArgList->at(i));
1073 mainComponentData.
config();
1082 QByteArray localError = s->encodeOutput(error);
1083 if (localError.endsWith(
'\n'))
1085 fprintf(stderr,
"%s: %s\n", s->appName, localError.data());
1087 QString tmp =
i18n(
"Use --help to get a list of available command line options.");
1088 localError = s->encodeOutput(tmp);
1089 fprintf(stderr,
"%s: %s\n", s->appName, localError.data());
1097 Q_ASSERT(s->argsList != 0);
1100 QString optionFormatString = QString::fromLatin1(
" %1 %2\n");
1101 QString optionFormatStringDef = QString::fromLatin1(
" %1 %2 [%3]\n");
1105 KCmdLineArgsList::Iterator args = --(s->argsList->end());
1107 if ((*args)->d->id.isEmpty() && ((*args)->d->options.d->names.size() > 0) &&
1108 !(*args)->d->options.d->names[0].startsWith(
'+'))
1115 if (!(*args)->d->name.isEmpty())
1117 usage =
i18n(
"[%1-options]", (*args)->d->name.toString())+QLatin1Char(
' ')+
usage;
1119 if (args == s->argsList->begin())
1125 if (appOptions->d->id.isEmpty())
1128 for (
int i = 0; i < option.d->names.size(); i++)
1130 QByteArray opt_name = option.d->names[i];
1131 if (opt_name.startsWith(
'+'))
1132 usage += QString::fromLatin1(opt_name.mid(1)) + QLatin1Char(
' ');
1133 else if ( opt_name.startsWith(
"!+") )
1134 usage += QString::fromLatin1(opt_name.mid(2)) + QLatin1Char(
' ');
1139 s->printQ(QLatin1Char(
'\n')+s->about->shortDescription()+QLatin1Char(
'\n'));
1141 s->printQ(
i18n(
"\nGeneric options:\n"));
1142 s->printQ(optionFormatString.arg(QString::fromLatin1(
"--help"), -25)
1143 .arg(
i18n(
"Show help about options")));
1145 args = s->argsList->begin();
1146 while(args != s->argsList->end())
1148 if (!(*args)->d->name.isEmpty() && !(*args)->d->id.isEmpty())
1150 QString option = QString::fromLatin1(
"--help-%1").arg(QString::fromLatin1((*args)->d->id));
1151 QString desc =
i18n(
"Show %1 specific options", (*args)->d->name.toString());
1153 s->printQ(optionFormatString.arg(option, -25).arg(desc));
1158 s->printQ(optionFormatString.arg(QString::fromLatin1(
"--help-all"),-25).arg(
i18n(
"Show all options")));
1159 s->printQ(optionFormatString.arg(QString::fromLatin1(
"--author"),-25).arg(
i18n(
"Show author information")));
1160 s->printQ(optionFormatString.arg(QString::fromLatin1(
"-v, --version"),-25).arg(
i18n(
"Show version information")));
1161 s->printQ(optionFormatString.arg(QString::fromLatin1(
"--license"),-25).arg(
i18n(
"Show license information")));
1162 s->printQ(optionFormatString.arg(QString::fromLatin1(
"--"), -25).arg(
i18n(
"End of options")));
1164 args = s->argsList->begin();
1166 bool showAll = (
id ==
"all");
1170 while(args != s->argsList->end())
1172 if (
id == (*args)->d->id)
break;
1177 while(args != s->argsList->end())
1179 bool hasArgs =
false;
1180 bool hasOptions =
false;
1182 if (!(*args)->d->name.isEmpty())
1183 optionsHeader =
i18n(
"\n%1 options:\n", (*args)->d->name.toString());
1185 optionsHeader =
i18n(
"\nOptions:\n");
1187 while (args != s->argsList->end())
1192 for (
int i = 0; i < option.d->names.size(); i++)
1198 if (!option.d->descriptions[i].isEmpty()) {
1199 descriptionFull = option.d->descriptions[i].toString();
1203 if (option.d->names[i].startsWith(
':'))
1205 if (!descriptionFull.isEmpty())
1207 optionsHeader = QLatin1Char(
'\n')+descriptionFull;
1208 if (!optionsHeader.endsWith(QLatin1Char(
'\n')))
1209 optionsHeader.append(QLatin1Char(
'\n'));
1216 if (option.d->names[i].isEmpty())
1218 if (!descriptionFull.isEmpty())
1220 tmp = QLatin1Char(
'\n')+descriptionFull;
1221 if (!tmp.endsWith(QLatin1Char(
'\n')))
1222 tmp.append(QLatin1Char(
'\n'));
1229 if (!descriptionFull.isEmpty())
1231 dl = descriptionFull.split(QLatin1Char(
'\n'), QString::KeepEmptyParts);
1232 description = dl.first();
1233 dl.erase( dl.begin() );
1235 QByteArray name = option.d->names[i];
1236 if (name.startsWith(
'!'))
1239 if (name.startsWith(
'+'))
1243 s->printQ(
i18n(
"\nArguments:\n"));
1248 if (name.startsWith(
'[') && name.endsWith(
']'))
1249 name = name.mid(1, name.length()-2);
1250 s->printQ(optionFormatString.arg(QString::fromLocal8Bit(name), -25).arg(description));
1256 s->printQ(optionsHeader);
1260 if ((name.length() == 1) || (name[1] ==
' '))
1264 if (descriptionFull.isEmpty())
1271 if (option.d->defaults[i].isEmpty())
1273 s->printQ(optionFormatString.arg(QString::fromLatin1(opt), -25).arg(description));
1277 s->printQ(optionFormatStringDef.arg(QString::fromLatin1(opt), -25)
1278 .arg(description, option.d->defaults[i]));
1283 for(QStringList::Iterator it = dl.begin();
1287 s->printQ(optionFormatString.arg(
QString(), -25).arg(*it));
1292 if (args == s->argsList->end() || !(*args)->d->name.isEmpty() || (*args)->d->id.isEmpty())
1295 if (!showAll)
break;
1312 const QByteArray &_id)
1313 : d(new KCmdLineArgsPrivate(_options, _name, _id))
1322 if (!s.isDestroyed() && s->argsList)
1323 s->argsList->removeAll(
this);
1336 delete d->parsedArgList; d->parsedArgList = 0;
1337 delete d->parsedOptionList; d->parsedOptionList = 0;
1343 delete s->argsList; s->argsList = 0;
1348 KCmdLineArgsPrivate::save( QDataStream &ds)
const
1350 if (parsedOptionList)
1351 ds << (*(parsedOptionList));
1356 ds << (*(parsedArgList));
1362 KCmdLineArgsPrivate::load( QDataStream &ds)
1364 if (!parsedOptionList) parsedOptionList =
new KCmdLineParsedOptions;
1365 if (!parsedArgList) parsedArgList =
new KCmdLineParsedArgs;
1367 ds >> (*(parsedOptionList));
1368 ds >> (*(parsedArgList));
1370 if (parsedOptionList->count() == 0)
1372 delete parsedOptionList; parsedOptionList = 0;
1374 if (parsedArgList->count() == 0)
1376 delete parsedArgList; parsedArgList = 0;
1381 KCmdLineArgsPrivate::setOption(
const QByteArray &opt,
bool enabled)
1386 QByteArray argString =
"-";
1390 addArgument(argString);
1392 if (!parsedOptionList) {
1393 parsedOptionList =
new KCmdLineParsedOptions;
1397 parsedOptionList->insert( opt,
"t" );
1399 parsedOptionList->insert( opt,
"f" );
1403 KCmdLineArgsPrivate::setOption(
const QByteArray &opt,
const QByteArray &value)
1408 QByteArray argString =
"-";
1410 addArgument(argString);
1413 #if defined(Q_WS_X11) || defined(Q_WS_QWS)
1415 if (argString ==
"-display")
1417 setenv(
DISPLAY, value.data(),
true);
1421 if (!parsedOptionList) {
1422 parsedOptionList =
new KCmdLineParsedOptions;
1425 parsedOptionList->insertMulti( opt, value );
1431 QByteArray opt = _opt;
1433 if (d->parsedOptionList)
1435 value = d->parsedOptionList->value(opt);
1437 if (!value.isEmpty())
1438 return QString::fromLocal8Bit(value);
1441 QByteArray opt_name;
1444 int result = s->findOption( d->options, opt, opt_name, def, dummy) & ~4;
1448 fprintf(stderr,
"\n\nFAILURE (KCmdLineArgs):\n");
1449 fprintf(stderr,
"Application requests for getOption(\"%s\") but the \"%s\" option\n",
1450 opt.data(), opt.data());
1451 fprintf(stderr,
"has never been specified via addCmdLineOptions( ... )\n\n");
1463 if (!d->parsedOptionList)
1468 QByteArray value = d->parsedOptionList->take(opt);
1469 if (value.isEmpty())
1471 result.prepend(QString::fromLocal8Bit(value));
1479 Q_FOREACH(
const QString &str, result)
1481 d->parsedOptionList->insertMulti(opt, str.toLocal8Bit());
1490 QByteArray opt = _opt;
1491 QByteArray opt_name;
1494 KCmdLineArgsList::Iterator args = s->argsList->begin();
1495 while (args != s->argsList->end())
1498 result = s->findOption((*args)->d->options, opt, opt_name, def, dummy) & ~4;
1505 fprintf(stderr,
"\n\nFAILURE (KCmdLineArgs):\n");
1506 fprintf(stderr,
"Application requests for isSet(\"%s\") but the \"%s\" option\n",
1507 opt.data(), opt.data());
1508 fprintf(stderr,
"has never been specified via addCmdLineOptions( ... )\n\n");
1515 if (d->parsedOptionList)
1517 value = d->parsedOptionList->value(opt);
1520 if (!value.isEmpty())
1525 return (value.at(0) ==
't');
1533 return (result == 2);
1539 return d->parsedArgList?d->parsedArgList->count():0;
1545 if (!d->parsedArgList || (n >= (
int) d->parsedArgList->count()))
1547 fprintf(stderr,
"\n\nFAILURE (KCmdLineArgs): Argument out of bounds\n");
1548 fprintf(stderr,
"Application requests for arg(%d) without checking count() first.\n",
1555 return QString::fromLocal8Bit(d->parsedArgList->at(n));
1566 const QString urlArg = QString::fromUtf8(_urlArg);
1567 QFileInfo fileInfo(urlArg);
1568 if (!fileInfo.isRelative()) {
1570 result.
setPath(QDir::fromNativeSeparators(urlArg));
1576 result.
setPath(
cwd()+QLatin1Char(
'/')+urlArg);
1581 return KUrl(urlArg);
1585 KCmdLineArgsPrivate::addArgument(
const QByteArray &argument)
1588 parsedArgList =
new KCmdLineParsedArgs;
1590 parsedArgList->append(argument);
1597 tmpopt.
add(
"tempfile",
ki18n(
"The files/URLs opened by the application will be deleted after use") );
1604 return args && args->
isSet(
"tempfile" );
1611 for(
int i = 0; i < s->all_argc; i++) {
1612 char*
arg = s->all_argv[i];
1615 lst.append(QString::fromLocal8Bit(arg));