From 8bd62a3b0d3b362b783a273e2460811392485bbd Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 14 Feb 2013 17:17:18 -0600 Subject: Rename common header files for consistency with class renaming --- tdecore/CMakeLists.txt | 8 +- tdecore/MAINTAINERS | 6 +- tdecore/Makefile.am | 8 +- tdecore/kaboutdata.cpp | 512 --- tdecore/kaboutdata.h | 630 ---- tdecore/kapp.h | 6 +- tdecore/kappdcopiface.cpp | 2 +- tdecore/kapplication.cpp | 3638 -------------------- tdecore/kapplication.h | 1620 --------- tdecore/kapplication_win.cpp | 2 +- tdecore/kcharsets.cpp | 2 +- tdecore/kclipboard.cpp | 2 +- tdecore/kcmdlineargs.cpp | 1298 ------- tdecore/kcmdlineargs.h | 690 ---- tdecore/kcompletion.cpp | 2 +- tdecore/kcrash.cpp | 4 +- tdecore/kdebug.cpp | 2 +- tdecore/kdesktopfile.cpp | 2 +- tdecore/kdetcompmgr.cpp | 6 +- tdecore/kglobal.cpp | 4 +- tdecore/kglobalaccel_win.cpp | 2 +- tdecore/kglobalaccel_x11.cpp | 2 +- tdecore/kglobalsettings.cpp | 2 +- tdecore/kiconloader.cpp | 2 +- tdecore/kinstance.cpp | 2 +- tdecore/klibloader.cpp | 2 +- tdecore/klockfile.cpp | 4 +- tdecore/kmanagerselection.cpp | 2 +- tdecore/knotifyclient.cpp | 4 +- tdecore/kprotocolinfo_tdecore.cpp | 2 +- tdecore/kprotocolinfofactory.cpp | 2 +- tdecore/krandomsequence.cpp | 2 +- tdecore/krootprop.cpp | 2 +- tdecore/ksavefile.cpp | 2 +- tdecore/ksimpledirwatch.cpp | 2 +- tdecore/ksocks.cpp | 2 +- tdecore/kstartupinfo.cpp | 2 +- tdecore/ktempdir.cpp | 2 +- tdecore/ktempfile.cpp | 2 +- tdecore/kuniqueapplication.cpp | 4 +- tdecore/kuniqueapplication.h | 4 +- tdecore/kxmessages.cpp | 2 +- tdecore/network/kresolverstandardworkers.cpp | 2 +- tdecore/network/ksockssocketdevice.cpp | 2 +- tdecore/tde-config.cpp.cmake | 6 +- tdecore/tde-config.cpp.in | 6 +- tdecore/tdeaboutdata.cpp | 512 +++ tdecore/tdeaboutdata.h | 630 ++++ tdecore/tdeaccel.cpp | 2 +- tdecore/tdeapplication.cpp | 3638 ++++++++++++++++++++ tdecore/tdeapplication.h | 1620 +++++++++ tdecore/tdecmdlineargs.cpp | 1298 +++++++ tdecore/tdecmdlineargs.h | 690 ++++ tdecore/tdeconfig.cpp | 2 +- tdecore/tdeconfig_compiler/example/autoexample.cpp | 6 +- tdecore/tdeconfig_compiler/example/example.cpp | 6 +- tdecore/tdeconfig_compiler/tdeconfig_compiler.cpp | 6 +- tdecore/tdeconfigbackend.cpp | 2 +- tdecore/tdeconfigbase.cpp | 2 +- tdecore/tdeconfigdialogmanager.cpp | 2 +- tdecore/tdehardwaredevices.cpp | 2 +- tdecore/tdesycoca.cpp | 2 +- tdecore/tests/KIDLTest.cpp | 2 +- tdecore/tests/KIDLTestClient.cpp | 2 +- tdecore/tests/dcopkonqtest.cpp | 2 +- tdecore/tests/kapptest.cpp | 6 +- tdecore/tests/kcalendartest.cpp | 6 +- tdecore/tests/kcmdlineargstest.cpp | 4 +- tdecore/tests/kglobaltest.cpp | 4 +- tdecore/tests/kiconloadertest.cpp | 2 +- tdecore/tests/kipctest.cpp | 2 +- tdecore/tests/klocaletest.cpp | 2 +- tdecore/tests/kmacroexpandertest.cpp | 4 +- tdecore/tests/kmdcodectest.cpp | 4 +- tdecore/tests/kmemtest.cpp | 2 +- tdecore/tests/knotifytest.cpp | 2 +- tdecore/tests/kprocesstest.cpp | 2 +- tdecore/tests/kprociotest.cpp | 2 +- tdecore/tests/krandomsequencetest.cpp | 2 +- tdecore/tests/kresolvertest.cpp | 4 +- tdecore/tests/krfcdatetest.cpp | 2 +- tdecore/tests/ksimpleconfigtest.cpp | 2 +- tdecore/tests/ksocktest.cpp | 4 +- tdecore/tests/kstddirstest.cpp | 2 +- tdecore/tests/ktempfiletest.cpp | 2 +- tdecore/tests/ktimezonestest.cpp | 2 +- tdecore/tests/kuniqueapptest.cpp | 4 +- tdecore/tests/kurltest.cpp | 4 +- tdecore/tests/startserviceby.cpp | 6 +- tdecore/tests/tdeconfigtestgui.cpp | 2 +- tdecore/tests/tdeconfigtestgui.h | 2 +- tdecore/tests/tdestdacceltest.cpp | 2 +- tdecore/tests/testqtargs.cpp | 8 +- tdecore/twin.cpp | 2 +- tdecore/twinmodule.cpp | 2 +- 95 files changed, 8516 insertions(+), 8516 deletions(-) delete mode 100644 tdecore/kaboutdata.cpp delete mode 100644 tdecore/kaboutdata.h delete mode 100644 tdecore/kapplication.cpp delete mode 100644 tdecore/kapplication.h delete mode 100644 tdecore/kcmdlineargs.cpp delete mode 100644 tdecore/kcmdlineargs.h create mode 100644 tdecore/tdeaboutdata.cpp create mode 100644 tdecore/tdeaboutdata.h create mode 100644 tdecore/tdeapplication.cpp create mode 100644 tdecore/tdeapplication.h create mode 100644 tdecore/tdecmdlineargs.cpp create mode 100644 tdecore/tdecmdlineargs.h (limited to 'tdecore') diff --git a/tdecore/CMakeLists.txt b/tdecore/CMakeLists.txt index 871190eac..850bb10f2 100644 --- a/tdecore/CMakeLists.txt +++ b/tdecore/CMakeLists.txt @@ -71,8 +71,8 @@ link_directories( install( FILES tdeconfig.h tdeconfigskeleton.h tdeconfigdata.h ksimpleconfig.h tdeconfigdialogmanager.h tdeconfigbase.h kdesktopfile.h - kurl.h ksock.h kaboutdata.h kcmdlineargs.h tdeconfigbackend.h - kapp.h kapplication.h kuniqueapp.h kuniqueapplication.h + kurl.h ksock.h tdeaboutdata.h tdecmdlineargs.h tdeconfigbackend.h + kapp.h tdeapplication.h kuniqueapp.h kuniqueapplication.h kcharsets.h tdeversion.h kpty.h kprocess.h kprocctrl.h klocale.h kicontheme.h kiconloader.h kdebug.h twinmodule.h twin.h krootprop.h tdeshortcut.h kkeynative.h tdeaccel.h @@ -120,7 +120,7 @@ install( FILES eventsrc set( target tdecore ) set( ${target}_SRCS - libintl.cpp kapplication.cpp kdebug.cpp netwm.cpp + libintl.cpp tdeapplication.cpp kdebug.cpp netwm.cpp tdeconfigbase.cpp tdeconfig.cpp ksimpleconfig.cpp tdeconfigbackend.cpp kmanagerselection.cpp kdesktopfile.cpp kstandarddirs.cpp ksock.cpp kpty.cpp kprocess.cpp kprocctrl.cpp klocale.cpp @@ -134,7 +134,7 @@ set( ${target}_SRCS kinstance.cpp kpalette.cpp kipc.cpp klibloader.cpp ktempfile.cpp kuniqueapplication.cpp tdeaccelmanager.cpp ksavefile.cpp krandomsequence.cpp kstringhandler.cpp kcompletion.cpp - kcmdlineargs.cpp kaboutdata.cpp kcompletionbase.cpp knotifyclient.cpp + tdecmdlineargs.cpp tdeaboutdata.cpp kcompletionbase.cpp knotifyclient.cpp kaudioplayer.cpp kdcoppropertyproxy.cpp ksockaddr.cpp kextsock.cpp netsupp.cpp kprocio.cpp kbufferedio.cpp kpixmapprovider.cpp kurldrag.cpp kmdcodec.cpp ksocks.cpp diff --git a/tdecore/MAINTAINERS b/tdecore/MAINTAINERS index 2b171743c..e4a9ad80d 100644 --- a/tdecore/MAINTAINERS +++ b/tdecore/MAINTAINERS @@ -6,18 +6,18 @@ When adding yourself as a maintainer, don't be afraid to reorder the files to a more logical grouping. dmalloc.cpp -kaboutdata.cpp David Faure +tdeaboutdata.cpp David Faure tdeaccel.cpp Ellis Whitehead tdeaccelaction.cpp Ellis Whitehead tdeaccelbase.cpp Ellis Whitehead kallocator.cpp Waldo Bastian kappdcopiface.cpp -kapplication.cpp Waldo Bastian +tdeapplication.cpp Waldo Bastian kaudioplayer.cpp kcatalogue.cpp Hans Petter Bieker kcharsets.cpp Lars Knoll kckey.cpp -kcmdlineargs.cpp Waldo Bastian +tdecmdlineargs.cpp Waldo Bastian kcompletion.cpp Carsten Pfeiffer kcompletionbase.cpp tdeconfig.cpp Waldo Bastian diff --git a/tdecore/Makefile.am b/tdecore/Makefile.am index 332e178ea..ae5048ed9 100644 --- a/tdecore/Makefile.am +++ b/tdecore/Makefile.am @@ -38,8 +38,8 @@ lib_LIBRARIES = libtdefakes_nonpic.a libtdefakes_pic.a include_HEADERS = tdeconfig.h tdeconfigskeleton.h \ tdeconfigdata.h ksimpleconfig.h tdeconfigdialogmanager.h \ - tdeconfigbase.h kdesktopfile.h kurl.h ksock.h kaboutdata.h \ - kcmdlineargs.h tdeconfigbackend.h kapp.h kapplication.h kuniqueapp.h \ + tdeconfigbase.h kdesktopfile.h kurl.h ksock.h tdeaboutdata.h \ + tdecmdlineargs.h tdeconfigbackend.h kapp.h tdeapplication.h kuniqueapp.h \ kuniqueapplication.h kcharsets.h tdeversion.h kpty.h kprocess.h \ kprocctrl.h klocale.h kicontheme.h kiconloader.h kdebug.h \ twinmodule.h twin.h krootprop.h tdeshortcut.h kkeynative.h tdeaccel.h \ @@ -89,7 +89,7 @@ noinst_HEADERS = tdeaccelaction.h tdeaccelbase.h tdeaccelprivate.h kckey.h \ kcalendarsystemhijri.h kcalendarsystemhebrew.h kcalendarsystemjalali.h \ kprotocolinfofactory.h kqiodevicegzip_p.h kiconloader_p.h -libtdecore_la_SOURCES = libintl.cpp kapplication.cpp \ +libtdecore_la_SOURCES = libintl.cpp tdeapplication.cpp \ kdebug.cpp netwm.cpp tdeconfigbase.cpp tdeconfig.cpp ksimpleconfig.cpp \ tdeconfigbackend.cpp kmanagerselection.cpp kdesktopfile.cpp \ kstandarddirs.cpp ksock.cpp kpty.cpp kprocess.cpp kprocctrl.cpp \ @@ -103,7 +103,7 @@ libtdecore_la_SOURCES = libintl.cpp kapplication.cpp \ kinstance.cpp kpalette.cpp kipc.cpp klibloader.cpp ktempfile.cpp \ kuniqueapplication.cpp tdeaccelmanager.cpp \ ksavefile.cpp krandomsequence.cpp kstringhandler.cpp kcompletion.cpp \ - kcmdlineargs.cpp kaboutdata.cpp kcompletionbase.cpp knotifyclient.cpp \ + tdecmdlineargs.cpp tdeaboutdata.cpp kcompletionbase.cpp knotifyclient.cpp \ kaudioplayer.cpp kdcoppropertyproxy.cpp \ ksockaddr.cpp kextsock.cpp netsupp.cpp kprocio.cpp kbufferedio.cpp \ kpixmapprovider.cpp kurldrag.cpp \ diff --git a/tdecore/kaboutdata.cpp b/tdecore/kaboutdata.cpp deleted file mode 100644 index c5055e4dc..000000000 --- a/tdecore/kaboutdata.cpp +++ /dev/null @@ -1,512 +0,0 @@ -/* - * 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 -#include -#include -#include - -TQString -TDEAboutPerson::name() const -{ - return TQString::fromUtf8(mName); -} - -TQString -TDEAboutPerson::task() const -{ - if (mTask && *mTask) - return i18n(mTask); - else - return TQString::null; -} - -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) - , customAuthorTextEnabled(false) - , mTranslatedProgramName( 0 ) - {} - ~TDEAboutDataPrivate() - { - delete programLogo; - delete[] mTranslatedProgramName; - } - const char *translatorName; - const char *translatorEmail; - const char *productName; - TQImage* programLogo; - TQString customAuthorPlainText, customAuthorRichText; - bool customAuthorTextEnabled; - const char *mTranslatedProgramName; -}; - -const char *TDEAboutData::defaultBugTracker = "http://bugs.trinitydesktop.org"; - -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!=0)?bugsEmailAddress:defaultBugTracker ), - 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; - translateInternalProgramName(); -} - -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::null; -} - -const char* -TDEAboutData::internalProgramName() const -{ - if (d->mTranslatedProgramName) - return d->mTranslatedProgramName; - else - return mProgramName; -} - -// TDECrash should call as few things as possible and should avoid e.g. malloc() -// because it may deadlock. Since i18n() needs it, when TDELocale is available -// the i18n() call will be done here in advance. -void -TDEAboutData::translateInternalProgramName() const -{ - delete[] d->mTranslatedProgramName; - d->mTranslatedProgramName = 0; - if( TDEGlobal::locale() ) - d->mTranslatedProgramName = tqstrdup( programName().utf8()); -} - -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::null; -} - -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)) - { - nameList = TQStringList::split(',',names); - } - - - if(d->translatorEmail) - { - TQString emails = i18n(d->translatorEmail); - - if(emails != TQString::fromUtf8(d->translatorEmail)) - { - emailList = TQStringList::split(',',emails,true); - } - } - - - 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; - - personList.append(TDEAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace())); - } - - return personList; -} - -TQString -TDEAboutData::aboutTranslationTeam() -{ - return i18n("replace this with information about your translation team", - "

KDE is translated into many languages thanks to the work " - "of the translation teams all over the world.

" - "

For more information on KDE internationalization " - "visit http://l10n.kde.org

" - ); -} - -TQString -TDEAboutData::otherText() const -{ - if (mOtherText && *mOtherText) - return i18n(mOtherText); - else - return TQString::null; -} - - -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_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()) - { - TQFile file(f); - if (file.open(IO_ReadOnly)) - { - result += '\n'; - result += '\n'; - TQTextStream str(&file); - result += str.read(); - } - } - - return result; -} - -TQString -TDEAboutData::copyrightStatement() const -{ - if (mCopyrightStatement && *mCopyrightStatement) - return i18n(mCopyrightStatement); - else - return TQString::null; -} - -TQString -TDEAboutData::customAuthorPlainText() const -{ - return d->customAuthorPlainText; -} - -TQString -TDEAboutData::customAuthorRichText() const -{ - return d->customAuthorRichText; -} - -bool -TDEAboutData::customAuthorTextEnabled() const -{ - return d->customAuthorTextEnabled; -} - -void -TDEAboutData::setCustomAuthorText(const TQString &plainText, const TQString &richText) -{ - d->customAuthorPlainText = plainText; - d->customAuthorRichText = richText; - - d->customAuthorTextEnabled = true; -} - -void -TDEAboutData::unsetCustomAuthorText() -{ - d->customAuthorPlainText = TQString::null; - d->customAuthorRichText = TQString::null; - - d->customAuthorTextEnabled = false; -} - diff --git a/tdecore/kaboutdata.h b/tdecore/kaboutdata.h deleted file mode 100644 index d5addac0a..000000000 --- a/tdecore/kaboutdata.h +++ /dev/null @@ -1,630 +0,0 @@ -/* - * 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 -#include -#include -#include - -#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(): - * - * \code - * 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); - * \endcode - */ -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 QValueList - */ - TDEAboutPerson() {} - - /** - * The person's name - * @return the person's name (can be TQString::null, if it has been - * constructed with a null name) - */ - TQString name() const; - - /** - * The person's task - * @return the person's task (can be TQString::null, 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::null, 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::null, 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::null, - const TQString & emailAddress=TQString::null); - - /** - * The translator's name - * @return the translators's name (can be TQString::null, 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::null, 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_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 trinitydesktop.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 = 0 - ); - - ~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"). - * @since 3.2 - */ - 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; - - /** - * @internal - */ - const char* internalProgramName() const; - /** - * @internal - */ - void translateInternalProgramName() 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; - - /** - * @internal - */ - const char* internalVersion() const { return mVersion; } - - /** - * Returns a short, translated description. - * @return the short description (translated). Can be - * TQString::null if not set. - */ - TQString shortDescription() const; - - /** - * Returns the application homepage. - * @return the application homepage URL. Can be TQString::null if - * not set. - */ - TQString homepage() const; - - /** - * Returns the email address for bugs. - * @return the email address where to report bugs. - */ - TQString bugAddress() const; - - /** - * @internal - */ - const char* internalBugAddress() const { return mBugEmailAddress; } - - /** - * 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::null 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::null if not set. - */ - TQString copyrightStatement() const; - - /** - * Returns the plain text displayed around the list of authors instead - * of the default message telling users to send bug reports to bugAddress(). - * - * @return the plain text displayed around the list of authors instead - * of the default message. Can be TQString::null. - */ - TQString customAuthorPlainText() const; - - /** - * Returns the rich text displayed around the list of authors instead - * of the default message telling users to send bug reports to bugAddress(). - * - * @return the rich text displayed around the list of authors instead - * of the default message. Can be TQString::null. - */ - TQString customAuthorRichText() const; - - /** - * Returns whether custom text should be displayed around the list of - * authors. - * - * @return whether custom text should be displayed around the list of - * authors. - */ - bool customAuthorTextEnabled() const; - - /** - * Sets the custom text displayed around the list of authors instead - * of the default message telling users to send bug reports to bugAddress(). - * - * @param plainText The plain text. - * @param richText The rich text. - * - * Both parameters can be TQString::null to not display any message at - * all. Call unsetCustomAuthorText() to revert to the default mesage. - */ - void setCustomAuthorText(const TQString &plainText, const TQString &richText); - - /** - * Clears any custom text displayed around the list of authors and falls - * back to the default message telling users to send bug reports to - * bugAddress(). - */ - void unsetCustomAuthorText(); - - 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; - static const char *defaultBugTracker; - - TDEAboutDataPrivate *d; -}; - -#endif - diff --git a/tdecore/kapp.h b/tdecore/kapp.h index c51c463a0..5d48a852f 100644 --- a/tdecore/kapp.h +++ b/tdecore/kapp.h @@ -1,6 +1,6 @@ -// kapp.h is the old name. Use #include from now on +// kapp.h is the old name. Use #include from now on #ifdef KDE_NO_COMPAT -#error include instead of +#error include instead of #else -#include +#include #endif diff --git a/tdecore/kappdcopiface.cpp b/tdecore/kappdcopiface.cpp index 9f1148579..31bc8dd5b 100644 --- a/tdecore/kappdcopiface.cpp +++ b/tdecore/kappdcopiface.cpp @@ -18,7 +18,7 @@ */ #include "kappdcopiface.h" -#include +#include #include #include #include diff --git a/tdecore/kapplication.cpp b/tdecore/kapplication.cpp deleted file mode 100644 index 15c8a132b..000000000 --- a/tdecore/kapplication.cpp +++ /dev/null @@ -1,3638 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) - Copyright (C) 1998, 1999, 2000 KDE Team - - 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 "config.h" - -#ifdef HAVE_XCOMPOSITE -#define COMPOSITE -#endif - -// #ifdef QTRANSLATOR_H -// #error qtranslator.h was already included -// #endif // QTRANSLATOR_H -// -// #ifdef TQTRANSLATOR_H -// #error tqtranslator.h was already included -// #endif // TQTRANSLATOR_H - -#undef QT_NO_TRANSLATION -#undef TQT_NO_TRANSLATION -#include -#include "kapplication.h" -#define QT_NO_TRANSLATION -#define TQT_NO_TRANSLATION -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef QT_NO_SQL -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "kcheckaccelerators.h" -#include -#include -#include -#include -#include -#include -#include - -#if defined Q_WS_X11 -#include -#endif - -#include -#include - -#include -#ifdef HAVE_SYS_STAT_H -#include -#endif -#include -#include -#include - -#ifndef Q_WS_WIN -#include "twin.h" -#endif - -#include -#include // getenv(), srand(), rand() -#include -#include -#include -#include -#include -#include -#include -#if defined Q_WS_X11 -//#ifndef Q_WS_QWS //FIXME(E): NetWM should talk to QWS... -#include -#endif - -#include "kprocctrl.h" - -#ifdef HAVE_PATHS_H -#include -#endif - -#ifdef Q_WS_X11 -#include -#ifdef COMPOSITE -#include -#include -#include -#endif -#include -#include -#include -#include -#endif - -#include - -#ifndef Q_WS_WIN -#include -#else -typedef void* IceIOErrorHandler; -#include -//KDE4: remove -#define Button1Mask (1<<8) -#define Button2Mask (1<<9) -#define Button3Mask (1<<10) -#endif - -#ifdef Q_WS_X11 -#define DISPLAY "DISPLAY" -#elif defined(Q_WS_QWS) -#define DISPLAY "QWS_DISPLAY" -#endif - -#if defined Q_WS_X11 -#include -#endif - -#ifdef Q_WS_MACX -#include -#include -#endif - -#include "kappdcopiface.h" - -// exported for tdm kfrontend -KDE_EXPORT bool kde_have_kipc = true; // magic hook to disable kipc in tdm -bool kde_kiosk_exception = false; // flag to disable kiosk restrictions -bool kde_kiosk_admin = false; - -TDEApplication* TDEApplication::KApp = 0L; -bool TDEApplication::loadedByKdeinit = false; -DCOPClient *TDEApplication::s_DCOPClient = 0L; -bool TDEApplication::s_dcopClientNeedsPostInit = false; - -#ifdef Q_WS_X11 -static Atom atom_DesktopWindow; -static Atom atom_NetSupported; -static Atom kde_xdnd_drop; -#endif - -#ifdef Q_WS_X11 -static int composite_event, composite_error, composite_opcode; -static bool x11_composite_error_generated; -static int x11_error(Display *dpy, XErrorEvent *ev) { - if (ev->request_code == composite_opcode && ev->minor_code == X_CompositeRedirectSubwindows) - { - x11_composite_error_generated = true; - return 0; - } - return 1; -} -#endif - -// duplicated from patched Qt, so that there won't be unresolved symbols if Qt gets -// replaced by unpatched one -TDECORE_EXPORT bool tqt_qclipboard_bailout_hack = false; - -template class TQPtrList; - -#ifdef Q_WS_X11 -extern "C" { -static int kde_xio_errhandler( Display * dpy ) -{ - return kapp->xioErrhandler( dpy ); -} - -static int kde_x_errhandler( Display *dpy, XErrorEvent *err ) -{ - return kapp->xErrhandler( dpy, err ); -} - -} - -extern "C" { -static void kde_ice_ioerrorhandler( IceConn conn ) -{ - if(kapp) - kapp->iceIOErrorHandler( conn ); - // else ignore the error for now -} -} -#endif - -#ifdef Q_WS_WIN -void TDEApplication_init_windows(bool GUIenabled); - -class QAssistantClient; -#endif - -/* - Private data to make keeping binary compatibility easier - */ -class TDEApplicationPrivate -{ -public: - TDEApplicationPrivate() - : actionRestrictions( false ), - refCount( 1 ), - oldIceIOErrorHandler( 0 ), - checkAccelerators( 0 ), - overrideStyle( TQString::null ), - startup_id( "0" ), - app_started_timer( NULL ), - m_KAppDCOPInterface( 0L ), - session_save( false ) -#ifdef Q_WS_X11 - ,oldXErrorHandler( NULL ) - ,oldXIOErrorHandler( NULL ) -#elif defined Q_WS_WIN - ,qassistantclient( 0 ) -#endif - { - } - - ~TDEApplicationPrivate() - { -#ifdef Q_WS_WIN - delete qassistantclient; -#endif - } - - - bool actionRestrictions : 1; - bool guiEnabled : 1; - /** - * This counter indicates when to exit the application. - * It starts at 1, is decremented in TDEMainWindow when the last window is closed, but - * is incremented by operations that should outlive the last window closed - * (e.g. a file copy for a file manager, or 'compacting folders on exit' for a mail client). - */ - int refCount; - IceIOErrorHandler oldIceIOErrorHandler; - KCheckAccelerators* checkAccelerators; - TQString overrideStyle; - TQString geometry_arg; - TQCString startup_id; - TQTimer* app_started_timer; - KAppDCOPInterface *m_KAppDCOPInterface; - bool session_save; -#ifdef Q_WS_X11 - int (*oldXErrorHandler)(Display*,XErrorEvent*); - int (*oldXIOErrorHandler)(Display*); -#elif defined Q_WS_WIN - QAssistantClient* qassistantclient; -#endif - - class URLActionRule - { - public: -#define checkExactMatch(s, b) \ - if (s.isEmpty()) b = true; \ - else if (s[s.length()-1] == '!') \ - { b = false; s.truncate(s.length()-1); } \ - else b = true; -#define checkStartWildCard(s, b) \ - if (s.isEmpty()) b = true; \ - else if (s[0] == '*') \ - { b = true; s = s.mid(1); } \ - else b = false; -#define checkEqual(s, b) \ - b = (s == "="); - - URLActionRule(const TQString &act, - const TQString &bProt, const TQString &bHost, const TQString &bPath, - const TQString &dProt, const TQString &dHost, const TQString &dPath, - bool perm) - : action(act), - baseProt(bProt), baseHost(bHost), basePath(bPath), - destProt(dProt), destHost(dHost), destPath(dPath), - permission(perm) - { - checkExactMatch(baseProt, baseProtWildCard); - checkStartWildCard(baseHost, baseHostWildCard); - checkExactMatch(basePath, basePathWildCard); - checkExactMatch(destProt, destProtWildCard); - checkStartWildCard(destHost, destHostWildCard); - checkExactMatch(destPath, destPathWildCard); - checkEqual(destProt, destProtEqual); - checkEqual(destHost, destHostEqual); - } - - bool baseMatch(const KURL &url, const TQString &protClass) - { - if (baseProtWildCard) - { - if ( !baseProt.isEmpty() && !url.protocol().startsWith(baseProt) && - (protClass.isEmpty() || (protClass != baseProt)) ) - return false; - } - else - { - if ( (url.protocol() != baseProt) && - (protClass.isEmpty() || (protClass != baseProt)) ) - return false; - } - if (baseHostWildCard) - { - if (!baseHost.isEmpty() && !url.host().endsWith(baseHost)) - return false; - } - else - { - if (url.host() != baseHost) - return false; - } - if (basePathWildCard) - { - if (!basePath.isEmpty() && !url.path().startsWith(basePath)) - return false; - } - else - { - if (url.path() != basePath) - return false; - } - return true; - } - - bool destMatch(const KURL &url, const TQString &protClass, const KURL &base, const TQString &baseClass) - { - if (destProtEqual) - { - if ( (url.protocol() != base.protocol()) && - (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass) ) - return false; - } - else if (destProtWildCard) - { - if ( !destProt.isEmpty() && !url.protocol().startsWith(destProt) && - (protClass.isEmpty() || (protClass != destProt)) ) - return false; - } - else - { - if ( (url.protocol() != destProt) && - (protClass.isEmpty() || (protClass != destProt)) ) - return false; - } - if (destHostWildCard) - { - if (!destHost.isEmpty() && !url.host().endsWith(destHost)) - return false; - } - else if (destHostEqual) - { - if (url.host() != base.host()) - return false; - } - else - { - if (url.host() != destHost) - return false; - } - if (destPathWildCard) - { - if (!destPath.isEmpty() && !url.path().startsWith(destPath)) - return false; - } - else - { - if (url.path() != destPath) - return false; - } - return true; - } - - TQString action; - TQString baseProt; - TQString baseHost; - TQString basePath; - TQString destProt; - TQString destHost; - TQString destPath; - bool baseProtWildCard : 1; - bool baseHostWildCard : 1; - bool basePathWildCard : 1; - bool destProtWildCard : 1; - bool destHostWildCard : 1; - bool destPathWildCard : 1; - bool destProtEqual : 1; - bool destHostEqual : 1; - bool permission; - }; - TQPtrList urlActionRestrictions; - - TQString sessionKey; - TQString pSessionConfigFile; -}; - - -static TQPtrList*x11Filter = 0; -static bool autoDcopRegistration = true; - -void TDEApplication::installX11EventFilter( TQWidget* filter ) -{ - if ( !filter ) - return; - if (!x11Filter) - x11Filter = new TQPtrList; - connect ( filter, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( x11FilterDestroyed() ) ); - x11Filter->append( filter ); -} - -void TDEApplication::x11FilterDestroyed() -{ - removeX11EventFilter( static_cast< const TQWidget* >( sender())); -} - -void TDEApplication::removeX11EventFilter( const TQWidget* filter ) -{ - if ( !x11Filter || !filter ) - return; - x11Filter->removeRef( filter ); - if ( x11Filter->isEmpty() ) { - delete x11Filter; - x11Filter = 0; - } -} - -// FIXME: remove this when we've get a better method of -// customizing accelerator handling -- hopefully in Qt. -// For now, this is set whenever an accelerator is overridden -// in TDEAccelEventHandler so that the AccelOverride isn't sent twice. -- ellis, 19/10/02 -extern bool kde_g_bKillAccelOverride; - -bool TDEApplication::notify(TQObject *receiver, TQEvent *event) -{ - TQEvent::Type t = event->type(); - if (kde_g_bKillAccelOverride) - { - kde_g_bKillAccelOverride = false; - // Indicate that the accelerator has been overridden. - if (t == TQEvent::AccelOverride) - { - TQT_TQKEYEVENT(event)->accept(); - return true; - } - else - kdWarning(125) << "kde_g_bKillAccelOverride set, but received an event other than AccelOverride." << endl; - } - - if ((t == TQEvent::AccelOverride) || (t == TQEvent::KeyPress)) - { - static const TDEShortcut& _selectAll = TDEStdAccel::selectAll(); - TQLineEdit *edit = ::tqqt_cast(receiver); - if (edit) - { - // We have a keypress for a lineedit... - TQKeyEvent *kevent = TQT_TQKEYEVENT(event); - KKey key(kevent); - if (_selectAll.contains(key)) - { - if (t == TQEvent::KeyPress) - { - edit->selectAll(); - return true; - } - else - { - kevent->accept(); - } - } - // Ctrl-U deletes from start of line. - if (key == KKey(Qt::CTRL + Qt::Key_U)) - { - if (t == TQEvent::KeyPress) - { - if (!edit->isReadOnly()) - { - TQString t(edit->text()); - t = t.mid(edit->cursorPosition()); - edit->validateAndSet(t, 0, 0, 0); - } - return true; - } - else - { - kevent->accept(); - } - - } - } - TQTextEdit *medit = ::tqqt_cast(receiver); - if (medit) - { - // We have a keypress for a multilineedit... - TQKeyEvent *kevent = TQT_TQKEYEVENT(event); - if (_selectAll.contains(KKey(kevent))) - { - if (t == TQEvent::KeyPress) - { - medit->selectAll(); - return true; - } - else - { - kevent->accept(); - } - } - } - } - if( t == TQEvent::Show && receiver->isWidgetType()) - { - TQWidget* w = TQT_TQWIDGET( receiver ); -#if defined Q_WS_X11 - if( w->isTopLevel() && !startupId().isEmpty() && !TQT_TQSHOWEVENT(event)->spontaneous()) // TODO better done using window group leader? - TDEStartupInfo::setWindowStartupId( w->winId(), startupId()); -#endif - if( w->isTopLevel() && !w->testWFlags( WX11BypassWM ) && !w->isPopup() && !event->spontaneous()) - { - if( d->app_started_timer == NULL ) - { - d->app_started_timer = new TQTimer( this, "app_started_timer" ); - connect( d->app_started_timer, TQT_SIGNAL( timeout()), TQT_SLOT( checkAppStartedSlot())); - } - if( !d->app_started_timer->isActive()) - d->app_started_timer->start( 0, true ); - } - if( w->isTopLevel() && ( w->icon() == NULL || w->icon()->isNull())) - { - // icon() cannot be null pixmap, it'll be the "unknown" icon - so check if there is this application icon - static TQPixmap* ic = NULL; - if( ic == NULL ) - ic = new TQPixmap( TDEGlobal::iconLoader()->loadIcon( iconName(), - TDEIcon::NoGroup, 0, TDEIcon::DefaultState, NULL, true )); - if( !ic->isNull()) - { - w->setIcon( *ic ); -#if defined Q_WS_X11 - KWin::setIcons( w->winId(), *ic, miniIcon()); -#endif - } - } - } - return TQApplication::notify(receiver, event); -} - -void TDEApplication::checkAppStartedSlot() -{ -#if defined Q_WS_X11 - TDEStartupInfo::handleAutoAppStartedSending(); -#endif -} - -// the help class for session management communication -static TQPtrList* sessionClients() -{ - static TQPtrList* session_clients = 0L; - if ( !session_clients ) - session_clients = new TQPtrList; - return session_clients; -} - -/* - Auxiliary function to calculate a a session config name used for the - instance specific config object. - Syntax: "session/_" - */ -TQString TDEApplication::sessionConfigName() const -{ - TQString sessKey = sessionKey(); - if ( sessKey.isEmpty() && !d->sessionKey.isEmpty() ) - sessKey = d->sessionKey; - return TQString("session/%1_%2_%3").arg(name()).arg(sessionId()).arg(sessKey); -} - -#ifdef Q_WS_X11 -static SmcConn mySmcConnection = 0; -static SmcConn tmpSmcConnection = 0; -#else -// FIXME(E): Implement for Qt Embedded -// Possibly "steal" XFree86's libSM? -#endif -static TQTime* smModificationTime = 0; - -TDEApplication::TDEApplication( int& argc, char** argv, const TQCString& rAppName, - bool allowStyles, bool GUIenabled ) : - TQApplication( argc, argv, GUIenabled ), TDEInstance(rAppName), -#ifdef Q_WS_X11 - display(0L), - argb_visual(false), -#endif - d (new TDEApplicationPrivate()) -{ - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - if (!GUIenabled) - allowStyles = false; - useStyles = allowStyles; - Q_ASSERT (!rAppName.isEmpty()); - setName(rAppName); - - installSigpipeHandler(); - TDECmdLineArgs::initIgnore(argc, argv, rAppName.data()); - parseCommandLine( ); - init(GUIenabled); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} - -TDEApplication::TDEApplication( bool allowStyles, bool GUIenabled ) : -// TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), TRUE ), // Qt4 requires that there always be a GUI - TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), GUIenabled ), // We need to be able to run command line apps - TDEInstance( TDECmdLineArgs::about), -#ifdef Q_WS_X11 - display(0L), - argb_visual(false), -#endif - d (new TDEApplicationPrivate) -{ - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - if (!GUIenabled) - allowStyles = false; - useStyles = allowStyles; - setName( instanceName() ); - - installSigpipeHandler(); - parseCommandLine( ); - init(GUIenabled); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} - -#ifdef Q_WS_X11 -TDEApplication::TDEApplication( Display *dpy, bool allowStyles ) : - TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), - getX11RGBAVisual(dpy), getX11RGBAColormap(dpy) ), - TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate) -{ - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - useStyles = allowStyles; - setName( instanceName() ); - installSigpipeHandler(); - parseCommandLine( ); - init( true ); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} - -TDEApplication::TDEApplication( Display *dpy, bool disable_argb, Qt::HANDLE visual, Qt::HANDLE colormap, bool allowStyles ) : - TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), - disable_argb?visual:getX11RGBAVisual(dpy), disable_argb?colormap:getX11RGBAColormap(dpy) ), - TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate) -{ - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - useStyles = allowStyles; - if (disable_argb) argb_visual = false; - setName( instanceName() ); - installSigpipeHandler(); - parseCommandLine( ); - init( true ); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} - -TDEApplication::TDEApplication( Display *dpy, Qt::HANDLE visual, Qt::HANDLE colormap, - bool allowStyles ) : - TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), - visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ), - TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate) -{ - if ((visual) && (colormap)) - getX11RGBAInformation(dpy); - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - useStyles = allowStyles; - setName( instanceName() ); - installSigpipeHandler(); - parseCommandLine( ); - init( true ); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} - -TDEApplication::TDEApplication( Display *dpy, Qt::HANDLE visual, Qt::HANDLE colormap, - bool allowStyles, TDEInstance * _instance ) : - TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), - visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ), - TDEInstance( _instance ), display(0L), d (new TDEApplicationPrivate) -{ - if ((visual) && (colormap)) - getX11RGBAInformation(dpy); - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - useStyles = allowStyles; - setName( instanceName() ); - installSigpipeHandler(); - parseCommandLine( ); - init( true ); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} -#endif - -TDEApplication::TDEApplication( bool allowStyles, bool GUIenabled, TDEInstance* _instance ) : - TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), - GUIenabled ), - TDEInstance( _instance ), -#ifdef Q_WS_X11 - display(0L), -#endif - argb_visual(false), - d (new TDEApplicationPrivate) -{ - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - if (!GUIenabled) - allowStyles = false; - useStyles = allowStyles; - setName( instanceName() ); - - installSigpipeHandler(); - parseCommandLine( ); - init(GUIenabled); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} - -#ifdef Q_WS_X11 -TDEApplication::TDEApplication(Display *display, int& argc, char** argv, const TQCString& rAppName, - bool allowStyles, bool GUIenabled ) : - TQApplication( display ), TDEInstance(rAppName), - display(0L), - argb_visual(false), - d (new TDEApplicationPrivate()) -{ - aIconPixmap.pm.icon = 0L; - aIconPixmap.pm.miniIcon = 0L; - read_app_startup_id(); - if (!GUIenabled) - allowStyles = false; - useStyles = allowStyles; - - Q_ASSERT (!rAppName.isEmpty()); - setName(rAppName); - - installSigpipeHandler(); - TDECmdLineArgs::initIgnore(argc, argv, rAppName.data()); - parseCommandLine( ); - init(GUIenabled); - d->m_KAppDCOPInterface = new KAppDCOPInterface(this); -} -#endif - -int TDEApplication::xioErrhandler( Display* dpy ) -{ - if(kapp) - { - emit shutDown(); -#ifdef Q_WS_X11 - d->oldXIOErrorHandler( dpy ); -#else - Q_UNUSED(dpy); -#endif - } - exit( 1 ); - return 0; -} - -int TDEApplication::xErrhandler( Display* dpy, void* err_ ) -{ // no idea how to make forward decl. for XErrorEvent -#ifdef Q_WS_X11 - XErrorEvent* err = static_cast< XErrorEvent* >( err_ ); - if(kapp) - { - // add KDE specific stuff here - d->oldXErrorHandler( dpy, err ); - } -#endif - return 0; -} - -void TDEApplication::iceIOErrorHandler( _IceConn *conn ) -{ - emit shutDown(); - -#ifdef Q_WS_X11 - if ( d->oldIceIOErrorHandler != NULL ) - (*d->oldIceIOErrorHandler)( conn ); -#endif - exit( 1 ); -} - -class KDETranslator : public TQTranslator -{ -public: - KDETranslator(TQObject *parent) : TQTranslator(parent, "kdetranslator") {} - virtual TQTranslatorMessage findMessage(const char* context, - const char *sourceText, - const char* message) const - { - TQTranslatorMessage res; - res.setTranslation(TDEGlobal::locale()->translateQt(context, sourceText, message)); - return res; - } -}; - -void TDEApplication::init(bool GUIenabled) -{ - d->guiEnabled = GUIenabled; - if ((getuid() != geteuid()) || - (getgid() != getegid()) ) - { - // man permissions are not exploitable and better than - // world writable directories - struct group *man = getgrnam("man"); - if ( !man || man->gr_gid != getegid() ){ - fprintf(stderr, "The TDE libraries are not designed to run with suid privileges.\n"); - ::exit(127); - } - } - - TDEProcessController::ref(); - - (void) TDEClipboardSynchronizer::self(); - - TQApplication::setDesktopSettingsAware( false ); - - KApp = this; - - -#ifdef Q_WS_X11 //FIXME(E) - // create all required atoms in _one_ roundtrip to the X server - if ( GUIenabled ) { - const int max = 20; - Atom* atoms[max]; - char* names[max]; - Atom atoms_return[max]; - int n = 0; - - atoms[n] = &kipcCommAtom; - names[n++] = (char *) "KIPC_COMM_ATOM"; - - atoms[n] = &atom_DesktopWindow; - names[n++] = (char *) "KDE_DESKTOP_WINDOW"; - - atoms[n] = &atom_NetSupported; - names[n++] = (char *) "_NET_SUPPORTED"; - - atoms[n] = &kde_xdnd_drop; - names[n++] = (char *) "XdndDrop"; - - XInternAtoms( tqt_xdisplay(), names, n, false, atoms_return ); - - for (int i = 0; i < n; i++ ) - *atoms[i] = atoms_return[i]; - } -#endif - - dcopAutoRegistration(); - dcopClientPostInit(); - - smw = 0; - - // Initial KIPC event mask. -#if defined Q_WS_X11 - kipcEventMask = (1 << KIPC::StyleChanged) | (1 << KIPC::PaletteChanged) | - (1 << KIPC::FontChanged) | (1 << KIPC::BackgroundChanged) | - (1 << KIPC::ToolbarStyleChanged) | (1 << KIPC::SettingsChanged) | - (1 << KIPC::ClipboardConfigChanged) | (1 << KIPC::BlockShortcuts); -#endif - - // Trigger creation of locale. - (void) TDEGlobal::locale(); - - TDEConfig* config = TDEGlobal::config(); - d->actionRestrictions = config->hasGroup("KDE Action Restrictions" ) && !kde_kiosk_exception; - // For brain-dead configurations where the user's local config file is not writable. - // * We use kdialog to warn the user, so we better not generate warnings from - // kdialog itself. - // * Don't warn if we run with a read-only $HOME - TQCString readOnly = getenv("TDE_HOME_READONLY"); - if (readOnly.isEmpty() && (tqstrcmp(name(), "kdialog") != 0)) - { - TDEConfigGroupSaver saver(config, "KDE Action Restrictions"); - if (config->readBoolEntry("warn_unwritable_config",true)) - config->checkConfigFilesWritable(true); - } - - if (GUIenabled) - { -#ifdef Q_WS_X11 - // this is important since we fork() to launch the help (Matthias) - fcntl(ConnectionNumber(tqt_xdisplay()), F_SETFD, FD_CLOEXEC); - // set up the fancy (=robust and error ignoring ) KDE xio error handlers (Matthias) - d->oldXErrorHandler = XSetErrorHandler( kde_x_errhandler ); - d->oldXIOErrorHandler = XSetIOErrorHandler( kde_xio_errhandler ); -#endif - - connect( this, TQT_SIGNAL( aboutToQuit() ), this, TQT_SIGNAL( shutDown() ) ); - -#ifdef Q_WS_X11 //FIXME(E) - display = desktop()->x11Display(); -#endif - - { - TQStringList plugins = TDEGlobal::dirs()->resourceDirs( "qtplugins" ); - TQStringList::Iterator it = plugins.begin(); - while (it != plugins.end()) { - addLibraryPath( *it ); - ++it; - } - - } - tdedisplaySetStyle(); - tdedisplaySetFont(); -// tdedisplaySetPalette(); done by tdedisplaySetStyle - propagateSettings(SETTINGS_QT); - - // Set default mime-source factory - // XXX: This is a hack. Make our factory the default factory, but add the - // previous default factory to the list of factories. Why? When the default - // factory can't resolve something, it iterates in the list of factories. - // But it TQWhatsThis only uses the default factory. So if there was already - // a default factory (which happens when using an image library using uic), - // we prefer KDE's factory and so we put that old default factory in the - // list and use KDE as the default. This may speed up things as well. - TQMimeSourceFactory* oldDefaultFactory = TQMimeSourceFactory::takeDefaultFactory(); - TQMimeSourceFactory::setDefaultFactory( mimeSourceFactory() ); - if ( oldDefaultFactory ) { - TQMimeSourceFactory::addFactory( oldDefaultFactory ); - } - - d->checkAccelerators = new KCheckAccelerators( TQT_TQOBJECT(this) ); - } - -#ifdef Q_WS_MACX - if (GUIenabled) { - TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon( TDECmdLineArgs::appName(), - TDEIcon::NoGroup, TDEIcon::SizeLarge, TDEIcon::DefaultState, 0L, false ); - if (!pixmap.isNull()) { - TQImage i = pixmap.convertToImage().convertDepth(32).smoothScale(40, 40); - for(int y = 0; y < i.height(); y++) { - uchar *l = i.scanLine(y); - for(int x = 0; x < i.width(); x+=4) - *(l+x) = 255; - } - CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); - CGDataProviderRef dp = CGDataProviderCreateWithData(NULL, - i.bits(), i.numBytes(), NULL); - CGImageRef ir = CGImageCreate(i.width(), i.height(), 8, 32, i.bytesPerLine(), - cs, kCGImageAlphaNoneSkipFirst, dp, - 0, 0, kCGRenderingIntentDefault); - //cleanup - SetApplicationDockTileImage(ir); - CGImageRelease(ir); - CGColorSpaceRelease(cs); - CGDataProviderRelease(dp); - } - } -#endif - - - // save and restore the RTL setting, as installTranslator calls qt_detectRTLLanguage, - // which makes it impossible to use the -reverse cmdline switch with KDE apps - bool rtl = reverseLayout(); - installTranslator(new KDETranslator(TQT_TQOBJECT(this))); - setReverseLayout( rtl ); - if (i18n( "_: Dear Translator! Translate this string to the string 'LTR' in " - "left-to-right languages (as english) or to 'RTL' in right-to-left " - "languages (such as Hebrew and Arabic) to get proper widget layout." ) == "RTL") - setReverseLayout( !rtl ); - - // install appdata resource type - TDEGlobal::dirs()->addResourceType("appdata", TDEStandardDirs::kde_default("data") - + TQString::fromLatin1(name()) + '/'); - pSessionConfig = 0L; - bSessionManagement = true; - -#ifdef Q_WS_X11 - // register a communication window for desktop changes (Matthias) - if (GUIenabled && kde_have_kipc ) - { - smw = new TQWidget(0,0); - long data = 1; - XChangeProperty(tqt_xdisplay(), smw->winId(), - atom_DesktopWindow, atom_DesktopWindow, - 32, PropModeReplace, (unsigned char *)&data, 1); - } - d->oldIceIOErrorHandler = IceSetIOErrorHandler( kde_ice_ioerrorhandler ); -#elif defined(Q_WS_WIN) - TDEApplication_init_windows(GUIenabled); -#else - // FIXME(E): Implement for Qt Embedded -#endif -} - -static int my_system (const char *command) { - int pid, status; - - pid = fork(); - if (pid == -1) - return -1; - if (pid == 0) { - const char* shell = "/bin/sh"; - execl(shell, shell, "-c", command, (void *)0); - ::_exit(127); - } - do { - if (waitpid(pid, &status, 0) == -1) { - if (errno != EINTR) - return -1; - } else - return status; - } while(1); -} - - -DCOPClient *TDEApplication::dcopClient() -{ - if (s_DCOPClient) - return s_DCOPClient; - - s_DCOPClient = new DCOPClient(); - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("tde"); - if (args && args->isSet("dcopserver")) - { - s_DCOPClient->setServerAddress( args->getOption("dcopserver")); - } - if( kapp ) { - connect(s_DCOPClient, TQT_SIGNAL(attachFailed(const TQString &)), - kapp, TQT_SLOT(dcopFailure(const TQString &))); - connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(bool) ), - kapp, TQT_SLOT(dcopBlockUserInput(bool)) ); - } - else - s_dcopClientNeedsPostInit = true; - - DCOPClient::setMainClient( s_DCOPClient ); - return s_DCOPClient; -} - -void TDEApplication::dcopClientPostInit() -{ - if( s_dcopClientNeedsPostInit ) - { - s_dcopClientNeedsPostInit = false; - connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(bool) ), - TQT_SLOT(dcopBlockUserInput(bool)) ); - s_DCOPClient->bindToApp(); // Make sure we get events from the DCOPClient. - } -} - -void TDEApplication::dcopAutoRegistration() -{ - if (autoDcopRegistration) - { - ( void ) dcopClient(); - if( dcopClient()->appId().isEmpty()) - dcopClient()->registerAs(name()); - } -} - -void TDEApplication::disableAutoDcopRegistration() -{ - autoDcopRegistration = false; -} - -TDEConfig* TDEApplication::sessionConfig() -{ - if (pSessionConfig) - return pSessionConfig; - - // create an instance specific config object - pSessionConfig = new TDEConfig( sessionConfigName(), false, false); - return pSessionConfig; -} - -void TDEApplication::ref() -{ - d->refCount++; - //kdDebug() << "TDEApplication::ref() : refCount = " << d->refCount << endl; -} - -void TDEApplication::deref() -{ - d->refCount--; - //kdDebug() << "TDEApplication::deref() : refCount = " << d->refCount << endl; - if ( d->refCount <= 0 ) - quit(); -} - -KSessionManaged::KSessionManaged() -{ - sessionClients()->remove( this ); - sessionClients()->append( this ); -} - -KSessionManaged::~KSessionManaged() -{ - sessionClients()->remove( this ); -} - -bool KSessionManaged::saveState(TQSessionManager&) -{ - return true; -} - -bool KSessionManaged::commitData(TQSessionManager&) -{ - return true; -} - - -void TDEApplication::disableSessionManagement() { - bSessionManagement = false; -} - -void TDEApplication::enableSessionManagement() { - bSessionManagement = true; -#ifdef Q_WS_X11 - // Session management support in Qt/TDE is awfully broken. - // If konqueror disables session management right after its startup, - // and enables it later (preloading stuff), it won't be properly - // saved on session shutdown. - // I'm not actually sure why it doesn't work, but saveState() - // doesn't seem to be called on session shutdown, possibly - // because disabling session management after konqueror startup - // disabled it somehow. Forcing saveState() here for this application - // seems to fix it. - if( mySmcConnection ) { - SmcRequestSaveYourself( mySmcConnection, SmSaveLocal, False, - SmInteractStyleAny, - False, False ); - - // flush the request - IceFlush(SmcGetIceConnection(mySmcConnection)); - } -#endif -} - - -bool TDEApplication::requestShutDown( - ShutdownConfirm confirm, ShutdownType sdtype, ShutdownMode sdmode ) -{ -#ifdef Q_WS_X11 - TQApplication::syncX(); - /* use ksmserver's dcop interface if necessary */ - if ( confirm == ShutdownConfirmYes || - sdtype != ShutdownTypeDefault || - sdmode != ShutdownModeDefault ) - { - TQByteArray data; - TQDataStream arg(data, IO_WriteOnly); - arg << (int)confirm << (int)sdtype << (int)sdmode; - return dcopClient()->send( "ksmserver", "ksmserver", - "logout(int,int,int)", data ); - } - - if ( mySmcConnection ) { - // we already have a connection to the session manager, use it. - SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True, - SmInteractStyleAny, - confirm == ShutdownConfirmNo, True ); - - // flush the request - IceFlush(SmcGetIceConnection(mySmcConnection)); - return true; - } - - // open a temporary connection, if possible - - propagateSessionManager(); - TQCString smEnv = ::getenv("SESSION_MANAGER"); - if (smEnv.isEmpty()) - return false; - - if (! tmpSmcConnection) { - char cerror[256]; - char* myId = 0; - char* prevId = 0; - SmcCallbacks cb; - tmpSmcConnection = SmcOpenConnection( 0, 0, 1, 0, - 0, &cb, - prevId, - &myId, - 255, - cerror ); - ::free( myId ); // it was allocated by C - if (!tmpSmcConnection ) - return false; - } - - SmcRequestSaveYourself( tmpSmcConnection, SmSaveBoth, True, - SmInteractStyleAny, False, True ); - - // flush the request - IceFlush(SmcGetIceConnection(tmpSmcConnection)); - return true; -#else - // FIXME(E): Implement for Qt Embedded - return false; -#endif -} - -void TDEApplication::propagateSessionManager() -{ -#ifdef Q_WS_X11 - TQCString fName = TQFile::encodeName(locateLocal("socket", "KSMserver")); - TQCString display = ::getenv(DISPLAY); - // strip the screen number from the display - display.replace(TQRegExp("\\.[0-9]+$"), ""); - int i; - while( (i = display.find(':')) >= 0) - display[i] = '_'; - - fName += "_"+display; - TQCString smEnv = ::getenv("SESSION_MANAGER"); - bool check = smEnv.isEmpty(); - if ( !check && smModificationTime ) { - TQFileInfo info( fName ); - TQTime current = TQT_TQTIME_OBJECT(info.lastModified().time()); - check = current > *smModificationTime; - } - if ( check ) { - delete smModificationTime; - TQFile f( fName ); - if ( !f.open( IO_ReadOnly ) ) - return; - TQFileInfo info ( f ); - smModificationTime = new TQTime( TQT_TQTIME_OBJECT(info.lastModified().time()) ); - TQTextStream t(&f); - t.setEncoding( TQTextStream::Latin1 ); - TQString s = t.readLine(); - f.close(); - ::setenv( "SESSION_MANAGER", s.latin1(), true ); - } -#endif -} - -void TDEApplication::commitData( TQSessionManager& sm ) -{ - d->session_save = true; - bool canceled = false; - for (KSessionManaged* it = sessionClients()->first(); - it && !canceled; - it = sessionClients()->next() ) { - canceled = !it->commitData( sm ); - } - if ( canceled ) - sm.cancel(); - - if ( sm.allowsInteraction() ) { - TQWidgetList done; - TQWidgetList *list = TQApplication::topLevelWidgets(); - bool canceled = false; - TQWidget* w = list->first(); - while ( !canceled && w ) { - if ( !w->testWState( WState_ForceHide ) && !w->inherits("TDEMainWindow") ) { - TQCloseEvent e; - sendEvent( w, &e ); - canceled = !e.isAccepted(); - if ( !canceled ) - done.append( w ); - delete list; // one never knows... - list = TQApplication::topLevelWidgets(); - w = list->first(); - } else { - w = list->next(); - } - while ( w && done.containsRef( w ) ) - w = list->next(); - } - delete list; - } - - - if ( !bSessionManagement ) - sm.setRestartHint( TQSessionManager::RestartNever ); - else - sm.setRestartHint( TQSessionManager::RestartIfRunning ); - d->session_save = false; -} - -static void checkRestartVersion( TQSessionManager& sm ) -{ - Display* dpy = tqt_xdisplay(); - Atom type; - int format; - unsigned long nitems, after; - unsigned char* data; - if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy, "TDE_FULL_SESSION", False ), - 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) { - if( data != NULL ) - XFree( data ); - if( type == XA_STRING && format == 8 ) { // session set, check if TDE_SESSION_VERSION is not set (meaning KDE3) - if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy, "TDE_SESSION_VERSION", False ), - 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) { - if( data != NULL ) - XFree( data ); // KDE4 or newer - if( type == None ) - return; // we run in our native session, no need to wrap - } else { - return; // we run in our native session, no need to wrap - } - } - } - TQString wrapper = TDEStandardDirs::findExe( "trinity" ); - TQStringList restartCommand = sm.restartCommand(); - restartCommand.prepend( wrapper ); - sm.setRestartCommand( restartCommand ); -} - -void TDEApplication::saveState( TQSessionManager& sm ) -{ - d->session_save = true; -#ifdef Q_WS_X11 - static bool firstTime = true; - mySmcConnection = (SmcConn) sm.handle(); - - if ( !bSessionManagement ) { - sm.setRestartHint( TQSessionManager::RestartNever ); - d->session_save = false; - return; - } - else - sm.setRestartHint( TQSessionManager::RestartIfRunning ); - - if ( firstTime ) { - firstTime = false; - d->session_save = false; - return; // no need to save the state. - } - - // remove former session config if still existing, we want a new - // and fresh one. Note that we do not delete the config file here, - // this is done by the session manager when it executes the - // discard commands. In fact it would be harmful to remove the - // file here, as the session might be stored under a different - // name, meaning the user still might need it eventually. - if ( pSessionConfig ) { - delete pSessionConfig; - pSessionConfig = 0; - } - - // tell the session manager about our new lifecycle - TQStringList restartCommand = sm.restartCommand(); - - TQCString multiHead = getenv("TDE_MULTIHEAD"); - if (multiHead.lower() == "true") { - // if multihead is enabled, we save our -display argument so that - // we are restored onto the correct head... one problem with this - // is that the display is hard coded, which means we cannot restore - // to a different display (ie. if we are in a university lab and try, - // try to restore a multihead session, our apps could be started on - // someone else's display instead of our own) - TQCString displayname = getenv(DISPLAY); - if (! displayname.isNull()) { - // only store the command if we actually have a DISPLAY - // environment variable - restartCommand.append("-display"); - restartCommand.append(displayname); - } - sm.setRestartCommand( restartCommand ); - } - - checkRestartVersion( sm ); - - // finally: do session management - emit saveYourself(); // for compatibility - bool canceled = false; - for (KSessionManaged* it = sessionClients()->first(); - it && !canceled; - it = sessionClients()->next() ) { - canceled = !it->saveState( sm ); - } - - // if we created a new session config object, register a proper discard command - if ( pSessionConfig ) { - pSessionConfig->sync(); - TQStringList discard; - discard << "rm" << locateLocal("config", sessionConfigName()); - sm.setDiscardCommand( discard ); - } else { - sm.setDiscardCommand( TQStringList("") ); - } - - if ( canceled ) - sm.cancel(); -#else - // FIXME(E): Implement for Qt Embedded -#endif - d->session_save = false; -} - -bool TDEApplication::sessionSaving() const -{ - return d->session_save; -} - -void TDEApplication::startKdeinit() -{ -#ifndef Q_WS_WIN //TODO - TDEInstance inst( "starttdeinitlock" ); - TDELockFile lock( locateLocal( "tmp", "starttdeinitlock", &inst )); - if( lock.lock( TDELockFile::LockNoBlock ) != TDELockFile::LockOK ) { - lock.lock(); - DCOPClient cl; - if( cl.attach()) - return; // whoever held the lock has already started dcopserver - } - // Try to launch tdeinit. - TQString srv = TDEStandardDirs::findExe(TQString::fromLatin1("tdeinit")); - if (srv.isEmpty()) - srv = TDEStandardDirs::findExe(TQString::fromLatin1("tdeinit"), TDEGlobal::dirs()->kfsstnd_defaultbindir()); - if (srv.isEmpty()) - return; - if (kapp && (Tty != kapp->type())) - setOverrideCursor( tqwaitCursor ); - my_system(TQFile::encodeName(srv)+" --suicide"+" --new-startup"); - if (kapp && (Tty != kapp->type())) - restoreOverrideCursor(); -#endif -} - -void TDEApplication::dcopFailure(const TQString &msg) -{ - static int failureCount = 0; - failureCount++; - if (failureCount == 1) - { - startKdeinit(); - return; - } - if (failureCount == 2) - { -#ifdef Q_WS_WIN - TDEGlobal::config()->setGroup("General"); - if (TDEGlobal::config()->readBoolEntry("ignoreDCOPFailures", false)) - return; -#endif - TQString msgStr(i18n("There was an error setting up inter-process " - "communications for TDE. The message returned " - "by the system was:\n\n")); - msgStr += msg; - msgStr += i18n("\n\nPlease check that the \"dcopserver\" program is running!"); - - if (Tty != kapp->type()) - { - TQMessageBox::critical - ( - kapp->mainWidget(), - i18n("DCOP communications error (%1)").arg(kapp->caption()), - msgStr, - i18n("&OK") - ); - } - else - { - fprintf(stderr, "%s\n", msgStr.local8Bit().data()); - } - - return; - } -} - -static const TDECmdLineOptions qt_options[] = -{ - //FIXME: Check if other options are specific to Qt/X11 -#ifdef Q_WS_X11 - { "display ", I18N_NOOP("Use the X-server display 'displayname'"), 0}, -#else - { "display ", I18N_NOOP("Use the QWS display 'displayname'"), 0}, -#endif - { "session ", I18N_NOOP("Restore the application for the given 'sessionId'"), 0}, - { "cmap", I18N_NOOP("Causes the application to install a private color\nmap on an 8-bit display"), 0}, - { "ncols ", I18N_NOOP("Limits the number of colors allocated in the color\ncube on an 8-bit display, if the application is\nusing the TQApplication::ManyColor color\nspecification"), 0}, - { "nograb", I18N_NOOP("tells Qt to never grab the mouse or the keyboard"), 0}, - { "dograb", I18N_NOOP("running under a debugger can cause an implicit\n-nograb, use -dograb to override"), 0}, - { "sync", I18N_NOOP("switches to synchronous mode for debugging"), 0}, - { "fn", 0, 0}, - { "font ", I18N_NOOP("defines the application font"), 0}, - { "bg", 0, 0}, - { "background ", I18N_NOOP("sets the default background color and an\napplication palette (light and dark shades are\ncalculated)"), 0}, - { "fg", 0, 0}, - { "foreground ", I18N_NOOP("sets the default foreground color"), 0}, - { "btn", 0, 0}, - { "button ", I18N_NOOP("sets the default button color"), 0}, - { "name ", I18N_NOOP("sets the application name"), 0}, - { "title ", I18N_NOOP("sets the application title (caption)"), 0}, -#ifdef Q_WS_X11 - { "visual TrueColor", I18N_NOOP("forces the application to use a TrueColor visual on\nan 8-bit display"), 0}, - { "inputstyle <inputstyle>", I18N_NOOP("sets XIM (X Input Method) input style. Possible\nvalues are onthespot, overthespot, offthespot and\nroot"), 0 }, - { "im <XIM server>", I18N_NOOP("set XIM server"),0}, - { "noxim", I18N_NOOP("disable XIM"), 0 }, -#endif -#ifdef Q_WS_QWS - { "qws", I18N_NOOP("forces the application to run as QWS Server"), 0}, -#endif - { "reverse", I18N_NOOP("mirrors the whole layout of widgets"), 0}, - TDECmdLineLastOption -}; - -static const TDECmdLineOptions kde_options[] = -{ - { "caption <caption>", I18N_NOOP("Use 'caption' as name in the titlebar"), 0}, - { "icon <icon>", I18N_NOOP("Use 'icon' as the application icon"), 0}, - { "miniicon <icon>", I18N_NOOP("Use 'icon' as the icon in the titlebar"), 0}, - { "config <filename>", I18N_NOOP("Use alternative configuration file"), 0}, - { "dcopserver <server>", I18N_NOOP("Use the DCOP Server specified by 'server'"), 0}, - { "nocrashhandler", I18N_NOOP("Disable crash handler, to get core dumps"), 0}, - { "waitforwm", I18N_NOOP("Waits for a WM_NET compatible windowmanager"), 0}, - { "style <style>", I18N_NOOP("sets the application GUI style"), 0}, - { "geometry <geometry>", I18N_NOOP("sets the client geometry of the main widget - see man X for the argument format"), 0}, - { "smkey <sessionKey>", 0, 0}, // this option is obsolete and exists only to allow smooth upgrades from sessions - // saved under Qt 3.0.x -- Qt 3.1.x includes the session key now automatically in - // the session id (Simon) - TDECmdLineLastOption -}; - -void -TDEApplication::addCmdLineOptions() -{ - TDECmdLineArgs::addCmdLineOptions(qt_options, "Qt", "qt"); - TDECmdLineArgs::addCmdLineOptions(kde_options, "TDE", "tde"); -} - -void TDEApplication::parseCommandLine( ) -{ - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("tde"); - - if ( !args ) return; - - if (args->isSet("config")) - { - TQString config = TQString::fromLocal8Bit(args->getOption("config")); - setConfigName(config); - } - - if (args->isSet("style")) - { - - TQStringList plugins = TDEGlobal::dirs()->resourceDirs( "qtplugins" ); - TQStringList::Iterator itp = plugins.begin(); - while (itp != plugins.end()) { - addLibraryPath( *itp ); - ++itp; - } - - TQStringList styles = TQStyleFactory::keys(); - TQString reqStyle(args->getOption("style").lower()); - - TQStringList list = libraryPaths(); - TQStringList::Iterator it = list.begin(); - while( it != list.end() ) { - ++it; - } - - for (TQStringList::ConstIterator it = styles.begin(); it != styles.end(); ++it) { - if ((*it).lower() == reqStyle) - { - d->overrideStyle = *it; - break; - } - } - - if (d->overrideStyle.isEmpty()) - fprintf(stderr, "%s", TQString(i18n("The style %1 was not found\n").arg(reqStyle)).local8Bit().data()); - } - - if (args->isSet("caption")) - { - aCaption = TQString::fromLocal8Bit(args->getOption("caption")); - } - - if (args->isSet("miniicon")) - { - const char *tmp = args->getOption("miniicon"); - if (!aIconPixmap.pm.miniIcon) { - aIconPixmap.pm.miniIcon = new TQPixmap; - } - *aIconPixmap.pm.miniIcon = SmallIcon(tmp); - aMiniIconName = tmp; - } - - if (args->isSet("icon")) - { - const char *tmp = args->getOption("icon"); - if (!aIconPixmap.pm.icon) { - aIconPixmap.pm.icon = new TQPixmap; - } - *aIconPixmap.pm.icon = DesktopIcon( tmp ); - aIconName = tmp; - if (!aIconPixmap.pm.miniIcon) { - aIconPixmap.pm.miniIcon = new TQPixmap; - } - if (aIconPixmap.pm.miniIcon->isNull()) - { - *aIconPixmap.pm.miniIcon = SmallIcon( tmp ); - aMiniIconName = tmp; - } - } - - bool nocrashhandler = (getenv("TDE_DEBUG") != NULL); - if (!nocrashhandler && args->isSet("crashhandler")) - { - // set default crash handler / set emergency save function to nothing - TDECrash::setCrashHandler(TDECrash::defaultCrashHandler); - TDECrash::setEmergencySaveFunction(NULL); - - TDECrash::setApplicationName(TQString(args->appName())); - } - -#ifdef Q_WS_X11 - if ( args->isSet( "waitforwm" ) ) { - Atom type; - (void) desktop(); // trigger desktop creation, we need PropertyNotify events for the root window - int format; - unsigned long length, after; - unsigned char *data; - while ( XGetWindowProperty( tqt_xdisplay(), tqt_xrootwin(), atom_NetSupported, - 0, 1, false, AnyPropertyType, &type, &format, - &length, &after, &data ) != Success || !length ) { - if ( data ) - XFree( data ); - XEvent event; - XWindowEvent( tqt_xdisplay(), tqt_xrootwin(), PropertyChangeMask, &event ); - } - if ( data ) - XFree( data ); - } -#else - // FIXME(E): Implement for Qt Embedded -#endif - - if (args->isSet("geometry")) - { - d->geometry_arg = args->getOption("geometry"); - } - - if (args->isSet("smkey")) - { - d->sessionKey = args->getOption("smkey"); - } - -} - -TQString TDEApplication::geometryArgument() const -{ - return d->geometry_arg; -} - -TQPixmap TDEApplication::icon() const -{ - if( !aIconPixmap.pm.icon) { - aIconPixmap.pm.icon = new TQPixmap; - } - if( aIconPixmap.pm.icon->isNull()) { - *aIconPixmap.pm.icon = DesktopIcon( instanceName() ); - } - return *aIconPixmap.pm.icon; -} - -TQString TDEApplication::iconName() const -{ - return aIconName.isNull() ? (TQString)instanceName() : aIconName; -} - -TQPixmap TDEApplication::miniIcon() const -{ - if (!aIconPixmap.pm.miniIcon) { - aIconPixmap.pm.miniIcon = new TQPixmap; - } - if (aIconPixmap.pm.miniIcon->isNull()) { - *aIconPixmap.pm.miniIcon = SmallIcon( instanceName() ); - } - return *aIconPixmap.pm.miniIcon; -} - -TQString TDEApplication::miniIconName() const -{ - return aMiniIconName.isNull() ? (TQString)instanceName() : aMiniIconName; -} - -extern void kDebugCleanup(); - -TDEApplication::~TDEApplication() -{ - delete aIconPixmap.pm.miniIcon; - aIconPixmap.pm.miniIcon = 0L; - delete aIconPixmap.pm.icon; - aIconPixmap.pm.icon = 0L; - delete d->m_KAppDCOPInterface; - - // First call the static deleters and then call KLibLoader::cleanup() - // The static deleters may delete libraries for which they need KLibLoader. - // KLibLoader will take care of the remaining ones. - TDEGlobal::deleteStaticDeleters(); - KLibLoader::cleanUp(); - - delete smw; - - // close down IPC - delete s_DCOPClient; - s_DCOPClient = 0L; - - TDEProcessController::deref(); - -#ifdef Q_WS_X11 - if ( d->oldXErrorHandler != NULL ) - XSetErrorHandler( d->oldXErrorHandler ); - if ( d->oldXIOErrorHandler != NULL ) - XSetIOErrorHandler( d->oldXIOErrorHandler ); - if ( d->oldIceIOErrorHandler != NULL ) - IceSetIOErrorHandler( d->oldIceIOErrorHandler ); -#endif - - delete d; - KApp = 0; - -#ifdef Q_WS_X11 - mySmcConnection = 0; - delete smModificationTime; - smModificationTime = 0; - - // close the temporary smc connection - if (tmpSmcConnection) { - SmcCloseConnection( tmpSmcConnection, 0, 0 ); - tmpSmcConnection = 0; - } -#else - // FIXME(E): Implement for Qt Embedded -#endif -} - - -#ifdef Q_WS_X11 -class KAppX11HackWidget: public TQWidget -{ -public: - bool publicx11Event( XEvent * e) { return x11Event( e ); } -}; -#endif - -#if defined(Q_WS_X11) && defined(COMPOSITE) -bool TDEApplication::isCompositionManagerAvailable() { - bool have_manager = false; - const char *home; - struct passwd *p; - p = getpwuid(getuid()); - if (p) - home = p->pw_dir; - else - home = getenv("HOME"); - - char *filename; - const char *configfile = "/.kompmgr.available"; - int n = strlen(home)+strlen(configfile)+1; - filename = (char*)malloc(n*sizeof(char)); - memset(filename,0,n); - strcat(filename, home); - strcat(filename, configfile); - - // Now that we did all that by way of introduction...read the file! - FILE *pFile; - pFile = fopen(filename, "r"); - if (pFile) { - have_manager = true; - fclose(pFile); - } - - free(filename); - filename = NULL; - - return have_manager; -} - -bool TDEApplication::detectCompositionManagerAvailable(bool force_available, bool available) { - bool compositing_manager_available; - if (force_available) { - compositing_manager_available = available; - } - else { - // See if compositing has been enabled - TDECmdLineArgs *qtargs = TDECmdLineArgs::parsedArgs("qt"); - char *displayname = 0; - if ( qtargs->isSet("display")) - displayname = qtargs->getOption( "display" ).data(); - - Display *dpy = XOpenDisplay( displayname ); - - x11_composite_error_generated = false; - compositing_manager_available = false; - XSetErrorHandler(x11_error); - if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode, &composite_event, &composite_error)) { - XSetErrorHandler(NULL); - compositing_manager_available = false; - } - else { - if (available) { // FIXME This variable does double duty to avoid breaking the ABI for R14.0. In reality it should be called perform_deep_check - Window root_window = XDefaultRootWindow(dpy); - XCompositeRedirectSubwindows(dpy, root_window, CompositeRedirectManual); - XSync(dpy, false); - if (x11_composite_error_generated == true) { - compositing_manager_available = true; - } - else { - XCompositeUnredirectSubwindows(dpy, root_window, CompositeRedirectManual); - compositing_manager_available = false; - } - XSetErrorHandler(NULL); - XCloseDisplay(dpy); - } - else { - compositing_manager_available = true; - } - } - } - - const char *home; - struct passwd *p; - p = getpwuid(getuid()); - if (p) - home = p->pw_dir; - else - home = getenv("HOME"); - - char *filename; - const char *configfile = "/.kompmgr.available"; - int n = strlen(home)+strlen(configfile)+1; - filename = (char*)malloc(n*sizeof(char)); - memset(filename,0,n); - strcat(filename, home); - strcat(filename, configfile); - - /* now that we did all that by way of introduction...create or remove the file! */ - if (compositing_manager_available) { - FILE *pFile; - char buffer[255]; - sprintf(buffer, "available"); - pFile = fopen(filename, "w"); - if (pFile) { - fwrite(buffer,1,strlen(buffer), pFile); - fclose(pFile); - } - } - else { - unlink(filename); - } - - free(filename); - filename = NULL; - - return compositing_manager_available; -} - -Display* TDEApplication::openX11RGBADisplay() { - TDECmdLineArgs *qtargs = TDECmdLineArgs::parsedArgs("qt"); - char *display = 0; - if ( qtargs->isSet("display")) - display = qtargs->getOption( "display" ).data(); - - Display *dpy = XOpenDisplay( display ); - if ( !dpy ) { - kdError() << "cannot connect to X server " << display << endl; - exit( 1 ); - } - - return dpy; -} - -Qt::HANDLE TDEApplication::getX11RGBAVisual(Display *dpy) { - getX11RGBAInformation(dpy); - if (TDEApplication::isCompositionManagerAvailable() == true) { - return argb_x11_visual; - } - else { - return (Qt::HANDLE)NULL; - } -} - -Qt::HANDLE TDEApplication::getX11RGBAColormap(Display *dpy) { - getX11RGBAInformation(dpy); - if (TDEApplication::isCompositionManagerAvailable() == true) { - return argb_x11_colormap; - } - else { - return (Qt::HANDLE)NULL; - } -} - -bool TDEApplication::isX11CompositionAvailable() { - return (argb_visual & isCompositionManagerAvailable()); -} - -void TDEApplication::getX11RGBAInformation(Display *dpy) { - if ( !dpy ) { - argb_visual = false; - return; - } - - int screen = DefaultScreen( dpy ); - Colormap colormap = 0; - Visual *visual = 0; - int event_base, error_base; - - if ( XRenderQueryExtension( dpy, &event_base, &error_base ) ) { - int nvi; - XVisualInfo templ; - templ.screen = screen; - templ.depth = 32; - templ.c_class = TrueColor; - XVisualInfo *xvi = XGetVisualInfo( dpy, VisualScreenMask | VisualDepthMask - | VisualClassMask, &templ, &nvi ); - - for ( int i = 0; i < nvi; i++ ) { - XRenderPictFormat *format = XRenderFindVisualFormat( dpy, xvi[i].visual ); - if ( format->type == PictTypeDirect && format->direct.alphaMask ) { - visual = xvi[i].visual; - colormap = XCreateColormap( dpy, RootWindow( dpy, screen ), visual, AllocNone ); - kdDebug() << "found visual with alpha support" << endl; - argb_visual = true; - break; - } - } - } - - if( argb_visual ) { - argb_x11_visual = Qt::HANDLE( visual ); - argb_x11_colormap = Qt::HANDLE( colormap ); - argb_visual = true; - return; - } - argb_visual = false; - return; -} -#else -void TDEApplication::getX11RGBAInformation(Display *dpy) { -} - -bool TDEApplication::isCompositionManagerAvailable() { - return false; -} - -bool TDEApplication::detectCompositionManagerAvailable(bool force_available) { - const char *home; - struct passwd *p; - p = getpwuid(getuid()); - if (p) - home = p->pw_dir; - else - home = getenv("HOME"); - - char *filename; - const char *configfile = "/.kompmgr.available"; - int n = strlen(home)+strlen(configfile)+1; - filename = (char*)malloc(n*sizeof(char)); - memset(filename,0,n); - strcat(filename, home); - strcat(filename, configfile); - - /* now that we did all that by way of introduction...create or remove the file! */ - if (force_available) { - FILE *pFile; - char buffer[255]; - sprintf(buffer, "available"); - pFile = fopen(filename, "w"); - if (pFile) { - fwrite(buffer,1,strlen(buffer), pFile); - fclose(pFile); - } - } - else { - unlink(filename); - } - - free(filename); - filename = NULL; - - return false; -} - -Display* TDEApplication::openX11RGBADisplay() { - return 0; -} - -Qt::HANDLE TDEApplication::getX11RGBAVisual(char *display) { - return 0; -} - -Qt::HANDLE TDEApplication::getX11RGBAColormap(char *display) { - return 0; -} - -bool TDEApplication::isX11CompositionAvailable() { - return false; -} - -TDEApplication TDEApplication::KARGBApplication( bool allowStyles ) { - return TDEApplication::TDEApplication(allowStyles, true); -} -#endif - -static bool kapp_block_user_input = false; - -void TDEApplication::dcopBlockUserInput( bool b ) -{ - kapp_block_user_input = b; -} - -#ifdef Q_WS_X11 -bool TDEApplication::x11EventFilter( XEvent *_event ) -{ - switch ( _event->type ) { - case ClientMessage: - { -#if KDE_IS_VERSION( 3, 90, 90 ) -#warning This should be already in Qt, check. -#endif - // Workaround for focus stealing prevention not working when dragging e.g. text from KWrite - // to KDesktop -> the dialog asking for filename doesn't get activated. This is because - // Qt-3.2.x doesn't have concept of tqt_x_user_time at all, and Qt-3.3.0b1 passes the timestamp - // in the XdndDrop message in incorrect field (and doesn't update tqt_x_user_time either). - // Patch already sent, future Qt version should have this fixed. - if( _event->xclient.message_type == kde_xdnd_drop ) - { // if the message is XdndDrop - if( _event->xclient.data.l[ 1 ] == 1 << 24 // and it's broken the way it's in Qt-3.2.x - && _event->xclient.data.l[ 2 ] == 0 - && _event->xclient.data.l[ 4 ] == 0 - && _event->xclient.data.l[ 3 ] != 0 ) - { - if( GET_QT_X_USER_TIME() == 0 - || NET::timestampCompare( _event->xclient.data.l[ 3 ], GET_QT_X_USER_TIME() ) > 0 ) - { // and the timestamp looks reasonable - SET_QT_X_USER_TIME(_event->xclient.data.l[ 3 ]); // update our tqt_x_user_time from it - } - } - else // normal DND, only needed until Qt updates tqt_x_user_time from XdndDrop - { - if( GET_QT_X_USER_TIME() == 0 - || NET::timestampCompare( _event->xclient.data.l[ 2 ], GET_QT_X_USER_TIME() ) > 0 ) - { // the timestamp looks reasonable - SET_QT_X_USER_TIME(_event->xclient.data.l[ 2 ]); // update our tqt_x_user_time from it - } - } - } - } - default: break; - } - - if ( kapp_block_user_input ) { - switch ( _event->type ) { - case ButtonPress: - case ButtonRelease: - case XKeyPress: - case XKeyRelease: - case MotionNotify: - case EnterNotify: - case LeaveNotify: - return true; - default: - break; - } - } - - if (x11Filter) { - for (TQWidget *w=x11Filter->first(); w; w=x11Filter->next()) { - if (((KAppX11HackWidget*) w)->publicx11Event(_event)) - return true; - } - } - - if ((_event->type == ClientMessage) && - (_event->xclient.message_type == kipcCommAtom)) - { - XClientMessageEvent *cme = (XClientMessageEvent *) _event; - - int id = cme->data.l[0]; - int arg = cme->data.l[1]; - if ((id < 32) && (kipcEventMask & (1 << id))) - { - switch (id) - { - case KIPC::StyleChanged: - TDEGlobal::config()->reparseConfiguration(); - tdedisplaySetStyle(); - break; - - case KIPC::ToolbarStyleChanged: - TDEGlobal::config()->reparseConfiguration(); - if (useStyles) - emit toolbarAppearanceChanged(arg); - break; - - case KIPC::PaletteChanged: - TDEGlobal::config()->reparseConfiguration(); - tdedisplaySetPalette(); - break; - - case KIPC::FontChanged: - TDEGlobal::config()->reparseConfiguration(); - TDEGlobalSettings::rereadFontSettings(); - tdedisplaySetFont(); - break; - - case KIPC::BackgroundChanged: - emit backgroundChanged(arg); - break; - - case KIPC::SettingsChanged: - TDEGlobal::config()->reparseConfiguration(); - if (arg == SETTINGS_PATHS) - TDEGlobalSettings::rereadPathSettings(); - else if (arg == SETTINGS_MOUSE) - TDEGlobalSettings::rereadMouseSettings(); - propagateSettings((SettingsCategory)arg); - break; - - case KIPC::IconChanged: - TQPixmapCache::clear(); - TDEGlobal::config()->reparseConfiguration(); - TDEGlobal::instance()->newIconLoader(); - emit updateIconLoaders(); - emit iconChanged(arg); - break; - - case KIPC::ClipboardConfigChanged: - TDEClipboardSynchronizer::newConfiguration(arg); - break; - - case KIPC::BlockShortcuts: - TDEGlobalAccel::blockShortcuts(arg); - emit kipcMessage(id, arg); // some apps may do additional things - break; - } - } - else if (id >= 32) - { - emit kipcMessage(id, arg); - } - return true; - } - return false; -} -#endif // Q_WS_X11 - -void TDEApplication::updateUserTimestamp( unsigned long time ) -{ -#if defined Q_WS_X11 - if( time == 0 ) - { // get current X timestamp - Window w = XCreateSimpleWindow( tqt_xdisplay(), tqt_xrootwin(), 0, 0, 1, 1, 0, 0, 0 ); - XSelectInput( tqt_xdisplay(), w, PropertyChangeMask ); - unsigned char data[ 1 ]; - XChangeProperty( tqt_xdisplay(), w, XA_ATOM, XA_ATOM, 8, PropModeAppend, data, 1 ); - XEvent ev; - XWindowEvent( tqt_xdisplay(), w, PropertyChangeMask, &ev ); - time = ev.xproperty.time; - XDestroyWindow( tqt_xdisplay(), w ); - } - if( GET_QT_X_USER_TIME() == 0 - || NET::timestampCompare( time, GET_QT_X_USER_TIME() ) > 0 ) // check time > tqt_x_user_time - SET_QT_X_USER_TIME(time); -#endif -} - -unsigned long TDEApplication::userTimestamp() const -{ -#if defined Q_WS_X11 - return GET_QT_X_USER_TIME(); -#else - return 0; -#endif -} - -void TDEApplication::updateRemoteUserTimestamp( const TQCString& dcopId, unsigned long time ) -{ -#if defined Q_WS_X11 - if( time == 0 ) - time = GET_QT_X_USER_TIME(); - DCOPRef( dcopId, "MainApplication-Interface" ).call( "updateUserTimestamp", time ); -#endif -} - -void TDEApplication::invokeEditSlot( const char *slot ) -{ - TQObject *object = TQT_TQOBJECT(focusWidget()); - if( !object ) - return; - - TQMetaObject *meta = object->metaObject(); - - int idx = meta->findSlot( slot + 1, true ); - if( idx < 0 ) - return; - - object->tqt_invoke( idx, 0 ); -} - -void TDEApplication::addKipcEventMask(int id) -{ - if (id >= 32) - { - kdDebug(101) << "Cannot use KIPC event mask for message IDs >= 32\n"; - return; - } - kipcEventMask |= (1 << id); -} - -void TDEApplication::removeKipcEventMask(int id) -{ - if (id >= 32) - { - kdDebug(101) << "Cannot use KIPC event mask for message IDs >= 32\n"; - return; - } - kipcEventMask &= ~(1 << id); -} - -void TDEApplication::enableStyles() -{ - if (!useStyles) - { - useStyles = true; - applyGUIStyle(); - } -} - -void TDEApplication::disableStyles() -{ - useStyles = false; -} - -void TDEApplication::applyGUIStyle() -{ - if ( !useStyles ) return; - - TDEConfigGroup pConfig (TDEGlobal::config(), "General"); - TQString defaultStyle = TDEStyle::defaultStyle(); - TQString styleStr = pConfig.readEntry("widgetStyle", defaultStyle); - - if (d->overrideStyle.isEmpty()) { - // ### add check whether we already use the correct style to return then - // (workaround for Qt misbehavior to avoid double style initialization) - - TQStyle* sp = TQStyleFactory::create( styleStr ); - - // If there is no default style available, try falling back any available style - if ( !sp && styleStr != defaultStyle) - sp = TQStyleFactory::create( defaultStyle ); - if ( !sp ) - sp = TQStyleFactory::create( *(TQStyleFactory::keys().begin()) ); - setStyle(sp); - } - else - setStyle(d->overrideStyle); - // Reread palette from config file. - tdedisplaySetPalette(); -} - -TQString TDEApplication::caption() const -{ - // Caption set from command line ? - if( !aCaption.isNull() ) - return aCaption; - else - // We have some about data ? - if ( TDEGlobal::instance()->aboutData() ) - return TDEGlobal::instance()->aboutData()->programName(); - else - // Last resort : application name - return name(); -} - - -// -// 1999-09-20: Espen Sand -// An attempt to simplify consistent captions. -// -TQString TDEApplication::makeStdCaption( const TQString &userCaption, - bool withAppName, bool modified ) const -{ - TQString s = userCaption.isEmpty() ? caption() : userCaption; - - // If the document is modified, add '[modified]'. - if (modified) - s += TQString::fromUtf8(" [") + i18n("modified") + TQString::fromUtf8("]"); - - if ( !userCaption.isEmpty() ) { - // Add the application name if: - // User asked for it, it's not a duplication and the app name (caption()) is not empty - if ( withAppName && !caption().isNull() && !userCaption.endsWith(caption()) ) - s += TQString::fromUtf8(" - ") + caption(); - } - - return s; -} - -TQPalette TDEApplication::createApplicationPalette() -{ - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "General" ); - return createApplicationPalette( config, TDEGlobalSettings::contrast() ); -} - -TQPalette TDEApplication::createApplicationPalette( TDEConfig *config, int contrast_ ) -{ - TQColor trinity4Background( 239, 239, 239 ); - TQColor trinity4Blue( 103,141,178 ); - - TQColor trinity4Button; - if ( TQPixmap::defaultDepth() > 8 ) - trinity4Button.setRgb( 221, 223, 228 ); - else - trinity4Button.setRgb( 220, 220, 220 ); - - TQColor trinity4Link( 0, 0, 238 ); - TQColor trinity4VisitedLink( 82, 24, 139 ); - - TQColor background = config->readColorEntry( "background", &trinity4Background ); - TQColor foreground = config->readColorEntry( "foreground", tqblackptr ); - TQColor button = config->readColorEntry( "buttonBackground", &trinity4Button ); - TQColor buttonText = config->readColorEntry( "buttonForeground", tqblackptr ); - TQColor highlight = config->readColorEntry( "selectBackground", &trinity4Blue ); - TQColor highlightedText = config->readColorEntry( "selectForeground", tqwhiteptr ); - TQColor base = config->readColorEntry( "windowBackground", tqwhiteptr ); - TQColor baseText = config->readColorEntry( "windowForeground", tqblackptr ); - TQColor link = config->readColorEntry( "linkColor", &trinity4Link ); - TQColor visitedLink = config->readColorEntry( "visitedLinkColor", &trinity4VisitedLink ); - - int highlightVal, lowlightVal; - highlightVal = 100 + (2*contrast_+4)*16/10; - lowlightVal = 100 + (2*contrast_+4)*10; - - TQColor disfg = foreground; - - int h, s, v; - disfg.hsv( &h, &s, &v ); - if (v > 128) - // dark bg, light fg - need a darker disabled fg - disfg = disfg.dark(lowlightVal); - else if (disfg != Qt::black) - // light bg, dark fg - need a lighter disabled fg - but only if !black - disfg = disfg.light(highlightVal); - else - // black fg - use darkgray disabled fg - disfg = Qt::darkGray; - - - TQColorGroup disabledgrp(disfg, background, - background.light(highlightVal), - background.dark(lowlightVal), - background.dark(120), - background.dark(120), base); - - TQColorGroup colgrp(foreground, background, background.light(highlightVal), - background.dark(lowlightVal), - background.dark(120), - baseText, base); - - int inlowlightVal = lowlightVal-25; - if(inlowlightVal < 120) - inlowlightVal = 120; - - colgrp.setColor(TQColorGroup::Highlight, highlight); - colgrp.setColor(TQColorGroup::HighlightedText, highlightedText); - colgrp.setColor(TQColorGroup::Button, button); - colgrp.setColor(TQColorGroup::ButtonText, buttonText); - colgrp.setColor(TQColorGroup::Midlight, background.light(110)); - colgrp.setColor(TQColorGroup::Link, link); - colgrp.setColor(TQColorGroup::LinkVisited, visitedLink); - - disabledgrp.setColor(TQColorGroup::Button, button); - - TQColor disbtntext = buttonText; - disbtntext.hsv( &h, &s, &v ); - if (v > 128) - // dark button, light buttonText - need a darker disabled buttonText - disbtntext = disbtntext.dark(lowlightVal); - else if (disbtntext != Qt::black) - // light buttonText, dark button - need a lighter disabled buttonText - but only if !black - disbtntext = disbtntext.light(highlightVal); - else - // black button - use darkgray disabled buttonText - disbtntext = Qt::darkGray; - - disabledgrp.setColor(TQColorGroup::ButtonText, disbtntext); - disabledgrp.setColor(TQColorGroup::Midlight, background.light(110)); - disabledgrp.setColor(TQColorGroup::Highlight, highlight.dark(120)); - disabledgrp.setColor(TQColorGroup::Link, link); - disabledgrp.setColor(TQColorGroup::LinkVisited, visitedLink); - - return TQPalette(colgrp, disabledgrp, colgrp); -} - - -void TDEApplication::tdedisplaySetPalette() -{ -#ifdef Q_WS_MACX - //Can I have this on other platforms, please!? --Sam - { - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "General" ); - bool do_not_set_palette = FALSE; - if(config->readBoolEntry("nopaletteChange", &do_not_set_palette)) - return; - } -#endif - TQApplication::setPalette( createApplicationPalette(), true); - emit tdedisplayPaletteChanged(); - emit appearanceChanged(); -} - - -void TDEApplication::tdedisplaySetFont() -{ - TQApplication::setFont(TDEGlobalSettings::generalFont(), true); - TQApplication::setFont(TDEGlobalSettings::menuFont(), true, TQMENUBAR_OBJECT_NAME_STRING); - TQApplication::setFont(TDEGlobalSettings::menuFont(), true, TQPOPUPMENU_OBJECT_NAME_STRING); - TQApplication::setFont(TDEGlobalSettings::menuFont(), true, "TDEPopupTitle"); - - // "patch" standard TQStyleSheet to follow our fonts - TQStyleSheet* sheet = TQStyleSheet::defaultSheet(); - sheet->item ("pre")->setFontFamily (TDEGlobalSettings::fixedFont().family()); - sheet->item ("code")->setFontFamily (TDEGlobalSettings::fixedFont().family()); - sheet->item ("tt")->setFontFamily (TDEGlobalSettings::fixedFont().family()); - - emit tdedisplayFontChanged(); - emit appearanceChanged(); -} - - -void TDEApplication::tdedisplaySetStyle() -{ - if (useStyles) - { - applyGUIStyle(); - emit tdedisplayStyleChanged(); - emit appearanceChanged(); - } -} - - -void TDEApplication::propagateSettings(SettingsCategory arg) -{ - TDEConfigBase* config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "KDE" ); - -#ifdef QT_HAVE_MAX_IMAGE_SIZE - TQSize maxImageSize(4096, 4096); - maxImageSize = config->readSizeEntry("MaxImageSize", &maxImageSize); - TQImage::setMaxImageSize(maxImageSize); -#endif - - int num = config->readNumEntry("CursorBlinkRate", TQApplication::cursorFlashTime()); - if ((num != 0) && (num < 200)) - num = 200; - if (num > 2000) - num = 2000; - TQApplication::setCursorFlashTime(num); - num = config->readNumEntry("DoubleClickInterval", TQApplication::doubleClickInterval()); - TQApplication::setDoubleClickInterval(num); - num = config->readNumEntry("StartDragTime", TQApplication::startDragTime()); - TQApplication::setStartDragTime(num); - num = config->readNumEntry("StartDragDist", TQApplication::startDragDistance()); - TQApplication::setStartDragDistance(num); - num = config->readNumEntry("WheelScrollLines", TQApplication::wheelScrollLines()); - TQApplication::setWheelScrollLines(num); - - bool b = config->readBoolEntry("EffectAnimateMenu", false); - TQApplication::setEffectEnabled( Qt::UI_AnimateMenu, b); - b = config->readBoolEntry("EffectFadeMenu", false); - TQApplication::setEffectEnabled( Qt::UI_FadeMenu, b); - b = config->readBoolEntry("EffectAnimateCombo", false); - TQApplication::setEffectEnabled( Qt::UI_AnimateCombo, b); - b = config->readBoolEntry("EffectAnimateTooltip", false); - TQApplication::setEffectEnabled( Qt::UI_AnimateTooltip, b); - b = config->readBoolEntry("EffectFadeTooltip", false); - TQApplication::setEffectEnabled( Qt::UI_FadeTooltip, b); - b = !config->readBoolEntry("EffectNoTooltip", false); - TQToolTip::setGloballyEnabled( b ); - - emit settingsChanged(arg); -} - -void TDEApplication::installKDEPropertyMap() -{ -#ifndef QT_NO_SQL - static bool installed = false; - if (installed) return; - installed = true; - /** - * If you are adding a widget that was missing please - * make sure to also add it to TDEConfigDialogManager's retrieveSettings() - * function. - * Thanks. - */ - // TQSqlPropertyMap takes ownership of the new default map. - TQSqlPropertyMap *kdeMap = new TQSqlPropertyMap; - kdeMap->insert( "KColorButton", "color" ); - kdeMap->insert( "KComboBox", "currentItem" ); - kdeMap->insert( "KDatePicker", "date" ); - kdeMap->insert( "KDateWidget", "date" ); - kdeMap->insert( "KDateTimeWidget", "dateTime" ); - kdeMap->insert( "KEditListBox", "items" ); - kdeMap->insert( "TDEFontCombo", "family" ); - kdeMap->insert( "TDEFontRequester", "font" ); - kdeMap->insert( "TDEFontChooser", "font" ); - kdeMap->insert( "KHistoryCombo", "currentItem" ); - kdeMap->insert( "TDEListBox", "currentItem" ); - kdeMap->insert( "KLineEdit", "text" ); - kdeMap->insert( "KRestrictedLine", "text" ); - kdeMap->insert( "KSqueezedTextLabel", "text" ); - kdeMap->insert( "KTextBrowser", "source" ); - kdeMap->insert( "KTextEdit", "text" ); - kdeMap->insert( "KURLRequester", "url" ); - kdeMap->insert( "KPasswordEdit", "password" ); - kdeMap->insert( "KIntNumInput", "value" ); - kdeMap->insert( "KIntSpinBox", "value" ); - kdeMap->insert( "KDoubleNumInput", "value" ); - // Temp til fixed in QT then enable ifdef with the correct version num - kdeMap->insert( TQGROUPBOX_OBJECT_NAME_STRING, "checked" ); - kdeMap->insert( TQTABWIDGET_OBJECT_NAME_STRING, "currentPage" ); - TQSqlPropertyMap::installDefaultMap( kdeMap ); -#endif -} - -void TDEApplication::invokeHelp( const TQString& anchor, - const TQString& _appname) const -{ - return invokeHelp( anchor, _appname, "" ); -} - -#ifndef Q_WS_WIN -// for win32 we're using simple help tools like Qt Assistant, -// see kapplication_win.cpp -void TDEApplication::invokeHelp( const TQString& anchor, - const TQString& _appname, - const TQCString& startup_id ) const -{ - TQString url; - TQString appname; - if (_appname.isEmpty()) - appname = name(); - else - appname = _appname; - - if (!anchor.isEmpty()) - url = TQString("help:/%1?anchor=%2").arg(appname).arg(anchor); - else - url = TQString("help:/%1/index.html").arg(appname); - - TQString error; - if ( !dcopClient()->isApplicationRegistered("khelpcenter") ) - { - if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, startup_id, false)) - { - if (Tty != kapp->type()) - TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Help Center"), - i18n("Could not launch the TDE Help Center:\n\n%1").arg(error), i18n("&OK")); - else - kdWarning() << "Could not launch help:\n" << error << endl; - return; - } - } - else - DCOPRef( "khelpcenter", "KHelpCenterIface" ).send( "openUrl", url, startup_id ); -} -#endif - -void TDEApplication::invokeHTMLHelp( const TQString& _filename, const TQString& topic ) const -{ - kdWarning() << "invoking HTML help is deprecated! use docbook and invokeHelp!\n"; - - TQString filename; - - if( _filename.isEmpty() ) - filename = TQString(name()) + "/index.html"; - else - filename = _filename; - - TQString url; - if (!topic.isEmpty()) - url = TQString("help:/%1#%2").arg(filename).arg(topic); - else - url = TQString("help:/%1").arg(filename); - - TQString error; - if ( !dcopClient()->isApplicationRegistered("khelpcenter") ) - { - if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, "", false)) - { - if (Tty != kapp->type()) - TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Help Center"), - i18n("Could not launch the TDE Help Center:\n\n%1").arg(error), i18n("&OK")); - else - kdWarning() << "Could not launch help:\n" << error << endl; - return; - } - } - else - DCOPRef( "khelpcenter", "KHelpCenterIface" ).send( "openUrl", url ); -} - - -void TDEApplication::invokeMailer(const TQString &address, const TQString &subject) -{ - return invokeMailer(address,subject,""); -} - -void TDEApplication::invokeMailer(const TQString &address, const TQString &subject, const TQCString& startup_id) -{ - invokeMailer(address, TQString::null, TQString::null, subject, TQString::null, TQString::null, - TQStringList(), startup_id ); -} - -void TDEApplication::invokeMailer(const KURL &mailtoURL) -{ - return invokeMailer( mailtoURL, "" ); -} - -void TDEApplication::invokeMailer(const KURL &mailtoURL, const TQCString& startup_id ) -{ - return invokeMailer( mailtoURL, startup_id, false); -} - -void TDEApplication::invokeMailer(const KURL &mailtoURL, const TQCString& startup_id, bool allowAttachments ) -{ - TQString address = KURL::decode_string(mailtoURL.path()), subject, cc, bcc, body; - TQStringList queries = TQStringList::split('&', mailtoURL.query().mid(1)); - TQStringList attachURLs; - for (TQStringList::Iterator it = queries.begin(); it != queries.end(); ++it) - { - TQString q = (*it).lower(); - if (q.startsWith("subject=")) - subject = KURL::decode_string((*it).mid(8)); - else - if (q.startsWith("cc=")) - cc = cc.isEmpty()? KURL::decode_string((*it).mid(3)): cc + ',' + KURL::decode_string((*it).mid(3)); - else - if (q.startsWith("bcc=")) - bcc = bcc.isEmpty()? KURL::decode_string((*it).mid(4)): bcc + ',' + KURL::decode_string((*it).mid(4)); - else - if (q.startsWith("body=")) - body = KURL::decode_string((*it).mid(5)); - else - if (allowAttachments && q.startsWith("attach=")) - attachURLs.push_back(KURL::decode_string((*it).mid(7))); - else - if (allowAttachments && q.startsWith("attachment=")) - attachURLs.push_back(KURL::decode_string((*it).mid(11))); - else - if (q.startsWith("to=")) - address = address.isEmpty()? KURL::decode_string((*it).mid(3)): address + ',' + KURL::decode_string((*it).mid(3)); - } - - invokeMailer( address, cc, bcc, subject, body, TQString::null, attachURLs, startup_id ); -} - -void TDEApplication::invokeMailer(const TQString &to, const TQString &cc, const TQString &bcc, - const TQString &subject, const TQString &body, - const TQString & messageFile, const TQStringList &attachURLs) -{ - return invokeMailer(to,cc,bcc,subject,body,messageFile,attachURLs,""); -} - -#ifndef Q_WS_WIN -// on win32, for invoking browser we're using win32 API -// see kapplication_win.cpp - -static TQStringList splitEmailAddressList( const TQString & aStr ) -{ - // This is a copy of KPIM::splitEmailAddrList(). - // Features: - // - always ignores quoted characters - // - ignores everything (including parentheses and commas) - // inside quoted strings - // - supports nested comments - // - ignores everything (including double quotes and commas) - // inside comments - - TQStringList list; - - if (aStr.isEmpty()) - return list; - - TQString addr; - uint addrstart = 0; - int commentlevel = 0; - bool insidequote = false; - - for (uint index=0; index<aStr.length(); index++) { - // the following conversion to latin1 is o.k. because - // we can safely ignore all non-latin1 characters - switch (aStr[index].latin1()) { - case '"' : // start or end of quoted string - if (commentlevel == 0) - insidequote = !insidequote; - break; - case '(' : // start of comment - if (!insidequote) - commentlevel++; - break; - case ')' : // end of comment - if (!insidequote) { - if (commentlevel > 0) - commentlevel--; - else { - //kdDebug() << "Error in address splitting: Unmatched ')'" - // << endl; - return list; - } - } - break; - case '\\' : // quoted character - index++; // ignore the quoted character - break; - case ',' : - if (!insidequote && (commentlevel == 0)) { - addr = aStr.mid(addrstart, index-addrstart); - if (!addr.isEmpty()) - list += addr.simplifyWhiteSpace(); - addrstart = index+1; - } - break; - } - } - // append the last address to the list - if (!insidequote && (commentlevel == 0)) { - addr = aStr.mid(addrstart, aStr.length()-addrstart); - if (!addr.isEmpty()) - list += addr.simplifyWhiteSpace(); - } - //else - // kdDebug() << "Error in address splitting: " - // << "Unexpected end of address list" - // << endl; - - return list; -} - -void TDEApplication::invokeMailer(const TQString &_to, const TQString &_cc, const TQString &_bcc, - const TQString &subject, const TQString &body, - const TQString & /*messageFile TODO*/, const TQStringList &attachURLs, - const TQCString& startup_id ) -{ - TDEConfig config("emaildefaults"); - - config.setGroup("Defaults"); - TQString group = config.readEntry("Profile","Default"); - - config.setGroup( TQString("PROFILE_%1").arg(group) ); - TQString command = config.readPathEntry("EmailClient"); - - TQString to, cc, bcc; - if (command.isEmpty() || command == TQString::fromLatin1("kmail") - || command.endsWith("/kmail")) - { - command = TQString::fromLatin1("kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t"); - if ( !_to.isEmpty() ) - { - // put the whole address lists into RFC2047 encoded blobs; technically - // this isn't correct, but KMail understands it nonetheless - to = TQString( "=?utf8?b?%1?=" ) - .arg( TQString(KCodecs::base64Encode( _to.utf8(), false )) ); - } - if ( !_cc.isEmpty() ) - cc = TQString( "=?utf8?b?%1?=" ) - .arg( TQString(KCodecs::base64Encode( _cc.utf8(), false )) ); - if ( !_bcc.isEmpty() ) - bcc = TQString( "=?utf8?b?%1?=" ) - .arg( TQString(KCodecs::base64Encode( _bcc.utf8(), false )) ); - } else { - to = _to; - cc = _cc; - bcc = _bcc; - if( !command.contains( '%' )) - command += " %u"; - } - - if (config.readBoolEntry("TerminalClient", false)) - { - TDEConfigGroup confGroup( TDEGlobal::config(), "General" ); - TQString preferredTerminal = confGroup.readPathEntry("TerminalApplication", "konsole"); - command = preferredTerminal + " -e " + command; - } - - TQStringList cmdTokens = KShell::splitArgs(command); - TQString cmd = cmdTokens[0]; - cmdTokens.remove(cmdTokens.begin()); - - KURL url; - TQStringList qry; - if (!to.isEmpty()) - { - TQStringList tos = splitEmailAddressList( to ); - url.setPath( tos.first() ); - tos.remove( tos.begin() ); - for (TQStringList::ConstIterator it = tos.begin(); it != tos.end(); ++it) - qry.append( "to=" + KURL::encode_string( *it ) ); - } - const TQStringList ccs = splitEmailAddressList( cc ); - for (TQStringList::ConstIterator it = ccs.begin(); it != ccs.end(); ++it) - qry.append( "cc=" + KURL::encode_string( *it ) ); - const TQStringList bccs = splitEmailAddressList( bcc ); - for (TQStringList::ConstIterator it = bccs.begin(); it != bccs.end(); ++it) - qry.append( "bcc=" + KURL::encode_string( *it ) ); - for (TQStringList::ConstIterator it = attachURLs.begin(); it != attachURLs.end(); ++it) - qry.append( "attach=" + KURL::encode_string( *it ) ); - if (!subject.isEmpty()) - qry.append( "subject=" + KURL::encode_string( subject ) ); - if (!body.isEmpty()) - qry.append( "body=" + KURL::encode_string( body ) ); - url.setQuery( qry.join( "&" ) ); - if ( ! (to.isEmpty() && qry.isEmpty()) ) - url.setProtocol("mailto"); - - TQMap<TQChar, TQString> keyMap; - keyMap.insert('t', to); - keyMap.insert('s', subject); - keyMap.insert('c', cc); - keyMap.insert('b', bcc); - keyMap.insert('B', body); - keyMap.insert('u', url.url()); - - TQString attachlist = attachURLs.join(","); - attachlist.prepend('\''); - attachlist.append('\''); - keyMap.insert('A', attachlist); - - for (TQStringList::Iterator it = cmdTokens.begin(); it != cmdTokens.end(); ) - { - if (*it == "%A") - { - if (it == cmdTokens.begin()) // better safe than sorry ... - continue; - TQStringList::ConstIterator urlit = attachURLs.begin(); - TQStringList::ConstIterator urlend = attachURLs.end(); - if ( urlit != urlend ) - { - TQStringList::Iterator previt = it; - --previt; - *it = *urlit; - ++it; - while ( ++urlit != urlend ) - { - cmdTokens.insert( it, *previt ); - cmdTokens.insert( it, *urlit ); - } - } else { - --it; - it = cmdTokens.remove( cmdTokens.remove( it ) ); - } - } else { - *it = KMacroExpander::expandMacros(*it, keyMap); - ++it; - } - } - - TQString error; - // TODO this should check if cmd has a .desktop file, and use data from it, together - // with sending more ASN data - if (tdeinitExec(cmd, cmdTokens, &error, NULL, startup_id )) { - if (Tty != kapp->type()) { - TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Mail Client"), - i18n("Could not launch the mail client:\n\n%1").arg(error), i18n("&OK")); - } - else { - kdWarning() << "Could not launch mail client:\n" << error << endl; - } - } -} -#endif - -void TDEApplication::invokeBrowser( const TQString &url ) -{ - return invokeBrowser( url, "" ); -} - -#ifndef Q_WS_WIN -// on win32, for invoking browser we're using win32 API -// see kapplication_win.cpp -void TDEApplication::invokeBrowser( const TQString &url, const TQCString& startup_id ) -{ - TQString error; - - if (startServiceByDesktopName("kfmclient", url, &error, 0, 0, startup_id, false)) - { - if (Tty != kapp->type()) - TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Browser"), - i18n("Could not launch the browser:\n\n%1").arg(error), i18n("&OK")); - else - kdWarning() << "Could not launch browser:\n" << error << endl; - return; - } -} -#endif - -void TDEApplication::cut() -{ - invokeEditSlot( TQT_SLOT( cut() ) ); -} - -void TDEApplication::copy() -{ - invokeEditSlot( TQT_SLOT( copy() ) ); -} - -void TDEApplication::paste() -{ - invokeEditSlot( TQT_SLOT( paste() ) ); -} - -void TDEApplication::clear() -{ - invokeEditSlot( TQT_SLOT( clear() ) ); -} - -void TDEApplication::selectAll() -{ - invokeEditSlot( TQT_SLOT( selectAll() ) ); -} - -void TDEApplication::broadcastKeyCode(unsigned int keyCode) -{ - emit coreFakeKeyPress(keyCode); -} - -TQCString -TDEApplication::launcher() -{ - return "tdelauncher"; -} - -static int -startServiceInternal( const TQCString &function, - const TQString& _name, const TQStringList &URLs, - TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) -{ - struct serviceResult - { - int result; - TQCString dcopName; - TQString error; - pid_t pid; - }; - - // Register app as able to send DCOP messages - DCOPClient *dcopClient; - if (kapp) - dcopClient = kapp->dcopClient(); - else - dcopClient = new DCOPClient; - - if (!dcopClient->isAttached()) - { - if (!dcopClient->attach()) - { - if (error) - *error = i18n("Could not register with DCOP.\n"); - if (!kapp) - delete dcopClient; - - return -1; - } - } - TQByteArray params; - TQDataStream stream(params, IO_WriteOnly); - stream << _name << URLs; - TQCString replyType; - TQByteArray replyData; - TQCString _launcher = TDEApplication::launcher(); - TQValueList<TQCString> envs; -#ifdef Q_WS_X11 - if (tqt_xdisplay()) { - TQCString dpystring(XDisplayString(tqt_xdisplay())); - envs.append( TQCString("DISPLAY=") + dpystring ); - } else if( getenv( "DISPLAY" )) { - TQCString dpystring( getenv( "DISPLAY" )); - envs.append( TQCString("DISPLAY=") + dpystring ); - } -#endif - stream << envs; -#if defined Q_WS_X11 - // make sure there is id, so that user timestamp exists - stream << ( startup_id.isEmpty() ? TDEStartupInfo::createNewStartupId() : startup_id ); -#endif - if( function.left( 12 ) != "tdeinit_exec" ) - stream << noWait; - - if (!dcopClient->call(_launcher, _launcher, - function, params, replyType, replyData)) - { - if (error) - *error = i18n("TDELauncher could not be reached via DCOP.\n"); - if (!kapp) - delete dcopClient; - return -1; - } - if (!kapp) - delete dcopClient; - - if (noWait) - return 0; - - TQDataStream stream2(replyData, IO_ReadOnly); - serviceResult result; - stream2 >> result.result >> result.dcopName >> result.error >> result.pid; - if (dcopService) - *dcopService = result.dcopName; - if (error) - *error = result.error; - if (pid) - *pid = result.pid; - return result.result; -} - -int -TDEApplication::startServiceByName( const TQString& _name, const TQString &URL, - TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) -{ - TQStringList URLs; - if (!URL.isEmpty()) - URLs.append(URL); - return startServiceInternal( - "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", - _name, URLs, error, dcopService, pid, startup_id, noWait); -} - -int -TDEApplication::startServiceByName( const TQString& _name, const TQStringList &URLs, - TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) -{ - return startServiceInternal( - "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", - _name, URLs, error, dcopService, pid, startup_id, noWait); -} - -int -TDEApplication::startServiceByDesktopPath( const TQString& _name, const TQString &URL, - TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) -{ - TQStringList URLs; - if (!URL.isEmpty()) - URLs.append(URL); - return startServiceInternal( - "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", - _name, URLs, error, dcopService, pid, startup_id, noWait); -} - -int -TDEApplication::startServiceByDesktopPath( const TQString& _name, const TQStringList &URLs, - TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) -{ - return startServiceInternal( - "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", - _name, URLs, error, dcopService, pid, startup_id, noWait); -} - -int -TDEApplication::startServiceByDesktopName( const TQString& _name, const TQString &URL, - TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) -{ - TQStringList URLs; - if (!URL.isEmpty()) - URLs.append(URL); - return startServiceInternal( - "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", - _name, URLs, error, dcopService, pid, startup_id, noWait); -} - -int -TDEApplication::startServiceByDesktopName( const TQString& _name, const TQStringList &URLs, - TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) -{ - return startServiceInternal( - "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", - _name, URLs, error, dcopService, pid, startup_id, noWait); -} - -int -TDEApplication::tdeinitExec( const TQString& name, const TQStringList &args, - TQString *error, int *pid ) -{ - return tdeinitExec( name, args, error, pid, "" ); -} - -int -TDEApplication::tdeinitExec( const TQString& name, const TQStringList &args, - TQString *error, int *pid, const TQCString& startup_id ) -{ - return startServiceInternal("tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)", - name, args, error, 0, pid, startup_id, false); -} - -int -TDEApplication::tdeinitExecWait( const TQString& name, const TQStringList &args, - TQString *error, int *pid ) -{ - return tdeinitExecWait( name, args, error, pid, "" ); -} - -int -TDEApplication::tdeinitExecWait( const TQString& name, const TQStringList &args, - TQString *error, int *pid, const TQCString& startup_id ) -{ - return startServiceInternal("tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>,TQCString)", - name, args, error, 0, pid, startup_id, false); -} - -TQString TDEApplication::tempSaveName( const TQString& pFilename ) const -{ - TQString aFilename; - - if( TQDir::isRelativePath(pFilename) ) - { - kdWarning(101) << "Relative filename passed to TDEApplication::tempSaveName" << endl; - aFilename = TQFileInfo( TQDir( "." ), pFilename ).absFilePath(); - } - else - aFilename = pFilename; - - TQDir aAutosaveDir( TQDir::homeDirPath() + "/autosave/" ); - if( !aAutosaveDir.exists() ) - { - if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) ) - { - // Last chance: use temp dir - aAutosaveDir.setPath( TDEGlobal::dirs()->saveLocation("tmp") ); - } - } - - aFilename.replace( "/", "\\!" ).prepend( "#" ).append( "#" ).prepend( "/" ).prepend( aAutosaveDir.absPath() ); - - return aFilename; -} - - -TQString TDEApplication::checkRecoverFile( const TQString& pFilename, - bool& bRecover ) const -{ - TQString aFilename; - - if( TQDir::isRelativePath(pFilename) ) - { - kdWarning(101) << "Relative filename passed to TDEApplication::tempSaveName" << endl; - aFilename = TQFileInfo( TQDir( "." ), pFilename ).absFilePath(); - } - else - aFilename = pFilename; - - TQDir aAutosaveDir( TQDir::homeDirPath() + "/autosave/" ); - if( !aAutosaveDir.exists() ) - { - if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) ) - { - // Last chance: use temp dir - aAutosaveDir.setPath( TDEGlobal::dirs()->saveLocation("tmp") ); - } - } - - aFilename.replace( "/", "\\!" ).prepend( "#" ).append( "#" ).prepend( "/" ).prepend( aAutosaveDir.absPath() ); - - if( TQFile( aFilename ).exists() ) - { - bRecover = true; - return aFilename; - } - else - { - bRecover = false; - return pFilename; - } -} - - -bool checkAccess(const TQString& pathname, int mode) -{ - int accessOK = access( TQFile::encodeName(pathname), mode ); - if ( accessOK == 0 ) - return true; // OK, I can really access the file - - // else - // if we want to write the file would be created. Check, if the - // user may write to the directory to create the file. - if ( (mode & W_OK) == 0 ) - return false; // Check for write access is not part of mode => bail out - - - if (!access( TQFile::encodeName(pathname), F_OK)) // if it already exists - return false; - - //strip the filename (everything until '/' from the end - TQString dirName(pathname); - int pos = dirName.findRev('/'); - if ( pos == -1 ) - return false; // No path in argument. This is evil, we won't allow this - else if ( pos == 0 ) // don't turn e.g. /root into an empty string - pos = 1; - - dirName.truncate(pos); // strip everything starting from the last '/' - - accessOK = access( TQFile::encodeName(dirName), W_OK ); - // -?- Can I write to the accessed diretory - if ( accessOK == 0 ) - return true; // Yes - else - return false; // No -} - -void TDEApplication::setTopWidget( TQWidget *topWidget ) -{ - if( !topWidget ) - return; - - // set the specified caption - if ( !topWidget->inherits("TDEMainWindow") ) { // TDEMainWindow does this already for us - topWidget->setCaption( caption() ); - } - - // set the specified icons - topWidget->setIcon( icon() ); //standard X11 -#if defined Q_WS_X11 -//#ifdef Q_WS_X11 // FIXME(E): Implement for Qt/Embedded - KWin::setIcons(topWidget->winId(), icon(), miniIcon() ); // NET_WM hints for KWin - - // set the app startup notification window property - TDEStartupInfo::setWindowStartupId( topWidget->winId(), startupId()); -#endif -} - -TQCString TDEApplication::startupId() const -{ - return d->startup_id; -} - -void TDEApplication::setStartupId( const TQCString& startup_id ) -{ - if( startup_id == d->startup_id ) - return; -#if defined Q_WS_X11 - TDEStartupInfo::handleAutoAppStartedSending(); // finish old startup notification if needed -#endif - if( startup_id.isEmpty()) - d->startup_id = "0"; - else - { - d->startup_id = startup_id; -#if defined Q_WS_X11 - TDEStartupInfoId id; - id.initId( startup_id ); - long timestamp = id.timestamp(); - if( timestamp != 0 ) - updateUserTimestamp( timestamp ); -#endif - } -} - -// read the startup notification env variable, save it and unset it in order -// not to propagate it to processes started from this app -void TDEApplication::read_app_startup_id() -{ -#if defined Q_WS_X11 - TDEStartupInfoId id = TDEStartupInfo::currentStartupIdEnv(); - TDEStartupInfo::resetStartupEnv(); - d->startup_id = id.id(); -#endif -} - -int TDEApplication::random() -{ - static bool init = false; - if (!init) - { - unsigned int seed; - init = true; - int fd = open("/dev/urandom", O_RDONLY); - if (fd < 0 || ::read(fd, &seed, sizeof(seed)) != sizeof(seed)) - { - // No /dev/urandom... try something else. - srand(getpid()); - seed = rand()+time(0); - } - if (fd >= 0) close(fd); - srand(seed); - } - return rand(); -} - -TQString TDEApplication::randomString(int length) -{ - if (length <=0 ) return TQString::null; - - TQString str; str.setLength( length ); - int i = 0; - while (length--) - { - int r=random() % 62; - r+=48; - if (r>57) r+=7; - if (r>90) r+=6; - str[i++] = char(r); - // so what if I work backwards? - } - return str; -} - -bool TDEApplication::authorize(const TQString &genericAction) -{ - if (!d->actionRestrictions) - return true; - - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "KDE Action Restrictions" ); - return config->readBoolEntry(genericAction, true); -} - -bool TDEApplication::authorizeTDEAction(const char *action) -{ - if (!d->actionRestrictions || !action) - return true; - - static const TQString &action_prefix = TDEGlobal::staticQString( "action/" ); - - return authorize(action_prefix + action); -} - -bool TDEApplication::authorizeControlModule(const TQString &menuId) -{ - if (menuId.isEmpty() || kde_kiosk_exception) - return true; - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "TDE Control Module Restrictions" ); - return config->readBoolEntry(menuId, true); -} - -TQStringList TDEApplication::authorizeControlModules(const TQStringList &menuIds) -{ - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "TDE Control Module Restrictions" ); - TQStringList result; - for(TQStringList::ConstIterator it = menuIds.begin(); - it != menuIds.end(); ++it) - { - if (config->readBoolEntry(*it, true)) - result.append(*it); - } - return result; -} - -void TDEApplication::initUrlActionRestrictions() -{ - d->urlActionRestrictions.setAutoDelete(true); - d->urlActionRestrictions.clear(); - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("open", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true)); - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true)); -// TEST: -// d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule -// ("list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, false)); -// d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule -// ("list", TQString::null, TQString::null, TQString::null, "file", TQString::null, TQDir::homeDirPath(), true)); - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("link", TQString::null, TQString::null, TQString::null, ":internet", TQString::null, TQString::null, true)); - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("redirect", TQString::null, TQString::null, TQString::null, ":internet", TQString::null, TQString::null, true)); - - // We allow redirections to file: but not from internet protocols, redirecting to file: - // is very popular among io-slaves and we don't want to break them - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("redirect", TQString::null, TQString::null, TQString::null, "file", TQString::null, TQString::null, true)); - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("redirect", ":internet", TQString::null, TQString::null, "file", TQString::null, TQString::null, false)); - - // local protocols may redirect everywhere - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("redirect", ":local", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true)); - - // Anyone may redirect to about: - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("redirect", TQString::null, TQString::null, TQString::null, "about", TQString::null, TQString::null, true)); - - // Anyone may redirect to itself, cq. within it's own group - d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule - ("redirect", TQString::null, TQString::null, TQString::null, "=", TQString::null, TQString::null, true)); - - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "KDE URL Restrictions" ); - int count = config->readNumEntry("rule_count"); - TQString keyFormat = TQString("rule_%1"); - for(int i = 1; i <= count; i++) - { - TQString key = keyFormat.arg(i); - TQStringList rule = config->readListEntry(key); - if (rule.count() != 8) - continue; - TQString action = rule[0]; - TQString refProt = rule[1]; - TQString refHost = rule[2]; - TQString refPath = rule[3]; - TQString urlProt = rule[4]; - TQString urlHost = rule[5]; - TQString urlPath = rule[6]; - TQString strEnabled = rule[7].lower(); - - bool bEnabled = (strEnabled == "true"); - - if (refPath.startsWith("$HOME")) - refPath.replace(0, 5, TQDir::homeDirPath()); - else if (refPath.startsWith("~")) - refPath.replace(0, 1, TQDir::homeDirPath()); - if (urlPath.startsWith("$HOME")) - urlPath.replace(0, 5, TQDir::homeDirPath()); - else if (urlPath.startsWith("~")) - urlPath.replace(0, 1, TQDir::homeDirPath()); - - if (refPath.startsWith("$TMP")) - refPath.replace(0, 4, TDEGlobal::dirs()->saveLocation("tmp")); - if (urlPath.startsWith("$TMP")) - urlPath.replace(0, 4, TDEGlobal::dirs()->saveLocation("tmp")); - - d->urlActionRestrictions.append(new TDEApplicationPrivate::URLActionRule - ( action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled)); - } -} - -void TDEApplication::allowURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL) -{ - if (authorizeURLAction(action, _baseURL, _destURL)) - return; - - d->urlActionRestrictions.append(new TDEApplicationPrivate::URLActionRule - ( action, _baseURL.protocol(), _baseURL.host(), _baseURL.path(-1), - _destURL.protocol(), _destURL.host(), _destURL.path(-1), true)); -} - -bool TDEApplication::authorizeURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL) -{ - if (_destURL.isEmpty()) - return true; - - bool result = false; - if (d->urlActionRestrictions.isEmpty()) - initUrlActionRestrictions(); - - KURL baseURL(_baseURL); - baseURL.setPath(TQDir::cleanDirPath(baseURL.path())); - TQString baseClass = KProtocolInfo::protocolClass(baseURL.protocol()); - KURL destURL(_destURL); - destURL.setPath(TQDir::cleanDirPath(destURL.path())); - TQString destClass = KProtocolInfo::protocolClass(destURL.protocol()); - - for(TDEApplicationPrivate::URLActionRule *rule = d->urlActionRestrictions.first(); - rule; rule = d->urlActionRestrictions.next()) - { - if ((result != rule->permission) && // No need to check if it doesn't make a difference - (action == rule->action) && - rule->baseMatch(baseURL, baseClass) && - rule->destMatch(destURL, destClass, baseURL, baseClass)) - { - result = rule->permission; - } - } - return result; -} - - -uint TDEApplication::keyboardModifiers() -{ -#ifdef Q_WS_X11 - Window root; - Window child; - int root_x, root_y, win_x, win_y; - uint keybstate; - XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child, - &root_x, &root_y, &win_x, &win_y, &keybstate ); - return keybstate & 0x00ff; -#elif defined W_WS_MACX - return GetCurrentEventKeyModifiers() & 0x00ff; -#else - //TODO for win32 - return 0; -#endif -} - -uint TDEApplication::mouseState() -{ - uint mousestate; -#ifdef Q_WS_X11 - Window root; - Window child; - int root_x, root_y, win_x, win_y; - XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child, - &root_x, &root_y, &win_x, &win_y, &mousestate ); -#elif defined(Q_WS_WIN) - const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON); - if (GetAsyncKeyState(VK_LBUTTON)) - mousestate |= (mousebtn_swapped ? Button3Mask : Button1Mask); - if (GetAsyncKeyState(VK_MBUTTON)) - mousestate |= Button2Mask; - if (GetAsyncKeyState(VK_RBUTTON)) - mousestate |= (mousebtn_swapped ? Button1Mask : Button3Mask); -#elif defined(Q_WS_MACX) - mousestate = GetCurrentEventButtonState(); -#else - //TODO: other platforms -#endif - return mousestate & 0xff00; -} - -TQ_ButtonState TDEApplication::keyboardMouseState() -{ - int ret = 0; -#ifdef Q_WS_X11 - Window root; - Window child; - int root_x, root_y, win_x, win_y; - uint state; - XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child, - &root_x, &root_y, &win_x, &win_y, &state ); - // transform the same way like Qt's qt_x11_translateButtonState() - if( state & Button1Mask ) - ret |= TQ_LeftButton; - if( state & Button2Mask ) - ret |= TQ_MidButton; - if( state & Button3Mask ) - ret |= TQ_RightButton; - if( state & ShiftMask ) - ret |= TQ_ShiftButton; - if( state & ControlMask ) - ret |= TQ_ControlButton; - if( state & KKeyNative::modX( KKey::ALT )) - ret |= TQ_AltButton; - if( state & KKeyNative::modX( KKey::WIN )) - ret |= TQ_MetaButton; -#elif defined(Q_WS_WIN) - const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON); - if (GetAsyncKeyState(VK_LBUTTON)) - ret |= (mousebtn_swapped ? RightButton : LeftButton); - if (GetAsyncKeyState(VK_MBUTTON)) - ret |= TQ_MidButton; - if (GetAsyncKeyState(VK_RBUTTON)) - ret |= (mousebtn_swapped ? TQ_LeftButton : TQ_RightButton); - if (GetAsyncKeyState(VK_SHIFT)) - ret |= TQ_ShiftButton; - if (GetAsyncKeyState(VK_CONTROL)) - ret |= TQ_ControlButton; - if (GetAsyncKeyState(VK_MENU)) - ret |= TQ_AltButton; - if (GetAsyncKeyState(VK_LWIN) || GetAsyncKeyState(VK_RWIN)) - ret |= TQ_MetaButton; -#else - //TODO: other platforms -#endif - return static_cast< ButtonState >( ret ); -} - -void TDEApplication::installSigpipeHandler() -{ -#ifdef Q_OS_UNIX - struct sigaction act; - act.sa_handler = SIG_IGN; - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; - sigaction( SIGPIPE, &act, 0 ); -#endif -} - -void TDEApplication::sigpipeHandler(int) -{ - int saved_errno = errno; - // Using kdDebug from a signal handler is not a good idea. -#ifndef NDEBUG - char msg[1000]; - sprintf(msg, "*** SIGPIPE *** (ignored, pid = %ld)\n", (long) getpid()); - if (write(2, msg, strlen(msg)) < 0) { - // ERROR - } -#endif - - // Do nothing. - errno = saved_errno; -} - -bool TDEApplication::guiEnabled() -{ - return kapp && kapp->d->guiEnabled; -} - -void TDEApplication::virtual_hook( int id, void* data ) -{ TDEInstance::virtual_hook( id, data ); } - -void KSessionManaged::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "kapplication.moc" diff --git a/tdecore/kapplication.h b/tdecore/kapplication.h deleted file mode 100644 index 5ab8d7ee7..000000000 --- a/tdecore/kapplication.h +++ /dev/null @@ -1,1620 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) - Copyright (c) 1998, 1999 KDE Team - - 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. -*/ - -#ifndef _KAPP_H -#define _KAPP_H - -// Version macros. Never put this further down. -#include "tdeversion.h" -#include "tdelibs_export.h" - -class TDEConfig; -class KCharsets; -class DCOPClient; -class DCOPObject; - -#include <tqtglobaldefines.h> - -typedef unsigned long Atom; -#if !defined(Q_WS_X11) -typedef void Display; -#endif - -#include <tqapplication.h> -#include <tqpixmap.h> -#include <kinstance.h> - -struct _IceConn; -class TQPopupMenu; -class TQStrList; -class KSessionManaged; -class TDEStyle; -class KURL; - -#define kapp TDEApplication::kApplication() - -class TDEApplicationPrivate; - -/** -* Controls and provides information to all KDE applications. -* -* Only one object of this class can be instantiated in a single app. -* This instance is always accessible via the 'kapp' global variable. -* See cut() for an example. -* -* This class provides the following services to all KDE applications. -* -* @li It controls the event queue (see TQApplication ). -* @li It provides the application with KDE resources such as -* accelerators, common menu entries, a TDEConfig object. session -* management events, help invocation etc. -* @li Installs a signal handler for the SIGCHLD signal in order to -* avoid zombie children. If you want to catch this signal yourself or -* don't want it to be caught at all, you have set a new signal handler -* (or SIG_IGN) after TDEApplication's constructor has run. -* @li Installs an empty signal handler for the SIGPIPE signal using -* installSigpipeHandler(). If you want to catch this signal -* yourself, you have set a new signal handler after TDEApplication's -* constructor has run. -* @li It can start new services -* -* -* The way a service gets started depends on the 'X-DCOP-ServiceType' -* entry in the desktop file of the service: -* -* There are three possibilities: -* @li X-DCOP-ServiceType=None (default) -* Always start a new service, -* don't wait till the service registers with dcop. -* @li X-DCOP-ServiceType=Multi -* Always start a new service, -* wait until the service has registered with dcop. -* @li X-DCOP-ServiceType=Unique -* Only start the service if it isn't already running, -* wait until the service has registered with dcop. -* -* @short Controls and provides information to all KDE applications. -* @author Matthias Kalle Dalheimer <kalle@kde.org> -*/ -class TDECORE_EXPORT TDEApplication : public TQApplication, public TDEInstance -{ - - Q_OBJECT -public: - /** Position of the caption (presumably in the application window's - * title bar). This enum appears to be unused. - * - * @todo Find out if this is used anywhere. - */ - enum CaptionLayout { - CaptionAppLast=1 /**< Display the application name last (before document name). */, - CaptionAppFirst /**< Display the application name first. */ , - CaptionNoApp /**< Do not display application name at all. */ - }; - - /** - * This constructor takes aboutData and command line - * arguments from TDECmdLineArgs. - * - * If ARGB (transparent) widgets are to be used in your application, - * please use - * TDEApplication app(TDEApplication::openX11RGBADisplay()); - * or - * TDEApplication app(TDEApplication::openX11RGBADisplay(), useStyles); - * - * @param allowStyles Set to false to disable the loading on plugin based - * styles. This is only useful to applications that do not display a GUI - * normally. If you do create an application with @p allowStyles set to false - * it normally runs in the background but under special circumstances - * displays widgets. Call enableStyles() before displaying any widgets. - * - * @param GUIenabled Set to false to disable all GUI stuff. This implies - * no styles either. - */ - TDEApplication( bool allowStyles=true, bool GUIenabled=true); - -#ifdef Q_WS_X11 - /** - * Constructor. Parses command-line arguments. Use this constructor when you - * you want ARGB support to be automatically detected and enabled. - * - * @param display Will be passed to Qt as the X display. The display must be - * valid and already opened. - * - * @param allowStyles Set to false to disable the loading on plugin based - * styles. This is only useful to applications that do not display a GUI - * normally. If you do create an application with @p allowStyles set to false - * that normally runs in the background but under special circumstances - * displays widgets call enableStyles() before displaying any widgets. - * - * @since KDE 3.5 - * - * @see RGBADisplay() - */ - TDEApplication(Display *display, bool allowStyles); - - /** - * Constructor. Parses command-line arguments. Use this constructor when you - * you want ARGB support to be automatically detected and enabled. - * - * @param display Will be passed to Qt as the X display. The display must be - * valid and already opened. - * - * @param disable_argb Set to true to disable ARGB visuals in this application. - * - * @param display Will be passed to Qt as the X display. The display must be - * valid and already opened. - * - * @param visual A pointer to the X11 visual that should be used by the - * appliction. Note that only TrueColor visuals are supported on depths - * greater than 8 bpp. If this parameter is NULL, the default visual will - * be used instead. - * - * @param allowStyles Set to false to disable the loading on plugin based - * styles. This is only useful to applications that do not display a GUI - * normally. If you do create an application with @p allowStyles set to false - * that normally runs in the background but under special circumstances - * displays widgets call enableStyles() before displaying any widgets. - * - * @since KDE 3.5 - * - * @see RGBADisplay() - */ - TDEApplication(Display *display, bool disable_argb, Qt::HANDLE visual, Qt::HANDLE colormap, bool allowStyles); - - /** - * Constructor. Parses command-line arguments. Use this constructor when you - * you need to use a non-default visual or colormap. - * - * @param display Will be passed to Qt as the X display. The display must be - * valid and already opened. - * - * @param visual A pointer to the X11 visual that should be used by the - * appliction. Note that only TrueColor visuals are supported on depths - * greater than 8 bpp. If this parameter is NULL, the default visual will - * be used instead. - * - * @param colormap The colormap that should be used by the application. If - * this parameter is 0, the default colormap will be used instead. - * - * @param allowStyles Set to false to disable the loading on plugin based - * styles. This is only useful to applications that do not display a GUI - * normally. If you do create an application with @p allowStyles set to false - * that normally runs in the background but under special circumstances - * displays widgets call enableStyles() before displaying any widgets. - * - * @since KDE 3.3 - */ - TDEApplication(Display *display, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0, - bool allowStyles=true); - - /** - * Constructor. Parses command-line arguments. Use this constructor to use TDEApplication - * in a Motif or Xt program. - * - * @param display Will be passed to Qt as the X display. The display must be valid and already - * opened. - * - * @param argc command line argument count - * - * @param argv command line argument value(s) - * - * @param rAppName application name. Will be used for finding the - * associated message files and icon files, and as the default - * registration name for DCOP. This is a mandatory parameter. - * - * @param allowStyles Set to false to disable the loading on plugin based - * styles. This is only useful to applications that do not display a GUI - * normally. If you do create an application with @p allowStyles set to false - * that normally runs in the background but under special circumstances - * displays widgets call enableStyles() before displaying any widgets. - * - * @param GUIenabled Set to false to disable all GUI stuff. This implies - * no styles either. - */ - TDEApplication(Display *display, int& argc, char** argv, const TQCString& rAppName, - bool allowStyles=true, bool GUIenabled=true); -#endif - - /** - * @deprecated do not use it at all, it will make your application crash, use TDECmdLineArgs - * - * Constructor. Parses command-line arguments. - * - * @param argc command line argument count - * - * @param argv command line argument value(s) - * - * @param rAppName application name. Will be used for finding the - * associated message files and icon files, and as the default - * registration name for DCOP. This is a mandatory parameter. - * - * @param allowStyles Set to false to disable the loading on plugin based - * styles. This is only useful to applications that do not display a GUI - * normally. If you do create an application with @p allowStyles set to false - * that normally runs in the background but under special circumstances - * displays widgets call enableStyles() before displaying any widgets. - * - * @param GUIenabled Set to false to disable all GUI stuff. This implies - * no styles either. - */ - // REMOVE FOR KDE 4.0 - using it only gives crashing applications because - // TDECmdLineArgs::init isn't called - TDEApplication(int& argc, char** argv, - const TQCString& rAppName, bool allowStyles=true, bool GUIenabled=true) KDE_DEPRECATED; - - /** - * Add Qt and KDE command line options to TDECmdLineArgs. - */ - static void addCmdLineOptions(); - - virtual ~TDEApplication(); - - /** - * Returns the current application object. - * - * This is similar to the global TQApplication pointer tqApp. It - * allows access to the single global TDEApplication object, since - * more than one cannot be created in the same application. It - * saves you the trouble of having to pass the pointer explicitly - * to every function that may require it. - * @return the current application object - */ - static TDEApplication* kApplication() { return KApp; } - - /** - * Returns the application session config object. - * - * @return A pointer to the application's instance specific - * TDEConfig object. - * @see TDEConfig - */ - TDEConfig* sessionConfig(); - - /** - * Is the application restored from the session manager? - * - * @return If true, this application was restored by the session manager. - * Note that this may mean the config object returned by - * sessionConfig() contains data saved by a session closedown. - * @see sessionConfig() - */ - bool isRestored() const { return TQApplication::isSessionRestored(); } - - /** - * Disables session management for this application. - * - * Useful in case your application is started by the - * initial "starttde" script. - */ - void disableSessionManagement(); - - /** - * Enables again session management for this application, formerly - * disabled by calling disableSessionManagement(). You usually - * shouldn't call this function, as the session management is enabled - * by default. - */ - void enableSessionManagement(); - - /** - * The possible values for the @p confirm parameter of requestShutDown(). - */ - enum ShutdownConfirm { - /** - * Obey the user's confirmation setting. - */ - ShutdownConfirmDefault = -1, - /** - * Don't confirm, shutdown without asking. - */ - ShutdownConfirmNo = 0, - /** - * Always confirm, ask even if the user turned it off. - */ - ShutdownConfirmYes = 1 - }; - - /** - * The possible values for the @p sdtype parameter of requestShutDown(). - */ - enum ShutdownType { - /** - * Select previous action or the default if it's the first time. - */ - ShutdownTypeDefault = -1, - /** - * Only log out. - */ - ShutdownTypeNone = 0, - /** - * Log out and reboot the machine. - */ - ShutdownTypeReboot = 1, - /** - * Log out and halt the machine. - */ - ShutdownTypeHalt = 2 - }; - - /** - * The possible values for the @p sdmode parameter of requestShutDown(). - */ - enum ShutdownMode { - /** - * Select previous mode or the default if it's the first time. - */ - ShutdownModeDefault = -1, - /** - * Schedule a shutdown (halt or reboot) for the time all active sessions - * have exited. - */ - ShutdownModeSchedule = 0, - /** - * Shut down, if no sessions are active. Otherwise do nothing. - */ - ShutdownModeTryNow = 1, - /** - * Force shutdown. Kill any possibly active sessions. - */ - ShutdownModeForceNow = 2, - /** - * Pop up a dialog asking the user what to do if sessions are still active. - */ - ShutdownModeInteractive = 3 - }; - - /** - * Asks the session manager to shut the session down. - * - * Using @p confirm == ShutdownConfirmYes or @p sdtype != ShutdownTypeDefault or - * @p sdmode != ShutdownModeDefault causes the use of ksmserver's DCOP - * interface. The remaining two combinations use the standard XSMP and - * will work with any session manager compliant with it. - * - * @param confirm Whether to ask the user if he really wants to log out. - * ShutdownConfirm - * @param sdtype The action to take after logging out. ShutdownType - * @param sdmode If/When the action should be taken. ShutdownMode - * @return true on success, false if the session manager could not be - * contacted. - */ - bool requestShutDown( ShutdownConfirm confirm = ShutdownConfirmDefault, - ShutdownType sdtype = ShutdownTypeDefault, - ShutdownMode sdmode = ShutdownModeDefault ); - - /** - * Propagates the network address of the session manager in the - * SESSION_MANAGER environment variable so that child processes can - * pick it up. - * - * If SESSION_MANAGER isn't defined yet, the address is searched in - * $HOME/.KSMserver. - * - * This function is called by clients that are started outside the - * session ( i.e. before ksmserver is started), but want to launch - * other processes that should participate in the session. Examples - * are kdesktop or kicker. - */ - void propagateSessionManager(); - - /** - * Reimplemented for internal purposes, mainly the highlevel - * handling of session management with KSessionManaged. - * @internal - */ - void commitData( TQSessionManager& sm ); - - /** - * Reimplemented for internal purposes, mainly the highlevel - * handling of session management with KSessionManaged. - * @internal - */ - void saveState( TQSessionManager& sm ); - - /** - * Returns true if the application is currently saving its session - * data (most probably before KDE logout). This is intended for use - * mainly in TDEMainWindow::queryClose() and TDEMainWindow::queryExit(). - * - * @see TDEMainWindow::queryClose - * @see TDEMainWindow::queryExit - * @since 3.1.1 - */ - bool sessionSaving() const; - - /** - * Returns a pointer to a DCOPClient for the application. - * If a client does not exist yet, it is created when this - * function is called. - * @return the DCOPClient for the application - */ - static DCOPClient *dcopClient(); - - /** - * Disable automatic dcop registration - * Must be called before creating a TDEApplication instance to have an effect. - */ - static void disableAutoDcopRegistration(); - - /** - * Returns a TQPixmap with the application icon. - * @return the application icon - */ - TQPixmap icon() const; - - /** - * Returns the name of the application icon. - * @return the icon's name - */ - TQString iconName() const; - - /** - * Returns the mini-icon for the application as a TQPixmap. - * @return the application's mini icon - */ - TQPixmap miniIcon() const; - - /** - * Returns the name of the mini-icon for the application. - * @return the mini icon's name - */ - TQString miniIconName() const; - - /** - * Sets the top widget of the application. - * This means basically applying the right window caption and - * icon. An application may have several top widgets. You don't - * need to call this function manually when using TDEMainWindow. - * - * @param topWidget A top widget of the application. - * - * @see icon(), caption() - **/ - void setTopWidget( TQWidget *topWidget ); - - /** - * Invokes the KHelpCenter HTML help viewer from docbook sources. - * - * @param anchor This has to be a defined anchor in your - * docbook sources. If empty the main index - * is loaded - * @param appname This allows you to show the help of another - * application. If empty the current name() is - * used - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - */ - void invokeHelp( const TQString& anchor, - const TQString& appname, - const TQCString& startup_id ) const; - - // KDE4 merge with above with startup_id = "" - void invokeHelp( const TQString& anchor = TQString::null, - const TQString& appname = TQString::null ) const; - - /** - * @deprecated - * Invoke the khelpcenter HTML help viewer from HTML sources. - * Please use invokeHelp() instead. - * - * @param aFilename The filename that is to be loaded. Its - * location is computed automatically - * according to the KFSSTND. If @p aFilename - * is empty, the logical appname with .html - * appended to it is used. - * @param aTopic This allows context-sensitive help. Its - * value will be appended to the filename, - * prefixed with a "#" (hash) character. - */ - void invokeHTMLHelp( const TQString& aFilename, const TQString& aTopic = TQString::null ) const KDE_DEPRECATED; - - /** - * Convenience method; invokes the standard email application. - * - * @param address The destination address - * @param subject Subject string. Can be TQString::null. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - */ - void invokeMailer( const TQString &address, const TQString &subject, const TQCString& startup_id ); - // KDE4 merge with above with startup_id = "" - void invokeMailer( const TQString &address, const TQString &subject ); - - /** - * Invokes the standard email application. - * - * @param mailtoURL A mailto URL. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @param allowAttachments whether attachments specified in mailtoURL should be honoured. - The default is false; do not honour requests for attachments. - */ - void invokeMailer( const KURL &mailtoURL, const TQCString& startup_id, bool allowAttachments ); - // KDE4 merge with above with allowAttachments = false - void invokeMailer( const KURL &mailtoURL, const TQCString& startup_id ); - // KDE4 merge with above with startup_id = "" - void invokeMailer( const KURL &mailtoURL ); - - /** - * Convenience method; invokes the standard email application. - * - * All parameters are optional. - * - * @param to The destination address. - * @param cc The Cc field - * @param bcc The Bcc field - * @param subject Subject string - * @param body A string containing the body of the mail (exclusive with messageFile) - * @param messageFile A file (URL) containing the body of the mail (exclusive with body) - currently unsupported - * @param attachURLs List of URLs to be attached to the mail. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - */ - void invokeMailer(const TQString &to, const TQString &cc, const TQString &bcc, - const TQString &subject, const TQString &body, - const TQString &messageFile, const TQStringList &attachURLs, - const TQCString& startup_id ); - // KDE4 merge with above with startup_id = "" - void invokeMailer(const TQString &to, const TQString &cc, const TQString &bcc, - const TQString &subject, const TQString &body, - const TQString &messageFile = TQString::null, const TQStringList &attachURLs = TQStringList()); - -public slots: - /** - * Invokes the standard browser. - * Note that you should only do this when you know for sure that the browser can - * handle the URL (i.e. its mimetype). In doubt, if the URL can point to an image - * or anything else than directory or HTML, prefer to use new KRun( url ). - * - * @param url The destination address - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - */ - void invokeBrowser( const TQString &url, const TQCString& startup_id ); - // KDE4 merge with above with startup_id = "" - /** - * Invoke the standard browser. Uses a @p startup_id of "" (empty) - * and is otherwise the same as the above function. - */ - void invokeBrowser( const TQString &url ); - - /** - * If the widget with focus provides a cut() slot, call that slot. Thus for a - * simple application cut can be implemented as: - * \code - * KStdAction::cut( kapp, TQT_SLOT( cut() ), actionCollection() ); - * \endcode - */ - void cut(); - - /** - * If the widget with focus provides a copy() slot, call that slot. Thus for a - * simple application copy can be implemented as: - * \code - * KStdAction::copy( kapp, TQT_SLOT( copy() ), actionCollection() ); - * \endcode - */ - void copy(); - - /** - * If the widget with focus provides a paste() slot, call that slot. Thus for a - * simple application copy can be implemented as: - * \code - * KStdAction::paste( kapp, TQT_SLOT( paste() ), actionCollection() ); - * \endcode - */ - void paste(); - - /** - * If the widget with focus provides a clear() slot, call that slot. Thus for a - * simple application clear() can be implemented as: - * \code - * new TDEAction( i18n( "Clear" ), "editclear", 0, kapp, TQT_SLOT( clear() ), actionCollection(), "clear" ); - * \endcode - * - * Note that for some widgets, this may not provide the intended bahavior. For - * example if you make use of the code above and a TDEListView has the focus, clear() - * will clear all of the items in the list. If this is not the intened behavior - * and you want to make use of this slot, you can subclass TDEListView and reimplement - * this slot. For example the following code would implement a TDEListView without this - * behavior: - * - * \code - * class MyListView : public TDEListView { - * Q_OBJECT - * public: - * MyListView( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : TDEListView( parent, name, f ) {} - * virtual ~MyListView() {} - * public slots: - * virtual void clear() {} - * }; - * \endcode - */ - void clear(); - - /** - * If the widget with focus provides a selectAll() slot, call that slot. Thus for a - * simple application select all can be implemented as: - * \code - * KStdAction::selectAll( kapp, TQT_SLOT( selectAll() ), actionCollection() ); - * \endcode - */ - void selectAll(); - - /** - * Broadcast a received keycode to all listening KDE applications - * The primary use for this feature is to connect hotkeys such as - * XF86Display to their respective TDEGlobalAccel functions while - * the screen is locked by kdesktop_lock. - */ - void broadcastKeyCode(unsigned int keyCode); - -public: - /** - * Returns the DCOP name of the service launcher. This will be something like - * klaucher_$host_$uid. - * @return the name of the service launcher - */ - static TQCString launcher(); - - /** - * Starts a service based on the (translated) name of the service. - * E.g. "Web Browser" - * - * @param _name the name of the service - * @param URL if not empty this URL is passed to the service - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param dcopService On success, @p dcopService contains the DCOP name - * under which this service is available. If empty, the service does - * not provide DCOP services. If the pointer is 0 the argument - * will be ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @param noWait if set, the function does not wait till the service is running. - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int startServiceByName( const TQString& _name, const TQString &URL, - TQString *error=0, TQCString *dcopService=0, int *pid=0, const TQCString &startup_id = "", bool noWait = false ); - - /** - * Starts a service based on the (translated) name of the service. - * E.g. "Web Browser" - * - * @param _name the name of the service - * @param URLs if not empty these URLs will be passed to the service - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param dcopService On success, @p dcopService contains the DCOP name - * under which this service is available. If empty, the service does - * not provide DCOP services. If the pointer is 0 the argument - * will be ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @param noWait if set, the function does not wait till the service is running. - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int startServiceByName( const TQString& _name, const TQStringList &URLs=TQStringList(), - TQString *error=0, TQCString *dcopService=0, int *pid=0, const TQCString &startup_id = "", bool noWait = false ); - - /** - * Starts a service based on the desktop path of the service. - * E.g. "Applications/konqueror.desktop" or "/home/user/bla/myfile.desktop" - * - * @param _name the path of the desktop file - * @param URL if not empty this URL is passed to the service - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param dcopService On success, @p dcopService contains the DCOP name - * under which this service is available. If empty, the service does - * not provide DCOP services. If the pointer is 0 the argument - * will be ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @param noWait if set, the function does not wait till the service is running. - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int startServiceByDesktopPath( const TQString& _name, const TQString &URL, - TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); - - /** - * Starts a service based on the desktop path of the service. - * E.g. "Applications/konqueror.desktop" or "/home/user/bla/myfile.desktop" - * - * @param _name the path of the desktop file - * @param URLs if not empty these URLs will be passed to the service - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param dcopService On success, @p dcopService contains the DCOP name - * under which this service is available. If empty, the service does - * not provide DCOP services. If the pointer is 0 the argument - * will be ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @param noWait if set, the function does not wait till the service is running. - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int startServiceByDesktopPath( const TQString& _name, const TQStringList &URLs=TQStringList(), - TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); - - /** - * Starts a service based on the desktop name of the service. - * E.g. "konqueror" - * - * @param _name the desktop name of the service - * @param URL if not empty this URL is passed to the service - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param dcopService On success, @p dcopService contains the DCOP name - * under which this service is available. If empty, the service does - * not provide DCOP services. If the pointer is 0 the argument - * will be ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @param noWait if set, the function does not wait till the service is running. - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int startServiceByDesktopName( const TQString& _name, const TQString &URL, - TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); - - /** - * Starts a service based on the desktop name of the service. - * E.g. "konqueror" - * - * @param _name the desktop name of the service - * @param URLs if not empty these URLs will be passed to the service - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param dcopService On success, @p dcopService contains the DCOP name - * under which this service is available. If empty, the service does - * not provide DCOP services. If the pointer is 0 the argument - * will be ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @param noWait if set, the function does not wait till the service is running. - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int startServiceByDesktopName( const TQString& _name, const TQStringList &URLs=TQStringList(), - TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); - - /** - * Starts a program via tdeinit. - * - * program name and arguments are converted to according to the - * local encoding and passed as is to tdeinit. - * - * @param name Name of the program to start - * @param args Arguments to pass to the program - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int tdeinitExec( const TQString& name, const TQStringList &args, - TQString *error, int *pid, const TQCString& startup_id ); - // KDE4 merge with above with startup_id = "" - static int tdeinitExec( const TQString& name, const TQStringList &args=TQStringList(), - TQString *error=0, int *pid = 0 ); - - /** - * Starts a program via tdeinit and wait for it to finish. - * - * Like tdeinitExec(), but it waits till the program is finished. - * As such it behaves similar to the system(...) function. - * - * @param name Name of the program to start - * @param args Arguments to pass to the program - * @param error On failure, @p error contains a description of the error - * that occurred. If the pointer is 0, the argument will be - * ignored - * @param pid On success, the process id of the new service will be written - * here. If the pointer is 0, the argument will be ignored. - * @param startup_id for app startup notification, "0" for none, - * "" ( empty string ) is the default - * @return an error code indicating success (== 0) or failure (> 0). - */ - static int tdeinitExecWait( const TQString& name, const TQStringList &args, - TQString *error, int *pid, const TQCString& startup_id ); - // KDE4 merge with above with startup_id = "" - static int tdeinitExecWait( const TQString& name, const TQStringList &args=TQStringList(), - TQString *error=0, int *pid = 0 ); - - /** - * Returns a text for the window caption. - * - * This may be set by - * "-caption", otherwise it will be equivalent to the name of the - * executable. - * @return the text for the window caption - */ - TQString caption() const; - - /** - * @deprecated - */ - KDE_DEPRECATED TDEStyle* kstyle() const { return 0; } - - /** - * Builds a caption that contains the application name along with the - * userCaption using a standard layout. - * - * To make a compliant caption - * for your window, simply do: @p setCaption(kapp->makeStdCaption(yourCaption)); - * - * @param userCaption The caption string you want to display in the - * window caption area. Do not include the application name! - * @param withAppName Indicates that the method shall include or ignore - * the application name when making the caption string. You are not - * compliant if you set this to @p false. - * @param modified If true, a 'modified' sign will be included in the - * returned string. This is useful when indicating that a file is - * modified, i.e., it contains data that has not been saved. - * @return the created caption - */ - TQString makeStdCaption( const TQString &userCaption, - bool withAppName=true, bool modified=false ) const; - - /** - * Get a file name in order to make a temporary copy of your document. - * - * @param pFilename The full path to the current file of your - * document. - * @return A new filename for auto-saving. - */ - TQString tempSaveName( const TQString& pFilename ) const; - - /** - * Check whether an auto-save file exists for the document you want to - * open. - * - * @param pFilename The full path to the document you want to open. - * @param bRecover This gets set to true if there was a recover - * file. - * @return The full path of the file to open. - */ - TQString checkRecoverFile( const TQString& pFilename, bool& bRecover ) const; - -#if defined(Q_WS_X11) - /** - * @internal - * Get the X11 display - * @return the X11 Display - */ - Display *getDisplay() { return display; } -#endif - - /** - * @internal - * Gets X11 composition information - */ - void getX11RGBAInformation(Display *dpy); - - /** - * Gets the availability of a composition manager such as kompmgr - * Note that at least one application must have called detectCompositionManagerAvailable - * while the current X display was active in order for this method to return valid results. - * @see detectCompositionManagerAvailable() - * @return whether the composition manager is enabled - */ - static bool isCompositionManagerAvailable(); - - /** - * Detects the availability of a composition manager such as kompmgr - * Note that calling this method will probably cause the screen to flicker. - * @see isCompositionManagerAvailable() - * @param force_available If set, force TDE to assume a composition manager is available - * @param available Whether or not the composition manager is available (only used if force_available is TRUE) - * @return whether the composition manager is enabled - */ - bool detectCompositionManagerAvailable(bool force_available=false, bool available=true); - - /** - * @internal - * Opens the display - * This can be used to initialize a TDEApplication with RGBA support like this: - * TDEApplication app(TDEApplication::openX11RGBADisplay()); - * or - * TDEApplication app(TDEApplication::openX11RGBADisplay(), useStyles); - */ - static Display* openX11RGBADisplay(); - - /** - * Returns the X11 display visual - * - * @return A pointer to the X11 display visual - */ - Qt::HANDLE getX11RGBAVisual(Display *dpy); - - /** - * Returns the X11 display colormap - * - * @return An X11 display colormap object - */ - Qt::HANDLE getX11RGBAColormap(Display *dpy); - - /** - * Returns whether or not X11 composition is available - * - * You must first call getX11RGBAInformation() - * - * Note that getX11RGBAInformation() has already - * been called if you used the default TDEApplication - * constructor. - * - * Additionally, at least one application must have called - * detectCompositionManagerAvailable while the current X - * display was active in order for this method to return - * valid results. - * - * @return true if composition is available - */ - bool isX11CompositionAvailable(); - - /** - * Enables style plugins. - * - * This is useful only to applications that normally - * do not display a GUI and create the TDEApplication with - * allowStyles set to false. - */ - void enableStyles(); - - /** - * Disables style plugins. - * - * Current style plugins do not get unloaded. - * - * This is only useful when used in combination with enableStyles(). - */ - void disableStyles(); - - /** - * Installs widget filter as global X11 event filter. - * - * The widget - * filter receives XEvents in its standard TQWidget::x11Event() function. - * - * Warning: Only do this when absolutely necessary. An installed X11 filter - * can slow things down. - **/ - void installX11EventFilter( TQWidget* filter ); - - /** - * Removes global X11 event filter previously installed by - * installX11EventFilter(). - */ - void removeX11EventFilter( const TQWidget* filter ); - - /** - * Generates a uniform random number. - * @return A truly unpredictable number in the range [0, RAND_MAX) - */ - static int random(); - - /** - * Generates a random string. It operates in the range [A-Za-z0-9] - * @param length Generate a string of this length. - * @return the random string - */ - static TQString randomString(int length); - - /** - * Adds a message type to the KIPC event mask. You can only add "system - * messages" to the event mask. These are the messages with id < 32. - * Messages with id >= 32 are user messages. - * @param id The message id. See KIPC::Message. - * @see KIPC - * @see removeKipcEventMask() - * @see kipcMessage() - */ - void addKipcEventMask(int id); - - /** - * Removes a message type from the KIPC event mask. This message will - * not be handled anymore. - * @param id The message id. - * @see KIPC - * @see addKipcEventMask() - * @see kipcMessage() - */ - void removeKipcEventMask(int id); - - /** - * Returns the app startup notification identifier for this running - * application. - * @return the startup notification identifier - */ - TQCString startupId() const; - - /** - * @internal - * Sets a new value for the application startup notification window property for newly - * created toplevel windows. - * @param startup_id the startup notification identifier - * @see TDEStartupInfo::setNewStartupId - */ - void setStartupId( const TQCString& startup_id ); - - /** - * Updates the last user action timestamp to the given time, or to the current time, - * if 0 is given. Do not use unless you're really sure what you're doing. - * Consult focus stealing prevention section in tdebase/twin/README. - * @since 3.2 - */ - void updateUserTimestamp( unsigned long time = 0 ); - - /** - * Returns the last user action timestamp or 0 if no user activity has taken place yet. - * @since 3.2.3 - * @see updateuserTimestamp - */ - unsigned long userTimestamp() const; - - /** - * Updates the last user action timestamp in the application registered to DCOP with dcopId - * to the given time, or to this application's user time, if 0 is given. - * Use before causing user interaction in the remote application, e.g. invoking a dialog - * in the application using a DCOP call. - * Consult focus stealing prevention section in tdebase/twin/README. - * @since 3.3 - */ - void updateRemoteUserTimestamp( const TQCString& dcopId, unsigned long time = 0 ); - - /** - * Returns the argument to --geometry if any, so the geometry can be set - * wherever necessary - * @return the geometry argument, or TQString::null if there is none - */ - TQString geometryArgument() const; - - /** - * Install a Qt SQL property map with entries for all KDE widgets - * Call this in any application using KDE widgets in TQSqlForm or TQDataView. - */ - void installKDEPropertyMap(); - - /** - * Returns whether a certain action is authorized - * @param genericAction The name of a generic action - * @return true if the action is authorized - */ - bool authorize(const TQString &genericAction); - - /** - * Returns whether a certain TDEAction is authorized. - * - * @param action The name of a TDEAction action. The name is prepended - * with "action/" before being passed to authorize() - * @return true if the TDEAction is authorized - */ - bool authorizeTDEAction(const char *action); - - /** - * Returns whether a certain URL related action is authorized. - * - * @param action The name of the action. Known actions are - * list (may be listed (e.g. in file selection dialog)), - * link (may be linked to), - * open (may open) and - * redirect (may be redirected to) - * @param baseURL The url where the action originates from - * @param destURL The object of the action - * @return true when the action is authorized, false otherwise. - * @since 3.1 - */ - bool authorizeURLAction(const TQString &action, const KURL &baseURL, const KURL &destURL); - - /** - * Allow a certain URL action. This can be useful if your application - * needs to ensure access to an application specific directory that may - * otherwise be subject to KIOSK restrictions. - * @param action The name of the action. - * @param _baseURL The url where the action originates from - * @param _destURL The object of the action - * @since 3.2 - */ - void allowURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL); - - /** - * Returns whether access to a certain control module is authorized. - * - * @param menuId identifying the control module, e.g. tde-mouse.desktop - * @return true if access to the module is authorized, false otherwise. - * @since 3.2 - */ - bool authorizeControlModule(const TQString &menuId); - - /** - * Returns whether access to a certain control modules is authorized. - * - * @param menuIds list of menu-ids of control module, - * an example of a menu-id is tde-mouse.desktop. - * @return Those control modules for which access has been authorized. - * @since 3.2 - */ - TQStringList authorizeControlModules(const TQStringList &menuIds); - - /** - * Returns the state of the currently pressed keyboard modifiers (e.g. shift, control, etc.) - * and mouse buttons, similarly to TQKeyEvent::state() and TQMouseEvent::state(). - * You usually should simply use the information provided by TQKeyEvent and TQMouseEvent, - * but it can be useful to query for the status of the modifiers at another moment - * (e.g. some KDE apps do that upon a drop event). - * @return the keyboard modifiers and mouse buttons state - * @since 3.4 - */ - static ButtonState keyboardMouseState(); - - // Same values as ShiftMask etc. in X.h - enum { ShiftModifier = 1<<0, - LockModifier = 1<<1, - ControlModifier = 1<<2, - Modifier1 = 1<<3, - Modifier2 = 1<<4, - Modifier3 = 1<<5, - Modifier4 = 1<<6, - Modifier5 = 1<<7 }; - /** - * @deprecated Use keyboardMouseState() - * @since 3.1 - */ - static uint keyboardModifiers() KDE_DEPRECATED; - - /** @deprecated Same values as Button1Mask etc. in X.h */ - enum { Button1Pressed = 1<<8, - Button2Pressed = 1<<9, - Button3Pressed = 1<<10, - Button4Pressed = 1<<11, - Button5Pressed = 1<<12 }; - /** - * @deprecated Use keyboardMouseState() - * @since 3.1 - */ - static uint mouseState() KDE_DEPRECATED; - - -public slots: - /** - * Tells TDEApplication about one more operation that should be finished - * before the application exits. The standard behavior is to exit on the - * "last window closed" event, but some events should outlive the last window closed - * (e.g. a file copy for a file manager, or 'compacting folders on exit' for a mail client). - */ - void ref(); - - /** - * Tells TDEApplication that one operation such as those described in ref() just finished. - * The application exits if the counter is back to 0. - */ - void deref(); - -protected: - /** - * @internal Used by KUniqueApplication - */ - TDEApplication( bool allowStyles, bool GUIenabled, TDEInstance* _instance ); - -#ifdef Q_WS_X11 - /** - * @internal Used by KUniqueApplication - */ - TDEApplication( Display *display, Qt::HANDLE visual, Qt::HANDLE colormap, - bool allowStyles, TDEInstance* _instance ); - - /** - * Used to catch X11 events - */ - bool x11EventFilter( XEvent * ); - - Display *display; -#endif - Atom kipcCommAtom; - int kipcEventMask; - - /// Current application object. - static TDEApplication *KApp; - int pArgc; - - /** - * This method is used internally to determine which edit slots are implemented - * by the widget that has the focus, and to invoke those slots if available. - * - * @param slot is the slot as returned using the TQT_SLOT() macro, for example TQT_SLOT( cut() ) - * - * This method can be used in TDEApplication subclasses to implement application wide - * edit actions not supported by the TDEApplication class. For example (in your subclass): - * - * \code - * void MyApplication::deselect() - * { - * invokeEditSlot( TQT_SLOT( deselect() ) ); - * } - * \endcode - * - * Now in your application calls to MyApplication::deselect() will call this slot on the - * focused widget if it provides this slot. You can combine this with TDEAction with: - * - * \code - * KStdAction::deselect( static_cast<MyApplication *>( kapp ), TQT_SLOT( cut() ), actionCollection() ); - * \endcode - * - * @see cut() - * @see copy() - * @see paste() - * @see clear() - * @see selectAll() - * - * @since 3.2 - */ - void invokeEditSlot( const char *slot ); - -private slots: - void dcopFailure(const TQString &); - void dcopBlockUserInput( bool ); - void x11FilterDestroyed(); - void checkAppStartedSlot(); - -private: - TQString sessionConfigName() const; - TDEConfig* pSessionConfig; //instance specific application config object - static DCOPClient *s_DCOPClient; // app specific application communication client - static bool s_dcopClientNeedsPostInit; - TQString aCaption; // the name for the window title - bool bSessionManagement; - struct oldPixmapType { TQPixmap a, b; }; - mutable union { - struct { - TQPixmap *icon, *miniIcon; - } pm; - char unused[sizeof(oldPixmapType)]; - } aIconPixmap; // KDE4: remove me - TQString aIconName; - TQString aMiniIconName; - bool useStyles; - TQWidget *smw; - - void init( bool GUIenabled ); - - void parseCommandLine( ); // Handle KDE arguments (Using TDECmdLineArgs) - - void read_app_startup_id(); - - void dcopAutoRegistration(); - void dcopClientPostInit(); - void initUrlActionRestrictions(); - - bool argb_visual; -#if defined(Q_WS_X11) - Qt::HANDLE argb_x11_visual; - Qt::HANDLE argb_x11_colormap; -#endif - -public: - /** - * @internal - */ - bool notify(TQObject *receiver, TQEvent *event); - - /** - @internal - */ - int xErrhandler( Display*, void* ); - - /** - @internal - */ - int xioErrhandler( Display* ); - - /** - * @internal - */ - void iceIOErrorHandler( _IceConn *conn ); - - /** - * @internal - */ - static bool loadedByKdeinit; - - /** - * @internal - */ - static void startKdeinit(); - - /** - * Valid values for the settingsChanged signal - */ - enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS, - SETTINGS_POPUPMENU, SETTINGS_QT, SETTINGS_SHORTCUTS }; - - /** - * Used to obtain the TQPalette that will be used to set the application palette. - * - * This is only useful for configuration modules such as krdb and should not be - * used in normal circumstances. - * @return the QPalette - * @since 3.1 - */ - static TQPalette createApplicationPalette(); - - /** - * @internal - * Raw access for use by TDM. - */ - static TQPalette createApplicationPalette( TDEConfig *config, int contrast ); - - /** - * Installs a handler for the SIGPIPE signal. It is thrown when you write to - * a pipe or socket that has been closed. - * The handler is installed automatically in the constructor, but you may - * need it if your application or component does not have a TDEApplication - * instance. - */ - static void installSigpipeHandler(); - - /** - * @internal - * Whether widgets can be used. - * - * @since 3.2 - */ - static bool guiEnabled(); - -signals: - /** - * Emitted when TDEApplication has changed its palette due to a KControl request. - * - * Normally, widgets will update their palette automatically, but you - * should connect to this to program special behavior. - */ - void tdedisplayPaletteChanged(); - - /** - * Emitted when TDEApplication has changed its GUI style in response to a KControl request. - * - * Normally, widgets will update their styles automatically (as they would - * respond to an explicit setGUIStyle() call), but you should connect to - * this to program special behavior. - */ - void tdedisplayStyleChanged(); - - /** - * Emitted when TDEApplication has changed its font in response to a KControl request. - * - * Normally widgets will update their fonts automatically, but you should - * connect to this to monitor global font changes, especially if you are - * using explicit fonts. - * - * Note: If you derive from a QWidget-based class, a faster method is to - * reimplement TQWidget::fontChange(). This is the preferred way - * to get informed about font updates. - */ - void tdedisplayFontChanged(); - - /** - * Emitted when TDEApplication has changed either its GUI style, its font or its palette - * in response to a tdedisplay request. Normally, widgets will update their styles - * automatically, but you should connect to this to program special - * behavior. */ - void appearanceChanged(); - - /** - * Emitted when the settings for toolbars have been changed. TDEToolBar will know what to do. - */ - void toolbarAppearanceChanged(int); - - /** - * Emitted when the desktop background has been changed by @p kcmdisplay. - * - * @param desk The desktop whose background has changed. - */ - void backgroundChanged(int desk); - - /** - * Emitted when the global settings have been changed - see TDEGlobalSettings - * TDEApplication takes care of calling reparseConfiguration on TDEGlobal::config() - * so that applications/classes using this only have to re-read the configuration - * @param category the category among the enum above - */ - void settingsChanged(int category); - - /** - * Emitted when the global icon settings have been changed. - * @param group the new group - */ - void iconChanged(int group); - - /** - * Emitted when a KIPC user message has been received. - * @param id the message id - * @param data the data - * @see KIPC - * @see KIPC::Message - * @see addKipcEventMask - * @see removeKipcEventMask - */ - void kipcMessage(int id, int data); - - /** - Session management asks you to save the state of your application. - - This signal is provided for compatibility only. For new - applications, simply use TDEMainWindow. By reimplementing - TDEMainWindow::queryClose(), TDEMainWindow::saveProperties() and - TDEMainWindow::readProperties() you can simply handle session - management for applications with multiple toplevel windows. - - For purposes without TDEMainWindow, create an instance of - KSessionManaged and reimplement the functions - KSessionManaged::commitData() and/or - KSessionManaged::saveState() - - If you still want to use this signal, here is what you should do: - - Connect to this signal in order to save your data. Do NOT - manipulate the UI in that slot, it is blocked by the session - manager. - - Use the sessionConfig() TDEConfig object to store all your - instance specific data. - - Do not do any closing at this point! The user may still select - Cancel wanting to continue working with your - application. Cleanups could be done after shutDown() (see - the following). - - */ - void saveYourself(); - - /** Your application is killed. Either by your program itself, - @p xkill or (the usual case) by KDE's logout. - - The signal is particularly useful if your application has to do some - last-second cleanups. Note that no user interaction is possible at - this state. - */ - void shutDown(); - - /** - * @internal - * Used to notify TDEIconLoader objects that they need to reload. - */ - void updateIconLoaders(); - - /** - * @internal - * Used to send TDEGlobalAccel objects a new keypress from physical hotkeys. - */ - void coreFakeKeyPress(unsigned int keyCode); - -private: - void propagateSettings(SettingsCategory category); - void tdedisplaySetPalette(); - void tdedisplaySetStyle(); - void tdedisplaySetFont(); - void applyGUIStyle(); - static void sigpipeHandler(int); - - int captionLayout; - - TDEApplication(const TDEApplication&); - TDEApplication& operator=(const TDEApplication&); -protected: - virtual void virtual_hook( int id, void* data ); -private: - TDEApplicationPrivate* d; -}; - - -/** - * \relates TDEGlobal - * Check, if a file may be accessed in a given mode. - * This is a wrapper around the access() system call. - * checkAccess() calls access() with the given parameters. - * If this is OK, checkAccess() returns true. If not, and W_OK - * is part of mode, it is checked if there is write access to - * the directory. If yes, checkAccess() returns true. - * In all other cases checkAccess() returns false. - * - * Other than access() this function EXPLICITLY ignores non-existant - * files if checking for write access. - * - * @param pathname The full path of the file you want to test - * @param mode The access mode, as in the access() system call. - * @return Whether the access is allowed, true = Access allowed - */ -TDECORE_EXPORT bool checkAccess(const TQString& pathname, int mode); - -class KSessionManagedPrivate; - -/** - Provides highlevel access to session management on a per-object - base. - - KSessionManaged makes it possible to provide implementations for - TQApplication::commitData() and TQApplication::saveState(), without - subclassing TDEApplication. TDEMainWindow internally makes use of this. - - You don't need to do anything with this class when using - TDEMainWindow. Instead, use TDEMainWindow::saveProperties(), - TDEMainWindow::readProperties(), TDEMainWindow::queryClose(), - TDEMainWindow::queryExit() and friends. - - @short Highlevel access to session management. - @author Matthias Ettrich <ettrich@kde.org> - */ -class TDECORE_EXPORT KSessionManaged -{ -public: - KSessionManaged(); - virtual ~KSessionManaged(); - - /** - See TQApplication::saveState() for documentation. - - This function is just a convenience version to avoid subclassing TDEApplication. - - Return true to indicate a successful state save or false to - indicate a problem and to halt the shutdown process (will - implicitly call sm.cancel() ). - */ - virtual bool saveState( TQSessionManager& sm ); - /** - See TQApplication::commitData() for documentation. - - This function is just a convenience version to avoid subclassing TDEApplication. - - Return true to indicate a successful commit of data or false to - indicate a problem and to halt the shutdown process (will - implicitly call sm.cancel() ). - */ - virtual bool commitData( TQSessionManager& sm ); - -protected: - virtual void virtual_hook( int id, void* data ); -private: - KSessionManagedPrivate *d; -}; - - -#endif - diff --git a/tdecore/kapplication_win.cpp b/tdecore/kapplication_win.cpp index cd7145ac7..940bc379e 100644 --- a/tdecore/kapplication_win.cpp +++ b/tdecore/kapplication_win.cpp @@ -17,7 +17,7 @@ Boston, MA 02110-1301, USA. */ -#include <kapplication.h> +#include <tdeapplication.h> #include <kstandarddirs.h> #include <klocale.h> #include <kurl.h> diff --git a/tdecore/kcharsets.cpp b/tdecore/kcharsets.cpp index 17617bf9e..fa623b693 100644 --- a/tdecore/kcharsets.cpp +++ b/tdecore/kcharsets.cpp @@ -21,7 +21,7 @@ #include "kqiodevicegzip_p.h" #include "kentities.c" -#include <kapplication.h> +#include <tdeapplication.h> #include <kglobal.h> #include <klocale.h> #include <tdeconfig.h> diff --git a/tdecore/kclipboard.cpp b/tdecore/kclipboard.cpp index 53865a2c2..54d051486 100644 --- a/tdecore/kclipboard.cpp +++ b/tdecore/kclipboard.cpp @@ -16,7 +16,7 @@ Boston, MA 02110-1301, USA. */ -#include <kapplication.h> +#include <tdeapplication.h> #include <tdeconfig.h> #include <kglobal.h> diff --git a/tdecore/kcmdlineargs.cpp b/tdecore/kcmdlineargs.cpp deleted file mode 100644 index a1d3adcf9..000000000 --- a/tdecore/kcmdlineargs.cpp +++ /dev/null @@ -1,1298 +0,0 @@ -/* - 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 <tqdir.h> -#include <tqfile.h> -#include <tqasciidict.h> -#include <tqstrlist.h> - -#include "kcmdlineargs.h" -#include <kaboutdata.h> -#include <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 TQAsciiDict<TQCString>; -template class TQPtrList<TDECmdLineArgs>; - -class TDECmdLineParsedOptions : public TQAsciiDict<TQCString> -{ -public: - TDECmdLineParsedOptions() - : TQAsciiDict<TQCString>( 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<TDECmdLineArgs> -{ -public: - TDECmdLineArgsList() { } -}; - -TDECmdLineArgsList *TDECmdLineArgs::argsList = 0; -int TDECmdLineArgs::argc = 0; -char **TDECmdLineArgs::argv = 0; -char *TDECmdLineArgs::mCwd = 0; -static KStaticDeleter <char> 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); - (void) getcwd(mCwd, PATH_MAX); -#ifdef Q_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 Qt and TDE options. - removeArgs("qt"); - removeArgs("tde"); - - 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) -{ - parsed = true; // don't reparse argc/argv! - - // Remove Qt and TDE options. - removeArgs("qt"); - removeArgs("tde"); - - 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; - int p = nextOption.find(' '); - if (p > 0) - nextOption = nextOption.left(p); - if (nextOption[0] == '!') - nextOption = nextOption.mid(1); - 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; - int j = opt.find('='); - 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, (const char*)argument); - 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, (const char*)argument); - } - else - { - args->setOption(opt, enabled); - } -} - -void -TDECmdLineArgs::printQ(const TQString &msg) -{ - TQCString localMsg = msg.local8Bit(); - 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("Qt: %1\n").arg(tqVersion())); - printQ( TQString("TDE: %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<TDEAboutPerson> authors = about->authors(); - if ( !authors.isEmpty() ) { - TQString authorlist; - for (TQValueList<TDEAboutPerson>::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("This application was written by somebody who wants to remain anonymous.") ); - } - if (about) - { - if (!about->customAuthorTextEnabled ()) - { - if (about->bugAddress().isEmpty() || about->bugAddress() == "bugs.pearsoncomputing.net" ) - printQ( i18n( "Please use http://bugs.pearsoncomputing.net to report bugs.\n" ) ); - else { - if( about->authors().count() == 1 && about->authors().first().emailAddress() == about->bugAddress() ) - printQ( i18n( "Please report bugs to %1.\n" ).arg( about->authors().first().emailAddress() ) ); - else - printQ( i18n( "Please report bugs to %1.\n" ).arg(about->bugAddress()) ); - } - } - else - { - printQ(about->customAuthorPlainText()); - } - } - 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); - TQCString localError = error.local8Bit(); - 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."); - localError = tmp.local8Bit(); - 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); - dl = TQStringList::split("\n", description, true); - description = dl.first(); - dl.remove( 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(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(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; - isQt = (::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 (isQt) - { - // Qt 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 (isQt) - { - // Qt does it's own parsing. - TQCString 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 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) -{ - const TQString urlArg = TQFile::decodeName(_urlArg); - TQFileInfo fileInfo(urlArg); - if (!fileInfo.isRelative()) { // i.e. starts with '/', on unix - KURL result; - result.setPath(urlArg); - return result; // Absolute path. - } - - if ( KURL::isRelativeURL(urlArg) || fileInfo.exists() ) { - KURL result; - result.setPath( cwd()+'/'+urlArg ); - result.cleanPath(); - return result; // Relative path - } - - return KURL(urlArg); // Argument is a URL -} - -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, "TDE-tempfile", "tde-tempfile" ); -} - -bool TDECmdLineArgs::isTempFileSet() -{ - TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs( "tde-tempfile" ); - if ( args ) - return args->isSet( "tempfile" ); - return false; -} diff --git a/tdecore/kcmdlineargs.h b/tdecore/kcmdlineargs.h deleted file mode 100644 index 9b7dc0f4f..000000000 --- a/tdecore/kcmdlineargs.h +++ /dev/null @@ -1,690 +0,0 @@ -/* 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 "tdelibs_export.h" -#include <kurl.h> - -#include <tqptrlist.h> -#include <tqstring.h> -#include <tqvaluelist.h> - -typedef TQValueList<TQCString> 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 <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 - * TDECmdLineArgs::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 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 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 %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 \<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 }, - * 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<TDECmdLineArgs>; -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 \<argument>", 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 \<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 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 - * 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 \<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. - */ - 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 \<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 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 Qt 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 isQt; - - 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/tdecore/kcompletion.cpp b/tdecore/kcompletion.cpp index 730eadbf9..a5349b3ee 100644 --- a/tdecore/kcompletion.cpp +++ b/tdecore/kcompletion.cpp @@ -18,7 +18,7 @@ */ -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <klocale.h> #include <knotifyclient.h> diff --git a/tdecore/kcrash.cpp b/tdecore/kcrash.cpp index 05f502311..2eed7c282 100644 --- a/tdecore/kcrash.cpp +++ b/tdecore/kcrash.cpp @@ -46,9 +46,9 @@ #include <tqwindowdefs.h> #include <kglobal.h> #include <kinstance.h> -#include <kaboutdata.h> +#include <tdeaboutdata.h> #include <kdebug.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <dcopclient.h> #include <../kinit/tdelauncher_cmds.h> diff --git a/tdecore/kdebug.cpp b/tdecore/kdebug.cpp index 27dcf1418..062864fca 100644 --- a/tdecore/kdebug.cpp +++ b/tdecore/kdebug.cpp @@ -27,7 +27,7 @@ #include "kdebugdcopiface.h" -#include "kapplication.h" +#include "tdeapplication.h" #include "kglobal.h" #include "kinstance.h" #include "kstandarddirs.h" diff --git a/tdecore/kdesktopfile.cpp b/tdecore/kdesktopfile.cpp index 41d7a3d41..a5a57cdd8 100644 --- a/tdecore/kdesktopfile.cpp +++ b/tdecore/kdesktopfile.cpp @@ -31,7 +31,7 @@ #include <kdebug.h> #include "kurl.h" #include "tdeconfigbackend.h" -#include "kapplication.h" +#include "tdeapplication.h" #include "kstandarddirs.h" #include "kmountpoint.h" #include "kcatalogue.h" diff --git a/tdecore/kdetcompmgr.cpp b/tdecore/kdetcompmgr.cpp index 1c7a6f1c3..d78d76b34 100644 --- a/tdecore/kdetcompmgr.cpp +++ b/tdecore/kdetcompmgr.cpp @@ -21,9 +21,9 @@ #include <stdio.h> #include <stdlib.h> -#include <kapplication.h> -#include <kaboutdata.h> -#include <kcmdlineargs.h> +#include <tdeapplication.h> +#include <tdeaboutdata.h> +#include <tdecmdlineargs.h> #include <klocale.h> #include <kdebug.h> #include <tdeconfig.h> diff --git a/tdecore/kglobal.cpp b/tdecore/kglobal.cpp index 107d3317e..965a537a3 100644 --- a/tdecore/kglobal.cpp +++ b/tdecore/kglobal.cpp @@ -27,8 +27,8 @@ #include <tqptrlist.h> #include "kglobal.h" -#include <kapplication.h> -#include <kaboutdata.h> +#include <tdeapplication.h> +#include <tdeaboutdata.h> #include <kdebug.h> #include <tdeconfig.h> #include <klocale.h> diff --git a/tdecore/kglobalaccel_win.cpp b/tdecore/kglobalaccel_win.cpp index 0393bdd8d..09c216b99 100644 --- a/tdecore/kglobalaccel_win.cpp +++ b/tdecore/kglobalaccel_win.cpp @@ -31,7 +31,7 @@ #include <tqwidget.h> #include <tqmetaobject.h> #include <private/qucomextra_p.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <kkeynative.h> diff --git a/tdecore/kglobalaccel_x11.cpp b/tdecore/kglobalaccel_x11.cpp index 64af90572..2a67c73b5 100644 --- a/tdecore/kglobalaccel_x11.cpp +++ b/tdecore/kglobalaccel_x11.cpp @@ -31,7 +31,7 @@ #include <tqwidget.h> #include <tqmetaobject.h> #include <tqucomextra_p.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <kkeynative.h> diff --git a/tdecore/kglobalsettings.cpp b/tdecore/kglobalsettings.cpp index d7006b37a..a103c4652 100644 --- a/tdecore/kglobalsettings.cpp +++ b/tdecore/kglobalsettings.cpp @@ -25,7 +25,7 @@ #include <tdeconfig.h> #include <ksimpleconfig.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kipc.h> diff --git a/tdecore/kiconloader.cpp b/tdecore/kiconloader.cpp index 5938331cd..be44a921f 100644 --- a/tdecore/kiconloader.cpp +++ b/tdecore/kiconloader.cpp @@ -26,7 +26,7 @@ #include <tqmovie.h> #include <tqbitmap.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kipc.h> #include <kdebug.h> #include <kstandarddirs.h> diff --git a/tdecore/kinstance.cpp b/tdecore/kinstance.cpp index 749979750..cf0b35791 100644 --- a/tdecore/kinstance.cpp +++ b/tdecore/kinstance.cpp @@ -26,7 +26,7 @@ #include "kiconloader.h" #include "tdehardwaredevices.h" #include "tdenetworkconnections.h" -#include "kaboutdata.h" +#include "tdeaboutdata.h" #include "kstandarddirs.h" #include "kdebug.h" #include "kglobal.h" diff --git a/tdecore/klibloader.cpp b/tdecore/klibloader.cpp index b7cad0fbe..f7e63c215 100644 --- a/tdecore/klibloader.cpp +++ b/tdecore/klibloader.cpp @@ -25,7 +25,7 @@ #include <tqtimer.h> #include <tqobjectdict.h> -#include "kapplication.h" +#include "tdeapplication.h" #include "klibloader.h" #include "kstandarddirs.h" #include "kdebug.h" diff --git a/tdecore/klockfile.cpp b/tdecore/klockfile.cpp index 8b4a991ce..ee09a06c8 100644 --- a/tdecore/klockfile.cpp +++ b/tdecore/klockfile.cpp @@ -37,8 +37,8 @@ #include <tqtextstream.h> #include <kde_file.h> -#include <kapplication.h> -#include <kcmdlineargs.h> +#include <tdeapplication.h> +#include <tdecmdlineargs.h> #include <kglobal.h> #include <ktempfile.h> diff --git a/tdecore/kmanagerselection.cpp b/tdecore/kmanagerselection.cpp index 15e273d6d..2e019f73e 100644 --- a/tdecore/kmanagerselection.cpp +++ b/tdecore/kmanagerselection.cpp @@ -47,7 +47,7 @@ DEALINGS IN THE SOFTWARE. #include <kdebug.h> #include <tqwidget.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kxerrorhandler.h> #include <X11/Xatom.h> diff --git a/tdecore/knotifyclient.cpp b/tdecore/knotifyclient.cpp index 309be40f0..b6f70bd23 100644 --- a/tdecore/knotifyclient.cpp +++ b/tdecore/knotifyclient.cpp @@ -23,9 +23,9 @@ #include <tqdatastream.h> #include <tqptrstack.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kstandarddirs.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <tdeconfig.h> #include <dcopclient.h> #include <kdebug.h> diff --git a/tdecore/kprotocolinfo_tdecore.cpp b/tdecore/kprotocolinfo_tdecore.cpp index 088ea0363..8cc5091c5 100644 --- a/tdecore/kprotocolinfo_tdecore.cpp +++ b/tdecore/kprotocolinfo_tdecore.cpp @@ -27,7 +27,7 @@ #include <kstandarddirs.h> #include <kglobal.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <ksimpleconfig.h> #include <tdeconfig.h> diff --git a/tdecore/kprotocolinfofactory.cpp b/tdecore/kprotocolinfofactory.cpp index c651024ef..4daab08dd 100644 --- a/tdecore/kprotocolinfofactory.cpp +++ b/tdecore/kprotocolinfofactory.cpp @@ -19,7 +19,7 @@ #include <kstandarddirs.h> #include <kglobal.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <tdesycoca.h> #include <tdesycocadict.h> diff --git a/tdecore/krandomsequence.cpp b/tdecore/krandomsequence.cpp index 9529ccabb..8896db70b 100644 --- a/tdecore/krandomsequence.cpp +++ b/tdecore/krandomsequence.cpp @@ -21,7 +21,7 @@ #include <tqptrlist.h> #include "krandomsequence.h" -#include "kapplication.h" +#include "tdeapplication.h" const int KRandomSequence::m_nShuffleTableSize = 32; diff --git a/tdecore/krootprop.cpp b/tdecore/krootprop.cpp index cb0200c99..bb15462dd 100644 --- a/tdecore/krootprop.cpp +++ b/tdecore/krootprop.cpp @@ -26,7 +26,7 @@ #include "kglobal.h" #include "klocale.h" #include "kcharsets.h" -#include "kapplication.h" +#include "tdeapplication.h" #include <tqtextstream.h> #include <X11/Xlib.h> diff --git a/tdecore/ksavefile.cpp b/tdecore/ksavefile.cpp index fdf47daf9..4ad96c0f2 100644 --- a/tdecore/ksavefile.cpp +++ b/tdecore/ksavefile.cpp @@ -36,7 +36,7 @@ #include <tqdir.h> #include <kde_file.h> -#include "kapplication.h" +#include "tdeapplication.h" #include "ksavefile.h" #include "kstandarddirs.h" diff --git a/tdecore/ksimpledirwatch.cpp b/tdecore/ksimpledirwatch.cpp index 8454c7a74..f39a94221 100644 --- a/tdecore/ksimpledirwatch.cpp +++ b/tdecore/ksimpledirwatch.cpp @@ -43,7 +43,7 @@ #include <tqstringlist.h> #include <tqtimer.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <tdeconfig.h> #include <kglobal.h> diff --git a/tdecore/ksocks.cpp b/tdecore/ksocks.cpp index cc0cde8ca..95e36dc15 100644 --- a/tdecore/ksocks.cpp +++ b/tdecore/ksocks.cpp @@ -30,7 +30,7 @@ #include <kdebug.h> #include "klibloader.h" #include <tdeconfig.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <sys/types.h> #include <sys/socket.h> diff --git a/tdecore/kstartupinfo.cpp b/tdecore/kstartupinfo.cpp index 0eb0e91de..a472de5fd 100644 --- a/tdecore/kstartupinfo.cpp +++ b/tdecore/kstartupinfo.cpp @@ -55,7 +55,7 @@ DEALINGS IN THE SOFTWARE. #include <netwm.h> #endif #include <kdebug.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <signal.h> #ifdef Q_WS_X11 #include <twinmodule.h> diff --git a/tdecore/ktempdir.cpp b/tdecore/ktempdir.cpp index 69554fd86..53cc83f99 100644 --- a/tdecore/ktempdir.cpp +++ b/tdecore/ktempdir.cpp @@ -48,7 +48,7 @@ #include <tqdir.h> #include "kglobal.h" -#include "kapplication.h" +#include "tdeapplication.h" #include "kinstance.h" #include "ktempdir.h" #include "kstandarddirs.h" diff --git a/tdecore/ktempfile.cpp b/tdecore/ktempfile.cpp index 35d66f81c..973e14070 100644 --- a/tdecore/ktempfile.cpp +++ b/tdecore/ktempfile.cpp @@ -49,7 +49,7 @@ #include <tqtextstream.h> #include "kglobal.h" -#include "kapplication.h" +#include "tdeapplication.h" #include "kinstance.h" #include "ktempfile.h" #include "kstandarddirs.h" diff --git a/tdecore/kuniqueapplication.cpp b/tdecore/kuniqueapplication.cpp index fb8cda9fd..964c7c8c7 100644 --- a/tdecore/kuniqueapplication.cpp +++ b/tdecore/kuniqueapplication.cpp @@ -34,9 +34,9 @@ #include <tqtimer.h> #include <dcopclient.h> -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> #include <kstandarddirs.h> -#include <kaboutdata.h> +#include <tdeaboutdata.h> #if defined Q_WS_X11 #include <twin.h> diff --git a/tdecore/kuniqueapplication.h b/tdecore/kuniqueapplication.h index ede89ef19..3b7bd8d6e 100644 --- a/tdecore/kuniqueapplication.h +++ b/tdecore/kuniqueapplication.h @@ -21,7 +21,7 @@ #ifndef _KUNIQUEAPP_H #define _KUNIQUEAPP_H -#include <kapplication.h> +#include <tdeapplication.h> #include <dcopobject.h> class KUniqueApplicationPrivate; @@ -36,7 +36,7 @@ class KUniqueApplicationPrivate; * the information to the first instance and then quit. * * The .desktop file for the application should state X-DCOP-ServiceType=Unique, - * see kapplication.h + * see tdeapplication.h * * If your application is used to open files, it should also support the --tempfile * option (see TDECmdLineArgs::addTempFileOption()), to delete tempfiles after use. diff --git a/tdecore/kxmessages.cpp b/tdecore/kxmessages.cpp index 52781188f..116c74d1c 100644 --- a/tdecore/kxmessages.cpp +++ b/tdecore/kxmessages.cpp @@ -26,7 +26,7 @@ DEALINGS IN THE SOFTWARE. #include "kxmessages.h" -#include <kapplication.h> +#include <tdeapplication.h> #ifdef Q_WS_X11 // FIXME(E): Figure out what parts we can/should emulate in QT/E diff --git a/tdecore/network/kresolverstandardworkers.cpp b/tdecore/network/kresolverstandardworkers.cpp index dd5e33f23..cde24f752 100644 --- a/tdecore/network/kresolverstandardworkers.cpp +++ b/tdecore/network/kresolverstandardworkers.cpp @@ -46,7 +46,7 @@ #include "kdebug.h" #include "kglobal.h" #include "kstandarddirs.h" -#include "kapplication.h" +#include "tdeapplication.h" #include "kresolver.h" #include "tdesocketaddress.h" diff --git a/tdecore/network/ksockssocketdevice.cpp b/tdecore/network/ksockssocketdevice.cpp index c1649c340..69c674438 100644 --- a/tdecore/network/ksockssocketdevice.cpp +++ b/tdecore/network/ksockssocketdevice.cpp @@ -32,7 +32,7 @@ #define kde_socklen_t ksocklen_t #endif -#include "kapplication.h" +#include "tdeapplication.h" #include "ksocks.h" #include "tdesocketaddress.h" diff --git a/tdecore/tde-config.cpp.cmake b/tdecore/tde-config.cpp.cmake index e235c4f8c..98481cefe 100644 --- a/tdecore/tde-config.cpp.cmake +++ b/tdecore/tde-config.cpp.cmake @@ -1,15 +1,15 @@ // -*- c++ -*- -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> #include <klocale.h> #include <kinstance.h> #include <kstandarddirs.h> #include <kglobal.h> #include <kglobalsettings.h> #include <stdio.h> -#include <kaboutdata.h> +#include <tdeaboutdata.h> #include <config.h> -#include <kapplication.h> +#include <tdeapplication.h> static const char *description = I18N_NOOP("A little program to output installation paths"); diff --git a/tdecore/tde-config.cpp.in b/tdecore/tde-config.cpp.in index d44ccd6b5..ac49e5c41 100644 --- a/tdecore/tde-config.cpp.in +++ b/tdecore/tde-config.cpp.in @@ -1,15 +1,15 @@ // -*- c++ -*- -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> #include <klocale.h> #include <kinstance.h> #include <kstandarddirs.h> #include <kglobal.h> #include <kglobalsettings.h> #include <stdio.h> -#include <kaboutdata.h> +#include <tdeaboutdata.h> #include <config.h> -#include <kapplication.h> +#include <tdeapplication.h> static const char *description = I18N_NOOP("A little program to output installation paths"); diff --git a/tdecore/tdeaboutdata.cpp b/tdecore/tdeaboutdata.cpp new file mode 100644 index 000000000..bf8538152 --- /dev/null +++ b/tdecore/tdeaboutdata.cpp @@ -0,0 +1,512 @@ +/* + * 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 <tdeaboutdata.h> +#include <kstandarddirs.h> +#include <tqfile.h> +#include <tqtextstream.h> + +TQString +TDEAboutPerson::name() const +{ + return TQString::fromUtf8(mName); +} + +TQString +TDEAboutPerson::task() const +{ + if (mTask && *mTask) + return i18n(mTask); + else + return TQString::null; +} + +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) + , customAuthorTextEnabled(false) + , mTranslatedProgramName( 0 ) + {} + ~TDEAboutDataPrivate() + { + delete programLogo; + delete[] mTranslatedProgramName; + } + const char *translatorName; + const char *translatorEmail; + const char *productName; + TQImage* programLogo; + TQString customAuthorPlainText, customAuthorRichText; + bool customAuthorTextEnabled; + const char *mTranslatedProgramName; +}; + +const char *TDEAboutData::defaultBugTracker = "http://bugs.trinitydesktop.org"; + +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!=0)?bugsEmailAddress:defaultBugTracker ), + 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; + translateInternalProgramName(); +} + +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::null; +} + +const char* +TDEAboutData::internalProgramName() const +{ + if (d->mTranslatedProgramName) + return d->mTranslatedProgramName; + else + return mProgramName; +} + +// TDECrash should call as few things as possible and should avoid e.g. malloc() +// because it may deadlock. Since i18n() needs it, when TDELocale is available +// the i18n() call will be done here in advance. +void +TDEAboutData::translateInternalProgramName() const +{ + delete[] d->mTranslatedProgramName; + d->mTranslatedProgramName = 0; + if( TDEGlobal::locale() ) + d->mTranslatedProgramName = tqstrdup( programName().utf8()); +} + +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::null; +} + +TQString +TDEAboutData::homepage() const +{ + return TQString::fromLatin1(mHomepageAddress); +} + +TQString +TDEAboutData::bugAddress() const +{ + return TQString::fromLatin1(mBugEmailAddress); +} + +const TQValueList<TDEAboutPerson> +TDEAboutData::authors() const +{ + return mAuthorList; +} + +const TQValueList<TDEAboutPerson> +TDEAboutData::credits() const +{ + return mCreditList; +} + +const TQValueList<TDEAboutTranslator> +TDEAboutData::translators() const +{ + TQValueList<TDEAboutTranslator> personList; + + if(d->translatorName == 0) + return personList; + + TQStringList nameList; + TQStringList emailList; + + TQString names = i18n(d->translatorName); + if(names != TQString::fromUtf8(d->translatorName)) + { + nameList = TQStringList::split(',',names); + } + + + if(d->translatorEmail) + { + TQString emails = i18n(d->translatorEmail); + + if(emails != TQString::fromUtf8(d->translatorEmail)) + { + emailList = TQStringList::split(',',emails,true); + } + } + + + 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; + + personList.append(TDEAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace())); + } + + return personList; +} + +TQString +TDEAboutData::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 <a href=\"http://l10n.kde.org\">http://l10n.kde.org</a></p>" + ); +} + +TQString +TDEAboutData::otherText() const +{ + if (mOtherText && *mOtherText) + return i18n(mOtherText); + else + return TQString::null; +} + + +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_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()) + { + TQFile file(f); + if (file.open(IO_ReadOnly)) + { + result += '\n'; + result += '\n'; + TQTextStream str(&file); + result += str.read(); + } + } + + return result; +} + +TQString +TDEAboutData::copyrightStatement() const +{ + if (mCopyrightStatement && *mCopyrightStatement) + return i18n(mCopyrightStatement); + else + return TQString::null; +} + +TQString +TDEAboutData::customAuthorPlainText() const +{ + return d->customAuthorPlainText; +} + +TQString +TDEAboutData::customAuthorRichText() const +{ + return d->customAuthorRichText; +} + +bool +TDEAboutData::customAuthorTextEnabled() const +{ + return d->customAuthorTextEnabled; +} + +void +TDEAboutData::setCustomAuthorText(const TQString &plainText, const TQString &richText) +{ + d->customAuthorPlainText = plainText; + d->customAuthorRichText = richText; + + d->customAuthorTextEnabled = true; +} + +void +TDEAboutData::unsetCustomAuthorText() +{ + d->customAuthorPlainText = TQString::null; + d->customAuthorRichText = TQString::null; + + d->customAuthorTextEnabled = false; +} + diff --git a/tdecore/tdeaboutdata.h b/tdecore/tdeaboutdata.h new file mode 100644 index 000000000..d5addac0a --- /dev/null +++ b/tdecore/tdeaboutdata.h @@ -0,0 +1,630 @@ +/* + * 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 <tqvaluelist.h> +#include <tqstring.h> +#include <tqimage.h> +#include <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(): + * + * \code + * 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); + * \endcode + */ +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 QValueList + */ + TDEAboutPerson() {} + + /** + * The person's name + * @return the person's name (can be TQString::null, if it has been + * constructed with a null name) + */ + TQString name() const; + + /** + * The person's task + * @return the person's task (can be TQString::null, 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::null, 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::null, 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::null, + const TQString & emailAddress=TQString::null); + + /** + * The translator's name + * @return the translators's name (can be TQString::null, 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::null, 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_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 trinitydesktop.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 = 0 + ); + + ~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"). + * @since 3.2 + */ + 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; + + /** + * @internal + */ + const char* internalProgramName() const; + /** + * @internal + */ + void translateInternalProgramName() 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; + + /** + * @internal + */ + const char* internalVersion() const { return mVersion; } + + /** + * Returns a short, translated description. + * @return the short description (translated). Can be + * TQString::null if not set. + */ + TQString shortDescription() const; + + /** + * Returns the application homepage. + * @return the application homepage URL. Can be TQString::null if + * not set. + */ + TQString homepage() const; + + /** + * Returns the email address for bugs. + * @return the email address where to report bugs. + */ + TQString bugAddress() const; + + /** + * @internal + */ + const char* internalBugAddress() const { return mBugEmailAddress; } + + /** + * Returns a list of authors. + * @return author information (list of persons). + */ + const TQValueList<TDEAboutPerson> authors() const; + + /** + * Returns a list of persons who contributed. + * @return credit information (list of persons). + */ + const TQValueList<TDEAboutPerson> credits() const; + + /** + * Returns a list of translators. + * @return translators information (list of persons) + */ + const TQValueList<TDEAboutTranslator> 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::null 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::null if not set. + */ + TQString copyrightStatement() const; + + /** + * Returns the plain text displayed around the list of authors instead + * of the default message telling users to send bug reports to bugAddress(). + * + * @return the plain text displayed around the list of authors instead + * of the default message. Can be TQString::null. + */ + TQString customAuthorPlainText() const; + + /** + * Returns the rich text displayed around the list of authors instead + * of the default message telling users to send bug reports to bugAddress(). + * + * @return the rich text displayed around the list of authors instead + * of the default message. Can be TQString::null. + */ + TQString customAuthorRichText() const; + + /** + * Returns whether custom text should be displayed around the list of + * authors. + * + * @return whether custom text should be displayed around the list of + * authors. + */ + bool customAuthorTextEnabled() const; + + /** + * Sets the custom text displayed around the list of authors instead + * of the default message telling users to send bug reports to bugAddress(). + * + * @param plainText The plain text. + * @param richText The rich text. + * + * Both parameters can be TQString::null to not display any message at + * all. Call unsetCustomAuthorText() to revert to the default mesage. + */ + void setCustomAuthorText(const TQString &plainText, const TQString &richText); + + /** + * Clears any custom text displayed around the list of authors and falls + * back to the default message telling users to send bug reports to + * bugAddress(). + */ + void unsetCustomAuthorText(); + + 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<TDEAboutPerson> mAuthorList; + TQValueList<TDEAboutPerson> mCreditList; + const char *mLicenseText; + static const char *defaultBugTracker; + + TDEAboutDataPrivate *d; +}; + +#endif + diff --git a/tdecore/tdeaccel.cpp b/tdecore/tdeaccel.cpp index be8fba51b..e019baafc 100644 --- a/tdecore/tdeaccel.cpp +++ b/tdecore/tdeaccel.cpp @@ -27,7 +27,7 @@ #include <tqtimer.h> #include "tdeaccelbase.h" -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <klocale.h> #include <tdeshortcut.h> diff --git a/tdecore/tdeapplication.cpp b/tdecore/tdeapplication.cpp new file mode 100644 index 000000000..24c77826b --- /dev/null +++ b/tdecore/tdeapplication.cpp @@ -0,0 +1,3638 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) + Copyright (C) 1998, 1999, 2000 KDE Team + + 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 "config.h" + +#ifdef HAVE_XCOMPOSITE +#define COMPOSITE +#endif + +// #ifdef QTRANSLATOR_H +// #error qtranslator.h was already included +// #endif // QTRANSLATOR_H +// +// #ifdef TQTRANSLATOR_H +// #error tqtranslator.h was already included +// #endif // TQTRANSLATOR_H + +#undef QT_NO_TRANSLATION +#undef TQT_NO_TRANSLATION +#include <tqtranslator.h> +#include "tdeapplication.h" +#define QT_NO_TRANSLATION +#define TQT_NO_TRANSLATION +#include <tqdir.h> +#include <tqptrcollection.h> +#include <tqwidgetlist.h> +#include <tqstrlist.h> +#include <tqfile.h> +#include <tqmessagebox.h> +#include <tqtextstream.h> +#include <tqregexp.h> +#include <tqlineedit.h> +#include <tqtextedit.h> +#include <tqsessionmanager.h> +#include <tqptrlist.h> +#include <tqtimer.h> +#include <tqstylesheet.h> +#include <tqpixmapcache.h> +#include <tqtooltip.h> +#include <tqstylefactory.h> +#include <tqmetaobject.h> +#include <tqimage.h> +#ifndef QT_NO_SQL +#include <tqsqlpropertymap.h> +#endif + +#include <kglobal.h> +#include <kstandarddirs.h> +#include <kdebug.h> +#include <klocale.h> +#include <tdestyle.h> +#include <kiconloader.h> +#include <kclipboard.h> +#include <tdeconfig.h> +#include <ksimpleconfig.h> +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> +#include <kglobalsettings.h> +#include <kcrash.h> +#include <kdatastream.h> +#include <klibloader.h> +#include <kmimesourcefactory.h> +#include <tdestdaccel.h> +#include <tdeaccel.h> +#include "kcheckaccelerators.h" +#include <tqptrdict.h> +#include <kmacroexpander.h> +#include <kshell.h> +#include <kprotocolinfo.h> +#include <kkeynative.h> +#include <kmdcodec.h> +#include <kglobalaccel.h> + +#if defined Q_WS_X11 +#include <kstartupinfo.h> +#endif + +#include <dcopclient.h> +#include <dcopref.h> + +#include <sys/types.h> +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif +#include <sys/wait.h> +#include <grp.h> +#include <sys/types.h> + +#ifndef Q_WS_WIN +#include "twin.h" +#endif + +#include <fcntl.h> +#include <stdlib.h> // getenv(), srand(), rand() +#include <signal.h> +#include <unistd.h> +#include <time.h> +#include <sys/time.h> +#include <errno.h> +#include <string.h> +#include <netdb.h> +#if defined Q_WS_X11 +//#ifndef Q_WS_QWS //FIXME(E): NetWM should talk to QWS... +#include <netwm.h> +#endif + +#include "kprocctrl.h" + +#ifdef HAVE_PATHS_H +#include <paths.h> +#endif + +#ifdef Q_WS_X11 +#include <X11/Xlib.h> +#ifdef COMPOSITE +#include <X11/extensions/Xrender.h> +#include <X11/extensions/Xcomposite.h> +#include <dlfcn.h> +#endif +#include <X11/Xutil.h> +#include <X11/Xatom.h> +#include <X11/SM/SMlib.h> +#include <fixx11h.h> +#endif + +#include <pwd.h> + +#ifndef Q_WS_WIN +#include <KDE-ICE/ICElib.h> +#else +typedef void* IceIOErrorHandler; +#include <windows.h> +//KDE4: remove +#define Button1Mask (1<<8) +#define Button2Mask (1<<9) +#define Button3Mask (1<<10) +#endif + +#ifdef Q_WS_X11 +#define DISPLAY "DISPLAY" +#elif defined(Q_WS_QWS) +#define DISPLAY "QWS_DISPLAY" +#endif + +#if defined Q_WS_X11 +#include <kipc.h> +#endif + +#ifdef Q_WS_MACX +#include <Carbon/Carbon.h> +#include <tqimage.h> +#endif + +#include "kappdcopiface.h" + +// exported for tdm kfrontend +KDE_EXPORT bool kde_have_kipc = true; // magic hook to disable kipc in tdm +bool kde_kiosk_exception = false; // flag to disable kiosk restrictions +bool kde_kiosk_admin = false; + +TDEApplication* TDEApplication::KApp = 0L; +bool TDEApplication::loadedByKdeinit = false; +DCOPClient *TDEApplication::s_DCOPClient = 0L; +bool TDEApplication::s_dcopClientNeedsPostInit = false; + +#ifdef Q_WS_X11 +static Atom atom_DesktopWindow; +static Atom atom_NetSupported; +static Atom kde_xdnd_drop; +#endif + +#ifdef Q_WS_X11 +static int composite_event, composite_error, composite_opcode; +static bool x11_composite_error_generated; +static int x11_error(Display *dpy, XErrorEvent *ev) { + if (ev->request_code == composite_opcode && ev->minor_code == X_CompositeRedirectSubwindows) + { + x11_composite_error_generated = true; + return 0; + } + return 1; +} +#endif + +// duplicated from patched Qt, so that there won't be unresolved symbols if Qt gets +// replaced by unpatched one +TDECORE_EXPORT bool tqt_qclipboard_bailout_hack = false; + +template class TQPtrList<KSessionManaged>; + +#ifdef Q_WS_X11 +extern "C" { +static int kde_xio_errhandler( Display * dpy ) +{ + return kapp->xioErrhandler( dpy ); +} + +static int kde_x_errhandler( Display *dpy, XErrorEvent *err ) +{ + return kapp->xErrhandler( dpy, err ); +} + +} + +extern "C" { +static void kde_ice_ioerrorhandler( IceConn conn ) +{ + if(kapp) + kapp->iceIOErrorHandler( conn ); + // else ignore the error for now +} +} +#endif + +#ifdef Q_WS_WIN +void TDEApplication_init_windows(bool GUIenabled); + +class QAssistantClient; +#endif + +/* + Private data to make keeping binary compatibility easier + */ +class TDEApplicationPrivate +{ +public: + TDEApplicationPrivate() + : actionRestrictions( false ), + refCount( 1 ), + oldIceIOErrorHandler( 0 ), + checkAccelerators( 0 ), + overrideStyle( TQString::null ), + startup_id( "0" ), + app_started_timer( NULL ), + m_KAppDCOPInterface( 0L ), + session_save( false ) +#ifdef Q_WS_X11 + ,oldXErrorHandler( NULL ) + ,oldXIOErrorHandler( NULL ) +#elif defined Q_WS_WIN + ,qassistantclient( 0 ) +#endif + { + } + + ~TDEApplicationPrivate() + { +#ifdef Q_WS_WIN + delete qassistantclient; +#endif + } + + + bool actionRestrictions : 1; + bool guiEnabled : 1; + /** + * This counter indicates when to exit the application. + * It starts at 1, is decremented in TDEMainWindow when the last window is closed, but + * is incremented by operations that should outlive the last window closed + * (e.g. a file copy for a file manager, or 'compacting folders on exit' for a mail client). + */ + int refCount; + IceIOErrorHandler oldIceIOErrorHandler; + KCheckAccelerators* checkAccelerators; + TQString overrideStyle; + TQString geometry_arg; + TQCString startup_id; + TQTimer* app_started_timer; + KAppDCOPInterface *m_KAppDCOPInterface; + bool session_save; +#ifdef Q_WS_X11 + int (*oldXErrorHandler)(Display*,XErrorEvent*); + int (*oldXIOErrorHandler)(Display*); +#elif defined Q_WS_WIN + QAssistantClient* qassistantclient; +#endif + + class URLActionRule + { + public: +#define checkExactMatch(s, b) \ + if (s.isEmpty()) b = true; \ + else if (s[s.length()-1] == '!') \ + { b = false; s.truncate(s.length()-1); } \ + else b = true; +#define checkStartWildCard(s, b) \ + if (s.isEmpty()) b = true; \ + else if (s[0] == '*') \ + { b = true; s = s.mid(1); } \ + else b = false; +#define checkEqual(s, b) \ + b = (s == "="); + + URLActionRule(const TQString &act, + const TQString &bProt, const TQString &bHost, const TQString &bPath, + const TQString &dProt, const TQString &dHost, const TQString &dPath, + bool perm) + : action(act), + baseProt(bProt), baseHost(bHost), basePath(bPath), + destProt(dProt), destHost(dHost), destPath(dPath), + permission(perm) + { + checkExactMatch(baseProt, baseProtWildCard); + checkStartWildCard(baseHost, baseHostWildCard); + checkExactMatch(basePath, basePathWildCard); + checkExactMatch(destProt, destProtWildCard); + checkStartWildCard(destHost, destHostWildCard); + checkExactMatch(destPath, destPathWildCard); + checkEqual(destProt, destProtEqual); + checkEqual(destHost, destHostEqual); + } + + bool baseMatch(const KURL &url, const TQString &protClass) + { + if (baseProtWildCard) + { + if ( !baseProt.isEmpty() && !url.protocol().startsWith(baseProt) && + (protClass.isEmpty() || (protClass != baseProt)) ) + return false; + } + else + { + if ( (url.protocol() != baseProt) && + (protClass.isEmpty() || (protClass != baseProt)) ) + return false; + } + if (baseHostWildCard) + { + if (!baseHost.isEmpty() && !url.host().endsWith(baseHost)) + return false; + } + else + { + if (url.host() != baseHost) + return false; + } + if (basePathWildCard) + { + if (!basePath.isEmpty() && !url.path().startsWith(basePath)) + return false; + } + else + { + if (url.path() != basePath) + return false; + } + return true; + } + + bool destMatch(const KURL &url, const TQString &protClass, const KURL &base, const TQString &baseClass) + { + if (destProtEqual) + { + if ( (url.protocol() != base.protocol()) && + (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass) ) + return false; + } + else if (destProtWildCard) + { + if ( !destProt.isEmpty() && !url.protocol().startsWith(destProt) && + (protClass.isEmpty() || (protClass != destProt)) ) + return false; + } + else + { + if ( (url.protocol() != destProt) && + (protClass.isEmpty() || (protClass != destProt)) ) + return false; + } + if (destHostWildCard) + { + if (!destHost.isEmpty() && !url.host().endsWith(destHost)) + return false; + } + else if (destHostEqual) + { + if (url.host() != base.host()) + return false; + } + else + { + if (url.host() != destHost) + return false; + } + if (destPathWildCard) + { + if (!destPath.isEmpty() && !url.path().startsWith(destPath)) + return false; + } + else + { + if (url.path() != destPath) + return false; + } + return true; + } + + TQString action; + TQString baseProt; + TQString baseHost; + TQString basePath; + TQString destProt; + TQString destHost; + TQString destPath; + bool baseProtWildCard : 1; + bool baseHostWildCard : 1; + bool basePathWildCard : 1; + bool destProtWildCard : 1; + bool destHostWildCard : 1; + bool destPathWildCard : 1; + bool destProtEqual : 1; + bool destHostEqual : 1; + bool permission; + }; + TQPtrList<URLActionRule> urlActionRestrictions; + + TQString sessionKey; + TQString pSessionConfigFile; +}; + + +static TQPtrList<TQWidget>*x11Filter = 0; +static bool autoDcopRegistration = true; + +void TDEApplication::installX11EventFilter( TQWidget* filter ) +{ + if ( !filter ) + return; + if (!x11Filter) + x11Filter = new TQPtrList<TQWidget>; + connect ( filter, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( x11FilterDestroyed() ) ); + x11Filter->append( filter ); +} + +void TDEApplication::x11FilterDestroyed() +{ + removeX11EventFilter( static_cast< const TQWidget* >( sender())); +} + +void TDEApplication::removeX11EventFilter( const TQWidget* filter ) +{ + if ( !x11Filter || !filter ) + return; + x11Filter->removeRef( filter ); + if ( x11Filter->isEmpty() ) { + delete x11Filter; + x11Filter = 0; + } +} + +// FIXME: remove this when we've get a better method of +// customizing accelerator handling -- hopefully in Qt. +// For now, this is set whenever an accelerator is overridden +// in TDEAccelEventHandler so that the AccelOverride isn't sent twice. -- ellis, 19/10/02 +extern bool kde_g_bKillAccelOverride; + +bool TDEApplication::notify(TQObject *receiver, TQEvent *event) +{ + TQEvent::Type t = event->type(); + if (kde_g_bKillAccelOverride) + { + kde_g_bKillAccelOverride = false; + // Indicate that the accelerator has been overridden. + if (t == TQEvent::AccelOverride) + { + TQT_TQKEYEVENT(event)->accept(); + return true; + } + else + kdWarning(125) << "kde_g_bKillAccelOverride set, but received an event other than AccelOverride." << endl; + } + + if ((t == TQEvent::AccelOverride) || (t == TQEvent::KeyPress)) + { + static const TDEShortcut& _selectAll = TDEStdAccel::selectAll(); + TQLineEdit *edit = ::tqqt_cast<TQLineEdit *>(receiver); + if (edit) + { + // We have a keypress for a lineedit... + TQKeyEvent *kevent = TQT_TQKEYEVENT(event); + KKey key(kevent); + if (_selectAll.contains(key)) + { + if (t == TQEvent::KeyPress) + { + edit->selectAll(); + return true; + } + else + { + kevent->accept(); + } + } + // Ctrl-U deletes from start of line. + if (key == KKey(Qt::CTRL + Qt::Key_U)) + { + if (t == TQEvent::KeyPress) + { + if (!edit->isReadOnly()) + { + TQString t(edit->text()); + t = t.mid(edit->cursorPosition()); + edit->validateAndSet(t, 0, 0, 0); + } + return true; + } + else + { + kevent->accept(); + } + + } + } + TQTextEdit *medit = ::tqqt_cast<TQTextEdit *>(receiver); + if (medit) + { + // We have a keypress for a multilineedit... + TQKeyEvent *kevent = TQT_TQKEYEVENT(event); + if (_selectAll.contains(KKey(kevent))) + { + if (t == TQEvent::KeyPress) + { + medit->selectAll(); + return true; + } + else + { + kevent->accept(); + } + } + } + } + if( t == TQEvent::Show && receiver->isWidgetType()) + { + TQWidget* w = TQT_TQWIDGET( receiver ); +#if defined Q_WS_X11 + if( w->isTopLevel() && !startupId().isEmpty() && !TQT_TQSHOWEVENT(event)->spontaneous()) // TODO better done using window group leader? + TDEStartupInfo::setWindowStartupId( w->winId(), startupId()); +#endif + if( w->isTopLevel() && !w->testWFlags( WX11BypassWM ) && !w->isPopup() && !event->spontaneous()) + { + if( d->app_started_timer == NULL ) + { + d->app_started_timer = new TQTimer( this, "app_started_timer" ); + connect( d->app_started_timer, TQT_SIGNAL( timeout()), TQT_SLOT( checkAppStartedSlot())); + } + if( !d->app_started_timer->isActive()) + d->app_started_timer->start( 0, true ); + } + if( w->isTopLevel() && ( w->icon() == NULL || w->icon()->isNull())) + { + // icon() cannot be null pixmap, it'll be the "unknown" icon - so check if there is this application icon + static TQPixmap* ic = NULL; + if( ic == NULL ) + ic = new TQPixmap( TDEGlobal::iconLoader()->loadIcon( iconName(), + TDEIcon::NoGroup, 0, TDEIcon::DefaultState, NULL, true )); + if( !ic->isNull()) + { + w->setIcon( *ic ); +#if defined Q_WS_X11 + KWin::setIcons( w->winId(), *ic, miniIcon()); +#endif + } + } + } + return TQApplication::notify(receiver, event); +} + +void TDEApplication::checkAppStartedSlot() +{ +#if defined Q_WS_X11 + TDEStartupInfo::handleAutoAppStartedSending(); +#endif +} + +// the help class for session management communication +static TQPtrList<KSessionManaged>* sessionClients() +{ + static TQPtrList<KSessionManaged>* session_clients = 0L; + if ( !session_clients ) + session_clients = new TQPtrList<KSessionManaged>; + return session_clients; +} + +/* + Auxiliary function to calculate a a session config name used for the + instance specific config object. + Syntax: "session/<appname>_<sessionId>" + */ +TQString TDEApplication::sessionConfigName() const +{ + TQString sessKey = sessionKey(); + if ( sessKey.isEmpty() && !d->sessionKey.isEmpty() ) + sessKey = d->sessionKey; + return TQString("session/%1_%2_%3").arg(name()).arg(sessionId()).arg(sessKey); +} + +#ifdef Q_WS_X11 +static SmcConn mySmcConnection = 0; +static SmcConn tmpSmcConnection = 0; +#else +// FIXME(E): Implement for Qt Embedded +// Possibly "steal" XFree86's libSM? +#endif +static TQTime* smModificationTime = 0; + +TDEApplication::TDEApplication( int& argc, char** argv, const TQCString& rAppName, + bool allowStyles, bool GUIenabled ) : + TQApplication( argc, argv, GUIenabled ), TDEInstance(rAppName), +#ifdef Q_WS_X11 + display(0L), + argb_visual(false), +#endif + d (new TDEApplicationPrivate()) +{ + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + if (!GUIenabled) + allowStyles = false; + useStyles = allowStyles; + Q_ASSERT (!rAppName.isEmpty()); + setName(rAppName); + + installSigpipeHandler(); + TDECmdLineArgs::initIgnore(argc, argv, rAppName.data()); + parseCommandLine( ); + init(GUIenabled); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} + +TDEApplication::TDEApplication( bool allowStyles, bool GUIenabled ) : +// TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), TRUE ), // Qt4 requires that there always be a GUI + TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), GUIenabled ), // We need to be able to run command line apps + TDEInstance( TDECmdLineArgs::about), +#ifdef Q_WS_X11 + display(0L), + argb_visual(false), +#endif + d (new TDEApplicationPrivate) +{ + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + if (!GUIenabled) + allowStyles = false; + useStyles = allowStyles; + setName( instanceName() ); + + installSigpipeHandler(); + parseCommandLine( ); + init(GUIenabled); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} + +#ifdef Q_WS_X11 +TDEApplication::TDEApplication( Display *dpy, bool allowStyles ) : + TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), + getX11RGBAVisual(dpy), getX11RGBAColormap(dpy) ), + TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate) +{ + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + useStyles = allowStyles; + setName( instanceName() ); + installSigpipeHandler(); + parseCommandLine( ); + init( true ); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} + +TDEApplication::TDEApplication( Display *dpy, bool disable_argb, Qt::HANDLE visual, Qt::HANDLE colormap, bool allowStyles ) : + TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), + disable_argb?visual:getX11RGBAVisual(dpy), disable_argb?colormap:getX11RGBAColormap(dpy) ), + TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate) +{ + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + useStyles = allowStyles; + if (disable_argb) argb_visual = false; + setName( instanceName() ); + installSigpipeHandler(); + parseCommandLine( ); + init( true ); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} + +TDEApplication::TDEApplication( Display *dpy, Qt::HANDLE visual, Qt::HANDLE colormap, + bool allowStyles ) : + TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), + visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ), + TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate) +{ + if ((visual) && (colormap)) + getX11RGBAInformation(dpy); + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + useStyles = allowStyles; + setName( instanceName() ); + installSigpipeHandler(); + parseCommandLine( ); + init( true ); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} + +TDEApplication::TDEApplication( Display *dpy, Qt::HANDLE visual, Qt::HANDLE colormap, + bool allowStyles, TDEInstance * _instance ) : + TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), + visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ), + TDEInstance( _instance ), display(0L), d (new TDEApplicationPrivate) +{ + if ((visual) && (colormap)) + getX11RGBAInformation(dpy); + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + useStyles = allowStyles; + setName( instanceName() ); + installSigpipeHandler(); + parseCommandLine( ); + init( true ); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} +#endif + +TDEApplication::TDEApplication( bool allowStyles, bool GUIenabled, TDEInstance* _instance ) : + TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), + GUIenabled ), + TDEInstance( _instance ), +#ifdef Q_WS_X11 + display(0L), +#endif + argb_visual(false), + d (new TDEApplicationPrivate) +{ + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + if (!GUIenabled) + allowStyles = false; + useStyles = allowStyles; + setName( instanceName() ); + + installSigpipeHandler(); + parseCommandLine( ); + init(GUIenabled); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} + +#ifdef Q_WS_X11 +TDEApplication::TDEApplication(Display *display, int& argc, char** argv, const TQCString& rAppName, + bool allowStyles, bool GUIenabled ) : + TQApplication( display ), TDEInstance(rAppName), + display(0L), + argb_visual(false), + d (new TDEApplicationPrivate()) +{ + aIconPixmap.pm.icon = 0L; + aIconPixmap.pm.miniIcon = 0L; + read_app_startup_id(); + if (!GUIenabled) + allowStyles = false; + useStyles = allowStyles; + + Q_ASSERT (!rAppName.isEmpty()); + setName(rAppName); + + installSigpipeHandler(); + TDECmdLineArgs::initIgnore(argc, argv, rAppName.data()); + parseCommandLine( ); + init(GUIenabled); + d->m_KAppDCOPInterface = new KAppDCOPInterface(this); +} +#endif + +int TDEApplication::xioErrhandler( Display* dpy ) +{ + if(kapp) + { + emit shutDown(); +#ifdef Q_WS_X11 + d->oldXIOErrorHandler( dpy ); +#else + Q_UNUSED(dpy); +#endif + } + exit( 1 ); + return 0; +} + +int TDEApplication::xErrhandler( Display* dpy, void* err_ ) +{ // no idea how to make forward decl. for XErrorEvent +#ifdef Q_WS_X11 + XErrorEvent* err = static_cast< XErrorEvent* >( err_ ); + if(kapp) + { + // add KDE specific stuff here + d->oldXErrorHandler( dpy, err ); + } +#endif + return 0; +} + +void TDEApplication::iceIOErrorHandler( _IceConn *conn ) +{ + emit shutDown(); + +#ifdef Q_WS_X11 + if ( d->oldIceIOErrorHandler != NULL ) + (*d->oldIceIOErrorHandler)( conn ); +#endif + exit( 1 ); +} + +class KDETranslator : public TQTranslator +{ +public: + KDETranslator(TQObject *parent) : TQTranslator(parent, "kdetranslator") {} + virtual TQTranslatorMessage findMessage(const char* context, + const char *sourceText, + const char* message) const + { + TQTranslatorMessage res; + res.setTranslation(TDEGlobal::locale()->translateQt(context, sourceText, message)); + return res; + } +}; + +void TDEApplication::init(bool GUIenabled) +{ + d->guiEnabled = GUIenabled; + if ((getuid() != geteuid()) || + (getgid() != getegid()) ) + { + // man permissions are not exploitable and better than + // world writable directories + struct group *man = getgrnam("man"); + if ( !man || man->gr_gid != getegid() ){ + fprintf(stderr, "The TDE libraries are not designed to run with suid privileges.\n"); + ::exit(127); + } + } + + TDEProcessController::ref(); + + (void) TDEClipboardSynchronizer::self(); + + TQApplication::setDesktopSettingsAware( false ); + + KApp = this; + + +#ifdef Q_WS_X11 //FIXME(E) + // create all required atoms in _one_ roundtrip to the X server + if ( GUIenabled ) { + const int max = 20; + Atom* atoms[max]; + char* names[max]; + Atom atoms_return[max]; + int n = 0; + + atoms[n] = &kipcCommAtom; + names[n++] = (char *) "KIPC_COMM_ATOM"; + + atoms[n] = &atom_DesktopWindow; + names[n++] = (char *) "KDE_DESKTOP_WINDOW"; + + atoms[n] = &atom_NetSupported; + names[n++] = (char *) "_NET_SUPPORTED"; + + atoms[n] = &kde_xdnd_drop; + names[n++] = (char *) "XdndDrop"; + + XInternAtoms( tqt_xdisplay(), names, n, false, atoms_return ); + + for (int i = 0; i < n; i++ ) + *atoms[i] = atoms_return[i]; + } +#endif + + dcopAutoRegistration(); + dcopClientPostInit(); + + smw = 0; + + // Initial KIPC event mask. +#if defined Q_WS_X11 + kipcEventMask = (1 << KIPC::StyleChanged) | (1 << KIPC::PaletteChanged) | + (1 << KIPC::FontChanged) | (1 << KIPC::BackgroundChanged) | + (1 << KIPC::ToolbarStyleChanged) | (1 << KIPC::SettingsChanged) | + (1 << KIPC::ClipboardConfigChanged) | (1 << KIPC::BlockShortcuts); +#endif + + // Trigger creation of locale. + (void) TDEGlobal::locale(); + + TDEConfig* config = TDEGlobal::config(); + d->actionRestrictions = config->hasGroup("KDE Action Restrictions" ) && !kde_kiosk_exception; + // For brain-dead configurations where the user's local config file is not writable. + // * We use kdialog to warn the user, so we better not generate warnings from + // kdialog itself. + // * Don't warn if we run with a read-only $HOME + TQCString readOnly = getenv("TDE_HOME_READONLY"); + if (readOnly.isEmpty() && (tqstrcmp(name(), "kdialog") != 0)) + { + TDEConfigGroupSaver saver(config, "KDE Action Restrictions"); + if (config->readBoolEntry("warn_unwritable_config",true)) + config->checkConfigFilesWritable(true); + } + + if (GUIenabled) + { +#ifdef Q_WS_X11 + // this is important since we fork() to launch the help (Matthias) + fcntl(ConnectionNumber(tqt_xdisplay()), F_SETFD, FD_CLOEXEC); + // set up the fancy (=robust and error ignoring ) KDE xio error handlers (Matthias) + d->oldXErrorHandler = XSetErrorHandler( kde_x_errhandler ); + d->oldXIOErrorHandler = XSetIOErrorHandler( kde_xio_errhandler ); +#endif + + connect( this, TQT_SIGNAL( aboutToQuit() ), this, TQT_SIGNAL( shutDown() ) ); + +#ifdef Q_WS_X11 //FIXME(E) + display = desktop()->x11Display(); +#endif + + { + TQStringList plugins = TDEGlobal::dirs()->resourceDirs( "qtplugins" ); + TQStringList::Iterator it = plugins.begin(); + while (it != plugins.end()) { + addLibraryPath( *it ); + ++it; + } + + } + tdedisplaySetStyle(); + tdedisplaySetFont(); +// tdedisplaySetPalette(); done by tdedisplaySetStyle + propagateSettings(SETTINGS_QT); + + // Set default mime-source factory + // XXX: This is a hack. Make our factory the default factory, but add the + // previous default factory to the list of factories. Why? When the default + // factory can't resolve something, it iterates in the list of factories. + // But it TQWhatsThis only uses the default factory. So if there was already + // a default factory (which happens when using an image library using uic), + // we prefer KDE's factory and so we put that old default factory in the + // list and use KDE as the default. This may speed up things as well. + TQMimeSourceFactory* oldDefaultFactory = TQMimeSourceFactory::takeDefaultFactory(); + TQMimeSourceFactory::setDefaultFactory( mimeSourceFactory() ); + if ( oldDefaultFactory ) { + TQMimeSourceFactory::addFactory( oldDefaultFactory ); + } + + d->checkAccelerators = new KCheckAccelerators( TQT_TQOBJECT(this) ); + } + +#ifdef Q_WS_MACX + if (GUIenabled) { + TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon( TDECmdLineArgs::appName(), + TDEIcon::NoGroup, TDEIcon::SizeLarge, TDEIcon::DefaultState, 0L, false ); + if (!pixmap.isNull()) { + TQImage i = pixmap.convertToImage().convertDepth(32).smoothScale(40, 40); + for(int y = 0; y < i.height(); y++) { + uchar *l = i.scanLine(y); + for(int x = 0; x < i.width(); x+=4) + *(l+x) = 255; + } + CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB(); + CGDataProviderRef dp = CGDataProviderCreateWithData(NULL, + i.bits(), i.numBytes(), NULL); + CGImageRef ir = CGImageCreate(i.width(), i.height(), 8, 32, i.bytesPerLine(), + cs, kCGImageAlphaNoneSkipFirst, dp, + 0, 0, kCGRenderingIntentDefault); + //cleanup + SetApplicationDockTileImage(ir); + CGImageRelease(ir); + CGColorSpaceRelease(cs); + CGDataProviderRelease(dp); + } + } +#endif + + + // save and restore the RTL setting, as installTranslator calls qt_detectRTLLanguage, + // which makes it impossible to use the -reverse cmdline switch with KDE apps + bool rtl = reverseLayout(); + installTranslator(new KDETranslator(TQT_TQOBJECT(this))); + setReverseLayout( rtl ); + if (i18n( "_: Dear Translator! Translate this string to the string 'LTR' in " + "left-to-right languages (as english) or to 'RTL' in right-to-left " + "languages (such as Hebrew and Arabic) to get proper widget layout." ) == "RTL") + setReverseLayout( !rtl ); + + // install appdata resource type + TDEGlobal::dirs()->addResourceType("appdata", TDEStandardDirs::kde_default("data") + + TQString::fromLatin1(name()) + '/'); + pSessionConfig = 0L; + bSessionManagement = true; + +#ifdef Q_WS_X11 + // register a communication window for desktop changes (Matthias) + if (GUIenabled && kde_have_kipc ) + { + smw = new TQWidget(0,0); + long data = 1; + XChangeProperty(tqt_xdisplay(), smw->winId(), + atom_DesktopWindow, atom_DesktopWindow, + 32, PropModeReplace, (unsigned char *)&data, 1); + } + d->oldIceIOErrorHandler = IceSetIOErrorHandler( kde_ice_ioerrorhandler ); +#elif defined(Q_WS_WIN) + TDEApplication_init_windows(GUIenabled); +#else + // FIXME(E): Implement for Qt Embedded +#endif +} + +static int my_system (const char *command) { + int pid, status; + + pid = fork(); + if (pid == -1) + return -1; + if (pid == 0) { + const char* shell = "/bin/sh"; + execl(shell, shell, "-c", command, (void *)0); + ::_exit(127); + } + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) + return -1; + } else + return status; + } while(1); +} + + +DCOPClient *TDEApplication::dcopClient() +{ + if (s_DCOPClient) + return s_DCOPClient; + + s_DCOPClient = new DCOPClient(); + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("tde"); + if (args && args->isSet("dcopserver")) + { + s_DCOPClient->setServerAddress( args->getOption("dcopserver")); + } + if( kapp ) { + connect(s_DCOPClient, TQT_SIGNAL(attachFailed(const TQString &)), + kapp, TQT_SLOT(dcopFailure(const TQString &))); + connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(bool) ), + kapp, TQT_SLOT(dcopBlockUserInput(bool)) ); + } + else + s_dcopClientNeedsPostInit = true; + + DCOPClient::setMainClient( s_DCOPClient ); + return s_DCOPClient; +} + +void TDEApplication::dcopClientPostInit() +{ + if( s_dcopClientNeedsPostInit ) + { + s_dcopClientNeedsPostInit = false; + connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(bool) ), + TQT_SLOT(dcopBlockUserInput(bool)) ); + s_DCOPClient->bindToApp(); // Make sure we get events from the DCOPClient. + } +} + +void TDEApplication::dcopAutoRegistration() +{ + if (autoDcopRegistration) + { + ( void ) dcopClient(); + if( dcopClient()->appId().isEmpty()) + dcopClient()->registerAs(name()); + } +} + +void TDEApplication::disableAutoDcopRegistration() +{ + autoDcopRegistration = false; +} + +TDEConfig* TDEApplication::sessionConfig() +{ + if (pSessionConfig) + return pSessionConfig; + + // create an instance specific config object + pSessionConfig = new TDEConfig( sessionConfigName(), false, false); + return pSessionConfig; +} + +void TDEApplication::ref() +{ + d->refCount++; + //kdDebug() << "TDEApplication::ref() : refCount = " << d->refCount << endl; +} + +void TDEApplication::deref() +{ + d->refCount--; + //kdDebug() << "TDEApplication::deref() : refCount = " << d->refCount << endl; + if ( d->refCount <= 0 ) + quit(); +} + +KSessionManaged::KSessionManaged() +{ + sessionClients()->remove( this ); + sessionClients()->append( this ); +} + +KSessionManaged::~KSessionManaged() +{ + sessionClients()->remove( this ); +} + +bool KSessionManaged::saveState(TQSessionManager&) +{ + return true; +} + +bool KSessionManaged::commitData(TQSessionManager&) +{ + return true; +} + + +void TDEApplication::disableSessionManagement() { + bSessionManagement = false; +} + +void TDEApplication::enableSessionManagement() { + bSessionManagement = true; +#ifdef Q_WS_X11 + // Session management support in Qt/TDE is awfully broken. + // If konqueror disables session management right after its startup, + // and enables it later (preloading stuff), it won't be properly + // saved on session shutdown. + // I'm not actually sure why it doesn't work, but saveState() + // doesn't seem to be called on session shutdown, possibly + // because disabling session management after konqueror startup + // disabled it somehow. Forcing saveState() here for this application + // seems to fix it. + if( mySmcConnection ) { + SmcRequestSaveYourself( mySmcConnection, SmSaveLocal, False, + SmInteractStyleAny, + False, False ); + + // flush the request + IceFlush(SmcGetIceConnection(mySmcConnection)); + } +#endif +} + + +bool TDEApplication::requestShutDown( + ShutdownConfirm confirm, ShutdownType sdtype, ShutdownMode sdmode ) +{ +#ifdef Q_WS_X11 + TQApplication::syncX(); + /* use ksmserver's dcop interface if necessary */ + if ( confirm == ShutdownConfirmYes || + sdtype != ShutdownTypeDefault || + sdmode != ShutdownModeDefault ) + { + TQByteArray data; + TQDataStream arg(data, IO_WriteOnly); + arg << (int)confirm << (int)sdtype << (int)sdmode; + return dcopClient()->send( "ksmserver", "ksmserver", + "logout(int,int,int)", data ); + } + + if ( mySmcConnection ) { + // we already have a connection to the session manager, use it. + SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True, + SmInteractStyleAny, + confirm == ShutdownConfirmNo, True ); + + // flush the request + IceFlush(SmcGetIceConnection(mySmcConnection)); + return true; + } + + // open a temporary connection, if possible + + propagateSessionManager(); + TQCString smEnv = ::getenv("SESSION_MANAGER"); + if (smEnv.isEmpty()) + return false; + + if (! tmpSmcConnection) { + char cerror[256]; + char* myId = 0; + char* prevId = 0; + SmcCallbacks cb; + tmpSmcConnection = SmcOpenConnection( 0, 0, 1, 0, + 0, &cb, + prevId, + &myId, + 255, + cerror ); + ::free( myId ); // it was allocated by C + if (!tmpSmcConnection ) + return false; + } + + SmcRequestSaveYourself( tmpSmcConnection, SmSaveBoth, True, + SmInteractStyleAny, False, True ); + + // flush the request + IceFlush(SmcGetIceConnection(tmpSmcConnection)); + return true; +#else + // FIXME(E): Implement for Qt Embedded + return false; +#endif +} + +void TDEApplication::propagateSessionManager() +{ +#ifdef Q_WS_X11 + TQCString fName = TQFile::encodeName(locateLocal("socket", "KSMserver")); + TQCString display = ::getenv(DISPLAY); + // strip the screen number from the display + display.replace(TQRegExp("\\.[0-9]+$"), ""); + int i; + while( (i = display.find(':')) >= 0) + display[i] = '_'; + + fName += "_"+display; + TQCString smEnv = ::getenv("SESSION_MANAGER"); + bool check = smEnv.isEmpty(); + if ( !check && smModificationTime ) { + TQFileInfo info( fName ); + TQTime current = TQT_TQTIME_OBJECT(info.lastModified().time()); + check = current > *smModificationTime; + } + if ( check ) { + delete smModificationTime; + TQFile f( fName ); + if ( !f.open( IO_ReadOnly ) ) + return; + TQFileInfo info ( f ); + smModificationTime = new TQTime( TQT_TQTIME_OBJECT(info.lastModified().time()) ); + TQTextStream t(&f); + t.setEncoding( TQTextStream::Latin1 ); + TQString s = t.readLine(); + f.close(); + ::setenv( "SESSION_MANAGER", s.latin1(), true ); + } +#endif +} + +void TDEApplication::commitData( TQSessionManager& sm ) +{ + d->session_save = true; + bool canceled = false; + for (KSessionManaged* it = sessionClients()->first(); + it && !canceled; + it = sessionClients()->next() ) { + canceled = !it->commitData( sm ); + } + if ( canceled ) + sm.cancel(); + + if ( sm.allowsInteraction() ) { + TQWidgetList done; + TQWidgetList *list = TQApplication::topLevelWidgets(); + bool canceled = false; + TQWidget* w = list->first(); + while ( !canceled && w ) { + if ( !w->testWState( WState_ForceHide ) && !w->inherits("TDEMainWindow") ) { + TQCloseEvent e; + sendEvent( w, &e ); + canceled = !e.isAccepted(); + if ( !canceled ) + done.append( w ); + delete list; // one never knows... + list = TQApplication::topLevelWidgets(); + w = list->first(); + } else { + w = list->next(); + } + while ( w && done.containsRef( w ) ) + w = list->next(); + } + delete list; + } + + + if ( !bSessionManagement ) + sm.setRestartHint( TQSessionManager::RestartNever ); + else + sm.setRestartHint( TQSessionManager::RestartIfRunning ); + d->session_save = false; +} + +static void checkRestartVersion( TQSessionManager& sm ) +{ + Display* dpy = tqt_xdisplay(); + Atom type; + int format; + unsigned long nitems, after; + unsigned char* data; + if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy, "TDE_FULL_SESSION", False ), + 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) { + if( data != NULL ) + XFree( data ); + if( type == XA_STRING && format == 8 ) { // session set, check if TDE_SESSION_VERSION is not set (meaning KDE3) + if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy, "TDE_SESSION_VERSION", False ), + 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) { + if( data != NULL ) + XFree( data ); // KDE4 or newer + if( type == None ) + return; // we run in our native session, no need to wrap + } else { + return; // we run in our native session, no need to wrap + } + } + } + TQString wrapper = TDEStandardDirs::findExe( "trinity" ); + TQStringList restartCommand = sm.restartCommand(); + restartCommand.prepend( wrapper ); + sm.setRestartCommand( restartCommand ); +} + +void TDEApplication::saveState( TQSessionManager& sm ) +{ + d->session_save = true; +#ifdef Q_WS_X11 + static bool firstTime = true; + mySmcConnection = (SmcConn) sm.handle(); + + if ( !bSessionManagement ) { + sm.setRestartHint( TQSessionManager::RestartNever ); + d->session_save = false; + return; + } + else + sm.setRestartHint( TQSessionManager::RestartIfRunning ); + + if ( firstTime ) { + firstTime = false; + d->session_save = false; + return; // no need to save the state. + } + + // remove former session config if still existing, we want a new + // and fresh one. Note that we do not delete the config file here, + // this is done by the session manager when it executes the + // discard commands. In fact it would be harmful to remove the + // file here, as the session might be stored under a different + // name, meaning the user still might need it eventually. + if ( pSessionConfig ) { + delete pSessionConfig; + pSessionConfig = 0; + } + + // tell the session manager about our new lifecycle + TQStringList restartCommand = sm.restartCommand(); + + TQCString multiHead = getenv("TDE_MULTIHEAD"); + if (multiHead.lower() == "true") { + // if multihead is enabled, we save our -display argument so that + // we are restored onto the correct head... one problem with this + // is that the display is hard coded, which means we cannot restore + // to a different display (ie. if we are in a university lab and try, + // try to restore a multihead session, our apps could be started on + // someone else's display instead of our own) + TQCString displayname = getenv(DISPLAY); + if (! displayname.isNull()) { + // only store the command if we actually have a DISPLAY + // environment variable + restartCommand.append("-display"); + restartCommand.append(displayname); + } + sm.setRestartCommand( restartCommand ); + } + + checkRestartVersion( sm ); + + // finally: do session management + emit saveYourself(); // for compatibility + bool canceled = false; + for (KSessionManaged* it = sessionClients()->first(); + it && !canceled; + it = sessionClients()->next() ) { + canceled = !it->saveState( sm ); + } + + // if we created a new session config object, register a proper discard command + if ( pSessionConfig ) { + pSessionConfig->sync(); + TQStringList discard; + discard << "rm" << locateLocal("config", sessionConfigName()); + sm.setDiscardCommand( discard ); + } else { + sm.setDiscardCommand( TQStringList("") ); + } + + if ( canceled ) + sm.cancel(); +#else + // FIXME(E): Implement for Qt Embedded +#endif + d->session_save = false; +} + +bool TDEApplication::sessionSaving() const +{ + return d->session_save; +} + +void TDEApplication::startKdeinit() +{ +#ifndef Q_WS_WIN //TODO + TDEInstance inst( "starttdeinitlock" ); + TDELockFile lock( locateLocal( "tmp", "starttdeinitlock", &inst )); + if( lock.lock( TDELockFile::LockNoBlock ) != TDELockFile::LockOK ) { + lock.lock(); + DCOPClient cl; + if( cl.attach()) + return; // whoever held the lock has already started dcopserver + } + // Try to launch tdeinit. + TQString srv = TDEStandardDirs::findExe(TQString::fromLatin1("tdeinit")); + if (srv.isEmpty()) + srv = TDEStandardDirs::findExe(TQString::fromLatin1("tdeinit"), TDEGlobal::dirs()->kfsstnd_defaultbindir()); + if (srv.isEmpty()) + return; + if (kapp && (Tty != kapp->type())) + setOverrideCursor( tqwaitCursor ); + my_system(TQFile::encodeName(srv)+" --suicide"+" --new-startup"); + if (kapp && (Tty != kapp->type())) + restoreOverrideCursor(); +#endif +} + +void TDEApplication::dcopFailure(const TQString &msg) +{ + static int failureCount = 0; + failureCount++; + if (failureCount == 1) + { + startKdeinit(); + return; + } + if (failureCount == 2) + { +#ifdef Q_WS_WIN + TDEGlobal::config()->setGroup("General"); + if (TDEGlobal::config()->readBoolEntry("ignoreDCOPFailures", false)) + return; +#endif + TQString msgStr(i18n("There was an error setting up inter-process " + "communications for TDE. The message returned " + "by the system was:\n\n")); + msgStr += msg; + msgStr += i18n("\n\nPlease check that the \"dcopserver\" program is running!"); + + if (Tty != kapp->type()) + { + TQMessageBox::critical + ( + kapp->mainWidget(), + i18n("DCOP communications error (%1)").arg(kapp->caption()), + msgStr, + i18n("&OK") + ); + } + else + { + fprintf(stderr, "%s\n", msgStr.local8Bit().data()); + } + + return; + } +} + +static const TDECmdLineOptions qt_options[] = +{ + //FIXME: Check if other options are specific to Qt/X11 +#ifdef Q_WS_X11 + { "display <displayname>", I18N_NOOP("Use the X-server display 'displayname'"), 0}, +#else + { "display <displayname>", I18N_NOOP("Use the QWS display 'displayname'"), 0}, +#endif + { "session <sessionId>", I18N_NOOP("Restore the application for the given 'sessionId'"), 0}, + { "cmap", I18N_NOOP("Causes the application to install a private color\nmap on an 8-bit display"), 0}, + { "ncols <count>", I18N_NOOP("Limits the number of colors allocated in the color\ncube on an 8-bit display, if the application is\nusing the TQApplication::ManyColor color\nspecification"), 0}, + { "nograb", I18N_NOOP("tells Qt to never grab the mouse or the keyboard"), 0}, + { "dograb", I18N_NOOP("running under a debugger can cause an implicit\n-nograb, use -dograb to override"), 0}, + { "sync", I18N_NOOP("switches to synchronous mode for debugging"), 0}, + { "fn", 0, 0}, + { "font <fontname>", I18N_NOOP("defines the application font"), 0}, + { "bg", 0, 0}, + { "background <color>", I18N_NOOP("sets the default background color and an\napplication palette (light and dark shades are\ncalculated)"), 0}, + { "fg", 0, 0}, + { "foreground <color>", I18N_NOOP("sets the default foreground color"), 0}, + { "btn", 0, 0}, + { "button <color>", I18N_NOOP("sets the default button color"), 0}, + { "name <name>", I18N_NOOP("sets the application name"), 0}, + { "title <title>", I18N_NOOP("sets the application title (caption)"), 0}, +#ifdef Q_WS_X11 + { "visual TrueColor", I18N_NOOP("forces the application to use a TrueColor visual on\nan 8-bit display"), 0}, + { "inputstyle <inputstyle>", I18N_NOOP("sets XIM (X Input Method) input style. Possible\nvalues are onthespot, overthespot, offthespot and\nroot"), 0 }, + { "im <XIM server>", I18N_NOOP("set XIM server"),0}, + { "noxim", I18N_NOOP("disable XIM"), 0 }, +#endif +#ifdef Q_WS_QWS + { "qws", I18N_NOOP("forces the application to run as QWS Server"), 0}, +#endif + { "reverse", I18N_NOOP("mirrors the whole layout of widgets"), 0}, + TDECmdLineLastOption +}; + +static const TDECmdLineOptions kde_options[] = +{ + { "caption <caption>", I18N_NOOP("Use 'caption' as name in the titlebar"), 0}, + { "icon <icon>", I18N_NOOP("Use 'icon' as the application icon"), 0}, + { "miniicon <icon>", I18N_NOOP("Use 'icon' as the icon in the titlebar"), 0}, + { "config <filename>", I18N_NOOP("Use alternative configuration file"), 0}, + { "dcopserver <server>", I18N_NOOP("Use the DCOP Server specified by 'server'"), 0}, + { "nocrashhandler", I18N_NOOP("Disable crash handler, to get core dumps"), 0}, + { "waitforwm", I18N_NOOP("Waits for a WM_NET compatible windowmanager"), 0}, + { "style <style>", I18N_NOOP("sets the application GUI style"), 0}, + { "geometry <geometry>", I18N_NOOP("sets the client geometry of the main widget - see man X for the argument format"), 0}, + { "smkey <sessionKey>", 0, 0}, // this option is obsolete and exists only to allow smooth upgrades from sessions + // saved under Qt 3.0.x -- Qt 3.1.x includes the session key now automatically in + // the session id (Simon) + TDECmdLineLastOption +}; + +void +TDEApplication::addCmdLineOptions() +{ + TDECmdLineArgs::addCmdLineOptions(qt_options, "Qt", "qt"); + TDECmdLineArgs::addCmdLineOptions(kde_options, "TDE", "tde"); +} + +void TDEApplication::parseCommandLine( ) +{ + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("tde"); + + if ( !args ) return; + + if (args->isSet("config")) + { + TQString config = TQString::fromLocal8Bit(args->getOption("config")); + setConfigName(config); + } + + if (args->isSet("style")) + { + + TQStringList plugins = TDEGlobal::dirs()->resourceDirs( "qtplugins" ); + TQStringList::Iterator itp = plugins.begin(); + while (itp != plugins.end()) { + addLibraryPath( *itp ); + ++itp; + } + + TQStringList styles = TQStyleFactory::keys(); + TQString reqStyle(args->getOption("style").lower()); + + TQStringList list = libraryPaths(); + TQStringList::Iterator it = list.begin(); + while( it != list.end() ) { + ++it; + } + + for (TQStringList::ConstIterator it = styles.begin(); it != styles.end(); ++it) { + if ((*it).lower() == reqStyle) + { + d->overrideStyle = *it; + break; + } + } + + if (d->overrideStyle.isEmpty()) + fprintf(stderr, "%s", TQString(i18n("The style %1 was not found\n").arg(reqStyle)).local8Bit().data()); + } + + if (args->isSet("caption")) + { + aCaption = TQString::fromLocal8Bit(args->getOption("caption")); + } + + if (args->isSet("miniicon")) + { + const char *tmp = args->getOption("miniicon"); + if (!aIconPixmap.pm.miniIcon) { + aIconPixmap.pm.miniIcon = new TQPixmap; + } + *aIconPixmap.pm.miniIcon = SmallIcon(tmp); + aMiniIconName = tmp; + } + + if (args->isSet("icon")) + { + const char *tmp = args->getOption("icon"); + if (!aIconPixmap.pm.icon) { + aIconPixmap.pm.icon = new TQPixmap; + } + *aIconPixmap.pm.icon = DesktopIcon( tmp ); + aIconName = tmp; + if (!aIconPixmap.pm.miniIcon) { + aIconPixmap.pm.miniIcon = new TQPixmap; + } + if (aIconPixmap.pm.miniIcon->isNull()) + { + *aIconPixmap.pm.miniIcon = SmallIcon( tmp ); + aMiniIconName = tmp; + } + } + + bool nocrashhandler = (getenv("TDE_DEBUG") != NULL); + if (!nocrashhandler && args->isSet("crashhandler")) + { + // set default crash handler / set emergency save function to nothing + TDECrash::setCrashHandler(TDECrash::defaultCrashHandler); + TDECrash::setEmergencySaveFunction(NULL); + + TDECrash::setApplicationName(TQString(args->appName())); + } + +#ifdef Q_WS_X11 + if ( args->isSet( "waitforwm" ) ) { + Atom type; + (void) desktop(); // trigger desktop creation, we need PropertyNotify events for the root window + int format; + unsigned long length, after; + unsigned char *data; + while ( XGetWindowProperty( tqt_xdisplay(), tqt_xrootwin(), atom_NetSupported, + 0, 1, false, AnyPropertyType, &type, &format, + &length, &after, &data ) != Success || !length ) { + if ( data ) + XFree( data ); + XEvent event; + XWindowEvent( tqt_xdisplay(), tqt_xrootwin(), PropertyChangeMask, &event ); + } + if ( data ) + XFree( data ); + } +#else + // FIXME(E): Implement for Qt Embedded +#endif + + if (args->isSet("geometry")) + { + d->geometry_arg = args->getOption("geometry"); + } + + if (args->isSet("smkey")) + { + d->sessionKey = args->getOption("smkey"); + } + +} + +TQString TDEApplication::geometryArgument() const +{ + return d->geometry_arg; +} + +TQPixmap TDEApplication::icon() const +{ + if( !aIconPixmap.pm.icon) { + aIconPixmap.pm.icon = new TQPixmap; + } + if( aIconPixmap.pm.icon->isNull()) { + *aIconPixmap.pm.icon = DesktopIcon( instanceName() ); + } + return *aIconPixmap.pm.icon; +} + +TQString TDEApplication::iconName() const +{ + return aIconName.isNull() ? (TQString)instanceName() : aIconName; +} + +TQPixmap TDEApplication::miniIcon() const +{ + if (!aIconPixmap.pm.miniIcon) { + aIconPixmap.pm.miniIcon = new TQPixmap; + } + if (aIconPixmap.pm.miniIcon->isNull()) { + *aIconPixmap.pm.miniIcon = SmallIcon( instanceName() ); + } + return *aIconPixmap.pm.miniIcon; +} + +TQString TDEApplication::miniIconName() const +{ + return aMiniIconName.isNull() ? (TQString)instanceName() : aMiniIconName; +} + +extern void kDebugCleanup(); + +TDEApplication::~TDEApplication() +{ + delete aIconPixmap.pm.miniIcon; + aIconPixmap.pm.miniIcon = 0L; + delete aIconPixmap.pm.icon; + aIconPixmap.pm.icon = 0L; + delete d->m_KAppDCOPInterface; + + // First call the static deleters and then call KLibLoader::cleanup() + // The static deleters may delete libraries for which they need KLibLoader. + // KLibLoader will take care of the remaining ones. + TDEGlobal::deleteStaticDeleters(); + KLibLoader::cleanUp(); + + delete smw; + + // close down IPC + delete s_DCOPClient; + s_DCOPClient = 0L; + + TDEProcessController::deref(); + +#ifdef Q_WS_X11 + if ( d->oldXErrorHandler != NULL ) + XSetErrorHandler( d->oldXErrorHandler ); + if ( d->oldXIOErrorHandler != NULL ) + XSetIOErrorHandler( d->oldXIOErrorHandler ); + if ( d->oldIceIOErrorHandler != NULL ) + IceSetIOErrorHandler( d->oldIceIOErrorHandler ); +#endif + + delete d; + KApp = 0; + +#ifdef Q_WS_X11 + mySmcConnection = 0; + delete smModificationTime; + smModificationTime = 0; + + // close the temporary smc connection + if (tmpSmcConnection) { + SmcCloseConnection( tmpSmcConnection, 0, 0 ); + tmpSmcConnection = 0; + } +#else + // FIXME(E): Implement for Qt Embedded +#endif +} + + +#ifdef Q_WS_X11 +class KAppX11HackWidget: public TQWidget +{ +public: + bool publicx11Event( XEvent * e) { return x11Event( e ); } +}; +#endif + +#if defined(Q_WS_X11) && defined(COMPOSITE) +bool TDEApplication::isCompositionManagerAvailable() { + bool have_manager = false; + const char *home; + struct passwd *p; + p = getpwuid(getuid()); + if (p) + home = p->pw_dir; + else + home = getenv("HOME"); + + char *filename; + const char *configfile = "/.kompmgr.available"; + int n = strlen(home)+strlen(configfile)+1; + filename = (char*)malloc(n*sizeof(char)); + memset(filename,0,n); + strcat(filename, home); + strcat(filename, configfile); + + // Now that we did all that by way of introduction...read the file! + FILE *pFile; + pFile = fopen(filename, "r"); + if (pFile) { + have_manager = true; + fclose(pFile); + } + + free(filename); + filename = NULL; + + return have_manager; +} + +bool TDEApplication::detectCompositionManagerAvailable(bool force_available, bool available) { + bool compositing_manager_available; + if (force_available) { + compositing_manager_available = available; + } + else { + // See if compositing has been enabled + TDECmdLineArgs *qtargs = TDECmdLineArgs::parsedArgs("qt"); + char *displayname = 0; + if ( qtargs->isSet("display")) + displayname = qtargs->getOption( "display" ).data(); + + Display *dpy = XOpenDisplay( displayname ); + + x11_composite_error_generated = false; + compositing_manager_available = false; + XSetErrorHandler(x11_error); + if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode, &composite_event, &composite_error)) { + XSetErrorHandler(NULL); + compositing_manager_available = false; + } + else { + if (available) { // FIXME This variable does double duty to avoid breaking the ABI for R14.0. In reality it should be called perform_deep_check + Window root_window = XDefaultRootWindow(dpy); + XCompositeRedirectSubwindows(dpy, root_window, CompositeRedirectManual); + XSync(dpy, false); + if (x11_composite_error_generated == true) { + compositing_manager_available = true; + } + else { + XCompositeUnredirectSubwindows(dpy, root_window, CompositeRedirectManual); + compositing_manager_available = false; + } + XSetErrorHandler(NULL); + XCloseDisplay(dpy); + } + else { + compositing_manager_available = true; + } + } + } + + const char *home; + struct passwd *p; + p = getpwuid(getuid()); + if (p) + home = p->pw_dir; + else + home = getenv("HOME"); + + char *filename; + const char *configfile = "/.kompmgr.available"; + int n = strlen(home)+strlen(configfile)+1; + filename = (char*)malloc(n*sizeof(char)); + memset(filename,0,n); + strcat(filename, home); + strcat(filename, configfile); + + /* now that we did all that by way of introduction...create or remove the file! */ + if (compositing_manager_available) { + FILE *pFile; + char buffer[255]; + sprintf(buffer, "available"); + pFile = fopen(filename, "w"); + if (pFile) { + fwrite(buffer,1,strlen(buffer), pFile); + fclose(pFile); + } + } + else { + unlink(filename); + } + + free(filename); + filename = NULL; + + return compositing_manager_available; +} + +Display* TDEApplication::openX11RGBADisplay() { + TDECmdLineArgs *qtargs = TDECmdLineArgs::parsedArgs("qt"); + char *display = 0; + if ( qtargs->isSet("display")) + display = qtargs->getOption( "display" ).data(); + + Display *dpy = XOpenDisplay( display ); + if ( !dpy ) { + kdError() << "cannot connect to X server " << display << endl; + exit( 1 ); + } + + return dpy; +} + +Qt::HANDLE TDEApplication::getX11RGBAVisual(Display *dpy) { + getX11RGBAInformation(dpy); + if (TDEApplication::isCompositionManagerAvailable() == true) { + return argb_x11_visual; + } + else { + return (Qt::HANDLE)NULL; + } +} + +Qt::HANDLE TDEApplication::getX11RGBAColormap(Display *dpy) { + getX11RGBAInformation(dpy); + if (TDEApplication::isCompositionManagerAvailable() == true) { + return argb_x11_colormap; + } + else { + return (Qt::HANDLE)NULL; + } +} + +bool TDEApplication::isX11CompositionAvailable() { + return (argb_visual & isCompositionManagerAvailable()); +} + +void TDEApplication::getX11RGBAInformation(Display *dpy) { + if ( !dpy ) { + argb_visual = false; + return; + } + + int screen = DefaultScreen( dpy ); + Colormap colormap = 0; + Visual *visual = 0; + int event_base, error_base; + + if ( XRenderQueryExtension( dpy, &event_base, &error_base ) ) { + int nvi; + XVisualInfo templ; + templ.screen = screen; + templ.depth = 32; + templ.c_class = TrueColor; + XVisualInfo *xvi = XGetVisualInfo( dpy, VisualScreenMask | VisualDepthMask + | VisualClassMask, &templ, &nvi ); + + for ( int i = 0; i < nvi; i++ ) { + XRenderPictFormat *format = XRenderFindVisualFormat( dpy, xvi[i].visual ); + if ( format->type == PictTypeDirect && format->direct.alphaMask ) { + visual = xvi[i].visual; + colormap = XCreateColormap( dpy, RootWindow( dpy, screen ), visual, AllocNone ); + kdDebug() << "found visual with alpha support" << endl; + argb_visual = true; + break; + } + } + } + + if( argb_visual ) { + argb_x11_visual = Qt::HANDLE( visual ); + argb_x11_colormap = Qt::HANDLE( colormap ); + argb_visual = true; + return; + } + argb_visual = false; + return; +} +#else +void TDEApplication::getX11RGBAInformation(Display *dpy) { +} + +bool TDEApplication::isCompositionManagerAvailable() { + return false; +} + +bool TDEApplication::detectCompositionManagerAvailable(bool force_available) { + const char *home; + struct passwd *p; + p = getpwuid(getuid()); + if (p) + home = p->pw_dir; + else + home = getenv("HOME"); + + char *filename; + const char *configfile = "/.kompmgr.available"; + int n = strlen(home)+strlen(configfile)+1; + filename = (char*)malloc(n*sizeof(char)); + memset(filename,0,n); + strcat(filename, home); + strcat(filename, configfile); + + /* now that we did all that by way of introduction...create or remove the file! */ + if (force_available) { + FILE *pFile; + char buffer[255]; + sprintf(buffer, "available"); + pFile = fopen(filename, "w"); + if (pFile) { + fwrite(buffer,1,strlen(buffer), pFile); + fclose(pFile); + } + } + else { + unlink(filename); + } + + free(filename); + filename = NULL; + + return false; +} + +Display* TDEApplication::openX11RGBADisplay() { + return 0; +} + +Qt::HANDLE TDEApplication::getX11RGBAVisual(char *display) { + return 0; +} + +Qt::HANDLE TDEApplication::getX11RGBAColormap(char *display) { + return 0; +} + +bool TDEApplication::isX11CompositionAvailable() { + return false; +} + +TDEApplication TDEApplication::KARGBApplication( bool allowStyles ) { + return TDEApplication::TDEApplication(allowStyles, true); +} +#endif + +static bool kapp_block_user_input = false; + +void TDEApplication::dcopBlockUserInput( bool b ) +{ + kapp_block_user_input = b; +} + +#ifdef Q_WS_X11 +bool TDEApplication::x11EventFilter( XEvent *_event ) +{ + switch ( _event->type ) { + case ClientMessage: + { +#if KDE_IS_VERSION( 3, 90, 90 ) +#warning This should be already in Qt, check. +#endif + // Workaround for focus stealing prevention not working when dragging e.g. text from KWrite + // to KDesktop -> the dialog asking for filename doesn't get activated. This is because + // Qt-3.2.x doesn't have concept of tqt_x_user_time at all, and Qt-3.3.0b1 passes the timestamp + // in the XdndDrop message in incorrect field (and doesn't update tqt_x_user_time either). + // Patch already sent, future Qt version should have this fixed. + if( _event->xclient.message_type == kde_xdnd_drop ) + { // if the message is XdndDrop + if( _event->xclient.data.l[ 1 ] == 1 << 24 // and it's broken the way it's in Qt-3.2.x + && _event->xclient.data.l[ 2 ] == 0 + && _event->xclient.data.l[ 4 ] == 0 + && _event->xclient.data.l[ 3 ] != 0 ) + { + if( GET_QT_X_USER_TIME() == 0 + || NET::timestampCompare( _event->xclient.data.l[ 3 ], GET_QT_X_USER_TIME() ) > 0 ) + { // and the timestamp looks reasonable + SET_QT_X_USER_TIME(_event->xclient.data.l[ 3 ]); // update our tqt_x_user_time from it + } + } + else // normal DND, only needed until Qt updates tqt_x_user_time from XdndDrop + { + if( GET_QT_X_USER_TIME() == 0 + || NET::timestampCompare( _event->xclient.data.l[ 2 ], GET_QT_X_USER_TIME() ) > 0 ) + { // the timestamp looks reasonable + SET_QT_X_USER_TIME(_event->xclient.data.l[ 2 ]); // update our tqt_x_user_time from it + } + } + } + } + default: break; + } + + if ( kapp_block_user_input ) { + switch ( _event->type ) { + case ButtonPress: + case ButtonRelease: + case XKeyPress: + case XKeyRelease: + case MotionNotify: + case EnterNotify: + case LeaveNotify: + return true; + default: + break; + } + } + + if (x11Filter) { + for (TQWidget *w=x11Filter->first(); w; w=x11Filter->next()) { + if (((KAppX11HackWidget*) w)->publicx11Event(_event)) + return true; + } + } + + if ((_event->type == ClientMessage) && + (_event->xclient.message_type == kipcCommAtom)) + { + XClientMessageEvent *cme = (XClientMessageEvent *) _event; + + int id = cme->data.l[0]; + int arg = cme->data.l[1]; + if ((id < 32) && (kipcEventMask & (1 << id))) + { + switch (id) + { + case KIPC::StyleChanged: + TDEGlobal::config()->reparseConfiguration(); + tdedisplaySetStyle(); + break; + + case KIPC::ToolbarStyleChanged: + TDEGlobal::config()->reparseConfiguration(); + if (useStyles) + emit toolbarAppearanceChanged(arg); + break; + + case KIPC::PaletteChanged: + TDEGlobal::config()->reparseConfiguration(); + tdedisplaySetPalette(); + break; + + case KIPC::FontChanged: + TDEGlobal::config()->reparseConfiguration(); + TDEGlobalSettings::rereadFontSettings(); + tdedisplaySetFont(); + break; + + case KIPC::BackgroundChanged: + emit backgroundChanged(arg); + break; + + case KIPC::SettingsChanged: + TDEGlobal::config()->reparseConfiguration(); + if (arg == SETTINGS_PATHS) + TDEGlobalSettings::rereadPathSettings(); + else if (arg == SETTINGS_MOUSE) + TDEGlobalSettings::rereadMouseSettings(); + propagateSettings((SettingsCategory)arg); + break; + + case KIPC::IconChanged: + TQPixmapCache::clear(); + TDEGlobal::config()->reparseConfiguration(); + TDEGlobal::instance()->newIconLoader(); + emit updateIconLoaders(); + emit iconChanged(arg); + break; + + case KIPC::ClipboardConfigChanged: + TDEClipboardSynchronizer::newConfiguration(arg); + break; + + case KIPC::BlockShortcuts: + TDEGlobalAccel::blockShortcuts(arg); + emit kipcMessage(id, arg); // some apps may do additional things + break; + } + } + else if (id >= 32) + { + emit kipcMessage(id, arg); + } + return true; + } + return false; +} +#endif // Q_WS_X11 + +void TDEApplication::updateUserTimestamp( unsigned long time ) +{ +#if defined Q_WS_X11 + if( time == 0 ) + { // get current X timestamp + Window w = XCreateSimpleWindow( tqt_xdisplay(), tqt_xrootwin(), 0, 0, 1, 1, 0, 0, 0 ); + XSelectInput( tqt_xdisplay(), w, PropertyChangeMask ); + unsigned char data[ 1 ]; + XChangeProperty( tqt_xdisplay(), w, XA_ATOM, XA_ATOM, 8, PropModeAppend, data, 1 ); + XEvent ev; + XWindowEvent( tqt_xdisplay(), w, PropertyChangeMask, &ev ); + time = ev.xproperty.time; + XDestroyWindow( tqt_xdisplay(), w ); + } + if( GET_QT_X_USER_TIME() == 0 + || NET::timestampCompare( time, GET_QT_X_USER_TIME() ) > 0 ) // check time > tqt_x_user_time + SET_QT_X_USER_TIME(time); +#endif +} + +unsigned long TDEApplication::userTimestamp() const +{ +#if defined Q_WS_X11 + return GET_QT_X_USER_TIME(); +#else + return 0; +#endif +} + +void TDEApplication::updateRemoteUserTimestamp( const TQCString& dcopId, unsigned long time ) +{ +#if defined Q_WS_X11 + if( time == 0 ) + time = GET_QT_X_USER_TIME(); + DCOPRef( dcopId, "MainApplication-Interface" ).call( "updateUserTimestamp", time ); +#endif +} + +void TDEApplication::invokeEditSlot( const char *slot ) +{ + TQObject *object = TQT_TQOBJECT(focusWidget()); + if( !object ) + return; + + TQMetaObject *meta = object->metaObject(); + + int idx = meta->findSlot( slot + 1, true ); + if( idx < 0 ) + return; + + object->tqt_invoke( idx, 0 ); +} + +void TDEApplication::addKipcEventMask(int id) +{ + if (id >= 32) + { + kdDebug(101) << "Cannot use KIPC event mask for message IDs >= 32\n"; + return; + } + kipcEventMask |= (1 << id); +} + +void TDEApplication::removeKipcEventMask(int id) +{ + if (id >= 32) + { + kdDebug(101) << "Cannot use KIPC event mask for message IDs >= 32\n"; + return; + } + kipcEventMask &= ~(1 << id); +} + +void TDEApplication::enableStyles() +{ + if (!useStyles) + { + useStyles = true; + applyGUIStyle(); + } +} + +void TDEApplication::disableStyles() +{ + useStyles = false; +} + +void TDEApplication::applyGUIStyle() +{ + if ( !useStyles ) return; + + TDEConfigGroup pConfig (TDEGlobal::config(), "General"); + TQString defaultStyle = TDEStyle::defaultStyle(); + TQString styleStr = pConfig.readEntry("widgetStyle", defaultStyle); + + if (d->overrideStyle.isEmpty()) { + // ### add check whether we already use the correct style to return then + // (workaround for Qt misbehavior to avoid double style initialization) + + TQStyle* sp = TQStyleFactory::create( styleStr ); + + // If there is no default style available, try falling back any available style + if ( !sp && styleStr != defaultStyle) + sp = TQStyleFactory::create( defaultStyle ); + if ( !sp ) + sp = TQStyleFactory::create( *(TQStyleFactory::keys().begin()) ); + setStyle(sp); + } + else + setStyle(d->overrideStyle); + // Reread palette from config file. + tdedisplaySetPalette(); +} + +TQString TDEApplication::caption() const +{ + // Caption set from command line ? + if( !aCaption.isNull() ) + return aCaption; + else + // We have some about data ? + if ( TDEGlobal::instance()->aboutData() ) + return TDEGlobal::instance()->aboutData()->programName(); + else + // Last resort : application name + return name(); +} + + +// +// 1999-09-20: Espen Sand +// An attempt to simplify consistent captions. +// +TQString TDEApplication::makeStdCaption( const TQString &userCaption, + bool withAppName, bool modified ) const +{ + TQString s = userCaption.isEmpty() ? caption() : userCaption; + + // If the document is modified, add '[modified]'. + if (modified) + s += TQString::fromUtf8(" [") + i18n("modified") + TQString::fromUtf8("]"); + + if ( !userCaption.isEmpty() ) { + // Add the application name if: + // User asked for it, it's not a duplication and the app name (caption()) is not empty + if ( withAppName && !caption().isNull() && !userCaption.endsWith(caption()) ) + s += TQString::fromUtf8(" - ") + caption(); + } + + return s; +} + +TQPalette TDEApplication::createApplicationPalette() +{ + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "General" ); + return createApplicationPalette( config, TDEGlobalSettings::contrast() ); +} + +TQPalette TDEApplication::createApplicationPalette( TDEConfig *config, int contrast_ ) +{ + TQColor trinity4Background( 239, 239, 239 ); + TQColor trinity4Blue( 103,141,178 ); + + TQColor trinity4Button; + if ( TQPixmap::defaultDepth() > 8 ) + trinity4Button.setRgb( 221, 223, 228 ); + else + trinity4Button.setRgb( 220, 220, 220 ); + + TQColor trinity4Link( 0, 0, 238 ); + TQColor trinity4VisitedLink( 82, 24, 139 ); + + TQColor background = config->readColorEntry( "background", &trinity4Background ); + TQColor foreground = config->readColorEntry( "foreground", tqblackptr ); + TQColor button = config->readColorEntry( "buttonBackground", &trinity4Button ); + TQColor buttonText = config->readColorEntry( "buttonForeground", tqblackptr ); + TQColor highlight = config->readColorEntry( "selectBackground", &trinity4Blue ); + TQColor highlightedText = config->readColorEntry( "selectForeground", tqwhiteptr ); + TQColor base = config->readColorEntry( "windowBackground", tqwhiteptr ); + TQColor baseText = config->readColorEntry( "windowForeground", tqblackptr ); + TQColor link = config->readColorEntry( "linkColor", &trinity4Link ); + TQColor visitedLink = config->readColorEntry( "visitedLinkColor", &trinity4VisitedLink ); + + int highlightVal, lowlightVal; + highlightVal = 100 + (2*contrast_+4)*16/10; + lowlightVal = 100 + (2*contrast_+4)*10; + + TQColor disfg = foreground; + + int h, s, v; + disfg.hsv( &h, &s, &v ); + if (v > 128) + // dark bg, light fg - need a darker disabled fg + disfg = disfg.dark(lowlightVal); + else if (disfg != Qt::black) + // light bg, dark fg - need a lighter disabled fg - but only if !black + disfg = disfg.light(highlightVal); + else + // black fg - use darkgray disabled fg + disfg = Qt::darkGray; + + + TQColorGroup disabledgrp(disfg, background, + background.light(highlightVal), + background.dark(lowlightVal), + background.dark(120), + background.dark(120), base); + + TQColorGroup colgrp(foreground, background, background.light(highlightVal), + background.dark(lowlightVal), + background.dark(120), + baseText, base); + + int inlowlightVal = lowlightVal-25; + if(inlowlightVal < 120) + inlowlightVal = 120; + + colgrp.setColor(TQColorGroup::Highlight, highlight); + colgrp.setColor(TQColorGroup::HighlightedText, highlightedText); + colgrp.setColor(TQColorGroup::Button, button); + colgrp.setColor(TQColorGroup::ButtonText, buttonText); + colgrp.setColor(TQColorGroup::Midlight, background.light(110)); + colgrp.setColor(TQColorGroup::Link, link); + colgrp.setColor(TQColorGroup::LinkVisited, visitedLink); + + disabledgrp.setColor(TQColorGroup::Button, button); + + TQColor disbtntext = buttonText; + disbtntext.hsv( &h, &s, &v ); + if (v > 128) + // dark button, light buttonText - need a darker disabled buttonText + disbtntext = disbtntext.dark(lowlightVal); + else if (disbtntext != Qt::black) + // light buttonText, dark button - need a lighter disabled buttonText - but only if !black + disbtntext = disbtntext.light(highlightVal); + else + // black button - use darkgray disabled buttonText + disbtntext = Qt::darkGray; + + disabledgrp.setColor(TQColorGroup::ButtonText, disbtntext); + disabledgrp.setColor(TQColorGroup::Midlight, background.light(110)); + disabledgrp.setColor(TQColorGroup::Highlight, highlight.dark(120)); + disabledgrp.setColor(TQColorGroup::Link, link); + disabledgrp.setColor(TQColorGroup::LinkVisited, visitedLink); + + return TQPalette(colgrp, disabledgrp, colgrp); +} + + +void TDEApplication::tdedisplaySetPalette() +{ +#ifdef Q_WS_MACX + //Can I have this on other platforms, please!? --Sam + { + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "General" ); + bool do_not_set_palette = FALSE; + if(config->readBoolEntry("nopaletteChange", &do_not_set_palette)) + return; + } +#endif + TQApplication::setPalette( createApplicationPalette(), true); + emit tdedisplayPaletteChanged(); + emit appearanceChanged(); +} + + +void TDEApplication::tdedisplaySetFont() +{ + TQApplication::setFont(TDEGlobalSettings::generalFont(), true); + TQApplication::setFont(TDEGlobalSettings::menuFont(), true, TQMENUBAR_OBJECT_NAME_STRING); + TQApplication::setFont(TDEGlobalSettings::menuFont(), true, TQPOPUPMENU_OBJECT_NAME_STRING); + TQApplication::setFont(TDEGlobalSettings::menuFont(), true, "TDEPopupTitle"); + + // "patch" standard TQStyleSheet to follow our fonts + TQStyleSheet* sheet = TQStyleSheet::defaultSheet(); + sheet->item ("pre")->setFontFamily (TDEGlobalSettings::fixedFont().family()); + sheet->item ("code")->setFontFamily (TDEGlobalSettings::fixedFont().family()); + sheet->item ("tt")->setFontFamily (TDEGlobalSettings::fixedFont().family()); + + emit tdedisplayFontChanged(); + emit appearanceChanged(); +} + + +void TDEApplication::tdedisplaySetStyle() +{ + if (useStyles) + { + applyGUIStyle(); + emit tdedisplayStyleChanged(); + emit appearanceChanged(); + } +} + + +void TDEApplication::propagateSettings(SettingsCategory arg) +{ + TDEConfigBase* config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "KDE" ); + +#ifdef QT_HAVE_MAX_IMAGE_SIZE + TQSize maxImageSize(4096, 4096); + maxImageSize = config->readSizeEntry("MaxImageSize", &maxImageSize); + TQImage::setMaxImageSize(maxImageSize); +#endif + + int num = config->readNumEntry("CursorBlinkRate", TQApplication::cursorFlashTime()); + if ((num != 0) && (num < 200)) + num = 200; + if (num > 2000) + num = 2000; + TQApplication::setCursorFlashTime(num); + num = config->readNumEntry("DoubleClickInterval", TQApplication::doubleClickInterval()); + TQApplication::setDoubleClickInterval(num); + num = config->readNumEntry("StartDragTime", TQApplication::startDragTime()); + TQApplication::setStartDragTime(num); + num = config->readNumEntry("StartDragDist", TQApplication::startDragDistance()); + TQApplication::setStartDragDistance(num); + num = config->readNumEntry("WheelScrollLines", TQApplication::wheelScrollLines()); + TQApplication::setWheelScrollLines(num); + + bool b = config->readBoolEntry("EffectAnimateMenu", false); + TQApplication::setEffectEnabled( Qt::UI_AnimateMenu, b); + b = config->readBoolEntry("EffectFadeMenu", false); + TQApplication::setEffectEnabled( Qt::UI_FadeMenu, b); + b = config->readBoolEntry("EffectAnimateCombo", false); + TQApplication::setEffectEnabled( Qt::UI_AnimateCombo, b); + b = config->readBoolEntry("EffectAnimateTooltip", false); + TQApplication::setEffectEnabled( Qt::UI_AnimateTooltip, b); + b = config->readBoolEntry("EffectFadeTooltip", false); + TQApplication::setEffectEnabled( Qt::UI_FadeTooltip, b); + b = !config->readBoolEntry("EffectNoTooltip", false); + TQToolTip::setGloballyEnabled( b ); + + emit settingsChanged(arg); +} + +void TDEApplication::installKDEPropertyMap() +{ +#ifndef QT_NO_SQL + static bool installed = false; + if (installed) return; + installed = true; + /** + * If you are adding a widget that was missing please + * make sure to also add it to TDEConfigDialogManager's retrieveSettings() + * function. + * Thanks. + */ + // TQSqlPropertyMap takes ownership of the new default map. + TQSqlPropertyMap *kdeMap = new TQSqlPropertyMap; + kdeMap->insert( "KColorButton", "color" ); + kdeMap->insert( "KComboBox", "currentItem" ); + kdeMap->insert( "KDatePicker", "date" ); + kdeMap->insert( "KDateWidget", "date" ); + kdeMap->insert( "KDateTimeWidget", "dateTime" ); + kdeMap->insert( "KEditListBox", "items" ); + kdeMap->insert( "TDEFontCombo", "family" ); + kdeMap->insert( "TDEFontRequester", "font" ); + kdeMap->insert( "TDEFontChooser", "font" ); + kdeMap->insert( "KHistoryCombo", "currentItem" ); + kdeMap->insert( "TDEListBox", "currentItem" ); + kdeMap->insert( "KLineEdit", "text" ); + kdeMap->insert( "KRestrictedLine", "text" ); + kdeMap->insert( "KSqueezedTextLabel", "text" ); + kdeMap->insert( "KTextBrowser", "source" ); + kdeMap->insert( "KTextEdit", "text" ); + kdeMap->insert( "KURLRequester", "url" ); + kdeMap->insert( "KPasswordEdit", "password" ); + kdeMap->insert( "KIntNumInput", "value" ); + kdeMap->insert( "KIntSpinBox", "value" ); + kdeMap->insert( "KDoubleNumInput", "value" ); + // Temp til fixed in QT then enable ifdef with the correct version num + kdeMap->insert( TQGROUPBOX_OBJECT_NAME_STRING, "checked" ); + kdeMap->insert( TQTABWIDGET_OBJECT_NAME_STRING, "currentPage" ); + TQSqlPropertyMap::installDefaultMap( kdeMap ); +#endif +} + +void TDEApplication::invokeHelp( const TQString& anchor, + const TQString& _appname) const +{ + return invokeHelp( anchor, _appname, "" ); +} + +#ifndef Q_WS_WIN +// for win32 we're using simple help tools like Qt Assistant, +// see kapplication_win.cpp +void TDEApplication::invokeHelp( const TQString& anchor, + const TQString& _appname, + const TQCString& startup_id ) const +{ + TQString url; + TQString appname; + if (_appname.isEmpty()) + appname = name(); + else + appname = _appname; + + if (!anchor.isEmpty()) + url = TQString("help:/%1?anchor=%2").arg(appname).arg(anchor); + else + url = TQString("help:/%1/index.html").arg(appname); + + TQString error; + if ( !dcopClient()->isApplicationRegistered("khelpcenter") ) + { + if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, startup_id, false)) + { + if (Tty != kapp->type()) + TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Help Center"), + i18n("Could not launch the TDE Help Center:\n\n%1").arg(error), i18n("&OK")); + else + kdWarning() << "Could not launch help:\n" << error << endl; + return; + } + } + else + DCOPRef( "khelpcenter", "KHelpCenterIface" ).send( "openUrl", url, startup_id ); +} +#endif + +void TDEApplication::invokeHTMLHelp( const TQString& _filename, const TQString& topic ) const +{ + kdWarning() << "invoking HTML help is deprecated! use docbook and invokeHelp!\n"; + + TQString filename; + + if( _filename.isEmpty() ) + filename = TQString(name()) + "/index.html"; + else + filename = _filename; + + TQString url; + if (!topic.isEmpty()) + url = TQString("help:/%1#%2").arg(filename).arg(topic); + else + url = TQString("help:/%1").arg(filename); + + TQString error; + if ( !dcopClient()->isApplicationRegistered("khelpcenter") ) + { + if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, "", false)) + { + if (Tty != kapp->type()) + TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Help Center"), + i18n("Could not launch the TDE Help Center:\n\n%1").arg(error), i18n("&OK")); + else + kdWarning() << "Could not launch help:\n" << error << endl; + return; + } + } + else + DCOPRef( "khelpcenter", "KHelpCenterIface" ).send( "openUrl", url ); +} + + +void TDEApplication::invokeMailer(const TQString &address, const TQString &subject) +{ + return invokeMailer(address,subject,""); +} + +void TDEApplication::invokeMailer(const TQString &address, const TQString &subject, const TQCString& startup_id) +{ + invokeMailer(address, TQString::null, TQString::null, subject, TQString::null, TQString::null, + TQStringList(), startup_id ); +} + +void TDEApplication::invokeMailer(const KURL &mailtoURL) +{ + return invokeMailer( mailtoURL, "" ); +} + +void TDEApplication::invokeMailer(const KURL &mailtoURL, const TQCString& startup_id ) +{ + return invokeMailer( mailtoURL, startup_id, false); +} + +void TDEApplication::invokeMailer(const KURL &mailtoURL, const TQCString& startup_id, bool allowAttachments ) +{ + TQString address = KURL::decode_string(mailtoURL.path()), subject, cc, bcc, body; + TQStringList queries = TQStringList::split('&', mailtoURL.query().mid(1)); + TQStringList attachURLs; + for (TQStringList::Iterator it = queries.begin(); it != queries.end(); ++it) + { + TQString q = (*it).lower(); + if (q.startsWith("subject=")) + subject = KURL::decode_string((*it).mid(8)); + else + if (q.startsWith("cc=")) + cc = cc.isEmpty()? KURL::decode_string((*it).mid(3)): cc + ',' + KURL::decode_string((*it).mid(3)); + else + if (q.startsWith("bcc=")) + bcc = bcc.isEmpty()? KURL::decode_string((*it).mid(4)): bcc + ',' + KURL::decode_string((*it).mid(4)); + else + if (q.startsWith("body=")) + body = KURL::decode_string((*it).mid(5)); + else + if (allowAttachments && q.startsWith("attach=")) + attachURLs.push_back(KURL::decode_string((*it).mid(7))); + else + if (allowAttachments && q.startsWith("attachment=")) + attachURLs.push_back(KURL::decode_string((*it).mid(11))); + else + if (q.startsWith("to=")) + address = address.isEmpty()? KURL::decode_string((*it).mid(3)): address + ',' + KURL::decode_string((*it).mid(3)); + } + + invokeMailer( address, cc, bcc, subject, body, TQString::null, attachURLs, startup_id ); +} + +void TDEApplication::invokeMailer(const TQString &to, const TQString &cc, const TQString &bcc, + const TQString &subject, const TQString &body, + const TQString & messageFile, const TQStringList &attachURLs) +{ + return invokeMailer(to,cc,bcc,subject,body,messageFile,attachURLs,""); +} + +#ifndef Q_WS_WIN +// on win32, for invoking browser we're using win32 API +// see kapplication_win.cpp + +static TQStringList splitEmailAddressList( const TQString & aStr ) +{ + // This is a copy of KPIM::splitEmailAddrList(). + // Features: + // - always ignores quoted characters + // - ignores everything (including parentheses and commas) + // inside quoted strings + // - supports nested comments + // - ignores everything (including double quotes and commas) + // inside comments + + TQStringList list; + + if (aStr.isEmpty()) + return list; + + TQString addr; + uint addrstart = 0; + int commentlevel = 0; + bool insidequote = false; + + for (uint index=0; index<aStr.length(); index++) { + // the following conversion to latin1 is o.k. because + // we can safely ignore all non-latin1 characters + switch (aStr[index].latin1()) { + case '"' : // start or end of quoted string + if (commentlevel == 0) + insidequote = !insidequote; + break; + case '(' : // start of comment + if (!insidequote) + commentlevel++; + break; + case ')' : // end of comment + if (!insidequote) { + if (commentlevel > 0) + commentlevel--; + else { + //kdDebug() << "Error in address splitting: Unmatched ')'" + // << endl; + return list; + } + } + break; + case '\\' : // quoted character + index++; // ignore the quoted character + break; + case ',' : + if (!insidequote && (commentlevel == 0)) { + addr = aStr.mid(addrstart, index-addrstart); + if (!addr.isEmpty()) + list += addr.simplifyWhiteSpace(); + addrstart = index+1; + } + break; + } + } + // append the last address to the list + if (!insidequote && (commentlevel == 0)) { + addr = aStr.mid(addrstart, aStr.length()-addrstart); + if (!addr.isEmpty()) + list += addr.simplifyWhiteSpace(); + } + //else + // kdDebug() << "Error in address splitting: " + // << "Unexpected end of address list" + // << endl; + + return list; +} + +void TDEApplication::invokeMailer(const TQString &_to, const TQString &_cc, const TQString &_bcc, + const TQString &subject, const TQString &body, + const TQString & /*messageFile TODO*/, const TQStringList &attachURLs, + const TQCString& startup_id ) +{ + TDEConfig config("emaildefaults"); + + config.setGroup("Defaults"); + TQString group = config.readEntry("Profile","Default"); + + config.setGroup( TQString("PROFILE_%1").arg(group) ); + TQString command = config.readPathEntry("EmailClient"); + + TQString to, cc, bcc; + if (command.isEmpty() || command == TQString::fromLatin1("kmail") + || command.endsWith("/kmail")) + { + command = TQString::fromLatin1("kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t"); + if ( !_to.isEmpty() ) + { + // put the whole address lists into RFC2047 encoded blobs; technically + // this isn't correct, but KMail understands it nonetheless + to = TQString( "=?utf8?b?%1?=" ) + .arg( TQString(KCodecs::base64Encode( _to.utf8(), false )) ); + } + if ( !_cc.isEmpty() ) + cc = TQString( "=?utf8?b?%1?=" ) + .arg( TQString(KCodecs::base64Encode( _cc.utf8(), false )) ); + if ( !_bcc.isEmpty() ) + bcc = TQString( "=?utf8?b?%1?=" ) + .arg( TQString(KCodecs::base64Encode( _bcc.utf8(), false )) ); + } else { + to = _to; + cc = _cc; + bcc = _bcc; + if( !command.contains( '%' )) + command += " %u"; + } + + if (config.readBoolEntry("TerminalClient", false)) + { + TDEConfigGroup confGroup( TDEGlobal::config(), "General" ); + TQString preferredTerminal = confGroup.readPathEntry("TerminalApplication", "konsole"); + command = preferredTerminal + " -e " + command; + } + + TQStringList cmdTokens = KShell::splitArgs(command); + TQString cmd = cmdTokens[0]; + cmdTokens.remove(cmdTokens.begin()); + + KURL url; + TQStringList qry; + if (!to.isEmpty()) + { + TQStringList tos = splitEmailAddressList( to ); + url.setPath( tos.first() ); + tos.remove( tos.begin() ); + for (TQStringList::ConstIterator it = tos.begin(); it != tos.end(); ++it) + qry.append( "to=" + KURL::encode_string( *it ) ); + } + const TQStringList ccs = splitEmailAddressList( cc ); + for (TQStringList::ConstIterator it = ccs.begin(); it != ccs.end(); ++it) + qry.append( "cc=" + KURL::encode_string( *it ) ); + const TQStringList bccs = splitEmailAddressList( bcc ); + for (TQStringList::ConstIterator it = bccs.begin(); it != bccs.end(); ++it) + qry.append( "bcc=" + KURL::encode_string( *it ) ); + for (TQStringList::ConstIterator it = attachURLs.begin(); it != attachURLs.end(); ++it) + qry.append( "attach=" + KURL::encode_string( *it ) ); + if (!subject.isEmpty()) + qry.append( "subject=" + KURL::encode_string( subject ) ); + if (!body.isEmpty()) + qry.append( "body=" + KURL::encode_string( body ) ); + url.setQuery( qry.join( "&" ) ); + if ( ! (to.isEmpty() && qry.isEmpty()) ) + url.setProtocol("mailto"); + + TQMap<TQChar, TQString> keyMap; + keyMap.insert('t', to); + keyMap.insert('s', subject); + keyMap.insert('c', cc); + keyMap.insert('b', bcc); + keyMap.insert('B', body); + keyMap.insert('u', url.url()); + + TQString attachlist = attachURLs.join(","); + attachlist.prepend('\''); + attachlist.append('\''); + keyMap.insert('A', attachlist); + + for (TQStringList::Iterator it = cmdTokens.begin(); it != cmdTokens.end(); ) + { + if (*it == "%A") + { + if (it == cmdTokens.begin()) // better safe than sorry ... + continue; + TQStringList::ConstIterator urlit = attachURLs.begin(); + TQStringList::ConstIterator urlend = attachURLs.end(); + if ( urlit != urlend ) + { + TQStringList::Iterator previt = it; + --previt; + *it = *urlit; + ++it; + while ( ++urlit != urlend ) + { + cmdTokens.insert( it, *previt ); + cmdTokens.insert( it, *urlit ); + } + } else { + --it; + it = cmdTokens.remove( cmdTokens.remove( it ) ); + } + } else { + *it = KMacroExpander::expandMacros(*it, keyMap); + ++it; + } + } + + TQString error; + // TODO this should check if cmd has a .desktop file, and use data from it, together + // with sending more ASN data + if (tdeinitExec(cmd, cmdTokens, &error, NULL, startup_id )) { + if (Tty != kapp->type()) { + TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Mail Client"), + i18n("Could not launch the mail client:\n\n%1").arg(error), i18n("&OK")); + } + else { + kdWarning() << "Could not launch mail client:\n" << error << endl; + } + } +} +#endif + +void TDEApplication::invokeBrowser( const TQString &url ) +{ + return invokeBrowser( url, "" ); +} + +#ifndef Q_WS_WIN +// on win32, for invoking browser we're using win32 API +// see kapplication_win.cpp +void TDEApplication::invokeBrowser( const TQString &url, const TQCString& startup_id ) +{ + TQString error; + + if (startServiceByDesktopName("kfmclient", url, &error, 0, 0, startup_id, false)) + { + if (Tty != kapp->type()) + TQMessageBox::critical(kapp->mainWidget(), i18n("Could not Launch Browser"), + i18n("Could not launch the browser:\n\n%1").arg(error), i18n("&OK")); + else + kdWarning() << "Could not launch browser:\n" << error << endl; + return; + } +} +#endif + +void TDEApplication::cut() +{ + invokeEditSlot( TQT_SLOT( cut() ) ); +} + +void TDEApplication::copy() +{ + invokeEditSlot( TQT_SLOT( copy() ) ); +} + +void TDEApplication::paste() +{ + invokeEditSlot( TQT_SLOT( paste() ) ); +} + +void TDEApplication::clear() +{ + invokeEditSlot( TQT_SLOT( clear() ) ); +} + +void TDEApplication::selectAll() +{ + invokeEditSlot( TQT_SLOT( selectAll() ) ); +} + +void TDEApplication::broadcastKeyCode(unsigned int keyCode) +{ + emit coreFakeKeyPress(keyCode); +} + +TQCString +TDEApplication::launcher() +{ + return "tdelauncher"; +} + +static int +startServiceInternal( const TQCString &function, + const TQString& _name, const TQStringList &URLs, + TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) +{ + struct serviceResult + { + int result; + TQCString dcopName; + TQString error; + pid_t pid; + }; + + // Register app as able to send DCOP messages + DCOPClient *dcopClient; + if (kapp) + dcopClient = kapp->dcopClient(); + else + dcopClient = new DCOPClient; + + if (!dcopClient->isAttached()) + { + if (!dcopClient->attach()) + { + if (error) + *error = i18n("Could not register with DCOP.\n"); + if (!kapp) + delete dcopClient; + + return -1; + } + } + TQByteArray params; + TQDataStream stream(params, IO_WriteOnly); + stream << _name << URLs; + TQCString replyType; + TQByteArray replyData; + TQCString _launcher = TDEApplication::launcher(); + TQValueList<TQCString> envs; +#ifdef Q_WS_X11 + if (tqt_xdisplay()) { + TQCString dpystring(XDisplayString(tqt_xdisplay())); + envs.append( TQCString("DISPLAY=") + dpystring ); + } else if( getenv( "DISPLAY" )) { + TQCString dpystring( getenv( "DISPLAY" )); + envs.append( TQCString("DISPLAY=") + dpystring ); + } +#endif + stream << envs; +#if defined Q_WS_X11 + // make sure there is id, so that user timestamp exists + stream << ( startup_id.isEmpty() ? TDEStartupInfo::createNewStartupId() : startup_id ); +#endif + if( function.left( 12 ) != "tdeinit_exec" ) + stream << noWait; + + if (!dcopClient->call(_launcher, _launcher, + function, params, replyType, replyData)) + { + if (error) + *error = i18n("TDELauncher could not be reached via DCOP.\n"); + if (!kapp) + delete dcopClient; + return -1; + } + if (!kapp) + delete dcopClient; + + if (noWait) + return 0; + + TQDataStream stream2(replyData, IO_ReadOnly); + serviceResult result; + stream2 >> result.result >> result.dcopName >> result.error >> result.pid; + if (dcopService) + *dcopService = result.dcopName; + if (error) + *error = result.error; + if (pid) + *pid = result.pid; + return result.result; +} + +int +TDEApplication::startServiceByName( const TQString& _name, const TQString &URL, + TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) +{ + TQStringList URLs; + if (!URL.isEmpty()) + URLs.append(URL); + return startServiceInternal( + "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", + _name, URLs, error, dcopService, pid, startup_id, noWait); +} + +int +TDEApplication::startServiceByName( const TQString& _name, const TQStringList &URLs, + TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) +{ + return startServiceInternal( + "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", + _name, URLs, error, dcopService, pid, startup_id, noWait); +} + +int +TDEApplication::startServiceByDesktopPath( const TQString& _name, const TQString &URL, + TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) +{ + TQStringList URLs; + if (!URL.isEmpty()) + URLs.append(URL); + return startServiceInternal( + "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", + _name, URLs, error, dcopService, pid, startup_id, noWait); +} + +int +TDEApplication::startServiceByDesktopPath( const TQString& _name, const TQStringList &URLs, + TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) +{ + return startServiceInternal( + "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", + _name, URLs, error, dcopService, pid, startup_id, noWait); +} + +int +TDEApplication::startServiceByDesktopName( const TQString& _name, const TQString &URL, + TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) +{ + TQStringList URLs; + if (!URL.isEmpty()) + URLs.append(URL); + return startServiceInternal( + "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", + _name, URLs, error, dcopService, pid, startup_id, noWait); +} + +int +TDEApplication::startServiceByDesktopName( const TQString& _name, const TQStringList &URLs, + TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait ) +{ + return startServiceInternal( + "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)", + _name, URLs, error, dcopService, pid, startup_id, noWait); +} + +int +TDEApplication::tdeinitExec( const TQString& name, const TQStringList &args, + TQString *error, int *pid ) +{ + return tdeinitExec( name, args, error, pid, "" ); +} + +int +TDEApplication::tdeinitExec( const TQString& name, const TQStringList &args, + TQString *error, int *pid, const TQCString& startup_id ) +{ + return startServiceInternal("tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)", + name, args, error, 0, pid, startup_id, false); +} + +int +TDEApplication::tdeinitExecWait( const TQString& name, const TQStringList &args, + TQString *error, int *pid ) +{ + return tdeinitExecWait( name, args, error, pid, "" ); +} + +int +TDEApplication::tdeinitExecWait( const TQString& name, const TQStringList &args, + TQString *error, int *pid, const TQCString& startup_id ) +{ + return startServiceInternal("tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>,TQCString)", + name, args, error, 0, pid, startup_id, false); +} + +TQString TDEApplication::tempSaveName( const TQString& pFilename ) const +{ + TQString aFilename; + + if( TQDir::isRelativePath(pFilename) ) + { + kdWarning(101) << "Relative filename passed to TDEApplication::tempSaveName" << endl; + aFilename = TQFileInfo( TQDir( "." ), pFilename ).absFilePath(); + } + else + aFilename = pFilename; + + TQDir aAutosaveDir( TQDir::homeDirPath() + "/autosave/" ); + if( !aAutosaveDir.exists() ) + { + if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) ) + { + // Last chance: use temp dir + aAutosaveDir.setPath( TDEGlobal::dirs()->saveLocation("tmp") ); + } + } + + aFilename.replace( "/", "\\!" ).prepend( "#" ).append( "#" ).prepend( "/" ).prepend( aAutosaveDir.absPath() ); + + return aFilename; +} + + +TQString TDEApplication::checkRecoverFile( const TQString& pFilename, + bool& bRecover ) const +{ + TQString aFilename; + + if( TQDir::isRelativePath(pFilename) ) + { + kdWarning(101) << "Relative filename passed to TDEApplication::tempSaveName" << endl; + aFilename = TQFileInfo( TQDir( "." ), pFilename ).absFilePath(); + } + else + aFilename = pFilename; + + TQDir aAutosaveDir( TQDir::homeDirPath() + "/autosave/" ); + if( !aAutosaveDir.exists() ) + { + if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) ) + { + // Last chance: use temp dir + aAutosaveDir.setPath( TDEGlobal::dirs()->saveLocation("tmp") ); + } + } + + aFilename.replace( "/", "\\!" ).prepend( "#" ).append( "#" ).prepend( "/" ).prepend( aAutosaveDir.absPath() ); + + if( TQFile( aFilename ).exists() ) + { + bRecover = true; + return aFilename; + } + else + { + bRecover = false; + return pFilename; + } +} + + +bool checkAccess(const TQString& pathname, int mode) +{ + int accessOK = access( TQFile::encodeName(pathname), mode ); + if ( accessOK == 0 ) + return true; // OK, I can really access the file + + // else + // if we want to write the file would be created. Check, if the + // user may write to the directory to create the file. + if ( (mode & W_OK) == 0 ) + return false; // Check for write access is not part of mode => bail out + + + if (!access( TQFile::encodeName(pathname), F_OK)) // if it already exists + return false; + + //strip the filename (everything until '/' from the end + TQString dirName(pathname); + int pos = dirName.findRev('/'); + if ( pos == -1 ) + return false; // No path in argument. This is evil, we won't allow this + else if ( pos == 0 ) // don't turn e.g. /root into an empty string + pos = 1; + + dirName.truncate(pos); // strip everything starting from the last '/' + + accessOK = access( TQFile::encodeName(dirName), W_OK ); + // -?- Can I write to the accessed diretory + if ( accessOK == 0 ) + return true; // Yes + else + return false; // No +} + +void TDEApplication::setTopWidget( TQWidget *topWidget ) +{ + if( !topWidget ) + return; + + // set the specified caption + if ( !topWidget->inherits("TDEMainWindow") ) { // TDEMainWindow does this already for us + topWidget->setCaption( caption() ); + } + + // set the specified icons + topWidget->setIcon( icon() ); //standard X11 +#if defined Q_WS_X11 +//#ifdef Q_WS_X11 // FIXME(E): Implement for Qt/Embedded + KWin::setIcons(topWidget->winId(), icon(), miniIcon() ); // NET_WM hints for KWin + + // set the app startup notification window property + TDEStartupInfo::setWindowStartupId( topWidget->winId(), startupId()); +#endif +} + +TQCString TDEApplication::startupId() const +{ + return d->startup_id; +} + +void TDEApplication::setStartupId( const TQCString& startup_id ) +{ + if( startup_id == d->startup_id ) + return; +#if defined Q_WS_X11 + TDEStartupInfo::handleAutoAppStartedSending(); // finish old startup notification if needed +#endif + if( startup_id.isEmpty()) + d->startup_id = "0"; + else + { + d->startup_id = startup_id; +#if defined Q_WS_X11 + TDEStartupInfoId id; + id.initId( startup_id ); + long timestamp = id.timestamp(); + if( timestamp != 0 ) + updateUserTimestamp( timestamp ); +#endif + } +} + +// read the startup notification env variable, save it and unset it in order +// not to propagate it to processes started from this app +void TDEApplication::read_app_startup_id() +{ +#if defined Q_WS_X11 + TDEStartupInfoId id = TDEStartupInfo::currentStartupIdEnv(); + TDEStartupInfo::resetStartupEnv(); + d->startup_id = id.id(); +#endif +} + +int TDEApplication::random() +{ + static bool init = false; + if (!init) + { + unsigned int seed; + init = true; + int fd = open("/dev/urandom", O_RDONLY); + if (fd < 0 || ::read(fd, &seed, sizeof(seed)) != sizeof(seed)) + { + // No /dev/urandom... try something else. + srand(getpid()); + seed = rand()+time(0); + } + if (fd >= 0) close(fd); + srand(seed); + } + return rand(); +} + +TQString TDEApplication::randomString(int length) +{ + if (length <=0 ) return TQString::null; + + TQString str; str.setLength( length ); + int i = 0; + while (length--) + { + int r=random() % 62; + r+=48; + if (r>57) r+=7; + if (r>90) r+=6; + str[i++] = char(r); + // so what if I work backwards? + } + return str; +} + +bool TDEApplication::authorize(const TQString &genericAction) +{ + if (!d->actionRestrictions) + return true; + + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "KDE Action Restrictions" ); + return config->readBoolEntry(genericAction, true); +} + +bool TDEApplication::authorizeTDEAction(const char *action) +{ + if (!d->actionRestrictions || !action) + return true; + + static const TQString &action_prefix = TDEGlobal::staticQString( "action/" ); + + return authorize(action_prefix + action); +} + +bool TDEApplication::authorizeControlModule(const TQString &menuId) +{ + if (menuId.isEmpty() || kde_kiosk_exception) + return true; + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "TDE Control Module Restrictions" ); + return config->readBoolEntry(menuId, true); +} + +TQStringList TDEApplication::authorizeControlModules(const TQStringList &menuIds) +{ + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "TDE Control Module Restrictions" ); + TQStringList result; + for(TQStringList::ConstIterator it = menuIds.begin(); + it != menuIds.end(); ++it) + { + if (config->readBoolEntry(*it, true)) + result.append(*it); + } + return result; +} + +void TDEApplication::initUrlActionRestrictions() +{ + d->urlActionRestrictions.setAutoDelete(true); + d->urlActionRestrictions.clear(); + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("open", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true)); + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true)); +// TEST: +// d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule +// ("list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, false)); +// d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule +// ("list", TQString::null, TQString::null, TQString::null, "file", TQString::null, TQDir::homeDirPath(), true)); + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("link", TQString::null, TQString::null, TQString::null, ":internet", TQString::null, TQString::null, true)); + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("redirect", TQString::null, TQString::null, TQString::null, ":internet", TQString::null, TQString::null, true)); + + // We allow redirections to file: but not from internet protocols, redirecting to file: + // is very popular among io-slaves and we don't want to break them + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("redirect", TQString::null, TQString::null, TQString::null, "file", TQString::null, TQString::null, true)); + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("redirect", ":internet", TQString::null, TQString::null, "file", TQString::null, TQString::null, false)); + + // local protocols may redirect everywhere + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("redirect", ":local", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true)); + + // Anyone may redirect to about: + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("redirect", TQString::null, TQString::null, TQString::null, "about", TQString::null, TQString::null, true)); + + // Anyone may redirect to itself, cq. within it's own group + d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule + ("redirect", TQString::null, TQString::null, TQString::null, "=", TQString::null, TQString::null, true)); + + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "KDE URL Restrictions" ); + int count = config->readNumEntry("rule_count"); + TQString keyFormat = TQString("rule_%1"); + for(int i = 1; i <= count; i++) + { + TQString key = keyFormat.arg(i); + TQStringList rule = config->readListEntry(key); + if (rule.count() != 8) + continue; + TQString action = rule[0]; + TQString refProt = rule[1]; + TQString refHost = rule[2]; + TQString refPath = rule[3]; + TQString urlProt = rule[4]; + TQString urlHost = rule[5]; + TQString urlPath = rule[6]; + TQString strEnabled = rule[7].lower(); + + bool bEnabled = (strEnabled == "true"); + + if (refPath.startsWith("$HOME")) + refPath.replace(0, 5, TQDir::homeDirPath()); + else if (refPath.startsWith("~")) + refPath.replace(0, 1, TQDir::homeDirPath()); + if (urlPath.startsWith("$HOME")) + urlPath.replace(0, 5, TQDir::homeDirPath()); + else if (urlPath.startsWith("~")) + urlPath.replace(0, 1, TQDir::homeDirPath()); + + if (refPath.startsWith("$TMP")) + refPath.replace(0, 4, TDEGlobal::dirs()->saveLocation("tmp")); + if (urlPath.startsWith("$TMP")) + urlPath.replace(0, 4, TDEGlobal::dirs()->saveLocation("tmp")); + + d->urlActionRestrictions.append(new TDEApplicationPrivate::URLActionRule + ( action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled)); + } +} + +void TDEApplication::allowURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL) +{ + if (authorizeURLAction(action, _baseURL, _destURL)) + return; + + d->urlActionRestrictions.append(new TDEApplicationPrivate::URLActionRule + ( action, _baseURL.protocol(), _baseURL.host(), _baseURL.path(-1), + _destURL.protocol(), _destURL.host(), _destURL.path(-1), true)); +} + +bool TDEApplication::authorizeURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL) +{ + if (_destURL.isEmpty()) + return true; + + bool result = false; + if (d->urlActionRestrictions.isEmpty()) + initUrlActionRestrictions(); + + KURL baseURL(_baseURL); + baseURL.setPath(TQDir::cleanDirPath(baseURL.path())); + TQString baseClass = KProtocolInfo::protocolClass(baseURL.protocol()); + KURL destURL(_destURL); + destURL.setPath(TQDir::cleanDirPath(destURL.path())); + TQString destClass = KProtocolInfo::protocolClass(destURL.protocol()); + + for(TDEApplicationPrivate::URLActionRule *rule = d->urlActionRestrictions.first(); + rule; rule = d->urlActionRestrictions.next()) + { + if ((result != rule->permission) && // No need to check if it doesn't make a difference + (action == rule->action) && + rule->baseMatch(baseURL, baseClass) && + rule->destMatch(destURL, destClass, baseURL, baseClass)) + { + result = rule->permission; + } + } + return result; +} + + +uint TDEApplication::keyboardModifiers() +{ +#ifdef Q_WS_X11 + Window root; + Window child; + int root_x, root_y, win_x, win_y; + uint keybstate; + XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child, + &root_x, &root_y, &win_x, &win_y, &keybstate ); + return keybstate & 0x00ff; +#elif defined W_WS_MACX + return GetCurrentEventKeyModifiers() & 0x00ff; +#else + //TODO for win32 + return 0; +#endif +} + +uint TDEApplication::mouseState() +{ + uint mousestate; +#ifdef Q_WS_X11 + Window root; + Window child; + int root_x, root_y, win_x, win_y; + XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child, + &root_x, &root_y, &win_x, &win_y, &mousestate ); +#elif defined(Q_WS_WIN) + const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON); + if (GetAsyncKeyState(VK_LBUTTON)) + mousestate |= (mousebtn_swapped ? Button3Mask : Button1Mask); + if (GetAsyncKeyState(VK_MBUTTON)) + mousestate |= Button2Mask; + if (GetAsyncKeyState(VK_RBUTTON)) + mousestate |= (mousebtn_swapped ? Button1Mask : Button3Mask); +#elif defined(Q_WS_MACX) + mousestate = GetCurrentEventButtonState(); +#else + //TODO: other platforms +#endif + return mousestate & 0xff00; +} + +TQ_ButtonState TDEApplication::keyboardMouseState() +{ + int ret = 0; +#ifdef Q_WS_X11 + Window root; + Window child; + int root_x, root_y, win_x, win_y; + uint state; + XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child, + &root_x, &root_y, &win_x, &win_y, &state ); + // transform the same way like Qt's qt_x11_translateButtonState() + if( state & Button1Mask ) + ret |= TQ_LeftButton; + if( state & Button2Mask ) + ret |= TQ_MidButton; + if( state & Button3Mask ) + ret |= TQ_RightButton; + if( state & ShiftMask ) + ret |= TQ_ShiftButton; + if( state & ControlMask ) + ret |= TQ_ControlButton; + if( state & KKeyNative::modX( KKey::ALT )) + ret |= TQ_AltButton; + if( state & KKeyNative::modX( KKey::WIN )) + ret |= TQ_MetaButton; +#elif defined(Q_WS_WIN) + const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON); + if (GetAsyncKeyState(VK_LBUTTON)) + ret |= (mousebtn_swapped ? RightButton : LeftButton); + if (GetAsyncKeyState(VK_MBUTTON)) + ret |= TQ_MidButton; + if (GetAsyncKeyState(VK_RBUTTON)) + ret |= (mousebtn_swapped ? TQ_LeftButton : TQ_RightButton); + if (GetAsyncKeyState(VK_SHIFT)) + ret |= TQ_ShiftButton; + if (GetAsyncKeyState(VK_CONTROL)) + ret |= TQ_ControlButton; + if (GetAsyncKeyState(VK_MENU)) + ret |= TQ_AltButton; + if (GetAsyncKeyState(VK_LWIN) || GetAsyncKeyState(VK_RWIN)) + ret |= TQ_MetaButton; +#else + //TODO: other platforms +#endif + return static_cast< ButtonState >( ret ); +} + +void TDEApplication::installSigpipeHandler() +{ +#ifdef Q_OS_UNIX + struct sigaction act; + act.sa_handler = SIG_IGN; + sigemptyset( &act.sa_mask ); + act.sa_flags = 0; + sigaction( SIGPIPE, &act, 0 ); +#endif +} + +void TDEApplication::sigpipeHandler(int) +{ + int saved_errno = errno; + // Using kdDebug from a signal handler is not a good idea. +#ifndef NDEBUG + char msg[1000]; + sprintf(msg, "*** SIGPIPE *** (ignored, pid = %ld)\n", (long) getpid()); + if (write(2, msg, strlen(msg)) < 0) { + // ERROR + } +#endif + + // Do nothing. + errno = saved_errno; +} + +bool TDEApplication::guiEnabled() +{ + return kapp && kapp->d->guiEnabled; +} + +void TDEApplication::virtual_hook( int id, void* data ) +{ TDEInstance::virtual_hook( id, data ); } + +void KSessionManaged::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "tdeapplication.moc" diff --git a/tdecore/tdeapplication.h b/tdecore/tdeapplication.h new file mode 100644 index 000000000..5ab8d7ee7 --- /dev/null +++ b/tdecore/tdeapplication.h @@ -0,0 +1,1620 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) + Copyright (c) 1998, 1999 KDE Team + + 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. +*/ + +#ifndef _KAPP_H +#define _KAPP_H + +// Version macros. Never put this further down. +#include "tdeversion.h" +#include "tdelibs_export.h" + +class TDEConfig; +class KCharsets; +class DCOPClient; +class DCOPObject; + +#include <tqtglobaldefines.h> + +typedef unsigned long Atom; +#if !defined(Q_WS_X11) +typedef void Display; +#endif + +#include <tqapplication.h> +#include <tqpixmap.h> +#include <kinstance.h> + +struct _IceConn; +class TQPopupMenu; +class TQStrList; +class KSessionManaged; +class TDEStyle; +class KURL; + +#define kapp TDEApplication::kApplication() + +class TDEApplicationPrivate; + +/** +* Controls and provides information to all KDE applications. +* +* Only one object of this class can be instantiated in a single app. +* This instance is always accessible via the 'kapp' global variable. +* See cut() for an example. +* +* This class provides the following services to all KDE applications. +* +* @li It controls the event queue (see TQApplication ). +* @li It provides the application with KDE resources such as +* accelerators, common menu entries, a TDEConfig object. session +* management events, help invocation etc. +* @li Installs a signal handler for the SIGCHLD signal in order to +* avoid zombie children. If you want to catch this signal yourself or +* don't want it to be caught at all, you have set a new signal handler +* (or SIG_IGN) after TDEApplication's constructor has run. +* @li Installs an empty signal handler for the SIGPIPE signal using +* installSigpipeHandler(). If you want to catch this signal +* yourself, you have set a new signal handler after TDEApplication's +* constructor has run. +* @li It can start new services +* +* +* The way a service gets started depends on the 'X-DCOP-ServiceType' +* entry in the desktop file of the service: +* +* There are three possibilities: +* @li X-DCOP-ServiceType=None (default) +* Always start a new service, +* don't wait till the service registers with dcop. +* @li X-DCOP-ServiceType=Multi +* Always start a new service, +* wait until the service has registered with dcop. +* @li X-DCOP-ServiceType=Unique +* Only start the service if it isn't already running, +* wait until the service has registered with dcop. +* +* @short Controls and provides information to all KDE applications. +* @author Matthias Kalle Dalheimer <kalle@kde.org> +*/ +class TDECORE_EXPORT TDEApplication : public TQApplication, public TDEInstance +{ + + Q_OBJECT +public: + /** Position of the caption (presumably in the application window's + * title bar). This enum appears to be unused. + * + * @todo Find out if this is used anywhere. + */ + enum CaptionLayout { + CaptionAppLast=1 /**< Display the application name last (before document name). */, + CaptionAppFirst /**< Display the application name first. */ , + CaptionNoApp /**< Do not display application name at all. */ + }; + + /** + * This constructor takes aboutData and command line + * arguments from TDECmdLineArgs. + * + * If ARGB (transparent) widgets are to be used in your application, + * please use + * TDEApplication app(TDEApplication::openX11RGBADisplay()); + * or + * TDEApplication app(TDEApplication::openX11RGBADisplay(), useStyles); + * + * @param allowStyles Set to false to disable the loading on plugin based + * styles. This is only useful to applications that do not display a GUI + * normally. If you do create an application with @p allowStyles set to false + * it normally runs in the background but under special circumstances + * displays widgets. Call enableStyles() before displaying any widgets. + * + * @param GUIenabled Set to false to disable all GUI stuff. This implies + * no styles either. + */ + TDEApplication( bool allowStyles=true, bool GUIenabled=true); + +#ifdef Q_WS_X11 + /** + * Constructor. Parses command-line arguments. Use this constructor when you + * you want ARGB support to be automatically detected and enabled. + * + * @param display Will be passed to Qt as the X display. The display must be + * valid and already opened. + * + * @param allowStyles Set to false to disable the loading on plugin based + * styles. This is only useful to applications that do not display a GUI + * normally. If you do create an application with @p allowStyles set to false + * that normally runs in the background but under special circumstances + * displays widgets call enableStyles() before displaying any widgets. + * + * @since KDE 3.5 + * + * @see RGBADisplay() + */ + TDEApplication(Display *display, bool allowStyles); + + /** + * Constructor. Parses command-line arguments. Use this constructor when you + * you want ARGB support to be automatically detected and enabled. + * + * @param display Will be passed to Qt as the X display. The display must be + * valid and already opened. + * + * @param disable_argb Set to true to disable ARGB visuals in this application. + * + * @param display Will be passed to Qt as the X display. The display must be + * valid and already opened. + * + * @param visual A pointer to the X11 visual that should be used by the + * appliction. Note that only TrueColor visuals are supported on depths + * greater than 8 bpp. If this parameter is NULL, the default visual will + * be used instead. + * + * @param allowStyles Set to false to disable the loading on plugin based + * styles. This is only useful to applications that do not display a GUI + * normally. If you do create an application with @p allowStyles set to false + * that normally runs in the background but under special circumstances + * displays widgets call enableStyles() before displaying any widgets. + * + * @since KDE 3.5 + * + * @see RGBADisplay() + */ + TDEApplication(Display *display, bool disable_argb, Qt::HANDLE visual, Qt::HANDLE colormap, bool allowStyles); + + /** + * Constructor. Parses command-line arguments. Use this constructor when you + * you need to use a non-default visual or colormap. + * + * @param display Will be passed to Qt as the X display. The display must be + * valid and already opened. + * + * @param visual A pointer to the X11 visual that should be used by the + * appliction. Note that only TrueColor visuals are supported on depths + * greater than 8 bpp. If this parameter is NULL, the default visual will + * be used instead. + * + * @param colormap The colormap that should be used by the application. If + * this parameter is 0, the default colormap will be used instead. + * + * @param allowStyles Set to false to disable the loading on plugin based + * styles. This is only useful to applications that do not display a GUI + * normally. If you do create an application with @p allowStyles set to false + * that normally runs in the background but under special circumstances + * displays widgets call enableStyles() before displaying any widgets. + * + * @since KDE 3.3 + */ + TDEApplication(Display *display, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0, + bool allowStyles=true); + + /** + * Constructor. Parses command-line arguments. Use this constructor to use TDEApplication + * in a Motif or Xt program. + * + * @param display Will be passed to Qt as the X display. The display must be valid and already + * opened. + * + * @param argc command line argument count + * + * @param argv command line argument value(s) + * + * @param rAppName application name. Will be used for finding the + * associated message files and icon files, and as the default + * registration name for DCOP. This is a mandatory parameter. + * + * @param allowStyles Set to false to disable the loading on plugin based + * styles. This is only useful to applications that do not display a GUI + * normally. If you do create an application with @p allowStyles set to false + * that normally runs in the background but under special circumstances + * displays widgets call enableStyles() before displaying any widgets. + * + * @param GUIenabled Set to false to disable all GUI stuff. This implies + * no styles either. + */ + TDEApplication(Display *display, int& argc, char** argv, const TQCString& rAppName, + bool allowStyles=true, bool GUIenabled=true); +#endif + + /** + * @deprecated do not use it at all, it will make your application crash, use TDECmdLineArgs + * + * Constructor. Parses command-line arguments. + * + * @param argc command line argument count + * + * @param argv command line argument value(s) + * + * @param rAppName application name. Will be used for finding the + * associated message files and icon files, and as the default + * registration name for DCOP. This is a mandatory parameter. + * + * @param allowStyles Set to false to disable the loading on plugin based + * styles. This is only useful to applications that do not display a GUI + * normally. If you do create an application with @p allowStyles set to false + * that normally runs in the background but under special circumstances + * displays widgets call enableStyles() before displaying any widgets. + * + * @param GUIenabled Set to false to disable all GUI stuff. This implies + * no styles either. + */ + // REMOVE FOR KDE 4.0 - using it only gives crashing applications because + // TDECmdLineArgs::init isn't called + TDEApplication(int& argc, char** argv, + const TQCString& rAppName, bool allowStyles=true, bool GUIenabled=true) KDE_DEPRECATED; + + /** + * Add Qt and KDE command line options to TDECmdLineArgs. + */ + static void addCmdLineOptions(); + + virtual ~TDEApplication(); + + /** + * Returns the current application object. + * + * This is similar to the global TQApplication pointer tqApp. It + * allows access to the single global TDEApplication object, since + * more than one cannot be created in the same application. It + * saves you the trouble of having to pass the pointer explicitly + * to every function that may require it. + * @return the current application object + */ + static TDEApplication* kApplication() { return KApp; } + + /** + * Returns the application session config object. + * + * @return A pointer to the application's instance specific + * TDEConfig object. + * @see TDEConfig + */ + TDEConfig* sessionConfig(); + + /** + * Is the application restored from the session manager? + * + * @return If true, this application was restored by the session manager. + * Note that this may mean the config object returned by + * sessionConfig() contains data saved by a session closedown. + * @see sessionConfig() + */ + bool isRestored() const { return TQApplication::isSessionRestored(); } + + /** + * Disables session management for this application. + * + * Useful in case your application is started by the + * initial "starttde" script. + */ + void disableSessionManagement(); + + /** + * Enables again session management for this application, formerly + * disabled by calling disableSessionManagement(). You usually + * shouldn't call this function, as the session management is enabled + * by default. + */ + void enableSessionManagement(); + + /** + * The possible values for the @p confirm parameter of requestShutDown(). + */ + enum ShutdownConfirm { + /** + * Obey the user's confirmation setting. + */ + ShutdownConfirmDefault = -1, + /** + * Don't confirm, shutdown without asking. + */ + ShutdownConfirmNo = 0, + /** + * Always confirm, ask even if the user turned it off. + */ + ShutdownConfirmYes = 1 + }; + + /** + * The possible values for the @p sdtype parameter of requestShutDown(). + */ + enum ShutdownType { + /** + * Select previous action or the default if it's the first time. + */ + ShutdownTypeDefault = -1, + /** + * Only log out. + */ + ShutdownTypeNone = 0, + /** + * Log out and reboot the machine. + */ + ShutdownTypeReboot = 1, + /** + * Log out and halt the machine. + */ + ShutdownTypeHalt = 2 + }; + + /** + * The possible values for the @p sdmode parameter of requestShutDown(). + */ + enum ShutdownMode { + /** + * Select previous mode or the default if it's the first time. + */ + ShutdownModeDefault = -1, + /** + * Schedule a shutdown (halt or reboot) for the time all active sessions + * have exited. + */ + ShutdownModeSchedule = 0, + /** + * Shut down, if no sessions are active. Otherwise do nothing. + */ + ShutdownModeTryNow = 1, + /** + * Force shutdown. Kill any possibly active sessions. + */ + ShutdownModeForceNow = 2, + /** + * Pop up a dialog asking the user what to do if sessions are still active. + */ + ShutdownModeInteractive = 3 + }; + + /** + * Asks the session manager to shut the session down. + * + * Using @p confirm == ShutdownConfirmYes or @p sdtype != ShutdownTypeDefault or + * @p sdmode != ShutdownModeDefault causes the use of ksmserver's DCOP + * interface. The remaining two combinations use the standard XSMP and + * will work with any session manager compliant with it. + * + * @param confirm Whether to ask the user if he really wants to log out. + * ShutdownConfirm + * @param sdtype The action to take after logging out. ShutdownType + * @param sdmode If/When the action should be taken. ShutdownMode + * @return true on success, false if the session manager could not be + * contacted. + */ + bool requestShutDown( ShutdownConfirm confirm = ShutdownConfirmDefault, + ShutdownType sdtype = ShutdownTypeDefault, + ShutdownMode sdmode = ShutdownModeDefault ); + + /** + * Propagates the network address of the session manager in the + * SESSION_MANAGER environment variable so that child processes can + * pick it up. + * + * If SESSION_MANAGER isn't defined yet, the address is searched in + * $HOME/.KSMserver. + * + * This function is called by clients that are started outside the + * session ( i.e. before ksmserver is started), but want to launch + * other processes that should participate in the session. Examples + * are kdesktop or kicker. + */ + void propagateSessionManager(); + + /** + * Reimplemented for internal purposes, mainly the highlevel + * handling of session management with KSessionManaged. + * @internal + */ + void commitData( TQSessionManager& sm ); + + /** + * Reimplemented for internal purposes, mainly the highlevel + * handling of session management with KSessionManaged. + * @internal + */ + void saveState( TQSessionManager& sm ); + + /** + * Returns true if the application is currently saving its session + * data (most probably before KDE logout). This is intended for use + * mainly in TDEMainWindow::queryClose() and TDEMainWindow::queryExit(). + * + * @see TDEMainWindow::queryClose + * @see TDEMainWindow::queryExit + * @since 3.1.1 + */ + bool sessionSaving() const; + + /** + * Returns a pointer to a DCOPClient for the application. + * If a client does not exist yet, it is created when this + * function is called. + * @return the DCOPClient for the application + */ + static DCOPClient *dcopClient(); + + /** + * Disable automatic dcop registration + * Must be called before creating a TDEApplication instance to have an effect. + */ + static void disableAutoDcopRegistration(); + + /** + * Returns a TQPixmap with the application icon. + * @return the application icon + */ + TQPixmap icon() const; + + /** + * Returns the name of the application icon. + * @return the icon's name + */ + TQString iconName() const; + + /** + * Returns the mini-icon for the application as a TQPixmap. + * @return the application's mini icon + */ + TQPixmap miniIcon() const; + + /** + * Returns the name of the mini-icon for the application. + * @return the mini icon's name + */ + TQString miniIconName() const; + + /** + * Sets the top widget of the application. + * This means basically applying the right window caption and + * icon. An application may have several top widgets. You don't + * need to call this function manually when using TDEMainWindow. + * + * @param topWidget A top widget of the application. + * + * @see icon(), caption() + **/ + void setTopWidget( TQWidget *topWidget ); + + /** + * Invokes the KHelpCenter HTML help viewer from docbook sources. + * + * @param anchor This has to be a defined anchor in your + * docbook sources. If empty the main index + * is loaded + * @param appname This allows you to show the help of another + * application. If empty the current name() is + * used + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + */ + void invokeHelp( const TQString& anchor, + const TQString& appname, + const TQCString& startup_id ) const; + + // KDE4 merge with above with startup_id = "" + void invokeHelp( const TQString& anchor = TQString::null, + const TQString& appname = TQString::null ) const; + + /** + * @deprecated + * Invoke the khelpcenter HTML help viewer from HTML sources. + * Please use invokeHelp() instead. + * + * @param aFilename The filename that is to be loaded. Its + * location is computed automatically + * according to the KFSSTND. If @p aFilename + * is empty, the logical appname with .html + * appended to it is used. + * @param aTopic This allows context-sensitive help. Its + * value will be appended to the filename, + * prefixed with a "#" (hash) character. + */ + void invokeHTMLHelp( const TQString& aFilename, const TQString& aTopic = TQString::null ) const KDE_DEPRECATED; + + /** + * Convenience method; invokes the standard email application. + * + * @param address The destination address + * @param subject Subject string. Can be TQString::null. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + */ + void invokeMailer( const TQString &address, const TQString &subject, const TQCString& startup_id ); + // KDE4 merge with above with startup_id = "" + void invokeMailer( const TQString &address, const TQString &subject ); + + /** + * Invokes the standard email application. + * + * @param mailtoURL A mailto URL. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @param allowAttachments whether attachments specified in mailtoURL should be honoured. + The default is false; do not honour requests for attachments. + */ + void invokeMailer( const KURL &mailtoURL, const TQCString& startup_id, bool allowAttachments ); + // KDE4 merge with above with allowAttachments = false + void invokeMailer( const KURL &mailtoURL, const TQCString& startup_id ); + // KDE4 merge with above with startup_id = "" + void invokeMailer( const KURL &mailtoURL ); + + /** + * Convenience method; invokes the standard email application. + * + * All parameters are optional. + * + * @param to The destination address. + * @param cc The Cc field + * @param bcc The Bcc field + * @param subject Subject string + * @param body A string containing the body of the mail (exclusive with messageFile) + * @param messageFile A file (URL) containing the body of the mail (exclusive with body) - currently unsupported + * @param attachURLs List of URLs to be attached to the mail. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + */ + void invokeMailer(const TQString &to, const TQString &cc, const TQString &bcc, + const TQString &subject, const TQString &body, + const TQString &messageFile, const TQStringList &attachURLs, + const TQCString& startup_id ); + // KDE4 merge with above with startup_id = "" + void invokeMailer(const TQString &to, const TQString &cc, const TQString &bcc, + const TQString &subject, const TQString &body, + const TQString &messageFile = TQString::null, const TQStringList &attachURLs = TQStringList()); + +public slots: + /** + * Invokes the standard browser. + * Note that you should only do this when you know for sure that the browser can + * handle the URL (i.e. its mimetype). In doubt, if the URL can point to an image + * or anything else than directory or HTML, prefer to use new KRun( url ). + * + * @param url The destination address + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + */ + void invokeBrowser( const TQString &url, const TQCString& startup_id ); + // KDE4 merge with above with startup_id = "" + /** + * Invoke the standard browser. Uses a @p startup_id of "" (empty) + * and is otherwise the same as the above function. + */ + void invokeBrowser( const TQString &url ); + + /** + * If the widget with focus provides a cut() slot, call that slot. Thus for a + * simple application cut can be implemented as: + * \code + * KStdAction::cut( kapp, TQT_SLOT( cut() ), actionCollection() ); + * \endcode + */ + void cut(); + + /** + * If the widget with focus provides a copy() slot, call that slot. Thus for a + * simple application copy can be implemented as: + * \code + * KStdAction::copy( kapp, TQT_SLOT( copy() ), actionCollection() ); + * \endcode + */ + void copy(); + + /** + * If the widget with focus provides a paste() slot, call that slot. Thus for a + * simple application copy can be implemented as: + * \code + * KStdAction::paste( kapp, TQT_SLOT( paste() ), actionCollection() ); + * \endcode + */ + void paste(); + + /** + * If the widget with focus provides a clear() slot, call that slot. Thus for a + * simple application clear() can be implemented as: + * \code + * new TDEAction( i18n( "Clear" ), "editclear", 0, kapp, TQT_SLOT( clear() ), actionCollection(), "clear" ); + * \endcode + * + * Note that for some widgets, this may not provide the intended bahavior. For + * example if you make use of the code above and a TDEListView has the focus, clear() + * will clear all of the items in the list. If this is not the intened behavior + * and you want to make use of this slot, you can subclass TDEListView and reimplement + * this slot. For example the following code would implement a TDEListView without this + * behavior: + * + * \code + * class MyListView : public TDEListView { + * Q_OBJECT + * public: + * MyListView( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 ) : TDEListView( parent, name, f ) {} + * virtual ~MyListView() {} + * public slots: + * virtual void clear() {} + * }; + * \endcode + */ + void clear(); + + /** + * If the widget with focus provides a selectAll() slot, call that slot. Thus for a + * simple application select all can be implemented as: + * \code + * KStdAction::selectAll( kapp, TQT_SLOT( selectAll() ), actionCollection() ); + * \endcode + */ + void selectAll(); + + /** + * Broadcast a received keycode to all listening KDE applications + * The primary use for this feature is to connect hotkeys such as + * XF86Display to their respective TDEGlobalAccel functions while + * the screen is locked by kdesktop_lock. + */ + void broadcastKeyCode(unsigned int keyCode); + +public: + /** + * Returns the DCOP name of the service launcher. This will be something like + * klaucher_$host_$uid. + * @return the name of the service launcher + */ + static TQCString launcher(); + + /** + * Starts a service based on the (translated) name of the service. + * E.g. "Web Browser" + * + * @param _name the name of the service + * @param URL if not empty this URL is passed to the service + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param dcopService On success, @p dcopService contains the DCOP name + * under which this service is available. If empty, the service does + * not provide DCOP services. If the pointer is 0 the argument + * will be ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @param noWait if set, the function does not wait till the service is running. + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int startServiceByName( const TQString& _name, const TQString &URL, + TQString *error=0, TQCString *dcopService=0, int *pid=0, const TQCString &startup_id = "", bool noWait = false ); + + /** + * Starts a service based on the (translated) name of the service. + * E.g. "Web Browser" + * + * @param _name the name of the service + * @param URLs if not empty these URLs will be passed to the service + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param dcopService On success, @p dcopService contains the DCOP name + * under which this service is available. If empty, the service does + * not provide DCOP services. If the pointer is 0 the argument + * will be ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @param noWait if set, the function does not wait till the service is running. + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int startServiceByName( const TQString& _name, const TQStringList &URLs=TQStringList(), + TQString *error=0, TQCString *dcopService=0, int *pid=0, const TQCString &startup_id = "", bool noWait = false ); + + /** + * Starts a service based on the desktop path of the service. + * E.g. "Applications/konqueror.desktop" or "/home/user/bla/myfile.desktop" + * + * @param _name the path of the desktop file + * @param URL if not empty this URL is passed to the service + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param dcopService On success, @p dcopService contains the DCOP name + * under which this service is available. If empty, the service does + * not provide DCOP services. If the pointer is 0 the argument + * will be ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @param noWait if set, the function does not wait till the service is running. + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int startServiceByDesktopPath( const TQString& _name, const TQString &URL, + TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); + + /** + * Starts a service based on the desktop path of the service. + * E.g. "Applications/konqueror.desktop" or "/home/user/bla/myfile.desktop" + * + * @param _name the path of the desktop file + * @param URLs if not empty these URLs will be passed to the service + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param dcopService On success, @p dcopService contains the DCOP name + * under which this service is available. If empty, the service does + * not provide DCOP services. If the pointer is 0 the argument + * will be ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @param noWait if set, the function does not wait till the service is running. + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int startServiceByDesktopPath( const TQString& _name, const TQStringList &URLs=TQStringList(), + TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); + + /** + * Starts a service based on the desktop name of the service. + * E.g. "konqueror" + * + * @param _name the desktop name of the service + * @param URL if not empty this URL is passed to the service + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param dcopService On success, @p dcopService contains the DCOP name + * under which this service is available. If empty, the service does + * not provide DCOP services. If the pointer is 0 the argument + * will be ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @param noWait if set, the function does not wait till the service is running. + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int startServiceByDesktopName( const TQString& _name, const TQString &URL, + TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); + + /** + * Starts a service based on the desktop name of the service. + * E.g. "konqueror" + * + * @param _name the desktop name of the service + * @param URLs if not empty these URLs will be passed to the service + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param dcopService On success, @p dcopService contains the DCOP name + * under which this service is available. If empty, the service does + * not provide DCOP services. If the pointer is 0 the argument + * will be ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @param noWait if set, the function does not wait till the service is running. + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int startServiceByDesktopName( const TQString& _name, const TQStringList &URLs=TQStringList(), + TQString *error=0, TQCString *dcopService=0, int *pid = 0, const TQCString &startup_id = "", bool noWait = false ); + + /** + * Starts a program via tdeinit. + * + * program name and arguments are converted to according to the + * local encoding and passed as is to tdeinit. + * + * @param name Name of the program to start + * @param args Arguments to pass to the program + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int tdeinitExec( const TQString& name, const TQStringList &args, + TQString *error, int *pid, const TQCString& startup_id ); + // KDE4 merge with above with startup_id = "" + static int tdeinitExec( const TQString& name, const TQStringList &args=TQStringList(), + TQString *error=0, int *pid = 0 ); + + /** + * Starts a program via tdeinit and wait for it to finish. + * + * Like tdeinitExec(), but it waits till the program is finished. + * As such it behaves similar to the system(...) function. + * + * @param name Name of the program to start + * @param args Arguments to pass to the program + * @param error On failure, @p error contains a description of the error + * that occurred. If the pointer is 0, the argument will be + * ignored + * @param pid On success, the process id of the new service will be written + * here. If the pointer is 0, the argument will be ignored. + * @param startup_id for app startup notification, "0" for none, + * "" ( empty string ) is the default + * @return an error code indicating success (== 0) or failure (> 0). + */ + static int tdeinitExecWait( const TQString& name, const TQStringList &args, + TQString *error, int *pid, const TQCString& startup_id ); + // KDE4 merge with above with startup_id = "" + static int tdeinitExecWait( const TQString& name, const TQStringList &args=TQStringList(), + TQString *error=0, int *pid = 0 ); + + /** + * Returns a text for the window caption. + * + * This may be set by + * "-caption", otherwise it will be equivalent to the name of the + * executable. + * @return the text for the window caption + */ + TQString caption() const; + + /** + * @deprecated + */ + KDE_DEPRECATED TDEStyle* kstyle() const { return 0; } + + /** + * Builds a caption that contains the application name along with the + * userCaption using a standard layout. + * + * To make a compliant caption + * for your window, simply do: @p setCaption(kapp->makeStdCaption(yourCaption)); + * + * @param userCaption The caption string you want to display in the + * window caption area. Do not include the application name! + * @param withAppName Indicates that the method shall include or ignore + * the application name when making the caption string. You are not + * compliant if you set this to @p false. + * @param modified If true, a 'modified' sign will be included in the + * returned string. This is useful when indicating that a file is + * modified, i.e., it contains data that has not been saved. + * @return the created caption + */ + TQString makeStdCaption( const TQString &userCaption, + bool withAppName=true, bool modified=false ) const; + + /** + * Get a file name in order to make a temporary copy of your document. + * + * @param pFilename The full path to the current file of your + * document. + * @return A new filename for auto-saving. + */ + TQString tempSaveName( const TQString& pFilename ) const; + + /** + * Check whether an auto-save file exists for the document you want to + * open. + * + * @param pFilename The full path to the document you want to open. + * @param bRecover This gets set to true if there was a recover + * file. + * @return The full path of the file to open. + */ + TQString checkRecoverFile( const TQString& pFilename, bool& bRecover ) const; + +#if defined(Q_WS_X11) + /** + * @internal + * Get the X11 display + * @return the X11 Display + */ + Display *getDisplay() { return display; } +#endif + + /** + * @internal + * Gets X11 composition information + */ + void getX11RGBAInformation(Display *dpy); + + /** + * Gets the availability of a composition manager such as kompmgr + * Note that at least one application must have called detectCompositionManagerAvailable + * while the current X display was active in order for this method to return valid results. + * @see detectCompositionManagerAvailable() + * @return whether the composition manager is enabled + */ + static bool isCompositionManagerAvailable(); + + /** + * Detects the availability of a composition manager such as kompmgr + * Note that calling this method will probably cause the screen to flicker. + * @see isCompositionManagerAvailable() + * @param force_available If set, force TDE to assume a composition manager is available + * @param available Whether or not the composition manager is available (only used if force_available is TRUE) + * @return whether the composition manager is enabled + */ + bool detectCompositionManagerAvailable(bool force_available=false, bool available=true); + + /** + * @internal + * Opens the display + * This can be used to initialize a TDEApplication with RGBA support like this: + * TDEApplication app(TDEApplication::openX11RGBADisplay()); + * or + * TDEApplication app(TDEApplication::openX11RGBADisplay(), useStyles); + */ + static Display* openX11RGBADisplay(); + + /** + * Returns the X11 display visual + * + * @return A pointer to the X11 display visual + */ + Qt::HANDLE getX11RGBAVisual(Display *dpy); + + /** + * Returns the X11 display colormap + * + * @return An X11 display colormap object + */ + Qt::HANDLE getX11RGBAColormap(Display *dpy); + + /** + * Returns whether or not X11 composition is available + * + * You must first call getX11RGBAInformation() + * + * Note that getX11RGBAInformation() has already + * been called if you used the default TDEApplication + * constructor. + * + * Additionally, at least one application must have called + * detectCompositionManagerAvailable while the current X + * display was active in order for this method to return + * valid results. + * + * @return true if composition is available + */ + bool isX11CompositionAvailable(); + + /** + * Enables style plugins. + * + * This is useful only to applications that normally + * do not display a GUI and create the TDEApplication with + * allowStyles set to false. + */ + void enableStyles(); + + /** + * Disables style plugins. + * + * Current style plugins do not get unloaded. + * + * This is only useful when used in combination with enableStyles(). + */ + void disableStyles(); + + /** + * Installs widget filter as global X11 event filter. + * + * The widget + * filter receives XEvents in its standard TQWidget::x11Event() function. + * + * Warning: Only do this when absolutely necessary. An installed X11 filter + * can slow things down. + **/ + void installX11EventFilter( TQWidget* filter ); + + /** + * Removes global X11 event filter previously installed by + * installX11EventFilter(). + */ + void removeX11EventFilter( const TQWidget* filter ); + + /** + * Generates a uniform random number. + * @return A truly unpredictable number in the range [0, RAND_MAX) + */ + static int random(); + + /** + * Generates a random string. It operates in the range [A-Za-z0-9] + * @param length Generate a string of this length. + * @return the random string + */ + static TQString randomString(int length); + + /** + * Adds a message type to the KIPC event mask. You can only add "system + * messages" to the event mask. These are the messages with id < 32. + * Messages with id >= 32 are user messages. + * @param id The message id. See KIPC::Message. + * @see KIPC + * @see removeKipcEventMask() + * @see kipcMessage() + */ + void addKipcEventMask(int id); + + /** + * Removes a message type from the KIPC event mask. This message will + * not be handled anymore. + * @param id The message id. + * @see KIPC + * @see addKipcEventMask() + * @see kipcMessage() + */ + void removeKipcEventMask(int id); + + /** + * Returns the app startup notification identifier for this running + * application. + * @return the startup notification identifier + */ + TQCString startupId() const; + + /** + * @internal + * Sets a new value for the application startup notification window property for newly + * created toplevel windows. + * @param startup_id the startup notification identifier + * @see TDEStartupInfo::setNewStartupId + */ + void setStartupId( const TQCString& startup_id ); + + /** + * Updates the last user action timestamp to the given time, or to the current time, + * if 0 is given. Do not use unless you're really sure what you're doing. + * Consult focus stealing prevention section in tdebase/twin/README. + * @since 3.2 + */ + void updateUserTimestamp( unsigned long time = 0 ); + + /** + * Returns the last user action timestamp or 0 if no user activity has taken place yet. + * @since 3.2.3 + * @see updateuserTimestamp + */ + unsigned long userTimestamp() const; + + /** + * Updates the last user action timestamp in the application registered to DCOP with dcopId + * to the given time, or to this application's user time, if 0 is given. + * Use before causing user interaction in the remote application, e.g. invoking a dialog + * in the application using a DCOP call. + * Consult focus stealing prevention section in tdebase/twin/README. + * @since 3.3 + */ + void updateRemoteUserTimestamp( const TQCString& dcopId, unsigned long time = 0 ); + + /** + * Returns the argument to --geometry if any, so the geometry can be set + * wherever necessary + * @return the geometry argument, or TQString::null if there is none + */ + TQString geometryArgument() const; + + /** + * Install a Qt SQL property map with entries for all KDE widgets + * Call this in any application using KDE widgets in TQSqlForm or TQDataView. + */ + void installKDEPropertyMap(); + + /** + * Returns whether a certain action is authorized + * @param genericAction The name of a generic action + * @return true if the action is authorized + */ + bool authorize(const TQString &genericAction); + + /** + * Returns whether a certain TDEAction is authorized. + * + * @param action The name of a TDEAction action. The name is prepended + * with "action/" before being passed to authorize() + * @return true if the TDEAction is authorized + */ + bool authorizeTDEAction(const char *action); + + /** + * Returns whether a certain URL related action is authorized. + * + * @param action The name of the action. Known actions are + * list (may be listed (e.g. in file selection dialog)), + * link (may be linked to), + * open (may open) and + * redirect (may be redirected to) + * @param baseURL The url where the action originates from + * @param destURL The object of the action + * @return true when the action is authorized, false otherwise. + * @since 3.1 + */ + bool authorizeURLAction(const TQString &action, const KURL &baseURL, const KURL &destURL); + + /** + * Allow a certain URL action. This can be useful if your application + * needs to ensure access to an application specific directory that may + * otherwise be subject to KIOSK restrictions. + * @param action The name of the action. + * @param _baseURL The url where the action originates from + * @param _destURL The object of the action + * @since 3.2 + */ + void allowURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL); + + /** + * Returns whether access to a certain control module is authorized. + * + * @param menuId identifying the control module, e.g. tde-mouse.desktop + * @return true if access to the module is authorized, false otherwise. + * @since 3.2 + */ + bool authorizeControlModule(const TQString &menuId); + + /** + * Returns whether access to a certain control modules is authorized. + * + * @param menuIds list of menu-ids of control module, + * an example of a menu-id is tde-mouse.desktop. + * @return Those control modules for which access has been authorized. + * @since 3.2 + */ + TQStringList authorizeControlModules(const TQStringList &menuIds); + + /** + * Returns the state of the currently pressed keyboard modifiers (e.g. shift, control, etc.) + * and mouse buttons, similarly to TQKeyEvent::state() and TQMouseEvent::state(). + * You usually should simply use the information provided by TQKeyEvent and TQMouseEvent, + * but it can be useful to query for the status of the modifiers at another moment + * (e.g. some KDE apps do that upon a drop event). + * @return the keyboard modifiers and mouse buttons state + * @since 3.4 + */ + static ButtonState keyboardMouseState(); + + // Same values as ShiftMask etc. in X.h + enum { ShiftModifier = 1<<0, + LockModifier = 1<<1, + ControlModifier = 1<<2, + Modifier1 = 1<<3, + Modifier2 = 1<<4, + Modifier3 = 1<<5, + Modifier4 = 1<<6, + Modifier5 = 1<<7 }; + /** + * @deprecated Use keyboardMouseState() + * @since 3.1 + */ + static uint keyboardModifiers() KDE_DEPRECATED; + + /** @deprecated Same values as Button1Mask etc. in X.h */ + enum { Button1Pressed = 1<<8, + Button2Pressed = 1<<9, + Button3Pressed = 1<<10, + Button4Pressed = 1<<11, + Button5Pressed = 1<<12 }; + /** + * @deprecated Use keyboardMouseState() + * @since 3.1 + */ + static uint mouseState() KDE_DEPRECATED; + + +public slots: + /** + * Tells TDEApplication about one more operation that should be finished + * before the application exits. The standard behavior is to exit on the + * "last window closed" event, but some events should outlive the last window closed + * (e.g. a file copy for a file manager, or 'compacting folders on exit' for a mail client). + */ + void ref(); + + /** + * Tells TDEApplication that one operation such as those described in ref() just finished. + * The application exits if the counter is back to 0. + */ + void deref(); + +protected: + /** + * @internal Used by KUniqueApplication + */ + TDEApplication( bool allowStyles, bool GUIenabled, TDEInstance* _instance ); + +#ifdef Q_WS_X11 + /** + * @internal Used by KUniqueApplication + */ + TDEApplication( Display *display, Qt::HANDLE visual, Qt::HANDLE colormap, + bool allowStyles, TDEInstance* _instance ); + + /** + * Used to catch X11 events + */ + bool x11EventFilter( XEvent * ); + + Display *display; +#endif + Atom kipcCommAtom; + int kipcEventMask; + + /// Current application object. + static TDEApplication *KApp; + int pArgc; + + /** + * This method is used internally to determine which edit slots are implemented + * by the widget that has the focus, and to invoke those slots if available. + * + * @param slot is the slot as returned using the TQT_SLOT() macro, for example TQT_SLOT( cut() ) + * + * This method can be used in TDEApplication subclasses to implement application wide + * edit actions not supported by the TDEApplication class. For example (in your subclass): + * + * \code + * void MyApplication::deselect() + * { + * invokeEditSlot( TQT_SLOT( deselect() ) ); + * } + * \endcode + * + * Now in your application calls to MyApplication::deselect() will call this slot on the + * focused widget if it provides this slot. You can combine this with TDEAction with: + * + * \code + * KStdAction::deselect( static_cast<MyApplication *>( kapp ), TQT_SLOT( cut() ), actionCollection() ); + * \endcode + * + * @see cut() + * @see copy() + * @see paste() + * @see clear() + * @see selectAll() + * + * @since 3.2 + */ + void invokeEditSlot( const char *slot ); + +private slots: + void dcopFailure(const TQString &); + void dcopBlockUserInput( bool ); + void x11FilterDestroyed(); + void checkAppStartedSlot(); + +private: + TQString sessionConfigName() const; + TDEConfig* pSessionConfig; //instance specific application config object + static DCOPClient *s_DCOPClient; // app specific application communication client + static bool s_dcopClientNeedsPostInit; + TQString aCaption; // the name for the window title + bool bSessionManagement; + struct oldPixmapType { TQPixmap a, b; }; + mutable union { + struct { + TQPixmap *icon, *miniIcon; + } pm; + char unused[sizeof(oldPixmapType)]; + } aIconPixmap; // KDE4: remove me + TQString aIconName; + TQString aMiniIconName; + bool useStyles; + TQWidget *smw; + + void init( bool GUIenabled ); + + void parseCommandLine( ); // Handle KDE arguments (Using TDECmdLineArgs) + + void read_app_startup_id(); + + void dcopAutoRegistration(); + void dcopClientPostInit(); + void initUrlActionRestrictions(); + + bool argb_visual; +#if defined(Q_WS_X11) + Qt::HANDLE argb_x11_visual; + Qt::HANDLE argb_x11_colormap; +#endif + +public: + /** + * @internal + */ + bool notify(TQObject *receiver, TQEvent *event); + + /** + @internal + */ + int xErrhandler( Display*, void* ); + + /** + @internal + */ + int xioErrhandler( Display* ); + + /** + * @internal + */ + void iceIOErrorHandler( _IceConn *conn ); + + /** + * @internal + */ + static bool loadedByKdeinit; + + /** + * @internal + */ + static void startKdeinit(); + + /** + * Valid values for the settingsChanged signal + */ + enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS, + SETTINGS_POPUPMENU, SETTINGS_QT, SETTINGS_SHORTCUTS }; + + /** + * Used to obtain the TQPalette that will be used to set the application palette. + * + * This is only useful for configuration modules such as krdb and should not be + * used in normal circumstances. + * @return the QPalette + * @since 3.1 + */ + static TQPalette createApplicationPalette(); + + /** + * @internal + * Raw access for use by TDM. + */ + static TQPalette createApplicationPalette( TDEConfig *config, int contrast ); + + /** + * Installs a handler for the SIGPIPE signal. It is thrown when you write to + * a pipe or socket that has been closed. + * The handler is installed automatically in the constructor, but you may + * need it if your application or component does not have a TDEApplication + * instance. + */ + static void installSigpipeHandler(); + + /** + * @internal + * Whether widgets can be used. + * + * @since 3.2 + */ + static bool guiEnabled(); + +signals: + /** + * Emitted when TDEApplication has changed its palette due to a KControl request. + * + * Normally, widgets will update their palette automatically, but you + * should connect to this to program special behavior. + */ + void tdedisplayPaletteChanged(); + + /** + * Emitted when TDEApplication has changed its GUI style in response to a KControl request. + * + * Normally, widgets will update their styles automatically (as they would + * respond to an explicit setGUIStyle() call), but you should connect to + * this to program special behavior. + */ + void tdedisplayStyleChanged(); + + /** + * Emitted when TDEApplication has changed its font in response to a KControl request. + * + * Normally widgets will update their fonts automatically, but you should + * connect to this to monitor global font changes, especially if you are + * using explicit fonts. + * + * Note: If you derive from a QWidget-based class, a faster method is to + * reimplement TQWidget::fontChange(). This is the preferred way + * to get informed about font updates. + */ + void tdedisplayFontChanged(); + + /** + * Emitted when TDEApplication has changed either its GUI style, its font or its palette + * in response to a tdedisplay request. Normally, widgets will update their styles + * automatically, but you should connect to this to program special + * behavior. */ + void appearanceChanged(); + + /** + * Emitted when the settings for toolbars have been changed. TDEToolBar will know what to do. + */ + void toolbarAppearanceChanged(int); + + /** + * Emitted when the desktop background has been changed by @p kcmdisplay. + * + * @param desk The desktop whose background has changed. + */ + void backgroundChanged(int desk); + + /** + * Emitted when the global settings have been changed - see TDEGlobalSettings + * TDEApplication takes care of calling reparseConfiguration on TDEGlobal::config() + * so that applications/classes using this only have to re-read the configuration + * @param category the category among the enum above + */ + void settingsChanged(int category); + + /** + * Emitted when the global icon settings have been changed. + * @param group the new group + */ + void iconChanged(int group); + + /** + * Emitted when a KIPC user message has been received. + * @param id the message id + * @param data the data + * @see KIPC + * @see KIPC::Message + * @see addKipcEventMask + * @see removeKipcEventMask + */ + void kipcMessage(int id, int data); + + /** + Session management asks you to save the state of your application. + + This signal is provided for compatibility only. For new + applications, simply use TDEMainWindow. By reimplementing + TDEMainWindow::queryClose(), TDEMainWindow::saveProperties() and + TDEMainWindow::readProperties() you can simply handle session + management for applications with multiple toplevel windows. + + For purposes without TDEMainWindow, create an instance of + KSessionManaged and reimplement the functions + KSessionManaged::commitData() and/or + KSessionManaged::saveState() + + If you still want to use this signal, here is what you should do: + + Connect to this signal in order to save your data. Do NOT + manipulate the UI in that slot, it is blocked by the session + manager. + + Use the sessionConfig() TDEConfig object to store all your + instance specific data. + + Do not do any closing at this point! The user may still select + Cancel wanting to continue working with your + application. Cleanups could be done after shutDown() (see + the following). + + */ + void saveYourself(); + + /** Your application is killed. Either by your program itself, + @p xkill or (the usual case) by KDE's logout. + + The signal is particularly useful if your application has to do some + last-second cleanups. Note that no user interaction is possible at + this state. + */ + void shutDown(); + + /** + * @internal + * Used to notify TDEIconLoader objects that they need to reload. + */ + void updateIconLoaders(); + + /** + * @internal + * Used to send TDEGlobalAccel objects a new keypress from physical hotkeys. + */ + void coreFakeKeyPress(unsigned int keyCode); + +private: + void propagateSettings(SettingsCategory category); + void tdedisplaySetPalette(); + void tdedisplaySetStyle(); + void tdedisplaySetFont(); + void applyGUIStyle(); + static void sigpipeHandler(int); + + int captionLayout; + + TDEApplication(const TDEApplication&); + TDEApplication& operator=(const TDEApplication&); +protected: + virtual void virtual_hook( int id, void* data ); +private: + TDEApplicationPrivate* d; +}; + + +/** + * \relates TDEGlobal + * Check, if a file may be accessed in a given mode. + * This is a wrapper around the access() system call. + * checkAccess() calls access() with the given parameters. + * If this is OK, checkAccess() returns true. If not, and W_OK + * is part of mode, it is checked if there is write access to + * the directory. If yes, checkAccess() returns true. + * In all other cases checkAccess() returns false. + * + * Other than access() this function EXPLICITLY ignores non-existant + * files if checking for write access. + * + * @param pathname The full path of the file you want to test + * @param mode The access mode, as in the access() system call. + * @return Whether the access is allowed, true = Access allowed + */ +TDECORE_EXPORT bool checkAccess(const TQString& pathname, int mode); + +class KSessionManagedPrivate; + +/** + Provides highlevel access to session management on a per-object + base. + + KSessionManaged makes it possible to provide implementations for + TQApplication::commitData() and TQApplication::saveState(), without + subclassing TDEApplication. TDEMainWindow internally makes use of this. + + You don't need to do anything with this class when using + TDEMainWindow. Instead, use TDEMainWindow::saveProperties(), + TDEMainWindow::readProperties(), TDEMainWindow::queryClose(), + TDEMainWindow::queryExit() and friends. + + @short Highlevel access to session management. + @author Matthias Ettrich <ettrich@kde.org> + */ +class TDECORE_EXPORT KSessionManaged +{ +public: + KSessionManaged(); + virtual ~KSessionManaged(); + + /** + See TQApplication::saveState() for documentation. + + This function is just a convenience version to avoid subclassing TDEApplication. + + Return true to indicate a successful state save or false to + indicate a problem and to halt the shutdown process (will + implicitly call sm.cancel() ). + */ + virtual bool saveState( TQSessionManager& sm ); + /** + See TQApplication::commitData() for documentation. + + This function is just a convenience version to avoid subclassing TDEApplication. + + Return true to indicate a successful commit of data or false to + indicate a problem and to halt the shutdown process (will + implicitly call sm.cancel() ). + */ + virtual bool commitData( TQSessionManager& sm ); + +protected: + virtual void virtual_hook( int id, void* data ); +private: + KSessionManagedPrivate *d; +}; + + +#endif + diff --git a/tdecore/tdecmdlineargs.cpp b/tdecore/tdecmdlineargs.cpp new file mode 100644 index 000000000..ad24467e2 --- /dev/null +++ b/tdecore/tdecmdlineargs.cpp @@ -0,0 +1,1298 @@ +/* + 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 <tqdir.h> +#include <tqfile.h> +#include <tqasciidict.h> +#include <tqstrlist.h> + +#include "tdecmdlineargs.h" +#include <tdeaboutdata.h> +#include <klocale.h> +#include <tdeapplication.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 TQAsciiDict<TQCString>; +template class TQPtrList<TDECmdLineArgs>; + +class TDECmdLineParsedOptions : public TQAsciiDict<TQCString> +{ +public: + TDECmdLineParsedOptions() + : TQAsciiDict<TQCString>( 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<TDECmdLineArgs> +{ +public: + TDECmdLineArgsList() { } +}; + +TDECmdLineArgsList *TDECmdLineArgs::argsList = 0; +int TDECmdLineArgs::argc = 0; +char **TDECmdLineArgs::argv = 0; +char *TDECmdLineArgs::mCwd = 0; +static KStaticDeleter <char> 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); + (void) getcwd(mCwd, PATH_MAX); +#ifdef Q_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 Qt and TDE options. + removeArgs("qt"); + removeArgs("tde"); + + 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) +{ + parsed = true; // don't reparse argc/argv! + + // Remove Qt and TDE options. + removeArgs("qt"); + removeArgs("tde"); + + 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; + int p = nextOption.find(' '); + if (p > 0) + nextOption = nextOption.left(p); + if (nextOption[0] == '!') + nextOption = nextOption.mid(1); + 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; + int j = opt.find('='); + 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, (const char*)argument); + 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, (const char*)argument); + } + else + { + args->setOption(opt, enabled); + } +} + +void +TDECmdLineArgs::printQ(const TQString &msg) +{ + TQCString localMsg = msg.local8Bit(); + 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("Qt: %1\n").arg(tqVersion())); + printQ( TQString("TDE: %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<TDEAboutPerson> authors = about->authors(); + if ( !authors.isEmpty() ) { + TQString authorlist; + for (TQValueList<TDEAboutPerson>::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("This application was written by somebody who wants to remain anonymous.") ); + } + if (about) + { + if (!about->customAuthorTextEnabled ()) + { + if (about->bugAddress().isEmpty() || about->bugAddress() == "bugs.pearsoncomputing.net" ) + printQ( i18n( "Please use http://bugs.pearsoncomputing.net to report bugs.\n" ) ); + else { + if( about->authors().count() == 1 && about->authors().first().emailAddress() == about->bugAddress() ) + printQ( i18n( "Please report bugs to %1.\n" ).arg( about->authors().first().emailAddress() ) ); + else + printQ( i18n( "Please report bugs to %1.\n" ).arg(about->bugAddress()) ); + } + } + else + { + printQ(about->customAuthorPlainText()); + } + } + 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); + TQCString localError = error.local8Bit(); + 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."); + localError = tmp.local8Bit(); + 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); + dl = TQStringList::split("\n", description, true); + description = dl.first(); + dl.remove( 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(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(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; + isQt = (::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 (isQt) + { + // Qt 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 (isQt) + { + // Qt does it's own parsing. + TQCString 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 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) +{ + const TQString urlArg = TQFile::decodeName(_urlArg); + TQFileInfo fileInfo(urlArg); + if (!fileInfo.isRelative()) { // i.e. starts with '/', on unix + KURL result; + result.setPath(urlArg); + return result; // Absolute path. + } + + if ( KURL::isRelativeURL(urlArg) || fileInfo.exists() ) { + KURL result; + result.setPath( cwd()+'/'+urlArg ); + result.cleanPath(); + return result; // Relative path + } + + return KURL(urlArg); // Argument is a URL +} + +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, "TDE-tempfile", "tde-tempfile" ); +} + +bool TDECmdLineArgs::isTempFileSet() +{ + TDECmdLineArgs* args = TDECmdLineArgs::parsedArgs( "tde-tempfile" ); + if ( args ) + return args->isSet( "tempfile" ); + return false; +} diff --git a/tdecore/tdecmdlineargs.h b/tdecore/tdecmdlineargs.h new file mode 100644 index 000000000..9b7dc0f4f --- /dev/null +++ b/tdecore/tdecmdlineargs.h @@ -0,0 +1,690 @@ +/* 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 "tdelibs_export.h" +#include <kurl.h> + +#include <tqptrlist.h> +#include <tqstring.h> +#include <tqvaluelist.h> + +typedef TQValueList<TQCString> 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 <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 + * TDECmdLineArgs::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 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 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 %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 \<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 }, + * 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<TDECmdLineArgs>; +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 \<argument>", 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 \<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 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 + * 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 \<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. + */ + 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 \<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 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 Qt 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 isQt; + + 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/tdecore/tdeconfig.cpp b/tdecore/tdeconfig.cpp index 1e75be6f1..35c5b73bc 100644 --- a/tdecore/tdeconfig.cpp +++ b/tdecore/tdeconfig.cpp @@ -32,7 +32,7 @@ #include <tqfileinfo.h> -#include <kapplication.h> +#include <tdeapplication.h> #include "tdeconfigbackend.h" #include "tdeconfig.h" diff --git a/tdecore/tdeconfig_compiler/example/autoexample.cpp b/tdecore/tdeconfig_compiler/example/autoexample.cpp index 6ed89d75f..e25219787 100644 --- a/tdecore/tdeconfig_compiler/example/autoexample.cpp +++ b/tdecore/tdeconfig_compiler/example/autoexample.cpp @@ -24,11 +24,11 @@ #include "exampleprefs_base.h" -#include <kaboutdata.h> -#include <kapplication.h> +#include <tdeaboutdata.h> +#include <tdeapplication.h> #include <kdebug.h> #include <klocale.h> -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> #include <kglobal.h> #include <tdeconfig.h> #include <kstandarddirs.h> diff --git a/tdecore/tdeconfig_compiler/example/example.cpp b/tdecore/tdeconfig_compiler/example/example.cpp index 6788d1ee0..c08339d4a 100644 --- a/tdecore/tdeconfig_compiler/example/example.cpp +++ b/tdecore/tdeconfig_compiler/example/example.cpp @@ -21,11 +21,11 @@ #include "exampleprefs_base.h" -#include <kaboutdata.h> -#include <kapplication.h> +#include <tdeaboutdata.h> +#include <tdeapplication.h> #include <kdebug.h> #include <klocale.h> -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> #include <kglobal.h> #include <tdeconfig.h> #include <kstandarddirs.h> diff --git a/tdecore/tdeconfig_compiler/tdeconfig_compiler.cpp b/tdecore/tdeconfig_compiler/tdeconfig_compiler.cpp index 4a8f52712..753bae532 100644 --- a/tdecore/tdeconfig_compiler/tdeconfig_compiler.cpp +++ b/tdecore/tdeconfig_compiler/tdeconfig_compiler.cpp @@ -27,11 +27,11 @@ #include <tqdom.h> #include <tqregexp.h> -#include <kaboutdata.h> -#include <kapplication.h> +#include <tdeaboutdata.h> +#include <tdeapplication.h> #include <kdebug.h> #include <klocale.h> -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> #include <kglobal.h> #include <tdeconfig.h> #include <ksimpleconfig.h> diff --git a/tdecore/tdeconfigbackend.cpp b/tdecore/tdeconfigbackend.cpp index 4ad70b4a8..d050a2efe 100644 --- a/tdecore/tdeconfigbackend.cpp +++ b/tdecore/tdeconfigbackend.cpp @@ -41,7 +41,7 @@ #include "tdeconfigbackend.h" #include "tdeconfigbase.h" -#include <kapplication.h> +#include <tdeapplication.h> #include <kglobal.h> #include <kprocess.h> #include <klocale.h> diff --git a/tdecore/tdeconfigbase.cpp b/tdecore/tdeconfigbase.cpp index d2ecef888..668a688d8 100644 --- a/tdecore/tdeconfigbase.cpp +++ b/tdecore/tdeconfigbase.cpp @@ -27,7 +27,7 @@ #include <tqdir.h> #include <tqtextstream.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kglobal.h> #include <klocale.h> #include <kcharsets.h> diff --git a/tdecore/tdeconfigdialogmanager.cpp b/tdecore/tdeconfigdialogmanager.cpp index ab5218687..dfabefb59 100644 --- a/tdecore/tdeconfigdialogmanager.cpp +++ b/tdecore/tdeconfigdialogmanager.cpp @@ -30,7 +30,7 @@ #include <tqtimer.h> #include <tqwhatsthis.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <tdeconfigskeleton.h> #include <kdebug.h> #include <kglobal.h> diff --git a/tdecore/tdehardwaredevices.cpp b/tdecore/tdehardwaredevices.cpp index 559650e20..263bc5507 100644 --- a/tdecore/tdehardwaredevices.cpp +++ b/tdecore/tdehardwaredevices.cpp @@ -30,7 +30,7 @@ #include <ksimpledirwatch.h> #include <kstandarddirs.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <dcopclient.h> #include <libudev.h> diff --git a/tdecore/tdesycoca.cpp b/tdecore/tdesycoca.cpp index 31da8b741..16914c0bc 100644 --- a/tdecore/tdesycoca.cpp +++ b/tdecore/tdesycoca.cpp @@ -26,7 +26,7 @@ #include <tqfile.h> #include <tqbuffer.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <dcopclient.h> #include <kglobal.h> #include <kdebug.h> diff --git a/tdecore/tests/KIDLTest.cpp b/tdecore/tests/KIDLTest.cpp index f022e307a..a54e32be5 100644 --- a/tdecore/tests/KIDLTest.cpp +++ b/tdecore/tests/KIDLTest.cpp @@ -1,6 +1,6 @@ #include "KIDLTest.h" -#include <kapplication.h> +#include <tdeapplication.h> #include <dcopclient.h> KIDLTest::KIDLTest( const TQCString& id ) diff --git a/tdecore/tests/KIDLTestClient.cpp b/tdecore/tests/KIDLTestClient.cpp index 75d5949c7..4614ed51e 100644 --- a/tdecore/tests/KIDLTestClient.cpp +++ b/tdecore/tests/KIDLTestClient.cpp @@ -1,4 +1,4 @@ -#include <kapplication.h> +#include <tdeapplication.h> #include <dcopclient.h> #include "KIDLTest_stub.h" diff --git a/tdecore/tests/dcopkonqtest.cpp b/tdecore/tests/dcopkonqtest.cpp index 79137cd5f..b8bb055d6 100644 --- a/tdecore/tests/dcopkonqtest.cpp +++ b/tdecore/tests/dcopkonqtest.cpp @@ -1,4 +1,4 @@ -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <dcopclient.h> diff --git a/tdecore/tests/kapptest.cpp b/tdecore/tests/kapptest.cpp index bae6a9c2e..0952f292c 100644 --- a/tdecore/tests/kapptest.cpp +++ b/tdecore/tests/kapptest.cpp @@ -17,11 +17,11 @@ */ #define private public -#include "kapplication.h" +#include "tdeapplication.h" #include <stdio.h> -#include <kcmdlineargs.h> -#include <kaboutdata.h> +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> #include <kglobalsettings.h> #include <tdesycoca.h> diff --git a/tdecore/tests/kcalendartest.cpp b/tdecore/tests/kcalendartest.cpp index 7856c0430..12c9010e2 100644 --- a/tdecore/tests/kcalendartest.cpp +++ b/tdecore/tests/kcalendartest.cpp @@ -7,12 +7,12 @@ #include <tqstringlist.h> -#include <kapplication.h> -#include <kaboutdata.h> +#include <tdeapplication.h> +#include <tdeaboutdata.h> #include <kdebug.h> #include <kglobal.h> #include <klocale.h> -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> class TDELocale; diff --git a/tdecore/tests/kcmdlineargstest.cpp b/tdecore/tests/kcmdlineargstest.cpp index f05168e1a..8148e4208 100644 --- a/tdecore/tests/kcmdlineargstest.cpp +++ b/tdecore/tests/kcmdlineargstest.cpp @@ -1,6 +1,6 @@ -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> #include <klocale.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <stdio.h> diff --git a/tdecore/tests/kglobaltest.cpp b/tdecore/tests/kglobaltest.cpp index 9c7b081de..eaab091f9 100644 --- a/tdecore/tests/kglobaltest.cpp +++ b/tdecore/tests/kglobaltest.cpp @@ -2,11 +2,11 @@ #include <kglobal.h> #include <stdio.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <stdlib.h> #include <kdebug.h> #include <assert.h> -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> static bool check(const TQString& txt, TQString a, TQString b) { diff --git a/tdecore/tests/kiconloadertest.cpp b/tdecore/tests/kiconloadertest.cpp index 29f810488..c6da1994c 100644 --- a/tdecore/tests/kiconloadertest.cpp +++ b/tdecore/tests/kiconloadertest.cpp @@ -1,7 +1,7 @@ #include <kiconloader.h> #include <tqdatetime.h> #include <stdio.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <stdlib.h> #include <kdebug.h> diff --git a/tdecore/tests/kipctest.cpp b/tdecore/tests/kipctest.cpp index d6cff80e3..af6785f0c 100644 --- a/tdecore/tests/kipctest.cpp +++ b/tdecore/tests/kipctest.cpp @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> #include <tqobject.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kipc.h> #include "kipctest.h" diff --git a/tdecore/tests/klocaletest.cpp b/tdecore/tests/klocaletest.cpp index 1d0ca7aba..0647a10d3 100644 --- a/tdecore/tests/klocaletest.cpp +++ b/tdecore/tests/klocaletest.cpp @@ -14,7 +14,7 @@ #include <kglobal.h> #include <kglobalsettings.h> #include "klocale.h" -#include <kapplication.h> +#include <tdeapplication.h> #include <kcharsets.h> #include <kdebug.h> diff --git a/tdecore/tests/kmacroexpandertest.cpp b/tdecore/tests/kmacroexpandertest.cpp index fe3f66c65..e357b5801 100644 --- a/tdecore/tests/kmacroexpandertest.cpp +++ b/tdecore/tests/kmacroexpandertest.cpp @@ -1,7 +1,7 @@ #include <kmacroexpander.h> -#include <kapplication.h> -#include <kcmdlineargs.h> +#include <tdeapplication.h> +#include <tdecmdlineargs.h> #include <kdebug.h> #include <stdlib.h> diff --git a/tdecore/tests/kmdcodectest.cpp b/tdecore/tests/kmdcodectest.cpp index 5cdf4ac3e..bd3162f52 100644 --- a/tdecore/tests/kmdcodectest.cpp +++ b/tdecore/tests/kmdcodectest.cpp @@ -28,8 +28,8 @@ #include <kdebug.h> #include <klocale.h> -#include <kcmdlineargs.h> -#include <kapplication.h> +#include <tdecmdlineargs.h> +#include <tdeapplication.h> #include <kmdcodec.h> diff --git a/tdecore/tests/kmemtest.cpp b/tdecore/tests/kmemtest.cpp index 0a2a1bdb8..f0115b569 100644 --- a/tdecore/tests/kmemtest.cpp +++ b/tdecore/tests/kmemtest.cpp @@ -1,5 +1,5 @@ #include <stdio.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <stdlib.h> #include <errno.h> #include <string.h> diff --git a/tdecore/tests/knotifytest.cpp b/tdecore/tests/knotifytest.cpp index 27076a1e8..6c5af25a7 100644 --- a/tdecore/tests/knotifytest.cpp +++ b/tdecore/tests/knotifytest.cpp @@ -1,5 +1,5 @@ #include <knotifyclient.h> -#include <kapplication.h> +#include <tdeapplication.h> int main( int argc, char **argv ) { diff --git a/tdecore/tests/kprocesstest.cpp b/tdecore/tests/kprocesstest.cpp index f86cb2f20..c81dada50 100644 --- a/tdecore/tests/kprocesstest.cpp +++ b/tdecore/tests/kprocesstest.cpp @@ -13,7 +13,7 @@ #include <stdio.h> #include <string.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <signal.h> diff --git a/tdecore/tests/kprociotest.cpp b/tdecore/tests/kprociotest.cpp index a4fbb19ad..ee7aaf2b7 100644 --- a/tdecore/tests/kprociotest.cpp +++ b/tdecore/tests/kprociotest.cpp @@ -13,7 +13,7 @@ #include <stdio.h> #include <string.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <signal.h> diff --git a/tdecore/tests/krandomsequencetest.cpp b/tdecore/tests/krandomsequencetest.cpp index 53c42facb..2ba0c72ae 100644 --- a/tdecore/tests/krandomsequencetest.cpp +++ b/tdecore/tests/krandomsequencetest.cpp @@ -19,7 +19,7 @@ #include <tqptrlist.h> #include "krandomsequence.h" -#include "kapplication.h" +#include "tdeapplication.h" #include <stdio.h> diff --git a/tdecore/tests/kresolvertest.cpp b/tdecore/tests/kresolvertest.cpp index 6e1a3080f..0e05cab4e 100644 --- a/tdecore/tests/kresolvertest.cpp +++ b/tdecore/tests/kresolvertest.cpp @@ -40,8 +40,8 @@ #include <ksocks.h> #include <ksockaddr.h> #include <kextsock.h> -#include <kaboutdata.h> -#include <kcmdlineargs.h> +#include <tdeaboutdata.h> +#include <tdecmdlineargs.h> #include "netsupp.h" diff --git a/tdecore/tests/krfcdatetest.cpp b/tdecore/tests/krfcdatetest.cpp index cb8bffbfd..6ef0fe5e5 100644 --- a/tdecore/tests/krfcdatetest.cpp +++ b/tdecore/tests/krfcdatetest.cpp @@ -1,5 +1,5 @@ #include <stdio.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <stdlib.h> #include <kdebug.h> #include <kglobal.h> diff --git a/tdecore/tests/ksimpleconfigtest.cpp b/tdecore/tests/ksimpleconfigtest.cpp index 85193f40b..8b0e4ef25 100644 --- a/tdecore/tests/ksimpleconfigtest.cpp +++ b/tdecore/tests/ksimpleconfigtest.cpp @@ -6,7 +6,7 @@ // demonstrates use of KSimpleConfig class #include <ksimpleconfig.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <unistd.h> #include <stdio.h> diff --git a/tdecore/tests/ksocktest.cpp b/tdecore/tests/ksocktest.cpp index e038cbd2c..01a9c4c3a 100644 --- a/tdecore/tests/ksocktest.cpp +++ b/tdecore/tests/ksocktest.cpp @@ -23,8 +23,8 @@ #include "ksockaddr.h" #include "kextsock.h" -#include <kaboutdata.h> -#include <kcmdlineargs.h> +#include <tdeaboutdata.h> +#include <tdecmdlineargs.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> diff --git a/tdecore/tests/kstddirstest.cpp b/tdecore/tests/kstddirstest.cpp index 75c326280..ae6ea16bd 100644 --- a/tdecore/tests/kstddirstest.cpp +++ b/tdecore/tests/kstddirstest.cpp @@ -1,4 +1,4 @@ -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <kinstance.h> #include <kstandarddirs.h> diff --git a/tdecore/tests/ktempfiletest.cpp b/tdecore/tests/ktempfiletest.cpp index ec3a004cd..20cd6b36d 100644 --- a/tdecore/tests/ktempfiletest.cpp +++ b/tdecore/tests/ktempfiletest.cpp @@ -17,7 +17,7 @@ */ #include "ktempfile.h" -#include "kapplication.h" +#include "tdeapplication.h" #include "kstandarddirs.h" #include <tqstring.h> diff --git a/tdecore/tests/ktimezonestest.cpp b/tdecore/tests/ktimezonestest.cpp index 729c88bb6..5eaf5a4fb 100644 --- a/tdecore/tests/ktimezonestest.cpp +++ b/tdecore/tests/ktimezonestest.cpp @@ -1,5 +1,5 @@ #include "ktimezones.h" -#include <kapplication.h> +#include <tdeapplication.h> #include <stdio.h> #include <stdlib.h> diff --git a/tdecore/tests/kuniqueapptest.cpp b/tdecore/tests/kuniqueapptest.cpp index 053956715..60ac98b5a 100644 --- a/tdecore/tests/kuniqueapptest.cpp +++ b/tdecore/tests/kuniqueapptest.cpp @@ -22,8 +22,8 @@ #include <unistd.h> #include <stdlib.h> #include <stdio.h> -#include <kcmdlineargs.h> -#include <kaboutdata.h> +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> class TestApp : public KUniqueApplication { diff --git a/tdecore/tests/kurltest.cpp b/tdecore/tests/kurltest.cpp index 178aec6d5..6694d0d80 100644 --- a/tdecore/tests/kurltest.cpp +++ b/tdecore/tests/kurltest.cpp @@ -2,7 +2,7 @@ #include <kurl.h> #include <stdio.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <stdlib.h> #include <kdebug.h> #include <kglobal.h> @@ -10,7 +10,7 @@ #include <tqtextcodec.h> #include <tqdatastream.h> #include <assert.h> -#include <kcmdlineargs.h> +#include <tdecmdlineargs.h> static bool check(TQString txt, TQString a, TQString b) { diff --git a/tdecore/tests/startserviceby.cpp b/tdecore/tests/startserviceby.cpp index 5cccaa3dc..20fc95f34 100644 --- a/tdecore/tests/startserviceby.cpp +++ b/tdecore/tests/startserviceby.cpp @@ -16,11 +16,11 @@ Boston, MA 02110-1301, USA. */ -#include "kapplication.h" +#include "tdeapplication.h" #include <stdio.h> -#include <kcmdlineargs.h> -#include <kaboutdata.h> +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> #include <kglobalsettings.h> #include <kdebug.h> diff --git a/tdecore/tests/tdeconfigtestgui.cpp b/tdecore/tests/tdeconfigtestgui.cpp index 5ae85d26d..d1e2d5393 100644 --- a/tdecore/tests/tdeconfigtestgui.cpp +++ b/tdecore/tests/tdeconfigtestgui.cpp @@ -29,7 +29,7 @@ #include <unistd.h> #include <stdlib.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <tqdialog.h> #include <tqfile.h> #include <tqfileinfo.h> diff --git a/tdecore/tests/tdeconfigtestgui.h b/tdecore/tests/tdeconfigtestgui.h index 347a9c81d..4aa50cb5f 100644 --- a/tdecore/tests/tdeconfigtestgui.h +++ b/tdecore/tests/tdeconfigtestgui.h @@ -19,7 +19,7 @@ #ifndef _KCONFIG_TEST_H #define _KCONFIG_TEST_H -#include <kapplication.h> +#include <tdeapplication.h> #include <tqdialog.h> #include <tqfile.h> #include <tqfileinfo.h> diff --git a/tdecore/tests/tdestdacceltest.cpp b/tdecore/tests/tdestdacceltest.cpp index fbc5077a5..7a1fe8697 100644 --- a/tdecore/tests/tdestdacceltest.cpp +++ b/tdecore/tests/tdestdacceltest.cpp @@ -1,6 +1,6 @@ #include <config.h> -#include <kapplication.h> +#include <tdeapplication.h> #include <kdebug.h> #include <tdestdaccel.h> #include <stdlib.h> // for exit diff --git a/tdecore/tests/testqtargs.cpp b/tdecore/tests/testqtargs.cpp index a27073468..8383f930e 100644 --- a/tdecore/tests/testqtargs.cpp +++ b/tdecore/tests/testqtargs.cpp @@ -28,7 +28,7 @@ --bg is aliased to --background but If you try it with --background or -background, you get the same thing. - in tdecore/kapplication.cpp, TDECmdLineOption qt_options is defined and used + in tdecore/tdeapplication.cpp, TDECmdLineOption qt_options is defined and used by the static method Kapplication::addCmdLineOptions to add the Qt options but its' entries look like this: @@ -43,9 +43,9 @@ application palette (light and dark shades are\ncalculated)."), 0}, */ -#include <kapplication.h> -#include <kcmdlineargs.h> -#include <kaboutdata.h> +#include <tdeapplication.h> +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> #include <klocale.h> static const TDECmdLineOptions options[] = diff --git a/tdecore/twin.cpp b/tdecore/twin.cpp index 841463e52..93352dacc 100644 --- a/tdecore/twin.cpp +++ b/tdecore/twin.cpp @@ -35,7 +35,7 @@ #include "config.h" #include "twin.h" -#include "kapplication.h" +#include "tdeapplication.h" #include <kglobal.h> #include <kiconloader.h> diff --git a/tdecore/twinmodule.cpp b/tdecore/twinmodule.cpp index adc20f218..27b8b0cdd 100644 --- a/tdecore/twinmodule.cpp +++ b/tdecore/twinmodule.cpp @@ -26,7 +26,7 @@ #include "twinmodule.h" #include "twin.h" #include <X11/Xatom.h> -#include "kapplication.h" +#include "tdeapplication.h" #include "kdebug.h" #include <tqtl.h> #include <tqptrlist.h> -- cgit v1.2.1