<commit_before>/*
    This file is part of KMail.

    Copyright (c) 2004 Jakob Schr�er <js@camaya.net>

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

    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.

    In addition, as a special exception, the copyright holders give
    permission to link the code of this program with any edition of
    the Qt library by Trolltech AS, Norway (or with modified versions
    of Qt that use the same license as Qt), and distribute linked
    combinations including the two.  You must obey the GNU General
    Public License in all respects for all of the code used other than
    Qt.  If you modify this file, you may extend this exception to
    your version of the file, but you are not obligated to do so.  If
    you do not wish to do so, delete this exception statement from
    your version.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "xfaceconfigurator.h"

#include <kactivelabel.h>
#include <kdialog.h>
#include <kfiledialog.h>
#include <kglobalsettings.h>
#include <kimageio.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kurl.h>
#include <kio/netaccess.h>
//Added by qt3to4:
#include <QPixmap>
#include <QVBoxLayout>
#include <Q3Frame>
#include <QHBoxLayout>
using namespace KIO;
#include <kxface.h>
using namespace KPIM;
#include <kabc/stdaddressbook.h>
#include <kabc/addressee.h>
using namespace KABC;

#include <qbitmap.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpushbutton.h>

#include <QStackedWidget>

// #include <assert.h>

using namespace KMail;
using namespace KPIM;

namespace KMail {

  XFaceConfigurator::XFaceConfigurator( QWidget * parent, const char * name )
    : QWidget( parent, name )
  {
    // tmp. vars:
    QLabel * label;
    QLabel * label1;
    KActiveLabel * label2;
    QWidget * page;
    QVBoxLayout * vlay;
    QHBoxLayout * hlay;
    QVBoxLayout * page_vlay;
    QPushButton * mFromFileBtn;
    QPushButton * mFromAddrbkBtn;

    vlay = new QVBoxLayout( this, 0, KDialog::spacingHint(), "main layout" );
    hlay = new QHBoxLayout( vlay );

    // "enable X-Face" checkbox:
    mEnableCheck = new QCheckBox( i18n("&Send picture with every message"), this );
    mEnableCheck->setWhatsThis(
        i18n( "Check this box if you want KMail to add a so-called X-Face header to messages "
            "written with this identity. An X-Face is a small (48x48 pixels) black and "
            "white image that some mail clients are able to display." ) );
    hlay->addWidget( mEnableCheck, Qt::AlignLeft | Qt::AlignVCenter );

    mXFaceLabel = new QLabel( this );
    mXFaceLabel->setWhatsThis(
                    i18n( "This is a preview of the picture selected/entered below." ) );
    mXFaceLabel->setFixedSize(48, 48);
    mXFaceLabel->setFrameShape( Q3Frame::Box );
    hlay->addWidget( mXFaceLabel );

//     label1 = new QLabel( "X-Face:", this );
//     vlay->addWidget( label1 );

    // "obtain X-Face from" combo and label:
    hlay = new QHBoxLayout( vlay ); // inherits spacing
    mSourceCombo = new QComboBox( false, this );
    mSourceCombo->setWhatsThis(
                    i18n("Click on the widgets below to obtain help on the input methods."));
    mSourceCombo->setEnabled( false ); // since !mEnableCheck->isChecked()
    mSourceCombo->insertStringList( QStringList()
        << i18n( "continuation of \"obtain picture from\"",
                 "External Source" )
        << i18n( "continuation of \"obtain picture from\"",
                 "Input Field Below" ) );
    label = new QLabel( mSourceCombo,
                        i18n("Obtain pic&ture from:"), this );
    label->setEnabled( false ); // since !mEnableCheck->isChecked()
    hlay->addWidget( label );
    hlay->addWidget( mSourceCombo, 1 );

    // widget stack that is controlled by the source combo:
    QStackedWidget * widgetStack = new QStackedWidget( this );
    widgetStack->setEnabled( false ); // since !mEnableCheck->isChecked()
    vlay->addWidget( widgetStack, 1 );
    connect( mSourceCombo, SIGNAL(highlighted(int)),
             widgetStack, SLOT(raiseWidget(int)) );
    connect( mEnableCheck, SIGNAL(toggled(bool)),
             mSourceCombo, SLOT(setEnabled(bool)) );
    connect( mEnableCheck, SIGNAL(toggled(bool)),
             widgetStack, SLOT(setEnabled(bool)) );
    connect( mEnableCheck, SIGNAL(toggled(bool)),
             label, SLOT(setEnabled(bool)) );
    // The focus might be still in the widget that is disabled
    connect( mEnableCheck, SIGNAL(clicked()),
             mEnableCheck, SLOT(setFocus()) );

    int pageno = 0;
    // page 0: create X-Face from image file or address book entry
    page = new QWidget( widgetStack );
    widgetStack->insertWidget( pageno, page ); // force sequential numbers (play safe)
    page_vlay = new QVBoxLayout( page, 0, KDialog::spacingHint() );
    hlay = new QHBoxLayout( page_vlay ); // inherits spacing
    mFromFileBtn = new QPushButton( i18n("Select File..."), page );
    mFromFileBtn->setWhatsThis(
                     i18n("Use this to select an image file to create the picture from. "
                         "The image should be of high contrast and nearly quadratic shape. "
                         "A light background helps improve the result." ) );
    mFromFileBtn->setAutoDefault( false );
    page_vlay->addWidget( mFromFileBtn, 1 );
    connect( mFromFileBtn, SIGNAL(released()),
             this, SLOT(slotSelectFile()) );
    mFromAddrbkBtn = new QPushButton( i18n("Set From Address Book"), page );
    mFromAddrbkBtn->setWhatsThis(
                     i18n( "You can use a scaled-down version of the picture "
                         "you have set in your address book entry." ) );
    mFromAddrbkBtn->setAutoDefault( false );
    page_vlay->addWidget( mFromAddrbkBtn, 1 );
    connect( mFromAddrbkBtn, SIGNAL(released()),
             this, SLOT(slotSelectFromAddressbook()) );
    label1 = new QLabel( i18n("<qt>KMail can send a small (48x48 pixels), low-quality, "
        "monochrome picture with every message. "
        "For example, this could be a picture of you or a glyph. "
        "It is shown in the recipient's mail client (if supported)." ), page );
    label1->setAlignment( Qt::TextWordWrap | Qt::AlignVCenter );
    page_vlay->addWidget( label1 );

    widgetStack->setCurrentIndex( 0 ); // since mSourceCombo->currentItem() == 0

    // page 1: input field for direct entering
    ++pageno;
    page = new QWidget( widgetStack );
    widgetStack->insertWidget( pageno,page );
    page_vlay = new QVBoxLayout( page, 0, KDialog::spacingHint() );
    mTextEdit = new Q3TextEdit( page );
    page_vlay->addWidget( mTextEdit );
    mTextEdit->setWhatsThis( i18n( "Use this field to enter an arbitrary X-Face string." ) );
    mTextEdit->setFont( KGlobalSettings::fixedFont() );
    mTextEdit->setWrapPolicy( Q3TextEdit::Anywhere );
    mTextEdit->setTextFormat( Qt::PlainText );
    label2 = new KActiveLabel( i18n("Examples are available at http://www.xs4all.nl/~ace/X-Faces/."), page );
    page_vlay->addWidget( label2 );

    connect(mTextEdit, SIGNAL(textChanged()), this, SLOT(slotUpdateXFace()));
  }

  XFaceConfigurator::~XFaceConfigurator() {

  }

  bool XFaceConfigurator::isXFaceEnabled() const {
    return mEnableCheck->isChecked();
  }

  void XFaceConfigurator::setXFaceEnabled( bool enable ) {
    mEnableCheck->setChecked( enable );
  }

  QString XFaceConfigurator::xface() const {
    return mTextEdit->text();
  }

  void XFaceConfigurator::setXFace( const QString & text ) {
    mTextEdit->setText( text );
  }

  void XFaceConfigurator::setXfaceFromFile( const KURL &url )
  {
    QString tmpFile;
    if( KIO::NetAccess::download( url, tmpFile, this ) )
    {
      KXFace xf;
      mTextEdit->setText( xf.fromImage( QImage( tmpFile ) ) );
      KIO::NetAccess::removeTempFile( tmpFile );
    } else {
      KMessageBox::error(this, KIO::NetAccess::lastErrorString() );
    }
  }

  void XFaceConfigurator::slotSelectFile()
  {
    QStringList mimeTypes = KImageIO::mimeTypes (KImageIO::Reading);
    QString filter = mimeTypes.join (" ");
    KURL url = KFileDialog::getOpenURL( QString::null, filter, this, QString::null );
    if ( !url.isEmpty() )
      setXfaceFromFile( url );
  }

  void XFaceConfigurator::slotSelectFromAddressbook()
  {
    StdAddressBook *ab = StdAddressBook::self( true );
    Addressee me = ab->whoAmI();
    if ( !me.isEmpty() )
    {
      if ( me.photo().isIntern() )
      {
        QImage photo = me.photo().data();
        if ( !photo.isNull() )
        {
          KXFace xf;
          mTextEdit->setText( xf.fromImage( photo ) );
        }
        else
          KMessageBox::information( this, i18n("No picture set for your address book entry."), i18n("No Picture") );

      }
      else
      {
        KURL url = me.photo().url();
        if( !url.isEmpty() )
          setXfaceFromFile( url );
        else
          KMessageBox::information( this, i18n("No picture set for your address book entry."), i18n("No Picture") );
      }
    }
    else
      KMessageBox::information( this, i18n("You do not have your own contact defined in the address book."), i18n("No Picture") );
  }

  void XFaceConfigurator::slotUpdateXFace()
  {
    QString str = mTextEdit->text();
    if ( !str.isEmpty() )
    {
      if ( str.startsWith("x-face:", false) )
      {
        str = str.remove("x-face:", false);
        mTextEdit->setText(str);
      }
      KXFace xf;
      QPixmap p( 48, 48 );
      p.convertFromImage( xf.toImage(str) );
      mXFaceLabel->setPixmap( p );
    }
    else
      mXFaceLabel->setPixmap( 0L );
  }

} // namespace KMail

#include "xfaceconfigurator.moc"
<commit_msg>Fix crash: setPixmap(0L) makes crash kmail => use clear<commit_after>/*
    This file is part of KMail.

    Copyright (c) 2004 Jakob Schr�er <js@camaya.net>

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

    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.

    In addition, as a special exception, the copyright holders give
    permission to link the code of this program with any edition of
    the Qt library by Trolltech AS, Norway (or with modified versions
    of Qt that use the same license as Qt), and distribute linked
    combinations including the two.  You must obey the GNU General
    Public License in all respects for all of the code used other than
    Qt.  If you modify this file, you may extend this exception to
    your version of the file, but you are not obligated to do so.  If
    you do not wish to do so, delete this exception statement from
    your version.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "xfaceconfigurator.h"
#include <kactivelabel.h>
#include <kdialog.h>
#include <kfiledialog.h>
#include <kglobalsettings.h>
#include <kimageio.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kurl.h>
#include <kio/netaccess.h>
//Added by qt3to4:
#include <QPixmap>
#include <QVBoxLayout>
#include <Q3Frame>
#include <QHBoxLayout>
using namespace KIO;
#include <kxface.h>
using namespace KPIM;
#include <kabc/stdaddressbook.h>
#include <kabc/addressee.h>
using namespace KABC;

#include <qbitmap.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpushbutton.h>

#include <QStackedWidget>

// #include <assert.h>

using namespace KMail;
using namespace KPIM;

namespace KMail {

  XFaceConfigurator::XFaceConfigurator( QWidget * parent, const char * name )
    : QWidget( parent, name )
  {
    // tmp. vars:
    QLabel * label;
    QLabel * label1;
    KActiveLabel * label2;
    QWidget * page;
    QVBoxLayout * vlay;
    QHBoxLayout * hlay;
    QVBoxLayout * page_vlay;
    QPushButton * mFromFileBtn;
    QPushButton * mFromAddrbkBtn;

    vlay = new QVBoxLayout( this, 0, KDialog::spacingHint(), "main layout" );
    hlay = new QHBoxLayout( vlay );

    // "enable X-Face" checkbox:
    mEnableCheck = new QCheckBox( i18n("&Send picture with every message"), this );
    mEnableCheck->setWhatsThis(
        i18n( "Check this box if you want KMail to add a so-called X-Face header to messages "
            "written with this identity. An X-Face is a small (48x48 pixels) black and "
            "white image that some mail clients are able to display." ) );
    hlay->addWidget( mEnableCheck, Qt::AlignLeft | Qt::AlignVCenter );

    mXFaceLabel = new QLabel( this );
    mXFaceLabel->setWhatsThis(
                    i18n( "This is a preview of the picture selected/entered below." ) );
    mXFaceLabel->setFixedSize(48, 48);
    mXFaceLabel->setFrameShape( Q3Frame::Box );
    hlay->addWidget( mXFaceLabel );

//     label1 = new QLabel( "X-Face:", this );
//     vlay->addWidget( label1 );

    // "obtain X-Face from" combo and label:
    hlay = new QHBoxLayout( vlay ); // inherits spacing
    mSourceCombo = new QComboBox( false, this );
    mSourceCombo->setWhatsThis(
                    i18n("Click on the widgets below to obtain help on the input methods."));
    mSourceCombo->setEnabled( false ); // since !mEnableCheck->isChecked()
    mSourceCombo->insertStringList( QStringList()
        << i18n( "continuation of \"obtain picture from\"",
                 "External Source" )
        << i18n( "continuation of \"obtain picture from\"",
                 "Input Field Below" ) );
    label = new QLabel( mSourceCombo,
                        i18n("Obtain pic&ture from:"), this );
    label->setEnabled( false ); // since !mEnableCheck->isChecked()
    hlay->addWidget( label );
    hlay->addWidget( mSourceCombo, 1 );

    // widget stack that is controlled by the source combo:
    QStackedWidget * widgetStack = new QStackedWidget( this );
    widgetStack->setEnabled( false ); // since !mEnableCheck->isChecked()
    vlay->addWidget( widgetStack, 1 );
    connect( mSourceCombo, SIGNAL(highlighted(int)),
             widgetStack, SLOT(raiseWidget(int)) );
    connect( mEnableCheck, SIGNAL(toggled(bool)),
             mSourceCombo, SLOT(setEnabled(bool)) );
    connect( mEnableCheck, SIGNAL(toggled(bool)),
             widgetStack, SLOT(setEnabled(bool)) );
    connect( mEnableCheck, SIGNAL(toggled(bool)),
             label, SLOT(setEnabled(bool)) );
    // The focus might be still in the widget that is disabled
    connect( mEnableCheck, SIGNAL(clicked()),
             mEnableCheck, SLOT(setFocus()) );

    int pageno = 0;
    // page 0: create X-Face from image file or address book entry
    page = new QWidget( widgetStack );
    widgetStack->insertWidget( pageno, page ); // force sequential numbers (play safe)
    page_vlay = new QVBoxLayout( page, 0, KDialog::spacingHint() );
    hlay = new QHBoxLayout( page_vlay ); // inherits spacing
    mFromFileBtn = new QPushButton( i18n("Select File..."), page );
    mFromFileBtn->setWhatsThis(
                     i18n("Use this to select an image file to create the picture from. "
                         "The image should be of high contrast and nearly quadratic shape. "
                         "A light background helps improve the result." ) );
    mFromFileBtn->setAutoDefault( false );
    page_vlay->addWidget( mFromFileBtn, 1 );
    connect( mFromFileBtn, SIGNAL(released()),
             this, SLOT(slotSelectFile()) );
    mFromAddrbkBtn = new QPushButton( i18n("Set From Address Book"), page );
    mFromAddrbkBtn->setWhatsThis(
                     i18n( "You can use a scaled-down version of the picture "
                         "you have set in your address book entry." ) );
    mFromAddrbkBtn->setAutoDefault( false );
    page_vlay->addWidget( mFromAddrbkBtn, 1 );
    connect( mFromAddrbkBtn, SIGNAL(released()),
             this, SLOT(slotSelectFromAddressbook()) );
    label1 = new QLabel( i18n("<qt>KMail can send a small (48x48 pixels), low-quality, "
        "monochrome picture with every message. "
        "For example, this could be a picture of you or a glyph. "
        "It is shown in the recipient's mail client (if supported)." ), page );
    label1->setAlignment( Qt::TextWordWrap | Qt::AlignVCenter );
    page_vlay->addWidget( label1 );

    widgetStack->setCurrentIndex( 0 ); // since mSourceCombo->currentItem() == 0

    // page 1: input field for direct entering
    ++pageno;
    page = new QWidget( widgetStack );
    widgetStack->insertWidget( pageno,page );
    page_vlay = new QVBoxLayout( page, 0, KDialog::spacingHint() );
    mTextEdit = new Q3TextEdit( page );
    page_vlay->addWidget( mTextEdit );
    mTextEdit->setWhatsThis( i18n( "Use this field to enter an arbitrary X-Face string." ) );
    mTextEdit->setFont( KGlobalSettings::fixedFont() );
    mTextEdit->setWrapPolicy( Q3TextEdit::Anywhere );
    mTextEdit->setTextFormat( Qt::PlainText );
    label2 = new KActiveLabel( i18n("Examples are available at http://www.xs4all.nl/~ace/X-Faces/."), page );
    page_vlay->addWidget( label2 );

    connect(mTextEdit, SIGNAL(textChanged()), this, SLOT(slotUpdateXFace()));
  }

  XFaceConfigurator::~XFaceConfigurator() {

  }

  bool XFaceConfigurator::isXFaceEnabled() const {
    return mEnableCheck->isChecked();
  }

  void XFaceConfigurator::setXFaceEnabled( bool enable ) {
    mEnableCheck->setChecked( enable );
  }

  QString XFaceConfigurator::xface() const {
    return mTextEdit->text();
  }

  void XFaceConfigurator::setXFace( const QString & text ) {
    mTextEdit->setText( text );
  }

  void XFaceConfigurator::setXfaceFromFile( const KURL &url )
  {
    QString tmpFile;
    if( KIO::NetAccess::download( url, tmpFile, this ) )
    {
      KXFace xf;
      mTextEdit->setText( xf.fromImage( QImage( tmpFile ) ) );
      KIO::NetAccess::removeTempFile( tmpFile );
    } else {
      KMessageBox::error(this, KIO::NetAccess::lastErrorString() );
    }
  }

  void XFaceConfigurator::slotSelectFile()
  {
    QStringList mimeTypes = KImageIO::mimeTypes (KImageIO::Reading);
    QString filter = mimeTypes.join (" ");
    KURL url = KFileDialog::getOpenURL( QString::null, filter, this, QString::null );
    if ( !url.isEmpty() )
      setXfaceFromFile( url );
  }

  void XFaceConfigurator::slotSelectFromAddressbook()
  {
    StdAddressBook *ab = StdAddressBook::self( true );
    Addressee me = ab->whoAmI();
    if ( !me.isEmpty() )
    {
      if ( me.photo().isIntern() )
      {
        QImage photo = me.photo().data();
        if ( !photo.isNull() )
        {
          KXFace xf;
          mTextEdit->setText( xf.fromImage( photo ) );
        }
        else
          KMessageBox::information( this, i18n("No picture set for your address book entry."), i18n("No Picture") );

      }
      else
      {
        KURL url = me.photo().url();
        if( !url.isEmpty() )
          setXfaceFromFile( url );
        else
          KMessageBox::information( this, i18n("No picture set for your address book entry."), i18n("No Picture") );
      }
    }
    else
      KMessageBox::information( this, i18n("You do not have your own contact defined in the address book."), i18n("No Picture") );
  }

  void XFaceConfigurator::slotUpdateXFace()
  {
    QString str = mTextEdit->text();

    if ( !str.isEmpty() )
    {
      if ( str.startsWith("x-face:", false) )
      {
        str = str.remove("x-face:", false);
        mTextEdit->setText(str);
      }
      KXFace xf;
      QPixmap p( 48, 48 );
      p.convertFromImage( xf.toImage(str) );
      mXFaceLabel->setPixmap( p );
    }
    else
    {
      mXFaceLabel->clear();
    }
  }

} // namespace KMail

#include "xfaceconfigurator.moc"
<|endoftext|>


<commit_before>/**
 * @file lldate.cpp
 * @author Phoenix
 * @date 2006-02-05
 * @brief Implementation of the date class
 *
 * $LicenseInfo:firstyear=2006&license=viewergpl$
 *
 * Copyright (c) 2006-2009, Linden Research, Inc.
 *
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 *
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at
 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
 *
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 *
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "lldate.h"

#include "apr_time.h"

#include <time.h>
#include <locale.h>
#include <string>
#include <iomanip>
#include <sstream>

#include "lltimer.h"
#include "llstring.h"

static const F64 DATE_EPOCH = 0.0;

static const F64 LL_APR_USEC_PER_SEC = 1000000.0;
	// should be APR_USEC_PER_SEC, but that relies on INT64_C which
	// isn't defined in glib under our build set up for some reason

LLDate::LLDate() : mSecondsSinceEpoch(DATE_EPOCH)
{
}

LLDate::LLDate(const LLDate& date) :
	mSecondsSinceEpoch(date.mSecondsSinceEpoch)
{
}

LLDate::LLDate(F64 seconds_since_epoch) :
	mSecondsSinceEpoch(seconds_since_epoch)
{
}

LLDate::LLDate(const std::string& iso8601_date)
{
	if(!fromString(iso8601_date))
	{
		llwarns << "date " << iso8601_date << " failed to parse; "
			<< "ZEROING IT OUT" << llendl;
		mSecondsSinceEpoch = DATE_EPOCH;
	}
}

std::string LLDate::asString() const
{
	std::ostringstream stream;
	toStream(stream);
	return stream.str();
}

//@ brief Converts time in seconds since EPOCH
//        to RFC 1123 compliant date format
//        E.g. 1184797044.037586 == Wednesday, 18 Jul 2007 22:17:24 GMT
//        in RFC 1123. HTTP dates are always in GMT and RFC 1123
//        is one of the standards used and the prefered format
std::string LLDate::asRFC1123() const
{
	return toHTTPDateString (std::string ("%A, %d %b %Y %H:%M:%S GMT"));
}

LLFastTimer::DeclareTimer FT_DATE_FORMAT("Date Format");

std::string LLDate::toHTTPDateString (std::string fmt) const
{
	LLFastTimer ft1(FT_DATE_FORMAT);

	time_t locSeconds = (time_t) mSecondsSinceEpoch;
	struct tm * gmt = gmtime (&locSeconds);
	return toHTTPDateString(gmt, fmt);
}

std::string LLDate::toHTTPDateString (tm * gmt, std::string fmt)
{
	LLFastTimer ft1(FT_DATE_FORMAT);

	// avoid calling setlocale() unnecessarily - it's expensive.
	static std::string prev_locale = "";
	std::string this_locale = LLStringUtil::getLocale();
	if (this_locale != prev_locale)
	{
		setlocale(LC_TIME, this_locale.c_str());
		prev_locale = this_locale;
	}

	// use strftime() as it appears to be faster than std::time_put
	char buffer[128];
	strftime(buffer, 128, fmt.c_str(), gmt);
	return std::string(buffer);
}

void LLDate::toStream(std::ostream& s) const
{
	apr_time_t time = (apr_time_t)(mSecondsSinceEpoch * LL_APR_USEC_PER_SEC);

	apr_time_exp_t exp_time;
	if (apr_time_exp_gmt(&exp_time, time) != APR_SUCCESS)
	{
		s << "1970-01-01T00:00:00Z";
		return;
	}

	s << std::dec << std::setfill('0');
#if( LL_WINDOWS || __GNUC__ > 2)
	s << std::right;
#else
	s.setf(ios::right);
#endif
	s		 << std::setw(4) << (exp_time.tm_year + 1900)
	  << '-' << std::setw(2) << (exp_time.tm_mon + 1)
	  << '-' << std::setw(2) << (exp_time.tm_mday)
	  << 'T' << std::setw(2) << (exp_time.tm_hour)
	  << ':' << std::setw(2) << (exp_time.tm_min)
	  << ':' << std::setw(2) << (exp_time.tm_sec);
	if (exp_time.tm_usec > 0)
	{
		s << '.' << std::setw(2)
		  << (int)(exp_time.tm_usec / (LL_APR_USEC_PER_SEC / 100));
	}
	s << 'Z'
	  << std::setfill(' ');
}

bool LLDate::split(S32 *year, S32 *month, S32 *day, S32 *hour, S32 *min, S32 *sec) const
{
	apr_time_t time = (apr_time_t)(mSecondsSinceEpoch * LL_APR_USEC_PER_SEC);

	apr_time_exp_t exp_time;
	if (apr_time_exp_gmt(&exp_time, time) != APR_SUCCESS)
	{
		return false;
	}

	if (year)
		*year = exp_time.tm_year + 1900;

	if (month)
		*month = exp_time.tm_mon + 1;

	if (day)
		*day = exp_time.tm_mday;

	if (hour)
		*hour = exp_time.tm_hour;

	if (min)
		*min = exp_time.tm_min;

	if (sec)
		*sec = exp_time.tm_sec;

	return true;
}

bool LLDate::fromString(const std::string& iso8601_date)
{
	std::istringstream stream(iso8601_date);
	return fromStream(stream);
}

bool LLDate::fromStream(std::istream& s)
{
	struct apr_time_exp_t exp_time;
	apr_int32_t tm_part;
	int c;

	s >> tm_part;
	exp_time.tm_year = tm_part - 1900;
	c = s.get(); // skip the hypen
	if (c != '-') { return false; }
	s >> tm_part;
	exp_time.tm_mon = tm_part - 1;
	c = s.get(); // skip the hypen
	if (c != '-') { return false; }
	s >> tm_part;
	exp_time.tm_mday = tm_part;

	c = s.get(); // skip the T
	if (c != 'T') { return false; }

	s >> tm_part;
	exp_time.tm_hour = tm_part;
	c = s.get(); // skip the :
	if (c != ':') { return false; }
	s >> tm_part;
	exp_time.tm_min = tm_part;
	c = s.get(); // skip the :
	if (c != ':') { return false; }
	s >> tm_part;
	exp_time.tm_sec = tm_part;

	// zero out the unused fields
	exp_time.tm_usec = 0;
	exp_time.tm_wday = 0;
	exp_time.tm_yday = 0;
	exp_time.tm_isdst = 0;
	exp_time.tm_gmtoff = 0;

	// generate a time_t from that
	apr_time_t time;
	if (apr_time_exp_gmt_get(&time, &exp_time) != APR_SUCCESS)
	{
		return false;
	}

	F64 seconds_since_epoch = time / LL_APR_USEC_PER_SEC;

	// check for fractional
	c = s.peek();
	if(c == '.')
	{
		F64 fractional = 0.0;
		s >> fractional;
		seconds_since_epoch += fractional;
	}

	c = s.peek(); // check for offset
	if (c == '+' || c == '-')
	{
		S32 offset_sign = (c == '+') ? 1 : -1;
		S32 offset_hours = 0;
		S32 offset_minutes = 0;
		S32 offset_in_seconds = 0;

		s >> offset_hours;

		c = s.get(); // skip the colon a get the minutes if there are any
		if (c == ':')
		{
			s >> offset_minutes;
		}

		offset_in_seconds =  (offset_hours * 60 + offset_sign * offset_minutes) * 60;
		seconds_since_epoch -= offset_in_seconds;
	}
	else if (c != 'Z') { return false; } // skip the Z

	mSecondsSinceEpoch = seconds_since_epoch;
	return true;
}

bool LLDate::fromYMDHMS(S32 year, S32 month, S32 day, S32 hour, S32 min, S32 sec)
{
	struct apr_time_exp_t exp_time;

	exp_time.tm_year = year - 1900;
	exp_time.tm_mon = month - 1;
	exp_time.tm_mday = day;
	exp_time.tm_hour = hour;
	exp_time.tm_min = min;
	exp_time.tm_sec = sec;

	// zero out the unused fields
	exp_time.tm_usec = 0;
	exp_time.tm_wday = 0;
	exp_time.tm_yday = 0;
	exp_time.tm_isdst = 0;
	exp_time.tm_gmtoff = 0;

	// generate a time_t from that
	apr_time_t time;
	if (apr_time_exp_gmt_get(&time, &exp_time) != APR_SUCCESS)
	{
		return false;
	}

	mSecondsSinceEpoch = time / LL_APR_USEC_PER_SEC;

	return true;
}

F64 LLDate::secondsSinceEpoch() const
{
	return mSecondsSinceEpoch;
}

void LLDate::secondsSinceEpoch(F64 seconds)
{
	mSecondsSinceEpoch = seconds;
}

/* static */ LLDate LLDate::now()
{
	// time() returns seconds, we want fractions of a second, which LLTimer provides --RN
	return LLDate(LLTimer::getTotalSeconds());
}

