1 /*****************************************************************************
2 * Messages.cpp : Information about an item
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * $Id: Messages.cpp 16024 2006-07-13 13:51:05Z xtophe $
7 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "input_manager.hpp"
25 #include "dialogs/messages.hpp"
26 #include "dialogs_provider.hpp"
27 #include "util/qvlcframe.hpp"
30 MessagesDialog *MessagesDialog::instance = NULL;
32 MessagesDialog::MessagesDialog( intf_thread_t *_p_intf, bool _main_input ) :
33 QVLCFrame( _p_intf ), main_input( _main_input )
35 setWindowTitle( _("Messages" ) );
38 layout = new QGridLayout(this);
39 closeButton = new QPushButton(qtr("&Close"));
40 clearButton = new QPushButton(qtr("&Clear"));
41 saveLogButton = new QPushButton(qtr("&Save as..."));
42 verbosityBox = new QSpinBox();
43 verbosityBox->setRange(1, 3);
44 verbosityBox->setWrapping(true);
45 verbosityLabel = new QLabel(qtr("Verbosity Level"));
46 messages = new QTextEdit();
47 messages->setReadOnly(true);
48 messages->setGeometry(0, 0, 440, 600);
49 messages->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
50 messagesCursor = new QTextCursor();
52 layout->addWidget(messages, 0, 0, 1, 0);
53 layout->addWidget(verbosityLabel, 1, 0, 1, 1);
54 layout->addWidget(verbosityBox, 1, 2);
55 layout->addWidget(saveLogButton, 2, 0);
56 layout->addWidget(clearButton, 2, 1);
57 layout->addWidget(closeButton, 2, 2);
59 connect( closeButton, SIGNAL( clicked() ) ,
60 this, SLOT( onCloseButton()));
61 connect( clearButton, SIGNAL( clicked() ) ,
62 this, SLOT( onClearButton()));
63 connect( saveLogButton, SIGNAL( clicked() ) ,
64 this, SLOT( onSaveButton()));
65 connect( verbosityBox, SIGNAL( valueChanged(int) ),
66 this, SLOT( onVerbosityChanged(int)));
67 connect( DialogsProvider::getInstance(NULL)->fixed_timer,
68 SIGNAL( timeout() ), this, SLOT(updateLog() ) );
73 MessagesDialog::~MessagesDialog()
77 void MessagesDialog::updateLog()
79 msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
82 vlc_mutex_lock( p_sub->p_lock );
83 int i_stop = *p_sub->pi_stop;
84 vlc_mutex_unlock( p_sub->p_lock );
86 if( p_sub->i_start != i_stop )
88 for( i_start = p_sub->i_start;
90 i_start = (i_start+1) % VLC_MSG_QSIZE )
92 // [FIXME] Does not work as the old one
93 // Outputs too much data ?
94 // if (p_sub->p_msg[i_start].i_type = VLC_MSG_ERR)
97 // VLC_MSG_ERR != p_sub->p_msg[i_start].i_type )
100 /* Append all messages to log window */
103 messages->setFontItalic(true);
104 messages->setTextColor("darkBlue");
105 messages->append(p_sub->p_msg[i_start].psz_module);
107 switch( p_sub->p_msg[i_start].i_type )
110 messages->setTextColor("blue");
111 messages->insertPlainText(": ");
114 messages->setTextColor("red");
115 messages->insertPlainText(" error: ");
118 messages->setTextColor("green");
119 messages->insertPlainText(" warning: ");
123 messages->setTextColor("grey");
124 messages->insertPlainText(" debug: ");
128 /* Add message Regular black Font */
129 messages->setFontItalic(false);
130 messages->setTextColor("black");
131 messages->insertPlainText( p_sub->p_msg[i_start].psz_msg );
134 vlc_mutex_lock( p_sub->p_lock );
135 p_sub->i_start = i_start;
136 vlc_mutex_unlock( p_sub->p_lock );
140 void MessagesDialog::onCloseButton()
142 this->toggleVisible();
145 void MessagesDialog::onClearButton()
150 bool MessagesDialog::onSaveButton()
152 QString saveLogFileName = QFileDialog::getSaveFileName(
154 "Choose a filename to save the logs under...",
155 p_intf->p_vlc->psz_homedir,
156 "Texts / Logs (*.log *.txt);; All (*.*) ");
158 if (saveLogFileName != NULL)
160 QFile file(saveLogFileName);
161 if (!file.open(QFile::WriteOnly | QFile::Text)) {
162 QMessageBox::warning(this, qtr("Application"),
163 qtr("Cannot write file %1:\n%2.")
164 .arg(saveLogFileName)
165 .arg(file.errorString()));
169 QTextStream out(&file);
170 out << messages->toPlainText() << "\n";
177 void MessagesDialog::onVerbosityChanged(int verbosityLevel)
179 //FIXME: Does not seems to work.
181 val.i_int = verbosityLevel - 1;
182 var_Set( p_intf->p_vlc, "verbose", val );