<commit_before>/*
    certificatewizardimpl.cpp

    This file is part of Kleopatra, the KDE keymanager
    Copyright (c) 2001,2002,2004 Klar�vdalens Datakonsult AB

    Kleopatra 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.

    Kleopatra 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

    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.
*/

#include <config-kleopatra.h>

#include "certificatewizardimpl.h"

// libkleopatra
#include "libkleo/kleo/oidmap.h"
#include "libkleo/kleo/keygenerationjob.h"
#include "libkleo/kleo/dn.h"
#include "libkleo/kleo/cryptobackendfactory.h"
#include "libkleo/ui/progressdialog.h"
#include "libkleo/ui/filenamerequester.h"

// gpgme++
#include <gpgme++/keygenerationresult.h>

// KDE
#ifdef KLEO_HAVE_KDEPIMLIBS
# include <kabc/stdaddressbook.h>
# include <kabc/addressee.h>
#endif

#include <kmessagebox.h>
#include <klocale.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kdialog.h>
#ifdef KLEO_TEMPORARILY_REMOVED //PENDING(frank)
#include <KDBusServiceStarter>
#include <kurlrequester.h>
#include <kio/job.h>
#include <kio/jobuidelegate.h>
#include <kio/netaccess.h>
#endif
#include <ktoolinvocation.h>
#include <kconfiggroup.h>

// Qt
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QRadioButton>
#include <QLayout>
#include <QLabel>
#include <QComboBox>
#include <QGridLayout>
#include <QByteArray>
#include <QVBoxLayout>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusReply>

#include <assert.h>

static const unsigned int keyLengths[] = {
  1024, 1532, 2048, 3072, 4096
};
static const unsigned int numKeyLengths = sizeof keyLengths / sizeof *keyLengths;

static QString attributeLabel( const QString & attr, bool required ) {
  if ( attr.isEmpty() )
    return QString();
  const QString label = Kleo::DNAttributeMapper::instance()->name2label( attr );
  if ( !label.isEmpty() )
    if ( required )
      return i18nc("Format string for the labels in the \"Your Personal Data\" page - required field",
		   "*%1 (%2):", label, attr );
    else
      return i18nc("Format string for the labels in the \"Your Personal Data\" page",
		   "%1 (%2):", label, attr );

  else if ( required )
    return '*' + attr + ':';
  else
    return attr + ':';
}

static QString attributeFromKey( const QString &key ) {
  QString t = key;
  return t.remove( '!' );
}

static bool availForMod( const QLineEdit * le ) {
  return le && le->isEnabled();
}

/*
 *  Constructs a CertificateWizardImpl which is a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'
 *
 *  The wizard will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal wizard.
 */
