KDECore
kcmdlineargs.h
Go to the documentation of this file.
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 <kdecore_export.h> 00023 #include <QtCore/QBool> 00024 00025 #include <klocale.h> 00026 00027 template <class T> class QList; 00028 class QString; 00029 class QStringList; 00030 class QByteArray; 00031 class QDataStream; 00032 class KUrl; 00033 00034 class KCmdLineArgs; 00035 class KCmdLineArgsPrivate; 00036 class KCmdLineArgsStatic; 00037 class KCmdLineOptionsPrivate; 00038 00048 class KDECORE_EXPORT KCmdLineOptions 00049 { 00050 friend class KCmdLineArgs; 00051 friend class KCmdLineArgsStatic; 00052 00053 public: 00057 KCmdLineOptions (); 00058 00062 KCmdLineOptions (const KCmdLineOptions &options); 00063 00067 KCmdLineOptions& operator= (const KCmdLineOptions &options); 00068 00072 ~KCmdLineOptions (); 00073 00121 KCmdLineOptions &add (const QByteArray &name, 00122 const KLocalizedString &description = KLocalizedString(), 00123 const QByteArray &defaultValue = QByteArray()); 00124 00130 KCmdLineOptions &add (const KCmdLineOptions &options); 00131 00132 private: 00133 00134 KCmdLineOptionsPrivate *d; //krazy:exclude=dpointer (for operator=) 00135 }; 00136 00137 class KCmdLineArgsList; 00138 class KApplication; 00139 class KAboutData; 00140 00281 class KDECORE_EXPORT KCmdLineArgs 00282 { 00283 friend class KApplication; 00284 friend class KCmdLineArgsList; 00285 friend class KCmdLineArgsStatic; 00286 public: 00287 // Static functions: 00288 00289 enum StdCmdLineArg { 00290 CmdLineArgQt = 0x01, 00291 CmdLineArgKDE = 0x02, 00292 CmdLineArgsMask=0x03, 00293 CmdLineArgNone = 0x00, 00294 Reserved = 0xff 00295 }; 00296 Q_DECLARE_FLAGS(StdCmdLineArgs, StdCmdLineArg) 00315 static void init(int argc, char **argv, 00316 const QByteArray &appname, 00317 const QByteArray &catalog, 00318 const KLocalizedString &programName, 00319 const QByteArray &version, 00320 const KLocalizedString &description = KLocalizedString(), 00321 StdCmdLineArgs stdargs=StdCmdLineArgs(CmdLineArgQt|CmdLineArgKDE)); 00322 00335 static void init(int _argc, 00336 char **_argv, 00337 const KAboutData *about, 00338 StdCmdLineArgs stdargs=StdCmdLineArgs(CmdLineArgQt|CmdLineArgKDE)); 00352 static void init(const KAboutData *about); 00353 00357 static void addStdCmdLineOptions(StdCmdLineArgs stdargs=StdCmdLineArgs(CmdLineArgQt|CmdLineArgKDE)); 00358 00422 static void addCmdLineOptions(const KCmdLineOptions &options, 00423 const KLocalizedString &name = KLocalizedString(), 00424 const QByteArray &id = QByteArray(), 00425 const QByteArray &afterId = QByteArray()); 00426 00436 static KCmdLineArgs *parsedArgs(const QByteArray &id = QByteArray()); 00437 00447 static QString cwd(); 00448 00453 static QString appName(); 00454 00462 static void usage(const QByteArray &id = QByteArray()); 00463 00468 static void usageError(const QString &error); 00469 00476 static void enable_i18n(); 00477 00478 // Member functions: 00479 00480 00499 QString getOption(const QByteArray &option) const; 00500 00517 QStringList getOptionList(const QByteArray &option) const; 00518 00533 bool isSet(const QByteArray &option) const; 00534 00541 int count() const; 00542 00551 QString arg(int n) const; 00552 00566 KUrl url(int n) const; 00567 00574 static KUrl makeURL( const QByteArray &urlArg ); 00575 00582 static void setCwd( const QByteArray &cwd ); 00583 00587 void clear(); 00588 00596 static void reset(); 00597 00601 static void loadAppArgs( QDataStream &); 00602 00608 static void saveAppArgs( QDataStream &); 00609 00613 static void addTempFileOption(); 00614 00615 // this avoids having to know the "id" used by addTempFileOption 00616 // but this approach doesn't scale well, we can't have 50 standard options here... 00620 static bool isTempFileSet(); 00621 00627 static int &qtArgc(); 00628 00637 static char **qtArgv(); 00638 00643 static QStringList allArguments(); 00644 00648 static const KAboutData *aboutData(); 00649 00650 protected: 00655 KCmdLineArgs( const KCmdLineOptions &_options, const KLocalizedString &_name, 00656 const QByteArray &_id); 00657 00665 ~KCmdLineArgs(); 00666 00667 private: 00668 00684 static void initIgnore(int _argc, char **_argv, const QByteArray &_appname); 00685 00686 KCmdLineArgsPrivate *const d; 00687 }; 00688 00689 Q_DECLARE_OPERATORS_FOR_FLAGS(KCmdLineArgs::StdCmdLineArgs) 00690 00691 #endif 00692
KDE 4.6 API Reference