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 
00247    static void init(int _argc, char **_argv, const char *_appname,
00248                     const char* programName, const char *_description,
00249                     const char *_version, bool noKApp = false);
00256   static void init(int _argc, char **_argv,
00257                    const char *_appname, const char *_description,
00258                    const char *_version, bool noKApp = false) KDE_DEPRECATED;
00259 
00273   static void init(int _argc, char **_argv,
00274                    const KAboutData *about, bool noKApp = false);
00275 
00289   static void init(const KAboutData *about);
00290 
00355   static void addCmdLineOptions( const KCmdLineOptions *options,
00356                  const char *name=0, const char *id = 0,
00357                  const char *afterId=0);
00358 
00368   static KCmdLineArgs *parsedArgs(const char *id=0);
00369 
00379   static QString cwd();
00380 
00385   static const char *appName();
00386 
00394   static void usage(const char *id = 0);
00395 
00400   static void usage(const QString &error);
00401 
00408   static void enable_i18n();
00409 
00410   // Member functions:
00411 
00412 
00431   QCString getOption(const char *option) const;
00432 
00449   QCStringList getOptionList(const char *option) const;
00450 
00465   bool isSet(const char *option) const;
00466 
00473   int count() const;
00474 
00483   const char *arg(int n) const;
00484 
00498   KURL url(int n) const;
00499 
00506   static KURL makeURL( const char * urlArg );
00507 
00514   static void setCwd( char * cwd ) { mCwd = cwd; }
00515 
00519   void clear();
00520 
00528   static void reset();
00529 
00533   static void loadAppArgs( QDataStream &);
00534 
00535 protected:
00540   KCmdLineArgs( const KCmdLineOptions *_options, const char *_name,
00541                 const char *_id);
00542 
00550   ~KCmdLineArgs();
00551 
00552 private:
00558   static void findOption(const char *_opt, QCString opt, int &i, bool enabled, bool &moreOptions);
00559 
00566   static void parseAllArgs();
00567 
00573   static int *qt_argc();
00574 
00581   static char ***qt_argv();
00582 
00590   static void removeArgs(const char *id);
00591 
00597   static void saveAppArgs( QDataStream &);
00598 
00604   void setOption(const QCString &option, bool enabled);
00605 
00611   void setOption(const QCString &option, const char *value);
00612 
00618   void addArgument(const char *argument);
00619 
00625   void save( QDataStream &) const;
00626 
00632   void load( QDataStream &);
00633 
00649   static void initIgnore(int _argc, char **_argv, const char *_appname);
00650 
00651   static void printQ(const QString &msg);
00652 
00653   const KCmdLineOptions *options;
00654   const char *name;
00655   const char *id;
00656   KCmdLineParsedOptions *parsedOptionList;
00657   KCmdLineParsedArgs *parsedArgList;
00658   bool isQt;
00659 
00660   static KCmdLineArgsList *argsList; // All options.
00661   static const KAboutData *about;
00662 
00663   static int argc; // The original argc
00664   static char **argv; // The original argv
00665   static bool parsed; // Whether we have parsed the arguments since calling init
00666   static bool ignoreUnknown; // Ignore unknown options and arguments
00667   static char *mCwd; // Current working directory. Important for KUnqiueApp!
00668   static bool parseArgs;
00669 
00670   KCmdLineArgsPrivate *d;
00671 };
00672 
00673 #endif
00674 
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:33:48 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003