]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/messages.cpp
Initialize the verbosity box
[vlc] / modules / gui / qt4 / dialogs / messages.cpp
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 $
6  *
7  * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include "input_manager.hpp"
25 #include "dialogs/messages.hpp"
26 #include "dialogs_provider.hpp"
27 #include "util/qvlcframe.hpp"
28 #include "qt4.hpp"
29
30 MessagesDialog *MessagesDialog::instance = NULL;
31
32 MessagesDialog::MessagesDialog( intf_thread_t *_p_intf, bool _main_input ) :
33                               QVLCFrame( _p_intf ), main_input( _main_input )
34 {
35     setWindowTitle( _("Messages" ) );
36     resize(600, 400);
37
38     QGridLayout *layout = new QGridLayout(this);
39     QPushButton *closeButton = new QPushButton(qtr("&Close"));
40     QPushButton *clearButton = new QPushButton(qtr("&Clear"));
41     QPushButton *saveLogButton = new QPushButton(qtr("&Save as..."));
42     QSpinBox *verbosityBox = new QSpinBox();
43     verbosityBox->setRange(0, 2);
44     verbosityBox->setValue(config_GetInt(p_intf, "verbose"));
45     verbosityBox->setWrapping(true);
46     QLabel *verbosityLabel = new QLabel(qtr("Verbosity Level"));
47     messages = new QTextEdit();
48     messages->setReadOnly(true);
49     messages->setGeometry(0, 0, 440, 600);
50     messages->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
51
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);
58
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() ) );
69
70     p_input = NULL;
71 }
72
73 MessagesDialog::~MessagesDialog()
74 {
75 }
76
77 void MessagesDialog::updateLog()
78 {
79     msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
80     int i_start;
81
82     vlc_mutex_lock( p_sub->p_lock );
83     int i_stop = *p_sub->pi_stop;
84     vlc_mutex_unlock( p_sub->p_lock );
85
86     messages->textCursor().movePosition( QTextCursor::End );
87     if( p_sub->i_start != i_stop )
88     {
89         for( i_start = p_sub->i_start;
90                 i_start != i_stop;
91                 i_start = (i_start+1) % VLC_MSG_QSIZE )
92         {
93           // [FIXME] Does not work as the old one
94           // Outputs too much data ?
95           // if (p_sub->p_msg[i_start].i_type = VLC_MSG_ERR)
96           //          continue;
97           //  if( !b_verbose &&
98           //         VLC_MSG_ERR != p_sub->p_msg[i_start].i_type )
99           //                continue;
100
101             /* Append all messages to log window */
102
103
104             messages->setFontItalic(true);
105             messages->setTextColor("darkBlue");
106             messages->insertPlainText(p_sub->p_msg[i_start].psz_module);
107
108             switch( p_sub->p_msg[i_start].i_type )
109             {
110                 case VLC_MSG_INFO:
111                     messages->setTextColor("blue");
112                     messages->insertPlainText(" info: ");
113                     break;
114                 case VLC_MSG_ERR:
115                     messages->setTextColor("red");
116                     messages->insertPlainText(" error: ");
117                     break;
118                 case VLC_MSG_WARN:
119                     messages->setTextColor("green");
120                     messages->insertPlainText(" warning: ");
121                     break;
122                 case VLC_MSG_DBG:
123                 default:
124                     messages->setTextColor("grey");
125                     messages->insertPlainText(" debug: ");
126                     break;
127             }
128
129             /* Add message Regular black Font */
130             messages->setFontItalic(false);
131             messages->setTextColor("black");
132             messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
133             messages->insertPlainText( "\n" );
134         }
135         messages->ensureCursorVisible();
136
137         vlc_mutex_lock( p_sub->p_lock );
138         p_sub->i_start = i_start;
139         vlc_mutex_unlock( p_sub->p_lock );
140     }
141 }
142
143 void MessagesDialog::onCloseButton()
144 {
145     this->toggleVisible();
146 }
147
148 void MessagesDialog::onClearButton()
149 {
150     messages->clear();
151 }
152
153 bool MessagesDialog::onSaveButton()
154 {
155     QString saveLogFileName = QFileDialog::getSaveFileName(
156             this,
157             "Choose a filename to save the logs under...",
158             p_intf->p_vlc->psz_homedir,
159             "Texts / Logs (*.log *.txt);; All (*.*) ");
160
161     if (saveLogFileName != NULL)
162     {
163         QFile file(saveLogFileName);
164         if (!file.open(QFile::WriteOnly | QFile::Text)) {
165             QMessageBox::warning(this, qtr("Application"),
166                     qtr("Cannot write file %1:\n%2.")
167                     .arg(saveLogFileName)
168                     .arg(file.errorString()));
169             return false;
170         }
171
172         QTextStream out(&file);
173         out << messages->toPlainText() << "\n";
174
175         return true;
176     }
177     return false;
178 }
179
180 void MessagesDialog::onVerbosityChanged(int verbosityLevel)
181 {
182     //FIXME: Does not seems to work.
183     vlc_value_t  val;
184     val.i_int = verbosityLevel - 1;
185     var_Set( p_intf->p_vlc, "verbose", val );
186 }
187