source: smplayer/trunk/src/logwindow.cpp@ 188

Last change on this file since 188 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

  • Property svn:eol-style set to LF
File size: 3.7 KB
Line 
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
34LogWindow::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
48LogWindow::~LogWindow() {
49}
50
51/*
52QTextEdit * LogWindow::editor() {
53 return browser;
54}
55*/
56
57void 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
70void LogWindow::setText(QString log) {
71 browser->setPlainText(log);
72}
73
74QString LogWindow::text() {
75 return browser->toPlainText();
76}
77
78void LogWindow::setHtml(QString text) {
79 browser->setHtml(text);
80}
81
82QString LogWindow::html() {
83 return browser->toHtml();
84}
85
86void LogWindow::clear() {
87 browser->clear();
88}
89
90void LogWindow::appendText(QString text) {
91 browser->moveCursor(QTextCursor::End);
92 browser->insertPlainText(text);
93}
94
95void LogWindow::appendHtml(QString text) {
96 browser->moveCursor(QTextCursor::End);
97 browser->insertHtml(text);
98}
99
100void LogWindow::on_copyButton_clicked() {
101 browser->selectAll();
102 browser->copy();
103}
104
105void 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
144void 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"
Note: See TracBrowser for help on using the repository browser.