| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kaboutdata.cpp

    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., 59 Temple Place - Suite 330,
    00018  * Boston, MA 02111-1307, 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         {}
    00083     ~KAboutDataPrivate()
    00084         {
    00085              delete programLogo;
    00086         }
    00087     const char *translatorName;
    00088     const char *translatorEmail;
    00089     const char *productName;
    00090     QImage* programLogo;
    00091 };
    00092
    00093
    00094
    00095 KAboutData::KAboutData( const char *appName,
    00096                         const char *programName,
    00097                         const char *version,
    00098                         const char *shortDescription,
    00099             int licenseType,
    00100             const char *copyrightStatement,
    00101             const char *text,
    00102             const char *homePageAddress,
    00103             const char *bugsEmailAddress
    00104             ) :
    00105   mProgramName( programName ),
    00106   mVersion( version ),
    00107   mShortDescription( shortDescription ),
    00108   mLicenseKey( licenseType ),
    00109   mCopyrightStatement( copyrightStatement ),
    00110   mOtherText( text ),
    00111   mHomepageAddress( homePageAddress ),
    00112   mBugEmailAddress( bugsEmailAddress ),
    00113   mLicenseText (0)
    00114 {
    00115    d = new KAboutDataPrivate;
    00116
    00117    if( appName ) {
    00118      const char *p = strrchr(appName, '/');
    00119      if( p )
    00120      mAppName = p+1;
    00121      else
    00122      mAppName = appName;
    00123    } else
    00124      mAppName = 0;
    00125 }
    00126
    00127 KAboutData::~KAboutData()
    00128 {
    00129     if (mLicenseKey == License_File)
    00130         delete [] mLicenseText;
    00131     delete d;
    00132 }
    00133
    00134 void
    00135 KAboutData::addAuthor( const char *name, const char *task,
    00136             const char *emailAddress, const char *webAddress )
    00137 {
    00138   mAuthorList.append(KAboutPerson(name,task,emailAddress,webAddress));
    00139 }
    00140
    00141 void
    00142 KAboutData::addCredit( const char *name, const char *task,
    00143             const char *emailAddress, const char *webAddress )
    00144 {
    00145   mCreditList.append(KAboutPerson(name,task,emailAddress,webAddress));
    00146 }
    00147
    00148 void
    00149 KAboutData::setTranslator( const char *name, const char *emailAddress)
    00150 {
    00151   d->translatorName=name;
    00152   d->translatorEmail=emailAddress;
    00153 }
    00154
    00155 void
    00156 KAboutData::setLicenseText( const char *licenseText )
    00157 {
    00158   mLicenseText = licenseText;
    00159   mLicenseKey = License_Custom;
    00160 }
    00161
    00162 void
    00163 KAboutData::setLicenseTextFile( const QString &file )
    00164 {
    00165   mLicenseText = qstrdup(QFile::encodeName(file));
    00166   mLicenseKey = License_File;
    00167 }
    00168
    00169 void
    00170 KAboutData::setAppName( const char *appName )
    00171 {
    00172   mAppName = appName;
    00173 }
    00174
    00175 void
    00176 KAboutData::setProgramName( const char* programName )
    00177 {
    00178   mProgramName = programName;
    00179 }
    00180
    00181 void
    00182 KAboutData::setVersion( const char* version )
    00183 {
    00184   mVersion = version;
    00185 }
    00186
    00187 void
    00188 KAboutData::setShortDescription( const char *shortDescription )
    00189 {
    00190   mShortDescription = shortDescription;
    00191 }
    00192
    00193 void
    00194 KAboutData::setLicense( LicenseKey licenseKey)
    00195 {
    00196   mLicenseKey = licenseKey;
    00197 }
    00198
    00199 void
    00200 KAboutData::setCopyrightStatement( const char *copyrightStatement )
    00201 {
    00202   mCopyrightStatement = copyrightStatement;
    00203 }
    00204
    00205 void
    00206 KAboutData::setOtherText( const char *otherText )
    00207 {
    00208   mOtherText = otherText;
    00209 }
    00210
    00211 void
    00212 KAboutData::setHomepage( const char *homepage )
    00213 {
    00214   mHomepageAddress = homepage;
    00215 }
    00216
    00217 void
    00218 KAboutData::setBugAddress( const char *bugAddress )
    00219 {
    00220   mBugEmailAddress = bugAddress;
    00221 }
    00222
    00223 void
    00224 KAboutData::setProductName( const char *productName )
    00225 {
    00226   d->productName = productName;
    00227 }
    00228
    00229 const char *
    00230 KAboutData::appName() const
    00231 {
    00232    return mAppName;
    00233 }
    00234
    00235 const char *
    00236 KAboutData::productName() const
    00237 {
    00238    if (d->productName)
    00239       return d->productName;
    00240    else
    00241       return appName();
    00242 }
    00243
    00244 QString
    00245 KAboutData::programName() const
    00246 {
    00247    if (mProgramName && *mProgramName)
    00248       return i18n(mProgramName);
    00249    else
    00250       return QString::null;
    00251 }
    00252
    00253 QImage
    00254 KAboutData::programLogo() const
    00255 {
    00256     return d->programLogo ? (*d->programLogo) : QImage();
    00257 }
    00258
    00259 void
    00260 KAboutData::setProgramLogo(const QImage& image)
    00261 {
    00262     if (!d->programLogo)
    00263        d->programLogo = new QImage( image );
    00264     else
    00265        *d->programLogo = image;
    00266 }
    00267
    00268 QString
    00269 KAboutData::version() const
    00270 {
    00271    return QString::fromLatin1(mVersion);
    00272 }
    00273
    00274 QString
    00275 KAboutData::shortDescription() const
    00276 {
    00277    if (mShortDescription && *mShortDescription)
    00278       return i18n(mShortDescription);
    00279    else
    00280       return QString::null;
    00281 }
    00282
    00283 QString
    00284 KAboutData::homepage() const
    00285 {
    00286    return QString::fromLatin1(mHomepageAddress);
    00287 }
    00288
    00289 QString
    00290 KAboutData::bugAddress() const
    00291 {
    00292    return QString::fromLatin1(mBugEmailAddress);
    00293 }
    00294
    00295 const QValueList<KAboutPerson>
    00296 KAboutData::authors() const
    00297 {
    00298    return mAuthorList;
    00299 }
    00300
    00301 const QValueList<KAboutPerson>
    00302 KAboutData::credits() const
    00303 {
    00304    return mCreditList;
    00305 }
    00306
    00307 const QValueList<KAboutTranslator>
    00308 KAboutData::translators() const
    00309 {
    00310     QValueList<KAboutTranslator> personList;
    00311
    00312     if(d->translatorName == 0)
    00313         return personList;
    00314
    00315     QStringList nameList;
    00316     QStringList emailList;
    00317
    00318     QString names = i18n(d->translatorName);
    00319     if(names != QString::fromUtf8(d->translatorName))
    00320     {
    00321         nameList = QStringList::split(',',names);
    00322     }
    00323
    00324
    00325     if(d->translatorEmail)
    00326     {
    00327         QString emails = i18n(d->translatorEmail);
    00328
    00329         if(emails != QString::fromUtf8(d->translatorEmail))
    00330         {
    00331             emailList = QStringList::split(',',emails,true);
    00332         }
    00333     }
    00334
    00335
    00336     QStringList::Iterator nit;
    00337     QStringList::Iterator eit=emailList.begin();
    00338
    00339     for(nit = nameList.begin(); nit != nameList.end(); ++nit)
    00340     {
    00341         QString email;
    00342         if(eit != emailList.end())
    00343         {
    00344             email=*eit;
    00345             ++eit;
    00346         }
    00347
    00348         QString name=*nit;
    00349
    00350         personList.append(KAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace()));
    00351     }
    00352
    00353     return personList;
    00354 }
    00355
    00356 QString
    00357 KAboutData::aboutTranslationTeam()
    00358 {
    00359     return i18n("replace this with information about your translation team",
    00360             "<p>KDE is translated into many languages thanks to the work "
    00361             "of the translation teams all over the world.</p>"
    00362             "<p>For more information on KDE internationalization "
    00363             "visit http://i18n.kde.org</p>");
    00364 }
    00365
    00366 QString
    00367 KAboutData::otherText() const
    00368 {
    00369    if (mOtherText && *mOtherText)
    00370       return i18n(mOtherText);
    00371    else
    00372       return QString::null;
    00373 }
    00374
    00375
    00376 QString
    00377 KAboutData::license() const
    00378 {
    00379   QString result;
    00380   if (!copyrightStatement().isEmpty())
    00381     result = copyrightStatement() + "\n\n";
    00382
    00383   QString l;
    00384   QString f;
    00385   switch ( mLicenseKey )
    00386   {
    00387     case License_File:
    00388        f = QFile::decodeName(mLicenseText);
    00389        break;
    00390     case License_GPL_V2:
    00391        l = "GPL v2";
    00392        f = locate("data", "LICENSES/GPL_V2");
    00393        break;
    00394     case License_LGPL_V2:
    00395        l = "LGPL v2";
    00396        f = locate("data", "LICENSES/LGPL_V2");
    00397        break;
    00398     case License_BSD:
    00399        l = "BSD License";
    00400        f = locate("data", "LICENSES/BSD");
    00401        break;
    00402     case License_Artistic:
    00403        l = "Artistic License";
    00404        f = locate("data", "LICENSES/ARTISTIC");
    00405        break;
    00406     case License_QPL_V1_0:
    00407        l = "QPL v1.0";
    00408        f = locate("data", "LICENSES/QPL_V1.0");
    00409        break;
    00410     case License_Custom:
    00411        if (mLicenseText && *mLicenseText)
    00412           return( i18n(mLicenseText) );
    00413        // fall through
    00414     default:
    00415        result += i18n("No licensing terms for this program have been specified.\n"
    00416                    "Please check the documentation or the source for any\n"
    00417                    "licensing terms.\n");
    00418        return result;
    00419       }
    00420
    00421   if (!l.isEmpty())
    00422      result += i18n("This program is distributed under the terms of the %1.").arg( l );
    00423
    00424   if (!f.isEmpty())
    00425   {
    00426      QFile file(f);
    00427      if (file.open(IO_ReadOnly))
    00428      {
    00429         result += '\n';
    00430         result += '\n';
    00431         QTextStream str(&file);
    00432         result += str.read();
    00433      }
    00434   }
    00435
    00436   return result;
    00437 }
    00438
    00439 QString
    00440 KAboutData::copyrightStatement() const
    00441 {
    00442   if (mCopyrightStatement && *mCopyrightStatement)
    00443      return i18n(mCopyrightStatement);
    00444   else
    00445      return QString::null;
    00446 }

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:00 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003