/* AnyMeal recipe management software
   Copyright (C) 2020, 2025 Jan Wedekind

   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 3 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, see <https://www.gnu.org/licenses/>. */
#include <QtCore/QStandardPaths>
#include <QtWidgets/QFileDialog>
#include "export_dialog.hh"


using namespace std;

ExportDialog::ExportDialog(QWidget *parent):
  QDialog(parent)
{
  m_ui.setupUi(this);
  connect(m_ui.browse_button, &QPushButton::clicked, this, &ExportDialog::select_error_file);
  QDir dir = QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
  m_ui.error_file_edit->setText(dir.filePath("export-errors.mmf"));
}

string ExportDialog::encoding(void) {
  return m_ui.encoding_combo->currentText().toUtf8().constData();
}

string ExportDialog::error_file(void) {
  return m_ui.error_file_edit->text().toUtf8().constData();
}

void ExportDialog::select_error_file(void) {
  QString result = QFileDialog::getSaveFileName(this, tr("Select Error File"), "", tr("MealMaster (*.mm *.MM *.mmf *.MMF);;"
                                                "Text (*.txt *.TXT);;All files (*)"));
  if (!result.isEmpty()) {
    m_ui.error_file_edit->setText(result);
  };
}
