From f037da190037979080d407f3c6f0a88026b6bb91 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 14 Feb 2013 17:10:09 -0600 Subject: Rename common header files for consistency with class renaming --- src/common/global/generic_config.cpp | 2 +- src/common/global/global.h | 10 +- src/common/gui/editlistbox.cpp | 2 +- src/common/nokde/nokde.pro | 4 +- src/common/nokde/nokde_kaboutdata.cpp | 467 ---------- src/common/nokde/nokde_kaboutdata.h | 571 ------------- src/common/nokde/nokde_kcmdlineargs.cpp | 1329 ----------------------------- src/common/nokde/nokde_kcmdlineargs.h | 701 --------------- src/common/nokde/nokde_tdeaboutdata.cpp | 467 ++++++++++ src/common/nokde/nokde_tdeaboutdata.h | 571 +++++++++++++ src/common/nokde/nokde_tdecmdlineargs.cpp | 1329 +++++++++++++++++++++++++++++ src/common/nokde/nokde_tdecmdlineargs.h | 701 +++++++++++++++ src/libgui/global_config.cpp | 2 +- src/libgui/likeback.cpp | 6 +- src/libgui/project_manager.cpp | 2 +- src/libgui/text_editor.cpp | 2 +- src/libgui/toplevel.cpp | 4 +- 17 files changed, 3085 insertions(+), 3085 deletions(-) delete mode 100644 src/common/nokde/nokde_kaboutdata.cpp delete mode 100644 src/common/nokde/nokde_kaboutdata.h delete mode 100644 src/common/nokde/nokde_kcmdlineargs.cpp delete mode 100644 src/common/nokde/nokde_kcmdlineargs.h create mode 100644 src/common/nokde/nokde_tdeaboutdata.cpp create mode 100644 src/common/nokde/nokde_tdeaboutdata.h create mode 100644 src/common/nokde/nokde_tdecmdlineargs.cpp create mode 100644 src/common/nokde/nokde_tdecmdlineargs.h (limited to 'src') diff --git a/src/common/global/generic_config.cpp b/src/common/global/generic_config.cpp index 48c705b..63f3f08 100644 --- a/src/common/global/generic_config.cpp +++ b/src/common/global/generic_config.cpp @@ -19,7 +19,7 @@ public: TQSettings _settings; }; #else -# include +# include # include class GenericConfigPrivate { diff --git a/src/common/global/global.h b/src/common/global/global.h index 0bc0b58..8dee015 100644 --- a/src/common/global/global.h +++ b/src/common/global/global.h @@ -26,14 +26,14 @@ # include "tqt_config.h" # include "common/nokde/nokde_kurl.h" # include "common/nokde/nokde_klocale.h" -# include "common/nokde/nokde_kaboutdata.h" -# include "common/nokde/nokde_kcmdlineargs.h" +# include "common/nokde/nokde_tdeaboutdata.h" +# include "common/nokde/nokde_tdecmdlineargs.h" #else # include "config.h" -# include +# include # include -# include -# include +# include +# include # include # include #endif diff --git a/src/common/gui/editlistbox.cpp b/src/common/gui/editlistbox.cpp index 432aacd..126f996 100644 --- a/src/common/gui/editlistbox.cpp +++ b/src/common/gui/editlistbox.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/common/nokde/nokde.pro b/src/common/nokde/nokde.pro index aa92599..ab37fbd 100644 --- a/src/common/nokde/nokde.pro +++ b/src/common/nokde/nokde.pro @@ -2,7 +2,7 @@ STOPDIR = ../../.. include($${STOPDIR}/lib.pro) TARGET = nokde -HEADERS += nokde_klocale.h nokde_kaboutdata.h nokde_kcmdlineargs.h nokde_kprocess.h -SOURCES += nokde_klocale.cpp nokde_kaboutdata.cpp nokde_kcmdlineargs.cpp nokde_kprocess.cpp +HEADERS += nokde_klocale.h nokde_tdeaboutdata.h nokde_tdecmdlineargs.h nokde_kprocess.h +SOURCES += nokde_klocale.cpp nokde_tdeaboutdata.cpp nokde_tdecmdlineargs.cpp nokde_kprocess.cpp win32:HEADERS += win32_utils.h win32:SOURCES += win32_utils.c \ No newline at end of file diff --git a/src/common/nokde/nokde_kaboutdata.cpp b/src/common/nokde/nokde_kaboutdata.cpp deleted file mode 100644 index 8b0a4fe..0000000 --- a/src/common/nokde/nokde_kaboutdata.cpp +++ /dev/null @@ -1,467 +0,0 @@ -// modified from KDE 3.4 for Windows port (Nicolas Hadacek) - -/* - * This file is part of the KDE Libraries - * Copyright (C) 2000 Espen Sand (espen@kde.org) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - - -#include "nokde_kaboutdata.h" -//#include -#include -#include -#include - -TQString -TDEAboutPerson::name() const -{ - return TQString::fromUtf8(mName); -} - -TQString -TDEAboutPerson::task() const -{ - if (mTask && *mTask) - return i18n(mTask); - else - return TQString(); -} - -TQString -TDEAboutPerson::emailAddress() const -{ - return TQString::fromUtf8(mEmailAddress); -} - - -TQString -TDEAboutPerson::webAddress() const -{ - return TQString::fromUtf8(mWebAddress); -} - - -TDEAboutTranslator::TDEAboutTranslator(const TQString & name, - const TQString & emailAddress) -{ - mName=name; - mEmail=emailAddress; -} - -TQString TDEAboutTranslator::name() const -{ - return mName; -} - -TQString TDEAboutTranslator::emailAddress() const -{ - return mEmail; -} - -class TDEAboutDataPrivate -{ -public: - TDEAboutDataPrivate() - : translatorName("_: NAME OF TRANSLATORS\nYour names") - , translatorEmail("_: EMAIL OF TRANSLATORS\nYour emails") - , productName(0) -// , programLogo(0) - {} - ~TDEAboutDataPrivate() - { -// delete programLogo; - } - const char *translatorName; - const char *translatorEmail; - const char *productName; -// TQImage* programLogo; -}; - - - -TDEAboutData::TDEAboutData( const char *appName, - const char *programName, - const char *version, - const char *shortDescription, - int licenseType, - const char *copyrightStatement, - const char *text, - const char *homePageAddress, - const char *bugsEmailAddress - ) : - mProgramName( programName ), - mVersion( version ), - mShortDescription( shortDescription ), - mLicenseKey( licenseType ), - mCopyrightStatement( copyrightStatement ), - mOtherText( text ), - mHomepageAddress( homePageAddress ), - mBugEmailAddress( bugsEmailAddress ), - mLicenseText (0) -{ - d = new TDEAboutDataPrivate; - - if( appName ) { - const char *p = strrchr(appName, '/'); - if( p ) - mAppName = p+1; - else - mAppName = appName; - } else - mAppName = 0; -} - -TDEAboutData::~TDEAboutData() -{ - if (mLicenseKey == License_File) - delete [] mLicenseText; - delete d; -} - -void -TDEAboutData::addAuthor( const char *name, const char *task, - const char *emailAddress, const char *webAddress ) -{ - mAuthorList.append(TDEAboutPerson(name,task,emailAddress,webAddress)); -} - -void -TDEAboutData::addCredit( const char *name, const char *task, - const char *emailAddress, const char *webAddress ) -{ - mCreditList.append(TDEAboutPerson(name,task,emailAddress,webAddress)); -} - -void -TDEAboutData::setTranslator( const char *name, const char *emailAddress) -{ - d->translatorName=name; - d->translatorEmail=emailAddress; -} - -void -TDEAboutData::setLicenseText( const char *licenseText ) -{ - mLicenseText = licenseText; - mLicenseKey = License_Custom; -} - -void -TDEAboutData::setLicenseTextFile( const TQString &file ) -{ - mLicenseText = tqstrdup(TQFile::encodeName(file)); - mLicenseKey = License_File; -} - -void -TDEAboutData::setAppName( const char *appName ) -{ - mAppName = appName; -} - -void -TDEAboutData::setProgramName( const char* programName ) -{ - mProgramName = programName; -} - -void -TDEAboutData::setVersion( const char* version ) -{ - mVersion = version; -} - -void -TDEAboutData::setShortDescription( const char *shortDescription ) -{ - mShortDescription = shortDescription; -} - -void -TDEAboutData::setLicense( LicenseKey licenseKey) -{ - mLicenseKey = licenseKey; -} - -void -TDEAboutData::setCopyrightStatement( const char *copyrightStatement ) -{ - mCopyrightStatement = copyrightStatement; -} - -void -TDEAboutData::setOtherText( const char *otherText ) -{ - mOtherText = otherText; -} - -void -TDEAboutData::setHomepage( const char *homepage ) -{ - mHomepageAddress = homepage; -} - -void -TDEAboutData::setBugAddress( const char *bugAddress ) -{ - mBugEmailAddress = bugAddress; -} - -void -TDEAboutData::setProductName( const char *productName ) -{ - d->productName = productName; -} - -const char * -TDEAboutData::appName() const -{ - return mAppName; -} - -const char * -TDEAboutData::productName() const -{ - if (d->productName) - return d->productName; - else - return appName(); -} - -TQString -TDEAboutData::programName() const -{ - if (mProgramName && *mProgramName) - return i18n(mProgramName); - else - return TQString(); -} -/* -TQImage -TDEAboutData::programLogo() const -{ - return d->programLogo ? (*d->programLogo) : TQImage(); -} - -void -TDEAboutData::setProgramLogo(const TQImage& image) -{ - if (!d->programLogo) - d->programLogo = new TQImage( image ); - else - *d->programLogo = image; -} -*/ -TQString -TDEAboutData::version() const -{ - return TQString::fromLatin1(mVersion); -} - -TQString -TDEAboutData::shortDescription() const -{ - if (mShortDescription && *mShortDescription) - return i18n(mShortDescription); - else - return TQString(); -} - -TQString -TDEAboutData::homepage() const -{ - return TQString::fromLatin1(mHomepageAddress); -} - -TQString -TDEAboutData::bugAddress() const -{ - return TQString::fromLatin1(mBugEmailAddress); -} - -const TQValueList -TDEAboutData::authors() const -{ - return mAuthorList; -} - -const TQValueList -TDEAboutData::credits() const -{ - return mCreditList; -} - -const TQValueList -TDEAboutData::translators() const -{ - TQValueList personList; - - if(d->translatorName == 0) - return personList; - - TQStringList nameList; - TQStringList emailList; - - TQString names = i18n(d->translatorName); - if(names != TQString::fromUtf8(d->translatorName)) - { -#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 - nameList = TQStringList::split(',',names); -#else - nameList = names.split(',', TQString::SkipEmptyParts); -#endif - } - - - if(d->translatorEmail) - { - TQString emails = i18n(d->translatorEmail); - - if(emails != TQString::fromUtf8(d->translatorEmail)) - { -#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 - emailList = TQStringList::split(',',emails,true); -#else - emailList = emails.split(','); -#endif - } - } - - - TQStringList::Iterator nit; - TQStringList::Iterator eit=emailList.begin(); - - for(nit = nameList.begin(); nit != nameList.end(); ++nit) - { - TQString email; - if(eit != emailList.end()) - { - email=*eit; - ++eit; - } - - TQString name=*nit; - -#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 - personList.append(TDEAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace())); -#else - personList.append(TDEAboutTranslator(name.trimmed(), email.trimmed())); -#endif - } - - return personList; -} - -TQString -TDEAboutData::aboutTranslationTeam() -{ - return i18n("replace this with information about your translation team", - "

TDE is translated into many languages thanks to the work " - "of many people all over the world.

