• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

  • kdecore
kaboutdata.cpp
1 /*
2  * This file is part of the KDE Libraries
3  * Copyright (C) 2000 Espen Sand (espen@kde.org)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  *
20  */
21 
22 
23 #include <kaboutdata.h>
24 #include <kstandarddirs.h>
25 #include <tqfile.h>
26 #include <tqtextstream.h>
27 
28 TQString
29 KAboutPerson::name() const
30 {
31  return TQString::fromUtf8(mName);
32 }
33 
34 TQString
35 KAboutPerson::task() const
36 {
37  if (mTask && *mTask)
38  return i18n(mTask);
39  else
40  return TQString::null;
41 }
42 
43 TQString
44 KAboutPerson::emailAddress() const
45 {
46  return TQString::fromUtf8(mEmailAddress);
47 }
48 
49 
50 TQString
51 KAboutPerson::webAddress() const
52 {
53  return TQString::fromUtf8(mWebAddress);
54 }
55 
56 
57 KAboutTranslator::KAboutTranslator(const TQString & name,
58  const TQString & emailAddress)
59 {
60  mName=name;
61  mEmail=emailAddress;
62 }
63 
64 TQString KAboutTranslator::name() const
65 {
66  return mName;
67 }
68 
69 TQString KAboutTranslator::emailAddress() const
70 {
71  return mEmail;
72 }
73 
74 class KAboutDataPrivate
75 {
76 public:
77  KAboutDataPrivate()
78  : translatorName("_: NAME OF TRANSLATORS\nYour names")
79  , translatorEmail("_: EMAIL OF TRANSLATORS\nYour emails")
80  , productName(0)
81  , programLogo(0)
82  , customAuthorTextEnabled(false)
83  , mTranslatedProgramName( 0 )
84  {}
85  ~KAboutDataPrivate()
86  {
87  delete programLogo;
88  delete[] mTranslatedProgramName;
89  }
90  const char *translatorName;
91  const char *translatorEmail;
92  const char *productName;
93  TQImage* programLogo;
94  TQString customAuthorPlainText, customAuthorRichText;
95  bool customAuthorTextEnabled;
96  const char *mTranslatedProgramName;
97 };
98 
99 const char *KAboutData::defaultBugTracker = "http://bugs.trinitydesktop.org";
100 
101 KAboutData::KAboutData( const char *appName,
102  const char *programName,
103  const char *version,
104  const char *shortDescription,
105  int licenseType,
106  const char *copyrightStatement,
107  const char *text,
108  const char *homePageAddress,
109  const char *bugsEmailAddress
110  ) :
111  mProgramName( programName ),
112  mVersion( version ),
113  mShortDescription( shortDescription ),
114  mLicenseKey( licenseType ),
115  mCopyrightStatement( copyrightStatement ),
116  mOtherText( text ),
117  mHomepageAddress( homePageAddress ),
118  mBugEmailAddress( (bugsEmailAddress!=0)?bugsEmailAddress:defaultBugTracker ),
119  mLicenseText (0)
120 {
121  d = new KAboutDataPrivate;
122 
123  if( appName ) {
124  const char *p = strrchr(appName, '/');
125  if( p )
126  mAppName = p+1;
127  else
128  mAppName = appName;
129  } else
130  mAppName = 0;
131 }
132 
133 KAboutData::~KAboutData()
134 {
135  if (mLicenseKey == License_File)
136  delete [] mLicenseText;
137  delete d;
138 }
139 
140 void
141 KAboutData::addAuthor( const char *name, const char *task,
142  const char *emailAddress, const char *webAddress )
143 {
144  mAuthorList.append(KAboutPerson(name,task,emailAddress,webAddress));
145 }
146 
147 void
148 KAboutData::addCredit( const char *name, const char *task,
149  const char *emailAddress, const char *webAddress )
150 {
151  mCreditList.append(KAboutPerson(name,task,emailAddress,webAddress));
152 }
153 
154 void
155 KAboutData::setTranslator( const char *name, const char *emailAddress)
156 {
157  d->translatorName=name;
158  d->translatorEmail=emailAddress;
159 }
160 
161 void
162 KAboutData::setLicenseText( const char *licenseText )
163 {
164  mLicenseText = licenseText;
165  mLicenseKey = License_Custom;
166 }
167 
168 void
169 KAboutData::setLicenseTextFile( const TQString &file )
170 {
171  mLicenseText = qstrdup(TQFile::encodeName(file));
172  mLicenseKey = License_File;
173 }
174 
175 void
176 KAboutData::setAppName( const char *appName )
177 {
178  mAppName = appName;
179 }
180 
181 void
182 KAboutData::setProgramName( const char* programName )
183 {
184  mProgramName = programName;
185  translateInternalProgramName();
186 }
187 
188 void
189 KAboutData::setVersion( const char* version )
190 {
191  mVersion = version;
192 }
193 
194 void
195 KAboutData::setShortDescription( const char *shortDescription )
196 {
197  mShortDescription = shortDescription;
198 }
199 
200 void
201 KAboutData::setLicense( LicenseKey licenseKey)
202 {
203  mLicenseKey = licenseKey;
204 }
205 
206 void
207 KAboutData::setCopyrightStatement( const char *copyrightStatement )
208 {
209  mCopyrightStatement = copyrightStatement;
210 }
211 
212 void
213 KAboutData::setOtherText( const char *otherText )
214 {
215  mOtherText = otherText;
216 }
217 
218 void
219 KAboutData::setHomepage( const char *homepage )
220 {
221  mHomepageAddress = homepage;
222 }
223 
224 void
225 KAboutData::setBugAddress( const char *bugAddress )
226 {
227  mBugEmailAddress = bugAddress;
228 }
229 
230 void
231 KAboutData::setProductName( const char *productName )
232 {
233  d->productName = productName;
234 }
235 
236 const char *
237 KAboutData::appName() const
238 {
239  return mAppName;
240 }
241 
242 const char *
243 KAboutData::productName() const
244 {
245  if (d->productName)
246  return d->productName;
247  else
248  return appName();
249 }
250 
251 TQString
252 KAboutData::programName() const
253 {
254  if (mProgramName && *mProgramName)
255  return i18n(mProgramName);
256  else
257  return TQString::null;
258 }
259 
260 const char*
261 KAboutData::internalProgramName() const
262 {
263  if (d->mTranslatedProgramName)
264  return d->mTranslatedProgramName;
265  else
266  return mProgramName;
267 }
268 
269 // KCrash should call as few things as possible and should avoid e.g. malloc()
270 // because it may deadlock. Since i18n() needs it, when KLocale is available
271 // the i18n() call will be done here in advance.
272 void
273 KAboutData::translateInternalProgramName() const
274 {
275  delete[] d->mTranslatedProgramName;
276  d->mTranslatedProgramName = 0;
277  if( KGlobal::locale() )
278  d->mTranslatedProgramName = qstrdup( programName().utf8());
279 }
280 
281 TQImage
282 KAboutData::programLogo() const
283 {
284  return d->programLogo ? (*d->programLogo) : TQImage();
285 }
286 
287 void
288 KAboutData::setProgramLogo(const TQImage& image)
289 {
290  if (!d->programLogo)
291  d->programLogo = new TQImage( image );
292  else
293  *d->programLogo = image;
294 }
295 
296 TQString
297 KAboutData::version() const
298 {
299  return TQString::fromLatin1(mVersion);
300 }
301 
302 TQString
303 KAboutData::shortDescription() const
304 {
305  if (mShortDescription && *mShortDescription)
306  return i18n(mShortDescription);
307  else
308  return TQString::null;
309 }
310 
311 TQString
312 KAboutData::homepage() const
313 {
314  return TQString::fromLatin1(mHomepageAddress);
315 }
316 
317 TQString
318 KAboutData::bugAddress() const
319 {
320  return TQString::fromLatin1(mBugEmailAddress);
321 }
322 
323 const TQValueList<KAboutPerson>
324 KAboutData::authors() const
325 {
326  return mAuthorList;
327 }
328 
329 const TQValueList<KAboutPerson>
330 KAboutData::credits() const
331 {
332  return mCreditList;
333 }
334 
335 const TQValueList<KAboutTranslator>
336 KAboutData::translators() const
337 {
338  TQValueList<KAboutTranslator> personList;
339 
340  if(d->translatorName == 0)
341  return personList;
342 
343  TQStringList nameList;
344  TQStringList emailList;
345 
346  TQString names = i18n(d->translatorName);
347  if(names != TQString::fromUtf8(d->translatorName))
348  {
349  nameList = TQStringList::split(',',names);
350  }
351 
352 
353  if(d->translatorEmail)
354  {
355  TQString emails = i18n(d->translatorEmail);
356 
357  if(emails != TQString::fromUtf8(d->translatorEmail))
358  {
359  emailList = TQStringList::split(',',emails,true);
360  }
361  }
362 
363 
364  TQStringList::Iterator nit;
365  TQStringList::Iterator eit=emailList.begin();
366 
367  for(nit = nameList.begin(); nit != nameList.end(); ++nit)
368  {
369  TQString email;
370  if(eit != emailList.end())
371  {
372  email=*eit;
373  ++eit;
374  }
375 
376  TQString name=*nit;
377 
378  personList.append(KAboutTranslator(name.stripWhiteSpace(), email.stripWhiteSpace()));
379  }
380 
381  return personList;
382 }
383 
384 TQString
385 KAboutData::aboutTranslationTeam()
386 {
387  return i18n("replace this with information about your translation team",
388  "<p>KDE is translated into many languages thanks to the work "
389  "of the translation teams all over the world.</p>"
390  "<p>For more information on KDE internationalization "
391  "visit <a href=\"http://l10n.kde.org\">http://l10n.kde.org</a></p>"
392  );
393 }
394 
395 TQString
396 KAboutData::otherText() const
397 {
398  if (mOtherText && *mOtherText)
399  return i18n(mOtherText);
400  else
401  return TQString::null;
402 }
403 
404 
405 TQString
406 KAboutData::license() const
407 {
408  TQString result;
409  if (!copyrightStatement().isEmpty())
410  result = copyrightStatement() + "\n\n";
411 
412  TQString l;
413  TQString f;
414  switch ( mLicenseKey )
415  {
416  case License_File:
417  f = TQFile::decodeName(mLicenseText);
418  break;
419  case License_GPL_V2:
420  l = "GPL v2";
421  f = locate("data", "LICENSES/GPL_V2");
422  break;
423  case License_LGPL_V2:
424  l = "LGPL v2";
425  f = locate("data", "LICENSES/LGPL_V2");
426  break;
427  case License_BSD:
428  l = "BSD License";
429  f = locate("data", "LICENSES/BSD");
430  break;
431  case License_Artistic:
432  l = "Artistic License";
433  f = locate("data", "LICENSES/ARTISTIC");
434  break;
435  case License_QPL_V1_0:
436  l = "QPL v1.0";
437  f = locate("data", "LICENSES/QPL_V1.0");
438  break;
439  case License_Custom:
440  if (mLicenseText && *mLicenseText)
441  return( i18n(mLicenseText) );
442  // fall through
443  default:
444  result += i18n("No licensing terms for this program have been specified.\n"
445  "Please check the documentation or the source for any\n"
446  "licensing terms.\n");
447  return result;
448  }
449 
450  if (!l.isEmpty())
451  result += i18n("This program is distributed under the terms of the %1.").arg( l );
452 
453  if (!f.isEmpty())
454  {
455  TQFile file(f);
456  if (file.open(IO_ReadOnly))
457  {
458  result += '\n';
459  result += '\n';
460  TQTextStream str(&file);
461  result += str.read();
462  }
463  }
464 
465  return result;
466 }
467 
468 TQString
469 KAboutData::copyrightStatement() const
470 {
471  if (mCopyrightStatement && *mCopyrightStatement)
472  return i18n(mCopyrightStatement);
473  else
474  return TQString::null;
475 }
476 
477 TQString
478 KAboutData::customAuthorPlainText() const
479 {
480  return d->customAuthorPlainText;
481 }
482 
483 TQString
484 KAboutData::customAuthorRichText() const
485 {
486  return d->customAuthorRichText;
487 }
488 
489 bool
490 KAboutData::customAuthorTextEnabled() const
491 {
492  return d->customAuthorTextEnabled;
493 }
494 
495 void
496 KAboutData::setCustomAuthorText(const TQString &plainText, const TQString &richText)
497 {
498  d->customAuthorPlainText = plainText;
499  d->customAuthorRichText = richText;
500 
501  d->customAuthorTextEnabled = true;
502 }
503 
504 void
505 KAboutData::unsetCustomAuthorText()
506 {
507  d->customAuthorPlainText = TQString::null;
508  d->customAuthorRichText = TQString::null;
509 
510  d->customAuthorTextEnabled = false;
511 }
512 

kdecore

Skip menu "kdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |