KDELibs4Support

k4aboutdata.cpp
1 /*
2  * This file is part of the KDE Libraries
3  * Copyright (C) 2000 Espen Sand ([email protected])
4  * Copyright (C) 2006 Nicolas GOUTTE <[email protected]>
5  * Copyright (C) 2008 Friedrich W. H. Kossebau <[email protected]>
6  * Copyright (C) 2010 Teo Mrnjavac <[email protected]>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 #include "k4aboutdata.h"
26 #include "kaboutdata.h"
27 
28 #include <QStandardPaths>
29 #include <QFile>
30 #include <QTextStream>
31 #include <QSharedData>
32 #include <QVariant>
33 #include <QList>
34 #include <QHash>
35 
36 // -----------------------------------------------------------------------------
37 // Design notes:
38 //
39 // These classes deal with a lot of text, some of which needs to be
40 // marked for translation. Since at the time when these object and calls are
41 // made the translation catalogs are usually still not initialized, the
42 // translation has to be delayed. This is achieved by using KLocalizedString
43 // for translatable strings. KLocalizedStrings are produced by ki18n* calls,
44 // instead of the more usuall i18n* calls which produce QString by trying to
45 // translate immediately.
46 //
47 // All the non-translatable string arguments to methods are taken QByteArray,
48 // all the translatable are KLocalizedString. The getter methods always return
49 // proper QString: the non-translatable strings supplied by the code are
50 // treated with QString::fromUtf8(), those coming from the outside with
51 // QTextCodec::toUnicode(), and translatable strings are finalized to QStrings
52 // at the point of getter calls (i.e. delayed translation).
53 // -----------------------------------------------------------------------------
54 
55 class Q_DECL_HIDDEN K4AboutPerson::Private
56 {
57 public:
58  KLocalizedString _name;
59  KLocalizedString _task;
60  QString _emailAddress;
61  QString _webAddress;
62  QString _ocsUsername;
63 
64  QString _nameNoop;
65 };
66 
68  const KLocalizedString &_task,
69  const QByteArray &_emailAddress,
70  const QByteArray &_webAddress)
71  : d(new Private)
72 {
73  d->_name = _name;
74  d->_task = _task;
75  d->_emailAddress = QString::fromUtf8(_emailAddress.data());
76  d->_webAddress = QString::fromUtf8(_webAddress.data());
77 }
78 
80  const KLocalizedString &_task,
81  const QByteArray &_emailAddress,
82  const QByteArray &_webAddress,
83  const QByteArray &_ocsUsername)
84  : d(new Private)
85 {
86  d->_name = _name;
87  d->_task = _task;
88  d->_emailAddress = QString::fromUtf8(_emailAddress.data());
89  d->_webAddress = QString::fromUtf8(_webAddress.data());
90  d->_ocsUsername = QString::fromUtf8(_ocsUsername.data());
91 }
92 
93 K4AboutPerson::K4AboutPerson(const QString &_name, const QString &_email)
94  : d(new Private)
95 {
96  d->_nameNoop = _name;
97  d->_emailAddress = _email;
98 }
99 
100 K4AboutPerson::K4AboutPerson(const K4AboutPerson &other): d(new Private)
101 {
102  *d = *other.d;
103 }
104 
105 K4AboutPerson::~K4AboutPerson()
106 {
107  delete d;
108 }
109 
111 {
112  if (!d->_nameNoop.isEmpty()) {
113  return d->_nameNoop;
114  }
115  return d->_name.toString();
116 }
117 
119 {
120  if (!d->_task.isEmpty()) {
121  return d->_task.toString();
122  }
123  return QString();
124 }
125 
127 {
128  return d->_emailAddress;
129 }
130 
132 {
133  return d->_webAddress;
134 }
135 
137 {
138  return d->_ocsUsername;
139 }
140 
142 {
143  *d = *other.d;
144  return *this;
145 }
146 
147 class Q_DECL_HIDDEN K4AboutLicense::Private : public QSharedData
148 {
149 public:
150  Private(enum K4AboutData::LicenseKey licenseType, const K4AboutData *aboutData);
151  Private(const QString &pathToFile, const K4AboutData *aboutData);
152  Private(const KLocalizedString &licenseText, const K4AboutData *aboutData);
153  Private(const Private &other);
154 public:
155  enum K4AboutData::LicenseKey _licenseKey;
156  KLocalizedString _licenseText;
157  QString _pathToLicenseTextFile;
158  // needed for access to the possibly changing copyrightStatement()
159  const K4AboutData *_aboutData;
160 };
161 
162 K4AboutLicense::Private::Private(enum K4AboutData::LicenseKey licenseType, const K4AboutData *aboutData)
163  : QSharedData(),
164  _licenseKey(licenseType),
165  _aboutData(aboutData)
166 {
167 }
168 
169 K4AboutLicense::Private::Private(const QString &pathToFile, const K4AboutData *aboutData)
170  : QSharedData(),
171  _licenseKey(K4AboutData::License_File),
172  _pathToLicenseTextFile(pathToFile),
173  _aboutData(aboutData)
174 {
175 }
176 
177 K4AboutLicense::Private::Private(const KLocalizedString &licenseText, const K4AboutData *aboutData)
178  : QSharedData(),
179  _licenseKey(K4AboutData::License_Custom),
180  _licenseText(licenseText),
181  _aboutData(aboutData)
182 {
183 }
184 
185 K4AboutLicense::Private::Private(const K4AboutLicense::Private &other)
186  : QSharedData(other),
187  _licenseKey(other._licenseKey),
188  _licenseText(other._licenseText),
189  _pathToLicenseTextFile(other._pathToLicenseTextFile),
190  _aboutData(other._aboutData)
191 {}
192 
193 K4AboutLicense::K4AboutLicense(enum K4AboutData::LicenseKey licenseType, const K4AboutData *aboutData)
194  : d(new Private(licenseType, aboutData))
195 {
196 }
197 
198 K4AboutLicense::K4AboutLicense(const QString &pathToFile, const K4AboutData *aboutData)
199  : d(new Private(pathToFile, aboutData))
200 {
201 }
202 
203 K4AboutLicense::K4AboutLicense(const KLocalizedString &licenseText, const K4AboutData *aboutData)
204  : d(new Private(licenseText, aboutData))
205 {
206 }
207 
208 K4AboutLicense::K4AboutLicense(const K4AboutLicense &other)
209  : d(other.d)
210 {
211 }
212 
213 K4AboutLicense::~K4AboutLicense()
214 {}
215 
217 {
218  QString result;
219 
220  const QString lineFeed = QString::fromLatin1("\n\n");
221 
222  if (d->_aboutData && !d->_aboutData->copyrightStatement().isEmpty()) {
223  result = d->_aboutData->copyrightStatement() + lineFeed;
224  }
225 
226  bool knownLicense = false;
227  QString pathToFile;
228  switch (d->_licenseKey) {
229  case K4AboutData::License_File:
230  pathToFile = d->_pathToLicenseTextFile;
231  break;
232  case K4AboutData::License_GPL_V2:
233  knownLicense = true;
234  pathToFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("LICENSES/GPL_V2"));
235  break;
236  case K4AboutData::License_LGPL_V2:
237  knownLicense = true;
238  pathToFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("LICENSES/LGPL_V2"));
239  break;
240  case K4AboutData::License_BSD:
241  knownLicense = true;
242  pathToFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("LICENSES/BSD"));
243  break;
244  case K4AboutData::License_Artistic:
245  knownLicense = true;
246  pathToFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("LICENSES/ARTISTIC"));
247  break;
248  case K4AboutData::License_QPL_V1_0:
249  knownLicense = true;
250  pathToFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("LICENSES/QPL_V1.0"));
251  break;
252  case K4AboutData::License_GPL_V3:
253  knownLicense = true;
254  pathToFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("LICENSES/GPL_V3"));
255  break;
256  case K4AboutData::License_LGPL_V3:
257  knownLicense = true;
258  pathToFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString::fromLatin1("LICENSES/LGPL_V3"));
259  break;
260  case K4AboutData::License_Custom:
261  if (!d->_licenseText.isEmpty()) {
262  result = d->_licenseText.toString();
263  break;
264  }
265  // fall through
266  default:
267  result += i18n("No licensing terms for this program have been specified.\n"
268  "Please check the documentation or the source for any\n"
269  "licensing terms.\n");
270  }
271 
272  if (knownLicense) {
273  result += i18n("This program is distributed under the terms of the %1.", name(K4AboutData::ShortName));
274  if (!pathToFile.isEmpty()) {
275  result += lineFeed;
276  }
277  }
278 
279  if (!pathToFile.isEmpty()) {
280  QFile file(pathToFile);
281  if (file.open(QIODevice::ReadOnly)) {
282  QTextStream str(&file);
283  result += str.readAll();
284  }
285  }
286 
287  return result;
288 }
289 
291 {
292  QString licenseShort;
293  QString licenseFull;
294 
295  switch (d->_licenseKey) {
296  case K4AboutData::License_GPL_V2:
297  licenseShort = i18nc("@item license (short name)", "GPL v2");
298  licenseFull = i18nc("@item license", "GNU General Public License Version 2");
299  break;
300  case K4AboutData::License_LGPL_V2:
301  licenseShort = i18nc("@item license (short name)", "LGPL v2");
302  licenseFull = i18nc("@item license", "GNU Lesser General Public License Version 2");
303  break;
304  case K4AboutData::License_BSD:
305  licenseShort = i18nc("@item license (short name)", "BSD License");
306  licenseFull = i18nc("@item license", "BSD License");
307  break;
308  case K4AboutData::License_Artistic:
309  licenseShort = i18nc("@item license (short name)", "Artistic License");
310  licenseFull = i18nc("@item license", "Artistic License");
311  break;
312  case K4AboutData::License_QPL_V1_0:
313  licenseShort = i18nc("@item license (short name)", "QPL v1.0");
314  licenseFull = i18nc("@item license", "Q Public License");
315  break;
316  case K4AboutData::License_GPL_V3:
317  licenseShort = i18nc("@item license (short name)", "GPL v3");
318  licenseFull = i18nc("@item license", "GNU General Public License Version 3");
319  break;
320  case K4AboutData::License_LGPL_V3:
321  licenseShort = i18nc("@item license (short name)", "LGPL v3");
322  licenseFull = i18nc("@item license", "GNU Lesser General Public License Version 3");
323  break;
324  case K4AboutData::License_Custom:
325  case K4AboutData::License_File:
326  licenseShort = licenseFull = i18nc("@item license", "Custom");
327  break;
328  default:
329  licenseShort = licenseFull = i18nc("@item license", "Not specified");
330  }
331 
332  const QString result =
333  (formatName == K4AboutData::ShortName) ? licenseShort :
334  (formatName == K4AboutData::FullName) ? licenseFull :
335  QString();
336 
337  return result;
338 }
339 
340 K4AboutLicense &K4AboutLicense::operator=(const K4AboutLicense &other)
341 {
342  d = other.d;
343  return *this;
344 }
345 
347 {
348  return d->_licenseKey;
349 }
350 
351 K4AboutLicense K4AboutLicense::byKeyword(const QString &rawKeyword)
352 {
353  // Setup keyword->enum dictionary on first call.
354  // Use normalized keywords, by the algorithm below.
356  if (ldict.isEmpty()) {
357  ldict.insert("gpl", K4AboutData::License_GPL);
358  ldict.insert("gplv2", K4AboutData::License_GPL_V2);
359  ldict.insert("gplv2+", K4AboutData::License_GPL_V2);
360  ldict.insert("lgpl", K4AboutData::License_LGPL);
361  ldict.insert("lgplv2", K4AboutData::License_LGPL_V2);
362  ldict.insert("lgplv2+", K4AboutData::License_LGPL_V2);
363  ldict.insert("bsd", K4AboutData::License_BSD);
364  ldict.insert("artistic", K4AboutData::License_Artistic);
365  ldict.insert("qpl", K4AboutData::License_QPL);
366  ldict.insert("qplv1", K4AboutData::License_QPL_V1_0);
367  ldict.insert("qplv10", K4AboutData::License_QPL_V1_0);
368  ldict.insert("gplv3", K4AboutData::License_GPL_V3);
369  ldict.insert("gplv3+", K4AboutData::License_GPL_V3);
370  ldict.insert("lgplv3", K4AboutData::License_LGPL_V3);
371  ldict.insert("lgplv3+", K4AboutData::License_LGPL_V3);
372  }
373 
374  // Normalize keyword.
375  QString keyword = rawKeyword;
376  keyword = keyword.toLower();
377  keyword.remove(QLatin1Char(' '));
378  keyword.remove(QLatin1Char('.'));
379 
380  K4AboutData::LicenseKey license = ldict.value(keyword.toLatin1(),
381  K4AboutData::License_Custom);
382  return K4AboutLicense(license, nullptr);
383 }
384 
385 class Q_DECL_HIDDEN K4AboutData::Private
386 {
387 public:
388  Private()
389  : customAuthorTextEnabled(false)
390  {}
391  QByteArray _appName;
392  KLocalizedString _programName;
393  KLocalizedString _shortDescription;
394  QByteArray _catalogName;
395  KLocalizedString _copyrightStatement;
396  KLocalizedString _otherText;
397  QString _homepageAddress;
398  QList<K4AboutPerson> _authorList;
399  QList<K4AboutPerson> _creditList;
400  QList<K4AboutLicense> _licenseList;
401  KLocalizedString translatorName;
402  KLocalizedString translatorEmail;
403  QString productName;
404  QString programIconName;
405  QVariant programLogo;
406  KLocalizedString customAuthorPlainText, customAuthorRichText;
407  bool customAuthorTextEnabled;
408 
409  QString organizationDomain;
410  QByteArray _ocsProviderUrl;
411 
412  // Everything dr.konqi needs, we store as utf-8, so we
413  // can just give it a pointer, w/o any allocations.
414  QByteArray _translatedProgramName; // ### I don't see it ever being translated, and I did not change that
415  QByteArray _version;
416  QByteArray _bugEmailAddress;
417 };
418 
420  const QByteArray &_catalogName,
421  const KLocalizedString &_programName,
422  const QByteArray &_version,
423  const KLocalizedString &_shortDescription,
424  enum LicenseKey licenseType,
425  const KLocalizedString &_copyrightStatement,
426  const KLocalizedString &text,
427  const QByteArray &homePageAddress,
428  const QByteArray &bugsEmailAddress
429  )
430  : d(new Private)
431 {
432  d->_appName = _appName;
433  int p = d->_appName.indexOf('/');
434  if (p >= 0) {
435  d->_appName = d->_appName.mid(p + 1);
436  }
437 
438  d->_catalogName = _catalogName;
439  d->_programName = _programName;
440  if (!d->_programName.isEmpty()) { // KComponentData("klauncher") gives empty program name
441  d->_translatedProgramName = _programName.toString().toUtf8();
442  }
443  d->_version = _version;
444  d->_shortDescription = _shortDescription;
445  d->_licenseList.append(K4AboutLicense(licenseType, this));
446  d->_copyrightStatement = _copyrightStatement;
447  d->_otherText = text;
448  d->_homepageAddress = QString::fromLatin1(homePageAddress.data());
449  d->_bugEmailAddress = bugsEmailAddress;
450 
451  if (d->_homepageAddress.contains(QLatin1String("http://"))) {
452  const int dot = d->_homepageAddress.indexOf(QLatin1Char('.'));
453  if (dot >= 0) {
454  d->organizationDomain = d->_homepageAddress.mid(dot + 1);
455  const int slash = d->organizationDomain.indexOf(QLatin1Char('/'));
456  if (slash >= 0) {
457  d->organizationDomain.truncate(slash);
458  }
459  } else {
460  d->organizationDomain = QString::fromLatin1("kde.org");
461  }
462  } else {
463  d->organizationDomain = QString::fromLatin1("kde.org");
464  }
465 }
466 
467 K4AboutData::~K4AboutData()
468 {
469  delete d;
470 }
471 
472 K4AboutData::K4AboutData(const K4AboutData &other): d(new Private)
473 {
474  *d = *other.d;
475  QList<K4AboutLicense>::iterator it = d->_licenseList.begin(), itEnd = d->_licenseList.end();
476  for (; it != itEnd; ++it) {
477  K4AboutLicense &al = *it;
478  al.d.detach();
479  al.d->_aboutData = this;
480  }
481 }
482 
483 K4AboutData &K4AboutData::operator=(const K4AboutData &other)
484 {
485  if (this != &other) {
486  *d = *other.d;
487  QList<K4AboutLicense>::iterator it = d->_licenseList.begin(), itEnd = d->_licenseList.end();
488  for (; it != itEnd; ++it) {
489  K4AboutLicense &al = *it;
490  al.d.detach();
491  al.d->_aboutData = this;
492  }
493  }
494  return *this;
495 }
496 
497 K4AboutData::operator KAboutData() const
498 {
499  // catalogName() is not used by KF5 KAboutData
501  KAboutLicense::Unknown, copyrightStatement(),
502  otherText(), d->_homepageAddress, bugAddress());
503  for (auto it = d->_licenseList.constBegin(); it != d->_licenseList.constEnd(); ++it) {
504  if (it->key() == K4AboutData::License_Custom) {
505  aboutData.addLicenseText(it->text());
506  } else if (it->key() == K4AboutData::License_File) {
507  aboutData.addLicenseTextFile(it->d->_pathToLicenseTextFile);
508  } else {
509  aboutData.addLicense(static_cast<KAboutLicense::LicenseKey>(it->key()));
510  }
511  }
512  return aboutData;
513 }
514 
515 K4AboutData &K4AboutData::addAuthor(const KLocalizedString &name,
516  const KLocalizedString &task,
517  const QByteArray &emailAddress,
518  const QByteArray &webAddress)
519 {
520  d->_authorList.append(K4AboutPerson(name, task, emailAddress, webAddress));
521  return *this;
522 }
523 
524 K4AboutData &K4AboutData::addAuthor(const KLocalizedString &name,
525  const KLocalizedString &task,
526  const QByteArray &emailAddress,
527  const QByteArray &webAddress,
528  const QByteArray &ocsUsername)
529 {
530  d->_authorList.append(K4AboutPerson(name, task, emailAddress, webAddress, ocsUsername));
531  return *this;
532 }
533 
534 K4AboutData &K4AboutData::addCredit(const KLocalizedString &name,
535  const KLocalizedString &task,
536  const QByteArray &emailAddress,
537  const QByteArray &webAddress)
538 {
539  d->_creditList.append(K4AboutPerson(name, task, emailAddress, webAddress));
540  return *this;
541 }
542 
543 K4AboutData &K4AboutData::addCredit(const KLocalizedString &name,
544  const KLocalizedString &task,
545  const QByteArray &emailAddress,
546  const QByteArray &webAddress,
547  const QByteArray &ocsUsername)
548 {
549  d->_creditList.append(K4AboutPerson(name, task, emailAddress, webAddress, ocsUsername));
550  return *this;
551 }
552 
554  const KLocalizedString &emailAddress)
555 {
556  d->translatorName = name;
557  d->translatorEmail = emailAddress;
558  return *this;
559 }
560 
561 K4AboutData &K4AboutData::setLicenseText(const KLocalizedString &licenseText)
562 {
563  d->_licenseList[0] = K4AboutLicense(licenseText, this);
564  return *this;
565 }
566 
567 K4AboutData &K4AboutData::addLicenseText(const KLocalizedString &licenseText)
568 {
569  // if the default license is unknown, overwrite instead of append
570  K4AboutLicense &firstLicense = d->_licenseList[0];
571  if (d->_licenseList.count() == 1 && firstLicense.d->_licenseKey == License_Unknown) {
572  firstLicense = K4AboutLicense(licenseText, this);
573  } else {
574  d->_licenseList.append(K4AboutLicense(licenseText, this));
575  }
576  return *this;
577 }
578 
579 K4AboutData &K4AboutData::setLicenseTextFile(const QString &pathToFile)
580 {
581  d->_licenseList[0] = K4AboutLicense(pathToFile, this);
582  return *this;
583 }
584 
585 K4AboutData &K4AboutData::addLicenseTextFile(const QString &pathToFile)
586 {
587  // if the default license is unknown, overwrite instead of append
588  K4AboutLicense &firstLicense = d->_licenseList[0];
589  if (d->_licenseList.count() == 1 && firstLicense.d->_licenseKey == License_Unknown) {
590  firstLicense = K4AboutLicense(pathToFile, this);
591  } else {
592  d->_licenseList.append(K4AboutLicense(pathToFile, this));
593  }
594  return *this;
595 }
596 
597 K4AboutData &K4AboutData::setAppName(const QByteArray &_appName)
598 {
599  d->_appName = _appName;
600  return *this;
601 }
602 
603 K4AboutData &K4AboutData::setProgramName(const KLocalizedString &_programName)
604 {
605  d->_programName = _programName;
607  return *this;
608 }
609 
610 K4AboutData &K4AboutData::setOcsProvider(const QByteArray &_ocsProviderUrl)
611 {
612  d->_ocsProviderUrl = _ocsProviderUrl;
613  return *this;
614 }
615 
616 K4AboutData &K4AboutData::setVersion(const QByteArray &_version)
617 {
618  d->_version = _version;
619  return *this;
620 }
621 
622 K4AboutData &K4AboutData::setShortDescription(const KLocalizedString &_shortDescription)
623 {
624  d->_shortDescription = _shortDescription;
625  return *this;
626 }
627 
628 K4AboutData &K4AboutData::setCatalogName(const QByteArray &_catalogName)
629 {
630  d->_catalogName = _catalogName;
631  return *this;
632 }
633 
634 K4AboutData &K4AboutData::setLicense(LicenseKey licenseKey)
635 {
636  d->_licenseList[0] = K4AboutLicense(licenseKey, this);
637  return *this;
638 }
639 
640 K4AboutData &K4AboutData::addLicense(LicenseKey licenseKey)
641 {
642  // if the default license is unknown, overwrite instead of append
643  K4AboutLicense &firstLicense = d->_licenseList[0];
644  if (d->_licenseList.count() == 1 && firstLicense.d->_licenseKey == License_Unknown) {
645  firstLicense = K4AboutLicense(licenseKey, this);
646  } else {
647  d->_licenseList.append(K4AboutLicense(licenseKey, this));
648  }
649  return *this;
650 }
651 
652 K4AboutData &K4AboutData::setCopyrightStatement(const KLocalizedString &_copyrightStatement)
653 {
654  d->_copyrightStatement = _copyrightStatement;
655  return *this;
656 }
657 
658 K4AboutData &K4AboutData::setOtherText(const KLocalizedString &_otherText)
659 {
660  d->_otherText = _otherText;
661  return *this;
662 }
663 
664 K4AboutData &K4AboutData::setHomepage(const QByteArray &_homepage)
665 {
666  d->_homepageAddress = QString::fromLatin1(_homepage.data());
667  return *this;
668 }
669 
670 K4AboutData &K4AboutData::setBugAddress(const QByteArray &_bugAddress)
671 {
672  d->_bugEmailAddress = _bugAddress;
673  return *this;
674 }
675 
677 {
678  d->organizationDomain = QString::fromLatin1(domain.data());
679  return *this;
680 }
681 
682 K4AboutData &K4AboutData::setProductName(const QByteArray &_productName)
683 {
684  d->productName = QString::fromUtf8(_productName.data());
685  return *this;
686 }
687 
689 {
690  return QString::fromUtf8(d->_appName.data());
691 }
692 
694 {
695  if (!d->productName.isEmpty()) {
696  return d->productName;
697  }
698  return appName();
699 }
700 
702 {
703  if (!d->_programName.isEmpty()) {
704  return d->_programName.toString();
705  }
706  return QString();
707 }
708 
713 {
714  return d->_translatedProgramName.constData();
715 }
716 
722 {
723  d->_translatedProgramName.clear();
724 #pragma message("KDE5 FIXME: This code must be replaced by something with KLocalizedString")
725 #if 0
726  if (KLocale::global()) {
727  d->_translatedProgramName = programName().toUtf8();
728  }
729 #endif
730 }
731 
733 {
734  return d->programIconName.isEmpty() ? appName() : d->programIconName;
735 }
736 
737 K4AboutData &K4AboutData::setProgramIconName(const QString &iconName)
738 {
739  d->programIconName = iconName;
740  return *this;
741 }
742 
744 {
745  return d->programLogo;
746 }
747 
748 K4AboutData &K4AboutData::setProgramLogo(const QVariant &image)
749 {
750  d->programLogo = image;
751  return *this;
752 }
753 
755 {
756  if (!d->_ocsProviderUrl.isEmpty()) {
757  return QString::fromUtf8(d->_ocsProviderUrl.data());
758  }
759  return QString();
760 }
761 
763 {
764  return QString::fromUtf8(d->_version.data());
765 }
766 
770 const char *K4AboutData::internalVersion() const
771 {
772  return d->_version.constData();
773 }
774 
776 {
777  if (!d->_shortDescription.isEmpty()) {
778  return d->_shortDescription.toString();
779  }
780  return QString();
781 }
782 
784 {
785  if (!d->_catalogName.isEmpty()) {
786  return QString::fromUtf8(d->_catalogName.data());
787  }
788  // Fallback to appname for catalog name if empty.
789  return QString::fromUtf8(d->_appName.data());
790 }
791 
793 {
794  return d->_homepageAddress;
795 }
796 
798 {
799  return QString::fromUtf8(d->_bugEmailAddress.data());
800 }
801 
803 {
804  return d->organizationDomain;
805 }
806 
811 {
812  if (d->_bugEmailAddress.isEmpty()) {
813  return nullptr;
814  }
815  return d->_bugEmailAddress.constData();
816 }
817 
819 {
820  return d->_authorList;
821 }
822 
824 {
825  return d->_creditList;
826 }
827 
828 #define NAME_OF_TRANSLATORS "Your names"
829 #define EMAIL_OF_TRANSLATORS "Your emails"
831 {
832  QList<K4AboutPerson> personList;
833 #pragma message("KDE5 TODO: What about this code ?")
834 #if 0
835  KLocale *tmpLocale = NULL;
836  if (KLocale::global()) {
837  // There could be many catalogs loaded into the global locale,
838  // e.g. in systemsettings. The tmp locale is needed to make sure we
839  // use the translators name from this aboutdata's catalog, rather than
840  // from any other loaded catalog.
841  tmpLocale = new KLocale(*KLocale::global());
842  tmpLocale->setActiveCatalog(catalogName());
843  }
844 #endif
845  QString translatorName;
846  if (!d->translatorName.isEmpty()) {
847  translatorName = d->translatorName.toString();
848  } else {
849  translatorName = ki18nc("NAME OF TRANSLATORS", NAME_OF_TRANSLATORS).toString(); //toString(tmpLocale);
850  }
851 
852  QString translatorEmail;
853  if (!d->translatorEmail.isEmpty()) {
854  translatorEmail = d->translatorEmail.toString();
855  } else {
856  translatorEmail = ki18nc("EMAIL OF TRANSLATORS", EMAIL_OF_TRANSLATORS).toString(); //toString(tmpLocale);
857  }
858 #if 0
859  delete tmpLocale;
860 #endif
861  if (translatorName.isEmpty() || translatorName == QString::fromUtf8(NAME_OF_TRANSLATORS)) {
862  return personList;
863  }
864 
865  const QStringList nameList(translatorName.split(QString(QLatin1Char(','))));
866 
867  QStringList emailList;
868  if (!translatorEmail.isEmpty() && translatorEmail != QString::fromUtf8(EMAIL_OF_TRANSLATORS)) {
869  emailList = translatorEmail.split(QString(QLatin1Char(',')), QString::KeepEmptyParts);
870  }
871 
873  QStringList::const_iterator eit = emailList.constBegin();
874 
875  for (nit = nameList.constBegin(); nit != nameList.constEnd(); ++nit) {
876  QString email;
877  if (eit != emailList.constEnd()) {
878  email = *eit;
879  ++eit;
880  }
881 
882  personList.append(K4AboutPerson((*nit).trimmed(), email.trimmed()));
883  }
884 
885  return personList;
886 }
887 
889 {
890  return i18nc("replace this with information about your translation team",
891  "<p>KDE is translated into many languages thanks to the work "
892  "of the translation teams all over the world.</p>"
893  "<p>For more information on KDE internationalization "
894  "visit <a href=\"http://l10n.kde.org\">http://l10n.kde.org</a></p>"
895  );
896 }
897 
899 {
900  if (!d->_otherText.isEmpty()) {
901  return d->_otherText.toString();
902  }
903  return QString();
904 }
905 
907 {
908  return d->_licenseList.at(0).text();
909 }
910 
912 {
913  return d->_licenseList.at(0).name(formatName);
914 }
915 
917 {
918  return d->_licenseList;
919 }
920 
922 {
923  if (!d->_copyrightStatement.isEmpty()) {
924  return d->_copyrightStatement.toString();
925  }
926  return QString();
927 }
928 
930 {
931  if (!d->customAuthorPlainText.isEmpty()) {
932  return d->customAuthorPlainText.toString();
933  }
934  return QString();
935 }
936 
938 {
939  if (!d->customAuthorRichText.isEmpty()) {
940  return d->customAuthorRichText.toString();
941  }
942  return QString();
943 }
944 
946 {
947  return d->customAuthorTextEnabled;
948 }
949 
951  const KLocalizedString &richText)
952 {
953  d->customAuthorPlainText = plainText;
954  d->customAuthorRichText = richText;
955 
956  d->customAuthorTextEnabled = true;
957 
958  return *this;
959 }
960 
962 {
963  d->customAuthorPlainText = KLocalizedString();
964  d->customAuthorRichText = KLocalizedString();
965 
966  d->customAuthorTextEnabled = false;
967 
968  return *this;
969 }
970 
QString copyrightStatement() const
Returns the copyright statement.
K4AboutData::LicenseKey key() const
Returns the license key.
QString webAddress() const
The home page or a relevant link.
QString organizationDomain() const
Returns the domain name of the organization that wrote this application.
QString text() const
Returns the full license text.
K4AboutData & setLicenseTextFile(const QString &file)
Defines a license text by pointing to a file where it resides.
K4AboutData & operator=(const K4AboutData &other)
Assignment operator.
K4AboutPerson(const KLocalizedString &name, const KLocalizedString &task=KLocalizedString(), const QByteArray &emailAddress=QByteArray(), const QByteArray &webAddress=QByteArray())
Convenience constructor.
Definition: k4aboutdata.cpp:67
QHash::iterator insert(const Key &key, const T &value)
QString name(K4AboutData::NameFormat formatName) const
Returns the license name.
bool customAuthorTextEnabled() const
Returns whether custom text should be displayed around the list of authors.
QString toString() const
const char * internalProgramName() const
LicenseKey
Describes the license of the software.
Definition: k4aboutdata.h:205
const char * internalVersion() const
QString emailAddress() const
The person&#39;s email address.
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
K4AboutData & setHomepage(const QByteArray &homepage)
Defines the program homepage.
QString productName() const
Returns the application&#39;s product name, which will be used in KBugReport dialog.
QString ocsProviderUrl() const
Returns the chosen Open Collaboration Services provider URL.
const char * internalBugAddress() const
K4AboutData & setCatalogName(const QByteArray &catalogName)
Defines the translation catalog that the program uses.
QString catalogName() const
Returns the program&#39;s translation catalog name.
QString appName() const
Returns the application&#39;s internal name.
QString task() const
The person&#39;s task.
QString customAuthorPlainText() const
Returns the plain text displayed around the list of authors instead of the default message telling us...
QString & remove(int position, int n)
K4AboutData & setTranslator(const KLocalizedString &name, const KLocalizedString &emailAddress)
Sets the name(s) of the translator(s) of the GUI.
K4AboutData & setOrganizationDomain(const QByteArray &domain)
Defines the Internet domain of the organization that wrote this application.
K4AboutData & setProgramLogo(const QVariant &image)
Defines the program logo.
QString otherText() const
Returns a translated, free form text.
K4AboutLicense & operator=(const K4AboutLicense &other)
Assignment operator.
void translateInternalProgramName() const
QString programIconName() const
Returns the program&#39;s icon name.
K4AboutData & unsetCustomAuthorText()
Clears any custom text displayed around the list of authors and falls back to the default message tel...
K4AboutData & setProductName(const QByteArray &name)
Defines the product name which will be used in the KBugReport dialog.
K4AboutData & setOtherText(const KLocalizedString &otherText)
Defines the additional text to show in the about dialog.
K4AboutData & setVersion(const QByteArray &version)
Defines the program version string.
K4AboutData & setLicense(LicenseKey licenseKey)
Defines the license identifier.
void append(const T &value)
QString fromUtf8(const char *str, int size)
QString homepage() const
Returns the application homepage.
QList< K4AboutPerson > credits() const
Returns a list of persons who contributed.
KAboutData & addLicenseTextFile(const QString &file)
QString shortDescription() const
Returns a short, translated description.
QString ocsUsername() const
The person&#39;s Open Collaboration Services username.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isEmpty() const const
QString trimmed() const const
QList< K4AboutPerson > authors() const
Returns a list of authors.
K4AboutData & setLicenseText(const KLocalizedString &license)
Defines a license text, which is marked for translation.
QString programName() const
Returns the translated program name.
KAboutData & addLicense(KAboutLicense::LicenseKey licenseKey)
K4AboutData & setProgramIconName(const QString &iconName)
Defines the program icon.
virtual bool open(QIODevice::OpenMode mode) override
static K4AboutLicense byKeyword(const QString &keyword)
Fetch a known license by a keyword.
QList< K4AboutPerson > translators() const
Returns a list of translators.
This class is used to store information about a program.
Definition: k4aboutdata.h:199
static KLocale * global()
Return the global KLocale instance.
Definition: klocale.cpp:309
QString toLower() const const
const T value(const Key &key) const const
K4AboutData & setShortDescription(const KLocalizedString &shortDescription)
Defines a short description of what the program does.
K4AboutLicense(const K4AboutLicense &other)
Copy constructor.
K4AboutData & setProgramName(const KLocalizedString &programName)
Defines the displayable program name string.
QString version() const
Returns the program&#39;s version.
QList< K4AboutLicense > licenses() const
Returns a list of licenses.
This class is used to store information about a person or developer.
Definition: k4aboutdata.h:76
QString licenseName(NameFormat formatName) const
Returns the license name.
QString i18n(const char *text, const TYPE &arg...)
K4AboutData(const QByteArray &appName, const QByteArray &catalogName, const KLocalizedString &programName, const QByteArray &version, const KLocalizedString &shortDescription=KLocalizedString(), enum LicenseKey licenseType=License_Unknown, const KLocalizedString &copyrightStatement=KLocalizedString(), const KLocalizedString &otherText=KLocalizedString(), const QByteArray &homePageAddress=QByteArray(), const QByteArray &bugsEmailAddress="[email protected].kde.org")
Constructor.
KAboutData & addLicenseText(const QString &license)
KLocalizedString KI18N_EXPORT ki18nc(const char *context, const char *text)
QByteArray toLatin1() const const
K4AboutData & addAuthor(const KLocalizedString &name, const KLocalizedString &task=KLocalizedString(), const QByteArray &emailAddress=QByteArray(), const QByteArray &webAddress=QByteArray())
Defines an author.
K4AboutData & setCopyrightStatement(const KLocalizedString &copyrightStatement)
Defines the copyright statement to show when displaying the license.
KLocale provides support for language and country specific stuff.
Definition: klocale.h:75
K4AboutData & setOcsProvider(const QByteArray &providerUrl)
Specifies an Open Collaboration Services provider by URL.
K4AboutData & addCredit(const KLocalizedString &name, const KLocalizedString &task=KLocalizedString(), const QByteArray &emailAddress=QByteArray(), const QByteArray &webAddress=QByteArray())
Defines a person that deserves credit.
static QString aboutTranslationTeam()
Returns a message about the translation team.
bool isEmpty() const const
QString customAuthorRichText() const
Returns the rich text displayed around the list of authors instead of the default message telling use...
char * data()
QString fromLatin1(const char *str, int size)
QString license() const
Returns the license.
QString name() const
The person&#39;s name.
K4AboutData & addLicense(LicenseKey licenseKey)
Adds a license identifier.
K4AboutPerson & operator=(const K4AboutPerson &other)
Assignment operator.
K4AboutData & setCustomAuthorText(const KLocalizedString &plainText, const KLocalizedString &richText)
Sets the custom text displayed around the list of authors instead of the default message telling user...
QString bugAddress() const
Returns the email address for bugs.
K4AboutData & setAppName(const QByteArray &appName)
Defines the program name used internally.
QString readAll()
K4AboutData & addLicenseText(const KLocalizedString &license)
Adds a license text, which is marked for translation.
QVariant programLogo() const
Returns the program logo image.
K4AboutData & setBugAddress(const QByteArray &bugAddress)
Defines the address where bug reports should be sent.
K4AboutData & addLicenseTextFile(const QString &file)
Adds a license text by pointing to a file where it resides.
QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options)
NameFormat
Format of the license name.
Definition: k4aboutdata.h:224
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed May 27 2020 22:55:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.