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

Last change on this file since 170 was 165, checked in by Silvan Scherrer, 11 years ago

SMPlayer: update trunk to latest 0.8.7

  • Property svn:eol-style set to LF
File size: 3.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2014 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
30LogWindow::LogWindow( QWidget* parent )
31 : QWidget(parent, Qt::Window )
32{
33 setupUi(this);
34
35 browser->setFont( QFont("fixed") );
36
37 retranslateStrings();
38}
39
40LogWindow::~LogWindow() {
41}
42
43/*
44QTextEdit * LogWindow::editor() {
45 return browser;
46}
47*/
48
49void LogWindow::retranslateStrings() {
50 retranslateUi(this);
51
52 saveButton->setText("");
53 copyButton->setText("");
54
55 saveButton->setIcon( Images::icon("save") );
56 copyButton->setIcon( Images::icon("copy") );
57
58 setWindowIcon( Images::icon("logo") );
59}
60
61
62void LogWindow::setText(QString log) {
63 browser->setPlainText(log);
64}
65
66QString LogWindow::text() {
67 return browser->toPlainText();
68}
69
70void LogWindow::setHtml(QString text) {
71 browser->setHtml(text);
72}
73
74QString LogWindow::html() {
75 return browser->toHtml();
76}
77
78void LogWindow::clear() {
79 browser->clear();
80}
81
82void LogWindow::appendText(QString text) {
83 browser->moveCursor(QTextCursor::End);
84 browser->insertPlainText(text);
85}
86
87void LogWindow::appendHtml(QString text) {
88 browser->moveCursor(QTextCursor::End);
89 browser->insertHtml(text);
90}
91
92void LogWindow::on_copyButton_clicked() {
93 browser->selectAll();
94 browser->copy();
95}
96
97void LogWindow::on_saveButton_clicked() {
98 QString s = MyFileDialog::getSaveFileName(
99 this, tr("Choose a filename to save under"),
100 "", tr("Logs") +" (*.log *.txt)" );
101
102 if (!s.isEmpty()) {
103 if (QFileInfo(s).exists()) {
104 int res =QMessageBox::question( this,
105 tr("Confirm overwrite?"),
106 tr("The file already exists.\n"
107 "Do you want to overwrite?"),
108 QMessageBox::Yes,
109 QMessageBox::No,
110 QMessageBox::NoButton);
111 if (res == QMessageBox::No ) {
112 return;
113 }
114 }
115
116 QFile file( s );
117 if ( file.open( QIODevice::WriteOnly ) ) {
118 QTextStream stream( &file );
119 stream << browser->toPlainText();
120 file.close();
121 } else {
122 // Error opening file
123 qDebug("LogWindow::save: error saving file");
124 QMessageBox::warning ( this,
125 tr("Error saving file"),
126 tr("The log couldn't be saved"),
127 QMessageBox::Ok,
128 QMessageBox::NoButton,
129 QMessageBox::NoButton );
130
131 }
132 }
133}
134
135// Language change stuff
136void LogWindow::changeEvent(QEvent *e) {
137 if (e->type() == QEvent::LanguageChange) {
138 retranslateStrings();
139 } else {
140 QWidget::changeEvent(e);
141 }
142}
143
144#include "moc_logwindow.cpp"
Note: See TracBrowser for help on using the repository browser.