bool LLDate::operator<(const LLDate& rhs) const
{
    return mSecondsSinceEpoch < rhs.mSecondsSinceEpoch;
}

std::ostream& operator<<(std::ostream& s, const LLDate& date)
{
	date.toStream(s);
	return s;
}

std::istream& operator>>(std::istream& s, LLDate& date)
{
	date.fromStream(s);
	return s;
}

<commit_msg>EXT-8524 FIXED Non-ASCII character corruption in date.<commit_after>/**
 * @file lldate.cpp
 * @author Phoenix
 * @date 2006-02-05
 * @brief Implementation of the date class
 *
 * $LicenseInfo:firstyear=2006&license=viewergpl$
 *
 * Copyright (c) 2006-2009, Linden Research, Inc.
 *
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 *
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at
 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
 *
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 *
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "lldate.h"

#include "apr_time.h"

#include <time.h>
#include <locale.h>
#include <string>
#include <iomanip>
#include <sstream>

#include "lltimer.h"
#include "llstring.h"

static const F64 DATE_EPOCH = 0.0;

static const F64 LL_APR_USEC_PER_SEC = 1000000.0;
	// should be APR_USEC_PER_SEC, but that relies on INT64_C which
	// isn't defined in glib under our build set up for some reason

LLDate::LLDate() : mSecondsSinceEpoch(DATE_EPOCH)
{
}

LLDate::LLDate(const LLDate& date) :
	mSecondsSinceEpoch(date.mSecondsSinceEpoch)
{
}

LLDate::LLDate(F64 seconds_since_epoch) :
	mSecondsSinceEpoch(seconds_since_epoch)
{
}

LLDate::LLDate(const std::string& iso8601_date)
{
	if(!fromString(iso8601_date))
	{
		llwarns << "date " << iso8601_date << " failed to parse; "
			<< "ZEROING IT OUT" << llendl;
		mSecondsSinceEpoch = DATE_EPOCH;
	}
}

std::string LLDate::asString() const
{
	std::ostringstream stream;
	toStream(stream);
	return stream.str();
}

//@ brief Converts time in seconds since EPOCH
//        to RFC 1123 compliant date format
//        E.g. 1184797044.037586 == Wednesday, 18 Jul 2007 22:17:24 GMT
//        in RFC 1123. HTTP dates are always in GMT and RFC 1123
//        is one of the standards used and the prefered format
std::string LLDate::asRFC1123() const
{
	return toHTTPDateString (std::string ("%A, %d %b %Y %H:%M:%S GMT"));
}

LLFastTimer::DeclareTimer FT_DATE_FORMAT("Date Format");

std::string LLDate::toHTTPDateString (std::string fmt) const
{
	LLFastTimer ft1(FT_DATE_FORMAT);

	time_t locSeconds = (time_t) mSecondsSinceEpoch;
	struct tm * gmt = gmtime (&locSeconds);
	return toHTTPDateString(gmt, fmt);
}

std::string LLDate::toHTTPDateString (tm * gmt, std::string fmt)
{
	LLFastTimer ft1(FT_DATE_FORMAT);

	// avoid calling setlocale() unnecessarily - it's expensive.
	static std::string prev_locale = "";
	std::string this_locale = LLStringUtil::getLocale();
	if (this_locale != prev_locale)
	{
		setlocale(LC_TIME, this_locale.c_str());
		prev_locale = this_locale;
	}

	// use strftime() as it appears to be faster than std::time_put
	char buffer[128];
	strftime(buffer, 128, fmt.c_str(), gmt);
	std::string res(buffer);
#if LL_WINDOWS
	// Convert from locale-dependant charset to UTF-8 (EXT-8524).
	res = ll_convert_string_to_utf8_string(res);
#endif
	return res;
}

void LLDate::toStream(std::ostream& s) const
{
	apr_time_t time = (apr_time_t)(mSecondsSinceEpoch * LL_APR_USEC_PER_SEC);

	apr_time_exp_t exp_time;
	if (apr_time_exp_gmt(&exp_time, time) != APR_SUCCESS)
	{
		s << "1970-01-01T00:00:00Z";
		return;
	}

	s << std::dec << std::setfill('0');
#if( LL_WINDOWS || __GNUC__ > 2)
	s << std::right;
#else
	s.setf(ios::right);
#endif
	s		 << std::setw(4) << (exp_time.tm_year + 1900)
	  << '-' << std::setw(2) << (exp_time.tm_mon + 1)
	  << '-' << std::setw(2) << (exp_time.tm_mday)
	  << 'T' << std::setw(2) << (exp_time.tm_hour)
	  << ':' << std::setw(2) << (exp_time.tm_min)
	  << ':' << std::setw(2) << (exp_time.tm_sec);
	if (exp_time.tm_usec > 0)
	{
		s << '.' << std::setw(2)
		  << (int)(exp_time.tm_usec / (LL_APR_USEC_PER_SEC / 100));
	}
	s << 'Z'
	  << std::setfill(' ');
}

bool LLDate::split(S32 *year, S32 *month, S32 *day, S32 *hour, S32 *min, S32 *sec) const
{
	apr_time_t time = (apr_time_t)(mSecondsSinceEpoch * LL_APR_USEC_PER_SEC);

	apr_time_exp_t exp_time;
	if (apr_time_exp_gmt(&exp_time, time) != APR_SUCCESS)
	{
		return false;
	}

	if (year)
		*year = exp_time.tm_year + 1900;

	if (month)
		*month = exp_time.tm_mon + 1;

	if (day)
		*day = exp_time.tm_mday;

	if (hour)
		*hour = exp_time.tm_hour;

	if (min)
		*min = exp_time.tm_min;

	if (sec)
		*sec = exp_time.tm_sec;

	return true;
}

bool LLDate::fromString(const std::string& iso8601_date)
{
	std::istringstream stream(iso8601_date);
	return fromStream(stream);
}

bool LLDate::fromStream(std::istream& s)
{
	struct apr_time_exp_t exp_time;
	apr_int32_t tm_part;
	int c;

	s >> tm_part;
	exp_time.tm_year = tm_part - 1900;
	c = s.get(); // skip the hypen
	if (c != '-') { return false; }
	s >> tm_part;
	exp_time.tm_mon = tm_part - 1;
	c = s.get(); // skip the hypen
	if (c != '-') { return false; }
	s >> tm_part;
	exp_time.tm_mday = tm_part;

	c = s.get(); // skip the T
	if (c != 'T') { return false; }

	s >> tm_part;
	exp_time.tm_hour = tm_part;
	c = s.get(); // skip the :
	if (c != ':') { return false; }
	s >> tm_part;
	exp_time.tm_min = tm_part;
	c = s.get(); // skip the :
	if (c != ':') { return false; }
	s >> tm_part;
	exp_time.tm_sec = tm_part;

	// zero out the unused fields
	exp_time.tm_usec = 0;
	exp_time.tm_wday = 0;
	exp_time.tm_yday = 0;
	exp_time.tm_isdst = 0;
	exp_time.tm_gmtoff = 0;

	// generate a time_t from that
	apr_time_t time;
	if (apr_time_exp_gmt_get(&time, &exp_time) != APR_SUCCESS)
	{
		return false;
	}

	F64 seconds_since_epoch = time / LL_APR_USEC_PER_SEC;

	// check for fractional
	c = s.peek();
	if(c == '.')
	{
		F64 fractional = 0.0;
		s >> fractional;
		seconds_since_epoch += fractional;
	}

	c = s.peek(); // check for offset
	if (c == '+' || c == '-')
	{
		S32 offset_sign = (c == '+') ? 1 : -1;
		S32 offset_hours = 0;
		S32 offset_minutes = 0;
		S32 offset_in_seconds = 0;

		s >> offset_hours;

		c = s.get(); // skip the colon a get the minutes if there are any
		if (c == ':')
		{
			s >> offset_minutes;
		}

		offset_in_seconds =  (offset_hours * 60 + offset_sign * offset_minutes) * 60;
		seconds_since_epoch -= offset_in_seconds;
	}
	else if (c != 'Z') { return false; } // skip the Z

	mSecondsSinceEpoch = seconds_since_epoch;
	return true;
}

bool LLDate::fromYMDHMS(S32 year, S32 month, S32 day, S32 hour, S32 min, S32 sec)
{
	struct apr_time_exp_t exp_time;

	exp_time.tm_year = year - 1900;
	exp_time.tm_mon = month - 1;
	exp_time.tm_mday = day;
	exp_time.tm_hour = hour;
	exp_time.tm_min = min;
	exp_time.tm_sec = sec;

	// zero out the unused fields
	exp_time.tm_usec = 0;
	exp_time.tm_wday = 0;
	exp_time.tm_yday = 0;
	exp_time.tm_isdst = 0;
	exp_time.tm_gmtoff = 0;

	// generate a time_t from that
	apr_time_t time;
	if (apr_time_exp_gmt_get(&time, &exp_time) != APR_SUCCESS)
	{
		return false;
	}

	mSecondsSinceEpoch = time / LL_APR_USEC_PER_SEC;

	return true;
}

F64 LLDate::secondsSinceEpoch() const
{
	return mSecondsSinceEpoch;
}

void LLDate::secondsSinceEpoch(F64 seconds)
{
	mSecondsSinceEpoch = seconds;
}

/* static */ LLDate LLDate::now()
{
	// time() returns seconds, we want fractions of a second, which LLTimer provides --RN
	return LLDate(LLTimer::getTotalSeconds());
}