"); -} - -TQString -TDEAboutData::otherText() const -{ - if (mOtherText && *mOtherText) - return i18n(mOtherText); - else - return TQString(); -} - - -TQString -TDEAboutData::license() const -{ - TQString result; - if (!copyrightStatement().isEmpty()) - result = copyrightStatement() + "\n\n"; - - TQString l; - TQString f; - switch ( mLicenseKey ) - { - case License_File: - f = TQFile::decodeName(mLicenseText); - break; - case License_GPL_V2: - l = "GPL v2"; - f = locate("data", "LICENSES/GPL_V2"); - break; - case License_LGPL_V2: - l = "LGPL v2"; - f = locate("data", "LICENSES/LGPL_V2"); - break; - case License_BSD: - l = "BSD License"; - f = locate("data", "LICENSES/BSD"); - break; - case License_Artistic: - l = "Artistic License"; - f = locate("data", "LICENSES/ARTISTIC"); - break; - case License_TQPL_V1_0: - l = "TQPL v1.0"; - f = locate("data", "LICENSES/TQPL_V1.0"); - break; - case License_Custom: - if (mLicenseText && *mLicenseText) - return( i18n(mLicenseText) ); - // fall through - default: - result += i18n("No licensing terms for this program have been specified.\n" - "Please check the documentation or the source for any\n" - "licensing terms.\n"); - return result; - } - - if (!l.isEmpty()) - result += i18n("This program is distributed under the terms of the %1.").arg( l ); - - if (!f.isEmpty()) - { - TQFile file(f); -#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 - if (file.open(IO_ReadOnly)) -#else - if (file.open(TQIODevice::ReadOnly)) -#endif - { - result += '\n'; - result += '\n'; - TQTextStream str(&file); -#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 - result += str.read(); -#else - result += str.readAll(); -#endif - } - } - - return result; -} - -TQString -TDEAboutData::copyrightStatement() const -{ - if (mCopyrightStatement && *mCopyrightStatement) - return i18n(mCopyrightStatement); - else - return TQString(); -} diff --git a/src/common/nokde/nokde_kaboutdata.h b/src/common/nokde/nokde_kaboutdata.h deleted file mode 100644 index 93a7768..0000000 --- a/src/common/nokde/nokde_kaboutdata.h +++ /dev/null @@ -1,571 +0,0 @@ -// modified from KDE 3.4 for Windows port (Nicolas Hadacek) - -/* - * This file is part of the KDE Libraries - * Copyright (C) 2000 Espen Sand (espen@kde.org) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - */ - -#include -#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 -# include -#else -# include -# define TQValueList Q3ValueList -# include -#endif -#include -//#include - -#include "nokde_klocale.h" - -#ifndef _KABOUTDATA_H_ -#define _KABOUTDATA_H_ - -class TDEAboutPersonPrivate; -class TDEAboutDataPrivate; - -/** - * This structure is used to store information about a person or developer. - * It can store the person's name, a task, an email address and a - * link to a home page. This class is intended for use in the - * TDEAboutData class, but it can be used elsewhere as well. - * Normally you should at least define the person's name. - * - * Example Usage within a main(): - * - * TDEAboutData about("khello", I18N_NOOP("KHello"), "0.1", - * I18N_NOOP("A TDE version of Hello, world!"), - * TDEAboutData::License_LGPL, - * I18N_NOOP("Copyright (c) 2003 Developer")); - * - * about.addAuthor("Joe Developer", I18N_NOOP("developer"), "joe@host.com", 0); - * about.addCredit("Joe User", I18N_NOOP("A lot of bug reports"), - * "joe.user@host.org", 0); - * TDECmdLineArgs::init(argc, argv, &about); - */ -class TDECORE_EXPORT TDEAboutPerson -{ -public: - /** - * Convenience constructor - * - * @param name The name of the person. - * - * @param task The task of this person. This string should be - * marked for translation, e.g. - * I18N_NOOP("Task description....") - * - * @param emailAddress The email address of the person. - * - * @param webAddress Home page of the person. - */ - TDEAboutPerson( const char *name, const char *task, - const char *emailAddress, const char *webAddress ) - { - mName = name; - mTask = task; - mEmailAddress = emailAddress; - mWebAddress = webAddress; - } - /** - * @internal - * Don't use. Required by TQValueList - */ - TDEAboutPerson() {} - - /** - * The person's name - * @return the person's name (can be TQString(), if it has been - * constructed with a null name) - */ - TQString name() const; - - /** - * The person's task - * @return the person's task (can be TQString(), if it has been - * constructed with a null task) - */ - TQString task() const; - - /** - * The person's email address - * @return the person's email address (can be TQString(), if it has been - * constructed with a null email) - */ - TQString emailAddress() const; - - /** - * The home page or a relevant link - * @return the persons home page (can be TQString(), if it has been - * constructed with a null home page) - */ - TQString webAddress() const; - -private: - const char *mName; - const char *mTask; - const char *mEmailAddress; - const char *mWebAddress; - - TDEAboutPersonPrivate *d; -}; - -class TDEAboutTranslatorPrivate; -/** - * This structure is used to store information about a translator. - * It can store the translator's name and an email address. - * This class is intended for use in the TDEAboutData class, - * but it can be used elsewhere as well. - * Normally you should at least define the translator's name. - * - * It's not possible to use TDEAboutPerson for this, because - * TDEAboutPerson stores internally only const char* pointers, but the - * translator information is generated dynamically from the translation - * of a dummy string. -*/ -class TDECORE_EXPORT TDEAboutTranslator -{ -public: - /** - * Convenience constructor - * - * @param name The name of the person. - * - * @param emailAddress The email address of the person. - */ - TDEAboutTranslator(const TQString & name=TQString(), - const TQString & emailAddress=TQString()); - - /** - * The translator's name - * @return the translators's name (can be TQString(), if it has been - * constructed with a null name) - */ - TQString name() const; - - /** - * The translator's email - * @return the translator's email address (can be TQString(), if it has been - * constructed with a null email) - */ - TQString emailAddress() const; - -private: - TQString mName; - TQString mEmail; - TDEAboutTranslatorPrivate* d; -}; - - -/** - * This class is used to store information about a program. It can store - * such values as version number, program name, home page, email address - * for bug reporting, multiple authors and contributors - * (using TDEAboutPerson), license and copyright information. - * - * Currently, the values set here are shown by the "About" box - * (see TDEAboutDialog), used by the bug report dialog (see KBugReport), - * and by the help shown on command line (see TDECmdLineArgs). - * - * @short Holds information needed by the "About" box and other - * classes. - * @author Espen Sand (espen@kde.org), David Faure (faure@kde.org) - */ -class TDECORE_EXPORT TDEAboutData -{ - public: - /** - * Descibes the license of the software. - */ - enum LicenseKey - { - License_Custom = -2, - License_File = -1, - License_Unknown = 0, - License_GPL = 1, - License_GPL_V2 = 1, - License_LGPL = 2, - License_LGPL_V2 = 2, - License_BSD = 3, - License_Artistic = 4, - License_TQPL = 5, - License_TQPL_V1_0 = 5 - }; - - public: - /** - * Constructor. - * - * @param appName The program name used internally. Example: "kedit" - * - * @param programName A displayable program name string. This string - * should be marked for translation. Example: I18N_NOOP("KEdit") - * - * @param version The program version string. - * - * @param shortDescription A short description of what the program does. - * This string should be marked for translation. - * Example: I18N_NOOP("A simple text editor.") - * - * @param licenseType The license identifier. Use setLicenseText if - * you use a license not predefined here. - * - * @param copyrightStatement A copyright statement, that can look like this: - * "(c) 1999-2000, Name". The string specified here is not modified - * in any manner. The author information from addAuthor is not - * used. - * - * @param text Some free form text, that can contain any kind of - * information. The text can contain newlines. This string - * should be marked for translation. - * - * @param homePageAddress The program homepage string. - * Start the address with "http://". "http://some.domain" is - * is correct, "some.domain" is not. - * - * @param bugsEmailAddress The bug report email address string. - * This defaults to the kde.org bug system. - * - */ - TDEAboutData( const char *appName, - const char *programName, - const char *version, - const char *shortDescription = 0, - int licenseType = License_Unknown, - const char *copyrightStatement = 0, - const char *text = 0, - const char *homePageAddress = 0, - const char *bugsEmailAddress = "submit@bugs.kde.org" - ); - - ~TDEAboutData(); - - /** - * Defines an author. You can call this function as many times you - * need. Each entry is appended to a list. The person in the first entry - * is assumed to be the leader of the project. - * - * @param name The developer's name in UTF-8 encoding. - * - * @param task What the person is responsible for. This text can contain - * newlines. It should be marked for translation like this: - * I18N_NOOP("Task description..."). Can be 0. - * - * @param emailAddress An Email address where the person can be reached. - * Can be 0. - * - * @param webAddress The person's homepage or a relevant link. - * Start the address with "http://". "http://some.domain" is - * correct, "some.domain" is not. Can be 0. - * - */ - void addAuthor( const char *name, - const char *task=0, - const char *emailAddress=0, - const char *webAddress=0 ); - - /** - * Defines a person that deserves credit. You can call this function - * as many times you need. Each entry is appended to a list. - * - * @param name The person's name in UTF-8 encoding. - * - * @param task What the person has done to deserve the honor. The - * text can contain newlines. It should be marked for - * translation like this: I18N_NOOP("Task description...") - * Can be 0. - * - * @param emailAddress An Email address when the person can be reached. - * Can be 0. - * - * @param webAddress The person's homepage or a relevant link. - * Start the address with "http://". "http://some.domain" is - * is correct, "some.domain" is not. Can be 0. - * - */ - void addCredit( const char *name, - const char *task=0, - const char *emailAddress=0, - const char *webAddress=0 ); - - /** - * Sets the name of the translator of the gui. Since this depends - * on the language, just use a dummy text marked for translation. - * - * For example: - * \code - * setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\\nYour names") - * ,I18N_NOOP("_: EMAIL OF TRANSLATORS\\nYour emails")); - * \endcode - * - * The translator can then translate this dummy text with his name - * or with a list of names separated with ",". - * If there is no translation or the application is used with the - * default language, this function call is ignored. - * - * Note: If you are using the default KDE automake environment, - * there is no need to use this function, because the two - * default strings above are added to the applications po file - * automatically. - * - * @param name the name of the translator - * @param emailAddress the email address of the translator - * @see TDEAboutTranslator - */ - void setTranslator(const char* name, const char* emailAddress); - - /** - * Defines a license text. - * - * The text will be translated if it got marked for - * translations with the I18N_NOOP() macro. - * - * Example: - * \code - * setLicenseText( I18N_NOOP("This is my license")); - * \endcode - * - * NOTE: No copy of the text is made. - * - * @param license The license text in utf8 encoding. - */ - void setLicenseText( const char *license ); - - /** - * Defines a license text. - * - * @param file File containing the license text. - */ - void setLicenseTextFile( const TQString &file ); - - /** - * Defines the program name used internally. - * - * @param appName The application name. Example: "kate". - */ - void setAppName( const char *appName ); - - /** - * Defines the displayable program name string. - * - * @param programName The program name. This string should be - * marked for translation. - * Example: I18N_NOOP("Advanced Text Editor"). - */ - void setProgramName( const char* programName ); - - /** - * Defines the program logo. - * Use this if you need to have application logo - * in AboutData other than application icon. - * - * @param image logo image. - * @see programLogo() - * @since 3.4 - */ -// void setProgramLogo(const TQImage& image); - - /** - * Defines the program version string. - * - * @param version The program version. - */ - void setVersion( const char* version ); - - /** - * Defines a short description of what the program does. - * - * @param shortDescription The program description This string should be marked - * for translation. Example: I18N_NOOP("An advanced text editor - * with syntax highlithing support."). - */ - void setShortDescription( const char *shortDescription ); - - /** - * Defines the license identifier. - * - * @param licenseKey The license identifier. - */ - void setLicense( LicenseKey licenseKey); - - /** - * Defines the copyright statement to show when displaying the license. - * - * @param copyrightStatement A copyright statement, that can look like - * this: "(c) 1999-2000, Name". The string specified here is not - * modified in any manner. The author information from addAuthor - * is not used. - */ - void setCopyrightStatement( const char *copyrightStatement ); - - /** - * Defines the additional text to show in the about dialog. - * - * @param otherText Some free form text, that can contain any kind of - * information. The text can contain newlines. This string - * should be marked for translation. - */ - void setOtherText( const char *otherText ); - - /** - * Defines the program homepage. - * - * @param homepage The program homepage string. - * Start the address with "http://". "http://kate.kde.org" is - * is correct, "kde.kde.org" is not. - */ - void setHomepage( const char *homepage ); - - /** - * Defines the address where bug reports should be sent. - * - * @param bugAddress The bug report email address string. - * This defaults to the kde.org bug system. - */ - void setBugAddress( const char *bugAddress ); - - /** - * Defines the product name wich will be used in the KBugReport dialog. - * By default it's the appName, but you can overwrite it here to provide - * support for special components e.g. 'product/component' like - * 'kontact/summary'. - * - * @param name The name of product - */ - void setProductName( const char *name ); - - /** - * Returns the application's internal name. - * @return the internal program name. - */ - const char *appName() const; - - /** - * Returns the application's product name, which will be used in KBugReport - * dialog. By default it returns appName(), otherwise the one which is set - * with setProductName() - * - * @return the product name. - */ - const char *productName() const; - - /** - * Returns the translated program name. - * @return the program name (translated). - */ - TQString programName() const; - - /** - * Returns the program logo image. - * @return the program logo data or null image if there is - * no custom application logo defined. - * @since 3.4 - */ -// TQImage programLogo() const; - - /** - * Returns the program's version. - * @return the version string. - */ - TQString version() const; - - /** - * Returns a short, translated description. - * @return the short description (translated). Can be - * TQString() if not set. - */ - TQString shortDescription() const; - - /** - * Returns the application homepage. - * @return the application homepage URL. Can be TQString() if - * not set. - */ - TQString homepage() const; - - /** - * Returns the email address for bugs. - * @return the email address where to report bugs. - */ - TQString bugAddress() const; - - /** - * Returns a list of authors. - * @return author information (list of persons). - */ - const TQValueList authors() const; - - /** - * Returns a list of persons who contributed. - * @return credit information (list of persons). - */ - const TQValueList credits() const; - - /** - * Returns a list of translators. - * @return translators information (list of persons) - */ - const TQValueList translators() const; - - /** - * Returns a message about the translation team. - * @return a message about the translation team - */ - static TQString aboutTranslationTeam(); - - /** - * Returns a translated, free form text. - * @return the free form text (translated). Can be TQString() if not set. - */ - TQString otherText() const; - - /** - * Returns the license. If the licenseType argument of the constructor has been - * used, any text defined by setLicenseText is ignored, - * and the standard text for the chosen license will be returned. - * - * @return The license text. - */ - TQString license() const; - - /** - * Returns the copyright statement. - * @return the copyright statement. Can be TQString() if not set. - */ - TQString copyrightStatement() const; - - private: - const char *mAppName; - const char *mProgramName; - const char *mVersion; - const char *mShortDescription; - int mLicenseKey; - const char *mCopyrightStatement; - const char *mOtherText; - const char *mHomepageAddress; - const char *mBugEmailAddress; - TQValueList mAuthorList; - TQValueList mCreditList; - const char *mLicenseText; - - TDEAboutDataPrivate *d; -}; - -#endif - diff --git a/src/common/nokde/nokde_kcmdlineargs.cpp b/src/common/nokde/nokde_kcmdlineargs.cpp deleted file mode 100644 index 15fc238..0000000 --- a/src/common/nokde/nokde_kcmdlineargs.cpp +++ /dev/null @@ -1,1329 +0,0 @@ -// modified from KDE 3.4 for Windows port (Nicolas Hadacek) - -/* - Copyright (C) 1999 Waldo Bastian - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -//#include - -#include - -#include -#include -#include -#include -#include - -#ifdef HAVE_LIMITS_H -#include -#endif - -#include -#include -#include - -#include -#if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 -# include -# include -#else -# include -# define TQGList Q3GList -# define TQStrList Q3StrList -# include -# define TQGDict Q3GDict -# define TQAsciiDict Q3AsciiDict -# include -# define TQPtrCollection Q3PtrCollection -#endif - - -#include "nokde_kcmdlineargs.h" -#include "nokde_kaboutdata.h" -#include "nokde_klocale.h" -//#include -//#include -//#include -//#include - -#ifdef TQ_WS_X11 -#define DISPLAY "DISPLAY" -#elif defined(TQ_WS_TQWS) -#define DISPLAY "TQWS_DISPLAY" -#endif - -#ifdef TQ_WS_WIN -#include -#endif - -template class TQAsciiDict; -template class TQPtrList; - -class TDECmdLineParsedOptions : public TQAsciiDict -{ -public: - TDECmdLineParsedOptions() - : TQAsciiDict( 7 ) { } - - // WABA: Huh? - // The compiler doesn't find TDECmdLineParsedOptions::write(s) by itself ??? - // WABA: No, because there is another write function that hides the - // write function in the base class even though this function has a - // different signature. (obscure C++ feature) - TQDataStream& save( TQDataStream &s) const - { return TQGDict::write(s); } - - TQDataStream& load( TQDataStream &s) - { return TQGDict::read(s); } - -protected: - virtual TQDataStream& write( TQDataStream &s, TQPtrCollection::Item data) const - { - TQCString *str = (TQCString *) data; - s << (*str); - return s; - } - - virtual TQDataStream& read( TQDataStream &s, TQPtrCollection::Item &item) - { - TQCString *str = new TQCString; - s >> (*str); - item = (void *)str; - return s; - } - -}; - -class TDECmdLineParsedArgs : public TQStrList -{ -public: - TDECmdLineParsedArgs() - : TQStrList( true ) { } - TQDataStream& save( TQDataStream &s) const - { return TQGList::write(s); } - - TQDataStream& load( TQDataStream &s) - { return TQGList::read(s); } -}; - - -class TDECmdLineArgsList: public TQPtrList -{ -public: - TDECmdLineArgsList() { } -}; - -TDECmdLineArgsList *TDECmdLineArgs::argsList = 0; -int TDECmdLineArgs::argc = 0; -char **TDECmdLineArgs::argv = 0; -char *TDECmdLineArgs::mCwd = 0; -//static KStaticDeleter mCwdd; -const TDEAboutData *TDECmdLineArgs::about = 0; -bool TDECmdLineArgs::parsed = false; -bool TDECmdLineArgs::ignoreUnknown = false; - -// -// Static functions -// - -void -TDECmdLineArgs::init(int _argc, char **_argv, const char *_appname, const char* programName, - const char *_description, const char *_version, bool noKApp) -{ - init(_argc, _argv, - new TDEAboutData(_appname, programName, _version, _description), - noKApp); -} - -void -TDECmdLineArgs::init(int _argc, char **_argv, const char *_appname, - const char *_description, const char *_version, bool noKApp) -{ - init(_argc, _argv, - new TDEAboutData(_appname, _appname, _version, _description), - noKApp); -} - -void -TDECmdLineArgs::initIgnore(int _argc, char **_argv, const char *_appname ) -{ - init(_argc, _argv, - new TDEAboutData(_appname, _appname, "unknown", "TDE Application", false)); - ignoreUnknown = true; -} - -void -TDECmdLineArgs::init(const TDEAboutData* ab) -{ - char **_argv = (char **) malloc(sizeof(char *)); - _argv[0] = (char *) ab->appName(); - init(1,_argv,ab, true); -} - - -void -TDECmdLineArgs::init(int _argc, char **_argv, const TDEAboutData *_about, bool /*noKApp*/) -{ - argc = _argc; - argv = _argv; - - if (!argv) - { - fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); - fprintf(stderr, "Passing null-pointer to 'argv' is not allowed.\n\n"); - - assert( 0 ); - exit(255); - } - - // Strip path from argv[0] - if (argc) { - char *p = strrchr( argv[0], '/'); - if (p) - argv[0] = p+1; - } - - about = _about; - parsed = false; - mCwd = /*mCwdd.setObject(mCwd, */new char [PATH_MAX+1];//, true); - getcwd(mCwd, PATH_MAX); -#ifdef TQ_WS_WIN - win32_slashify(mCwd, PATH_MAX); -#endif -// if (!noKApp) -// TDEApplication::addCmdLineOptions(); -} - -TQString TDECmdLineArgs::cwd() -{ - return TQFile::decodeName(TQCString(mCwd)); -} - -const char * TDECmdLineArgs::appName() -{ - if (!argc) return 0; - return argv[0]; -} - -void -TDECmdLineArgs::addCmdLineOptions( const TDECmdLineOptions *options, const char *name, - const char *id, const char *afterId) -{ - if (!argsList) - argsList = new TDECmdLineArgsList(); - - int pos = argsList->count(); - - if (pos && id && argsList->last() && !argsList->last()->name) - pos--; - - TDECmdLineArgs *args; - int i = 0; - for(args = argsList->first(); args; args = argsList->next(), i++) - { - if (!id && !args->id) - return; // Options already present. - - if (id && args->id && (::qstrcmp(id, args->id) == 0)) - return; // Options already present. - - if (afterId && args->id && (::qstrcmp(afterId, args->id) == 0)) - pos = i+1; - } - - assert( parsed == false ); // You must add _ALL_ cmd line options - // before accessing the arguments! - args = new TDECmdLineArgs(options, name, id); - argsList->insert(pos, args); -} - -void -TDECmdLineArgs::saveAppArgs( TQDataStream &ds) -{ - if (!parsed) - parseAllArgs(); - - // Remove TQt and KDE options. - removeArgs("qt"); - removeArgs("kde"); - - TQCString qCwd = mCwd; - ds << qCwd; - - uint count = argsList ? argsList->count() : 0; - ds << count; - - if (!count) return; - - TDECmdLineArgs *args; - for(args = argsList->first(); args; args = argsList->next()) - { - ds << TQCString(args->id); - args->save(ds); - } -} - -void -TDECmdLineArgs::loadAppArgs( TQDataStream &ds) -{ - // Remove TQt and KDE options. - removeArgs("qt"); - removeArgs("kde"); - - TDECmdLineArgs *args; - if ( argsList ) { - for(args = argsList->first(); args; args = argsList->next()) - { - args->clear(); - } - } - - if (ds.atEnd()) - return; - - TQCString qCwd; - ds >> qCwd; - delete [] mCwd; - - mCwd = /*mCwdd.setObject(mCwd, */new char[qCwd.length()+1];//, true); - strncpy(mCwd, qCwd.data(), qCwd.length()+1); - - uint count; - ds >> count; - - while(count--) - { - TQCString id; - ds >> id; - assert( argsList ); - for(args = argsList->first(); args; args = argsList->next()) - { - if (args->id == id) - { - args->load(ds); - break; - } - } - } - parsed = true; -} - -TDECmdLineArgs *TDECmdLineArgs::parsedArgs(const char *id) -{ - TDECmdLineArgs *args = argsList ? argsList->first() : 0; - while(args) - { - if ((id && ::qstrcmp(args->id, id) == 0) || (!id && !args->id)) - { - if (!parsed) - parseAllArgs(); - return args; - } - args = argsList->next(); - } - - return args; -} - -void TDECmdLineArgs::removeArgs(const char *id) -{ - TDECmdLineArgs *args = argsList ? argsList->first() : 0; - while(args) - { - if (args->id && id && ::qstrcmp(args->id, id) == 0) - { - if (!parsed) - parseAllArgs(); - break; - } - args = argsList->next(); - } - - if (args) - delete args; -} - -/* - * @return: - * 0 - option not found. - * 1 - option found // -fork - * 2 - inverse option found ('no') // -nofork - * 3 - option + arg found // -fork now - * - * +4 - no more options follow // !fork - */ -static int -findOption(const TDECmdLineOptions *options, TQCString &opt, - const char *&opt_name, const char *&def, bool &enabled) -{ - int result; - bool inverse; - int len = opt.length(); - while(options && options->name) - { - result = 0; - inverse = false; - opt_name = options->name; - if ((opt_name[0] == ':') || (opt_name[0] == 0)) - { - options++; - continue; - } - - if (opt_name[0] == '!') - { - opt_name++; - result = 4; - } - if ((opt_name[0] == 'n') && (opt_name[1] == 'o')) - { - opt_name += 2; - inverse = true; - } - if (strncmp(opt.data(), opt_name, len) == 0) - { - opt_name += len; - if (!opt_name[0]) - { - if (inverse) - return result+2; - - if (!options->description) - { - options++; - if (!options->name) - return result+0; - TQCString nextOption = options->name; -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 - int p = nextOption.find(' '); -#else - int p = TQString(nextOption).indexOf(' '); -#endif - if (p > 0) - nextOption = nextOption.left(p); - if (strncmp(nextOption.data(), "no", 2) == 0) - { - nextOption = nextOption.mid(2); - enabled = !enabled; - } - result = findOption(options, nextOption, opt_name, def, enabled); - assert(result); - opt = nextOption; - return result; - } - - return 1; - } - if (opt_name[0] == ' ') - { - opt_name++; - def = options->def; - return result+3; - } - } - - options++; - } - return 0; -} - - -void -TDECmdLineArgs::findOption(const char *_opt, TQCString opt, int &i, bool _enabled, bool &moreOptions) -{ - TDECmdLineArgs *args = argsList->first(); - const char *opt_name; - const char *def; - TQCString argument; -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 - int j = opt.find('='); -#else - int j = TQString(opt).indexOf('='); -#endif - if (j != -1) - { - argument = opt.mid(j+1); - opt = opt.left(j); - } - - bool enabled = true; - int result = 0; - while (args) - { - enabled = _enabled; - result = ::findOption(args->options, opt, opt_name, def, enabled); - if (result) break; - args = argsList->next(); - } - if (!args && (_opt[0] == '-') && _opt[1] && (_opt[1] != '-')) - { - // Option not found check if it is a valid option - // in the style of -Pprinter1 or ps -aux - int p = 1; - while (true) - { - TQCString singleCharOption = " "; - singleCharOption[0] = _opt[p]; - args = argsList->first(); - while (args) - { - enabled = _enabled; - result = ::findOption(args->options, singleCharOption, opt_name, def, enabled); - if (result) break; - args = argsList->next(); - } - if (!args) - break; // Unknown argument - - p++; - if (result == 1) // Single option - { - args->setOption(singleCharOption, enabled); - if (_opt[p]) - continue; // Next option - else - return; // Finished - } - else if (result == 3) // This option takes an argument - { - if (argument.isEmpty()) - { - argument = _opt+p; - } - args->setOption(singleCharOption, argument.data()); - return; - } - break; // Unknown argument - } - args = 0; - result = 0; - } - - if (!args || !result) - { - if (ignoreUnknown) - return; - enable_i18n(); - usage( i18n("Unknown option '%1'.").arg(TQString::fromLocal8Bit(_opt))); - } - - if ((result & 4) != 0) - { - result &= ~4; - moreOptions = false; - } - - if (result == 3) // This option takes an argument - { - if (!enabled) - { - if (ignoreUnknown) - return; - enable_i18n(); - usage( i18n("Unknown option '%1'.").arg(TQString::fromLocal8Bit(_opt))); - } - if (argument.isEmpty()) - { - i++; - if (i >= argc) - { - enable_i18n(); - usage( i18n("'%1' missing.").arg( opt_name)); - } - argument = argv[i]; - } - args->setOption(opt, argument.data()); - } - else - { - args->setOption(opt, enabled); - } -} - -void -TDECmdLineArgs::printQ(const TQString &msg) -{ -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 - TQCString localMsg = msg.local8Bit(); -#else - TQCString localMsg = msg.toLocal8Bit(); -#endif - fprintf(stdout, "%s", localMsg.data()); -} - -void -TDECmdLineArgs::parseAllArgs() -{ - bool allowArgs = false; - bool inOptions = true; - bool everythingAfterArgIsArgs = false; - TDECmdLineArgs *appOptions = argsList->last(); - if (!appOptions->id) - { - const TDECmdLineOptions *option = appOptions->options; - while(option && option->name) - { - if (option->name[0] == '+') - allowArgs = true; - if ( option->name[0] == '!' && option->name[1] == '+' ) - { - allowArgs = true; - everythingAfterArgIsArgs = true; - } - option++; - } - } - for(int i = 1; i < argc; i++) - { - if (!argv[i]) - continue; - - if ((argv[i][0] == '-') && argv[i][1] && inOptions) - { - bool enabled = true; - const char *option = &argv[i][1]; - const char *orig = argv[i]; - if (option[0] == '-') - { - option++; - argv[i]++; - if (!option[0]) - { - inOptions = false; - continue; - } - } - if (::qstrcmp(option, "help") == 0) - { - usage(0); - } - else if (strncmp(option, "help-",5) == 0) - { - usage(option+5); - } - else if ( (::qstrcmp(option, "version") == 0) || - (::qstrcmp(option, "v") == 0)) - { - printQ( TQString("TQt: %1\n").arg(tqVersion())); -// printQ( TQString("KDE: %1\n").arg(TDE_VERSION_STRING)); - printQ( TQString("%1: %2\n"). - arg(about->programName()).arg(about->version())); - exit(0); - } else if ( (::qstrcmp(option, "license") == 0) ) - { - enable_i18n(); - printQ( about->license() ); - printQ( "\n" ); - exit(0); - } else if ( ::qstrcmp( option, "author") == 0 ) { - enable_i18n(); - if ( about ) { - const TQValueList authors = about->authors(); - if ( !authors.isEmpty() ) { - TQString authorlist; - for (TQValueList::ConstIterator it = authors.begin(); it != authors.end(); ++it ) { - TQString email; - if ( !(*it).emailAddress().isEmpty() ) - email = " <" + (*it).emailAddress() + ">"; - authorlist += TQString(" ") + (*it).name() + email + "\n"; - } - printQ( i18n("the 2nd argument is a list of name+address, one on each line","%1 was written by\n%2").arg ( TQString(about->programName()) ).arg( authorlist ) ); - } - } else { - printQ( i18n("%1 was written by somebody who wants to remain anonymous.").arg(about->programName()) ); - } - if (!about->bugAddress().isEmpty()) - { - if (about->bugAddress() == "submit@bugs.kde.org") - printQ( i18n( "Please use http://bugs.kde.org to report bugs, do not mail the authors directly.\n" ) ); - else - printQ( i18n( "Please use %1 to report bugs, do not mail the authors directly.\n" ).arg(about->bugAddress()) ); - } - exit(0); - } else { - if ((option[0] == 'n') && (option[1] == 'o')) - { - option += 2; - enabled = false; - } - findOption(orig, option, i, enabled, inOptions); - } - } - else - { - // Check whether appOptions allows these arguments - if (!allowArgs) - { - if (ignoreUnknown) - continue; - enable_i18n(); - usage( i18n("Unexpected argument '%1'.").arg(TQString::fromLocal8Bit(argv[i]))); - } - else - { - appOptions->addArgument(argv[i]); - if (everythingAfterArgIsArgs) - inOptions = false; - } - } - } - parsed = true; -} - -/** - * For TDEApplication only: - * - * Return argc - */ -int * -TDECmdLineArgs::tqt_argc() -{ -// if (!argsList) -// TDEApplication::addCmdLineOptions(); // Lazy bastards! - - static int tqt_argc = -1; - if( tqt_argc != -1 ) - return &tqt_argc; - - TDECmdLineArgs *args = parsedArgs("qt"); - assert(args); // No qt options have been added! - if (!argv) - { - fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); - fprintf(stderr, "Application has not called TDECmdLineArgs::init(...).\n\n"); - - assert( 0 ); - exit(255); - } - - assert(argc >= (args->count()+1)); - tqt_argc = args->count() +1; - return &tqt_argc; -} - -/** - * For TDEApplication only: - * - * Return argv - */ -char *** -TDECmdLineArgs::tqt_argv() -{ -// if (!argsList) -// TDEApplication::addCmdLineOptions(); // Lazy bastards! - - static char** tqt_argv; - if( tqt_argv != NULL ) - return &tqt_argv; - - TDECmdLineArgs *args = parsedArgs("qt"); - assert(args); // No qt options have been added! - if (!argv) - { - fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); - fprintf(stderr, "Application has not called TDECmdLineArgs::init(...).\n\n"); - - assert( 0 ); - exit(255); - } - - tqt_argv = new char*[ args->count() + 2 ]; - tqt_argv[ 0 ] = tqstrdup( appName()); - int i = 0; - for(; i < args->count(); i++) - { - tqt_argv[i+1] = tqstrdup((char *) args->arg(i)); - } - tqt_argv[i+1] = 0; - - return &tqt_argv; -} - -void -TDECmdLineArgs::enable_i18n() -{ - // called twice or too late -/* if (TDEGlobal::_locale) - return; - - if (!TDEGlobal::_instance) { - TDEInstance *instance = new TDEInstance(about); - (void) instance->config(); - // Don't delete instance! - }*/ -} - -void -TDECmdLineArgs::usage(const TQString &error) -{ -// assert(TDEGlobal::_locale); -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 - TQCString localError = error.local8Bit(); -#else - TQCString localError = error.toLocal8Bit(); -#endif - if (localError[error.length()-1] == '\n') - localError = localError.left(error.length()-1); - fprintf(stderr, "%s: %s\n", argv[0], localError.data()); - - TQString tmp = i18n("Use --help to get a list of available command line options."); -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 - localError = tmp.local8Bit(); -#else - localError = tmp.toLocal8Bit(); -#endif - fprintf(stderr, "%s: %s\n", argv[0], localError.data()); - exit(254); -} - -void -TDECmdLineArgs::usage(const char *id) -{ - enable_i18n(); - assert(argsList != 0); // It's an error to call usage(...) without - // having done addCmdLineOptions first! - - TQString optionFormatString = " %1 %2\n"; - TQString optionFormatStringDef = " %1 %2 [%3]\n"; - TQString optionHeaderString = i18n("\n%1:\n"); - TQString tmp; - TQString usage; - - TDECmdLineArgs *args = argsList->last(); - - if (!(args->id) && (args->options) && - (args->options->name) && (args->options->name[0] != '+')) - { - usage = i18n("[options] ")+usage; - } - - while(args) - { - if (args->name) - { - usage = i18n("[%1-options]").arg(args->name)+" "+usage; - } - args = argsList->prev(); - } - - TDECmdLineArgs *appOptions = argsList->last(); - if (!appOptions->id) - { - const TDECmdLineOptions *option = appOptions->options; - while(option && option->name) - { - if (option->name[0] == '+') - usage = usage + (option->name+1) + " "; - else if ( option->name[0] == '!' && option->name[1] == '+' ) - usage = usage + (option->name+2) + " "; - - option++; - } - } - - printQ(i18n("Usage: %1 %2\n").arg(argv[0]).arg(usage)); - printQ("\n"+about->shortDescription()+"\n"); - - printQ(optionHeaderString.arg(i18n("Generic options"))); - printQ(optionFormatString.arg("--help", -25).arg(i18n("Show help about options"))); - - args = argsList->first(); - while(args) - { - if (args->name && args->id) - { - TQString option = TQString("--help-%1").arg(args->id); - TQString desc = i18n("Show %1 specific options").arg(args->name); - - printQ(optionFormatString.arg(option, -25).arg(desc)); - } - args = argsList->next(); - } - - printQ(optionFormatString.arg("--help-all",-25).arg(i18n("Show all options"))); - printQ(optionFormatString.arg("--author",-25).arg(i18n("Show author information"))); - printQ(optionFormatString.arg("-v, --version",-25).arg(i18n("Show version information"))); - printQ(optionFormatString.arg("--license",-25).arg(i18n("Show license information"))); - printQ(optionFormatString.arg("--", -25).arg(i18n("End of options"))); - - args = argsList->first(); // Sets current to 1st. - - bool showAll = id && (::qstrcmp(id, "all") == 0); - - if (!showAll) - { - while(args) - { - if (!id && !args->id) break; - if (id && (::qstrcmp(args->id, id) == 0)) break; - args = argsList->next(); - } - } - - while(args) - { - bool hasArgs = false; - bool hasOptions = false; - TQString optionsHeader; - if (args->name) - optionsHeader = optionHeaderString.arg(i18n("%1 options").arg(TQString::fromLatin1(args->name))); - else - optionsHeader = i18n("\nOptions:\n"); - - while (args) - { - const TDECmdLineOptions *option = args->options; - TQCString opt = ""; -// - while(option && option->name) - { - TQString description; - TQString descriptionRest; - TQStringList dl; - - // Option header - if (option->name[0] == ':') - { - if (option->description) - { - optionsHeader = "\n"+i18n(option->description); - if (!optionsHeader.endsWith("\n")) - optionsHeader.append("\n"); - hasOptions = false; - } - option++; - continue; - } - - // Free-form comment - if (option->name[0] == 0) - { - if (option->description) - { - TQString tmp = "\n"+i18n(option->description); - if (!tmp.endsWith("\n")) - tmp.append("\n"); - printQ(tmp); - } - option++; - continue; - } - - // Options - if (option->description) - { - description = i18n(option->description); -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 - dl = TQStringList::split("\n", description, true); -#else - dl = description.split("\n"); -#endif - description = dl.first(); - dl.erase( dl.begin() ); - } - TQCString name = option->name; - if (name[0] == '!') - name = name.mid(1); - - if (name[0] == '+') - { - if (!hasArgs) - { - printQ(i18n("\nArguments:\n")); - hasArgs = true; - } - - name = name.mid(1); - if ((name[0] == '[') && (name[name.length()-1] == ']')) - name = name.mid(1, name.length()-2); - printQ(optionFormatString.arg(TQString(name), -25) - .arg(description)); - } - else - { - if (!hasOptions) - { - printQ(optionsHeader); - hasOptions = true; - } - - if ((name.length() == 1) || (name[1] == ' ')) - name = "-"+name; - else - name = "--"+name; - if (!option->description) - { - opt = name + ", "; - } - else - { - opt = opt + name; - if (!option->def) - { - printQ(optionFormatString.arg(TQString(opt), -25) - .arg(description)); - } - else - { - printQ(optionFormatStringDef.arg(TQString(opt), -25) - .arg(description).arg(option->def)); - } - opt = ""; - } - } - for(TQStringList::Iterator it = dl.begin(); - it != dl.end(); - ++it) - { - printQ(optionFormatString.arg("", -25).arg(*it)); - } - - option++; - } - args = argsList->next(); - if (!args || args->name || !args->id) break; - } - if (!showAll) break; - } - - exit(254); -} - -// -// Member functions -// - -/** - * Constructor. - * - * The given arguments are assumed to be constants. - */ -TDECmdLineArgs::TDECmdLineArgs( const TDECmdLineOptions *_options, - const char *_name, const char *_id) - : options(_options), name(_name), id(_id) -{ - parsedOptionList = 0; - parsedArgList = 0; - isTQt = (::qstrcmp(id, "qt") == 0); -} - -/** - * Destructor. - */ -TDECmdLineArgs::~TDECmdLineArgs() -{ - delete parsedOptionList; - delete parsedArgList; - if (argsList) - argsList->removeRef(this); -} - -void -TDECmdLineArgs::clear() -{ - delete parsedArgList; - parsedArgList = 0; - delete parsedOptionList; - parsedOptionList = 0; -} - -void -TDECmdLineArgs::reset() -{ - if ( argsList ) { - argsList->setAutoDelete( true ); - argsList->clear(); - delete argsList; - argsList = 0; - } - parsed = false; -} - -void -TDECmdLineArgs::save( TQDataStream &ds) const -{ - uint count = 0; - if (parsedOptionList) - parsedOptionList->save( ds ); - else - ds << count; - - if (parsedArgList) - parsedArgList->save( ds ); - else - ds << count; -} - -void -TDECmdLineArgs::load( TQDataStream &ds) -{ - if (!parsedOptionList) parsedOptionList = new TDECmdLineParsedOptions; - if (!parsedArgList) parsedArgList = new TDECmdLineParsedArgs; - - parsedOptionList->load( ds ); - parsedArgList->load( ds ); - - if (parsedOptionList->count() == 0) - { - delete parsedOptionList; - parsedOptionList = 0; - } - if (parsedArgList->count() == 0) - { - delete parsedArgList; - parsedArgList = 0; - } -} - -void -TDECmdLineArgs::setOption(const TQCString &opt, bool enabled) -{ - if (isTQt) - { - // TQt does it own parsing. - TQCString arg = "-"; - if( !enabled ) - arg += "no"; - arg += opt; - addArgument(arg); - } - if (!parsedOptionList) { - parsedOptionList = new TDECmdLineParsedOptions; - parsedOptionList->setAutoDelete(true); - } - - if (enabled) - parsedOptionList->replace( opt, new TQCString("t") ); - else - parsedOptionList->replace( opt, new TQCString("f") ); -} - -void -TDECmdLineArgs::setOption(const TQCString &opt, const char *value) -{ - if (isTQt) - { - // TQt does it's own parsing. - TQCString arg = "-"; - arg += opt; - addArgument(arg); - addArgument(value); - -#ifdef TQ_WS_X11 - // Hack coming up! - if (arg == "-display") - { - setenv(DISPLAY, value, true); - } -#endif - } - if (!parsedOptionList) { - parsedOptionList = new TDECmdLineParsedOptions; - parsedOptionList->setAutoDelete(true); - } - - parsedOptionList->insert( opt, new TQCString(value) ); -} - -TQCString -TDECmdLineArgs::getOption(const char *_opt) const -{ - TQCString *value = 0; - if (parsedOptionList) - { - value = parsedOptionList->find(_opt); - } - - if (value) - return (*value); - - // Look up the default. - const char *opt_name; - const char *def; - bool dummy = true; - TQCString opt = _opt; - int result = ::findOption( options, opt, opt_name, def, dummy) & ~4; - - if (result != 3) - { - fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); - fprintf(stderr, "Application requests for getOption(\"%s\") but the \"%s\" option\n", - _opt, _opt); - fprintf(stderr, "has never been specified via addCmdLineOptions( ... )\n\n"); - - assert( 0 ); - exit(255); - } - return TQCString(def); -} - -QCStringList -TDECmdLineArgs::getOptionList(const char *_opt) const -{ - QCStringList result; - if (!parsedOptionList) - return result; - - while(true) - { - TQCString *value = parsedOptionList->take(_opt); - if (!value) - break; - result.prepend(*value); - delete value; - } - - // Reinsert items in dictionary - // WABA: This is rather silly, but I don't want to add restrictions - // to the API like "you can only call this function once". - // I can't access all items without taking them out of the list. - // So taking them out and then putting them back is the only way. - for(QCStringList::ConstIterator it=result.begin(); - it != result.end(); - ++it) - { - parsedOptionList->insert(_opt, new TQCString(*it)); - } - return result; -} - -bool -TDECmdLineArgs::isSet(const char *_opt) const -{ - // Look up the default. - const char *opt_name; - const char *def; - bool dummy = true; - TQCString opt = _opt; - int result = ::findOption( options, opt, opt_name, def, dummy) & ~4; - - if (result == 0) - { - fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); - fprintf(stderr, "Application requests for isSet(\"%s\") but the \"%s\" option\n", - _opt, _opt); - fprintf(stderr, "has never been specified via addCmdLineOptions( ... )\n\n"); - - assert( 0 ); - exit(255); - } - - TQCString *value = 0; - if (parsedOptionList) - { - value = parsedOptionList->find(opt); - } - - if (value) - { - if (result == 3) - return true; - else - return ((*value)[0] == 't'); - } - - if (result == 3) - return false; // String option has 'false' as default. - - // We return 'true' as default if the option was listed as '-nofork' - // We return 'false' as default if the option was listed as '-fork' - return (result == 2); -} - -int -TDECmdLineArgs::count() const -{ - if (!parsedArgList) - return 0; - return parsedArgList->count(); -} - -const char * -TDECmdLineArgs::arg(int n) const -{ - if (!parsedArgList || (n >= (int) parsedArgList->count())) - { - fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs): Argument out of bounds\n"); - fprintf(stderr, "Application requests for arg(%d) without checking count() first.\n", - n); - - assert( 0 ); - exit(255); - } - - return parsedArgList->at(n); -} - -KURL -TDECmdLineArgs::url(int n) const -{ - return makeURL( arg(n) ); -} - -KURL TDECmdLineArgs::makeURL(const char *_urlArg) -{ - TQString urlArg = TQFile::decodeName(_urlArg); - if (!TQDir::isRelativePath(urlArg)) - { - //KURL result; - //result.setPath(urlArg); - //return result; // Absolute path. - return urlArg; - } -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 - if ( !TQUrl::isRelativeUrl(urlArg) ) -#else - if ( !TQUrl(urlArg).isRelative() ) -#endif - //return KURL(urlArg); // Argument is a URL - return urlArg; - -// KURL result; -// result.setPath( cwd()+"/"+urlArg ); -// result.cleanPath(); -// return result; // Relative path - return cwd() + "/" + urlArg; -} - -void -TDECmdLineArgs::addArgument(const char *argument) -{ - if (!parsedArgList) - parsedArgList = new TDECmdLineParsedArgs; - - parsedArgList->append(argument); -} - -static const TDECmdLineOptions kde_tempfile_option[] = -{ - { "tempfile", I18N_NOOP("The files/URLs opened by the application will be deleted after use"), 0}, - TDECmdLineLastOption -}; - -void -TDECmdLineArgs::addTempFileOption() -{ - TDECmdLineArgs::addCmdLineOptions( kde_tempfile_option, "KDE-tempfile", "kde-tempfile" ); -} - -bool TDECmdLineArgs::isTempFileSet() -{ - TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs( "kde-tempfile" ); - if ( args ) - return args->isSet( "tempfile" ); - return false; -} diff --git a/src/common/nokde/nokde_kcmdlineargs.h b/src/common/nokde/nokde_kcmdlineargs.h deleted file mode 100644 index 58931a6..0000000 --- a/src/common/nokde/nokde_kcmdlineargs.h +++ /dev/null @@ -1,701 +0,0 @@ -// modified from KDE 3.4 for Windows port (Nicolas Hadacek) - -/* This file is part of the KDE project - Copyright (C) 1999 Waldo Bastian - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef _KCMDLINEARGS_H_ -#define _KCMDLINEARGS_H_ - -#include "nokde_klocale.h" -#include "nokde_kurl.h" - -# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 -# include -# include -#else -# include -# define TQCString Q3CString -# include -# define TQPtrList Q3PtrList -# include -# define TQValueList Q3ValueList -#endif -# include - -typedef TQValueList QCStringList; - -/** - * @short Structure that holds command line options. - * - * This class is intended to be used with the TDECmdLineArgs class, which - * provides convenient and powerful command line argument parsing and - * handling functionality. - * - * @see TDECmdLineArgs for additional usage information - */ -struct TDECORE_EXPORT TDECmdLineOptions -{ - /** - * The name of the argument as it should be called on the command line and - * appear in myapp --help. - * - * Note that if this option starts with "no" that you will need to test for - * the name without the "no" and the result will be the inverse of what is - * specified. i.e. if "nofoo" is the name of the option and - * myapp --nofoo is called: - * - * \code - * TDECmdLineArgs::parsedArgs()->isSet("foo"); // false - * \endcode - */ - const char *name; - /** - * The text description of the option as should appear in - * myapp --help. This value should be wrapped with I18N_NOOP(). - */ - const char *description; - /** - * The default value for the option, if it is not specified on the - * command line. - */ - const char *def; // Default -}; - -#define TDECmdLineLastOption { 0, 0, 0 } - -class TDECmdLineArgsList; -class TDEApplication; -class KUniqueApplication; -class TDECmdLineParsedOptions; -class TDECmdLineParsedArgs; -class TDEAboutData; -class TDECmdLineArgsPrivate; - -/** - * @short A class for command-line argument handling. - * - * TDECmdLineArgs provides simple access to the command-line arguments - * for an application. It takes into account TQt-specific options, - * KDE-specific options and application specific options. - * - * This class is used in %main() via the static method - * init(). - * - * A typical %KDE application using %TDECmdLineArgs should look like this: - * - * \code - * int main(int argc, char *argv[]) - * { - * // Initialize command line args - * TDECmdLineArgs::init(argc, argv, appName, programName, description, version); - * - * // Tell which options are supported - * TDECmdLineArgs::addCmdLineOptions( options ); - * - * // Add options from other components - * KUniqueApplication::addCmdLineOptions(); - * - * .... - * - * // Create application object without passing 'argc' and 'argv' again. - * KUniqueApplication app; - * - * .... - * - * // Handle our own options/arguments - * // A TDEApplication will usually do this in main but this is not - * // necessary. - * // A KUniqueApplication might want to handle it in newInstance(). - * - * TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - * - * // A binary option (on / off) - * if (args->isSet("some-option")) - * .... - * - * // An option which takes an additional argument - * TQCString anotherOptionArg = args->getOption("another-option"); - * - * // Arguments (e.g. files to open) - * for(int i = 0; i < args->count(); i++) // Counting start at 0! - * { - * // don't forget to convert to Unicode! - * openFile( TQFile::decodeName( args->arg(i))); - * // Or more convenient: - * // openURL( args->url(i)); - * - * } - * - * args->clear(); // Free up some memory. - * .... - * } - * \endcode - * - * The options that an application supports are configured using the - * TDECmdLineOptions class. An example is shown below: - * - * \code - * static const TDECmdLineOptions options[] = - * { - * { "a", I18N_NOOP("A short binary option"), 0 }, - * { "b \", I18N_NOOP("A short option which takes an argument"), 0 }, - * { "c \", I18N_NOOP("As above but with a default value"), "9600" }, - * { "option1", I18N_NOOP("A long binary option, off by default"), 0 }, - * { "nooption2", I18N_NOOP("A long binary option, on by default"), 0 }, - * { ":", I18N_NOOP("Extra options:"), 0 }, - * { "option3 \", I18N_NOOP("A long option which takes an argument"), 0 }, - * { "option4 \", I18N_NOOP("A long option which takes an argument, defaulting to 9600"), "9600" }, - * { "d", 0, 0 }, - * { "option5", I18N_NOOP("A long option which has a short option as alias"), 0 }, - * { "e", 0, 0 }, - * { "nooption6", I18N_NOOP("Another long option with an alias"), 0 }, - * { "f", 0, 0 }, - * { "option7 \", I18N_NOOP("'--option7 speed' is the same as '-f speed'"), 0 }, - * { "!option8 \", I18N_NOOP("All options following this one will be treated as arguments"), 0 }, - * { "+file", I18N_NOOP("A required argument 'file'"), 0 }, - * { "+[arg1]", I18N_NOOP("An optional argument 'arg1'"), 0 }, - * { "!+command", I18N_NOOP("A required argument 'command', that can contain multiple words, even starting with '-'"), 0 }, - * { "", I18N_NOOP("Additional help text not associated with any particular option") 0 }, - * TDECmdLineLastOption // End of options. - * }; - * \endcode - * - * The I18N_NOOP macro is used to indicate that these strings should be - * marked for translation. The actual translation is done by TDECmdLineArgs. - * You can't use i18n() here because we are setting up a static data - * structure and can't do translations at compile time. - * - * Note that a program should define the options before any arguments. - * - * When a long option has a short option as an alias, a program should - * only test for the long option. - * - * With the above options a command line could look like: - * \code - * myapp -a -c 4800 --display localhost:0.0 --nooption5 -d /tmp/file - * \endcode - * - * Long binary options can be in the form 'option' and 'nooption'. - * A command line may contain the same binary option multiple times, - * the last option determines the outcome: - * \code - * myapp --nooption4 --option4 --nooption4 - * \endcode - * is the same as: - * \code - * myapp --nooption4 - * \endcode - * - * If an option value is provided multiple times, normally only the last - * value is used: - * \code - * myapp -c 1200 -c 2400 -c 4800 - * \endcode - * is usually the same as: - * \code - * myapp -c 4800 - * \endcode - * - * However, an application can choose to use all values specified as well. - * As an example of this, consider that you may wish to specify a - * number of directories to use: - * \code - * myapp -I /usr/include -I /opt/kde/include -I /usr/X11/include - * \endcode - * When an application does this it should mention this in the description - * of the option. To access these options, use getOptionList() - * - * Tips for end-users: - * - * @li Single char options like "-a -b -c" may be combined into "-abc" - * @li The option "--foo bar" may also be written "--foo=bar" - * @li The option "-P lp1" may also be written "-P=lp1" or "-Plp1" - * @li The option "--foo bar" may also be written "-foo bar" - * - * @author Waldo Bastian - * @version 0.0.4 - */ -class TDECORE_EXPORT TDECmdLineArgs -{ - friend class TDEApplication; - friend class KUniqueApplication; - friend class TQPtrList; -public: - // Static functions: - - /** - * Initialize class. - * - * This function should be called as the very first thing in - * your application. - * @param _argc As passed to @p main(...). - * @param _argv As passed to @p main(...). - * @param _appname The untranslated name of your application. This should - * match with @p argv[0]. - * @param programName A program name string to be used for display - * purposes. This string should be marked for - * translation. Example: I18N_NOOP("KEdit") - * @param _description A short description of what your application is about. - * @param _version A version. - * @param noKApp Set this true to not add commandline options for - * TQApplication / TDEApplication - * - * @since 3.2 - */ - static void init(int _argc, char **_argv, const char *_appname, - const char* programName, const char *_description, - const char *_version, bool noKApp = false); - /** - * @deprecated - * You should convert any calls to this method to use the one - * above, by adding in the program name to be used for display - * purposes. Do not forget to mark it for translation using I18N_NOOP. - */ - static void init(int _argc, char **_argv, - const char *_appname, const char *_description, - const char *_version, bool noKApp = false) KDE_DEPRECATED; - - /** - * Initialize class. - * - * This function should be called as the very first thing in - * your application. It uses TDEAboutData to replace some of the - * arguments that would otherwise be required. - * - * @param _argc As passed to @p main(...). - * @param _argv As passed to @p main(...). - * @param about A TDEAboutData object describing your program. - * @param noKApp Set this true to not add commandline options for - * TQApplication / TDEApplication - */ - static void init(int _argc, char **_argv, - const TDEAboutData *about, bool noKApp = false); - - /** - * Initialize Class - * - * This function should be called as the very first thing in your - * application. This method will rarely be used, since it doesn't - * provide any argument parsing. It does provide access to the - * TDEAboutData information. - * This method is exactly the same as calling - * init(0,0, const TDEAboutData *about, true). - * - * @param about the about data. - * \see TDEAboutData - */ - static void init(const TDEAboutData *about); - - /** - * Add options to your application. - * - * You must make sure that all possible options have been added before - * any class uses the command line arguments. - * - * The list of options should look like this: - * - * \code - * static TDECmdLineOptions options[] = - * { - * { "option1 \", I18N_NOOP("Description 1"), "my_extra_arg" }, - * { "o", 0, 0 }, - * { "option2", I18N_NOOP("Description 2"), 0 }, - * { "nooption3", I18N_NOOP("Description 3"), 0 }, - * TDECmdLineLastOption - * } - * \endcode - * - * @li "option1" is an option that requires an additional argument, - * but if one is not provided, it uses "my_extra_arg". - * @li "option2" is an option that can be turned on. The default is off. - * @li "option3" is an option that can be turned off. The default is on. - * @li "o" does not have a description. It is an alias for the option - * that follows. In this case "option2". - * @li "+file" specifies an argument. The '+' is removed. If your program - * doesn't specify that it can use arguments your program will abort - * when an argument is passed to it. Note that the reverse is not - * true. If required, you must check yourself the number of arguments - * specified by the user: - * \code - * TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - * if (args->count() == 0) TDECmdLineArgs::usage(i18n("No file specified!")); - * \endcode - * - * In BNF: - * \code - * cmd = myapp [options] file - * options = (option)* - * option = --option1 \ | - * (-o | --option2 | --nooption2) | - * ( --option3 | --nooption3 ) - * \endcode - * - * Instead of "--option3" one may also use "-option3" - * - * Usage examples: - * - * @li "myapp --option1 test" - * @li "myapp" (same as "myapp --option1 my_extra_arg") - * @li "myapp --option2" - * @li "myapp --nooption2" (same as "myapp", since it is off by default) - * @li "myapp -o" (same as "myapp --option2") - * @li "myapp --nooption3" - * @li "myapp --option3 (same as "myapp", since it is on by default) - * @li "myapp --option2 --nooption2" (same as "myapp", because it - * option2 is off by default, and the last usage applies) - * @li "myapp /tmp/file" - * - * @param options A list of options that your code supplies. - * @param name the name of the option, can be 0. - * @param id A name with which these options can be identified, can be 0. - * @param afterId The options are inserted after this set of options, can be 0. - */ - static void addCmdLineOptions( const TDECmdLineOptions *options, - const char *name=0, const char *id = 0, - const char *afterId=0); - - /** - * Access parsed arguments. - * - * This function returns all command line arguments that your code - * handles. If unknown command-line arguments are encountered the program - * is aborted and usage information is shown. - * - * @param id The name of the options you are interested in, can be 0. - */ - static TDECmdLineArgs *parsedArgs(const char *id=0); - - /** - * Get the CWD (Current Working Directory) associated with the - * current command line arguments. - * - * Typically this is needed in KUniqueApplication::newInstance() - * since the CWD of the process may be different from the CWD - * where the user started a second instance. - * @return the current working directory - **/ - static TQString cwd(); - - /** - * Get the appname according to argv[0]. - * @return the name of the application - **/ - static const char *appName(); - - /** - * Print the usage help to stdout and exit. - * - * @param id if 0, print all options. If id is set, only print the - * option specified by id. The id is the value set by - * #ref addCmdLineOptions(). - **/ - static void usage(const char *id = 0); - - /** - * Print an error to stderr and the usage help to stdout and exit. - * @param error the error to print - **/ - static void usage(const TQString &error); - - /** - * Enable i18n to be able to print a translated error message. - * - * N.B.: This function leaks memory, therefore you are expected to exit - * afterwards (e.g., by calling usage()). - **/ - static void enable_i18n(); - - // Member functions: - - - /** - * Read out a string option. - * - * The option must have a corresponding TDECmdLineOptions entry - * of the form: - * \code - * { "option \", I18N_NOOP("Description"), "default" } - * \endcode - * You cannot test for the presence of an alias - you must always - * test for the full option. - * - * @param option The name of the option without '-'. - * - * @return The value of the option. If the option was not - * present on the command line the default is returned. - * If the option was present more than the value of the - * last occurrence is used. - */ - TQCString getOption(const char *option) const; - - /** - * Read out all occurrences of a string option. - * - * The option must have a corresponding TDECmdLineOptions entry - * of the form: - * \code - * { "option \", I18N_NOOP("Description"), "default" } - * \endcode - * You cannot test for the presence of an alias - you must always - * test for the full option. - * - * @param option The name of the option, without '-' or '-no'. - * - * @return A list of all option values. If no option was present - * on the command line, an empty list is returned. - */ - QCStringList getOptionList(const char *option) const; - - /** - * Read out a boolean option or check for the presence of string option. - * - * @param option The name of the option without '-' or '-no'. - * - * @return The value of the option. It will be true if the option - * was specifically turned on in the command line, or if the option - * is turned on by default (in the TDECmdLineOptions list) and was - * not specifically turned off in the command line. Equivalently, - * it will be false if the option was specifically turned off in - * the command line, or if the option is turned off by default (in - * the TDECmdLineOptions list) and was not specifically turned on in - * the command line. - */ - bool isSet(const char *option) const; - - /** - * Read the number of arguments that aren't options (but, - * for example, filenames). - * - * @return The number of arguments that aren't options - */ - int count() const; - - /** - * Read out an argument. - * - * @param n The argument to read. 0 is the first argument. - * count()-1 is the last argument. - * - * @return A @p const @p char @p * pointer to the n'th argument. - */ - const char *arg(int n) const; - - /** - * Read out an argument representing a URL. - * - * The argument can be - * @li an absolute filename - * @li a relative filename - * @li a URL - * - * @param n The argument to read. 0 is the first argument. - * count()-1 is the last argument. - * - * @return a URL representing the n'th argument. - */ - KURL url(int n) const; - - /** - * Used by url(). - * Made public for apps that don't use TDECmdLineArgs - * @param urlArg the argument - * @return the url. - */ - static KURL makeURL( const char * urlArg ); - - /** - * Made public for apps that don't use TDECmdLineArgs - * To be done before makeURL, to set the current working - * directory in case makeURL needs it. - * @param cwd the new working directory - */ - static void setCwd( char * cwd ) { mCwd = cwd; } - - /** - * Clear all options and arguments. - */ - void clear(); - - /** - * Reset all option definitions, i.e. cancel all addCmdLineOptions calls. - * Note that TDEApplication's options are removed too, you might want to - * call TDEApplication::addCmdLineOptions if you want them back. - * - * You usually don't want to call this method. - */ - static void reset(); - - /** - * Load arguments from a stream. - */ - static void loadAppArgs( TQDataStream &); - - /** - * Add standard option --tempfile - * @since 3.4 - */ - static void addTempFileOption(); - - // this avoids having to know the "id" used by addTempFileOption - // but this approach doesn't scale well, we can't have 50 standard options here... - /** - * @return true if --tempfile was set - * @since 3.4 - */ - static bool isTempFileSet(); - -protected: - /** - * @internal - * Constructor. - */ - TDECmdLineArgs( const TDECmdLineOptions *_options, const char *_name, - const char *_id); - - /** - * @internal use only. - * - * Use clear() if you want to free up some memory. - * - * Destructor. - */ - ~TDECmdLineArgs(); - -private: - /** - * @internal - * - * Checks what to do with a single option - */ - static void findOption(const char *_opt, TQCString opt, int &i, bool enabled, bool &moreOptions); - - /** - * @internal - * - * Parse all arguments, verify correct syntax and put all arguments - * where they belong. - */ - static void parseAllArgs(); - - /** - * @internal for TDEApplication only: - * - * Return argc - */ - static int *tqt_argc(); - - /** - * @internal for TDEApplication only: - * - * Return argv - */ - - static char ***tqt_argv(); - - /** - * @internal - * - * Remove named options. - * - * @param id The name of the options to be removed. - */ - static void removeArgs(const char *id); - - /** - * @internal for KUniqueApplication only: - * - * Save all but the TQt and KDE arguments to a stream. - */ - static void saveAppArgs( TQDataStream &); - - /** - * @internal - * - * Set a boolean option - */ - void setOption(const TQCString &option, bool enabled); - - /** - * @internal - * - * Set a string option - */ - void setOption(const TQCString &option, const char *value); - - /** - * @internal - * - * Add an argument - */ - void addArgument(const char *argument); - - /** - * @internal - * - * Save to a stream. - */ - void save( TQDataStream &) const; - - /** - * @internal - * - * Restore from a stream. - */ - void load( TQDataStream &); - - /** - * @internal for TDEApplication only - * - * Initialize class. - * - * This function should be called as the very first thing in - * your application. - * @param argc As passed to @p main(...). - * @param argv As passed to @p main(...). - * @param appname The untranslated name of your application. This should - * match with @p argv[0]. - * - * This function makes TDECmdLineArgs ignore all unknown options as well as - * all arguments. - */ - static void initIgnore(int _argc, char **_argv, const char *_appname); - - static void printQ(const TQString &msg); - - const TDECmdLineOptions *options; - const char *name; - const char *id; - TDECmdLineParsedOptions *parsedOptionList; - TDECmdLineParsedArgs *parsedArgList; - bool isTQt; - - static TDECmdLineArgsList *argsList; // All options. - static const TDEAboutData *about; - - static int argc; // The original argc - static char **argv; // The original argv - static bool parsed; // Whether we have parsed the arguments since calling init - static bool ignoreUnknown; // Ignore unknown options and arguments - static char *mCwd; // Current working directory. Important for KUnqiueApp! - static bool parseArgs; - - TDECmdLineArgsPrivate *d; -}; - -#endif - diff --git a/src/common/nokde/nokde_tdeaboutdata.cpp b/src/common/nokde/nokde_tdeaboutdata.cpp new file mode 100644 index 0000000..d8edd5f --- /dev/null +++ b/src/common/nokde/nokde_tdeaboutdata.cpp @@ -0,0 +1,467 @@ +// modified from KDE 3.4 for Windows port (Nicolas Hadacek) + +/* + * This file is part of the KDE Libraries + * Copyright (C) 2000 Espen Sand (espen@kde.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + + +#include "nokde_tdeaboutdata.h" +//#include +#include +#include +#include + +TQString +TDEAboutPerson::name() const +{ + return TQString::fromUtf8(mName); +} + +TQString +TDEAboutPerson::task() const +{ + if (mTask && *mTask) + return i18n(mTask); + else + return TQString(); +} + +TQString +TDEAboutPerson::emailAddress() const +{ + return TQString::fromUtf8(mEmailAddress); +} + + +TQString +TDEAboutPerson::webAddress() const +{ + return TQString::fromUtf8(mWebAddress); +} + + +TDEAboutTranslator::TDEAboutTranslator(const TQString & name, + const TQString & emailAddress) +{ + mName=name; + mEmail=emailAddress; +} + +TQString TDEAboutTranslator::name() const +{ + return mName; +} + +TQString TDEAboutTranslator::emailAddress() const +{ + return mEmail; +} + +class TDEAboutDataPrivate +{ +public: + TDEAboutDataPrivate() + : translatorName("_: NAME OF TRANSLATORS\nYour names") + , translatorEmail("_: EMAIL OF TRANSLATORS\nYour emails") + , productName(0) +// , programLogo(0) + {} + ~TDEAboutDataPrivate() + { +// delete programLogo; + } + const char *translatorName; + const char *translatorEmail; + const char *productName; +// TQImage* programLogo; +}; + + + +TDEAboutData::TDEAboutData( const char *appName, + const char *programName, + const char *version, + const char *shortDescription, + int licenseType, + const char *copyrightStatement, + const char *text, + const char *homePageAddress, + const char *bugsEmailAddress + ) : + mProgramName( programName ), + mVersion( version ), + mShortDescription( shortDescription ), + mLicenseKey( licenseType ), + mCopyrightStatement( copyrightStatement ), + mOtherText( text ), + mHomepageAddress( homePageAddress ), + mBugEmailAddress( bugsEmailAddress ), + mLicenseText (0) +{ + d = new TDEAboutDataPrivate; + + if( appName ) { + const char *p = strrchr(appName, '/'); + if( p ) + mAppName = p+1; + else + mAppName = appName; + } else + mAppName = 0; +} + +TDEAboutData::~TDEAboutData() +{ + if (mLicenseKey == License_File) + delete [] mLicenseText; + delete d; +} + +void +TDEAboutData::addAuthor( const char *name, const char *task, + const char *emailAddress, const char *webAddress ) +{ + mAuthorList.append(TDEAboutPerson(name,task,emailAddress,webAddress)); +} + +void +TDEAboutData::addCredit( const char *name, const char *task, + const char *emailAddress, const char *webAddress ) +{ + mCreditList.append(TDEAboutPerson(name,task,emailAddress,webAddress)); +} + +void +TDEAboutData::setTranslator( const char *name, const char *emailAddress) +{ + d->translatorName=name; + d->translatorEmail=emailAddress; +} + +void +TDEAboutData::setLicenseText( const char *licenseText ) +{ + mLicenseText = licenseText; + mLicenseKey = License_Custom; +} + +void +TDEAboutData::setLicenseTextFile( const TQString &file ) +{ + mLicenseText = tqstrdup(TQFile::encodeName(file)); + mLicenseKey = License_File; +} + +void +TDEAboutData::setAppName( const char *appName ) +{ + mAppName = appName; +} + +void +TDEAboutData::setProgramName( const char* programName ) +{ + mProgramName = programName; +} + +void +TDEAboutData::setVersion( const char* version ) +{ + mVersion = version; +} + +void +TDEAboutData::setShortDescription( const char *shortDescription ) +{ + mShortDescription = shortDescription; +} + +void +TDEAboutData::setLicense( LicenseKey licenseKey) +{ + mLicenseKey = licenseKey; +} + +void +TDEAboutData::setCopyrightStatement( const char *copyrightStatement ) +{ + mCopyrightStatement = copyrightStatement; +} + +void +TDEAboutData::setOtherText( const char *otherText ) +{ + mOtherText = otherText; +} + +void +TDEAboutData::setHomepage( const char *homepage ) +{ + mHomepageAddress = homepage; +} + +void +TDEAboutData::setBugAddress( const char *bugAddress ) +{ + mBugEmailAddress = bugAddress; +} + +void +TDEAboutData::setProductName( const char *productName ) +{ + d->productName = productName; +} + +const char * +TDEAboutData::appName() const +{ + return mAppName; +} + +const char * +TDEAboutData::productName() const +{ + if (d->productName) + return d->productName; + else + return appName(); +} + +TQString +TDEAboutData::programName() const +{ + if (mProgramName && *mProgramName) + return i18n(mProgramName); + else + return TQString(); +} +/* +TQImage +TDEAboutData::programLogo() const +{ + return d->programLogo ? (*d->programLogo) : TQImage(); +} + +void +TDEAboutData::setProgramLogo(const TQImage& image) +{ + if (!d->programLogo) + d->programLogo = new TQImage( image ); + else + *d->programLogo = image; +} +*/ +TQString +TDEAboutData::version() const +{ + return TQString::fromLatin1(mVersion); +} + +TQString +TDEAboutData::shortDescription() const +{ + if (mShortDescription && *mShortDescription) + return i18n(mShortDescription); + else + return TQString(); +} + +TQString +TDEAboutData::homepage() const +{ + return TQString::fromLatin1(mHomepageAddress); +} + +TQString +TDEAboutData::bugAddress() const +{ + return TQString::fromLatin1(mBugEmailAddress); +} + +const TQValueList +TDEAboutData::authors() const +{ + return mAuthorList; +} + +const TQValueList +TDEAboutData::credits() const +{ + return mCreditList; +} + +const TQValueList +TDEAboutData::translators() const +{ + TQValueList personList; + + if(d->translatorName == 0) + return personList; + + TQStringList nameList; + TQStringList emailList; + + TQString names = i18n(d->translatorName); + if(names != TQString::fromUtf8(d->translatorName)) + { +#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 + nameList = TQStringList::split(',',names); +#else + nameList = names.split(',', TQString::SkipEmptyParts); +#endif + } + + + if(d->translatorEmail) + { + TQString emails = i18n(d->translatorEmail); + + if(emails != TQString::fromUtf8(d->translatorEmail)) + { +#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 + emailList = TQStringList::split(',',emails,true); +#else + emailList = emails.split(','); +#endif + } + } + + + TQStringList::Iterator nit; + TQStringList::Iterator eit=emailList.begin(); + + for(nit = nameList.begin(); nit != nameList.end(); ++nit) + { + TQString email; + if(eit != emailList.end()) + { + email=*eit; + ++eit; + } + + TQString name=*nit; + +#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 + personList.append(TDEAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace())); +#else + personList.append(TDEAboutTranslator(name.trimmed(), email.trimmed())); +#endif + } + + return personList; +} + +TQString +TDEAboutData::aboutTranslationTeam() +{ + return i18n("replace this with information about your translation team", + "

