<commit_before>/*
  This file is part of KDE Kontact.

  Copyright (c) 2003 <NAME> <<EMAIL>>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program 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 General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/

#include "aboutdialog.h"
#include "core.h"
#include "plugin.h"

#include <kdebug.h>
#include <klocale.h>
#include <kcomponentdata.h>
#include <kaboutdata.h>
#include <ktextbrowser.h>
#include <kicon.h>

#include <QLayout>
#include <QLabel>
#include <QTextEdit>

using namespace Kontact;

AboutDialog::AboutDialog( Kontact::Core *core )
  : KPageDialog( core ), mCore( core )
{
  setCaption( i18n( "About Kontact" ) );
  setButtons( Ok );
  setDefaultButton( Ok );
  setModal( false );
  showButtonSeparator( true );
  setFaceType( KPageDialog::List );
  addAboutData( i18n( "Kontact Container" ), QString( "kontact" ),
                KGlobal::mainComponent().aboutData() );

  QList<Plugin*> plugins = mCore->pluginList();
  QList<Plugin*>::ConstIterator end = plugins.constEnd();
  QList<Plugin*>::ConstIterator it = plugins.constBegin();
  for ( ; it != end; ++it ) {
    addAboutPlugin( *it );
  }

  addLicenseText( KGlobal::mainComponent().aboutData() );

  setInitialSize( QSize( 600, 400 ) );
  restoreDialogSize( KConfigGroup( KGlobal::config(), "AboutDialog" ) );
  connect( this, SIGNAL(finished(int)), this, SLOT(saveSize()) );
}

void AboutDialog::saveSize()
{
  KConfigGroup group( KGlobal::config(), "AboutDialog" );
  saveDialogSize( group );
  group.sync();
}

void AboutDialog::addAboutPlugin( Kontact::Plugin *plugin )
{
  addAboutData( plugin->title(), plugin->icon(), plugin->aboutData() );
}

void AboutDialog::addAboutData( const QString &title, const QString &icon,
                                const KAboutData *about )
{
  QIcon pixmap = KIcon( icon );

  QFrame *topFrame = new QFrame();
  KPageWidgetItem *pageItem = new KPageWidgetItem( topFrame, title );
  pageItem->setIcon( KIcon( pixmap ) );

  addPage( pageItem );

  QBoxLayout *topLayout = new QVBoxLayout( topFrame );

  if ( !about ) {
    QLabel *label = new QLabel( i18n( "No about information available." ), topFrame );
    topLayout->addWidget( label );
  } else {
    QString text;

    text += "<p>";
    text += "<b>" + about->programName() + "</b>";
    text += "<br>";

    text += i18n( "Version %1", about->version() );
    text += "</p>";

    if ( !about->shortDescription().isEmpty() ) {
      text += "<p>" + about->shortDescription() + "<br>" +
               about->copyrightStatement() + "</p>";
    }

    QString home = about->homepage();
    if ( !home.isEmpty() ) {
      text += "<a href=\"" + home + "\">" + home + "</a><br>";
    }

    text.replace( "\n", "<br>" );

    QLabel *label = new QLabel( text, topFrame );
    label->setAlignment( Qt::AlignTop );
    label->setOpenExternalLinks(true);
    label->setTextInteractionFlags(
      Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard | Qt::LinksAccessibleByMouse );
    topLayout->addWidget( label );

    QTextEdit *personView = new QTextEdit( topFrame ); //krazy:exclude=qclasses
    personView->setReadOnly( true );
    topLayout->addWidget( personView, 1 );

    text = "";

    text +="\
    <i>This Free Software product was improved as part of a commercial project:</i>\
    <h3>Credits</h3>\
    v20080902.2  Project Kowi (March 2007 - )<br /><br />\
    \
    <b>Production / Project Coordination</b><br />\<commit_msg>No date code here.<commit_after>/*
  This file is part of KDE Kontact.

  Copyright (c) 2003 <NAME> <<EMAIL>>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program 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 General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  As a special exception, permission is given to link this program
  with any edition of Qt, and distribute the resulting executable,
  without including the source code for Qt in the source distribution.
*/

