00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00270
00271
00272 void
00273 KAboutData::translateInternalProgramName() const
00274 {
00275 delete[] d->mTranslatedProgramName;
00276 d->mTranslatedProgramName = 0;
00277 if( KGlobal::locale())
00278 d->mTranslatedProgramName = qstrdup( i18n( mProgramName ).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 http://i18n.kde.org</p>");
00392 }
00393
00394 QString
00395 KAboutData::otherText() const
00396 {
00397 if (mOtherText && *mOtherText)
00398 return i18n(mOtherText);
00399 else
00400 return QString::null;
00401 }
00402
00403
00404 QString
00405 KAboutData::license() const
00406 {
00407 QString result;
00408 if (!copyrightStatement().isEmpty())
00409 result = copyrightStatement() + "\n\n";
00410
00411 QString l;
00412 QString f;
00413 switch ( mLicenseKey )
00414 {
00415 case License_File:
00416 f = QFile::decodeName(mLicenseText);
00417 break;
00418 case License_GPL_V2:
00419 l = "GPL v2";
00420 f = locate("data", "LICENSES/GPL_V2");
00421 break;
00422 case License_LGPL_V2:
00423 l = "LGPL v2";
00424 f = locate("data", "LICENSES/LGPL_V2");
00425 break;
00426 case License_BSD:
00427 l = "BSD License";
00428 f = locate("data", "LICENSES/BSD");
00429 break;
00430 case License_Artistic:
00431 l = "Artistic License";
00432 f = locate("data", "LICENSES/ARTISTIC");
00433 break;
00434 case License_QPL_V1_0:
00435 l = "QPL v1.0";
00436 f = locate("data", "LICENSES/QPL_V1.0");
00437 break;
00438 case License_Custom:
00439 if (mLicenseText && *mLicenseText)
00440 return( i18n(mLicenseText) );
00441
00442 default:
00443 result += i18n("No licensing terms for this program have been specified.\n"
00444 "Please check the documentation or the source for any\n"
00445 "licensing terms.\n");
00446 return result;
00447 }
00448
00449 if (!l.isEmpty())
00450 result += i18n("This program is distributed under the terms of the %1.").arg( l );
00451
00452 if (!f.isEmpty())
00453 {
00454 QFile file(f);
00455 if (file.open(IO_ReadOnly))
00456 {
00457 result += '\n';
00458 result += '\n';
00459 QTextStream str(&file);
00460 result += str.read();
00461 }
00462 }
00463
00464 return result;
00465 }
00466
00467 QString
00468 KAboutData::copyrightStatement() const
00469 {
00470 if (mCopyrightStatement && *mCopyrightStatement)
00471 return i18n(mCopyrightStatement);
00472 else
00473 return QString::null;
00474 }
00475
00476 QString
00477 KAboutData::customAuthorPlainText() const
00478 {
00479 return d->customAuthorPlainText;
00480 }
00481
00482 QString
00483 KAboutData::customAuthorRichText() const
00484 {
00485 return d->customAuthorRichText;
00486 }
00487
00488 bool
00489 KAboutData::customAuthorTextEnabled() const
00490 {
00491 return d->customAuthorTextEnabled;
00492 }
00493
00494 void
00495 KAboutData::setCustomAuthorText(const QString &plainText, const QString &richText)
00496 {
00497 d->customAuthorPlainText = plainText;
00498 d->customAuthorRichText = richText;
00499
00500 d->customAuthorTextEnabled = true;
00501 }
00502
00503 void
00504 KAboutData::unsetCustomAuthorText()
00505 {
00506 d->customAuthorPlainText = QString::null;
00507 d->customAuthorRichText = QString::null;
00508
00509 d->customAuthorTextEnabled = false;
00510 }
00511