OSDN Git Service

Updated changelog.
[lamexp/LameXP.git] / src / Dialog_LogView.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2023 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version; always including the non-optional
9 // LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 //
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "Dialog_LogView.h"
24
25 //UIC includes
26 #include "UIC_LogViewDialog.h"
27
28 //Internal
29 #include "Global.h"
30
31 //MUtils
32 #include <MUtils/Global.h>
33 #include <MUtils/Sound.h>
34
35 //Qt includes
36 #include <QClipboard>
37 #include <QFileDialog>
38 #include <QMimeData>
39 #include <QTimer>
40
41 LogViewDialog::LogViewDialog(QWidget *parent)
42 :
43         QDialog(parent),
44         m_acceptIcon(new QIcon(":/icons/accept.png")),
45         m_oldIcon(new QIcon()),
46         ui(new Ui::LogViewDialog)
47 {
48         //Init the dialog, from the .ui file
49         ui->setupUi(this);
50         setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
51         
52         //Translate
53         ui->headerText->setText(QString("<b>%1</b><br>%2").arg(tr("Log File"), tr("The log file shows detailed information about the selected job.")));
54
55         //Clear
56         ui->textEdit->clear();
57
58         //Enable buttons
59         connect(ui->buttonCopy, SIGNAL(clicked()), this, SLOT(copyButtonClicked()));
60         connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
61
62         //Init flags
63         m_clipboardUsed = false;
64 }
65
66 LogViewDialog::~LogViewDialog(void)
67 {
68         if(m_clipboardUsed)
69         {
70                 QApplication::clipboard()->clear();
71         }
72
73         MUTILS_DELETE(m_oldIcon);
74         MUTILS_DELETE(m_acceptIcon);
75         MUTILS_DELETE(ui);
76 }
77
78 int LogViewDialog::exec(const QStringList &logData)
79 {
80         ui->textEdit->setPlainText(logData.join("\n"));
81         return QDialog::exec();
82 }
83
84 void LogViewDialog::copyButtonClicked(void)
85 {
86         QMimeData *mime = new QMimeData();
87         mime->setData("text/plain", MUTILS_UTF8(ui->textEdit->toPlainText()));
88         QApplication::clipboard()->setMimeData(mime);
89         m_clipboardUsed = true;
90         *m_oldIcon = ui->buttonCopy->icon();
91         ui->buttonCopy->setIcon(*m_acceptIcon);
92         ui->buttonCopy->blockSignals(true);
93         QTimer::singleShot(1250, this, SLOT(restoreIcon()));
94         MUtils::Sound::beep(MUtils::Sound::BEEP_NFO);
95 }
96
97 void LogViewDialog::saveButtonClicked(void)
98 {
99         QString fileName = QFileDialog::getSaveFileName(this, "Save Log File", QDir::homePath(), "Log Files (*.txt)");
100         
101         if(!fileName.isEmpty())
102         {
103                 QFile file(fileName);
104                 if(file.open(QIODevice::WriteOnly))
105                 {
106                         QByteArray data = ui->textEdit->toPlainText().toUtf8();
107                         data.replace("\n", "\r\n");
108                         file.write(data.constData(), data.size());
109                         file.close();
110                 }
111         }
112 }
113
114 void LogViewDialog::restoreIcon(void)
115 {
116         if(!m_oldIcon->isNull())
117         {
118                 ui->buttonCopy->setIcon(*m_oldIcon);
119                 ui->buttonCopy->blockSignals(false);
120                 *m_oldIcon = QIcon();
121         }
122 }