CertificateWizardImpl::CertificateWizardImpl( QWidget* parent )
    : CertificateWizard( parent )
{
    setModal(false);
    // don't allow to go to last page until a key has been generated
    setNextEnabled( generatePage, false );
    // setNextEnabled( personalDataPage, false ); // ## disable again once we have a criteria when to enable again

    createPersonalDataPage();
    QVBoxLayout* layout = new QVBoxLayout( storeCAWidget );
    layout->setMargin( 0 );
    _storeFR = new Kleo::FileNameRequester;
    connect( storeInFileRB, SIGNAL( toggled( bool ) ), 
            _storeFR, SLOT( setEnabled( bool ) ) );
    layout->addWidget( _storeFR );
    // Allow to select remote URLs
    
#ifdef KLEO_TEMPORARILY_REMOVED //PENDING(frank)
    _storeFR->setMode( KFile::File ); 
    _storeFR->setFilter( "application/pkcs10" );
    connect( storeUR, SIGNAL( urlSelected( const KUrl& ) ),
             this, SLOT( slotURLSelected( const KUrl& ) ) );
#endif
    const KConfigGroup config( KGlobal::config(), "CertificateCreationWizard" );<commit_msg>Don't force existing files here, that doesn't make sense.<commit_after>/*
    certificatewizardimpl.cpp

    This file is part of Kleopatra, the KDE keymanager
    Copyright (c) 2001,2002,2004 Klar�vdalens Datakonsult AB

    Kleopatra 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.

    Kleopatra 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

    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.
*/

#include <config-kleopatra.h>

#include "certificatewizardimpl.h"

// libkleopatra
#include "libkleo/kleo/oidmap.h"
#include "libkleo/kleo/keygenerationjob.h"
#include "libkleo/kleo/dn.h"
#include "libkleo/kleo/cryptobackendfactory.h"
#include "libkleo/ui/progressdialog.h"
#include "libkleo/ui/filenamerequester.h"

// gpgme++
#include <gpgme++/keygenerationresult.h>

// KDE
#ifdef KLEO_HAVE_KDEPIMLIBS
# include <kabc/stdaddressbook.h>
# include <kabc/addressee.h>
#endif

#include <kmessagebox.h>
#include <klocale.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kdialog.h>
#ifdef KLEO_TEMPORARILY_REMOVED //PENDING(frank)
#include <KDBusServiceStarter>
#include <kurlrequester.h>
#include <kio/job.h>
#include <kio/jobuidelegate.h>
#include <kio/netaccess.h>
#endif
#include <ktoolinvocation.h>
#include <kconfiggroup.h>

// Qt
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QRadioButton>
#include <QLayout>
#include <QLabel>
#include <QComboBox>
#include <QGridLayout>
#include <QByteArray>
#include <QVBoxLayout>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusReply>

#include <assert.h>

static const unsigned int keyLengths[] = {
  1024, 1532, 2048, 3072, 4096
};
static const unsigned int numKeyLengths = sizeof keyLengths / sizeof *keyLengths;

static QString attributeLabel( const QString & attr, bool required ) {
  if ( attr.isEmpty() )
    return QString();
  const QString label = Kleo::DNAttributeMapper::instance()->name2label( attr );
  if ( !label.isEmpty() )
    if ( required )
      return i18nc("Format string for the labels in the \"Your Personal Data\" page - required field",
		   "*%1 (%2):", label, attr );
    else
      return i18nc("Format string for the labels in the \"Your Personal Data\" page",
		   "%1 (%2):", label, attr );

  else if ( required )
    return '*' + attr + ':';
  else
    return attr + ':';
}

static QString attributeFromKey( const QString &key ) {
  QString t = key;
  return t.remove( '!' );
}

static bool availForMod( const QLineEdit * le ) {
  return le && le->isEnabled();
}

/*
 *  Constructs a CertificateWizardImpl which is a child of 'parent', with the
 *  name 'name' and widget flags set to 'f'
 *
 *  The wizard will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal wizard.
 */
CertificateWizardImpl::CertificateWizardImpl( QWidget* parent )
    : CertificateWizard( parent )
{
    setModal(false);
    // don't allow to go to last page until a key has been generated
    setNextEnabled( generatePage, false );
    // setNextEnabled( personalDataPage, false ); // ## disable again once we have a criteria when to enable again

    createPersonalDataPage();
    QVBoxLayout* layout = new QVBoxLayout( storeCAWidget );
    layout->setMargin( 0 );
    _storeFR = new Kleo::FileNameRequester;
    _storeFR->setExistingOnly( false );
    _storeFR->setFilter( QDir::Files );
    connect( storeInFileRB, SIGNAL( toggled( bool ) ), 
            _storeFR, SLOT( setEnabled( bool ) ) );
    layout->addWidget( _storeFR );
    // Allow to select remote URLs
    
#ifdef KLEO_TEMPORARILY_REMOVED //PENDING(frank)
    _storeFR->setMode( KFile::File ); 
    _storeFR->setFilter( "application/pkcs10" );
    connect( storeUR, SIGNAL( urlSelected( const KUrl& ) ),
             this, SLOT( slotURLSelected( const KUrl& ) ) );
#endif
    const KConfigGroup config( KGlobal::config(), "CertificateCreationWizard" );
{'fraction_non_alphanumeric': 0.09873570138470801, 'fraction_numerical': 0.011238209913706602, 'mean_word_length': 3.86669921875, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 77, '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': '347452', 'n_tokens_mistral': 3185, 'n_tokens_neox': 3076, 'n_words': 1108}