kontact

aboutdialog.cpp
1 /*
2  This file is part of KDE Kontact.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include "aboutdialog.h"
26 
27 #include "core.h"
28 #include "plugin.h"
29 
30 #include <tdelocale.h>
31 #include <kiconloader.h>
32 #include <tdeaboutdata.h>
33 #include <kactivelabel.h>
34 #include <ktextbrowser.h>
35 
36 #include <tqlayout.h>
37 #include <tqlabel.h>
38 
39 #include <kdebug.h>
40 
41 using namespace Kontact;
42 
43 AboutDialog::AboutDialog( Kontact::Core *core, const char *name )
44  : KDialogBase( IconList, i18n("About Kontact"), Ok, Ok, core, name, false,
45  true ),
46  mCore( core )
47 {
48  addAboutData( i18n( "Kontact Container" ), TQString( "kontact" ),
49  TDEGlobal::instance()->aboutData() );
50 
51  TQValueList<Plugin*> plugins = mCore->pluginList();
52  TQValueList<Plugin*>::ConstIterator end = plugins.end();
53  TQValueList<Plugin*>::ConstIterator it = plugins.begin();
54  for ( ; it != end; ++it )
55  addAboutPlugin( *it );
56 
57  addLicenseText( TDEGlobal::instance()->aboutData() );
58 }
59 
60 void AboutDialog::addAboutPlugin( Kontact::Plugin *plugin )
61 {
62  addAboutData( plugin->title(), plugin->icon(), plugin->aboutData() );
63 }
64 
65 void AboutDialog::addAboutData( const TQString &title, const TQString &icon,
66  const TDEAboutData *about )
67 {
68  TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon( icon,
69  TDEIcon::Desktop, 48 );
70 
71  TQFrame *topFrame = addPage( title, TQString(), pixmap );
72 
73  TQBoxLayout *topLayout = new TQVBoxLayout( topFrame );
74 
75  if ( !about ) {
76  TQLabel *label = new TQLabel( i18n( "No about information available." ),
77  topFrame );
78  topLayout->addWidget( label );
79  } else {
80  TQString text;
81 
82  text += "<p><b>" + about->programName() + "</b><br>";
83 
84  text += i18n( "Version %1</p>" ).arg( about->version() );
85 
86  if ( !about->shortDescription().isEmpty() ) {
87  text += "<p>" + about->shortDescription() + "<br>" +
88  about->copyrightStatement() + "</p>";
89  }
90 
91  TQString home = about->homepage();
92  if ( !home.isEmpty() ) {
93  text += "<a href=\"" + home + "\">" + home + "</a><br>";
94  }
95 
96  text.replace( "\n", "<br>" );
97 
98  KActiveLabel *label = new KActiveLabel( text, topFrame );
99  label->setAlignment( AlignTop );
100  topLayout->addWidget( label );
101 
102 
103  TQTextEdit *personView = new TQTextEdit( topFrame );
104  personView->setReadOnly( true );
105  topLayout->addWidget( personView, 1 );
106 
107  text = "";
108 
109  const TQValueList<TDEAboutPerson> authors = about->authors();
110  if ( !authors.isEmpty() ) {
111  text += i18n( "<p><b>Authors:</b></p>" );
112 
113  TQValueList<TDEAboutPerson>::ConstIterator it;
114  for ( it = authors.begin(); it != authors.end(); ++it ) {
115  text += formatPerson( (*it).name(), (*it).emailAddress() );
116  if ( !(*it).task().isEmpty() )
117  text += "<i>" + (*it).task() + "</i><br>";
118  }
119  }
120 
121  const TQValueList<TDEAboutPerson> credits = about->credits();
122  if ( !credits.isEmpty() ) {
123  text += i18n( "<p><b>Thanks to:</b></p>" );
124 
125  TQValueList<TDEAboutPerson>::ConstIterator it;
126  for ( it = credits.begin(); it != credits.end(); ++it ) {
127  text += formatPerson( (*it).name(), (*it).emailAddress() );
128  if ( !(*it).task().isEmpty() )
129  text += "<i>" + (*it).task() + "</i><br>";
130  }
131  }
132 
133  const TQValueList<TDEAboutTranslator> translators = about->translators();
134  if ( !translators.isEmpty() ) {
135  text += i18n("<p><b>Translators:</b></p>");
136 
137  TQValueList<TDEAboutTranslator>::ConstIterator it;
138  for ( it = translators.begin(); it != translators.end(); ++it ) {
139  text += formatPerson( (*it).name(), (*it).emailAddress() );
140  }
141  }
142 
143  personView->setText( text );
144  }
145 }
146 
147 TQString AboutDialog::formatPerson( const TQString &name, const TQString &email )
148 {
149  TQString text = name;
150  if ( !email.isEmpty() ) {
151  text += " &lt;<a href=\"mailto:" + email + "\">" + email + "</a>&gt;";
152  }
153 
154  text += "<br>";
155  return text;
156 }
157 
158 void AboutDialog::addLicenseText( const TDEAboutData *about )
159 {
160  if ( !about || about->license().isEmpty() )
161  return;
162 
163  TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon( "signature",
164  TDEIcon::Desktop, 48 );
165 
166  TQString title = i18n( "%1 License" ).arg( about->programName() );
167 
168  TQFrame *topFrame = addPage( title, TQString(), pixmap );
169  TQBoxLayout *topLayout = new TQVBoxLayout( topFrame );
170 
171  KTextBrowser *textBrowser = new KTextBrowser( topFrame );
172  textBrowser->setText( TQString( "<pre>%1</pre>" ).arg( about->license() ) );
173 
174  topLayout->addWidget( textBrowser );
175 }
176 
177 #include "aboutdialog.moc"
This class provides the interface to the Kontact core for the plugins.
Definition: core.h:42
Base class for all Plugins in Kontact.
Definition: plugin.h:59
virtual const TDEAboutData * aboutData()
Reimplement this method if you want to add your credits to the Kontact about dialog.
Definition: plugin.cpp:129
TQString title() const
Returns the localized title.
Definition: plugin.cpp:94
TQString icon() const
Returns the icon name.
Definition: plugin.cpp:104