#include "aboutdialog.h"
#include "core.h"
#include "plugin.h"

#include <kdebug.h>
#include <klocale.h>
#include <kcomponentdata.h>
#include <kaboutdata.h>
#include <ktextbrowser.h>
#include <kicon.h>

#include <QLayout>
#include <QLabel>
#include <QTextEdit>

using namespace Kontact;

AboutDialog::AboutDialog( Kontact::Core *core )
  : KPageDialog( core ), mCore( core )
{
  setCaption( i18n( "About Kontact" ) );
  setButtons( Ok );
  setDefaultButton( Ok );
  setModal( false );
  showButtonSeparator( true );
  setFaceType( KPageDialog::List );
  addAboutData( i18n( "Kontact Container" ), QString( "kontact" ),
                KGlobal::mainComponent().aboutData() );

  QList<Plugin*> plugins = mCore->pluginList();
  QList<Plugin*>::ConstIterator end = plugins.constEnd();
  QList<Plugin*>::ConstIterator it = plugins.constBegin();
  for ( ; it != end; ++it ) {
    addAboutPlugin( *it );
  }

  addLicenseText( KGlobal::mainComponent().aboutData() );

  setInitialSize( QSize( 600, 400 ) );
  restoreDialogSize( KConfigGroup( KGlobal::config(), "AboutDialog" ) );
  connect( this, SIGNAL(finished(int)), this, SLOT(saveSize()) );
}

void AboutDialog::saveSize()
{
  KConfigGroup group( KGlobal::config(), "AboutDialog" );
  saveDialogSize( group );
  group.sync();
}

void AboutDialog::addAboutPlugin( Kontact::Plugin *plugin )
{
  addAboutData( plugin->title(), plugin->icon(), plugin->aboutData() );
}

void AboutDialog::addAboutData( const QString &title, const QString &icon,
                                const KAboutData *about )
{
  QIcon pixmap = KIcon( icon );

  QFrame *topFrame = new QFrame();
  KPageWidgetItem *pageItem = new KPageWidgetItem( topFrame, title );
  pageItem->setIcon( KIcon( pixmap ) );

  addPage( pageItem );

  QBoxLayout *topLayout = new QVBoxLayout( topFrame );

  if ( !about ) {
    QLabel *label = new QLabel( i18n( "No about information available." ), topFrame );
    topLayout->addWidget( label );
  } else {
    QString text;

    text += "<p>";
    text += "<b>" + about->programName() + "</b>";
    text += "<br>";

    text += i18n( "Version %1", about->version() );
    text += "</p>";

    if ( !about->shortDescription().isEmpty() ) {
      text += "<p>" + about->shortDescription() + "<br>" +
               about->copyrightStatement() + "</p>";
    }

    QString home = about->homepage();
    if ( !home.isEmpty() ) {
      text += "<a href=\"" + home + "\">" + home + "</a><br>";
    }

    text.replace( "\n", "<br>" );

    QLabel *label = new QLabel( text, topFrame );
    label->setAlignment( Qt::AlignTop );
    label->setOpenExternalLinks(true);
    label->setTextInteractionFlags(
      Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard | Qt::LinksAccessibleByMouse );
    topLayout->addWidget( label );

    QTextEdit *personView = new QTextEdit( topFrame ); //krazy:exclude=qclasses
    personView->setReadOnly( true );
    topLayout->addWidget( personView, 1 );

    text = "";

    text +="\
    <i>This Free Software product was improved as part of a commercial project:</i>\
    <h3>Credits</h3>\
    Project Kowi (March 2007 - )<br /><br />\
    \
    <b>Production / Project Coordination</b><br />\
{'fraction_non_alphanumeric': 0.13946305535756712, 'fraction_numerical': 0.010097410311237823, 'mean_word_length': 3.6668514412416853, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1047119', 'n_tokens_mistral': 2646, 'n_tokens_neox': 2545, 'n_words': 802}