/* This file is part of the KDE libraries Copyright (C) 2007 Urs Wolfer Copyright (C) 2008 Friedrich W. H. Kossebau Copyright (C) 2010 Teo Mrnjavac Parts of this class have been take from the KAboutApplication class, which was Copyright (C) 2000 Waldo Bastian (bastian@kde.org) and Espen Sand (espen@kde.org) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kaboutapplicationdialog.h" #include "kaboutapplicationpersonmodel_p.h" #include "kaboutapplicationpersonlistview_p.h" #include "kaboutapplicationpersonlistdelegate_p.h" #include "kdeui/icons/kiconloader.h" #include "kdeui/kernel/kapplication.h" #include "kdeui/kernel/kglobalsettings.h" #include "kdeui/widgets/ktitlewidget.h" #include #include #include #include #include #include #include #include #include #include #include class KAboutApplicationDialog::Private { public: Private(KAboutApplicationDialog *parent) : q(parent), aboutData(0) {} void init( const KAboutData *aboutData, Options opt ); void _k_showLicense( const QString &number ); KAboutApplicationDialog *q; const KAboutData *aboutData; }; KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, QWidget *parent) : KDialog(parent), d(new Private(this)) { d->init( aboutData, NoOptions ); } KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, Options opt, QWidget *parent) : KDialog(parent), d(new Private(this)) { d->init( aboutData, opt ); } void KAboutApplicationDialog::Private::init( const KAboutData *ad, Options opt ) { if (ad == 0) ad = KGlobal::mainComponent().aboutData(); aboutData = ad; if (!aboutData) { QLabel *errorLabel = new QLabel(i18n("No information available.
" "The supplied KAboutData object does not exist.
"), q); errorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); q->setMainWidget(errorLabel); return; } q->setWindowTitle(i18n("About %1", aboutData->programName())); q->setButtons(KDialog::Close); q->setDefaultButton(KDialog::Close); q->setModal(false); //Set up the title widget... KTitleWidget *titleWidget = new KTitleWidget(q); QIcon windowIcon; if (!aboutData->programIconName().isEmpty()) { windowIcon = KIcon(aboutData->programIconName()); } else { windowIcon = qApp->windowIcon(); } titleWidget->setPixmap(windowIcon.pixmap(64, 64), KTitleWidget::ImageLeft); if (aboutData->programLogo().canConvert()) titleWidget->setPixmap(aboutData->programLogo().value(), KTitleWidget::ImageLeft); else if (aboutData->programLogo().canConvert()) titleWidget->setPixmap(QPixmap::fromImage(aboutData->programLogo().value()), KTitleWidget::ImageLeft); if ( opt & HideKdeVersion ) titleWidget->setText(i18n("%1
Version %2
 ", aboutData->programName(), aboutData->version())); else titleWidget->setText(i18nc("Program name, version and Katana platform version; do not translate 'Development Platform'", "%1
Version %2
Using Katana Development Platform %3", aboutData->programName(), aboutData->version(), QString(KDE_VERSION_STRING))); //Then the tab bar... QTabWidget *tabWidget = new QTabWidget; tabWidget->setUsesScrollButtons(false); //Set up the first page... QString aboutPageText = aboutData->shortDescription() + '\n'; if (!aboutData->otherText().isEmpty()) aboutPageText += '\n' + aboutData->otherText() + '\n'; if (!aboutData->copyrightStatement().isEmpty()) aboutPageText += '\n' + aboutData->copyrightStatement() + '\n'; if (!aboutData->homepage().isEmpty()) aboutPageText += '\n' + QString("%1").arg(aboutData->homepage()) + '\n'; aboutPageText = aboutPageText.trimmed(); QLabel *aboutLabel = new QLabel; aboutLabel->setWordWrap(true); aboutLabel->setOpenExternalLinks(true); aboutLabel->setText(aboutPageText.replace('\n', "
")); aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); QVBoxLayout *aboutLayout = new QVBoxLayout; aboutLayout->addStretch(); aboutLayout->addWidget(aboutLabel); const int licenseCount = aboutData->licenses().count(); for (int i = 0; i < licenseCount; ++i) { const KAboutLicense &license = aboutData->licenses().at(i); QLabel *showLicenseLabel = new QLabel; showLicenseLabel->setText(QString("%2").arg(QString::number(i), i18n("License: %1", license.name(KAboutData::FullName)))); showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); connect(showLicenseLabel, SIGNAL(linkActivated(QString)), q, SLOT(_k_showLicense(QString))); aboutLayout->addWidget(showLicenseLabel); } aboutLayout->addStretch(); QWidget *aboutWidget = new QWidget(q); aboutWidget->setLayout(aboutLayout); tabWidget->addTab(aboutWidget, i18n("&About")); //Palette needed at least for translators... QPalette transparentBackgroundPalette; transparentBackgroundPalette.setColor(QPalette::Base, Qt::transparent); transparentBackgroundPalette.setColor(QPalette::Text, transparentBackgroundPalette.color(QPalette::WindowText)); //And here we go, authors page... const int authorCount = aboutData->authors().count(); if (authorCount) { QWidget *authorWidget = new QWidget( q ); QVBoxLayout *authorLayout = new QVBoxLayout( authorWidget ); authorLayout->setMargin( 0 ); if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) { QLabel *bugsLabel = new QLabel( authorWidget ); bugsLabel->setContentsMargins( 4, 2, 0, 4 ); bugsLabel->setOpenExternalLinks( true ); if (!aboutData->customAuthorTextEnabled()) { if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == BUG_REPORT_EMAIL) bugsLabel->setText( i18n("Please use %2 to report bugs.\n", QString(BUG_REPORT_URL), QString(BUG_REPORT_URL)) ); else { if( ( aboutData->authors().count() == 1 ) && ( aboutData->authors().first().emailAddress() == aboutData->bugAddress() ) ) { bugsLabel->setText( i18n("Please report bugs to %2.\n", aboutData->authors().first().emailAddress(), aboutData->authors().first().emailAddress() ) ); } else { bugsLabel->setText( i18n("Please report bugs to %2.\n", aboutData->bugAddress(), aboutData->bugAddress())); } } } else bugsLabel->setText( aboutData->customAuthorRichText() ); bugsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); authorLayout->addWidget( bugsLabel ); } KDEPrivate::KAboutApplicationPersonModel *authorModel = new KDEPrivate::KAboutApplicationPersonModel( aboutData->authors(), aboutData->ocsProviderUrl(), authorWidget ); KDEPrivate::KAboutApplicationPersonListView *authorView = new KDEPrivate::KAboutApplicationPersonListView( authorWidget ); KDEPrivate::KAboutApplicationPersonListDelegate *authorDelegate = new KDEPrivate::KAboutApplicationPersonListDelegate( authorView, authorView ); authorView->setModel( authorModel ); authorView->setItemDelegate( authorDelegate ); authorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); authorLayout->addWidget( authorView ); QString authorPageTitle = QString( ( authorCount == 1 ) ? i18n("A&uthor") : i18n("A&uthors") ); tabWidget->addTab( authorWidget, authorPageTitle ); } //And credits page... const int creditsCount = aboutData->credits().count(); if (creditsCount) { QWidget *creditWidget = new QWidget( q ); QVBoxLayout *creditLayout = new QVBoxLayout( creditWidget ); creditLayout->setMargin( 0 ); KDEPrivate::KAboutApplicationPersonModel *creditModel = new KDEPrivate::KAboutApplicationPersonModel( aboutData->credits(), aboutData->ocsProviderUrl(), creditWidget ); KDEPrivate::KAboutApplicationPersonListView *creditView = new KDEPrivate::KAboutApplicationPersonListView( creditWidget ); KDEPrivate::KAboutApplicationPersonListDelegate *creditDelegate = new KDEPrivate::KAboutApplicationPersonListDelegate( creditView, creditView ); creditView->setModel( creditModel ); creditView->setItemDelegate( creditDelegate ); creditView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); creditLayout->addWidget( creditView ); tabWidget->addTab( creditWidget, i18n("&Thanks To")); } //Finally, the optional translators page... if ( !( opt & HideTranslators ) ) { const int translatorsCount = aboutData->translators().count(); if( translatorsCount ) { QWidget *translatorWidget = new QWidget( q ); QVBoxLayout *translatorLayout = new QVBoxLayout( translatorWidget ); translatorLayout->setMargin( 0 ); KDEPrivate::KAboutApplicationPersonModel *translatorModel = new KDEPrivate::KAboutApplicationPersonModel( aboutData->translators(), aboutData->ocsProviderUrl(), translatorWidget ); KDEPrivate::KAboutApplicationPersonListView *translatorView = new KDEPrivate::KAboutApplicationPersonListView( translatorWidget ); KDEPrivate::KAboutApplicationPersonListDelegate *translatorDelegate = new KDEPrivate::KAboutApplicationPersonListDelegate( translatorView, translatorView ); translatorView->setModel( translatorModel ); translatorView->setItemDelegate( translatorDelegate ); translatorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); translatorLayout->addWidget( translatorView ); QString aboutTranslationTeam = KAboutData::aboutTranslationTeam(); if( !aboutTranslationTeam.isEmpty() ) { QLabel *translationTeamLabel = new QLabel( translatorWidget ); translationTeamLabel->setContentsMargins( 4, 2, 4, 4 ); translationTeamLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); translationTeamLabel->setWordWrap( true ); translationTeamLabel->setText( aboutTranslationTeam ); translationTeamLabel->setOpenExternalLinks( true ); translatorLayout->addWidget( translationTeamLabel ); //TODO: this could be displayed as a view item to save space } tabWidget->addTab( translatorWidget, i18n("T&ranslation")); } } //And we jam everything together in a layout... QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(titleWidget); mainLayout->addWidget(tabWidget); mainLayout->setMargin(0); QWidget *mainWidget = new QWidget; mainWidget->setLayout(mainLayout); q->setMainWidget(mainWidget); } KAboutApplicationDialog::~KAboutApplicationDialog() { delete d; // The delegate wants to be deleted before the items it created, otherwise // complains bitterly about it qDeleteAll(findChildren()); } void KAboutApplicationDialog::Private::_k_showLicense( const QString &number ) { KDialog *dialog = new KDialog(q); dialog->setAttribute( Qt::WA_DeleteOnClose ); dialog->setCaption(i18n("License Agreement")); dialog->setButtons(KDialog::Close); dialog->setDefaultButton(KDialog::Close); const QFont font = KGlobalSettings::fixedFont(); QFontMetrics metrics(font); const QString licenseText = aboutData->licenses().at(number.toInt()).text(); QTextBrowser *licenseBrowser = new QTextBrowser; licenseBrowser->setFont(font); licenseBrowser->setLineWrapMode(QTextEdit::NoWrap); licenseBrowser->setText(licenseText); dialog->setMainWidget(licenseBrowser); // try to set up the dialog such that the full width of the // document is visible without horizontal scroll-bars being required const qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint()) + licenseBrowser->verticalScrollBar()->width() * 2; // try to allow enough height for a reasonable number of lines to be shown const int idealHeight = metrics.height() * 30; dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight))); dialog->show(); } #include "moc_kaboutapplicationdialog.cpp"