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