<commit_before>/*
 * kPPPlogview: a accounting log system for kPPP
 *
 *            Copyright (C) 1998 <NAME> <<EMAIL>>
 *
 * This file has been contributed by <NAME> <<EMAIL>>
 *
 * This program 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 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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.
 */

#include "export.h"

#include <qpushbutton.h>
#include <qtextcodec.h>

class Export;

/***** ExportFormats *****/
static struct {
    int id;
    QString name;
    QString desc;
    QString ext;
  }

ExportFormats [] = {
    { 1, I18N_NOOP("CSV"),
      I18N_NOOP("Export to a text file, using semicolons as separators.<p></p>Can be used for spreadsheet programs like <i>KSpread</i>."),
      "csv" },
    { 2, I18N_NOOP("HTML"),
      I18N_NOOP("Export to a HTML Page.<p></p>Can be used for easy exchange over the <i>Internet</i>."),
      "html" },
    { 0, QString(), QString(), QString() }  /* !! don't forget !! */
};


/***** ExportWizard *****/
ExportWizard::ExportWizard(QWidget *parent, const QString &_date)
  : K3Wizard(parent, "", true) {
  date = _date;

  filterID = 0;

  setWindowTitle(i18n("Export Wizard for kPPP Logs"));

  /* format-page */
  formatPage = new QWidget();
  QHBoxLayout *formatLayout = new QHBoxLayout(formatPage);

  typeList = new Q3ListBox(formatPage);
  connect(typeList, SIGNAL(highlighted(int)), SLOT (typeHighlighted(int)));
  typeList->setMinimumSize(50, 200);
  typeList->setToolTip( i18n("List with possible output formats"));
  int i=0;
  while (ExportFormats[i].id) { // add each format to the list
    typeList->insertItem(i18n(ExportFormats[i].name.toUtf8()));
    i++;
  }

  formatLayout->addWidget(typeList);
  formatLayout->addSpacing(10);

  typeInfo = new QLabel(formatPage);
  typeInfo->setAlignment(Qt::AlignTop);
  typeInfo->setWordWrap( true );
  typeInfo->setText(i18n("<qt><b>Please choose the output format on the left side.</b></qt>"));
  typeInfo->setMinimumSize(350, 200);
  formatLayout->addWidget(typeInfo);

  addPage(formatPage, i18n("Selection of Filetype"));


  /* filename-page */
  filenamePage = new QWidget();
  QVBoxLayout *filenameLayout = new QVBoxLayout( filenamePage );

  QLabel *fnLbl = new QLabel(filenamePage);
  fnLbl->setText(i18n("Filename:"));
  filenameLayout->addWidget(fnLbl);

  fnLine = new QLineEdit(filenamePage);
  fnLine->setText(i18n("[No file selected]"));
  fnLine->setReadOnly(true);
  filenameLayout->addWidget(fnLine);
  filenameLayout->addStretch(1);

  fnGet = new QPushButton(filenamePage);
  fnGet->setText(i18n("&Select File..."));
  fnGet->setMaximumWidth(200);
  fnGet->setToolTip( i18n("Select the filename of the exported output file"));
  filenameLayout->addWidget(fnGet);
  connect(fnGet, SIGNAL(clicked()), SLOT(getFilename()));
  filenameLayout->addStretch(2);

  addPage(filenamePage, i18n("Selection of Filename"));
  setNextEnabled( filenamePage, false );
  setHelpEnabled( filenamePage, false );

  setNextEnabled( formatPage, false );
  setHelpEnabled( formatPage, false );
}

Export * ExportWizard::createExportFilter() {
  switch (filterID) { // IDs: see data-struct ExportFormats
    case 1 : return new CSVExport(filename, ";");
    case 2 : return new HTMLExport(filename, date);
    default : return NULL; // oops..
  };
}

void ExportWizard::typeHighlighted(int index) {
  typeInfo->setText("<qt><b>"+i18n(ExportFormats[index].name.toUtf8())+' ' +
                    i18n("File Format") + "</b><p></p>" + i18n(ExportFormats[index].desc.toUtf8())
                    +"</qt>");
  setNextEnabled(formatPage, true );
}

void ExportWizard::getFilename() {
  int i = typeList->currentItem();
  if ( i == -1 )
      return;
  // prepare filter: e.g.: HTML (*.html *.HTML)
  QString filter = "*." + ExportFormats[i].ext + " *." + ExportFormats[i].ext.toUpper() + '|' +
                   i18n(ExportFormats[i].name.toUtf8()) + " (*." + ExportFormats[i].ext + " *." +
                   ExportFormats[i].ext.toUpper() + ')';

  filename = KFileDialog::getSaveFileName(date + '.' + ExportFormats[i].ext, filter, 0, i18n("Please Choose File"));
  if (filename.isEmpty()) // no file selected
    return;
  fnLine->setText(filename);
  setFinishEnabled(filenamePage, true);
}

void ExportWizard::reject()  {
    hide();
    filename.clear();
}

