kdecore Library API Documentation

kcmdlineargs.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #ifndef _KCMDLINEARGS_H_
00020 #define _KCMDLINEARGS_H_
00021 
00022 #include <kurl.h>
00023 
00024 #include <qptrlist.h>
00025 #include <qstring.h>
00026 #include <qvaluelist.h>
00027 
00028 typedef QValueList<QCString> QCStringList;
00029 
00033 struct KCmdLineOptions
00034 {
00035    const char *name;
00036    const char *description;
00037    const char *def; // Default
00038 };
00039 
00040 #define KCmdLineLastOption { 0, 0, 0 }
00041 
00042 class KCmdLineArgsList;
00043 class KApplication;
00044 class KUniqueApplication;
00045 class KCmdLineParsedOptions;
00046 class KCmdLineParsedArgs;
00047 class KAboutData;
00048 class KCmdLineArgsPrivate;
00049 
00190 class KCmdLineArgs
00191 {
00192   friend class KApplication;
00193   friend class KUniqueApplication;
00194   friend class QPtrList<KCmdLineArgs>;
00195 public:
00196   // Static functions:
00197 
00211   static void init(int _argc, char **_argv,
00212                    const char *_appname, const char *_description,
00213                    const char *_version, bool noKApp = false);
00214 
00225   static void init(int _argc, char **_argv,
00226                    const KAboutData *about, bool noKApp = false);
00227 
00238   static void init(const KAboutData *about);
00239 
00292   static void addCmdLineOptions( const KCmdLineOptions *options,
00293                                  const char *name=0, const char *id = 0,
00294                                  const char *afterId=0);
00295 
00305   static KCmdLineArgs *parsedArgs(const char *id=0);
00306 
00316   static QString cwd();
00317 
00322   static const char *appName();
00323 
00331   static void usage(const char *id = 0);
00332 
00337   static void usage(const QString &error);
00338 
00345   static void enable_i18n();
00346 
00347   // Member functions:
00348 
00349 
00366   QCString getOption(const char *option) const;
00367 
00382   QCStringList getOptionList(const char *option) const;
00383 
00400   bool isSet(const char *option) const;
00401 
00408   int count() const;
00409 
00418   const char *arg(int n) const;
00419 
00433   KURL url(int n) const;
00434 
00441   static KURL makeURL( const char * urlArg );
00442 
00449   static void setCwd( char * cwd ) { mCwd = cwd; }
00450 
00454   void clear();
00455 
00456 
00457 protected:
00462   KCmdLineArgs( const KCmdLineOptions *_options, const char *_id,
00463                 const char *_name);
00464 
00472   ~KCmdLineArgs();
00473 
00474 private:
00480   static void findOption(const char *_opt, QCString opt, int &i, bool enabled, bool &moreOptions);
00481 
00488   static void parseAllArgs();
00489 
00495   static int *qt_argc();
00496 
00503   static char ***qt_argv();
00504 
00512   static void removeArgs(const char *id);
00513 
00514 
00520   static void saveAppArgs( QDataStream &);
00521 
00527   static void loadAppArgs( QDataStream &);
00528 
00534   void setOption(const QCString &option, bool enabled);
00535 
00541   void setOption(const QCString &option, const char *value);
00542 
00548   void addArgument(const char *argument);
00549 
00555   void save( QDataStream &) const;
00556 
00562   void load( QDataStream &);
00563 
00579   static void initIgnore(int _argc, char **_argv, const char *_appname);
00580 
00581   static void printQ(const QString &msg);
00582 
00583   const KCmdLineOptions *options;
00584   const char *name;
00585   const char *id;
00586   KCmdLineParsedOptions *parsedOptionList;
00587   KCmdLineParsedArgs *parsedArgList;
00588   bool isQt;
00589 
00590   static KCmdLineArgsList *argsList; // All options.
00591   static const KAboutData *about;
00592 
00593   static int argc; // The original argc
00594   static char **argv; // The original argv
00595   static bool parsed; // Whether we have parsed the arguments since calling init
00596   static bool ignoreUnknown; // Ignore unknown options and arguments
00597   static char *mCwd; // Current working directory. Important for KUnqiueApp!
00598 
00599   KCmdLineArgsPrivate *d;
00600 };
00601 
00602 #endif
00603 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:21 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001