File indexing completed on 2024-04-28 16:06:13

0001 /* AUDEX CDDA EXTRACTOR
0002  * SPDX-FileCopyrightText: Copyright (C) 2007 Marco Nelles
0003  * <https://userbase.kde.org/Audex>
0004  *
0005  * SPDX-License-Identifier: GPL-3.0-or-later
0006  */
0007 
0008 #include "logviewdialog.h"
0009 
0010 #include <QFileDialog>
0011 #include <QTextStream>
0012 
0013 #include <KConfigGroup>
0014 #include <KLocalizedString>
0015 #include <QDialogButtonBox>
0016 #include <QPushButton>
0017 #include <QVBoxLayout>
0018 
0019 LogViewDialog::LogViewDialog(const QStringList &log, const QString &title, QWidget *parent)
0020     : QDialog(parent)
0021 {
0022     Q_UNUSED(parent);
0023 
0024     setWindowTitle(title);
0025 
0026     auto *mainLayout = new QVBoxLayout;
0027     setLayout(mainLayout);
0028 
0029     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Close);
0030     connect(buttonBox, &QDialogButtonBox::accepted, this, &LogViewDialog::slotSaveLog);
0031     connect(buttonBox, &QDialogButtonBox::rejected, this, &LogViewDialog::slotClosed);
0032 
0033     QWidget *widget = new QWidget(this);
0034     mainLayout->addWidget(widget);
0035     mainLayout->addWidget(buttonBox);
0036     ui.setupUi(widget);
0037 
0038     ui.ktextedit->setPlainText(log.join("\n"));
0039 
0040     this->log = log;
0041     this->title = title;
0042 }
0043 
0044 LogViewDialog::~LogViewDialog()
0045 {
0046 }
0047 
0048 void LogViewDialog::slotClosed()
0049 {
0050     close();
0051 }
0052 
0053 void LogViewDialog::slotSaveLog()
0054 {
0055     save();
0056 }
0057 
0058 void LogViewDialog::save()
0059 {
0060     QString fileName = QFileDialog::getSaveFileName(this, i18n("Save %1", title), QDir::homePath(), "*.log");
0061     if (!fileName.isEmpty()) {
0062         QFile data(fileName);
0063         if (data.open(QFile::WriteOnly | QFile::Truncate)) {
0064             QTextStream out(&data);
0065             out << "AUDEX " << title << Qt::endl;
0066             out << i18n("created on ") << QDateTime::currentDateTime().toString() << Qt::endl;
0067             out << Qt::endl;
0068             for (int i = 0; i < log.count(); i++) {
0069                 out << log.at(i) << Qt::endl;
0070             }
0071         }
0072     }
0073 }