1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "logwindow.h"
|
---|
20 | #include <QTextEdit>
|
---|
21 | #include "filedialog.h"
|
---|
22 | #include <QFile>
|
---|
23 | #include <QTextStream>
|
---|
24 | #include <QMessageBox>
|
---|
25 | #include <QFileInfo>
|
---|
26 | #include <QPushButton>
|
---|
27 |
|
---|
28 | #include "images.h"
|
---|
29 |
|
---|
30 | #if QT_VERSION >= 0x050000
|
---|
31 | #include "myscroller.h"
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | LogWindow::LogWindow( QWidget* parent )
|
---|
35 | : QWidget(parent, Qt::Window )
|
---|
36 | {
|
---|
37 | setupUi(this);
|
---|
38 |
|
---|
39 | browser->setFont( QFont("fixed") );
|
---|
40 |
|
---|
41 | #if QT_VERSION >= 0x050000
|
---|
42 | MyScroller::setScroller(browser);
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | retranslateStrings();
|
---|
46 | }
|
---|
47 |
|
---|
48 | LogWindow::~LogWindow() {
|
---|
49 | }
|
---|
50 |
|
---|
51 | /*
|
---|
52 | QTextEdit * LogWindow::editor() {
|
---|
53 | return browser;
|
---|
54 | }
|
---|
55 | */
|
---|
56 |
|
---|
57 | void LogWindow::retranslateStrings() {
|
---|
58 | retranslateUi(this);
|
---|
59 |
|
---|
60 | saveButton->setText("");
|
---|
61 | copyButton->setText("");
|
---|
62 |
|
---|
63 | saveButton->setIcon( Images::icon("save") );
|
---|
64 | copyButton->setIcon( Images::icon("copy") );
|
---|
65 |
|
---|
66 | setWindowIcon( Images::icon("logo") );
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | void LogWindow::setText(QString log) {
|
---|
71 | browser->setPlainText(log);
|
---|
72 | }
|
---|
73 |
|
---|
74 | QString LogWindow::text() {
|
---|
75 | return browser->toPlainText();
|
---|
76 | }
|
---|
77 |
|
---|
78 | void LogWindow::setHtml(QString text) {
|
---|
79 | browser->setHtml(text);
|
---|
80 | }
|
---|
81 |
|
---|
82 | QString LogWindow::html() {
|
---|
83 | return browser->toHtml();
|
---|
84 | }
|
---|
85 |
|
---|
86 | void LogWindow::clear() {
|
---|
87 | browser->clear();
|
---|
88 | }
|
---|
89 |
|
---|
90 | void LogWindow::appendText(QString text) {
|
---|
91 | browser->moveCursor(QTextCursor::End);
|
---|
92 | browser->insertPlainText(text);
|
---|
93 | }
|
---|
94 |
|
---|
95 | void LogWindow::appendHtml(QString text) {
|
---|
96 | browser->moveCursor(QTextCursor::End);
|
---|
97 | browser->insertHtml(text);
|
---|
98 | }
|
---|
99 |
|
---|
100 | void LogWindow::on_copyButton_clicked() {
|
---|
101 | browser->selectAll();
|
---|
102 | browser->copy();
|
---|
103 | }
|
---|
104 |
|
---|
105 | void LogWindow::on_saveButton_clicked() {
|
---|
106 | QString s = MyFileDialog::getSaveFileName(
|
---|
107 | this, tr("Choose a filename to save under"),
|
---|
108 | "", tr("Logs") +" (*.log *.txt)" );
|
---|
109 |
|
---|
110 | if (!s.isEmpty()) {
|
---|
111 | if (QFileInfo(s).exists()) {
|
---|
112 | int res =QMessageBox::question( this,
|
---|
113 | tr("Confirm overwrite?"),
|
---|
114 | tr("The file already exists.\n"
|
---|
115 | "Do you want to overwrite?"),
|
---|
116 | QMessageBox::Yes,
|
---|
117 | QMessageBox::No,
|
---|
118 | QMessageBox::NoButton);
|
---|
119 | if (res == QMessageBox::No ) {
|
---|
120 | return;
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | QFile file( s );
|
---|
125 | if ( file.open( QIODevice::WriteOnly ) ) {
|
---|
126 | QTextStream stream( &file );
|
---|
127 | stream << browser->toPlainText();
|
---|
128 | file.close();
|
---|
129 | } else {
|
---|
130 | // Error opening file
|
---|
131 | qDebug("LogWindow::save: error saving file");
|
---|
132 | QMessageBox::warning ( this,
|
---|
133 | tr("Error saving file"),
|
---|
134 | tr("The log couldn't be saved"),
|
---|
135 | QMessageBox::Ok,
|
---|
136 | QMessageBox::NoButton,
|
---|
137 | QMessageBox::NoButton );
|
---|
138 |
|
---|
139 | }
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | // Language change stuff
|
---|
144 | void LogWindow::changeEvent(QEvent *e) {
|
---|
145 | if (e->type() == QEvent::LanguageChange) {
|
---|
146 | retranslateStrings();
|
---|
147 | } else {
|
---|
148 | QWidget::changeEvent(e);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | #include "moc_logwindow.cpp"
|
---|