kdecore Library API Documentation

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 {}; 00081 const char *translatorName; 00082 const char *translatorEmail; 00083 const char *productName; 00084 }; 00085 00086 00087 00088 KAboutData::KAboutData( const char *appName, 00089 const char *programName, 00090 const char *version, 00091 const char *shortDescription, 00092 int licenseType, 00093 const char *copyrightStatement, 00094 const char *text, 00095 const char *homePageAddress, 00096 const char *bugsEmailAddress 00097 ) : 00098 mProgramName( programName ), 00099 mVersion( version ), 00100 mShortDescription( shortDescription ), 00101 mLicenseKey( licenseType ), 00102 mCopyrightStatement( copyrightStatement ), 00103 mOtherText( text ), 00104 mHomepageAddress( homePageAddress ), 00105 mBugEmailAddress( bugsEmailAddress ) 00106 { 00107 d = new KAboutDataPrivate; 00108 d->productName = 0; 00109 00110 if( appName ) { 00111 const char *p = strrchr(appName, '/'); 00112 if( p ) 00113 mAppName = p+1; 00114 else 00115 mAppName = appName; 00116 } else 00117 mAppName = 0; 00118 } 00119 00120 KAboutData::~KAboutData() 00121 { 00122 delete d; 00123 } 00124 00125 void 00126 KAboutData::addAuthor( const char *name, const char *task, 00127 const char *emailAddress, const char *webAddress ) 00128 { 00129 mAuthorList.append(KAboutPerson(name,task,emailAddress,webAddress)); 00130 } 00131 00132 void 00133 KAboutData::addCredit( const char *name, const char *task, 00134 const char *emailAddress, const char *webAddress ) 00135 { 00136 mCreditList.append(KAboutPerson(name,task,emailAddress,webAddress)); 00137 } 00138 00139 void 00140 KAboutData::setTranslator( const char *name, const char *emailAddress) 00141 { 00142 d->translatorName=name; 00143 d->translatorEmail=emailAddress; 00144 } 00145 00146 void 00147 KAboutData::setLicenseText( const char *licenseText ) 00148 { 00149 mLicenseText = licenseText; 00150 mLicenseKey = License_Custom; 00151 } 00152 00153 void 00154 KAboutData::setLicenseTextFile( const QString &file ) 00155 { 00156 mLicenseText = qstrdup(QFile::encodeName(file)); 00157 mLicenseKey = License_File; 00158 } 00159 00160 void 00161 KAboutData::setProductName( const char *productName ) 00162 { 00163 d->productName = productName; 00164 } 00165 00166 const char * 00167 KAboutData::appName() const 00168 { 00169 return mAppName; 00170 } 00171 00172 const char * 00173 KAboutData::productName() const 00174 { 00175 if (d->productName) 00176 return d->productName; 00177 else 00178 return appName(); 00179 } 00180 00181 QString 00182 KAboutData::programName() const 00183 { 00184 if (mProgramName && *mProgramName) 00185 return i18n(mProgramName); 00186 else 00187 return QString::null; 00188 } 00189 00190 QString 00191 KAboutData::version() const 00192 { 00193 return QString::fromLatin1(mVersion); 00194 } 00195 00196 QString 00197 KAboutData::shortDescription() const 00198 { 00199 if (mShortDescription && *mShortDescription) 00200 return i18n(mShortDescription); 00201 else 00202 return QString::null; 00203 } 00204 00205 QString 00206 KAboutData::homepage() const 00207 { 00208 return QString::fromLatin1(mHomepageAddress); 00209 } 00210 00211 QString 00212 KAboutData::bugAddress() const 00213 { 00214 return QString::fromLatin1(mBugEmailAddress); 00215 } 00216 00217 const QValueList<KAboutPerson> 00218 KAboutData::authors() const 00219 { 00220 return mAuthorList; 00221 } 00222 00223 const QValueList<KAboutPerson> 00224 KAboutData::credits() const 00225 { 00226 return mCreditList; 00227 } 00228 00229 const QValueList<KAboutTranslator> 00230 KAboutData::translators() const 00231 { 00232 QValueList<KAboutTranslator> personList; 00233 00234 if(d->translatorName == 0) 00235 return personList; 00236 00237 QStringList nameList; 00238 QStringList emailList; 00239 00240 QString names = i18n(d->translatorName); 00241 if(names != QString::fromUtf8(d->translatorName)) 00242 { 00243 nameList = QStringList::split(',',names); 00244 } 00245 00246 00247 if(d->translatorEmail) 00248 { 00249 QString emails = i18n(d->translatorEmail); 00250 00251 if(emails != QString::fromUtf8(d->translatorEmail)) 00252 { 00253 emailList = QStringList::split(',',emails,true); 00254 } 00255 } 00256 00257 00258 QStringList::Iterator nit; 00259 QStringList::Iterator eit=emailList.begin(); 00260 00261 for(nit = nameList.begin(); nit != nameList.end(); ++nit) 00262 { 00263 QString email; 00264 if(eit != emailList.end()) 00265 { 00266 email=*eit; 00267 ++eit; 00268 } 00269 00270 QString name=*nit; 00271 00272 personList.append(KAboutTranslator( name, email)); 00273 } 00274 00275 return personList; 00276 } 00277 00278 QString 00279 KAboutData::aboutTranslationTeam() 00280 { 00281 return i18n("replace this with information about your translation team", 00282 "<p>KDE is translated into many languages thanks to the work " 00283 "of the translation teams all over the world.</p>" 00284 "<p>For more information on KDE internationalization " 00285 "visit http://i18n.kde.org</p>"); 00286 } 00287 00288 QString 00289 KAboutData::otherText() const 00290 { 00291 if (mOtherText && *mOtherText) 00292 return i18n(mOtherText); 00293 else 00294 return QString::null; 00295 } 00296 00297 00298 QString 00299 KAboutData::license() const 00300 { 00301 QString result = copyrightStatement() + "\n\n"; 00302 QString l; 00303 QString f; 00304 switch ( mLicenseKey ) 00305 { 00306 case License_File: 00307 f = QFile::decodeName(mLicenseText); 00308 break; 00309 case License_GPL_V2: 00310 l = "GPL v2"; 00311 f = locate("data", "LICENSES/GPL_V2"); 00312 break; 00313 case License_LGPL_V2: 00314 l = "LGPL v2"; 00315 f = locate("data", "LICENSES/LGPL_V2"); 00316 break; 00317 case License_BSD: 00318 l = "BSD License"; 00319 f = locate("data", "LICENSES/BSD"); 00320 break; 00321 case License_Artistic: 00322 l = "Artistic License"; 00323 f = locate("data", "LICENSES/ARTISTIC"); 00324 break; 00325 case License_QPL_V1_0: 00326 l = "QPL v1.0"; 00327 f = locate("data", "LICENSES/QPL_V1.0"); 00328 break; 00329 case License_Custom: 00330 if (mLicenseText && *mLicenseText) 00331 return( i18n(mLicenseText) ); 00332 // fall through 00333 default: 00334 result += i18n("No licensing terms for this program have been specified.\n" 00335 "Please check the documentation or the source for any\n" 00336 "licensing terms.\n"); 00337 return result; 00338 } 00339 00340 if (!l.isEmpty()) 00341 result += i18n("This program is distributed under the terms of the %1.").arg( l ); 00342 00343 if (!f.isEmpty()) 00344 { 00345 QFile file(f); 00346 if (file.open(IO_ReadOnly)) 00347 { 00348 result += '\n'; 00349 result += '\n'; 00350 QTextStream str(&file); 00351 result += str.read(); 00352 } 00353 } 00354 00355 return result; 00356 } 00357 00358 QString 00359 KAboutData::copyrightStatement() const 00360 { 00361 if (mCopyrightStatement && *mCopyrightStatement) 00362 return i18n(mCopyrightStatement); 00363 else 00364 return QString::null; 00365 }
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 20 09:48:24 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003