Updated Opus encoder/decoder libraries to v1.3-RC-1 (2018-06-01) and Opus-Tools to...
[LameXP.git] / src / Dialog_LogView.cpp
blob70c83a09a93a48589b71276ee13c423af395bd9b
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2018 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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
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.
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.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Dialog_LogView.h"
25 //UIC includes
26 #include "UIC_LogViewDialog.h"
28 //Internal
29 #include "Global.h"
31 //MUtils
32 #include <MUtils/Global.h>
33 #include <MUtils/Sound.h>
35 //Qt includes
36 #include <QClipboard>
37 #include <QFileDialog>
38 #include <QMimeData>
39 #include <QTimer>
41 LogViewDialog::LogViewDialog(QWidget *parent)
43 QDialog(parent),
44 m_acceptIcon(new QIcon(":/icons/accept.png")),
45 m_oldIcon(new QIcon()),
46 ui(new Ui::LogViewDialog)
48 //Init the dialog, from the .ui file
49 ui->setupUi(this);
50 setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
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.")));
55 //Clear
56 ui->textEdit->clear();
58 //Enable buttons
59 connect(ui->buttonCopy, SIGNAL(clicked()), this, SLOT(copyButtonClicked()));
60 connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
62 //Init flags
63 m_clipboardUsed = false;
66 LogViewDialog::~LogViewDialog(void)
68 if(m_clipboardUsed)
70 QApplication::clipboard()->clear();
73 MUTILS_DELETE(m_oldIcon);
74 MUTILS_DELETE(m_acceptIcon);
75 MUTILS_DELETE(ui);
78 int LogViewDialog::exec(const QStringList &logData)
80 ui->textEdit->setPlainText(logData.join("\n"));
81 return QDialog::exec();
84 void LogViewDialog::copyButtonClicked(void)
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->swap(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);
97 void LogViewDialog::saveButtonClicked(void)
99 QString fileName = QFileDialog::getSaveFileName(this, "Save Log File", QDir::homePath(), "Log Files (*.txt)");
101 if(!fileName.isEmpty())
103 QFile file(fileName);
104 if(file.open(QIODevice::WriteOnly))
106 QByteArray data = ui->textEdit->toPlainText().toUtf8();
107 data.replace("\n", "\r\n");
108 file.write(data.constData(), data.size());
109 file.close();
114 void LogViewDialog::restoreIcon(void)
116 if(!m_oldIcon->isNull())
118 ui->buttonCopy->setIcon(*m_oldIcon);
119 ui->buttonCopy->blockSignals(false);
120 m_oldIcon->swap(QIcon());