kontact
aboutdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "aboutdialog.h"
00026 #include "core.h"
00027 #include "plugin.h"
00028
00029 #include <kdebug.h>
00030 #include <klocale.h>
00031 #include <kcomponentdata.h>
00032 #include <kaboutdata.h>
00033 #include <ktextbrowser.h>
00034 #include <kicon.h>
00035
00036 #include <QLayout>
00037 #include <QLabel>
00038 #include <QTextEdit>
00039
00040 using namespace Kontact;
00041
00042 AboutDialog::AboutDialog( Kontact::Core *core )
00043 : KPageDialog( core ), mCore( core )
00044 {
00045 setCaption( i18n( "About Kontact" ) );
00046 setButtons( Ok );
00047 setDefaultButton( Ok );
00048 setModal( false );
00049 showButtonSeparator( true );
00050 setFaceType( KPageDialog::List );
00051 addAboutData( i18n( "Kontact Container" ), QString( "kontact" ),
00052 KGlobal::mainComponent().aboutData() );
00053
00054 QList<Plugin*> plugins = mCore->pluginList();
00055 QList<Plugin*>::ConstIterator end = plugins.end();
00056 QList<Plugin*>::ConstIterator it = plugins.begin();
00057 for ( ; it != end; ++it ) {
00058 addAboutPlugin( *it );
00059 }
00060
00061 addLicenseText( KGlobal::mainComponent().aboutData() );
00062
00063 setInitialSize( QSize( 600, 400 ) );
00064 restoreDialogSize( KConfigGroup( KGlobal::config(), "AboutDialog" ) );
00065 connect( this, SIGNAL(finished(int)), this, SLOT(saveSize()) );
00066 }
00067
00068 void AboutDialog::saveSize()
00069 {
00070 KConfigGroup group( KGlobal::config(), "AboutDialog" );
00071 saveDialogSize( group );
00072 group.sync();
00073 }
00074
00075 void AboutDialog::addAboutPlugin( Kontact::Plugin *plugin )
00076 {
00077 addAboutData( plugin->title(), plugin->icon(), plugin->aboutData() );
00078 }
00079
00080 void AboutDialog::addAboutData( const QString &title, const QString &icon,
00081 const KAboutData *about )
00082 {
00083 QIcon pixmap = KIcon( icon );
00084
00085 QFrame *topFrame = new QFrame();
00086 KPageWidgetItem *pageItem = new KPageWidgetItem( topFrame, title );
00087 pageItem->setIcon( KIcon( pixmap ) );
00088
00089 addPage( pageItem );
00090
00091 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00092
00093 if ( !about ) {
00094 QLabel *label = new QLabel( i18n( "No about information available." ), topFrame );
00095 topLayout->addWidget( label );
00096 } else {
00097 QString text;
00098
00099 text += "<p>";
00100 text += "<b>" + about->programName() + "</b>";
00101 text += "<br>";
00102
00103 text += i18n( "Version %1", about->version() );
00104 text += "</p>";
00105
00106 if ( !about->shortDescription().isEmpty() ) {
00107 text += "<p>" + about->shortDescription() + "<br>" +
00108 about->copyrightStatement() + "</p>";
00109 }
00110
00111 QString home = about->homepage();
00112 if ( !home.isEmpty() ) {
00113 text += "<a href=\"" + home + "\">" + home + "</a><br>";
00114 }
00115
00116 text.replace( "\n", "<br>" );
00117
00118 QLabel *label = new QLabel( text, topFrame );
00119 label->setAlignment( Qt::AlignTop );
00120 label->setOpenExternalLinks(true);
00121 label->setTextInteractionFlags(
00122 Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard | Qt::LinksAccessibleByMouse );
00123 topLayout->addWidget( label );
00124
00125 QTextEdit *personView = new QTextEdit( topFrame );
00126 personView->setReadOnly( true );
00127 topLayout->addWidget( personView, 1 );
00128
00129 text = "";
00130
00131 const QList<KAboutPerson> authors = about->authors();
00132 if ( !authors.isEmpty() ) {
00133 text += i18n( "<p><b>Authors:</b></p>" );
00134
00135 QList<KAboutPerson>::ConstIterator it;
00136 for ( it = authors.begin(); it != authors.end(); ++it ) {
00137 text += formatPerson( (*it).name(), (*it).emailAddress() );
00138 if ( !(*it).task().isEmpty() ) {
00139 text += "<i>" + (*it).task() + "</i><br>";
00140 }
00141 }
00142 }
00143
00144 const QList<KAboutPerson> credits = about->credits();
00145 if ( !credits.isEmpty() ) {
00146 text += i18n( "<p><b>Thanks to:</b></p>" );
00147
00148 QList<KAboutPerson>::ConstIterator it;
00149 for ( it = credits.begin(); it != credits.end(); ++it ) {
00150 text += formatPerson( (*it).name(), (*it).emailAddress() );
00151 if ( !(*it).task().isEmpty() ) {
00152 text += "<i>" + (*it).task() + "</i><br>";
00153 }
00154 }
00155 }
00156
00157 const QList<KAboutPerson> translators = about->translators();
00158 if ( !translators.isEmpty() ) {
00159 text += i18n( "<p><b>Translators:</b></p>" );
00160
00161 QList<KAboutPerson>::ConstIterator it;
00162 for ( it = translators.begin(); it != translators.end(); ++it ) {
00163 text += formatPerson( (*it).name(), (*it).emailAddress() );
00164 }
00165 }
00166
00167 personView->setText( text );
00168 }
00169 }
00170
00171 QString AboutDialog::formatPerson( const QString &name, const QString &email )
00172 {
00173 QString text = name;
00174 if ( !email.isEmpty() ) {
00175 text += " <<a href=\"mailto:" + email + "\">" + email + "</a>>";
00176 }
00177
00178 text += "<br>";
00179 return text;
00180 }
00181
00182 void AboutDialog::addLicenseText( const KAboutData *about )
00183 {
00184 if ( !about || about->license().isEmpty() ) {
00185 return;
00186 }
00187
00188 QPixmap pixmap = KIconLoader::global()->loadIcon( "help-about",
00189 KIconLoader::Desktop, 48 );
00190
00191 QString title = i18n( "%1 License", about->programName() );
00192
00193 QFrame *topFrame = new QFrame();
00194 KPageWidgetItem *page = new KPageWidgetItem( topFrame, title );
00195 page->setIcon( KIcon( pixmap ) );
00196 addPage( page );
00197 QBoxLayout *topLayout = new QVBoxLayout( topFrame );
00198
00199 KTextBrowser *textBrowser = new KTextBrowser( topFrame );
00200 textBrowser->setHtml( QString( "<pre>%1</pre>" ).arg( about->license() ) );
00201
00202 topLayout->addWidget( textBrowser );
00203 }
00204
00205 #include "aboutdialog.moc"