bool LLDate::operator<(const LLDate& rhs) const
{
    return mSecondsSinceEpoch < rhs.mSecondsSinceEpoch;
}

std::ostream& operator<<(std::ostream& s, const LLDate& date)
{
	date.toStream(s);
	return s;
}

std::istream& operator>>(std::istream& s, LLDate& date)
{
	date.fromStream(s);
	return s;
}

<|endoftext|>


<commit_before>#include "ArchiveExtractor.h"
#include "BigFix/ArchiveReader.h"
#include "BigFix/ArgParser.h"
#include "BigFix/DataRef.h"
#include "BigFix/Filesystem.h"
#include "BigFix/InflateStream.h"
#include <iostream>

using namespace BigFix;

static void PrintUsage()
{
  std::cout
    << "Usage:\n"
       "  bfarchive -a <source file or directory> <name of archive>\n"
       "  bfarchive -x <source archive> <target directory>\n"
       "  bfarchive -l <source archive>\n"
       "\n"
       "Where:\n"
       "  -a, --archive    Create an archive\n"
       "  -h, --help       Print this help message\n"
       "  -l, --list       List the archive contents\n"
       "  -v, --verbose    Print every file and directory as it is processed\n"
       "  -V, --version    Print the version and exit\n"
       "  -x, --extract    Extract an archive\n";
}

