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., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #ifndef _KCMDLINEARGS_H_ 00020 #define _KCMDLINEARGS_H_ 00021 00022 #include "kdelibs_export.h" 00023 #include <kurl.h> 00024 00025 #include <tqptrlist.h> 00026 #include <tqstring.h> 00027 #include <tqvaluelist.h> 00028 00029 typedef TQValueList<TQCString> QCStringList; 00030 00040 struct KDECORE_EXPORT 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 KDECORE_EXPORT KCmdLineArgs 00223 { 00224 friend class KApplication; 00225 friend class KUniqueApplication; 00226 friend class TQPtrList<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 TQString cwd(); 00382 00387 static const char *appName(); 00388 00396 static void usage(const char *id = 0); 00397 00402 static void usage(const TQString &error); 00403 00410 static void enable_i18n(); 00411 00412 // Member functions: 00413 00414 00433 TQCString 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( TQDataStream &); 00536 00541 static void addTempFileOption(); 00542 00543 // this avoids having to know the "id" used by addTempFileOption 00544 // but this approach doesn't scale well, we can't have 50 standard options here... 00549 static bool isTempFileSet(); 00550 00551 protected: 00556 KCmdLineArgs( const KCmdLineOptions *_options, const char *_name, 00557 const char *_id); 00558 00566 ~KCmdLineArgs(); 00567 00568 private: 00574 static void findOption(const char *_opt, TQCString opt, int &i, bool enabled, bool &moreOptions); 00575 00582 static void parseAllArgs(); 00583 00589 static int *qt_argc(); 00590 00597 static char ***qt_argv(); 00598 00606 static void removeArgs(const char *id); 00607 00613 static void saveAppArgs( TQDataStream &); 00614 00620 void setOption(const TQCString &option, bool enabled); 00621 00627 void setOption(const TQCString &option, const char *value); 00628 00634 void addArgument(const char *argument); 00635 00641 void save( TQDataStream &) const; 00642 00648 void load( TQDataStream &); 00649 00665 static void initIgnore(int _argc, char **_argv, const char *_appname); 00666 00667 static void printQ(const TQString &msg); 00668 00669 const KCmdLineOptions *options; 00670 const char *name; 00671 const char *id; 00672 KCmdLineParsedOptions *parsedOptionList; 00673 KCmdLineParsedArgs *parsedArgList; 00674 bool isQt; 00675 00676 static KCmdLineArgsList *argsList; // All options. 00677 static const KAboutData *about; 00678 00679 static int argc; // The original argc 00680 static char **argv; // The original argv 00681 static bool parsed; // Whether we have parsed the arguments since calling init 00682 static bool ignoreUnknown; // Ignore unknown options and arguments 00683 static char *mCwd; // Current working directory. Important for KUnqiueApp! 00684 static bool parseArgs; 00685 00686 KCmdLineArgsPrivate *d; 00687 }; 00688 00689 #endif 00690