void ExportWizard::accept() {
  filterID = typeList->currentItem() + 1; // translate to ID-count in ExportFormats
  hide();<commit_msg>Fix compile with "-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS"<commit_after>/*
 * kPPPlogview: a accounting log system for kPPP
 *
 *            Copyright (C) 1998 <NAME> <<EMAIL>>
 *
 * This file has been contributed by <NAME> <<EMAIL>>
 *
 * This program 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 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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.
 */

#include "export.h"

#include <qpushbutton.h>
#include <qtextcodec.h>

class Export;

/***** ExportFormats *****/
static struct {
    int id;
    QString name;
    QString desc;
    QString ext;
  }

ExportFormats [] = {
    { 1, I18N_NOOP("CSV"),
      I18N_NOOP("Export to a text file, using semicolons as separators.<p></p>Can be used for spreadsheet programs like <i>KSpread</i>."),
      "csv" },
    { 2, I18N_NOOP("HTML"),
      I18N_NOOP("Export to a HTML Page.<p></p>Can be used for easy exchange over the <i>Internet</i>."),
      "html" },
    { 0, QString(), QString(), QString() }  /* !! don't forget !! */
};


/***** ExportWizard *****/
ExportWizard::ExportWizard(QWidget *parent, const QString &_date)
  : K3Wizard(parent, "", true) {
  date = _date;

  filterID = 0;

  setWindowTitle(i18n("Export Wizard for kPPP Logs"));

  /* format-page */
  formatPage = new QWidget();
  QHBoxLayout *formatLayout = new QHBoxLayout(formatPage);

  typeList = new Q3ListBox(formatPage);
  connect(typeList, SIGNAL(highlighted(int)), SLOT (typeHighlighted(int)));
  typeList->setMinimumSize(50, 200);
  typeList->setToolTip( i18n("List with possible output formats"));
  int i=0;
  while (ExportFormats[i].id) { // add each format to the list
    typeList->insertItem(i18n(ExportFormats[i].name.toUtf8()));
    i++;
  }

  formatLayout->addWidget(typeList);
  formatLayout->addSpacing(10);

  typeInfo = new QLabel(formatPage);
  typeInfo->setAlignment(Qt::AlignTop);
  typeInfo->setWordWrap( true );
  typeInfo->setText(i18n("<qt><b>Please choose the output format on the left side.</b></qt>"));
  typeInfo->setMinimumSize(350, 200);
  formatLayout->addWidget(typeInfo);

  addPage(formatPage, i18n("Selection of Filetype"));


  /* filename-page */
  filenamePage = new QWidget();
  QVBoxLayout *filenameLayout = new QVBoxLayout( filenamePage );

  QLabel *fnLbl = new QLabel(filenamePage);
  fnLbl->setText(i18n("Filename:"));
  filenameLayout->addWidget(fnLbl);

  fnLine = new QLineEdit(filenamePage);
  fnLine->setText(i18n("[No file selected]"));
  fnLine->setReadOnly(true);
  filenameLayout->addWidget(fnLine);
  filenameLayout->addStretch(1);

  fnGet = new QPushButton(filenamePage);
  fnGet->setText(i18n("&Select File..."));
  fnGet->setMaximumWidth(200);
  fnGet->setToolTip( i18n("Select the filename of the exported output file"));
  filenameLayout->addWidget(fnGet);
  connect(fnGet, SIGNAL(clicked()), SLOT(getFilename()));
  filenameLayout->addStretch(2);

  addPage(filenamePage, i18n("Selection of Filename"));
  setNextEnabled( filenamePage, false );
  setHelpEnabled( filenamePage, false );

  setNextEnabled( formatPage, false );
  setHelpEnabled( formatPage, false );
}

Export * ExportWizard::createExportFilter() {
  switch (filterID) { // IDs: see data-struct ExportFormats
    case 1 : return new CSVExport(filename, ";");
    case 2 : return new HTMLExport(filename, date);
    default : return NULL; // oops..
  };
}

void ExportWizard::typeHighlighted(int index) {
  typeInfo->setText("<qt><b>"+i18n(ExportFormats[index].name.toUtf8())+' ' +
                    i18n("File Format") + "</b><p></p>" + i18n(ExportFormats[index].desc.toUtf8())
                    +"</qt>");
  setNextEnabled(formatPage, true );
}

void ExportWizard::getFilename() {
  int i = typeList->currentItem();
  if ( i == -1 )
      return;
  // prepare filter: e.g.: HTML (*.html *.HTML)
  QString filter = "*." + ExportFormats[i].ext + " *." + ExportFormats[i].ext.toUpper() + '|' +
                   i18n(ExportFormats[i].name.toUtf8()) + " (*." + ExportFormats[i].ext + " *." +
                   ExportFormats[i].ext.toUpper() + ')';

  filename = KFileDialog::getSaveFileName(QString(date + '.' + ExportFormats[i].ext), filter, 0, i18n("Please Choose File"));
  if (filename.isEmpty()) // no file selected
    return;
  fnLine->setText(filename);
  setFinishEnabled(filenamePage, true);
}

void ExportWizard::reject()  {
    hide();
    filename.clear();
}

void ExportWizard::accept() {
  filterID = typeList->currentItem() + 1; // translate to ID-count in ExportFormats
  hide();
{'fraction_non_alphanumeric': 0.14977277217941118, 'fraction_numerical': 0.01738786801027465, 'mean_word_length': 4.008906481939634, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 105, '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': '722030', 'n_tokens_mistral': 3421, 'n_tokens_neox': 3209, 'n_words': 847}