int main( int argc, const char* argv[] )
{
  try
  {
    ArgParser argParser;
    argParser.AddOption( 'a', "archive" );
    argParser.AddOption( 'h', "help" );
    argParser.AddOption( 'l', "list" );
    argParser.AddOption( 'v', "verbose" );
    argParser.AddOption( 'V', "version" );
    argParser.AddOption( 'x', "extract" );
    argParser.Parse( argc, argv );

    if ( argParser.HasOption( 'h' ) )
    {
      PrintUsage();
    }
    else if ( argParser.HasOption( 'V' ) )
    {
      std::cout << "Print version\n";
    }
    else if ( argParser.HasOption( 'a' ) )
    {
      std::cout << "Create archive\n";

      if ( argParser.HasOption( 'v' ) )
        std::cout << "Verbose\n";
    }
    else if ( argParser.HasOption( 'x' ) )
    {
      std::cout << "Extract archive\n";

      if ( argParser.HasOption( 'v' ) )
        std::cout << "Verbose\n";
    }
    else if ( argParser.HasOption( 'l' ) )
    {
      std::cout << "List archive\n";
    }
    else
    {
      PrintUsage();
    }
  }
  catch ( const std::exception& err )
  {
    std::cerr << "Error: " << err.what() << std::endl;
    return 1;
  }

  return 0;
}
<commit_msg>Look for the long name so it's easier to read<commit_after>#include "ArchiveExtractor.h"
#include "BigFix/ArchiveReader.h"
#include "BigFix/ArgParser.h"
#include "BigFix/DataRef.h"
#include "BigFix/Filesystem.h"
#include "BigFix/InflateStream.h"
#include <iostream>

