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 <tqfile.h> 00026 #include <tqtextstream.h> 00027 00028 TQString 00029 KAboutPerson::name() const 00030 { 00031 return TQString::fromUtf8(mName); 00032 } 00033 00034 TQString 00035 KAboutPerson::task() const 00036 { 00037 if (mTask && *mTask) 00038 return i18n(mTask); 00039 else 00040 return TQString::null; 00041 } 00042 00043 TQString 00044 KAboutPerson::emailAddress() const 00045 { 00046 return TQString::fromUtf8(mEmailAddress); 00047 } 00048 00049 00050 TQString 00051 KAboutPerson::webAddress() const 00052 { 00053 return TQString::fromUtf8(mWebAddress); 00054 } 00055 00056 00057 KAboutTranslator::KAboutTranslator(const TQString & name, 00058 const TQString & emailAddress) 00059 { 00060 mName=name; 00061 mEmail=emailAddress; 00062 } 00063 00064 TQString KAboutTranslator::name() const 00065 { 00066 return mName; 00067 } 00068 00069 TQString 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 TQImage* programLogo; 00094 TQString customAuthorPlainText, customAuthorRichText; 00095 bool customAuthorTextEnabled; 00096 const char *mTranslatedProgramName; 00097 }; 00098 00099 const char *KAboutData::defaultBugTracker = "http://bugs.trinitydesktop.org"; 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!=0)?bugsEmailAddress:defaultBugTracker ), 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 TQString &file ) 00170 { 00171 mLicenseText = qstrdup(TQFile::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 TQString 00252 KAboutData::programName() const 00253 { 00254 if (mProgramName && *mProgramName) 00255 return i18n(mProgramName); 00256 else 00257 return TQString::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 TQImage 00282 KAboutData::programLogo() const 00283 { 00284 return d->programLogo ? (*d->programLogo) : TQImage(); 00285 } 00286 00287 void 00288 KAboutData::setProgramLogo(const TQImage& image) 00289 { 00290 if (!d->programLogo) 00291 d->programLogo = new TQImage( image ); 00292 else 00293 *d->programLogo = image; 00294 } 00295 00296 TQString 00297 KAboutData::version() const 00298 { 00299 return TQString::fromLatin1(mVersion); 00300 } 00301 00302 TQString 00303 KAboutData::shortDescription() const 00304 { 00305 if (mShortDescription && *mShortDescription) 00306 return i18n(mShortDescription); 00307 else 00308 return TQString::null; 00309 } 00310 00311 TQString 00312 KAboutData::homepage() const 00313 { 00314 return TQString::fromLatin1(mHomepageAddress); 00315 } 00316 00317 TQString 00318 KAboutData::bugAddress() const 00319 { 00320 return TQString::fromLatin1(mBugEmailAddress); 00321 } 00322 00323 const TQValueList<KAboutPerson> 00324 KAboutData::authors() const 00325 { 00326 return mAuthorList; 00327 } 00328 00329 const TQValueList<KAboutPerson> 00330 KAboutData::credits() const 00331 { 00332 return mCreditList; 00333 } 00334 00335 const TQValueList<KAboutTranslator> 00336 KAboutData::translators() const 00337 { 00338 TQValueList<KAboutTranslator> personList; 00339 00340 if(d->translatorName == 0) 00341 return personList; 00342 00343 TQStringList nameList; 00344 TQStringList emailList; 00345 00346 TQString names = i18n(d->translatorName); 00347 if(names != TQString::fromUtf8(d->translatorName)) 00348 { 00349 nameList = TQStringList::split(',',names); 00350 } 00351 00352 00353 if(d->translatorEmail) 00354 { 00355 TQString emails = i18n(d->translatorEmail); 00356 00357 if(emails != TQString::fromUtf8(d->translatorEmail)) 00358 { 00359 emailList = TQStringList::split(',',emails,true); 00360 } 00361 } 00362 00363 00364 TQStringList::Iterator nit; 00365 TQStringList::Iterator eit=emailList.begin(); 00366 00367 for(nit = nameList.begin(); nit != nameList.end(); ++nit) 00368 { 00369 TQString email; 00370 if(eit != emailList.end()) 00371 { 00372 email=*eit; 00373 ++eit; 00374 } 00375 00376 TQString name=*nit; 00377 00378 personList.append(KAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace())); 00379 } 00380 00381 return personList; 00382 } 00383 00384 TQString 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 TQString 00396 KAboutData::otherText() const 00397 { 00398 if (mOtherText && *mOtherText) 00399 return i18n(mOtherText); 00400 else 00401 return TQString::null; 00402 } 00403 00404 00405 TQString 00406 KAboutData::license() const 00407 { 00408 TQString result; 00409 if (!copyrightStatement().isEmpty()) 00410 result = copyrightStatement() + "\n\n"; 00411 00412 TQString l; 00413 TQString f; 00414 switch ( mLicenseKey ) 00415 { 00416 case License_File: 00417 f = TQFile::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_GPL_V3: 00428 l = "GPL v3"; 00429 f = locate("data", "LICENSES/GPL_V3"); 00430 break; 00431 case License_LGPL_V3: 00432 l = "LGPL v3"; 00433 f = locate("data", "LICENSES/LGPL_V3"); 00434 break; 00435 case License_BSD: 00436 l = "BSD License"; 00437 f = locate("data", "LICENSES/BSD"); 00438 break; 00439 case License_Artistic: 00440 l = "Artistic License"; 00441 f = locate("data", "LICENSES/ARTISTIC"); 00442 break; 00443 case License_QPL_V1_0: 00444 l = "QPL v1.0"; 00445 f = locate("data", "LICENSES/QPL_V1.0"); 00446 break; 00447 case License_Custom: 00448 if (mLicenseText && *mLicenseText) 00449 return( i18n(mLicenseText) ); 00450 // fall through 00451 default: 00452 result += i18n("No licensing terms for this program have been specified.\n" 00453 "Please check the documentation or the source for any\n" 00454 "licensing terms.\n"); 00455 return result; 00456 } 00457 00458 if (!l.isEmpty()) 00459 result += i18n("This program is distributed under the terms of the %1.").arg( l ); 00460 00461 if (!f.isEmpty()) 00462 { 00463 TQFile file(f); 00464 if (file.open(IO_ReadOnly)) 00465 { 00466 result += '\n'; 00467 result += '\n'; 00468 TQTextStream str(&file); 00469 result += str.read(); 00470 } 00471 } 00472 00473 return result; 00474 } 00475 00476 TQString 00477 KAboutData::copyrightStatement() const 00478 { 00479 if (mCopyrightStatement && *mCopyrightStatement) 00480 return i18n(mCopyrightStatement); 00481 else 00482 return TQString::null; 00483 } 00484 00485 TQString 00486 KAboutData::customAuthorPlainText() const 00487 { 00488 return d->customAuthorPlainText; 00489 } 00490 00491 TQString 00492 KAboutData::customAuthorRichText() const 00493 { 00494 return d->customAuthorRichText; 00495 } 00496 00497 bool 00498 KAboutData::customAuthorTextEnabled() const 00499 { 00500 return d->customAuthorTextEnabled; 00501 } 00502 00503 void 00504 KAboutData::setCustomAuthorText(const TQString &plainText, const TQString &richText) 00505 { 00506 d->customAuthorPlainText = plainText; 00507 d->customAuthorRichText = richText; 00508 00509 d->customAuthorTextEnabled = true; 00510 } 00511 00512 void 00513 KAboutData::unsetCustomAuthorText() 00514 { 00515 d->customAuthorPlainText = TQString::null; 00516 d->customAuthorRichText = TQString::null; 00517 00518 d->customAuthorTextEnabled = false; 00519 } 00520