OSDN Git Service

Update MediaInfo binaries to v0.7.53 (2012-01-24), compiled with ICL 12.1.6 and MSVC...
[lamexp/LameXP.git] / src / Dialog_LogView.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "Dialog_LogView.h"
23
24 #include "Global.h"
25
26 #include <QClipboard>
27 #include <QFileDialog>
28
29 LogViewDialog::LogViewDialog(QWidget *parent)
30 :
31         QDialog(parent)
32 {
33         //Init the dialog, from the .ui file
34         setupUi(this);
35         setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
36         
37         //Translate
38         headerText->setText(QString("<b>%1</b><br>%2").arg(tr("Log File"), tr("The log file shows detailed information about the selected job.")));
39
40         //Clear
41         textEdit->clear();
42
43         //Enable buttons
44         connect(buttonCopy, SIGNAL(clicked()), this, SLOT(copyButtonClicked()));
45         connect(buttonSave, SIGNAL(clicked()), this, SLOT(saveButtonClicked()));
46
47         //Init flags
48         m_clipboardUsed = false;
49 }
50
51 LogViewDialog::~LogViewDialog(void)
52 {
53         if(m_clipboardUsed)
54         {
55                 QApplication::clipboard()->clear();
56         }
57 }
58
59 int LogViewDialog::exec(const QStringList &logData)
60 {
61         textEdit->setPlainText(logData.join("\n"));
62         return QDialog::exec();
63 }
64
65 void LogViewDialog::copyButtonClicked(void)
66 {
67         QMimeData *mime = new QMimeData();
68         mime->setData("text/plain", textEdit->toPlainText().toUtf8().constData());
69         QApplication::clipboard()->setMimeData(mime);
70         m_clipboardUsed = true;
71         MessageBeep(MB_ICONINFORMATION);
72 }
73
74 void LogViewDialog::saveButtonClicked(void)
75 {
76         QString fileName = QFileDialog::getSaveFileName(this, "Save Log File", QDir::homePath(), "Log Files (*.txt)");
77         
78         if(!fileName.isEmpty())
79         {
80                 QFile file(fileName);
81                 if(file.open(QIODevice::WriteOnly))
82                 {
83                         QByteArray data = textEdit->toPlainText().toUtf8();
84                         data.replace("\n", "\r\n");
85                         file.write(data.constData(), data.size());
86                         file.close();
87                 }
88         }
89 }