using namespace BigFix;

static void PrintUsage()
{
  std::cout
    << "Usage:\n"
       "  bfarchive -a <source file or directory> <name of archive>\n"
       "  bfarchive -x <source archive> <target directory>\n"
       "  bfarchive -l <source archive>\n"
       "\n"
       "Where:\n"
       "  -a, --create     Create an archive\n"
       "  -x, --extract    Extract an archive\n"
       "  -h, --help       Print this help message\n"
       "  -l, --list       List the archive contents\n"
       "  -v, --verbose    Print every file and directory as it is processed\n"
       "  -V, --version    Print the version and exit\n";
}

int main( int argc, const char* argv[] )
{
  try
  {
    ArgParser argParser;
    argParser.AddOption( 'a', "create" );
    argParser.AddOption( 'h', "help" );
    argParser.AddOption( 'l', "list" );
    argParser.AddOption( 'v', "verbose" );
    argParser.AddOption( 'V', "version" );
    argParser.AddOption( 'x', "extract" );
    argParser.Parse( argc, argv );

    if ( argParser.HasOption( "help" ) )
    {
      PrintUsage();
    }
    else if ( argParser.HasOption( "version" ) )
    {
      std::cout << "Print version\n";
    }
    else if ( argParser.HasOption( "create" ) )
    {
      std::cout << "Create archive\n";

      if ( argParser.HasOption( "verbose" ) )
        std::cout << "Verbose\n";
    }
    else if ( argParser.HasOption( "extract" ) )
    {
      std::cout << "Extract archive\n";

      if ( argParser.HasOption( "verbose" ) )
        std::cout << "Verbose\n";
    }
    else if ( argParser.HasOption( "list" ) )
    {
      std::cout << "List archive\n";
    }
    else
    {
      PrintUsage();
      return 1;
    }
  }
  catch ( const std::exception& err )
  {
    std::cerr << "Error: " << err.what() << std::endl;
    return 1;
  }

  return 0;
}
<|endoftext|>


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

  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>

  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 += "
";
    text += "" + about->programName() + "";
    text += "
";

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

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

    QString home = about->homepage();
    if ( !home.isEmpty() ) {
      text += "" + home + "
";
    }

    text.replace( "\n", "
" );

    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 +="\
    This Free Software product was improved as part of a commercial project:\

Credits
\
    v20080902.2  Project Kowi (March 2007 - )

\
    \
    Production / Project Coordination
\
    Bernhard Reiter
\
    Director of Development
\
    Till Adam\

\
    \

 \

\
     \
      Osnabrück Unit, Intevation GmbH\
     	\

\

\
     \
      Unit Lead
\
      Senior QA, Packaging
\
      QA, Packaging
\
      Additional NSIS
\
      Backup Coordinator\
     	\
     \
      Bernhard Reiter
\
      Bernhard Herzog
\
      Ludwig Reiter
\
      Emanuel Schütze
\
      Dr. Jan-Oliver Wagner\
     	\

\

\

\
    \

\

\
     \
        Berlin Unit, Klarälvdalens Datakonsult AB\
     	\

\

\
     \
      Unit Lead
\
      Development
\
      Development
\
      Additional D. + Crypto
\
      Crypto GUI Development\
     	\
     \
      Till Adam
\
      Jaroslaw Staniek
\
      Volker Krause
\
      Frank Osterfeld
\
      Marc Mutz\
     	\

\

\

\
    \

\

\
     \
      Düsseldorf Unit, g10 Code GmbH\
     	\

\

\
     \
      Crypto-Backend Porting
\
      Crypto-Backend\
     	\
     \
      Werner Koch
\
      Marcus Brinkmann\
     	\

\

\

\
    \

\

\
     \
      External QA Darmstadt, basysKom GmbH\
     	\

\

\
     \
      Unit-Lead\
     	\
     \
      Dr. Stefan Werden\
     	\

\

";

    const QList<KAboutPerson> authors = about->authors();
    if ( !authors.isEmpty() ) {
      text += i18n( "
Authors:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = authors.begin(); it != authors.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() ) {
          text += "" + (*it).task() + "
";
        }
      }
    }

    const QList<KAboutPerson> credits = about->credits();
    if ( !credits.isEmpty() ) {
      text += i18n( "
Thanks to:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = credits.begin(); it != credits.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() ) {
          text += "" + (*it).task() + "
";
        }
      }
    }

    const QList<KAboutPerson> translators = about->translators();
    if ( !translators.isEmpty() ) {
      text += i18n( "
Translators:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = translators.begin(); it != translators.end(); ++it ) {
       text += formatPerson( (*it).name(), (*it).emailAddress() );
      }
    }

    personView->setText( text );
  }
}

QString AboutDialog::formatPerson( const QString &name, const QString &email )
{
  QString text = name;
  if ( !email.isEmpty() ) {
    text += " <" + email + ">";
  }

  text += "
";
  return text;
}

