• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KDECore

kaboutdata.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of the KDE Libraries
00003  * Copyright (C) 2000 Espen Sand (espen@kde.org)
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  *
00020  */
00021 
00022 
00023 #include <kaboutdata.h>
00024 #include <kstandarddirs.h>
00025 #include <qfile.h>
00026 #include <qtextstream.h>
00027 
00028 QString
00029 KAboutPerson::name() const
00030 {
00031    return QString::fromUtf8(mName);
00032 }
00033 
00034 QString
00035 KAboutPerson::task() const
00036 {
00037    if (mTask && *mTask)
00038       return i18n(mTask);
00039    else
00040       return QString::null;
00041 }
00042 
00043 QString
00044 KAboutPerson::emailAddress() const
00045 {
00046    return QString::fromUtf8(mEmailAddress);
00047 }
00048 
00049 
00050 QString
00051 KAboutPerson::webAddress() const
00052 {
00053    return QString::fromUtf8(mWebAddress);
00054 }
00055 
00056 
00057 KAboutTranslator::KAboutTranslator(const QString & name,
00058                 const QString & emailAddress)
00059 {
00060     mName=name;
00061     mEmail=emailAddress;
00062 }
00063 
00064 QString KAboutTranslator::name() const
00065 {
00066     return mName;
00067 }
00068 
00069 QString KAboutTranslator::emailAddress() const
00070 {
00071     return mEmail;
00072 }
00073 
00074 class KAboutDataPrivate
00075 {
00076 public:
00077     KAboutDataPrivate()
00078         : translatorName("_: NAME OF TRANSLATORS\nYour names")
00079         , translatorEmail("_: EMAIL OF TRANSLATORS\nYour emails")
00080         , productName(0)
00081         , programLogo(0)
00082         , customAuthorTextEnabled(false)
00083         , mTranslatedProgramName( 0 )
00084         {}
00085     ~KAboutDataPrivate()
00086         {
00087              delete programLogo;
00088              delete[] mTranslatedProgramName;
00089         }
00090     const char *translatorName;
00091     const char *translatorEmail;
00092     const char *productName;
00093     QImage* programLogo;
00094     QString customAuthorPlainText, customAuthorRichText;
00095     bool customAuthorTextEnabled;
00096     const char *mTranslatedProgramName;
00097 };
00098 
00099 
00100 
00101 KAboutData::KAboutData( const char *appName,
00102                         const char *programName,
00103                         const char *version,
00104                         const char *shortDescription,
00105             int licenseType,
00106             const char *copyrightStatement,
00107             const char *text,
00108             const char *homePageAddress,
00109             const char *bugsEmailAddress
00110             ) :
00111   mProgramName( programName ),
00112   mVersion( version ),
00113   mShortDescription( shortDescription ),
00114   mLicenseKey( licenseType ),
00115   mCopyrightStatement( copyrightStatement ),
00116   mOtherText( text ),
00117   mHomepageAddress( homePageAddress ),
00118   mBugEmailAddress( bugsEmailAddress ),
00119   mLicenseText (0)
00120 {
00121    d = new KAboutDataPrivate;
00122 
00123    if( appName ) {
00124      const char *p = strrchr(appName, '/');
00125      if( p )
00126      mAppName = p+1;
00127      else
00128      mAppName = appName;
00129    } else
00130      mAppName = 0;
00131 }
00132 
00133 KAboutData::~KAboutData()
00134 {
00135     if (mLicenseKey == License_File)
00136         delete [] mLicenseText;
00137     delete d;
00138 }
00139 
00140 void
00141 KAboutData::addAuthor( const char *name, const char *task,
00142             const char *emailAddress, const char *webAddress )
00143 {
00144   mAuthorList.append(KAboutPerson(name,task,emailAddress,webAddress));
00145 }
00146 
00147 void
00148 KAboutData::addCredit( const char *name, const char *task,
00149             const char *emailAddress, const char *webAddress )
00150 {
00151   mCreditList.append(KAboutPerson(name,task,emailAddress,webAddress));
00152 }
00153 
00154 void
00155 KAboutData::setTranslator( const char *name, const char *emailAddress)
00156 {
00157   d->translatorName=name;
00158   d->translatorEmail=emailAddress;
00159 }
00160 
00161 void
00162 KAboutData::setLicenseText( const char *licenseText )
00163 {
00164   mLicenseText = licenseText;
00165   mLicenseKey = License_Custom;
00166 }
00167 
00168 void
00169 KAboutData::setLicenseTextFile( const QString &file )
00170 {
00171   mLicenseText = qstrdup(QFile::encodeName(file));
00172   mLicenseKey = License_File;
00173 }
00174 
00175 void
00176 KAboutData::setAppName( const char *appName )
00177 {
00178   mAppName = appName;
00179 }
00180 
00181 void
00182 KAboutData::setProgramName( const char* programName )
00183 {
00184   mProgramName = programName;
00185   translateInternalProgramName();
00186 }
00187 
00188 void
00189 KAboutData::setVersion( const char* version )
00190 {
00191   mVersion = version;
00192 }
00193 
00194 void
00195 KAboutData::setShortDescription( const char *shortDescription )
00196 {
00197   mShortDescription = shortDescription;
00198 }
00199 
00200 void
00201 KAboutData::setLicense( LicenseKey licenseKey)
00202 {
00203   mLicenseKey = licenseKey;
00204 }
00205 
00206 void
00207 KAboutData::setCopyrightStatement( const char *copyrightStatement )
00208 {
00209   mCopyrightStatement = copyrightStatement;
00210 }
00211 
00212 void
00213 KAboutData::setOtherText( const char *otherText )
00214 {
00215   mOtherText = otherText;
00216 }
00217 
00218 void
00219 KAboutData::setHomepage( const char *homepage )
00220 {
00221   mHomepageAddress = homepage;
00222 }
00223 
00224 void
00225 KAboutData::setBugAddress( const char *bugAddress )
00226 {
00227   mBugEmailAddress = bugAddress;
00228 }
00229 
00230 void
00231 KAboutData::setProductName( const char *productName )
00232 {
00233   d->productName = productName;
00234 }
00235 
00236 const char *
00237 KAboutData::appName() const
00238 {
00239    return mAppName;
00240 }
00241 
00242 const char *
00243 KAboutData::productName() const
00244 {
00245    if (d->productName)
00246       return d->productName;
00247    else
00248       return appName();
00249 }
00250 
00251 QString
00252 KAboutData::programName() const
00253 {
00254    if (mProgramName && *mProgramName)
00255       return i18n(mProgramName);
00256    else
00257       return QString::null;
00258 }
00259 
00260 const char*
00261 KAboutData::internalProgramName() const
00262 {
00263    if (d->mTranslatedProgramName)
00264       return d->mTranslatedProgramName;
00265    else
00266       return mProgramName;
00267 }
00268 
00269 // KCrash should call as few things as possible and should avoid e.g. malloc()
00270 // because it may deadlock. Since i18n() needs it, when KLocale is available
00271 // the i18n() call will be done here in advance.
00272 void
00273 KAboutData::translateInternalProgramName() const
00274 {
00275   delete[] d->mTranslatedProgramName;
00276   d->mTranslatedProgramName = 0;
00277   if( KGlobal::locale() )
00278       d->mTranslatedProgramName = qstrdup( programName().utf8());
00279 }
00280 
00281 QImage
00282 KAboutData::programLogo() const
00283 {
00284     return d->programLogo ? (*d->programLogo) : QImage();
00285 }
00286 
00287 void
00288 KAboutData::setProgramLogo(const QImage& image)
00289 {
00290     if (!d->programLogo)
00291        d->programLogo = new QImage( image );
00292     else
00293        *d->programLogo = image;
00294 }
00295 
00296 QString
00297 KAboutData::version() const
00298 {
00299    return QString::fromLatin1(mVersion);
00300 }
00301 
00302 QString
00303 KAboutData::shortDescription() const
00304 {
00305    if (mShortDescription && *mShortDescription)
00306       return i18n(mShortDescription);
00307    else
00308       return QString::null;
00309 }
00310 
00311 QString
00312 KAboutData::homepage() const
00313 {
00314    return QString::fromLatin1(mHomepageAddress);
00315 }
00316 
00317 QString
00318 KAboutData::bugAddress() const
00319 {
00320    return QString::fromLatin1(mBugEmailAddress);
00321 }
00322 
00323 const QValueList<KAboutPerson>
00324 KAboutData::authors() const
00325 {
00326    return mAuthorList;
00327 }
00328 
00329 const QValueList<KAboutPerson>
00330 KAboutData::credits() const
00331 {
00332    return mCreditList;
00333 }
00334 
00335 const QValueList<KAboutTranslator>
00336 KAboutData::translators() const
00337 {
00338     QValueList<KAboutTranslator> personList;
00339 
00340     if(d->translatorName == 0)
00341         return personList;
00342 
00343     QStringList nameList;
00344     QStringList emailList;
00345 
00346     QString names = i18n(d->translatorName);
00347     if(names != QString::fromUtf8(d->translatorName))
00348     {
00349         nameList = QStringList::split(',',names);
00350     }
00351 
00352 
00353     if(d->translatorEmail)
00354     {
00355         QString emails = i18n(d->translatorEmail);
00356 
00357         if(emails != QString::fromUtf8(d->translatorEmail))
00358         {
00359             emailList = QStringList::split(',',emails,true);
00360         }
00361     }
00362 
00363 
00364     QStringList::Iterator nit;
00365     QStringList::Iterator eit=emailList.begin();
00366 
00367     for(nit = nameList.begin(); nit != nameList.end(); ++nit)
00368     {
00369         QString email;
00370         if(eit != emailList.end())
00371         {
00372             email=*eit;
00373             ++eit;
00374         }
00375 
00376         QString name=*nit;
00377 
00378         personList.append(KAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace()));
00379     }
00380 
00381     return personList;
00382 }
00383 
00384 QString
00385 KAboutData::aboutTranslationTeam()
00386 {
00387     return i18n("replace this with information about your translation team",
00388             "<p>KDE is translated into many languages thanks to the work "
00389             "of the translation teams all over the world.</p>"
00390             "<p>For more information on KDE internationalization "
00391             "visit <a href=\"http://l10n.kde.org\">http://l10n.kde.org</a></p>"
00392             );
00393 }
00394 
00395 QString
00396 KAboutData::otherText() const
00397 {
00398    if (mOtherText && *mOtherText)
00399       return i18n(mOtherText);
00400    else
00401       return QString::null;
00402 }
00403 
00404 
00405 QString
00406 KAboutData::license() const
00407 {
00408   QString result;
00409   if (!copyrightStatement().isEmpty())
00410     result = copyrightStatement() + "\n\n";
00411 
00412   QString l;
00413   QString f;
00414   switch ( mLicenseKey )
00415   {
00416     case License_File:
00417        f = QFile::decodeName(mLicenseText);
00418        break;
00419     case License_GPL_V2:
00420        l = "GPL v2";
00421        f = locate("data", "LICENSES/GPL_V2");
00422        break;
00423     case License_LGPL_V2:
00424        l = "LGPL v2";
00425        f = locate("data", "LICENSES/LGPL_V2");
00426        break;
00427     case License_BSD:
00428        l = "BSD License";
00429        f = locate("data", "LICENSES/BSD");
00430        break;
00431     case License_Artistic:
00432        l = "Artistic License";
00433        f = locate("data", "LICENSES/ARTISTIC");
00434        break;
00435     case License_QPL_V1_0:
00436        l = "QPL v1.0";
00437        f = locate("data", "LICENSES/QPL_V1.0");
00438        break;
00439     case License_Custom:
00440        if (mLicenseText && *mLicenseText)
00441           return( i18n(mLicenseText) );
00442        // fall through
00443     default:
00444        result += i18n("No licensing terms for this program have been specified.\n"
00445                    "Please check the documentation or the source for any\n"
00446                    "licensing terms.\n");
00447        return result;
00448       }
00449 
00450   if (!l.isEmpty())
00451      result += i18n("This program is distributed under the terms of the %1.").arg( l );
00452 
00453   if (!f.isEmpty())
00454   {
00455      QFile file(f);
00456      if (file.open(IO_ReadOnly))
00457      {
00458         result += '\n';
00459         result += '\n';
00460         QTextStream str(&file);
00461         result += str.read();
00462      }
00463   }
00464 
00465   return result;
00466 }
00467 
00468 QString
00469 KAboutData::copyrightStatement() const
00470 {
00471   if (mCopyrightStatement && *mCopyrightStatement)
00472      return i18n(mCopyrightStatement);
00473   else
00474      return QString::null;
00475 }
00476 
00477 QString
00478 KAboutData::customAuthorPlainText() const
00479 {
00480   return d->customAuthorPlainText;
00481 }
00482 
00483 QString
00484 KAboutData::customAuthorRichText() const
00485 {
00486   return d->customAuthorRichText;
00487 }
00488 
00489 bool
00490 KAboutData::customAuthorTextEnabled() const
00491 {
00492   return d->customAuthorTextEnabled;
00493 }
00494     
00495 void
00496 KAboutData::setCustomAuthorText(const QString &plainText, const QString &richText)
00497 {
00498   d->customAuthorPlainText = plainText;
00499   d->customAuthorRichText = richText;
00500 
00501   d->customAuthorTextEnabled = true;
00502 }
00503     
00504 void
00505 KAboutData::unsetCustomAuthorText()
00506 {
00507   d->customAuthorPlainText = QString::null;
00508   d->customAuthorRichText = QString::null;
00509 
00510   d->customAuthorTextEnabled = false;
00511 }
00512 

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal