1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 05:37:29 +02:00

* Cleaned up DiagnosticsDialog.

This commit is contained in:
Christian Muehlhaeuser
2012-07-12 08:40:17 +02:00
parent f3d3f19ef8
commit a9dff282e3
3 changed files with 102 additions and 190 deletions

View File

@@ -22,10 +22,6 @@
#include "config.h"
#include "accounts/AccountManager.h"
#include "network/Servent.h"
#include "SourceList.h"
#include <QLabel>
#include <QTextEdit>
#include <QDialogButtonBox>
@@ -34,8 +30,13 @@
#include <QClipboard>
#include <QDebug>
#include "utils/Logger.h"
#include "accounts/AccountManager.h"
#include "network/Servent.h"
#include "SourceList.h"
#include "sip/SipHandler.h"
#include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h"
DiagnosticsDialog::DiagnosticsDialog( QWidget *parent )
@@ -44,10 +45,9 @@ DiagnosticsDialog::DiagnosticsDialog( QWidget *parent )
{
ui->setupUi( this );
connect( ui->clipboardButton, SIGNAL( clicked() ), this, SLOT( copyToClipboard() ) );
connect( ui->buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
ui->scrollAreaWidgetContents->setLayout( new QVBoxLayout() );
connect( ui->clipboardButton, SIGNAL( clicked() ), SLOT( copyToClipboard() ) );
connect( ui->logfileButton, SIGNAL( clicked() ), SLOT( openLogfile() ) );
connect( ui->buttonBox, SIGNAL( rejected() ), SLOT( reject() ) );
updateLogView();
}
@@ -58,16 +58,10 @@ DiagnosticsDialog::updateLogView()
{
QString log;
log.append(
QString("TOMAHAWK DIAGNOSTICS LOG -%1 \n\n")
.arg( QDateTime::currentDateTime().toString() )
);
// network
log.append( QString( "TOMAHAWK DIAGNOSTICS LOG -%1 \n\n" ).arg( QDateTime::currentDateTime().toString() ) );
log.append( "TOMAHAWK-VERSION: " TOMAHAWK_VERSION "\n\n" );
// network
log.append( "NETWORK:\n General:\n" );
if ( Servent::instance()->visibleExternally() )
{
log.append(
@@ -86,9 +80,7 @@ DiagnosticsDialog::updateLogView()
log.append( " visible: false" );
}
ui->scrollAreaWidgetContents->layout()->addWidget( new QLabel( log, this ) );
// Peers / Accounts, TODO
ui->scrollAreaWidgetContents->layout()->addWidget( new QLabel( "ACCOUNTS:\n", this ) );
log.append( "ACCOUNTS:\n" );
const QList< Tomahawk::source_ptr > sources = SourceList::instance()->sources( true );
const QList< Tomahawk::Accounts::Account* > accounts = Tomahawk::Accounts::AccountManager::instance()->accounts( Tomahawk::Accounts::SipType );
@@ -98,104 +90,36 @@ DiagnosticsDialog::updateLogView()
if ( !account || !account->sipPlugin() )
continue;
connect( account, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ),
SLOT( onAccountConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );
connect( account, SIGNAL( error( int, QString ) ),
SLOT( onAccountError( int, QString ) ) );
connect( account, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
connect( account, SIGNAL( error( int, QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
connect( account->sipPlugin(), SIGNAL( peerOnline( QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
connect( account->sipPlugin(), SIGNAL( peerOffline( QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
connect( account->sipPlugin(), SIGNAL( sipInfoReceived( QString, SipInfo ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
connect( account->sipPlugin(), SIGNAL( softwareVersionReceived( QString, QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
connect( account->sipPlugin(), SIGNAL( peerOnline( QString ) ), SLOT( onPeerOnline( QString ) ) );
connect( account->sipPlugin(), SIGNAL( peerOffline( QString ) ), SLOT( onPeerOffline( QString ) ) );
connect( account->sipPlugin(), SIGNAL( sipInfoReceived( QString, SipInfo ) ), SLOT( onSipInfoReceived( QString, SipInfo ) ) );
connect( account->sipPlugin(), SIGNAL( softwareVersionReceived( QString, QString ) ), SLOT( onSoftwareVersionReceived( QString, QString ) ) );
QLabel* accountInfoLabel = new QLabel( this );
ui->scrollAreaWidgetContents->layout()->addWidget( accountInfoLabel );
m_accountDescriptionStore.insert( account, accountInfoLabel );
updateAccountLabel( account );
log.append( accountLog( account ) + "\n" );
}
ui->scrollAreaWidgetContents->layout()->addItem( new QSpacerItem( 1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding ) );
ui->text->setText( log );
}
void
DiagnosticsDialog::copyToClipboard()
{
QString log;
foreach ( QLabel* label, m_accountDescriptionStore.values() )
{
log += label->text() + "\n\n";
}
QApplication::clipboard()->setText( log );
QApplication::clipboard()->setText( ui->text->toPlainText() );
}
void
DiagnosticsDialog::onAccountConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState /* state */ )
DiagnosticsDialog::openLogfile()
{
Tomahawk::Accounts::Account* account = qobject_cast< Tomahawk::Accounts::Account* >( sender() );
Q_ASSERT( account );
updateAccountLabel( account );
TomahawkUtils::openUrl( Logger::logFile() );
}
void
DiagnosticsDialog::onAccountError( int /* errorId */ , QString /* errorString */ )
{
Tomahawk::Accounts::Account* account = qobject_cast< Tomahawk::Accounts::Account* >( sender() );
Q_ASSERT( account );
}
void
DiagnosticsDialog::onPeerOnline( const QString& )
{
Tomahawk::Accounts::Account* account = qobject_cast< SipPlugin* >( sender() )->account();
Q_ASSERT( account );
updateAccountLabel( account );
}
void
DiagnosticsDialog::onPeerOffline( const QString& )
{
Tomahawk::Accounts::Account* account = qobject_cast< SipPlugin* >( sender() )->account();
Q_ASSERT( account );
updateAccountLabel( account );
}
void
DiagnosticsDialog::onSipInfoReceived( const QString& /* peerId */ , const SipInfo& /* info */ )
{
Tomahawk::Accounts::Account* account = qobject_cast< SipPlugin* >( sender() )->account();
Q_ASSERT( account );
updateAccountLabel( account );
}
void
DiagnosticsDialog::onSoftwareVersionReceived( const QString& /* peerId */ , const QString& /* versionString */ )
{
Tomahawk::Accounts::Account* account = qobject_cast< SipPlugin* >( sender() )->account();
Q_ASSERT( account );
updateAccountLabel( account );
}
void
DiagnosticsDialog::updateAccountLabel( Tomahawk::Accounts::Account* account )
{
QLabel* accountInfoLabel = m_accountDescriptionStore.value( account );
if ( accountInfoLabel )
QString
DiagnosticsDialog::accountLog( Tomahawk::Accounts::Account* account )
{
QString accountInfo;
QString stateString;
@@ -259,6 +183,5 @@ DiagnosticsDialog::updateAccountLabel( Tomahawk::Accounts::Account* account )
}
accountInfo.append( "\n" );
accountInfoLabel->setText( accountInfo );
}
return accountInfo;
}

View File

@@ -45,19 +45,11 @@ public:
private slots:
void updateLogView();
void copyToClipboard();
void openLogfile();
void onAccountConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
void onAccountError( int errorId, QString errorString );
void onPeerOnline( const QString& );
void onPeerOffline( const QString& );
void onSipInfoReceived( const QString& peerId, const SipInfo& info );
void onSoftwareVersionReceived( const QString& peerId, const QString& versionString );
QString accountLog( Tomahawk::Accounts::Account* );
void updateAccountLabel( Tomahawk::Accounts::Account* );
private:
QMap< Tomahawk::Accounts::Account*, QLabel* > m_accountDescriptionStore;
Ui::DiagnosticsDialog* ui;
};

View File

@@ -26,20 +26,10 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
<widget class="QTextBrowser" name="text">
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>708</width>
<height>386</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
@@ -49,7 +39,14 @@
<item>
<widget class="QPushButton" name="clipboardButton">
<property name="text">
<string>Copy to Clipboard</string>
<string>&amp;Copy to Clipboard</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="logfileButton">
<property name="text">
<string>Open &amp;Log-file</string>
</property>
</widget>
</item>