void AboutDialog::addLicenseText( const KAboutData *about )
{
  if ( !about || about->license().isEmpty() ) {
    return;
  }

  QPixmap pixmap = KIconLoader::global()->loadIcon( "help-about",
                                                    KIconLoader::Desktop, 48 );

  QString title = i18n( "%1 License", about->programName() );

  QFrame *topFrame = new QFrame();
  KPageWidgetItem *page = new KPageWidgetItem( topFrame, title );
  page->setIcon( KIcon( pixmap ) );
  addPage( page );
  QBoxLayout *topLayout = new QVBoxLayout( topFrame );

  KTextBrowser *textBrowser = new KTextBrowser( topFrame );
  textBrowser->setHtml( QString( "
%1
" ).arg( about->license() ) );

  topLayout->addWidget( textBrowser );
}

#include "aboutdialog.moc"
<commit_msg>No date code here.<commit_after>/*
  This file is part of KDE Kontact.

  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>

  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 += "
";
    text += "" + about->programName() + "";
    text += "
";

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

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

    QString home = about->homepage();
    if ( !home.isEmpty() ) {
      text += "" + home + "
";
    }

    text.replace( "\n", "
" );

    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 +="\
    This Free Software product was improved as part of a commercial project:\

Credits
\
    Project Kowi (March 2007 - )

\
    \
    Production / Project Coordination
\
    Bernhard Reiter
\
    Director of Development
\
    Till Adam\

\
    \

 \

\
     \
      Osnabrück Unit, Intevation GmbH\
     	\

\

\
     \
      Unit Lead
\
      Senior QA, Packaging
\
      QA, Packaging
\
      Additional NSIS
\
      Backup Coordinator\
     	\
     \
      Bernhard Reiter
\
      Bernhard Herzog
\
      Ludwig Reiter
\
      Emanuel Schütze
\
      Dr. Jan-Oliver Wagner\
     	\

\

\

\
    \

\

\
     \
        Berlin Unit, Klarälvdalens Datakonsult AB\
     	\

\

\
     \
      Unit Lead
\
      Development
\
      Development
\
      Additional D. + Crypto
\
      Crypto GUI Development\
     	\
     \
      Till Adam
\
      Jaroslaw Staniek
\
      Volker Krause
\
      Frank Osterfeld
\
      Marc Mutz\
     	\

\

\

\
    \

\

\
     \
      Düsseldorf Unit, g10 Code GmbH\
     	\

\

\
     \
      Crypto-Backend Porting
\
      Crypto-Backend\
     	\
     \
      Werner Koch
\
      Marcus Brinkmann\
     	\

\

\

\
    \

\

\
     \
      External QA Darmstadt, basysKom GmbH\
     	\

\

\
     \
      Unit-Lead\
     	\
     \
      Dr. Stefan Werden\
     	\

\

";

    const QList<KAboutPerson> authors = about->authors();
    if ( !authors.isEmpty() ) {
      text += i18n( "
Authors:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = authors.begin(); it != authors.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() ) {
          text += "" + (*it).task() + "
";
        }
      }
    }

    const QList<KAboutPerson> credits = about->credits();
    if ( !credits.isEmpty() ) {
      text += i18n( "
Thanks to:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = credits.begin(); it != credits.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() ) {
          text += "" + (*it).task() + "
";
        }
      }
    }

    const QList<KAboutPerson> translators = about->translators();
    if ( !translators.isEmpty() ) {
      text += i18n( "
Translators:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = translators.begin(); it != translators.end(); ++it ) {
       text += formatPerson( (*it).name(), (*it).emailAddress() );
      }
    }

    personView->setText( text );
  }
}

QString AboutDialog::formatPerson( const QString &name, const QString &email )
{
  QString text = name;
  if ( !email.isEmpty() ) {
    text += " <" + email + ">";
  }

  text += "
";
  return text;
}

void AboutDialog::addLicenseText( const KAboutData *about )
{
  if ( !about || about->license().isEmpty() ) {
    return;
  }

  QPixmap pixmap = KIconLoader::global()->loadIcon( "help-about",
                                                    KIconLoader::Desktop, 48 );

  QString title = i18n( "%1 License", about->programName() );

  QFrame *topFrame = new QFrame();
  KPageWidgetItem *page = new KPageWidgetItem( topFrame, title );
  page->setIcon( KIcon( pixmap ) );
  addPage( page );
  QBoxLayout *topLayout = new QVBoxLayout( topFrame );

  KTextBrowser *textBrowser = new KTextBrowser( topFrame );
  textBrowser->setHtml( QString( "
%1
" ).arg( about->license() ) );

  topLayout->addWidget( textBrowser );
}

#include "aboutdialog.moc"
<|endoftext|>


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

    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>

    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 <klocale.h>
#include <kcomponentdata.h>
#include <kaboutdata.h>
#include <ktextbrowser.h>
#include <kicon.h>
#include <QLayout>
#include <QLabel>

#include <kdebug.h>

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.end();
  QList<Plugin*>::ConstIterator it = plugins.begin();
  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);
}

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 += "
" + about->programName() + "
";

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

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

    QString home = about->homepage();
    if ( !home.isEmpty() ) {
      text += "" + home + "
";
    }

    text.replace( "\n", "
" );

    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 );
    personView->setReadOnly( true );
    topLayout->addWidget( personView, 1 );

    text = "";

    const QList<KAboutPerson> authors = about->authors();
    if ( !authors.isEmpty() ) {
      text += i18n( "
Authors:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = authors.begin(); it != authors.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() )
          text += "" + (*it).task() + "
";
      }
    }

    const QList<KAboutPerson> credits = about->credits();
    if ( !credits.isEmpty() ) {
      text += i18n( "
Thanks to:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = credits.begin(); it != credits.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() )
          text += "" + (*it).task() + "
";
      }
    }

    const QList<KAboutPerson> translators = about->translators();
    if ( !translators.isEmpty() ) {
      text += i18n("
Translators:
");

      QList<KAboutPerson>::ConstIterator it;
      for ( it = translators.begin(); it != translators.end(); ++it ) {
       text += formatPerson( (*it).name(), (*it).emailAddress() );
      }
    }

    personView->setText( text );
  }
}

QString AboutDialog::formatPerson( const QString &name, const QString &email )
{
  QString text = name;
  if ( !email.isEmpty() ) {
    text += " <" + email + ">";
  }

  text += "
";
  return text;
}

void AboutDialog::addLicenseText( const KAboutData *about )
{
  if ( !about || about->license().isEmpty() )
    return;

  QPixmap pixmap = KIconLoader::global()->loadIcon( "help-about",
                                                    KIconLoader::Desktop, 48 );

  QString title = i18n( "%1 License", about->programName() );

  QFrame *topFrame = new QFrame();
  KPageWidgetItem *page = new KPageWidgetItem( topFrame, title );
  page->setIcon(KIcon(pixmap));
  addPage( page );
  QBoxLayout *topLayout = new QVBoxLayout( topFrame );

  KTextBrowser *textBrowser = new KTextBrowser( topFrame );
  textBrowser->setHtml( QString( "
%1
" ).arg( about->license() ) );

  topLayout->addWidget( textBrowser );
}

#include "aboutdialog.moc"
<commit_msg>why do I even listen to Till? :)<commit_after>/*
    This file is part of KDE Kontact.

    Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>

    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 <klocale.h>
#include <kcomponentdata.h>
#include <kaboutdata.h>
#include <ktextbrowser.h>
#include <kicon.h>
#include <QLayout>
#include <QLabel>

#include <kdebug.h>

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.end();
  QList<Plugin*>::ConstIterator it = plugins.begin();
  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 += "
" + about->programName() + "
";

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

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

    QString home = about->homepage();
    if ( !home.isEmpty() ) {
      text += "" + home + "
";
    }

    text.replace( "\n", "
" );

    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 );
    personView->setReadOnly( true );
    topLayout->addWidget( personView, 1 );

    text = "";

    const QList<KAboutPerson> authors = about->authors();
    if ( !authors.isEmpty() ) {
      text += i18n( "
Authors:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = authors.begin(); it != authors.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() )
          text += "" + (*it).task() + "
";
      }
    }

    const QList<KAboutPerson> credits = about->credits();
    if ( !credits.isEmpty() ) {
      text += i18n( "
Thanks to:
" );

      QList<KAboutPerson>::ConstIterator it;
      for ( it = credits.begin(); it != credits.end(); ++it ) {
        text += formatPerson( (*it).name(), (*it).emailAddress() );
        if ( !(*it).task().isEmpty() )
          text += "" + (*it).task() + "
";
      }
    }

    const QList<KAboutPerson> translators = about->translators();
    if ( !translators.isEmpty() ) {
      text += i18n("
Translators:
");

      QList<KAboutPerson>::ConstIterator it;
      for ( it = translators.begin(); it != translators.end(); ++it ) {
       text += formatPerson( (*it).name(), (*it).emailAddress() );
      }
    }

    personView->setText( text );
  }
}

QString AboutDialog::formatPerson( const QString &name, const QString &email )
{
  QString text = name;
  if ( !email.isEmpty() ) {
    text += " <" + email + ">";
  }

  text += "
";
  return text;
}

void AboutDialog::addLicenseText( const KAboutData *about )
{
  if ( !about || about->license().isEmpty() )
    return;

  QPixmap pixmap = KIconLoader::global()->loadIcon( "help-about",
                                                    KIconLoader::Desktop, 48 );

  QString title = i18n( "%1 License", about->programName() );

  QFrame *topFrame = new QFrame();
  KPageWidgetItem *page = new KPageWidgetItem( topFrame, title );
  page->setIcon(KIcon(pixmap));
  addPage( page );
  QBoxLayout *topLayout = new QVBoxLayout( topFrame );

  KTextBrowser *textBrowser = new KTextBrowser( topFrame );
  textBrowser->setHtml( QString( "
%1
" ).arg( about->license() ) );

  topLayout->addWidget( textBrowser );
}

#include "aboutdialog.moc"
<|endoftext|>


<commit_before>// MMOVE.C -- implementation of MMOVE class

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ugens.h>
#include <mixerr.h>
#include <rt.h>
#include <rtdefs.h>

#include <common.h>
#include "MMOVE.h"

#undef debug

#ifdef SIG_DEBUG
#define DBG(stmt) { stmt; }
#else
#define DBG(stmt)
#endif

extern "C" int get_path_params(double *rhos, double *thetas, int *cartesian, double *mdiff);

// Defined in ../MOVE/common.C
extern double SINARRAY[1025], COSARRAY[1025], ATANARRAY[1025];

static const double radpt = 162.99746617261;   /* converts rads to 1024-element array ptr */
static const double radpt2 = 325.9493234522;

inline double SIN(double x) { return SINARRAY[(int)(wrap(x) * radpt + 0.5)]; }
inline double COS(double x) { return COSARRAY[(int)(wrap(x) * radpt + 0.5)]; }
inline double ATAN(double x) { return ATANARRAY[(int)((x) * radpt2) + 512]; }

static const double LocationUnset = -999999.999999;

/* ------------------------------------------------------------ makeMOVE --- */
Instrument *makeMMOVE()
{
   MOVE *inst;

   inst = new MOVE();	// The class is called MOVE, but the inst is MMOVE
   inst->set_bus_config("MMOVE");

   return inst;
}

extern Instrument *makeRVB();	// From RVB.C

/* ------------------------------------------------------------ rtprofile --- */
void rtprofile()
{
   RT_INTRO("MMOVE", makeMMOVE);
   RT_INTRO("RVB", makeRVB);
}

// Move methods

MOVE::MOVE()
{
    R_old = -100000.0;
    T_old = 0.0;
    m_updateCount = 0;
    m_updateSamps = BUFLEN;
    setup_trigfuns();
    rholoc = new double[ARRAYSIZE];
    thetaloc = new double[ARRAYSIZE];
    for (int n = 0; n < 2; n++)
        for (int o = 0; o < 13; o++)
	    oldOutlocs[n][o] = LocationUnset;	// to force update
}

MOVE::~MOVE()
{
    delete [] thetaloc;
    delete [] rholoc;
}

int MOVE::localInit(double *p, int n_args)
{
    if (n_args < 6)
        return die(name(), "Wrong number of args.");
    m_dist = p[4];
    m_inchan = n_args > 5 ? (int)p[5] : AVERAGE_CHANS;

    // copy global params into instrument

    if (get_path_params(&rholoc[0], &thetaloc[0], &m_cartflag, &mindiff) < 0)
		  return die(name(), "get_path_params failed.");

	// treat mindiff as update rate in seconds
	if (mindiff > 0.0) {
		m_updateSamps = (int) (SR * mindiff + 0.5);
		if (m_updateSamps <= BUFLEN)
		{
	        setBufferSize(m_updateSamps);
#ifdef debug
			printf("buffer size reset to %d samples\n", getBufferSize());
#endif
		}
		// if update rate is larger than BUFLEN samples, set buffer size
		// to be some integer fraction of the desired update count, then
		// reset update count to be multiple of this.
		else {
		    int divisor = 2;
			int newBufferLen;
			while ((newBufferLen = m_updateSamps / divisor) > BUFLEN)
			    divisor++;
			setBufferSize(newBufferLen);
			m_updateSamps = newBufferLen * divisor;
#ifdef debug
			printf("buffer size reset to %d samples\n", getBufferSize());
#endif
		}
#ifdef debug
	    printf("updating every %d samps\n", m_updateSamps);
#endif
	}

    // tables for positional lookup

    tableset(SR, m_dur, ARRAYSIZE, tabr);
    tableset(SR, m_dur, ARRAYSIZE, tabt);

    return 0;
}

int MOVE::finishInit(double rvb_time, double *ringdur)
{
    *ringdur = rvb_time;	// default
	tapcount = updatePosition(0);
    return 0;
}

void MOVE::get_tap(int currentSamp, int chan, int path, int len)
{
   Vector *vec = &m_vectors[chan][path];
   double outloc = vec->outloc;
   const double oldOutloc = oldOutlocs[chan][path];
   double delta;
   if (oldOutloc == LocationUnset)
       delta = 0.0;
   else
       delta = outloc - oldOutloc;
   oldOutlocs[chan][path] = outloc;

   double incr = 1.0 + delta / len;

   const int tap = currentSamp % m_tapsize;
   register double otap = (double) tap - outloc;
   if (otap < 0.0) otap += m_tapsize;
   double otapPlusOne = otap + 1.0;
   if (otapPlusOne >= (double) m_tapsize) otapPlusOne -= m_tapsize;

   double closestToEnd = max(otap, otapPlusOne);

   // run till one of output taps wrap, or len reached

   int len1 = min(len, m_tapsize - (int) closestToEnd);

   register double *tapdel = m_tapDelay;
   register double *Sig = vec->Sig;
   int out = 0;

   while (out < len)
   {
       const int clen = len1;
       for (int i = 0; i < clen; ++i) {
	   int outtap = (int) otap;
	   double frac = otap - (double)outtap;
	   Sig[out++] = tapdel[outtap] + frac * (tapdel[outtap + 1] - tapdel[outtap]);
	   otap += incr;
       }

       if (otap >= (double) m_tapsize) otap -= m_tapsize;
       otapPlusOne = otap + 1.0;
       if (otapPlusOne >= (double) m_tapsize) otapPlusOne -= m_tapsize;
       closestToEnd = max(otap, otapPlusOne);

       len1 = min(len - out, m_tapsize - (int) closestToEnd);
   }
}

// This gets called every internal buffer's worth of samples.  The actual
// update of source angles and delays only happens if we are due for an update
// (based on the update count) and there has been a change of position

int MOVE::updatePosition(int currentSamp)
{
    double R = tablei(currentSamp, rholoc, tabr);
    double T = tablei(currentSamp, thetaloc, tabt);
    int maxtap = tapcount;
	m_updateCount -= getBufferSize();
    if (m_updateCount <= 0 && (R != R_old || T != T_old)) {
#ifdef debug
        printf("updatePosition[%d]:\t\tR: %f  T: %f\n", currentSamp, R, T);
#endif
		if (roomtrig(R , T, m_dist, m_cartflag)) {
            return (-1);
		}
        // set taps, return max samp
        maxtap = tap_set(m_binaural);
 	    int resetFlag = (currentSamp == 0);
		airfil_set(resetFlag);
		if (m_binaural)
		   earfil_set(resetFlag);
		else
		   mike_set();
		R_old = R;
		T_old = T;
		m_updateCount = m_updateSamps;	// reset counter
    }
    return maxtap;	// return new maximum delay in samples
}
<commit_msg>Fixed serious bug involving overwrite of tap delay.<commit_after>// MMOVE.C -- implementation of MMOVE class

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ugens.h>
#include <mixerr.h>
#include <rt.h>
#include <rtdefs.h>
#include <assert.h>

#include <common.h>
#include "MMOVE.h"

//#define debug

#ifdef SIG_DEBUG
#define DBG(stmt) { stmt; }
#else
#define DBG(stmt)
#endif

extern "C" int get_path_params(double *rhos, double *thetas, int *cartesian, double *mdiff);

// Defined in ../MOVE/common.C
extern double SINARRAY[1025], COSARRAY[1025], ATANARRAY[1025];

static const double radpt = 162.99746617261;   /* converts rads to 1024-element array ptr */
static const double radpt2 = 325.9493234522;

inline double SIN(double x) { return SINARRAY[(int)(wrap(x) * radpt + 0.5)]; }
inline double COS(double x) { return COSARRAY[(int)(wrap(x) * radpt + 0.5)]; }
inline double ATAN(double x) { return ATANARRAY[(int)((x) * radpt2) + 512]; }

static const double LocationUnset = -999999.999999;

/* ------------------------------------------------------------ makeMOVE --- */
Instrument *makeMMOVE()
{
   MOVE *inst;

   inst = new MOVE();	// The class is called MOVE, but the inst is MMOVE
   inst->set_bus_config("MMOVE");

   return inst;
}

extern Instrument *makeRVB();	// From RVB.C

/* ------------------------------------------------------------ rtprofile --- */
void rtprofile()
{
   RT_INTRO("MMOVE", makeMMOVE);
   RT_INTRO("RVB", makeRVB);
}

// Move methods

MOVE::MOVE()
{
    R_old = -100000.0;
    T_old = 0.0;
    m_updateCount = 0;
    m_updateSamps = BUFLEN;
    setup_trigfuns();
    rholoc = new double[ARRAYSIZE];
    thetaloc = new double[ARRAYSIZE];
    for (int n = 0; n < 2; n++)
        for (int o = 0; o < 13; o++)
	    oldOutlocs[n][o] = LocationUnset;	// to force update
}

MOVE::~MOVE()
{
    delete [] thetaloc;
    delete [] rholoc;
}

int MOVE::localInit(double *p, int n_args)
{
    if (n_args < 6)
        return die(name(), "Wrong number of args.");
    m_dist = p[4];
    m_inchan = n_args > 5 ? (int)p[5] : AVERAGE_CHANS;

    // copy global params into instrument

    if (get_path_params(&rholoc[0], &thetaloc[0], &m_cartflag, &mindiff) < 0)
		  return die(name(), "get_path_params failed.");

	// treat mindiff as update rate in seconds
	if (mindiff > 0.0) {
		m_updateSamps = (int) (SR * mindiff + 0.5);
		if (m_updateSamps <= BUFLEN)
		{
	        setBufferSize(m_updateSamps);
#ifdef debug
			printf("buffer size reset to %d samples\n", getBufferSize());
#endif
		}
		// if update rate is larger than BUFLEN samples, set buffer size
		// to be some integer fraction of the desired update count, then
		// reset update count to be multiple of this.
		else {
		    int divisor = 2;
			int newBufferLen;
			while ((newBufferLen = m_updateSamps / divisor) > BUFLEN)
			    divisor++;
			setBufferSize(newBufferLen);
			m_updateSamps = newBufferLen * divisor;
#ifdef debug
			printf("buffer size reset to %d samples\n", getBufferSize());
#endif
		}
#ifdef debug
	    printf("updating every %d samps\n", m_updateSamps);
#endif
	}

    // tables for positional lookup

    tableset(SR, m_dur, ARRAYSIZE, tabr);
    tableset(SR, m_dur, ARRAYSIZE, tabt);

    return 0;
}

int MOVE::finishInit(double rvb_time, double *ringdur)
{
    *ringdur = rvb_time;	// default
	tapcount = updatePosition(0);
    return 0;
}

void MOVE::get_tap(int currentSamp, int chan, int path, int len)
{
   Vector *vec = &m_vectors[chan][path];
   const double outloc = (double) vec->outloc;
   if (outloc < -40000.0 || outloc > 40000.0) {
	   printf("WHAM\n");
   }
   const double oldOutloc = oldOutlocs[chan][path];
   const double delta = (oldOutloc == LocationUnset) ? 0.0 : outloc - oldOutloc;

   oldOutlocs[chan][path] = outloc;

   const double incr = 1.0 + delta / len;
   const int tap = currentSamp % m_tapsize;

   register double *tapdel = m_tapDelay;
   register double *Sig = vec->Sig;
   register double outTap = (double) tap - outloc;
   if (outTap < 0.0)
	   outTap += m_tapsize;
   int out = 0;

   while (out < len)
   {
		if (outTap >= (double) m_tapsize)
			outTap -= m_tapsize;
		int iouttap = (int) outTap;
		int outTapPlusOne = int(outTap + 1.0);
		if (outTapPlusOne >= m_tapsize)
			outTapPlusOne -= m_tapsize;
		double frac = outTap - (double)iouttap;
		Sig[out++] = tapdel[iouttap] + frac * (tapdel[outTapPlusOne] - tapdel[iouttap]);
		outTap += incr;
   }
}

// This gets called every internal buffer's worth of samples.  The actual
// update of source angles and delays only happens if we are due for an update
// (based on the update count) and there has been a change of position

int MOVE::updatePosition(int currentSamp)
{
    double R = tablei(currentSamp, rholoc, tabr);
    double T = tablei(currentSamp, thetaloc, tabt);
    int maxtap = tapcount;
	m_updateCount -= getBufferSize();
    if (m_updateCount <= 0 && (R != R_old || T != T_old)) {
#ifdef debug
        printf("updatePosition[%d]:\t\tR: %f  T: %f\n", currentSamp, R, T);
#endif
		if (roomtrig(R , T, m_dist, m_cartflag)) {
            return (-1);
		}
        // set taps, return max samp
        maxtap = tap_set(m_binaural);
 	    int resetFlag = (currentSamp == 0);
		airfil_set(resetFlag);
		if (m_binaural)
		   earfil_set(resetFlag);
		else
		   mike_set();
		R_old = R;
		T_old = T;
		m_updateCount = m_updateSamps;	// reset counter
    }
    return maxtap;	// return new maximum delay in samples
}
<|endoftext|>


<commit_before><commit_msg>ByteString::ToInt64 is atoi the same as ToInt32, and we downcast anyway<commit_after><|endoftext|>


<commit_before>#include <stdio.h>
#include "condor_common.h"
#include "exprTree.h"

void help( void );

int
main( void )
{
	ClassAd 	ad;
	char 		buffer1[2048], buffer2[2048];
	ExprTree	*expr=NULL, *fexpr=NULL;
	int 		command;
	Value		value;
	Source		src;
	Sink		snk;

	snk.setSink( stdout );

	printf( "'h' for help\n# " );
	while( 1 ) {
		command = tolower( getchar() );
		switch( command ) {
			case 'c':
				ad.clear();
				break;

			case 'd':
				if( scanf( "%s", buffer1 ) != 1 ) {
					printf( "Error reading attribute name\n" );
					break;
				}
				if( !ad.remove( buffer1 ) ) {
					printf( "Error removing attribute %s\n", buffer1 );
				}
				break;

			case 'e':
				fgets( buffer1, 2048, stdin );
				src.setSource( buffer1, 2048 );
				if( !src.parseExpression( expr ) ) {
					printf( "Error parsing expression: %s\n", buffer1 );
					break;
				}
				ad.evaluate( expr, value );
				value.toSink( snk );
				snk.flushSink();
				delete expr;
				expr = NULL;
				break;

			case 'f':
				fgets( buffer1, 2048, stdin );
				src.setSource( buffer1, 2048 );
				if( !src.parseExpression( expr ) ) {
					printf( "Error parsing expression: %s\n", buffer1 );
					break;
				}
				if( ad.flatten( expr, value, fexpr ) ) {
					if( fexpr ) {
						fexpr->toSink( snk );
						delete fexpr;
						fexpr = NULL;
					} else {
						value.toSink( snk );
					}
					snk.flushSink();
				} else {
					printf( "Error flattening expression\n" );
				}
				break;

			case 'h':
				help();
				break;

			case 'i':
				if( scanf( "%s", buffer1 ) != 1 ) {	// name
					printf( "Error reading attribute name\n" );
					break;
				}
				fgets( buffer2, 2048, stdin );		// expr
				src.setSource( buffer2, 2048 );
				if( !src.parseExpression( expr ) ) {
					printf( "Error parsing expression: %s\n", buffer2 );
				}
				if( !ad.insert( buffer1, expr ) ) {
					printf( "Error inserting expression\n" );
				}
				break;

			case 'n':
				ad.clear();
				fgets( buffer1, 2048, stdin );
				src.setSource( buffer1, 2048 );
				if( !src.parseClassAd( &ad ) ) {
					printf( "Error parsing classad\n" );
				}
				break;

			case 'p':
				ad.toSink( snk );
				snk.flushSink();
				break;

			case 'q':
				printf( "Done\n\n" );
				exit( 0 );

			case 's':
				ad.clear();
				sprintf( buffer1, "[adc1=[self=.adc1.ad;other=.adc2.ad;ad=[]];"
								  " adc2=[self=.adc2.ad;other=.adc1.ad;ad=[]]]"
						);
				src.setSource( buffer1, 2048 );
				ad.clear();
				if( !src.parseClassAd( &ad ) ) {
					printf( "Error parsing classad: %s\n", buffer1 );
				}
				break;

			default:
				printf( "Unknown command: '%c' -- Ignoring input\n", command );
				fflush( stdin );
		}

		fflush( stdin );
		printf( "\n# " );
	}

	exit( 0 );
}

void
help( void )
{
	printf( "\nCommands are:\n" );
	printf( "\tc\t\t- (C)lear toplevel ad\n" );
	printf( "\td <name>\t- (D)elete expression from ad\n" );
	printf( "\te <expr>\t- (E)valuate expression (in toplevel ad)\n" );
	printf( "\tf <expr>\t- (F)latten expression (in toplevel ad)\n" );
	printf( "\th\t\t- (H)elp; This screen\n" );
	printf( "\ti <name> <expr>\t- (I)nsert expression into toplevel ad\n" );
	printf( "\tn <classad>\t- Enter (n)ew toplevel ad\n" );
	printf( "\to\t\t- Output toplevel ad\n" );
	printf( "\tq\t\t- (Q)uit\n" );
	printf( "\ts\t\t- (S)etup Condor toplevel ad\n" );
}
<commit_msg>Upgraded and debugged classad expression interpreter.<commit_after>#include <stdio.h>
#include "condor_common.h"
/*
#include "condor_config.h"
*/
#include "classad_package.h"

void help( void );

int
main( void )
{
	ClassAd 	ad, *adptr;
	char 		buffer1[2048], buffer2[2048];
//	char		*tmp;
	ExprTree	*expr=NULL, *fexpr=NULL;
	int 		command;
	Value		value;
	Source		src;
	Sink		snk;

	snk.setSink( stdout );
/*
	config( 0 );
*/
	printf( "'h' for help\n# " );
	while( 1 ) {
		command = tolower( getchar() );
		switch( command ) {
			case 'c':
				ad.clear();
				break;

			case 'd':
				if( scanf( "%s", buffer1 ) != 1 ) {	// expr
					printf( "Error reading primary expression\n" );
					break;
				}
				src.setSource( buffer1, 2048 );
				if( !src.parseExpression( expr ) ) {
					printf( "Error parsing expression: %s\n", buffer1 );
					break;
				}
				if( scanf( "%s", buffer1 ) != 1 ) {
					printf( "Error reading attribute name\n" );
					break;
				}
				fgets( buffer2, 2048, stdin );
				src.setSource( buffer2, 2048 );
				if( !src.parseExpression( fexpr ) ) {
					printf( "Error parsing expression: %s\n", buffer2 );
					break;
				}
				ad.evaluate( expr, value );
				if( !value.isClassAdValue( adptr ) ) {
					printf( "Error:  Primary expression was not a classad\n" );
					break;
				}
				if( !adptr->insert( buffer1, fexpr ) ) {
					printf( "Error inserting expression\n" );
				}
				delete expr;
				adptr = NULL;
				expr  = NULL;
				break;

			case 'e':
				fgets( buffer1, 2048, stdin );
				src.setSource( buffer1, 2048 );
				if( !src.parseExpression( expr ) ) {
					printf( "Error parsing expression: %s\n", buffer1 );
					break;
				}
				ad.evaluate( expr, value );
				value.toSink( snk );
				snk.flushSink();
				delete expr;
				expr = NULL;
				break;

			case 'f':
				fgets( buffer1, 2048, stdin );
				src.setSource( buffer1, 2048 );
				if( !src.parseExpression( expr ) ) {
					printf( "Error parsing expression: %s\n", buffer1 );
					break;
				}
				if( ad.flatten( expr, value, fexpr ) ) {
					if( fexpr ) {
						fexpr->toSink( snk );
						delete fexpr;
						fexpr = NULL;
					} else {
						value.toSink( snk );
					}
					snk.flushSink();
				} else {
					printf( "Error flattening expression\n" );
				}
				break;

			case 'h':
				help();
				break;

			case 'i':
				if( scanf( "%s", buffer1 ) != 1 ) {
					printf( "Error reading attribute name\n" );
					break;
				}
				fgets( buffer2, 2048, stdin );
				src.setSource( buffer2, 2048 );
				if( !src.parseExpression( fexpr ) ) {
					printf( "Error parsing expression: %s\n", buffer2 );
					break;
				}
				if( ad.insert( buffer1, expr ) ) {
					printf( "Error inserting expression\n" );
				}
				expr  = NULL;
				break;

			case 'n':
				ad.clear();
				fgets( buffer1, 2048, stdin );
				src.setSource( buffer1, 2048 );
				if( !src.parseClassAd( &ad ) ) {
					printf( "Error parsing classad\n" );
				}
				break;

			case 'o':
				ad.toSink( snk );
				snk.flushSink();
				break;

/*
			case 'p':
				fgets( buffer1, 2048, stdin );
				if( !( tmp = param( buffer1 ) ) ) {
					printf( "Did not find %s in config file\n", buffer1 );
					break;
				}
				src.setSource( tmp, strlen( tmp ) );
				if( !src.parseExpression( expr ) ) {
					printf( "Error parsing expression: %s\n", tmp );
					free( tmp );
					break;
				}
				if( !ad.insert( buffer1, expr ) ) {
					printf( "Error inserting: %s = %s\n", buffer1, tmp );
				}
				delete tmp;
				expr = NULL;
				break;
*/

			case 'q':
				printf( "Done\n\n" );
				exit( 0 );

			case 'r':
				if( scanf( "%s", buffer1 ) != 1 ) {
					printf( "Error reading attribute name\n" );
					break;
				}
				if( !ad.remove( buffer1 ) ) {
					printf( "Error removing attribute %s\n", buffer1 );
				}
				break;

			case 's':
				ad.clear();
				sprintf( buffer1, "[adc1=[self=.adc1.ad;other=.adc2.ad;ad=[]];"
								  " adc2=[self=.adc2.ad;other=.adc1.ad;ad=[]]]"
						);
				src.setSource( buffer1, 2048 );
				ad.clear();
				if( !src.parseClassAd( &ad ) ) {
					printf( "Error parsing classad: %s\n", buffer1 );
				}
				break;

			default:
				printf( "Unknown command: '%c' -- Ignoring input\n", command );
				fflush( stdin );
		}

		fflush( stdin );
		printf( "\n# " );
	}

	exit( 0 );
}

void
help( void )
{
	printf( "\nCommands are:\n" );
	printf( "\tc\t\t- (C)lear toplevel ad\n" );
	printf( "\td <e1><name><e2>- (D)eep insert e2 into classad e1\n");
	printf( "\te <expr>\t- (E)valuate expression (in toplevel ad)\n" );
	printf( "\tf <expr>\t- (F)latten expression (in toplevel ad)\n" );
	printf( "\th\t\t- (H)elp; This screen\n" );
	printf( "\ti <name><expr>\t- (I)nsert expression into toplevel ad\n" );
	printf( "\tn <classad>\t- Enter (n)ew toplevel ad\n" );
	printf( "\to\t\t- (O)utput toplevel ad\n" );
/*
	printf( "\tp <name>\t- (P)aram from config file and insert in toplevel\n" );
*/
	printf( "\tq\t\t- (Q)uit\n" );
	printf( "\ts\t\t- (S)etup Condor toplevel ad\n" );
}
<|endoftext|>