diff options
Diffstat (limited to 'src/common/nokde')
-rw-r--r-- | src/common/nokde/nokde.pro | 8 | ||||
-rw-r--r-- | src/common/nokde/nokde_kaboutdata.cpp | 469 | ||||
-rw-r--r-- | src/common/nokde/nokde_kaboutdata.h | 571 | ||||
-rw-r--r-- | src/common/nokde/nokde_kcmdlineargs.cpp | 1329 | ||||
-rw-r--r-- | src/common/nokde/nokde_kcmdlineargs.h | 701 | ||||
-rw-r--r-- | src/common/nokde/nokde_klocale.cpp | 4 | ||||
-rw-r--r-- | src/common/nokde/nokde_klocale.h | 17 | ||||
-rw-r--r-- | src/common/nokde/nokde_kprocess.cpp | 100 | ||||
-rw-r--r-- | src/common/nokde/nokde_kprocess.h | 51 | ||||
-rw-r--r-- | src/common/nokde/nokde_kurl.h | 32 | ||||
-rw-r--r-- | src/common/nokde/win32_utils.c | 81 | ||||
-rw-r--r-- | src/common/nokde/win32_utils.h | 97 |
12 files changed, 3460 insertions, 0 deletions
diff --git a/src/common/nokde/nokde.pro b/src/common/nokde/nokde.pro new file mode 100644 index 0000000..aa92599 --- /dev/null +++ b/src/common/nokde/nokde.pro @@ -0,0 +1,8 @@ +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 +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 new file mode 100644 index 0000000..21b6917 --- /dev/null +++ b/src/common/nokde/nokde_kaboutdata.cpp @@ -0,0 +1,469 @@ +// 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 <kstandarddirs.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qstringlist.h> + +QString +KAboutPerson::name() const +{ + return QString::fromUtf8(mName); +} + +QString +KAboutPerson::task() const +{ + if (mTask && *mTask) + return i18n(mTask); + else + return QString::null; +} + +QString +KAboutPerson::emailAddress() const +{ + return QString::fromUtf8(mEmailAddress); +} + + +QString +KAboutPerson::webAddress() const +{ + return QString::fromUtf8(mWebAddress); +} + + +KAboutTranslator::KAboutTranslator(const QString & name, + const QString & emailAddress) +{ + mName=name; + mEmail=emailAddress; +} + +QString KAboutTranslator::name() const +{ + return mName; +} + +QString KAboutTranslator::emailAddress() const +{ + return mEmail; +} + +class KAboutDataPrivate +{ +public: + KAboutDataPrivate() + : translatorName("_: NAME OF TRANSLATORS\nYour names") + , translatorEmail("_: EMAIL OF TRANSLATORS\nYour emails") + , productName(0) +// , programLogo(0) + {} + ~KAboutDataPrivate() + { +// delete programLogo; + } + const char *translatorName; + const char *translatorEmail; + const char *productName; +// QImage* programLogo; +}; + + + +KAboutData::KAboutData( 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 KAboutDataPrivate; + + if( appName ) { + const char *p = strrchr(appName, '/'); + if( p ) + mAppName = p+1; + else + mAppName = appName; + } else + mAppName = 0; +} + +KAboutData::~KAboutData() +{ + if (mLicenseKey == License_File) + delete [] mLicenseText; + delete d; +} + +void +KAboutData::addAuthor( const char *name, const char *task, + const char *emailAddress, const char *webAddress ) +{ + mAuthorList.append(KAboutPerson(name,task,emailAddress,webAddress)); +} + +void +KAboutData::addCredit( const char *name, const char *task, + const char *emailAddress, const char *webAddress ) +{ + mCreditList.append(KAboutPerson(name,task,emailAddress,webAddress)); +} + +void +KAboutData::setTranslator( const char *name, const char *emailAddress) +{ + d->translatorName=name; + d->translatorEmail=emailAddress; +} + +void +KAboutData::setLicenseText( const char *licenseText ) +{ + mLicenseText = licenseText; + mLicenseKey = License_Custom; +} + +void +KAboutData::setLicenseTextFile( const QString &file ) +{ + mLicenseText = qstrdup(QFile::encodeName(file)); + mLicenseKey = License_File; +} + +void +KAboutData::setAppName( const char *appName ) +{ + mAppName = appName; +} + +void +KAboutData::setProgramName( const char* programName ) +{ + mProgramName = programName; +} + +void +KAboutData::setVersion( const char* version ) +{ + mVersion = version; +} + +void +KAboutData::setShortDescription( const char *shortDescription ) +{ + mShortDescription = shortDescription; +} + +void +KAboutData::setLicense( LicenseKey licenseKey) +{ + mLicenseKey = licenseKey; +} + +void +KAboutData::setCopyrightStatement( const char *copyrightStatement ) +{ + mCopyrightStatement = copyrightStatement; +} + +void +KAboutData::setOtherText( const char *otherText ) +{ + mOtherText = otherText; +} + +void +KAboutData::setHomepage( const char *homepage ) +{ + mHomepageAddress = homepage; +} + +void +KAboutData::setBugAddress( const char *bugAddress ) +{ + mBugEmailAddress = bugAddress; +} + +void +KAboutData::setProductName( const char *productName ) +{ + d->productName = productName; +} + +const char * +KAboutData::appName() const +{ + return mAppName; +} + +const char * +KAboutData::productName() const +{ + if (d->productName) + return d->productName; + else + return appName(); +} + +QString +KAboutData::programName() const +{ + if (mProgramName && *mProgramName) + return i18n(mProgramName); + else + return QString::null; +} +/* +QImage +KAboutData::programLogo() const +{ + return d->programLogo ? (*d->programLogo) : QImage(); +} + +void +KAboutData::setProgramLogo(const QImage& image) +{ + if (!d->programLogo) + d->programLogo = new QImage( image ); + else + *d->programLogo = image; +} +*/ +QString +KAboutData::version() const +{ + return QString::fromLatin1(mVersion); +} + +QString +KAboutData::shortDescription() const +{ + if (mShortDescription && *mShortDescription) + return i18n(mShortDescription); + else + return QString::null; +} + +QString +KAboutData::homepage() const +{ + return QString::fromLatin1(mHomepageAddress); +} + +QString +KAboutData::bugAddress() const +{ + return QString::fromLatin1(mBugEmailAddress); +} + +const QValueList<KAboutPerson> +KAboutData::authors() const +{ + return mAuthorList; +} + +const QValueList<KAboutPerson> +KAboutData::credits() const +{ + return mCreditList; +} + +const QValueList<KAboutTranslator> +KAboutData::translators() const +{ + QValueList<KAboutTranslator> personList; + + if(d->translatorName == 0) + return personList; + + QStringList nameList; + QStringList emailList; + + QString names = i18n(d->translatorName); + if(names != QString::fromUtf8(d->translatorName)) + { +#if QT_VERSION < 0x040000 + nameList = QStringList::split(',',names); +#else + nameList = names.split(',', QString::SkipEmptyParts); +#endif + } + + + if(d->translatorEmail) + { + QString emails = i18n(d->translatorEmail); + + if(emails != QString::fromUtf8(d->translatorEmail)) + { +#if QT_VERSION < 0x040000 + emailList = QStringList::split(',',emails,true); +#else + emailList = emails.split(','); +#endif + } + } + + + QStringList::Iterator nit; + QStringList::Iterator eit=emailList.begin(); + + for(nit = nameList.begin(); nit != nameList.end(); ++nit) + { + QString email; + if(eit != emailList.end()) + { + email=*eit; + ++eit; + } + + QString name=*nit; + +#if QT_VERSION < 0x040000 + personList.append(KAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace())); +#else + personList.append(KAboutTranslator(name.trimmed(), email.trimmed())); +#endif + } + + return personList; +} + +QString +KAboutData::aboutTranslationTeam() +{ + return i18n("replace this with information about your translation team", + "<p>KDE is translated into many languages thanks to the work " + "of the translation teams all over the world.</p>" + "<p>For more information on KDE internationalization " + "visit http://i18n.kde.org</p>"); +} + +QString +KAboutData::otherText() const +{ + if (mOtherText && *mOtherText) + return i18n(mOtherText); + else + return QString::null; +} + + +QString +KAboutData::license() const +{ + QString result; + if (!copyrightStatement().isEmpty()) + result = copyrightStatement() + "\n\n"; + + QString l; + QString f; + switch ( mLicenseKey ) + { + case License_File: + f = QFile::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_QPL_V1_0: + l = "QPL v1.0"; + f = locate("data", "LICENSES/QPL_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()) + { + QFile file(f); +#if QT_VERSION < 0x040000 + if (file.open(IO_ReadOnly)) +#else + if (file.open(QIODevice::ReadOnly)) +#endif + { + result += '\n'; + result += '\n'; + QTextStream str(&file); +#if QT_VERSION < 0x040000 + result += str.read(); +#else + result += str.readAll(); +#endif + } + } + + return result; +} + +QString +KAboutData::copyrightStatement() const +{ + if (mCopyrightStatement && *mCopyrightStatement) + return i18n(mCopyrightStatement); + else + return QString::null; +} diff --git a/src/common/nokde/nokde_kaboutdata.h b/src/common/nokde/nokde_kaboutdata.h new file mode 100644 index 0000000..13076d4 --- /dev/null +++ b/src/common/nokde/nokde_kaboutdata.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 <qglobal.h> +#if QT_VERSION < 0x040000 +# include <qvaluelist.h> +#else +# include <Qt3Support/Q3ValueList> +# define QValueList Q3ValueList +# include <QStringList> +#endif +#include <qstring.h> +//#include <qimage.h> + +#include "nokde_klocale.h" + +#ifndef _KABOUTDATA_H_ +#define _KABOUTDATA_H_ + +class KAboutPersonPrivate; +class KAboutDataPrivate; + +/** + * 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 + * KAboutData class, but it can be used elsewhere as well. + * Normally you should at least define the person's name. + * + * Example Usage within a main(): + * + * KAboutData about("khello", I18N_NOOP("KHello"), "0.1", + * I18N_NOOP("A KDE version of Hello, world!"), + * KAboutData::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); + * KCmdLineArgs::init(argc, argv, &about); + */ +class KDECORE_EXPORT KAboutPerson +{ +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. + */ + KAboutPerson( 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 QValueList + */ + KAboutPerson() {} + + /** + * The person's name + * @return the person's name (can be QString::null, if it has been + * constructed with a null name) + */ + QString name() const; + + /** + * The person's task + * @return the person's task (can be QString::null, if it has been + * constructed with a null task) + */ + QString task() const; + + /** + * The person's email address + * @return the person's email address (can be QString::null, if it has been + * constructed with a null email) + */ + QString emailAddress() const; + + /** + * The home page or a relevant link + * @return the persons home page (can be QString::null, if it has been + * constructed with a null home page) + */ + QString webAddress() const; + +private: + const char *mName; + const char *mTask; + const char *mEmailAddress; + const char *mWebAddress; + + KAboutPersonPrivate *d; +}; + +class KAboutTranslatorPrivate; +/** + * 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 KAboutData 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 KAboutPerson for this, because + * KAboutPerson stores internally only const char* pointers, but the + * translator information is generated dynamically from the translation + * of a dummy string. +*/ +class KDECORE_EXPORT KAboutTranslator +{ +public: + /** + * Convenience constructor + * + * @param name The name of the person. + * + * @param emailAddress The email address of the person. + */ + KAboutTranslator(const QString & name=QString::null, + const QString & emailAddress=QString::null); + + /** + * The translator's name + * @return the translators's name (can be QString::null, if it has been + * constructed with a null name) + */ + QString name() const; + + /** + * The translator's email + * @return the translator's email address (can be QString::null, if it has been + * constructed with a null email) + */ + QString emailAddress() const; + +private: + QString mName; + QString mEmail; + KAboutTranslatorPrivate* 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 KAboutPerson), license and copyright information. + * + * Currently, the values set here are shown by the "About" box + * (see KAboutDialog), used by the bug report dialog (see KBugReport), + * and by the help shown on command line (see KCmdLineArgs). + * + * @short Holds information needed by the "About" box and other + * classes. + * @author Espen Sand (espen@kde.org), David Faure (faure@kde.org) + */ +class KDECORE_EXPORT KAboutData +{ + 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_QPL = 5, + License_QPL_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. + * + */ + KAboutData( 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" + ); + + ~KAboutData(); + + /** + * 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 KAboutTranslator + */ + 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 QString &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 QImage& 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). + */ + QString 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 + */ +// QImage programLogo() const; + + /** + * Returns the program's version. + * @return the version string. + */ + QString version() const; + + /** + * Returns a short, translated description. + * @return the short description (translated). Can be + * QString::null if not set. + */ + QString shortDescription() const; + + /** + * Returns the application homepage. + * @return the application homepage URL. Can be QString::null if + * not set. + */ + QString homepage() const; + + /** + * Returns the email address for bugs. + * @return the email address where to report bugs. + */ + QString bugAddress() const; + + /** + * Returns a list of authors. + * @return author information (list of persons). + */ + const QValueList<KAboutPerson> authors() const; + + /** + * Returns a list of persons who contributed. + * @return credit information (list of persons). + */ + const QValueList<KAboutPerson> credits() const; + + /** + * Returns a list of translators. + * @return translators information (list of persons) + */ + const QValueList<KAboutTranslator> translators() const; + + /** + * Returns a message about the translation team. + * @return a message about the translation team + */ + static QString aboutTranslationTeam(); + + /** + * Returns a translated, free form text. + * @return the free form text (translated). Can be QString::null if not set. + */ + QString 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. + */ + QString license() const; + + /** + * Returns the copyright statement. + * @return the copyright statement. Can be QString::null if not set. + */ + QString 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; + QValueList<KAboutPerson> mAuthorList; + QValueList<KAboutPerson> mCreditList; + const char *mLicenseText; + + KAboutDataPrivate *d; +}; + +#endif + diff --git a/src/common/nokde/nokde_kcmdlineargs.cpp b/src/common/nokde/nokde_kcmdlineargs.cpp new file mode 100644 index 0000000..7f026fe --- /dev/null +++ b/src/common/nokde/nokde_kcmdlineargs.cpp @@ -0,0 +1,1329 @@ +// modified from KDE 3.4 for Windows port (Nicolas Hadacek) + +/* + Copyright (C) 1999 Waldo Bastian <bastian@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 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 <config.h> + +#include <sys/param.h> + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif + +#include <qdir.h> +#include <qfile.h> +#include <qurl.h> + +#include <qstringlist.h> +#if QT_VERSION<0x040000 +# include <qasciidict.h> +# include <qstrlist.h> +#else +# include <Qt3Support/Q3StrList> +# define QGList Q3GList +# define QStrList Q3StrList +# include <Qt3Support/Q3AsciiDict> +# define QGDict Q3GDict +# define QAsciiDict Q3AsciiDict +# include <Qt3Support/Q3PtrCollection> +# define QPtrCollection Q3PtrCollection +#endif + + +#include "nokde_kcmdlineargs.h" +#include "nokde_kaboutdata.h" +#include "nokde_klocale.h" +//#include <kapplication.h> +//#include <kglobal.h> +//#include <kstringhandler.h> +//#include <kstaticdeleter.h> + +#ifdef Q_WS_X11 +#define DISPLAY "DISPLAY" +#elif defined(Q_WS_QWS) +#define DISPLAY "QWS_DISPLAY" +#endif + +#ifdef Q_WS_WIN +#include <win32_utils.h> +#endif + +template class QAsciiDict<QCString>; +template class QPtrList<KCmdLineArgs>; + +class KCmdLineParsedOptions : public QAsciiDict<QCString> +{ +public: + KCmdLineParsedOptions() + : QAsciiDict<QCString>( 7 ) { } + + // WABA: Huh? + // The compiler doesn't find KCmdLineParsedOptions::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) + QDataStream& save( QDataStream &s) const + { return QGDict::write(s); } + + QDataStream& load( QDataStream &s) + { return QGDict::read(s); } + +protected: + virtual QDataStream& write( QDataStream &s, QPtrCollection::Item data) const + { + QCString *str = (QCString *) data; + s << (*str); + return s; + } + + virtual QDataStream& read( QDataStream &s, QPtrCollection::Item &item) + { + QCString *str = new QCString; + s >> (*str); + item = (void *)str; + return s; + } + +}; + +class KCmdLineParsedArgs : public QStrList +{ +public: + KCmdLineParsedArgs() + : QStrList( true ) { } + QDataStream& save( QDataStream &s) const + { return QGList::write(s); } + + QDataStream& load( QDataStream &s) + { return QGList::read(s); } +}; + + +class KCmdLineArgsList: public QPtrList<KCmdLineArgs> +{ +public: + KCmdLineArgsList() { } +}; + +KCmdLineArgsList *KCmdLineArgs::argsList = 0; +int KCmdLineArgs::argc = 0; +char **KCmdLineArgs::argv = 0; +char *KCmdLineArgs::mCwd = 0; +//static KStaticDeleter <char> mCwdd; +const KAboutData *KCmdLineArgs::about = 0; +bool KCmdLineArgs::parsed = false; +bool KCmdLineArgs::ignoreUnknown = false; + +// +// Static functions +// + +void +KCmdLineArgs::init(int _argc, char **_argv, const char *_appname, const char* programName, + const char *_description, const char *_version, bool noKApp) +{ + init(_argc, _argv, + new KAboutData(_appname, programName, _version, _description), + noKApp); +} + +void +KCmdLineArgs::init(int _argc, char **_argv, const char *_appname, + const char *_description, const char *_version, bool noKApp) +{ + init(_argc, _argv, + new KAboutData(_appname, _appname, _version, _description), + noKApp); +} + +void +KCmdLineArgs::initIgnore(int _argc, char **_argv, const char *_appname ) +{ + init(_argc, _argv, + new KAboutData(_appname, _appname, "unknown", "KDE Application", false)); + ignoreUnknown = true; +} + +void +KCmdLineArgs::init(const KAboutData* ab) +{ + char **_argv = (char **) malloc(sizeof(char *)); + _argv[0] = (char *) ab->appName(); + init(1,_argv,ab, true); +} + + +void +KCmdLineArgs::init(int _argc, char **_argv, const KAboutData *_about, bool /*noKApp*/) +{ + argc = _argc; + argv = _argv; + + if (!argv) + { + fprintf(stderr, "\n\nFAILURE (KCmdLineArgs):\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 Q_WS_WIN + win32_slashify(mCwd, PATH_MAX); +#endif +// if (!noKApp) +// KApplication::addCmdLineOptions(); +} + +QString KCmdLineArgs::cwd() +{ + return QFile::decodeName(QCString(mCwd)); +} + +const char * KCmdLineArgs::appName() +{ + if (!argc) return 0; + return argv[0]; +} + +void +KCmdLineArgs::addCmdLineOptions( const KCmdLineOptions *options, const char *name, + const char *id, const char *afterId) +{ + if (!argsList) + argsList = new KCmdLineArgsList(); + + int pos = argsList->count(); + + if (pos && id && argsList->last() && !argsList->last()->name) + pos--; + + KCmdLineArgs *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 KCmdLineArgs(options, name, id); + argsList->insert(pos, args); +} + +void +KCmdLineArgs::saveAppArgs( QDataStream &ds) +{ + if (!parsed) + parseAllArgs(); + + // Remove Qt and KDE options. + removeArgs("qt"); + removeArgs("kde"); + + QCString qCwd = mCwd; + ds << qCwd; + + uint count = argsList ? argsList->count() : 0; + ds << count; + + if (!count) return; + + KCmdLineArgs *args; + for(args = argsList->first(); args; args = argsList->next()) + { + ds << QCString(args->id); + args->save(ds); + } +} + +void +KCmdLineArgs::loadAppArgs( QDataStream &ds) +{ + // Remove Qt and KDE options. + removeArgs("qt"); + removeArgs("kde"); + + KCmdLineArgs *args; + if ( argsList ) { + for(args = argsList->first(); args; args = argsList->next()) + { + args->clear(); + } + } + + if (ds.atEnd()) + return; + + QCString 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--) + { + QCString id; + ds >> id; + assert( argsList ); + for(args = argsList->first(); args; args = argsList->next()) + { + if (args->id == id) + { + args->load(ds); + break; + } + } + } + parsed = true; +} + +KCmdLineArgs *KCmdLineArgs::parsedArgs(const char *id) +{ + KCmdLineArgs *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 KCmdLineArgs::removeArgs(const char *id) +{ + KCmdLineArgs *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 KCmdLineOptions *options, QCString &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; + QCString nextOption = options->name; +# if QT_VERSION<0x040000 + int p = nextOption.find(' '); +#else + int p = QString(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 +KCmdLineArgs::findOption(const char *_opt, QCString opt, int &i, bool _enabled, bool &moreOptions) +{ + KCmdLineArgs *args = argsList->first(); + const char *opt_name; + const char *def; + QCString argument; +# if QT_VERSION<0x040000 + int j = opt.find('='); +#else + int j = QString(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) + { + QCString 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(QString::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(QString::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 +KCmdLineArgs::printQ(const QString &msg) +{ +# if QT_VERSION<0x040000 + QCString localMsg = msg.local8Bit(); +#else + QCString localMsg = msg.toLocal8Bit(); +#endif + fprintf(stdout, "%s", localMsg.data()); +} + +void +KCmdLineArgs::parseAllArgs() +{ + bool allowArgs = false; + bool inOptions = true; + bool everythingAfterArgIsArgs = false; + KCmdLineArgs *appOptions = argsList->last(); + if (!appOptions->id) + { + const KCmdLineOptions *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( QString("Qt: %1\n").arg(qVersion())); +// printQ( QString("KDE: %1\n").arg(KDE_VERSION_STRING)); + printQ( QString("%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 QValueList<KAboutPerson> authors = about->authors(); + if ( !authors.isEmpty() ) { + QString authorlist; + for (QValueList<KAboutPerson>::ConstIterator it = authors.begin(); it != authors.end(); ++it ) { + QString email; + if ( !(*it).emailAddress().isEmpty() ) + email = " <" + (*it).emailAddress() + ">"; + authorlist += QString(" ") + (*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 ( QString(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(QString::fromLocal8Bit(argv[i]))); + } + else + { + appOptions->addArgument(argv[i]); + if (everythingAfterArgIsArgs) + inOptions = false; + } + } + } + parsed = true; +} + +/** + * For KApplication only: + * + * Return argc + */ +int * +KCmdLineArgs::qt_argc() +{ +// if (!argsList) +// KApplication::addCmdLineOptions(); // Lazy bastards! + + static int qt_argc = -1; + if( qt_argc != -1 ) + return &qt_argc; + + KCmdLineArgs *args = parsedArgs("qt"); + assert(args); // No qt options have been added! + if (!argv) + { + fprintf(stderr, "\n\nFAILURE (KCmdLineArgs):\n"); + fprintf(stderr, "Application has not called KCmdLineArgs::init(...).\n\n"); + + assert( 0 ); + exit(255); + } + + assert(argc >= (args->count()+1)); + qt_argc = args->count() +1; + return &qt_argc; +} + +/** + * For KApplication only: + * + * Return argv + */ +char *** +KCmdLineArgs::qt_argv() +{ +// if (!argsList) +// KApplication::addCmdLineOptions(); // Lazy bastards! + + static char** qt_argv; + if( qt_argv != NULL ) + return &qt_argv; + + KCmdLineArgs *args = parsedArgs("qt"); + assert(args); // No qt options have been added! + if (!argv) + { + fprintf(stderr, "\n\nFAILURE (KCmdLineArgs):\n"); + fprintf(stderr, "Application has not called KCmdLineArgs::init(...).\n\n"); + + assert( 0 ); + exit(255); + } + + qt_argv = new char*[ args->count() + 2 ]; + qt_argv[ 0 ] = qstrdup( appName()); + int i = 0; + for(; i < args->count(); i++) + { + qt_argv[i+1] = qstrdup((char *) args->arg(i)); + } + qt_argv[i+1] = 0; + + return &qt_argv; +} + +void +KCmdLineArgs::enable_i18n() +{ + // called twice or too late +/* if (KGlobal::_locale) + return; + + if (!KGlobal::_instance) { + KInstance *instance = new KInstance(about); + (void) instance->config(); + // Don't delete instance! + }*/ +} + +void +KCmdLineArgs::usage(const QString &error) +{ +// assert(KGlobal::_locale); +# if QT_VERSION<0x040000 + QCString localError = error.local8Bit(); +#else + QCString 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()); + + QString tmp = i18n("Use --help to get a list of available command line options."); +# if QT_VERSION<0x040000 + localError = tmp.local8Bit(); +#else + localError = tmp.toLocal8Bit(); +#endif + fprintf(stderr, "%s: %s\n", argv[0], localError.data()); + exit(254); +} + +void +KCmdLineArgs::usage(const char *id) +{ + enable_i18n(); + assert(argsList != 0); // It's an error to call usage(...) without + // having done addCmdLineOptions first! + + QString optionFormatString = " %1 %2\n"; + QString optionFormatStringDef = " %1 %2 [%3]\n"; + QString optionHeaderString = i18n("\n%1:\n"); + QString tmp; + QString usage; + + KCmdLineArgs *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(); + } + + KCmdLineArgs *appOptions = argsList->last(); + if (!appOptions->id) + { + const KCmdLineOptions *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) + { + QString option = QString("--help-%1").arg(args->id); + QString 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; + QString optionsHeader; + if (args->name) + optionsHeader = optionHeaderString.arg(i18n("%1 options").arg(QString::fromLatin1(args->name))); + else + optionsHeader = i18n("\nOptions:\n"); + + while (args) + { + const KCmdLineOptions *option = args->options; + QCString opt = ""; +// + while(option && option->name) + { + QString description; + QString descriptionRest; + QStringList 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) + { + QString 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 QT_VERSION<0x040000 + dl = QStringList::split("\n", description, true); +#else + dl = description.split("\n"); +#endif + description = dl.first(); + dl.erase( dl.begin() ); + } + QCString 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(QString(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(QString(opt), -25) + .arg(description)); + } + else + { + printQ(optionFormatStringDef.arg(QString(opt), -25) + .arg(description).arg(option->def)); + } + opt = ""; + } + } + for(QStringList::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. + */ +KCmdLineArgs::KCmdLineArgs( const KCmdLineOptions *_options, + const char *_name, const char *_id) + : options(_options), name(_name), id(_id) +{ + parsedOptionList = 0; + parsedArgList = 0; + isQt = (::qstrcmp(id, "qt") == 0); +} + +/** + * Destructor. + */ +KCmdLineArgs::~KCmdLineArgs() +{ + delete parsedOptionList; + delete parsedArgList; + if (argsList) + argsList->removeRef(this); +} + +void +KCmdLineArgs::clear() +{ + delete parsedArgList; + parsedArgList = 0; + delete parsedOptionList; + parsedOptionList = 0; +} + +void +KCmdLineArgs::reset() +{ + if ( argsList ) { + argsList->setAutoDelete( true ); + argsList->clear(); + delete argsList; + argsList = 0; + } + parsed = false; +} + +void +KCmdLineArgs::save( QDataStream &ds) const +{ + uint count = 0; + if (parsedOptionList) + parsedOptionList->save( ds ); + else + ds << count; + + if (parsedArgList) + parsedArgList->save( ds ); + else + ds << count; +} + +void +KCmdLineArgs::load( QDataStream &ds) +{ + if (!parsedOptionList) parsedOptionList = new KCmdLineParsedOptions; + if (!parsedArgList) parsedArgList = new KCmdLineParsedArgs; + + parsedOptionList->load( ds ); + parsedArgList->load( ds ); + + if (parsedOptionList->count() == 0) + { + delete parsedOptionList; + parsedOptionList = 0; + } + if (parsedArgList->count() == 0) + { + delete parsedArgList; + parsedArgList = 0; + } +} + +void +KCmdLineArgs::setOption(const QCString &opt, bool enabled) +{ + if (isQt) + { + // Qt does it own parsing. + QCString arg = "-"; + if( !enabled ) + arg += "no"; + arg += opt; + addArgument(arg); + } + if (!parsedOptionList) { + parsedOptionList = new KCmdLineParsedOptions; + parsedOptionList->setAutoDelete(true); + } + + if (enabled) + parsedOptionList->replace( opt, new QCString("t") ); + else + parsedOptionList->replace( opt, new QCString("f") ); +} + +void +KCmdLineArgs::setOption(const QCString &opt, const char *value) +{ + if (isQt) + { + // Qt does it's own parsing. + QCString arg = "-"; + arg += opt; + addArgument(arg); + addArgument(value); + +#ifdef Q_WS_X11 + // Hack coming up! + if (arg == "-display") + { + setenv(DISPLAY, value, true); + } +#endif + } + if (!parsedOptionList) { + parsedOptionList = new KCmdLineParsedOptions; + parsedOptionList->setAutoDelete(true); + } + + parsedOptionList->insert( opt, new QCString(value) ); +} + +QCString +KCmdLineArgs::getOption(const char *_opt) const +{ + QCString *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; + QCString opt = _opt; + int result = ::findOption( options, opt, opt_name, def, dummy) & ~4; + + if (result != 3) + { + fprintf(stderr, "\n\nFAILURE (KCmdLineArgs):\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 QCString(def); +} + +QCStringList +KCmdLineArgs::getOptionList(const char *_opt) const +{ + QCStringList result; + if (!parsedOptionList) + return result; + + while(true) + { + QCString *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 QCString(*it)); + } + return result; +} + +bool +KCmdLineArgs::isSet(const char *_opt) const +{ + // Look up the default. + const char *opt_name; + const char *def; + bool dummy = true; + QCString opt = _opt; + int result = ::findOption( options, opt, opt_name, def, dummy) & ~4; + + if (result == 0) + { + fprintf(stderr, "\n\nFAILURE (KCmdLineArgs):\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); + } + + QCString *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 +KCmdLineArgs::count() const +{ + if (!parsedArgList) + return 0; + return parsedArgList->count(); +} + +const char * +KCmdLineArgs::arg(int n) const +{ + if (!parsedArgList || (n >= (int) parsedArgList->count())) + { + fprintf(stderr, "\n\nFAILURE (KCmdLineArgs): 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 +KCmdLineArgs::url(int n) const +{ + return makeURL( arg(n) ); +} + +KURL KCmdLineArgs::makeURL(const char *_urlArg) +{ + QString urlArg = QFile::decodeName(_urlArg); + if (!QDir::isRelativePath(urlArg)) + { + //KURL result; + //result.setPath(urlArg); + //return result; // Absolute path. + return urlArg; + } +# if QT_VERSION<0x040000 + if ( !QUrl::isRelativeUrl(urlArg) ) +#else + if ( !QUrl(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 +KCmdLineArgs::addArgument(const char *argument) +{ + if (!parsedArgList) + parsedArgList = new KCmdLineParsedArgs; + + parsedArgList->append(argument); +} + +static const KCmdLineOptions kde_tempfile_option[] = +{ + { "tempfile", I18N_NOOP("The files/URLs opened by the application will be deleted after use"), 0}, + KCmdLineLastOption +}; + +void +KCmdLineArgs::addTempFileOption() +{ + KCmdLineArgs::addCmdLineOptions( kde_tempfile_option, "KDE-tempfile", "kde-tempfile" ); +} + +bool KCmdLineArgs::isTempFileSet() +{ + KCmdLineArgs* args = KCmdLineArgs::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 new file mode 100644 index 0000000..8b79b62 --- /dev/null +++ b/src/common/nokde/nokde_kcmdlineargs.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 <bastian@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 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 QT_VERSION<0x040000 +# include <qptrlist.h> +# include <qvaluelist.h> +#else +# include <Qt3Support/Q3CString> +# define QCString Q3CString +# include <Qt3Support/Q3PtrList> +# define QPtrList Q3PtrList +# include <Qt3Support/Q3ValueList> +# define QValueList Q3ValueList +#endif +# include <qstring.h> + +typedef QValueList<QCString> QCStringList; + +/** + * @short Structure that holds command line options. + * + * This class is intended to be used with the KCmdLineArgs class, which + * provides convenient and powerful command line argument parsing and + * handling functionality. + * + * @see KCmdLineArgs for additional usage information + */ +struct KDECORE_EXPORT KCmdLineOptions +{ + /** + * The name of the argument as it should be called on the command line and + * appear in <i>myapp --help</i>. + * + * 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 + * <i>myapp --nofoo</i> is called: + * + * \code + * KCmdLineArgs::parsedArgs()->isSet("foo"); // false + * \endcode + */ + const char *name; + /** + * The text description of the option as should appear in + * <i>myapp --help</i>. 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 KCmdLineLastOption { 0, 0, 0 } + +class KCmdLineArgsList; +class KApplication; +class KUniqueApplication; +class KCmdLineParsedOptions; +class KCmdLineParsedArgs; +class KAboutData; +class KCmdLineArgsPrivate; + +/** + * @short A class for command-line argument handling. + * + * KCmdLineArgs provides simple access to the command-line arguments + * for an application. It takes into account Qt-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 %KCmdLineArgs should look like this: + * + * \code + * int main(int argc, char *argv[]) + * { + * // Initialize command line args + * KCmdLineArgs::init(argc, argv, appName, programName, description, version); + * + * // Tell which options are supported + * KCmdLineArgs::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 KApplication will usually do this in main but this is not + * // necessary. + * // A KUniqueApplication might want to handle it in newInstance(). + * + * KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + * + * // A binary option (on / off) + * if (args->isSet("some-option")) + * .... + * + * // An option which takes an additional argument + * QCString 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( QFile::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 + * KCmdLineOptions class. An example is shown below: + * + * \code + * static const KCmdLineOptions options[] = + * { + * { "a", I18N_NOOP("A short binary option"), 0 }, + * { "b \<file>", I18N_NOOP("A short option which takes an argument"), 0 }, + * { "c \<speed>", 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 \<file>", I18N_NOOP("A long option which takes an argument"), 0 }, + * { "option4 \<speed>", 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 \<speed>", I18N_NOOP("'--option7 speed' is the same as '-f speed'"), 0 }, + * { "!option8 \<cmd>", 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 }, + * KCmdLineLastOption // 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 KCmdLineArgs. + * 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 KDECORE_EXPORT KCmdLineArgs +{ + friend class KApplication; + friend class KUniqueApplication; + friend class QPtrList<KCmdLineArgs>; +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 + * QApplication / KApplication + * + * @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 KAboutData 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 KAboutData object describing your program. + * @param noKApp Set this true to not add commandline options for + * QApplication / KApplication + */ + static void init(int _argc, char **_argv, + const KAboutData *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 + * KAboutData information. + * This method is exactly the same as calling + * init(0,0, const KAboutData *about, true). + * + * @param about the about data. + * \see KAboutData + */ + static void init(const KAboutData *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 KCmdLineOptions options[] = + * { + * { "option1 \<argument>", I18N_NOOP("Description 1"), "my_extra_arg" }, + * { "o", 0, 0 }, + * { "option2", I18N_NOOP("Description 2"), 0 }, + * { "nooption3", I18N_NOOP("Description 3"), 0 }, + * KCmdLineLastOption + * } + * \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 + * KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + * if (args->count() == 0) KCmdLineArgs::usage(i18n("No file specified!")); + * \endcode + * + * In BNF: + * \code + * cmd = myapp [options] file + * options = (option)* + * option = --option1 \<argument> | + * (-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 KCmdLineOptions *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 KCmdLineArgs *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 QString 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 QString &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 KCmdLineOptions entry + * of the form: + * \code + * { "option \<argument>", 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. + */ + QCString getOption(const char *option) const; + + /** + * Read out all occurrences of a string option. + * + * The option must have a corresponding KCmdLineOptions entry + * of the form: + * \code + * { "option \<argument>", 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 KCmdLineOptions 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 KCmdLineOptions 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 KCmdLineArgs + * @param urlArg the argument + * @return the url. + */ + static KURL makeURL( const char * urlArg ); + + /** + * Made public for apps that don't use KCmdLineArgs + * 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 KApplication's options are removed too, you might want to + * call KApplication::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( QDataStream &); + + /** + * 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. + */ + KCmdLineArgs( const KCmdLineOptions *_options, const char *_name, + const char *_id); + + /** + * @internal use only. + * + * Use clear() if you want to free up some memory. + * + * Destructor. + */ + ~KCmdLineArgs(); + +private: + /** + * @internal + * + * Checks what to do with a single option + */ + static void findOption(const char *_opt, QCString 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 KApplication only: + * + * Return argc + */ + static int *qt_argc(); + + /** + * @internal for KApplication only: + * + * Return argv + */ + + static char ***qt_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 Qt and KDE arguments to a stream. + */ + static void saveAppArgs( QDataStream &); + + /** + * @internal + * + * Set a boolean option + */ + void setOption(const QCString &option, bool enabled); + + /** + * @internal + * + * Set a string option + */ + void setOption(const QCString &option, const char *value); + + /** + * @internal + * + * Add an argument + */ + void addArgument(const char *argument); + + /** + * @internal + * + * Save to a stream. + */ + void save( QDataStream &) const; + + /** + * @internal + * + * Restore from a stream. + */ + void load( QDataStream &); + + /** + * @internal for KApplication 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 KCmdLineArgs ignore all unknown options as well as + * all arguments. + */ + static void initIgnore(int _argc, char **_argv, const char *_appname); + + static void printQ(const QString &msg); + + const KCmdLineOptions *options; + const char *name; + const char *id; + KCmdLineParsedOptions *parsedOptionList; + KCmdLineParsedArgs *parsedArgList; + bool isQt; + + static KCmdLineArgsList *argsList; // All options. + static const KAboutData *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; + + KCmdLineArgsPrivate *d; +}; + +#endif + diff --git a/src/common/nokde/nokde_klocale.cpp b/src/common/nokde/nokde_klocale.cpp new file mode 100644 index 0000000..e30ba2f --- /dev/null +++ b/src/common/nokde/nokde_klocale.cpp @@ -0,0 +1,4 @@ +#include "nokde_klocale.h" + +QString i18n(const QString &, const QString &text) { return text; } +QString locate(const QString &, const QString &) { return QString::null; } diff --git a/src/common/nokde/nokde_klocale.h b/src/common/nokde/nokde_klocale.h new file mode 100644 index 0000000..a1cf720 --- /dev/null +++ b/src/common/nokde/nokde_klocale.h @@ -0,0 +1,17 @@ +#ifndef NOKDE_KLOCALE_H +#define NOKDE_KLOCALE_H + +#undef KDECORE_EXPORT +#define KDECORE_EXPORT + +#undef KDE_DEPRECATED +#define KDE_DEPRECATED + +#undef I18N_NOOP +#define I18N_NOOP(x) (x) +#include <qstring.h> +inline QString i18n(const QString &text) { return text; } +extern QString i18n(const QString &index, const QString &text); +extern QString locate(const QString &, const QString &); + +#endif diff --git a/src/common/nokde/nokde_kprocess.cpp b/src/common/nokde/nokde_kprocess.cpp new file mode 100644 index 0000000..92c8968 --- /dev/null +++ b/src/common/nokde/nokde_kprocess.cpp @@ -0,0 +1,100 @@ +#include "nokde_kprocess.h" + +#if QT_VERSION<0x040000 +# include <qprocess.h> +# define Q3Process QProcess +#else +# include <Qt3Support/Q3Process> +#endif + +#if defined(Q_OS_UNIX) +# include <signal.h> +#endif + +KProcess::KProcess(QObject *parent, const char *name) + : QObject(parent, name) +{ + _process = new Q3Process(this); + connect(_process, SIGNAL(processExited()), SLOT(processExitedSlot())); + connect(_process, SIGNAL(readyReadStdout()), SLOT(readyReadStdoutSlot())); + connect(_process, SIGNAL(readyReadStderr()), SLOT(readyReadStderrSlot())); +} + +bool KProcess::start() +{ + _process->setArguments(_arguments); + QStringList env; + if ( !_environment.isEmpty() ) { + for (uint i=0; environ[i]; i++) env += environ[i]; + env += _environment; + } + return _process->start(env.isEmpty() ? 0 : &env); +} + +void KProcess::processExitedSlot() +{ + readyReadStdoutSlot(); + readyReadStderrSlot(); + emit processExited(this); +} + +void KProcess::readyReadStdoutSlot() +{ + QByteArray a = _process->readStdout(); + emit receivedStdout(this, a.data(), a.count()); +} + +void KProcess::readyReadStderrSlot() +{ + QByteArray a = _process->readStderr(); + emit receivedStderr(this, a.data(), a.count()); +} + +bool KProcess::writeStdin(const char *buffer, int len) +{ +#if QT_VERSION<0x040000 + QByteArray a; + a.assign(buffer, len); +#else + QByteArray a(buffer, len); +#endif + _process->writeToStdin(a); + return true; +} + +bool KProcess::kill() +{ + _process->kill(); + return true; +} + +bool KProcess::kill(int n) +{ +#if defined(Q_OS_UNIX) + return ( ::kill(_process->processIdentifier(), n)!=-1 ); +#elif defined(Q_OS_WIN) + // #### impossible to do ?? + return false; +#endif +} + +int KProcess::exitStatus() const +{ + return _process->exitStatus(); +} + +bool KProcess::isRunning() const +{ + return _process->isRunning(); +} + +void KProcess::setWorkingDirectory(const QDir &dir) +{ + return _process->setWorkingDirectory(dir); +} + +void KProcess::setUseShell(bool useShell) +{ + // ### TODO: just issue "/bin/sh" "-c" "command" + Q_ASSERT(false); +} diff --git a/src/common/nokde/nokde_kprocess.h b/src/common/nokde/nokde_kprocess.h new file mode 100644 index 0000000..59ff73c --- /dev/null +++ b/src/common/nokde/nokde_kprocess.h @@ -0,0 +1,51 @@ +#ifndef _KPROCESS_H_ +#define _KPROCESS_H_ + +#include <qdir.h> +#include "common/global/global.h" +#include "common/common/synchronous.h" +#if QT_VERSION<0x040000 +class QProcess; +#else +class Q3Process; +#endif + +class KProcess : public QObject +{ +Q_OBJECT +public: + KProcess(QObject *parent = 0, const char *name = 0); + void clearArguments() { _arguments.clear(); } + KProcess &operator<< (const QString &arg) { _arguments += arg; return *this; } + KProcess &operator<< (const QStringList &args) { _arguments += args; return *this; } + QStringList args() const { return _arguments; } + void setEnvironment(const QString &name, const QString &value) { _environment += name + "=" + value; } + bool start(); + bool writeStdin(const char *buffer, int len); + bool kill(); + bool kill(int n); + int exitStatus() const; + bool isRunning() const; + void setWorkingDirectory(const QDir &dir); + void setUseShell(bool useShell); + +signals: + void processExited(KProcess *process); + void receivedStdout(KProcess *process, char *buffer, int len); + void receivedStderr(KProcess *process, char *buffer, int len); + +private slots: + void processExitedSlot(); + void readyReadStdoutSlot(); + void readyReadStderrSlot(); + +private: +#if QT_VERSION<0x040000 + QProcess *_process; +#else + Q3Process *_process; +#endif + QStringList _arguments,_environment; +}; + +#endif diff --git a/src/common/nokde/nokde_kurl.h b/src/common/nokde/nokde_kurl.h new file mode 100644 index 0000000..202c46d --- /dev/null +++ b/src/common/nokde/nokde_kurl.h @@ -0,0 +1,32 @@ +#ifndef _KURL_H_ +#define _KURL_H_ + +#include <qfile.h> + +#include "common/global/global.h" + +class KURL : public Q3Url +{ +public: + KURL() {} + KURL(const QString &s) : Q3Url(s) {} + void cleanPath() {} + bool isEmpty() const { return toString(false, false).isEmpty(); } + QString fileName(bool b) const { Q_UNUSED(b); Q_ASSERT(!b); return Q3Url::fileName(); } + static KURL fromPathOrURL(const QString &s) { return KURL(s); } +#if QT_VERSION>=0x040000 + bool operator <(const KURL &url) const { return path()<url.path(); } + bool operator ==(const KURL &url) const { return path()==url.path(); } + bool operator !=(const KURL &url) const { return path()!=url.path(); } +#endif +}; + +// ### DUMMY +class KTempFile +{ +public: + const QFile *file() const { return 0; } + QFile *file() { return 0; } +}; + +#endif diff --git a/src/common/nokde/win32_utils.c b/src/common/nokde/win32_utils.c new file mode 100644 index 0000000..975261e --- /dev/null +++ b/src/common/nokde/win32_utils.c @@ -0,0 +1,81 @@ +/* + This file is part of the KDE libraries + Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl> + + 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. +*/ + +// helper functions + +#include "win32_utils.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <signal.h> + +//--------------------------------------------- +#define _fcopy_BUFLEN 1024*32 +int fcopy(const char *src, const char *dest) +{ + static char _fcopy_buf[_fcopy_BUFLEN]; //not reentrant! + FILE *in, *out; + int c_in=0, c_out=0; + int res=0; + + in=fopen(src, "rb"); + if (!in) + return fcopy_src_err; + out=fopen(dest, "wb"); + if (!out) + return fcopy_dest_err; + while (!feof(in) && !ferror(in) && !ferror(out)) { + c_in=fread(_fcopy_buf, 1, _fcopy_BUFLEN, in); + if (ferror(in) || c_in==0) { + break; + } + c_out=fwrite(_fcopy_buf, 1, c_in, out); + if (ferror(out) || c_in!=c_out) { + break; + } + } + + if (ferror(in)) { + res=fcopy_src_err; + } + else if (ferror(out)) { + res=fcopy_dest_err; + } + else if (c_in!=c_out) { + res=fcopy_dest_err; + } + fclose(in); + fclose(out); + return res; +} + +KDEWIN32_EXPORT +void win32_slashify(char *path, int maxlen) +{ + int len = 0; + if (!path) + return; + for (; *path && len < maxlen ; path++) + if ( *path == '\\' ) + *path = '/'; +} + diff --git a/src/common/nokde/win32_utils.h b/src/common/nokde/win32_utils.h new file mode 100644 index 0000000..cc5e110 --- /dev/null +++ b/src/common/nokde/win32_utils.h @@ -0,0 +1,97 @@ +/* + This file is part of the KDE libraries + Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl> + + 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 KDE_WIN32_UTILS_H +#define KDE_WIN32_UTILS_H + +#include <windows.h> + +//#include <kdecore/kdelibs_export.h> +#define KDEWIN32_EXPORT + +#ifdef __cplusplus +#include <qstring.h> + +extern "C" { +#endif + +#define fcopy_src_err -1 +#define fcopy_dest_err -2 + +/** + Copies @p src file to @p dest file. + @return 0 on success, fcopy_src_err on source file error, + fcopy_dest_err on destination file error. +*/ +KDEWIN32_EXPORT int fcopy(const char *src, const char *dest); + +/** + Converts all backslashes to slashes in @p path. + Converting is stopped on a null character or at @p maxlen character. +*/ +KDEWIN32_EXPORT void win32_slashify(char *path, int maxlen); + +#ifdef __cplusplus +} + +/** + \return a value from MS Windows native registry. + @param key is usually one of HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE + constants defined in WinReg.h. + @param subKey is a registry subkey defined as a path to a registry folder, eg. + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" + ('\' delimiter must be used) + @param item is an item inside subKey or "" if default folder's value should be returned + @param ok if not null, will be set to true on success and false on failure +*/ +KDEWIN32_EXPORT QString getWin32RegistryValue(HKEY key, const QString& subKey, + const QString& item, bool *ok = 0); + +/** + \return a value from MS Windows native registry for shell folder \a folder. +*/ +inline QString getWin32ShellFoldersPath(const QString& folder) { + return getWin32RegistryValue(HKEY_CURRENT_USER, + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", folder); +} + +/** + Shows native MS Windows file property dialog for a file \a fileName. + Return true on success. Only works for local absolute paths. + Used by KPropertiesDialog, if possible. +*/ +KDEWIN32_EXPORT +bool showWin32FilePropertyDialog(const QString& fileName); + +/** + \return two-letter locale name (like "en" or "pl") taken from MS Windows native registry. + Useful when we don't want to rely on KSyCoCa. + Used e.g. by kbuildsycoca application. +*/ +KDEWIN32_EXPORT +QCString getWin32LocaleName(); + +/*! Temporary solutiuon + \return a KFileDialog-compatible filter string converted to QFileDialog compatible one. + This is temporary solution for kdelibs/win32... */ +KDEWIN32_EXPORT QString convertKFileDialogFilterToQFileDialogFilter(const QString& filter); + +#endif //__cplusplus + +#endif |