tdeaboutdata.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 <tdeaboutdata.h> 00024 #include <kstandarddirs.h> 00025 #include <tqfile.h> 00026 #include <tqtextstream.h> 00027 00028 TQString 00029 TDEAboutPerson::name() const 00030 { 00031 return TQString::fromUtf8(mName); 00032 } 00033 00034 TQString 00035 TDEAboutPerson::task() const 00036 { 00037 if (mTask && *mTask) 00038 return i18n(mTask); 00039 else 00040 return TQString::null; 00041 } 00042 00043 TQString 00044 TDEAboutPerson::emailAddress() const 00045 { 00046 return TQString::fromUtf8(mEmailAddress); 00047 } 00048 00049 00050 TQString 00051 TDEAboutPerson::webAddress() const 00052 { 00053 return TQString::fromUtf8(mWebAddress); 00054 } 00055 00056 00057 TDEAboutTranslator::TDEAboutTranslator(const TQString & name, 00058 const TQString & emailAddress) 00059 { 00060 mName=name; 00061 mEmail=emailAddress; 00062 } 00063 00064 TQString TDEAboutTranslator::name() const 00065 { 00066 return mName; 00067 } 00068 00069 TQString TDEAboutTranslator::emailAddress() const 00070 { 00071 return mEmail; 00072 } 00073 00074 class TDEAboutDataPrivate 00075 { 00076 public: 00077 TDEAboutDataPrivate() 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 ~TDEAboutDataPrivate() 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 *TDEAboutData::defaultBugTracker = "http://bugs.trinitydesktop.org"; 00100 00101 TDEAboutData::TDEAboutData( 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 TDEAboutDataPrivate; 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 TDEAboutData::~TDEAboutData() 00134 { 00135 if (mLicenseKey == License_File) 00136 delete [] mLicenseText; 00137 delete d; 00138 } 00139 00140 void 00141 TDEAboutData::addAuthor( const char *name, const char *task, 00142 const char *emailAddress, const char *webAddress ) 00143 { 00144 mAuthorList.append(TDEAboutPerson(name,task,emailAddress,webAddress)); 00145 } 00146 00147 void 00148 TDEAboutData::addCredit( const char *name, const char *task, 00149 const char *emailAddress, const char *webAddress ) 00150 { 00151 mCreditList.append(TDEAboutPerson(name,task,emailAddress,webAddress)); 00152 } 00153 00154 void 00155 TDEAboutData::setTranslator( const char *name, const char *emailAddress) 00156 { 00157 d->translatorName=name; 00158 d->translatorEmail=emailAddress; 00159 } 00160 00161 void 00162 TDEAboutData::setLicenseText( const char *licenseText ) 00163 { 00164 mLicenseText = licenseText; 00165 mLicenseKey = License_Custom; 00166 } 00167 00168 void 00169 TDEAboutData::setLicenseTextFile( const TQString &file ) 00170 { 00171 mLicenseText = tqstrdup(TQFile::encodeName(file)); 00172 mLicenseKey = License_File; 00173 } 00174 00175 void 00176 TDEAboutData::setAppName( const char *appName ) 00177 { 00178 mAppName = appName; 00179 } 00180 00181 void 00182 TDEAboutData::setProgramName( const char* programName ) 00183 { 00184 mProgramName = programName; 00185 translateInternalProgramName(); 00186 } 00187 00188 void 00189 TDEAboutData::setVersion( const char* version ) 00190 { 00191 mVersion = version; 00192 } 00193 00194 void 00195 TDEAboutData::setShortDescription( const char *shortDescription ) 00196 { 00197 mShortDescription = shortDescription; 00198 } 00199 00200 void 00201 TDEAboutData::setLicense( LicenseKey licenseKey) 00202 { 00203 mLicenseKey = licenseKey; 00204 } 00205 00206 void 00207 TDEAboutData::setCopyrightStatement( const char *copyrightStatement ) 00208 { 00209 mCopyrightStatement = copyrightStatement; 00210 } 00211 00212 void 00213 TDEAboutData::setOtherText( const char *otherText ) 00214 { 00215 mOtherText = otherText; 00216 } 00217 00218 void 00219 TDEAboutData::setHomepage( const char *homepage ) 00220 { 00221 mHomepageAddress = homepage; 00222 } 00223 00224 void 00225 TDEAboutData::setBugAddress( const char *bugAddress ) 00226 { 00227 mBugEmailAddress = bugAddress; 00228 } 00229 00230 void 00231 TDEAboutData::setProductName( const char *productName ) 00232 { 00233 d->productName = productName; 00234 } 00235 00236 const char * 00237 TDEAboutData::appName() const 00238 { 00239 return mAppName; 00240 } 00241 00242 const char * 00243 TDEAboutData::productName() const 00244 { 00245 if (d->productName) 00246 return d->productName; 00247 else 00248 return appName(); 00249 } 00250 00251 TQString 00252 TDEAboutData::programName() const 00253 { 00254 if (mProgramName && *mProgramName) 00255 return i18n(mProgramName); 00256 else 00257 return TQString::null; 00258 } 00259 00260 const char* 00261 TDEAboutData::internalProgramName() const 00262 { 00263 if (d->mTranslatedProgramName) 00264 return d->mTranslatedProgramName; 00265 else 00266 return mProgramName; 00267 } 00268 00269 // TDECrash should call as few things as possible and should avoid e.g. malloc() 00270 // because it may deadlock. Since i18n() needs it, when TDELocale is available 00271 // the i18n() call will be done here in advance. 00272 void 00273 TDEAboutData::translateInternalProgramName() const 00274 { 00275 delete[] d->mTranslatedProgramName; 00276 d->mTranslatedProgramName = 0; 00277 if( TDEGlobal::locale() ) 00278 d->mTranslatedProgramName = tqstrdup( programName().utf8()); 00279 } 00280 00281 TQImage 00282 TDEAboutData::programLogo() const 00283 { 00284 return d->programLogo ? (*d->programLogo) : TQImage(); 00285 } 00286 00287 void 00288 TDEAboutData::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 TDEAboutData::version() const 00298 { 00299 return TQString::fromLatin1(mVersion); 00300 } 00301 00302 TQString 00303 TDEAboutData::shortDescription() const 00304 { 00305 if (mShortDescription && *mShortDescription) 00306 return i18n(mShortDescription); 00307 else 00308 return TQString::null; 00309 } 00310 00311 TQString 00312 TDEAboutData::homepage() const 00313 { 00314 return TQString::fromLatin1(mHomepageAddress); 00315 } 00316 00317 TQString 00318 TDEAboutData::bugAddress() const 00319 { 00320 return TQString::fromLatin1(mBugEmailAddress); 00321 } 00322 00323 const TQValueList<TDEAboutPerson> 00324 TDEAboutData::authors() const 00325 { 00326 return mAuthorList; 00327 } 00328 00329 const TQValueList<TDEAboutPerson> 00330 TDEAboutData::credits() const 00331 { 00332 return mCreditList; 00333 } 00334 00335 const TQValueList<TDEAboutTranslator> 00336 TDEAboutData::translators() const 00337 { 00338 TQValueList<TDEAboutTranslator> 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(TDEAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace())); 00379 } 00380 00381 return personList; 00382 } 00383 00384 TQString 00385 TDEAboutData::aboutTranslationTeam() 00386 { 00387 return i18n("replace this with information about your translation team", 00388 "<p>TDE 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 TDE internationalization " 00391 "visit the <a href=\"https://wiki.trinitydesktop.org/" 00392 "TDE_Weblate_Translation_Workspace\">TDE Weblate " 00393 "Translation Workspace (TWTW)</a></p>" 00394 ); 00395 } 00396 00397 TQString 00398 TDEAboutData::otherText() const 00399 { 00400 if (mOtherText && *mOtherText) 00401 return i18n(mOtherText); 00402 else 00403 return TQString::null; 00404 } 00405 00406 00407 TQString 00408 TDEAboutData::license() const 00409 { 00410 TQString result; 00411 if (!copyrightStatement().isEmpty()) 00412 result = copyrightStatement() + "\n\n"; 00413 00414 TQString l; 00415 TQString f; 00416 switch ( mLicenseKey ) 00417 { 00418 case License_File: 00419 f = TQFile::decodeName(mLicenseText); 00420 break; 00421 case License_GPL_V2: 00422 l = "GPL v2"; 00423 f = locate("data", "LICENSES/GPL_V2"); 00424 break; 00425 case License_LGPL_V2: 00426 l = "LGPL v2"; 00427 f = locate("data", "LICENSES/LGPL_V2"); 00428 break; 00429 case License_GPL_V3: 00430 l = "GPL v3"; 00431 f = locate("data", "LICENSES/GPL_V3"); 00432 break; 00433 case License_LGPL_V3: 00434 l = "LGPL v3"; 00435 f = locate("data", "LICENSES/LGPL_V3"); 00436 break; 00437 case License_BSD: 00438 l = "BSD License"; 00439 f = locate("data", "LICENSES/BSD"); 00440 break; 00441 case License_Artistic: 00442 l = "Artistic License"; 00443 f = locate("data", "LICENSES/ARTISTIC"); 00444 break; 00445 case License_QPL_V1_0: 00446 l = "QPL v1.0"; 00447 f = locate("data", "LICENSES/QPL_V1.0"); 00448 break; 00449 case License_Custom: 00450 if (mLicenseText && *mLicenseText) 00451 return( i18n(mLicenseText) ); 00452 // fall through 00453 default: 00454 result += i18n("No licensing terms for this program have been specified.\n" 00455 "Please check the documentation or the source for any\n" 00456 "licensing terms.\n"); 00457 return result; 00458 } 00459 00460 if (!l.isEmpty()) 00461 result += i18n("This program is distributed under the terms of the %1.").arg( l ); 00462 00463 if (!f.isEmpty()) 00464 { 00465 TQFile file(f); 00466 if (file.open(IO_ReadOnly)) 00467 { 00468 result += '\n'; 00469 result += '\n'; 00470 TQTextStream str(&file); 00471 result += str.read(); 00472 } 00473 } 00474 00475 return result; 00476 } 00477 00478 TQString 00479 TDEAboutData::copyrightStatement() const 00480 { 00481 if (mCopyrightStatement && *mCopyrightStatement) 00482 return i18n(mCopyrightStatement); 00483 else 00484 return TQString::null; 00485 } 00486 00487 TQString 00488 TDEAboutData::customAuthorPlainText() const 00489 { 00490 return d->customAuthorPlainText; 00491 } 00492 00493 TQString 00494 TDEAboutData::customAuthorRichText() const 00495 { 00496 return d->customAuthorRichText; 00497 } 00498 00499 bool 00500 TDEAboutData::customAuthorTextEnabled() const 00501 { 00502 return d->customAuthorTextEnabled; 00503 } 00504 00505 void 00506 TDEAboutData::setCustomAuthorText(const TQString &plainText, const TQString &richText) 00507 { 00508 d->customAuthorPlainText = plainText; 00509 d->customAuthorRichText = richText; 00510 00511 d->customAuthorTextEnabled = true; 00512 } 00513 00514 void 00515 TDEAboutData::unsetCustomAuthorText() 00516 { 00517 d->customAuthorPlainText = TQString::null; 00518 d->customAuthorRichText = TQString::null; 00519 00520 d->customAuthorTextEnabled = false; 00521 } 00522