From: Jean-Baptiste Kempf Date: Sat, 19 Aug 2006 13:08:04 +0000 (+0000) Subject: * First implementation of the messages dialog for qt4. X-Git-Tag: 0.9.0-test0~10621 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=2c2ebc9c31414a523710240e5ca6bc743057a42f;p=vlc * First implementation of the messages dialog for qt4. It works but it is not finished. - The changing verbosity does not work yet. - Too many messages are displayed ? --- diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am index 8a14a11162..5e401e1a91 100644 --- a/modules/gui/qt4/Modules.am +++ b/modules/gui/qt4/Modules.am @@ -22,6 +22,7 @@ TOMOC = main_interface \ playlist_model \ dialogs/playlist \ dialogs/prefs_dialog \ + dialogs/messages \ dialogs/streaminfo \ dialogs/interaction \ components/infopanels \ @@ -42,6 +43,7 @@ nodist_SOURCES_qt4 = \ playlist_model.moc.cpp \ dialogs/playlist.moc.cpp \ dialogs/streaminfo.moc.cpp \ + dialogs/messages.moc.cpp \ dialogs/prefs_dialog.moc.cpp \ dialogs/interaction.moc.cpp \ components/infopanels.moc.cpp \ @@ -83,6 +85,7 @@ SOURCES_qt4 = qt4.cpp \ dialogs/playlist.cpp \ dialogs/prefs_dialog.cpp \ dialogs/streaminfo.cpp \ + dialogs/messages.cpp \ dialogs/interaction.cpp \ components/infopanels.cpp \ components/preferences_widgets.cpp \ @@ -104,6 +107,7 @@ EXTRA_DIST += \ res.qrc \ dialogs/playlist.hpp \ dialogs/streaminfo.hpp \ + dialogs/messages.hpp \ dialogs/prefs_dialog.hpp \ dialogs/interaction.hpp \ components/infopanels.hpp \ diff --git a/modules/gui/qt4/dialogs/messages.cpp b/modules/gui/qt4/dialogs/messages.cpp new file mode 100644 index 0000000000..73b437b79e --- /dev/null +++ b/modules/gui/qt4/dialogs/messages.cpp @@ -0,0 +1,184 @@ +/***************************************************************************** + * 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 + * + * 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" ) ); + resize(420, 600); + + layout = new QGridLayout(this); + closeButton = new QPushButton(qtr("&Close")); + clearButton = new QPushButton(qtr("&Clear")); + saveLogButton = new QPushButton(qtr("&Save as...")); + verbosityBox = new QSpinBox(); + verbosityBox->setRange(1, 3); + verbosityBox->setWrapping(true); + verbosityLabel = new QLabel(qtr("Verbosity Level")); + messages = new QTextEdit(); + messages->setReadOnly(true); + messages->setGeometry(0, 0, 440, 600); + messages->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + messagesCursor = new QTextCursor(); + + 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 ); + + 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"); + messages->append(p_sub->p_msg[i_start].psz_module); + + switch( p_sub->p_msg[i_start].i_type ) + { + case VLC_MSG_INFO: + messages->setTextColor("blue"); + messages->insertPlainText(": "); + 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"); + messages->insertPlainText( p_sub->p_msg[i_start].psz_msg ); + } + + 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 ); +} + diff --git a/modules/gui/qt4/dialogs/messages.hpp b/modules/gui/qt4/dialogs/messages.hpp new file mode 100644 index 0000000000..efdd9f8b68 --- /dev/null +++ b/modules/gui/qt4/dialogs/messages.hpp @@ -0,0 +1,71 @@ +/***************************************************************************** + * Messages.hpp : Information about a stream + **************************************************************************** + * Copyright (C) 2006 the VideoLAN team + * $Id: Messages.hpp 16024 2006-07-13 13:51:05Z xtophe $ + * + * Authors: Jean-Baptiste Kempf + * + * 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. *****************************************************************************/ + +#ifndef _MESSAGES_DIALOG_H_ +#define _MESSAGES_DIALOG_H_ + +#include "util/qvlcframe.hpp" +#include +#include +#include +#include +#include +#include +#include + +class MessagesDialog : public QVLCFrame +{ + Q_OBJECT; +public: + static MessagesDialog * getInstance( intf_thread_t *p_intf, bool a ) + { + if( !instance) + instance = new MessagesDialog( p_intf, a ); + return instance; + } + virtual ~MessagesDialog(); + +private: + MessagesDialog( intf_thread_t *, bool ); + input_thread_t *p_input; + bool main_input; + static MessagesDialog *instance; + + QPushButton *closeButton; + QPushButton *clearButton; + QPushButton *saveLogButton; + QGridLayout *layout; + QSpinBox *verbosityBox; + QLabel *verbosityLabel; + QTextEdit *messages; + QTextCursor *messagesCursor; + QFile *saveLogFile; + +public slots: + void updateLog(); + void onCloseButton(); + void onClearButton(); + bool onSaveButton(); + void onVerbosityChanged(int verbosityLevel); +}; + +#endif diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp index fc7827bcc5..f6888371c7 100644 --- a/modules/gui/qt4/dialogs_provider.cpp +++ b/modules/gui/qt4/dialogs_provider.cpp @@ -26,6 +26,7 @@ #include "dialogs/playlist.hpp" #include "dialogs/prefs_dialog.hpp" #include "dialogs/streaminfo.hpp" +#include "dialogs/messages.hpp" #include #include #include "menus.hpp" @@ -155,6 +156,7 @@ void DialogsProvider::prefsDialog() void DialogsProvider::messagesDialog() { + MessagesDialog::getInstance( p_intf, true )->toggleVisible(); } void DialogsProvider::menuAction( QObject *data )