00001 #include "aboutdata.h"
00002
00003 #include <QString>
00004
00005 #include <QFile>
00006 #include <QTextIStream>
00007 #include <QSharedData>
00008 #include <QVariant>
00009 #include <QList>
00010 #include <QHash>
00011 #include <QtCore>
00012 #include <QObject>
00013 #include <QtGui>
00014
00015 class AboutPerson::Private
00016 {
00017 public:
00018 QString _name;
00019 QString _task;
00020 QString _emailAddress;
00021 QString _webAddress;
00022
00023 QString _nameNoop;
00024 };
00025
00026 AboutPerson::AboutPerson( const QString &_name, const QString &_task, const QByteArray &_emailAddress, const QByteArray &_webAddress ) : d(new Private)
00027 {
00028 d->_name = _name;
00029 d->_task = _task;
00030 d->_emailAddress = QString::fromUtf8(_emailAddress);
00031 d->_webAddress = QString::fromUtf8(_webAddress);
00032 }
00033
00034 AboutPerson::AboutPerson(QString& _name, QString& _email ) : d(new Private)
00035 {
00036 d->_nameNoop = _name;
00037 d->_emailAddress = _email;
00038 }
00039
00040 AboutPerson::AboutPerson(const AboutPerson& other): d(new Private)
00041 {
00042 *d = *other.d;
00043 }
00044
00045 AboutPerson::~AboutPerson()
00046 {
00047 delete d;
00048 }
00049
00050 QString
00051 AboutPerson::name() const
00052 {
00053 if (!d->_nameNoop.isEmpty())
00054 return d->_nameNoop;
00055 return d->_name;
00056 }
00057
00058 QString
00059 AboutPerson::task() const
00060 {
00061 if (!d->_task.isEmpty())
00062 return d->_task;
00063 return QString();
00064 }
00065
00066 QString
00067 AboutPerson::emailAddress() const
00068 {
00069 return d->_emailAddress;
00070 }
00071
00072
00073 QString
00074 AboutPerson::webAddress() const
00075 {
00076 return d->_webAddress;
00077 }
00078
00079
00080 AboutPerson&
00081 AboutPerson::operator=(const AboutPerson& other)
00082 {
00083 *d = *other.d;
00084 return *this;
00085 }
00086
00087
00088 class AboutData::Private
00089 {
00090 public:
00091 Private()
00092 : customAuthorTextEnabled(false)
00093 {}
00094 QString _appName;
00095 QString _programName;
00096 QString _shortDescription;
00097 QString _catalogName;
00098 QString _copyrightStatement;
00099 QString _otherText;
00100 QString _homepageAddress;
00101 QList<AboutPerson> _authorList;
00102 QList<AboutPerson> _creditList;
00103 QString translatorName;
00104 QString translatorEmail;
00105 QString productName;
00106 QString programIconName;
00107 QVariant programLogo;
00108 QString customAuthorPlainText, customAuthorRichText;
00109 bool customAuthorTextEnabled;
00110
00111 QString organizationDomain;
00112
00113
00114
00115 QByteArray _translatedProgramName;
00116 QByteArray _version;
00117 QByteArray _bugEmailAddress;
00118 };
00119
00120
00121 AboutData::AboutData( const QByteArray &_appName,
00122 const QByteArray &_catalogName,
00123 const QString &_programName,
00124 const QByteArray &_version,
00125 const QString &_shortDescription,
00126 const QString &_copyrightStatement,
00127 const QString &text,
00128 const QByteArray &homePageAddress,
00129 const QByteArray &bugsEmailAddress
00130 )
00131 : d(new Private)
00132 {
00133 d->_appName = QString::fromUtf8(_appName);
00134 int p = d->_appName.indexOf('/');
00135 if (p >= 0) {
00136 d->_appName = d->_appName.mid(p + 1);
00137 }
00138
00139 d->_catalogName = _catalogName;
00140 d->_programName = _programName;
00141 if (!d->_programName.isEmpty())
00142 d->_translatedProgramName = _programName.toUtf8();
00143 d->_version = _version;
00144 d->_shortDescription = _shortDescription;
00145 d->_copyrightStatement = _copyrightStatement;
00146 d->_otherText = text;
00147 d->_homepageAddress = homePageAddress;
00148 d->_bugEmailAddress = bugsEmailAddress;
00149
00150 if (d->_homepageAddress.contains("http://")) {
00151 int dot = d->_homepageAddress.indexOf('.');
00152 if (dot >= 0) {
00153 d->organizationDomain = d->_homepageAddress.mid(dot + 1);
00154 int slash = d->organizationDomain.indexOf('/');
00155 if (slash >= 0)
00156 d->organizationDomain.truncate(slash);
00157 }
00158 else {
00159 d->organizationDomain = "kde.org";
00160 }
00161 }
00162 else {
00163 d->organizationDomain = "kde.org";
00164 }
00165 }
00166
00167 AboutData::~AboutData()
00168 {
00169 delete d;
00170 }
00171
00172 AboutData::AboutData(const AboutData& other): d(new Private)
00173 {
00174 *d = *other.d;
00175 }
00176
00177 AboutData&
00178 AboutData::operator=(const AboutData& other)
00179 {
00180 *d = *other.d;
00181 return *this;
00182 }
00183
00184 AboutData &
00185 AboutData::addAuthor( const QString &name,
00186 const QString &task,
00187 const QByteArray &emailAddress,
00188 const QByteArray &webAddress )
00189 {
00190 d->_authorList.append(AboutPerson(name,task,emailAddress,webAddress));
00191 return *this;
00192 }
00193
00194 AboutData &
00195 AboutData::addCredit( const QString &name,
00196 const QString &task,
00197 const QByteArray &emailAddress,
00198 const QByteArray &webAddress )
00199 {
00200 d->_creditList.append(AboutPerson(name,task,emailAddress,webAddress));
00201 return *this;
00202 }
00203
00204 AboutData &
00205 AboutData::setTranslator( const QString& name,
00206 const QString& emailAddress )
00207 {
00208 d->translatorName = name;
00209 d->translatorEmail = emailAddress;
00210 return *this;
00211 }
00212
00213 AboutData &
00214 AboutData::setAppName( const QByteArray &_appName )
00215 {
00216 d->_appName = QString::fromUtf8(_appName);
00217 return *this;
00218 }
00219
00220 AboutData &
00221 AboutData::setProgramName( const QString &_programName )
00222 {
00223 d->_programName = _programName;
00224 translateInternalProgramName();
00225 return *this;
00226 }
00227
00228 AboutData &
00229 AboutData::setVersion( const QByteArray &_version )
00230 {
00231 d->_version = _version;
00232 return *this;
00233 }
00234
00235 AboutData &
00236 AboutData::setShortDescription( const QString &_shortDescription )
00237 {
00238 d->_shortDescription = _shortDescription;
00239 return *this;
00240 }
00241
00242 AboutData &
00243 AboutData::setCatalogName( const QByteArray &_catalogName )
00244 {
00245 d->_catalogName = _catalogName;
00246 return *this;
00247 }
00248
00249 AboutData &
00250 AboutData::setCopyrightStatement( const QString &_copyrightStatement )
00251 {
00252 d->_copyrightStatement = _copyrightStatement;
00253 return *this;
00254 }
00255
00256 AboutData &
00257 AboutData::setOtherText( const QString &_otherText )
00258 {
00259 d->_otherText = _otherText;
00260 return *this;
00261 }
00262
00263 AboutData &
00264 AboutData::setHomepage( const QByteArray &_homepage )
00265 {
00266 d->_homepageAddress = QString::fromUtf8(_homepage);
00267 return *this;
00268 }
00269
00270 AboutData &
00271 AboutData::setBugAddress( const QByteArray &_bugAddress )
00272 {
00273 d->_bugEmailAddress = _bugAddress;
00274 return *this;
00275 }
00276
00277 AboutData &
00278 AboutData::setOrganizationDomain( const QByteArray &domain )
00279 {
00280 d->organizationDomain = QString::fromUtf8(domain);
00281 return *this;
00282 }
00283
00284 AboutData &
00285 AboutData::setProductName( const QByteArray &_productName )
00286 {
00287 d->productName = QString::fromUtf8(_productName);
00288 return *this;
00289 }
00290
00291 QString
00292 AboutData::appName() const
00293 {
00294 return d->_appName;
00295 }
00296
00297 QString
00298 AboutData::productName() const
00299 {
00300 if (!d->productName.isEmpty())
00301 return d->productName;
00302 return appName();
00303 }
00304
00305 QString
00306 AboutData::programName() const
00307 {
00308 if (!d->_programName.isEmpty())
00309 return d->_programName;
00310 return QString();
00311 }
00312
00316 const char*
00317 AboutData::internalProgramName() const
00318 {
00319 return d->_translatedProgramName.constData();
00320 }
00321
00326 void
00327 AboutData::translateInternalProgramName() const
00328 {
00329 d->_translatedProgramName.clear();
00330
00331 d->_translatedProgramName = programName().toUtf8();
00332 }
00333
00334 QString
00335 AboutData::programIconName() const
00336 {
00337 return d->programIconName.isEmpty() ? appName() : d->programIconName;
00338 }
00339
00340 AboutData &
00341 AboutData::setProgramIconName( const QString &iconName )
00342 {
00343 d->programIconName = iconName;
00344 return *this;
00345 }
00346
00347 QVariant
00348 AboutData::programLogo() const
00349 {
00350 return d->programLogo;
00351 }
00352
00353 AboutData &
00354 AboutData::setProgramLogo(const QVariant& image)
00355 {
00356 d->programLogo = image ;
00357 return *this;
00358 }
00359
00360 QString
00361 AboutData::version() const
00362 {
00363 return QString::fromUtf8(d->_version);
00364 }
00365
00369 const char*
00370 AboutData::internalVersion() const
00371 {
00372 return d->_version.constData();
00373 }
00374
00375 QString
00376 AboutData::shortDescription() const
00377 {
00378 if (!d->_shortDescription.isEmpty())
00379 return d->_shortDescription;
00380 return QString();
00381 }
00382
00383 QString
00384 AboutData::catalogName() const
00385 {
00386 if (!d->_catalogName.isEmpty())
00387 return d->_catalogName;
00388
00389 return d->_appName;
00390 }
00391
00392 QString
00393 AboutData::homepage() const
00394 {
00395 return d->_homepageAddress;
00396 }
00397
00398 QString
00399 AboutData::bugAddress() const
00400 {
00401 return QString::fromUtf8(d->_bugEmailAddress);
00402 }
00403
00404 QString
00405 AboutData::organizationDomain() const
00406 {
00407 return d->organizationDomain;
00408 }
00409
00410
00414 const char*
00415 AboutData::internalBugAddress() const
00416 {
00417 if (d->_bugEmailAddress.isEmpty())
00418 return 0;
00419 return d->_bugEmailAddress.constData();
00420 }
00421
00422 QList<AboutPerson>
00423 AboutData::authors() const
00424 {
00425 return d->_authorList;
00426 }
00427
00428 QList<AboutPerson>
00429 AboutData::credits() const
00430 {
00431 return d->_creditList;
00432 }
00433
00434 #define NAME_OF_TRANSLATORS "Your names"
00435 #define EMAIL_OF_TRANSLATORS "Your emails"
00436 QList<AboutPerson>
00437 AboutData::translators() const
00438 {
00439 QList<AboutPerson> personList;
00440
00441 QString translatorName;
00442 if (!d->translatorName.isEmpty()) {
00443 translatorName = d->translatorName;
00444 }
00445 else {
00446 translatorName = QObject::tr("NAME OF TRANSLATORS", NAME_OF_TRANSLATORS);
00447 }
00448
00449 QString translatorEmail;
00450 if (!d->translatorEmail.isEmpty()) {
00451 translatorEmail = d->translatorEmail;
00452 }
00453 else {
00454 translatorEmail = QObject::tr("EMAIL OF TRANSLATORS", EMAIL_OF_TRANSLATORS);
00455 }
00456
00457 if ( translatorName.isEmpty() || translatorName == QString::fromUtf8( NAME_OF_TRANSLATORS ) )
00458 return personList;
00459
00460 const QStringList nameList ( translatorName.split( ',' ) );
00461
00462 QStringList emailList;
00463 if( !translatorEmail.isEmpty() && translatorEmail != QString::fromUtf8( EMAIL_OF_TRANSLATORS ) )
00464 {
00465 emailList = translatorEmail.split( ',', QString::KeepEmptyParts );
00466 }
00467
00468 QStringList::const_iterator nit;
00469 QStringList::const_iterator eit = emailList.constBegin();
00470
00471 for( nit = nameList.constBegin(); nit != nameList.constEnd(); ++nit )
00472 {
00473 QString email;
00474 if ( eit != emailList.constEnd() )
00475 {
00476 email = *eit;
00477 ++eit;
00478 }
00479
00480 QString n = (*nit).trimmed();
00481 QString e = email.trimmed();
00482 personList.append( AboutPerson(n, e) );
00483 }
00484
00485 return personList;
00486 }
00487
00488 QString
00489 AboutData::aboutTranslationTeam()
00490 {
00491 return QObject::tr("replace this with information about your translation team",
00492 "<p>KDE is translated into many languages thanks to the work "
00493 "of the translation teams all over the world.</p>"
00494 "<p>For more information on KDE internationalization "
00495 "visit <a href=\"http://l10n.kde.org\">http://l10n.kde.org</a></p>"
00496 );
00497 }
00498
00499 QString
00500 AboutData::otherText() const
00501 {
00502 if (!d->_otherText.isEmpty())
00503 return d->_otherText;
00504 return QString();
00505 }
00506
00507 QString
00508 AboutData::copyrightStatement() const
00509 {
00510 if (!d->_copyrightStatement.isEmpty())
00511 return d->_copyrightStatement;
00512 return QString();
00513 }
00514
00515 QString
00516 AboutData::customAuthorPlainText() const
00517 {
00518 if (!d->customAuthorPlainText.isEmpty())
00519 return d->customAuthorPlainText;
00520 return QString();
00521 }
00522
00523 QString
00524 AboutData::customAuthorRichText() const
00525 {
00526 if (!d->customAuthorRichText.isEmpty())
00527 return d->customAuthorRichText;
00528 return QString();
00529 }
00530
00531 bool
00532 AboutData::customAuthorTextEnabled() const
00533 {
00534 return d->customAuthorTextEnabled;
00535 }
00536
00537 AboutData &
00538 AboutData::setCustomAuthorText(const QString &plainText,
00539 const QString &richText)
00540 {
00541 d->customAuthorPlainText = plainText;
00542 d->customAuthorRichText = richText;
00543
00544 d->customAuthorTextEnabled = true;
00545
00546 return *this;
00547 }
00548
00549 AboutData &
00550 AboutData::unsetCustomAuthorText()
00551 {
00552 d->customAuthorPlainText = QString();
00553 d->customAuthorRichText = QString();
00554
00555 d->customAuthorTextEnabled = false;
00556
00557 return *this;
00558 }
00559