OSDN Git Service

Fixed number of tools (only relevant for DEBUG builds) + fixed an out-of-bounds array...
[lamexp/LameXP.git] / src / Dialog_LogView.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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.
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 "../tmp/UIC_LogViewDialog.h"
27
28 //Internal
29 #include "Global.h"
30
31 //Qt includes
32 #include <QClipboard>
33 #include <QFileDialog>
34 #include <QMimeData>
35 #include <QTimer>
36
37 LogViewDialog::LogViewDialog(QWidget *parent)
38 :
39         QDialog(parent),
40         m_acceptIcon(new QIcon(":/icons/accept.png")),
41         m_oldIcon(new QIcon()),
42         ui(new Ui::LogViewDialog)
43 {
44         //Init the dialog, from the .ui file
45         ui->setupUi(this);
46         setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
47         
48         //Translate
49         ui->headerText->setText(QString("<b>%1</b><br>%2").arg(tr("Log File"), tr("The log file shows detailed information about the selected job.")));
50
51         //Clear
52         ui->textEdit->clear();
53
54         //Enable buttons
55         connect(ui->buttonCopy, SIGNAL(clicked()), this, SLOT(copyButtonClicked()));
56         connect(ui->buttonSave, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
57
58         //Init flags
59         m_clipboardUsed = false;
60 }
61
62 LogViewDialog::~LogViewDialog(void)
63 {
64         if(m_clipboardUsed)
65         {
66                 QApplication::clipboard()->clear();
67         }
68
69         LAMEXP_DELETE(m_oldIcon);
70         LAMEXP_DELETE(m_acceptIcon);
71         LAMEXP_DELETE(ui);
72 }
73
74 int LogViewDialog::exec(const QStringList &logData)
75 {
76         ui->textEdit->setPlainText(logData.join("\n"));
77         return QDialog::exec();
78 }
79
80 void LogViewDialog::copyButtonClicked(void)
81 {
82         QMimeData *mime = new QMimeData();
83         mime->setData("text/plain", QUTF8(ui->textEdit->toPlainText()));
84         QApplication::clipboard()->setMimeData(mime);
85         m_clipboardUsed = true;
86         m_oldIcon->swap(ui->buttonCopy->icon());
87         ui->buttonCopy->setIcon(*m_acceptIcon);
88         ui->buttonCopy->blockSignals(true);
89         QTimer::singleShot(1250, this, SLOT(restoreIcon()));
90         lamexp_beep(lamexp_beep_info);
91 }
92
93 void LogViewDialog::saveButtonClicked(void)
94 {
95         QString fileName = QFileDialog::getSaveFileName(this, "Save Log File", QDir::homePath(), "Log Files (*.txt)");
96         
97         if(!fileName.isEmpty())
98         {
99                 QFile file(fileName);
100                 if(file.open(QIODevice::WriteOnly))
101                 {
102                         QByteArray data = ui->textEdit->toPlainText().toUtf8();
103                         data.replace("\n", "\r\n");
104                         file.write(data.constData(), data.size());
105                         file.close();
106                 }
107         }
108 }
109
110 void LogViewDialog::restoreIcon(void)
111 {
112         if(!m_oldIcon->isNull())
113         {
114                 ui->buttonCopy->setIcon(*m_oldIcon);
115                 ui->buttonCopy->blockSignals(false);
116                 m_oldIcon->swap(QIcon());
117         }
118 }