TDE is translated into many languages thanks to the work " + "of many people all over the world.

"); +} + +TQString +TDEAboutData::otherText() const +{ + if (mOtherText && *mOtherText) + return i18n(mOtherText); + else + return TQString(); +} + + +TQString +TDEAboutData::license() const +{ + TQString result; + if (!copyrightStatement().isEmpty()) + result = copyrightStatement() + "\n\n"; + + TQString l; + TQString f; + switch ( mLicenseKey ) + { + case License_File: + f = TQFile::decodeName(mLicenseText); + break; + case License_GPL_V2: + l = "GPL v2"; + f = locate("data", "LICENSES/GPL_V2"); + break; + case License_LGPL_V2: + l = "LGPL v2"; + f = locate("data", "LICENSES/LGPL_V2"); + break; + case License_BSD: + l = "BSD License"; + f = locate("data", "LICENSES/BSD"); + break; + case License_Artistic: + l = "Artistic License"; + f = locate("data", "LICENSES/ARTISTIC"); + break; + case License_TQPL_V1_0: + l = "TQPL v1.0"; + f = locate("data", "LICENSES/TQPL_V1.0"); + break; + case License_Custom: + if (mLicenseText && *mLicenseText) + return( i18n(mLicenseText) ); + // fall through + default: + result += i18n("No licensing terms for this program have been specified.\n" + "Please check the documentation or the source for any\n" + "licensing terms.\n"); + return result; + } + + if (!l.isEmpty()) + result += i18n("This program is distributed under the terms of the %1.").arg( l ); + + if (!f.isEmpty()) + { + TQFile file(f); +#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 + if (file.open(IO_ReadOnly)) +#else + if (file.open(TQIODevice::ReadOnly)) +#endif + { + result += '\n'; + result += '\n'; + TQTextStream str(&file); +#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 + result += str.read(); +#else + result += str.readAll(); +#endif + } + } + + return result; +} + +TQString +TDEAboutData::copyrightStatement() const +{ + if (mCopyrightStatement && *mCopyrightStatement) + return i18n(mCopyrightStatement); + else + return TQString(); +} diff --git a/src/common/nokde/nokde_tdeaboutdata.h b/src/common/nokde/nokde_tdeaboutdata.h new file mode 100644 index 0000000..93a7768 --- /dev/null +++ b/src/common/nokde/nokde_tdeaboutdata.h @@ -0,0 +1,571 @@ +// modified from KDE 3.4 for Windows port (Nicolas Hadacek) + +/* + * This file is part of the KDE Libraries + * Copyright (C) 2000 Espen Sand (espen@kde.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include +#if [[[TQT_VERSION IS DEPRECATED]]] < 0x040000 +# include +#else +# include +# define TQValueList Q3ValueList +# include +#endif +#include +//#include + +#include "nokde_klocale.h" + +#ifndef _KABOUTDATA_H_ +#define _KABOUTDATA_H_ + +class TDEAboutPersonPrivate; +class TDEAboutDataPrivate; + +/** + * This structure is used to store information about a person or developer. + * It can store the person's name, a task, an email address and a + * link to a home page. This class is intended for use in the + * TDEAboutData class, but it can be used elsewhere as well. + * Normally you should at least define the person's name. + * + * Example Usage within a main(): + * + * TDEAboutData about("khello", I18N_NOOP("KHello"), "0.1", + * I18N_NOOP("A TDE version of Hello, world!"), + * TDEAboutData::License_LGPL, + * I18N_NOOP("Copyright (c) 2003 Developer")); + * + * about.addAuthor("Joe Developer", I18N_NOOP("developer"), "joe@host.com", 0); + * about.addCredit("Joe User", I18N_NOOP("A lot of bug reports"), + * "joe.user@host.org", 0); + * TDECmdLineArgs::init(argc, argv, &about); + */ +class TDECORE_EXPORT TDEAboutPerson +{ +public: + /** + * Convenience constructor + * + * @param name The name of the person. + * + * @param task The task of this person. This string should be + * marked for translation, e.g. + * I18N_NOOP("Task description....") + * + * @param emailAddress The email address of the person. + * + * @param webAddress Home page of the person. + */ + TDEAboutPerson( const char *name, const char *task, + const char *emailAddress, const char *webAddress ) + { + mName = name; + mTask = task; + mEmailAddress = emailAddress; + mWebAddress = webAddress; + } + /** + * @internal + * Don't use. Required by TQValueList + */ + TDEAboutPerson() {} + + /** + * The person's name + * @return the person's name (can be TQString(), if it has been + * constructed with a null name) + */ + TQString name() const; + + /** + * The person's task + * @return the person's task (can be TQString(), if it has been + * constructed with a null task) + */ + TQString task() const; + + /** + * The person's email address + * @return the person's email address (can be TQString(), if it has been + * constructed with a null email) + */ + TQString emailAddress() const; + + /** + * The home page or a relevant link + * @return the persons home page (can be TQString(), if it has been + * constructed with a null home page) + */ + TQString webAddress() const; + +private: + const char *mName; + const char *mTask; + const char *mEmailAddress; + const char *mWebAddress; + + TDEAboutPersonPrivate *d; +}; + +class TDEAboutTranslatorPrivate; +/** + * This structure is used to store information about a translator. + * It can store the translator's name and an email address. + * This class is intended for use in the TDEAboutData class, + * but it can be used elsewhere as well. + * Normally you should at least define the translator's name. + * + * It's not possible to use TDEAboutPerson for this, because + * TDEAboutPerson stores internally only const char* pointers, but the + * translator information is generated dynamically from the translation + * of a dummy string. +*/ +class TDECORE_EXPORT TDEAboutTranslator +{ +public: + /** + * Convenience constructor + * + * @param name The name of the person. + * + * @param emailAddress The email address of the person. + */ + TDEAboutTranslator(const TQString & name=TQString(), + const TQString & emailAddress=TQString()); + + /** + * The translator's name + * @return the translators's name (can be TQString(), if it has been + * constructed with a null name) + */ + TQString name() const; + + /** + * The translator's email + * @return the translator's email address (can be TQString(), if it has been + * constructed with a null email) + */ + TQString emailAddress() const; + +private: + TQString mName; + TQString mEmail; + TDEAboutTranslatorPrivate* d; +}; + + +/** + * This class is used to store information about a program. It can store + * such values as version number, program name, home page, email address + * for bug reporting, multiple authors and contributors + * (using TDEAboutPerson), license and copyright information. + * + * Currently, the values set here are shown by the "About" box + * (see TDEAboutDialog), used by the bug report dialog (see KBugReport), + * and by the help shown on command line (see TDECmdLineArgs). + * + * @short Holds information needed by the "About" box and other + * classes. + * @author Espen Sand (espen@kde.org), David Faure (faure@kde.org) + */ +class TDECORE_EXPORT TDEAboutData +{ + public: + /** + * Descibes the license of the software. + */ + enum LicenseKey + { + License_Custom = -2, + License_File = -1, + License_Unknown = 0, + License_GPL = 1, + License_GPL_V2 = 1, + License_LGPL = 2, + License_LGPL_V2 = 2, + License_BSD = 3, + License_Artistic = 4, + License_TQPL = 5, + License_TQPL_V1_0 = 5 + }; + + public: + /** + * Constructor. + * + * @param appName The program name used internally. Example: "kedit" + * + * @param programName A displayable program name string. This string + * should be marked for translation. Example: I18N_NOOP("KEdit") + * + * @param version The program version string. + * + * @param shortDescription A short description of what the program does. + * This string should be marked for translation. + * Example: I18N_NOOP("A simple text editor.") + * + * @param licenseType The license identifier. Use setLicenseText if + * you use a license not predefined here. + * + * @param copyrightStatement A copyright statement, that can look like this: + * "(c) 1999-2000, Name". The string specified here is not modified + * in any manner. The author information from addAuthor is not + * used. + * + * @param text Some free form text, that can contain any kind of + * information. The text can contain newlines. This string + * should be marked for translation. + * + * @param homePageAddress The program homepage string. + * Start the address with "http://". "http://some.domain" is + * is correct, "some.domain" is not. + * + * @param bugsEmailAddress The bug report email address string. + * This defaults to the kde.org bug system. + * + */ + TDEAboutData( const char *appName, + const char *programName, + const char *version, + const char *shortDescription = 0, + int licenseType = License_Unknown, + const char *copyrightStatement = 0, + const char *text = 0, + const char *homePageAddress = 0, + const char *bugsEmailAddress = "submit@bugs.kde.org" + ); + + ~TDEAboutData(); + + /** + * Defines an author. You can call this function as many times you + * need. Each entry is appended to a list. The person in the first entry + * is assumed to be the leader of the project. + * + * @param name The developer's name in UTF-8 encoding. + * + * @param task What the person is responsible for. This text can contain + * newlines. It should be marked for translation like this: + * I18N_NOOP("Task description..."). Can be 0. + * + * @param emailAddress An Email address where the person can be reached. + * Can be 0. + * + * @param webAddress The person's homepage or a relevant link. + * Start the address with "http://". "http://some.domain" is + * correct, "some.domain" is not. Can be 0. + * + */ + void addAuthor( const char *name, + const char *task=0, + const char *emailAddress=0, + const char *webAddress=0 ); + + /** + * Defines a person that deserves credit. You can call this function + * as many times you need. Each entry is appended to a list. + * + * @param name The person's name in UTF-8 encoding. + * + * @param task What the person has done to deserve the honor. The + * text can contain newlines. It should be marked for + * translation like this: I18N_NOOP("Task description...") + * Can be 0. + * + * @param emailAddress An Email address when the person can be reached. + * Can be 0. + * + * @param webAddress The person's homepage or a relevant link. + * Start the address with "http://". "http://some.domain" is + * is correct, "some.domain" is not. Can be 0. + * + */ + void addCredit( const char *name, + const char *task=0, + const char *emailAddress=0, + const char *webAddress=0 ); + + /** + * Sets the name of the translator of the gui. Since this depends + * on the language, just use a dummy text marked for translation. + * + * For example: + * \code + * setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\\nYour names") + * ,I18N_NOOP("_: EMAIL OF TRANSLATORS\\nYour emails")); + * \endcode + * + * The translator can then translate this dummy text with his name + * or with a list of names separated with ",". + * If there is no translation or the application is used with the + * default language, this function call is ignored. + * + * Note: If you are using the default KDE automake environment, + * there is no need to use this function, because the two + * default strings above are added to the applications po file + * automatically. + * + * @param name the name of the translator + * @param emailAddress the email address of the translator + * @see TDEAboutTranslator + */ + void setTranslator(const char* name, const char* emailAddress); + + /** + * Defines a license text. + * + * The text will be translated if it got marked for + * translations with the I18N_NOOP() macro. + * + * Example: + * \code + * setLicenseText( I18N_NOOP("This is my license")); + * \endcode + * + * NOTE: No copy of the text is made. + * + * @param license The license text in utf8 encoding. + */ + void setLicenseText( const char *license ); + + /** + * Defines a license text. + * + * @param file File containing the license text. + */ + void setLicenseTextFile( const TQString &file ); + + /** + * Defines the program name used internally. + * + * @param appName The application name. Example: "kate". + */ + void setAppName( const char *appName ); + + /** + * Defines the displayable program name string. + * + * @param programName The program name. This string should be + * marked for translation. + * Example: I18N_NOOP("Advanced Text Editor"). + */ + void setProgramName( const char* programName ); + + /** + * Defines the program logo. + * Use this if you need to have application logo + * in AboutData other than application icon. + * + * @param image logo image. + * @see programLogo() + * @since 3.4 + */ +// void setProgramLogo(const TQImage& image); + + /** + * Defines the program version string. + * + * @param version The program version. + */ + void setVersion( const char* version ); + + /** + * Defines a short description of what the program does. + * + * @param shortDescription The program description This string should be marked + * for translation. Example: I18N_NOOP("An advanced text editor + * with syntax highlithing support."). + */ + void setShortDescription( const char *shortDescription ); + + /** + * Defines the license identifier. + * + * @param licenseKey The license identifier. + */ + void setLicense( LicenseKey licenseKey); + + /** + * Defines the copyright statement to show when displaying the license. + * + * @param copyrightStatement A copyright statement, that can look like + * this: "(c) 1999-2000, Name". The string specified here is not + * modified in any manner. The author information from addAuthor + * is not used. + */ + void setCopyrightStatement( const char *copyrightStatement ); + + /** + * Defines the additional text to show in the about dialog. + * + * @param otherText Some free form text, that can contain any kind of + * information. The text can contain newlines. This string + * should be marked for translation. + */ + void setOtherText( const char *otherText ); + + /** + * Defines the program homepage. + * + * @param homepage The program homepage string. + * Start the address with "http://". "http://kate.kde.org" is + * is correct, "kde.kde.org" is not. + */ + void setHomepage( const char *homepage ); + + /** + * Defines the address where bug reports should be sent. + * + * @param bugAddress The bug report email address string. + * This defaults to the kde.org bug system. + */ + void setBugAddress( const char *bugAddress ); + + /** + * Defines the product name wich will be used in the KBugReport dialog. + * By default it's the appName, but you can overwrite it here to provide + * support for special components e.g. 'product/component' like + * 'kontact/summary'. + * + * @param name The name of product + */ + void setProductName( const char *name ); + + /** + * Returns the application's internal name. + * @return the internal program name. + */ + const char *appName() const; + + /** + * Returns the application's product name, which will be used in KBugReport + * dialog. By default it returns appName(), otherwise the one which is set + * with setProductName() + * + * @return the product name. + */ + const char *productName() const; + + /** + * Returns the translated program name. + * @return the program name (translated). + */ + TQString programName() const; + + /** + * Returns the program logo image. + * @return the program logo data or null image if there is + * no custom application logo defined. + * @since 3.4 + */ +// TQImage programLogo() const; + + /** + * Returns the program's version. + * @return the version string. + */ + TQString version() const; + + /** + * Returns a short, translated description. + * @return the short description (translated). Can be + * TQString() if not set. + */ + TQString shortDescription() const; + + /** + * Returns the application homepage. + * @return the application homepage URL. Can be TQString() if + * not set. + */ + TQString homepage() const; + + /** + * Returns the email address for bugs. + * @return the email address where to report bugs. + */ + TQString bugAddress() const; + + /** + * Returns a list of authors. + * @return author information (list of persons). + */ + const TQValueList authors() const; + + /** + * Returns a list of persons who contributed. + * @return credit information (list of persons). + */ + const TQValueList credits() const; + + /** + * Returns a list of translators. + * @return translators information (list of persons) + */ + const TQValueList translators() const; + + /** + * Returns a message about the translation team. + * @return a message about the translation team + */ + static TQString aboutTranslationTeam(); + + /** + * Returns a translated, free form text. + * @return the free form text (translated). Can be TQString() if not set. + */ + TQString otherText() const; + + /** + * Returns the license. If the licenseType argument of the constructor has been + * used, any text defined by setLicenseText is ignored, + * and the standard text for the chosen license will be returned. + * + * @return The license text. + */ + TQString license() const; + + /** + * Returns the copyright statement. + * @return the copyright statement. Can be TQString() if not set. + */ + TQString copyrightStatement() const; + + private: + const char *mAppName; + const char *mProgramName; + const char *mVersion; + const char *mShortDescription; + int mLicenseKey; + const char *mCopyrightStatement; + const char *mOtherText; + const char *mHomepageAddress; + const char *mBugEmailAddress; + TQValueList mAuthorList; + TQValueList mCreditList; + const char *mLicenseText; + + TDEAboutDataPrivate *d; +}; + +#endif + diff --git a/src/common/nokde/nokde_tdecmdlineargs.cpp b/src/common/nokde/nokde_tdecmdlineargs.cpp new file mode 100644 index 0000000..4480077 --- /dev/null +++ b/src/common/nokde/nokde_tdecmdlineargs.cpp @@ -0,0 +1,1329 @@ +// modified from KDE 3.4 for Windows port (Nicolas Hadacek) + +/* + Copyright (C) 1999 Waldo Bastian + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +//#include + +#include + +#include +#include +#include +#include +#include + +#ifdef HAVE_LIMITS_H +#include +#endif + +#include +#include +#include + +#include +#if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 +# include +# include +#else +# include +# define TQGList Q3GList +# define TQStrList Q3StrList +# include +# define TQGDict Q3GDict +# define TQAsciiDict Q3AsciiDict +# include +# define TQPtrCollection Q3PtrCollection +#endif + + +#include "nokde_tdecmdlineargs.h" +#include "nokde_tdeaboutdata.h" +#include "nokde_klocale.h" +//#include +//#include +//#include +//#include + +#ifdef TQ_WS_X11 +#define DISPLAY "DISPLAY" +#elif defined(TQ_WS_TQWS) +#define DISPLAY "TQWS_DISPLAY" +#endif + +#ifdef TQ_WS_WIN +#include +#endif + +template class TQAsciiDict; +template class TQPtrList; + +class TDECmdLineParsedOptions : public TQAsciiDict +{ +public: + TDECmdLineParsedOptions() + : TQAsciiDict( 7 ) { } + + // WABA: Huh? + // The compiler doesn't find TDECmdLineParsedOptions::write(s) by itself ??? + // WABA: No, because there is another write function that hides the + // write function in the base class even though this function has a + // different signature. (obscure C++ feature) + TQDataStream& save( TQDataStream &s) const + { return TQGDict::write(s); } + + TQDataStream& load( TQDataStream &s) + { return TQGDict::read(s); } + +protected: + virtual TQDataStream& write( TQDataStream &s, TQPtrCollection::Item data) const + { + TQCString *str = (TQCString *) data; + s << (*str); + return s; + } + + virtual TQDataStream& read( TQDataStream &s, TQPtrCollection::Item &item) + { + TQCString *str = new TQCString; + s >> (*str); + item = (void *)str; + return s; + } + +}; + +class TDECmdLineParsedArgs : public TQStrList +{ +public: + TDECmdLineParsedArgs() + : TQStrList( true ) { } + TQDataStream& save( TQDataStream &s) const + { return TQGList::write(s); } + + TQDataStream& load( TQDataStream &s) + { return TQGList::read(s); } +}; + + +class TDECmdLineArgsList: public TQPtrList +{ +public: + TDECmdLineArgsList() { } +}; + +TDECmdLineArgsList *TDECmdLineArgs::argsList = 0; +int TDECmdLineArgs::argc = 0; +char **TDECmdLineArgs::argv = 0; +char *TDECmdLineArgs::mCwd = 0; +//static KStaticDeleter mCwdd; +const TDEAboutData *TDECmdLineArgs::about = 0; +bool TDECmdLineArgs::parsed = false; +bool TDECmdLineArgs::ignoreUnknown = false; + +// +// Static functions +// + +void +TDECmdLineArgs::init(int _argc, char **_argv, const char *_appname, const char* programName, + const char *_description, const char *_version, bool noKApp) +{ + init(_argc, _argv, + new TDEAboutData(_appname, programName, _version, _description), + noKApp); +} + +void +TDECmdLineArgs::init(int _argc, char **_argv, const char *_appname, + const char *_description, const char *_version, bool noKApp) +{ + init(_argc, _argv, + new TDEAboutData(_appname, _appname, _version, _description), + noKApp); +} + +void +TDECmdLineArgs::initIgnore(int _argc, char **_argv, const char *_appname ) +{ + init(_argc, _argv, + new TDEAboutData(_appname, _appname, "unknown", "TDE Application", false)); + ignoreUnknown = true; +} + +void +TDECmdLineArgs::init(const TDEAboutData* ab) +{ + char **_argv = (char **) malloc(sizeof(char *)); + _argv[0] = (char *) ab->appName(); + init(1,_argv,ab, true); +} + + +void +TDECmdLineArgs::init(int _argc, char **_argv, const TDEAboutData *_about, bool /*noKApp*/) +{ + argc = _argc; + argv = _argv; + + if (!argv) + { + fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); + fprintf(stderr, "Passing null-pointer to 'argv' is not allowed.\n\n"); + + assert( 0 ); + exit(255); + } + + // Strip path from argv[0] + if (argc) { + char *p = strrchr( argv[0], '/'); + if (p) + argv[0] = p+1; + } + + about = _about; + parsed = false; + mCwd = /*mCwdd.setObject(mCwd, */new char [PATH_MAX+1];//, true); + getcwd(mCwd, PATH_MAX); +#ifdef TQ_WS_WIN + win32_slashify(mCwd, PATH_MAX); +#endif +// if (!noKApp) +// TDEApplication::addCmdLineOptions(); +} + +TQString TDECmdLineArgs::cwd() +{ + return TQFile::decodeName(TQCString(mCwd)); +} + +const char * TDECmdLineArgs::appName() +{ + if (!argc) return 0; + return argv[0]; +} + +void +TDECmdLineArgs::addCmdLineOptions( const TDECmdLineOptions *options, const char *name, + const char *id, const char *afterId) +{ + if (!argsList) + argsList = new TDECmdLineArgsList(); + + int pos = argsList->count(); + + if (pos && id && argsList->last() && !argsList->last()->name) + pos--; + + TDECmdLineArgs *args; + int i = 0; + for(args = argsList->first(); args; args = argsList->next(), i++) + { + if (!id && !args->id) + return; // Options already present. + + if (id && args->id && (::qstrcmp(id, args->id) == 0)) + return; // Options already present. + + if (afterId && args->id && (::qstrcmp(afterId, args->id) == 0)) + pos = i+1; + } + + assert( parsed == false ); // You must add _ALL_ cmd line options + // before accessing the arguments! + args = new TDECmdLineArgs(options, name, id); + argsList->insert(pos, args); +} + +void +TDECmdLineArgs::saveAppArgs( TQDataStream &ds) +{ + if (!parsed) + parseAllArgs(); + + // Remove TQt and KDE options. + removeArgs("qt"); + removeArgs("kde"); + + TQCString qCwd = mCwd; + ds << qCwd; + + uint count = argsList ? argsList->count() : 0; + ds << count; + + if (!count) return; + + TDECmdLineArgs *args; + for(args = argsList->first(); args; args = argsList->next()) + { + ds << TQCString(args->id); + args->save(ds); + } +} + +void +TDECmdLineArgs::loadAppArgs( TQDataStream &ds) +{ + // Remove TQt and KDE options. + removeArgs("qt"); + removeArgs("kde"); + + TDECmdLineArgs *args; + if ( argsList ) { + for(args = argsList->first(); args; args = argsList->next()) + { + args->clear(); + } + } + + if (ds.atEnd()) + return; + + TQCString qCwd; + ds >> qCwd; + delete [] mCwd; + + mCwd = /*mCwdd.setObject(mCwd, */new char[qCwd.length()+1];//, true); + strncpy(mCwd, qCwd.data(), qCwd.length()+1); + + uint count; + ds >> count; + + while(count--) + { + TQCString id; + ds >> id; + assert( argsList ); + for(args = argsList->first(); args; args = argsList->next()) + { + if (args->id == id) + { + args->load(ds); + break; + } + } + } + parsed = true; +} + +TDECmdLineArgs *TDECmdLineArgs::parsedArgs(const char *id) +{ + TDECmdLineArgs *args = argsList ? argsList->first() : 0; + while(args) + { + if ((id && ::qstrcmp(args->id, id) == 0) || (!id && !args->id)) + { + if (!parsed) + parseAllArgs(); + return args; + } + args = argsList->next(); + } + + return args; +} + +void TDECmdLineArgs::removeArgs(const char *id) +{ + TDECmdLineArgs *args = argsList ? argsList->first() : 0; + while(args) + { + if (args->id && id && ::qstrcmp(args->id, id) == 0) + { + if (!parsed) + parseAllArgs(); + break; + } + args = argsList->next(); + } + + if (args) + delete args; +} + +/* + * @return: + * 0 - option not found. + * 1 - option found // -fork + * 2 - inverse option found ('no') // -nofork + * 3 - option + arg found // -fork now + * + * +4 - no more options follow // !fork + */ +static int +findOption(const TDECmdLineOptions *options, TQCString &opt, + const char *&opt_name, const char *&def, bool &enabled) +{ + int result; + bool inverse; + int len = opt.length(); + while(options && options->name) + { + result = 0; + inverse = false; + opt_name = options->name; + if ((opt_name[0] == ':') || (opt_name[0] == 0)) + { + options++; + continue; + } + + if (opt_name[0] == '!') + { + opt_name++; + result = 4; + } + if ((opt_name[0] == 'n') && (opt_name[1] == 'o')) + { + opt_name += 2; + inverse = true; + } + if (strncmp(opt.data(), opt_name, len) == 0) + { + opt_name += len; + if (!opt_name[0]) + { + if (inverse) + return result+2; + + if (!options->description) + { + options++; + if (!options->name) + return result+0; + TQCString nextOption = options->name; +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 + int p = nextOption.find(' '); +#else + int p = TQString(nextOption).indexOf(' '); +#endif + if (p > 0) + nextOption = nextOption.left(p); + if (strncmp(nextOption.data(), "no", 2) == 0) + { + nextOption = nextOption.mid(2); + enabled = !enabled; + } + result = findOption(options, nextOption, opt_name, def, enabled); + assert(result); + opt = nextOption; + return result; + } + + return 1; + } + if (opt_name[0] == ' ') + { + opt_name++; + def = options->def; + return result+3; + } + } + + options++; + } + return 0; +} + + +void +TDECmdLineArgs::findOption(const char *_opt, TQCString opt, int &i, bool _enabled, bool &moreOptions) +{ + TDECmdLineArgs *args = argsList->first(); + const char *opt_name; + const char *def; + TQCString argument; +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 + int j = opt.find('='); +#else + int j = TQString(opt).indexOf('='); +#endif + if (j != -1) + { + argument = opt.mid(j+1); + opt = opt.left(j); + } + + bool enabled = true; + int result = 0; + while (args) + { + enabled = _enabled; + result = ::findOption(args->options, opt, opt_name, def, enabled); + if (result) break; + args = argsList->next(); + } + if (!args && (_opt[0] == '-') && _opt[1] && (_opt[1] != '-')) + { + // Option not found check if it is a valid option + // in the style of -Pprinter1 or ps -aux + int p = 1; + while (true) + { + TQCString singleCharOption = " "; + singleCharOption[0] = _opt[p]; + args = argsList->first(); + while (args) + { + enabled = _enabled; + result = ::findOption(args->options, singleCharOption, opt_name, def, enabled); + if (result) break; + args = argsList->next(); + } + if (!args) + break; // Unknown argument + + p++; + if (result == 1) // Single option + { + args->setOption(singleCharOption, enabled); + if (_opt[p]) + continue; // Next option + else + return; // Finished + } + else if (result == 3) // This option takes an argument + { + if (argument.isEmpty()) + { + argument = _opt+p; + } + args->setOption(singleCharOption, argument.data()); + return; + } + break; // Unknown argument + } + args = 0; + result = 0; + } + + if (!args || !result) + { + if (ignoreUnknown) + return; + enable_i18n(); + usage( i18n("Unknown option '%1'.").arg(TQString::fromLocal8Bit(_opt))); + } + + if ((result & 4) != 0) + { + result &= ~4; + moreOptions = false; + } + + if (result == 3) // This option takes an argument + { + if (!enabled) + { + if (ignoreUnknown) + return; + enable_i18n(); + usage( i18n("Unknown option '%1'.").arg(TQString::fromLocal8Bit(_opt))); + } + if (argument.isEmpty()) + { + i++; + if (i >= argc) + { + enable_i18n(); + usage( i18n("'%1' missing.").arg( opt_name)); + } + argument = argv[i]; + } + args->setOption(opt, argument.data()); + } + else + { + args->setOption(opt, enabled); + } +} + +void +TDECmdLineArgs::printQ(const TQString &msg) +{ +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 + TQCString localMsg = msg.local8Bit(); +#else + TQCString localMsg = msg.toLocal8Bit(); +#endif + fprintf(stdout, "%s", localMsg.data()); +} + +void +TDECmdLineArgs::parseAllArgs() +{ + bool allowArgs = false; + bool inOptions = true; + bool everythingAfterArgIsArgs = false; + TDECmdLineArgs *appOptions = argsList->last(); + if (!appOptions->id) + { + const TDECmdLineOptions *option = appOptions->options; + while(option && option->name) + { + if (option->name[0] == '+') + allowArgs = true; + if ( option->name[0] == '!' && option->name[1] == '+' ) + { + allowArgs = true; + everythingAfterArgIsArgs = true; + } + option++; + } + } + for(int i = 1; i < argc; i++) + { + if (!argv[i]) + continue; + + if ((argv[i][0] == '-') && argv[i][1] && inOptions) + { + bool enabled = true; + const char *option = &argv[i][1]; + const char *orig = argv[i]; + if (option[0] == '-') + { + option++; + argv[i]++; + if (!option[0]) + { + inOptions = false; + continue; + } + } + if (::qstrcmp(option, "help") == 0) + { + usage(0); + } + else if (strncmp(option, "help-",5) == 0) + { + usage(option+5); + } + else if ( (::qstrcmp(option, "version") == 0) || + (::qstrcmp(option, "v") == 0)) + { + printQ( TQString("TQt: %1\n").arg(tqVersion())); +// printQ( TQString("KDE: %1\n").arg(TDE_VERSION_STRING)); + printQ( TQString("%1: %2\n"). + arg(about->programName()).arg(about->version())); + exit(0); + } else if ( (::qstrcmp(option, "license") == 0) ) + { + enable_i18n(); + printQ( about->license() ); + printQ( "\n" ); + exit(0); + } else if ( ::qstrcmp( option, "author") == 0 ) { + enable_i18n(); + if ( about ) { + const TQValueList authors = about->authors(); + if ( !authors.isEmpty() ) { + TQString authorlist; + for (TQValueList::ConstIterator it = authors.begin(); it != authors.end(); ++it ) { + TQString email; + if ( !(*it).emailAddress().isEmpty() ) + email = " <" + (*it).emailAddress() + ">"; + authorlist += TQString(" ") + (*it).name() + email + "\n"; + } + printQ( i18n("the 2nd argument is a list of name+address, one on each line","%1 was written by\n%2").arg ( TQString(about->programName()) ).arg( authorlist ) ); + } + } else { + printQ( i18n("%1 was written by somebody who wants to remain anonymous.").arg(about->programName()) ); + } + if (!about->bugAddress().isEmpty()) + { + if (about->bugAddress() == "submit@bugs.kde.org") + printQ( i18n( "Please use http://bugs.kde.org to report bugs, do not mail the authors directly.\n" ) ); + else + printQ( i18n( "Please use %1 to report bugs, do not mail the authors directly.\n" ).arg(about->bugAddress()) ); + } + exit(0); + } else { + if ((option[0] == 'n') && (option[1] == 'o')) + { + option += 2; + enabled = false; + } + findOption(orig, option, i, enabled, inOptions); + } + } + else + { + // Check whether appOptions allows these arguments + if (!allowArgs) + { + if (ignoreUnknown) + continue; + enable_i18n(); + usage( i18n("Unexpected argument '%1'.").arg(TQString::fromLocal8Bit(argv[i]))); + } + else + { + appOptions->addArgument(argv[i]); + if (everythingAfterArgIsArgs) + inOptions = false; + } + } + } + parsed = true; +} + +/** + * For TDEApplication only: + * + * Return argc + */ +int * +TDECmdLineArgs::tqt_argc() +{ +// if (!argsList) +// TDEApplication::addCmdLineOptions(); // Lazy bastards! + + static int tqt_argc = -1; + if( tqt_argc != -1 ) + return &tqt_argc; + + TDECmdLineArgs *args = parsedArgs("qt"); + assert(args); // No qt options have been added! + if (!argv) + { + fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); + fprintf(stderr, "Application has not called TDECmdLineArgs::init(...).\n\n"); + + assert( 0 ); + exit(255); + } + + assert(argc >= (args->count()+1)); + tqt_argc = args->count() +1; + return &tqt_argc; +} + +/** + * For TDEApplication only: + * + * Return argv + */ +char *** +TDECmdLineArgs::tqt_argv() +{ +// if (!argsList) +// TDEApplication::addCmdLineOptions(); // Lazy bastards! + + static char** tqt_argv; + if( tqt_argv != NULL ) + return &tqt_argv; + + TDECmdLineArgs *args = parsedArgs("qt"); + assert(args); // No qt options have been added! + if (!argv) + { + fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); + fprintf(stderr, "Application has not called TDECmdLineArgs::init(...).\n\n"); + + assert( 0 ); + exit(255); + } + + tqt_argv = new char*[ args->count() + 2 ]; + tqt_argv[ 0 ] = tqstrdup( appName()); + int i = 0; + for(; i < args->count(); i++) + { + tqt_argv[i+1] = tqstrdup((char *) args->arg(i)); + } + tqt_argv[i+1] = 0; + + return &tqt_argv; +} + +void +TDECmdLineArgs::enable_i18n() +{ + // called twice or too late +/* if (TDEGlobal::_locale) + return; + + if (!TDEGlobal::_instance) { + TDEInstance *instance = new TDEInstance(about); + (void) instance->config(); + // Don't delete instance! + }*/ +} + +void +TDECmdLineArgs::usage(const TQString &error) +{ +// assert(TDEGlobal::_locale); +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 + TQCString localError = error.local8Bit(); +#else + TQCString localError = error.toLocal8Bit(); +#endif + if (localError[error.length()-1] == '\n') + localError = localError.left(error.length()-1); + fprintf(stderr, "%s: %s\n", argv[0], localError.data()); + + TQString tmp = i18n("Use --help to get a list of available command line options."); +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 + localError = tmp.local8Bit(); +#else + localError = tmp.toLocal8Bit(); +#endif + fprintf(stderr, "%s: %s\n", argv[0], localError.data()); + exit(254); +} + +void +TDECmdLineArgs::usage(const char *id) +{ + enable_i18n(); + assert(argsList != 0); // It's an error to call usage(...) without + // having done addCmdLineOptions first! + + TQString optionFormatString = " %1 %2\n"; + TQString optionFormatStringDef = " %1 %2 [%3]\n"; + TQString optionHeaderString = i18n("\n%1:\n"); + TQString tmp; + TQString usage; + + TDECmdLineArgs *args = argsList->last(); + + if (!(args->id) && (args->options) && + (args->options->name) && (args->options->name[0] != '+')) + { + usage = i18n("[options] ")+usage; + } + + while(args) + { + if (args->name) + { + usage = i18n("[%1-options]").arg(args->name)+" "+usage; + } + args = argsList->prev(); + } + + TDECmdLineArgs *appOptions = argsList->last(); + if (!appOptions->id) + { + const TDECmdLineOptions *option = appOptions->options; + while(option && option->name) + { + if (option->name[0] == '+') + usage = usage + (option->name+1) + " "; + else if ( option->name[0] == '!' && option->name[1] == '+' ) + usage = usage + (option->name+2) + " "; + + option++; + } + } + + printQ(i18n("Usage: %1 %2\n").arg(argv[0]).arg(usage)); + printQ("\n"+about->shortDescription()+"\n"); + + printQ(optionHeaderString.arg(i18n("Generic options"))); + printQ(optionFormatString.arg("--help", -25).arg(i18n("Show help about options"))); + + args = argsList->first(); + while(args) + { + if (args->name && args->id) + { + TQString option = TQString("--help-%1").arg(args->id); + TQString desc = i18n("Show %1 specific options").arg(args->name); + + printQ(optionFormatString.arg(option, -25).arg(desc)); + } + args = argsList->next(); + } + + printQ(optionFormatString.arg("--help-all",-25).arg(i18n("Show all options"))); + printQ(optionFormatString.arg("--author",-25).arg(i18n("Show author information"))); + printQ(optionFormatString.arg("-v, --version",-25).arg(i18n("Show version information"))); + printQ(optionFormatString.arg("--license",-25).arg(i18n("Show license information"))); + printQ(optionFormatString.arg("--", -25).arg(i18n("End of options"))); + + args = argsList->first(); // Sets current to 1st. + + bool showAll = id && (::qstrcmp(id, "all") == 0); + + if (!showAll) + { + while(args) + { + if (!id && !args->id) break; + if (id && (::qstrcmp(args->id, id) == 0)) break; + args = argsList->next(); + } + } + + while(args) + { + bool hasArgs = false; + bool hasOptions = false; + TQString optionsHeader; + if (args->name) + optionsHeader = optionHeaderString.arg(i18n("%1 options").arg(TQString::fromLatin1(args->name))); + else + optionsHeader = i18n("\nOptions:\n"); + + while (args) + { + const TDECmdLineOptions *option = args->options; + TQCString opt = ""; +// + while(option && option->name) + { + TQString description; + TQString descriptionRest; + TQStringList dl; + + // Option header + if (option->name[0] == ':') + { + if (option->description) + { + optionsHeader = "\n"+i18n(option->description); + if (!optionsHeader.endsWith("\n")) + optionsHeader.append("\n"); + hasOptions = false; + } + option++; + continue; + } + + // Free-form comment + if (option->name[0] == 0) + { + if (option->description) + { + TQString tmp = "\n"+i18n(option->description); + if (!tmp.endsWith("\n")) + tmp.append("\n"); + printQ(tmp); + } + option++; + continue; + } + + // Options + if (option->description) + { + description = i18n(option->description); +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 + dl = TQStringList::split("\n", description, true); +#else + dl = description.split("\n"); +#endif + description = dl.first(); + dl.erase( dl.begin() ); + } + TQCString name = option->name; + if (name[0] == '!') + name = name.mid(1); + + if (name[0] == '+') + { + if (!hasArgs) + { + printQ(i18n("\nArguments:\n")); + hasArgs = true; + } + + name = name.mid(1); + if ((name[0] == '[') && (name[name.length()-1] == ']')) + name = name.mid(1, name.length()-2); + printQ(optionFormatString.arg(TQString(name), -25) + .arg(description)); + } + else + { + if (!hasOptions) + { + printQ(optionsHeader); + hasOptions = true; + } + + if ((name.length() == 1) || (name[1] == ' ')) + name = "-"+name; + else + name = "--"+name; + if (!option->description) + { + opt = name + ", "; + } + else + { + opt = opt + name; + if (!option->def) + { + printQ(optionFormatString.arg(TQString(opt), -25) + .arg(description)); + } + else + { + printQ(optionFormatStringDef.arg(TQString(opt), -25) + .arg(description).arg(option->def)); + } + opt = ""; + } + } + for(TQStringList::Iterator it = dl.begin(); + it != dl.end(); + ++it) + { + printQ(optionFormatString.arg("", -25).arg(*it)); + } + + option++; + } + args = argsList->next(); + if (!args || args->name || !args->id) break; + } + if (!showAll) break; + } + + exit(254); +} + +// +// Member functions +// + +/** + * Constructor. + * + * The given arguments are assumed to be constants. + */ +TDECmdLineArgs::TDECmdLineArgs( const TDECmdLineOptions *_options, + const char *_name, const char *_id) + : options(_options), name(_name), id(_id) +{ + parsedOptionList = 0; + parsedArgList = 0; + isTQt = (::qstrcmp(id, "qt") == 0); +} + +/** + * Destructor. + */ +TDECmdLineArgs::~TDECmdLineArgs() +{ + delete parsedOptionList; + delete parsedArgList; + if (argsList) + argsList->removeRef(this); +} + +void +TDECmdLineArgs::clear() +{ + delete parsedArgList; + parsedArgList = 0; + delete parsedOptionList; + parsedOptionList = 0; +} + +void +TDECmdLineArgs::reset() +{ + if ( argsList ) { + argsList->setAutoDelete( true ); + argsList->clear(); + delete argsList; + argsList = 0; + } + parsed = false; +} + +void +TDECmdLineArgs::save( TQDataStream &ds) const +{ + uint count = 0; + if (parsedOptionList) + parsedOptionList->save( ds ); + else + ds << count; + + if (parsedArgList) + parsedArgList->save( ds ); + else + ds << count; +} + +void +TDECmdLineArgs::load( TQDataStream &ds) +{ + if (!parsedOptionList) parsedOptionList = new TDECmdLineParsedOptions; + if (!parsedArgList) parsedArgList = new TDECmdLineParsedArgs; + + parsedOptionList->load( ds ); + parsedArgList->load( ds ); + + if (parsedOptionList->count() == 0) + { + delete parsedOptionList; + parsedOptionList = 0; + } + if (parsedArgList->count() == 0) + { + delete parsedArgList; + parsedArgList = 0; + } +} + +void +TDECmdLineArgs::setOption(const TQCString &opt, bool enabled) +{ + if (isTQt) + { + // TQt does it own parsing. + TQCString arg = "-"; + if( !enabled ) + arg += "no"; + arg += opt; + addArgument(arg); + } + if (!parsedOptionList) { + parsedOptionList = new TDECmdLineParsedOptions; + parsedOptionList->setAutoDelete(true); + } + + if (enabled) + parsedOptionList->replace( opt, new TQCString("t") ); + else + parsedOptionList->replace( opt, new TQCString("f") ); +} + +void +TDECmdLineArgs::setOption(const TQCString &opt, const char *value) +{ + if (isTQt) + { + // TQt does it's own parsing. + TQCString arg = "-"; + arg += opt; + addArgument(arg); + addArgument(value); + +#ifdef TQ_WS_X11 + // Hack coming up! + if (arg == "-display") + { + setenv(DISPLAY, value, true); + } +#endif + } + if (!parsedOptionList) { + parsedOptionList = new TDECmdLineParsedOptions; + parsedOptionList->setAutoDelete(true); + } + + parsedOptionList->insert( opt, new TQCString(value) ); +} + +TQCString +TDECmdLineArgs::getOption(const char *_opt) const +{ + TQCString *value = 0; + if (parsedOptionList) + { + value = parsedOptionList->find(_opt); + } + + if (value) + return (*value); + + // Look up the default. + const char *opt_name; + const char *def; + bool dummy = true; + TQCString opt = _opt; + int result = ::findOption( options, opt, opt_name, def, dummy) & ~4; + + if (result != 3) + { + fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); + fprintf(stderr, "Application requests for getOption(\"%s\") but the \"%s\" option\n", + _opt, _opt); + fprintf(stderr, "has never been specified via addCmdLineOptions( ... )\n\n"); + + assert( 0 ); + exit(255); + } + return TQCString(def); +} + +QCStringList +TDECmdLineArgs::getOptionList(const char *_opt) const +{ + QCStringList result; + if (!parsedOptionList) + return result; + + while(true) + { + TQCString *value = parsedOptionList->take(_opt); + if (!value) + break; + result.prepend(*value); + delete value; + } + + // Reinsert items in dictionary + // WABA: This is rather silly, but I don't want to add restrictions + // to the API like "you can only call this function once". + // I can't access all items without taking them out of the list. + // So taking them out and then putting them back is the only way. + for(QCStringList::ConstIterator it=result.begin(); + it != result.end(); + ++it) + { + parsedOptionList->insert(_opt, new TQCString(*it)); + } + return result; +} + +bool +TDECmdLineArgs::isSet(const char *_opt) const +{ + // Look up the default. + const char *opt_name; + const char *def; + bool dummy = true; + TQCString opt = _opt; + int result = ::findOption( options, opt, opt_name, def, dummy) & ~4; + + if (result == 0) + { + fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs):\n"); + fprintf(stderr, "Application requests for isSet(\"%s\") but the \"%s\" option\n", + _opt, _opt); + fprintf(stderr, "has never been specified via addCmdLineOptions( ... )\n\n"); + + assert( 0 ); + exit(255); + } + + TQCString *value = 0; + if (parsedOptionList) + { + value = parsedOptionList->find(opt); + } + + if (value) + { + if (result == 3) + return true; + else + return ((*value)[0] == 't'); + } + + if (result == 3) + return false; // String option has 'false' as default. + + // We return 'true' as default if the option was listed as '-nofork' + // We return 'false' as default if the option was listed as '-fork' + return (result == 2); +} + +int +TDECmdLineArgs::count() const +{ + if (!parsedArgList) + return 0; + return parsedArgList->count(); +} + +const char * +TDECmdLineArgs::arg(int n) const +{ + if (!parsedArgList || (n >= (int) parsedArgList->count())) + { + fprintf(stderr, "\n\nFAILURE (TDECmdLineArgs): Argument out of bounds\n"); + fprintf(stderr, "Application requests for arg(%d) without checking count() first.\n", + n); + + assert( 0 ); + exit(255); + } + + return parsedArgList->at(n); +} + +KURL +TDECmdLineArgs::url(int n) const +{ + return makeURL( arg(n) ); +} + +KURL TDECmdLineArgs::makeURL(const char *_urlArg) +{ + TQString urlArg = TQFile::decodeName(_urlArg); + if (!TQDir::isRelativePath(urlArg)) + { + //KURL result; + //result.setPath(urlArg); + //return result; // Absolute path. + return urlArg; + } +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 + if ( !TQUrl::isRelativeUrl(urlArg) ) +#else + if ( !TQUrl(urlArg).isRelative() ) +#endif + //return KURL(urlArg); // Argument is a URL + return urlArg; + +// KURL result; +// result.setPath( cwd()+"/"+urlArg ); +// result.cleanPath(); +// return result; // Relative path + return cwd() + "/" + urlArg; +} + +void +TDECmdLineArgs::addArgument(const char *argument) +{ + if (!parsedArgList) + parsedArgList = new TDECmdLineParsedArgs; + + parsedArgList->append(argument); +} + +static const TDECmdLineOptions kde_tempfile_option[] = +{ + { "tempfile", I18N_NOOP("The files/URLs opened by the application will be deleted after use"), 0}, + TDECmdLineLastOption +}; + +void +TDECmdLineArgs::addTempFileOption() +{ + TDECmdLineArgs::addCmdLineOptions( kde_tempfile_option, "KDE-tempfile", "kde-tempfile" ); +} + +bool TDECmdLineArgs::isTempFileSet() +{ + TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs( "kde-tempfile" ); + if ( args ) + return args->isSet( "tempfile" ); + return false; +} diff --git a/src/common/nokde/nokde_tdecmdlineargs.h b/src/common/nokde/nokde_tdecmdlineargs.h new file mode 100644 index 0000000..58931a6 --- /dev/null +++ b/src/common/nokde/nokde_tdecmdlineargs.h @@ -0,0 +1,701 @@ +// modified from KDE 3.4 for Windows port (Nicolas Hadacek) + +/* This file is part of the KDE project + Copyright (C) 1999 Waldo Bastian + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef _KCMDLINEARGS_H_ +#define _KCMDLINEARGS_H_ + +#include "nokde_klocale.h" +#include "nokde_kurl.h" + +# if [[[TQT_VERSION IS DEPRECATED]]]<0x040000 +# include +# include +#else +# include +# define TQCString Q3CString +# include +# define TQPtrList Q3PtrList +# include +# define TQValueList Q3ValueList +#endif +# include + +typedef TQValueList QCStringList; + +/** + * @short Structure that holds command line options. + * + * This class is intended to be used with the TDECmdLineArgs class, which + * provides convenient and powerful command line argument parsing and + * handling functionality. + * + * @see TDECmdLineArgs for additional usage information + */ +struct TDECORE_EXPORT TDECmdLineOptions +{ + /** + * The name of the argument as it should be called on the command line and + * appear in myapp --help. + * + * Note that if this option starts with "no" that you will need to test for + * the name without the "no" and the result will be the inverse of what is + * specified. i.e. if "nofoo" is the name of the option and + * myapp --nofoo is called: + * + * \code + * TDECmdLineArgs::parsedArgs()->isSet("foo"); // false + * \endcode + */ + const char *name; + /** + * The text description of the option as should appear in + * myapp --help. This value should be wrapped with I18N_NOOP(). + */ + const char *description; + /** + * The default value for the option, if it is not specified on the + * command line. + */ + const char *def; // Default +}; + +#define TDECmdLineLastOption { 0, 0, 0 } + +class TDECmdLineArgsList; +class TDEApplication; +class KUniqueApplication; +class TDECmdLineParsedOptions; +class TDECmdLineParsedArgs; +class TDEAboutData; +class TDECmdLineArgsPrivate; + +/** + * @short A class for command-line argument handling. + * + * TDECmdLineArgs provides simple access to the command-line arguments + * for an application. It takes into account TQt-specific options, + * KDE-specific options and application specific options. + * + * This class is used in %main() via the static method + * init(). + * + * A typical %KDE application using %TDECmdLineArgs should look like this: + * + * \code + * int main(int argc, char *argv[]) + * { + * // Initialize command line args + * TDECmdLineArgs::init(argc, argv, appName, programName, description, version); + * + * // Tell which options are supported + * TDECmdLineArgs::addCmdLineOptions( options ); + * + * // Add options from other components + * KUniqueApplication::addCmdLineOptions(); + * + * .... + * + * // Create application object without passing 'argc' and 'argv' again. + * KUniqueApplication app; + * + * .... + * + * // Handle our own options/arguments + * // A TDEApplication will usually do this in main but this is not + * // necessary. + * // A KUniqueApplication might want to handle it in newInstance(). + * + * TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + * + * // A binary option (on / off) + * if (args->isSet("some-option")) + * .... + * + * // An option which takes an additional argument + * TQCString anotherOptionArg = args->getOption("another-option"); + * + * // Arguments (e.g. files to open) + * for(int i = 0; i < args->count(); i++) // Counting start at 0! + * { + * // don't forget to convert to Unicode! + * openFile( TQFile::decodeName( args->arg(i))); + * // Or more convenient: + * // openURL( args->url(i)); + * + * } + * + * args->clear(); // Free up some memory. + * .... + * } + * \endcode + * + * The options that an application supports are configured using the + * TDECmdLineOptions class. An example is shown below: + * + * \code + * static const TDECmdLineOptions options[] = + * { + * { "a", I18N_NOOP("A short binary option"), 0 }, + * { "b \", I18N_NOOP("A short option which takes an argument"), 0 }, + * { "c \", I18N_NOOP("As above but with a default value"), "9600" }, + * { "option1", I18N_NOOP("A long binary option, off by default"), 0 }, + * { "nooption2", I18N_NOOP("A long binary option, on by default"), 0 }, + * { ":", I18N_NOOP("Extra options:"), 0 }, + * { "option3 \", I18N_NOOP("A long option which takes an argument"), 0 }, + * { "option4 \", I18N_NOOP("A long option which takes an argument, defaulting to 9600"), "9600" }, + * { "d", 0, 0 }, + * { "option5", I18N_NOOP("A long option which has a short option as alias"), 0 }, + * { "e", 0, 0 }, + * { "nooption6", I18N_NOOP("Another long option with an alias"), 0 }, + * { "f", 0, 0 }, + * { "option7 \", I18N_NOOP("'--option7 speed' is the same as '-f speed'"), 0 }, + * { "!option8 \", I18N_NOOP("All options following this one will be treated as arguments"), 0 }, + * { "+file", I18N_NOOP("A required argument 'file'"), 0 }, + * { "+[arg1]", I18N_NOOP("An optional argument 'arg1'"), 0 }, + * { "!+command", I18N_NOOP("A required argument 'command', that can contain multiple words, even starting with '-'"), 0 }, + * { "", I18N_NOOP("Additional help text not associated with any particular option") 0 }, + * TDECmdLineLastOption // End of options. + * }; + * \endcode + * + * The I18N_NOOP macro is used to indicate that these strings should be + * marked for translation. The actual translation is done by TDECmdLineArgs. + * You can't use i18n() here because we are setting up a static data + * structure and can't do translations at compile time. + * + * Note that a program should define the options before any arguments. + * + * When a long option has a short option as an alias, a program should + * only test for the long option. + * + * With the above options a command line could look like: + * \code + * myapp -a -c 4800 --display localhost:0.0 --nooption5 -d /tmp/file + * \endcode + * + * Long binary options can be in the form 'option' and 'nooption'. + * A command line may contain the same binary option multiple times, + * the last option determines the outcome: + * \code + * myapp --nooption4 --option4 --nooption4 + * \endcode + * is the same as: + * \code + * myapp --nooption4 + * \endcode + * + * If an option value is provided multiple times, normally only the last + * value is used: + * \code + * myapp -c 1200 -c 2400 -c 4800 + * \endcode + * is usually the same as: + * \code + * myapp -c 4800 + * \endcode + * + * However, an application can choose to use all values specified as well. + * As an example of this, consider that you may wish to specify a + * number of directories to use: + * \code + * myapp -I /usr/include -I /opt/kde/include -I /usr/X11/include + * \endcode + * When an application does this it should mention this in the description + * of the option. To access these options, use getOptionList() + * + * Tips for end-users: + * + * @li Single char options like "-a -b -c" may be combined into "-abc" + * @li The option "--foo bar" may also be written "--foo=bar" + * @li The option "-P lp1" may also be written "-P=lp1" or "-Plp1" + * @li The option "--foo bar" may also be written "-foo bar" + * + * @author Waldo Bastian + * @version 0.0.4 + */ +class TDECORE_EXPORT TDECmdLineArgs +{ + friend class TDEApplication; + friend class KUniqueApplication; + friend class TQPtrList; +public: + // Static functions: + + /** + * Initialize class. + * + * This function should be called as the very first thing in + * your application. + * @param _argc As passed to @p main(...). + * @param _argv As passed to @p main(...). + * @param _appname The untranslated name of your application. This should + * match with @p argv[0]. + * @param programName A program name string to be used for display + * purposes. This string should be marked for + * translation. Example: I18N_NOOP("KEdit") + * @param _description A short description of what your application is about. + * @param _version A version. + * @param noKApp Set this true to not add commandline options for + * TQApplication / TDEApplication + * + * @since 3.2 + */ + static void init(int _argc, char **_argv, const char *_appname, + const char* programName, const char *_description, + const char *_version, bool noKApp = false); + /** + * @deprecated + * You should convert any calls to this method to use the one + * above, by adding in the program name to be used for display + * purposes. Do not forget to mark it for translation using I18N_NOOP. + */ + static void init(int _argc, char **_argv, + const char *_appname, const char *_description, + const char *_version, bool noKApp = false) KDE_DEPRECATED; + + /** + * Initialize class. + * + * This function should be called as the very first thing in + * your application. It uses TDEAboutData to replace some of the + * arguments that would otherwise be required. + * + * @param _argc As passed to @p main(...). + * @param _argv As passed to @p main(...). + * @param about A TDEAboutData object describing your program. + * @param noKApp Set this true to not add commandline options for + * TQApplication / TDEApplication + */ + static void init(int _argc, char **_argv, + const TDEAboutData *about, bool noKApp = false); + + /** + * Initialize Class + * + * This function should be called as the very first thing in your + * application. This method will rarely be used, since it doesn't + * provide any argument parsing. It does provide access to the + * TDEAboutData information. + * This method is exactly the same as calling + * init(0,0, const TDEAboutData *about, true). + * + * @param about the about data. + * \see TDEAboutData + */ + static void init(const TDEAboutData *about); + + /** + * Add options to your application. + * + * You must make sure that all possible options have been added before + * any class uses the command line arguments. + * + * The list of options should look like this: + * + * \code + * static TDECmdLineOptions options[] = + * { + * { "option1 \", I18N_NOOP("Description 1"), "my_extra_arg" }, + * { "o", 0, 0 }, + * { "option2", I18N_NOOP("Description 2"), 0 }, + * { "nooption3", I18N_NOOP("Description 3"), 0 }, + * TDECmdLineLastOption + * } + * \endcode + * + * @li "option1" is an option that requires an additional argument, + * but if one is not provided, it uses "my_extra_arg". + * @li "option2" is an option that can be turned on. The default is off. + * @li "option3" is an option that can be turned off. The default is on. + * @li "o" does not have a description. It is an alias for the option + * that follows. In this case "option2". + * @li "+file" specifies an argument. The '+' is removed. If your program + * doesn't specify that it can use arguments your program will abort + * when an argument is passed to it. Note that the reverse is not + * true. If required, you must check yourself the number of arguments + * specified by the user: + * \code + * TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + * if (args->count() == 0) TDECmdLineArgs::usage(i18n("No file specified!")); + * \endcode + * + * In BNF: + * \code + * cmd = myapp [options] file + * options = (option)* + * option = --option1 \ | + * (-o | --option2 | --nooption2) | + * ( --option3 | --nooption3 ) + * \endcode + * + * Instead of "--option3" one may also use "-option3" + * + * Usage examples: + * + * @li "myapp --option1 test" + * @li "myapp" (same as "myapp --option1 my_extra_arg") + * @li "myapp --option2" + * @li "myapp --nooption2" (same as "myapp", since it is off by default) + * @li "myapp -o" (same as "myapp --option2") + * @li "myapp --nooption3" + * @li "myapp --option3 (same as "myapp", since it is on by default) + * @li "myapp --option2 --nooption2" (same as "myapp", because it + * option2 is off by default, and the last usage applies) + * @li "myapp /tmp/file" + * + * @param options A list of options that your code supplies. + * @param name the name of the option, can be 0. + * @param id A name with which these options can be identified, can be 0. + * @param afterId The options are inserted after this set of options, can be 0. + */ + static void addCmdLineOptions( const TDECmdLineOptions *options, + const char *name=0, const char *id = 0, + const char *afterId=0); + + /** + * Access parsed arguments. + * + * This function returns all command line arguments that your code + * handles. If unknown command-line arguments are encountered the program + * is aborted and usage information is shown. + * + * @param id The name of the options you are interested in, can be 0. + */ + static TDECmdLineArgs *parsedArgs(const char *id=0); + + /** + * Get the CWD (Current Working Directory) associated with the + * current command line arguments. + * + * Typically this is needed in KUniqueApplication::newInstance() + * since the CWD of the process may be different from the CWD + * where the user started a second instance. + * @return the current working directory + **/ + static TQString cwd(); + + /** + * Get the appname according to argv[0]. + * @return the name of the application + **/ + static const char *appName(); + + /** + * Print the usage help to stdout and exit. + * + * @param id if 0, print all options. If id is set, only print the + * option specified by id. The id is the value set by + * #ref addCmdLineOptions(). + **/ + static void usage(const char *id = 0); + + /** + * Print an error to stderr and the usage help to stdout and exit. + * @param error the error to print + **/ + static void usage(const TQString &error); + + /** + * Enable i18n to be able to print a translated error message. + * + * N.B.: This function leaks memory, therefore you are expected to exit + * afterwards (e.g., by calling usage()). + **/ + static void enable_i18n(); + + // Member functions: + + + /** + * Read out a string option. + * + * The option must have a corresponding TDECmdLineOptions entry + * of the form: + * \code + * { "option \", I18N_NOOP("Description"), "default" } + * \endcode + * You cannot test for the presence of an alias - you must always + * test for the full option. + * + * @param option The name of the option without '-'. + * + * @return The value of the option. If the option was not + * present on the command line the default is returned. + * If the option was present more than the value of the + * last occurrence is used. + */ + TQCString getOption(const char *option) const; + + /** + * Read out all occurrences of a string option. + * + * The option must have a corresponding TDECmdLineOptions entry + * of the form: + * \code + * { "option \", I18N_NOOP("Description"), "default" } + * \endcode + * You cannot test for the presence of an alias - you must always + * test for the full option. + * + * @param option The name of the option, without '-' or '-no'. + * + * @return A list of all option values. If no option was present + * on the command line, an empty list is returned. + */ + QCStringList getOptionList(const char *option) const; + + /** + * Read out a boolean option or check for the presence of string option. + * + * @param option The name of the option without '-' or '-no'. + * + * @return The value of the option. It will be true if the option + * was specifically turned on in the command line, or if the option + * is turned on by default (in the TDECmdLineOptions list) and was + * not specifically turned off in the command line. Equivalently, + * it will be false if the option was specifically turned off in + * the command line, or if the option is turned off by default (in + * the TDECmdLineOptions list) and was not specifically turned on in + * the command line. + */ + bool isSet(const char *option) const; + + /** + * Read the number of arguments that aren't options (but, + * for example, filenames). + * + * @return The number of arguments that aren't options + */ + int count() const; + + /** + * Read out an argument. + * + * @param n The argument to read. 0 is the first argument. + * count()-1 is the last argument. + * + * @return A @p const @p char @p * pointer to the n'th argument. + */ + const char *arg(int n) const; + + /** + * Read out an argument representing a URL. + * + * The argument can be + * @li an absolute filename + * @li a relative filename + * @li a URL + * + * @param n The argument to read. 0 is the first argument. + * count()-1 is the last argument. + * + * @return a URL representing the n'th argument. + */ + KURL url(int n) const; + + /** + * Used by url(). + * Made public for apps that don't use TDECmdLineArgs + * @param urlArg the argument + * @return the url. + */ + static KURL makeURL( const char * urlArg ); + + /** + * Made public for apps that don't use TDECmdLineArgs + * To be done before makeURL, to set the current working + * directory in case makeURL needs it. + * @param cwd the new working directory + */ + static void setCwd( char * cwd ) { mCwd = cwd; } + + /** + * Clear all options and arguments. + */ + void clear(); + + /** + * Reset all option definitions, i.e. cancel all addCmdLineOptions calls. + * Note that TDEApplication's options are removed too, you might want to + * call TDEApplication::addCmdLineOptions if you want them back. + * + * You usually don't want to call this method. + */ + static void reset(); + + /** + * Load arguments from a stream. + */ + static void loadAppArgs( TQDataStream &); + + /** + * Add standard option --tempfile + * @since 3.4 + */ + static void addTempFileOption(); + + // this avoids having to know the "id" used by addTempFileOption + // but this approach doesn't scale well, we can't have 50 standard options here... + /** + * @return true if --tempfile was set + * @since 3.4 + */ + static bool isTempFileSet(); + +protected: + /** + * @internal + * Constructor. + */ + TDECmdLineArgs( const TDECmdLineOptions *_options, const char *_name, + const char *_id); + + /** + * @internal use only. + * + * Use clear() if you want to free up some memory. + * + * Destructor. + */ + ~TDECmdLineArgs(); + +private: + /** + * @internal + * + * Checks what to do with a single option + */ + static void findOption(const char *_opt, TQCString opt, int &i, bool enabled, bool &moreOptions); + + /** + * @internal + * + * Parse all arguments, verify correct syntax and put all arguments + * where they belong. + */ + static void parseAllArgs(); + + /** + * @internal for TDEApplication only: + * + * Return argc + */ + static int *tqt_argc(); + + /** + * @internal for TDEApplication only: + * + * Return argv + */ + + static char ***tqt_argv(); + + /** + * @internal + * + * Remove named options. + * + * @param id The name of the options to be removed. + */ + static void removeArgs(const char *id); + + /** + * @internal for KUniqueApplication only: + * + * Save all but the TQt and KDE arguments to a stream. + */ + static void saveAppArgs( TQDataStream &); + + /** + * @internal + * + * Set a boolean option + */ + void setOption(const TQCString &option, bool enabled); + + /** + * @internal + * + * Set a string option + */ + void setOption(const TQCString &option, const char *value); + + /** + * @internal + * + * Add an argument + */ + void addArgument(const char *argument); + + /** + * @internal + * + * Save to a stream. + */ + void save( TQDataStream &) const; + + /** + * @internal + * + * Restore from a stream. + */ + void load( TQDataStream &); + + /** + * @internal for TDEApplication only + * + * Initialize class. + * + * This function should be called as the very first thing in + * your application. + * @param argc As passed to @p main(...). + * @param argv As passed to @p main(...). + * @param appname The untranslated name of your application. This should + * match with @p argv[0]. + * + * This function makes TDECmdLineArgs ignore all unknown options as well as + * all arguments. + */ + static void initIgnore(int _argc, char **_argv, const char *_appname); + + static void printQ(const TQString &msg); + + const TDECmdLineOptions *options; + const char *name; + const char *id; + TDECmdLineParsedOptions *parsedOptionList; + TDECmdLineParsedArgs *parsedArgList; + bool isTQt; + + static TDECmdLineArgsList *argsList; // All options. + static const TDEAboutData *about; + + static int argc; // The original argc + static char **argv; // The original argv + static bool parsed; // Whether we have parsed the arguments since calling init + static bool ignoreUnknown; // Ignore unknown options and arguments + static char *mCwd; // Current working directory. Important for KUnqiueApp! + static bool parseArgs; + + TDECmdLineArgsPrivate *d; +}; + +#endif + diff --git a/src/libgui/global_config.cpp b/src/libgui/global_config.cpp index 085f799..20d1ad3 100644 --- a/src/libgui/global_config.cpp +++ b/src/libgui/global_config.cpp @@ -9,7 +9,7 @@ ***************************************************************************/ #include "global_config.h" -#include +#include #include #include diff --git a/src/libgui/likeback.cpp b/src/libgui/likeback.cpp index 80519e2..cdc3eef 100644 --- a/src/libgui/likeback.cpp +++ b/src/libgui/likeback.cpp @@ -18,11 +18,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include -#include +#include +#include #include #include -#include +#include #include #include #include diff --git a/src/libgui/project_manager.cpp b/src/libgui/project_manager.cpp index c2877f3..58c33e6 100644 --- a/src/libgui/project_manager.cpp +++ b/src/libgui/project_manager.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include "project.h" #include "project_wizard.h" diff --git a/src/libgui/text_editor.cpp b/src/libgui/text_editor.cpp index 89eb7c6..68857cd 100644 --- a/src/libgui/text_editor.cpp +++ b/src/libgui/text_editor.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include "main_global.h" diff --git a/src/libgui/toplevel.cpp b/src/libgui/toplevel.cpp index 32e56ff..b241ce4 100644 --- a/src/libgui/toplevel.cpp +++ b/src/libgui/toplevel.cpp @@ -23,10 +23,10 @@ #include #include #include -#include +#include #include #include -#include +#include #include #include #include -- cgit v1.2.1