messages.cpp 6.26 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*****************************************************************************
 * Messages.cpp : Information about an item
 ****************************************************************************
 * Copyright (C) 2006 the VideoLAN team
 * $Id: Messages.cpp 16024 2006-07-13 13:51:05Z xtophe $
 *
 * Authors: Jean-Baptiste Kempf <jb (at) videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include "input_manager.hpp"
#include "dialogs/messages.hpp"
#include "dialogs_provider.hpp"
#include "util/qvlcframe.hpp"
#include "qt4.hpp"

MessagesDialog *MessagesDialog::instance = NULL;

MessagesDialog::MessagesDialog( intf_thread_t *_p_intf, bool _main_input ) :
                              QVLCFrame( _p_intf ), main_input( _main_input )
{
    setWindowTitle( _("Messages" ) );
zorglub's avatar
zorglub committed
36
    resize(600, 400);
37

38
39
40
41
42
    QGridLayout *layout = new QGridLayout(this);
    QPushButton *closeButton = new QPushButton(qtr("&Close"));
    QPushButton *clearButton = new QPushButton(qtr("&Clear"));
    QPushButton *saveLogButton = new QPushButton(qtr("&Save as..."));
    QSpinBox *verbosityBox = new QSpinBox();
43
44
    verbosityBox->setRange(0, 2);
    verbosityBox->setValue(config_GetInt(p_intf, "verbose"));
45
    verbosityBox->setWrapping(true);
46
    QLabel *verbosityLabel = new QLabel(qtr("Verbosity Level"));
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    messages = new QTextEdit();
    messages->setReadOnly(true);
    messages->setGeometry(0, 0, 440, 600);
    messages->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    layout->addWidget(messages, 0, 0, 1, 0);
    layout->addWidget(verbosityLabel, 1, 0, 1, 1);
    layout->addWidget(verbosityBox, 1, 2);
    layout->addWidget(saveLogButton, 2, 0);
    layout->addWidget(clearButton, 2, 1);
    layout->addWidget(closeButton, 2, 2);

    connect( closeButton, SIGNAL( clicked() ) ,
           this, SLOT( onCloseButton()));
    connect( clearButton, SIGNAL( clicked() ) ,
           this, SLOT( onClearButton()));
    connect( saveLogButton, SIGNAL( clicked() ) ,
           this, SLOT( onSaveButton()));
    connect( verbosityBox, SIGNAL( valueChanged(int) ),
           this, SLOT( onVerbosityChanged(int)));
    connect( DialogsProvider::getInstance(NULL)->fixed_timer,
             SIGNAL( timeout() ), this, SLOT(updateLog() ) );

    p_input = NULL;
}

MessagesDialog::~MessagesDialog()
{
}

void MessagesDialog::updateLog()
{
    msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
    int i_start;

    vlc_mutex_lock( p_sub->p_lock );
    int i_stop = *p_sub->pi_stop;
    vlc_mutex_unlock( p_sub->p_lock );

86
    messages->textCursor().movePosition( QTextCursor::End );
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
    if( p_sub->i_start != i_stop )
    {
        for( i_start = p_sub->i_start;
                i_start != i_stop;
                i_start = (i_start+1) % VLC_MSG_QSIZE )
        {
          // [FIXME] Does not work as the old one
          // Outputs too much data ?
          // if (p_sub->p_msg[i_start].i_type = VLC_MSG_ERR)
          //          continue;
          //  if( !b_verbose &&
          //         VLC_MSG_ERR != p_sub->p_msg[i_start].i_type )
          //                continue;

            /* Append all messages to log window */


            messages->setFontItalic(true);
            messages->setTextColor("darkBlue");
zorglub's avatar
zorglub committed
106
            messages->insertPlainText(p_sub->p_msg[i_start].psz_module);
107
108
109
110
111

            switch( p_sub->p_msg[i_start].i_type )
            {
                case VLC_MSG_INFO:
                    messages->setTextColor("blue");
zorglub's avatar
zorglub committed
112
                    messages->insertPlainText(" info: ");
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
                    break;
                case VLC_MSG_ERR:
                    messages->setTextColor("red");
                    messages->insertPlainText(" error: ");
                    break;
                case VLC_MSG_WARN:
                    messages->setTextColor("green");
                    messages->insertPlainText(" warning: ");
                    break;
                case VLC_MSG_DBG:
                default:
                    messages->setTextColor("grey");
                    messages->insertPlainText(" debug: ");
                    break;
            }

            /* Add message Regular black Font */
            messages->setFontItalic(false);
            messages->setTextColor("black");
zorglub's avatar
zorglub committed
132
            messages->insertPlainText( qfu(p_sub->p_msg[i_start].psz_msg) );
zorglub's avatar
zorglub committed
133
            messages->insertPlainText( "\n" );
134
        }
zorglub's avatar
zorglub committed
135
        messages->ensureCursorVisible();
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187

        vlc_mutex_lock( p_sub->p_lock );
        p_sub->i_start = i_start;
        vlc_mutex_unlock( p_sub->p_lock );
    }
}

void MessagesDialog::onCloseButton()
{
    this->toggleVisible();
}

void MessagesDialog::onClearButton()
{
    messages->clear();
}

bool MessagesDialog::onSaveButton()
{
    QString saveLogFileName = QFileDialog::getSaveFileName(
            this,
            "Choose a filename to save the logs under...",
            p_intf->p_vlc->psz_homedir,
            "Texts / Logs (*.log *.txt);; All (*.*) ");

    if (saveLogFileName != NULL)
    {
        QFile file(saveLogFileName);
        if (!file.open(QFile::WriteOnly | QFile::Text)) {
            QMessageBox::warning(this, qtr("Application"),
                    qtr("Cannot write file %1:\n%2.")
                    .arg(saveLogFileName)
                    .arg(file.errorString()));
            return false;
        }

        QTextStream out(&file);
        out << messages->toPlainText() << "\n";

        return true;
    }
    return false;
}

void MessagesDialog::onVerbosityChanged(int verbosityLevel)
{
    //FIXME: Does not seems to work.
    vlc_value_t  val;
    val.i_int = verbosityLevel - 1;
    var_Set( p_intf->p_vlc, "verbose", val );
}