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 "kdemacros.h"
00023 #include <kurl.h>
00024 
00025 #include <qptrlist.h>
00026 #include <qstring.h>
00027 #include <qvaluelist.h>
00028 
00029 typedef QValueList<QCString> QCStringList;
00030 
00040 struct KCmdLineOptions
00041 {
00055    const char *name;
00060    const char *description;
00065    const char *def; // Default
00066 };
00067 
00068 #define KCmdLineLastOption { 0, 0, 0 }
00069 
00070 class KCmdLineArgsList;
00071 class KApplication;
00072 class KUniqueApplication;
00073 class KCmdLineParsedOptions;
00074 class KCmdLineParsedArgs;
00075 class KAboutData;
00076 class KCmdLineArgsPrivate;
00077 
00222 class KCmdLineArgs
00223 {
00224   friend class KApplication;
00225   friend class KUniqueApplication;
00226   friend class QPtrList<KCmdLineArgs>;
00227 public:
00228   // Static functions:
00229 
00249    static void init(int _argc, char **_argv, const char *_appname,
00250                     const char* programName, const char *_description,
00251                     const char *_version, bool noKApp = false);
00258   static void init(int _argc, char **_argv,
00259                    const char *_appname, const char *_description,
00260                    const char *_version, bool noKApp = false) KDE_DEPRECATED;
00261 
00275   static void init(int _argc, char **_argv,
00276                    const KAboutData *about, bool noKApp = false);
00277 
00291   static void init(const KAboutData *about);
00292 
00357   static void addCmdLineOptions( const KCmdLineOptions *options,
00358                  const char *name=0, const char *id = 0,
00359                  const char *afterId=0);
00360 
00370   static KCmdLineArgs *parsedArgs(const char *id=0);
00371 
00381   static QString cwd();
00382 
00387   static const char *appName();
00388 
00396   static void usage(const char *id = 0);
00397 
00402   static void usage(const QString &error);
00403 
00410   static void enable_i18n();
00411 
00412   // Member functions:
00413 
00414 
00433   QCString getOption(const char *option) const;
00434 
00451   QCStringList getOptionList(const char *option) const;
00452 
00467   bool isSet(const char *option) const;
00468 
00475   int count() const;
00476 
00485   const char *arg(int n) const;
00486 
00500   KURL url(int n) const;
00501 
00508   static KURL makeURL( const char * urlArg );
00509 
00516   static void setCwd( char * cwd ) { mCwd = cwd; }
00517 
00521   void clear();
00522 
00530   static void reset();
00531 
00535   static void loadAppArgs( QDataStream &);
00536 
00537 protected:
00542   KCmdLineArgs( const KCmdLineOptions *_options, const char *_name,
00543                 const char *_id);
00544 
00552   ~KCmdLineArgs();
00553 
00554 private:
00560   static void findOption(const char *_opt, QCString opt, int &i, bool enabled, bool &moreOptions);
00561 
00568   static void parseAllArgs();
00569 
00575   static int *qt_argc();
00576 
00583   static char ***qt_argv();
00584 
00592   static void removeArgs(const char *id);
00593 
00599   static void saveAppArgs( QDataStream &);
00600 
00606   void setOption(const QCString &option, bool enabled);
00607 
00613   void setOption(const QCString &option, const char *value);
00614 
00620   void addArgument(const char *argument);
00621 
00627   void save( QDataStream &) const;
00628 
00634   void load( QDataStream &);
00635 
00651   static void initIgnore(int _argc, char **_argv, const char *_appname);
00652 
00653   static void printQ(const QString &msg);
00654 
00655   const KCmdLineOptions *options;
00656   const char *name;
00657   const char *id;
00658   KCmdLineParsedOptions *parsedOptionList;
00659   KCmdLineParsedArgs *parsedArgList;
00660   bool isQt;
00661 
00662   static KCmdLineArgsList *argsList; // All options.
00663   static const KAboutData *about;
00664 
00665   static int argc; // The original argc
00666   static char **argv; // The original argv
00667   static bool parsed; // Whether we have parsed the arguments since calling init
00668   static bool ignoreUnknown; // Ignore unknown options and arguments
00669   static char *mCwd; // Current working directory. Important for KUnqiueApp!
00670   static bool parseArgs;
00671 
00672   KCmdLineArgsPrivate *d;
00673 };
00674 
00675 #endif
00676 
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jan 22 16:43:38 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003