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

View File

@@ -45,19 +45,11 @@ public:
private slots: private slots:
void updateLogView(); void updateLogView();
void copyToClipboard(); void copyToClipboard();
void openLogfile();
void onAccountConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState state ); QString accountLog( Tomahawk::Accounts::Account* );
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 );
void updateAccountLabel( Tomahawk::Accounts::Account* );
private: private:
QMap< Tomahawk::Accounts::Account*, QLabel* > m_accountDescriptionStore;
Ui::DiagnosticsDialog* ui; Ui::DiagnosticsDialog* ui;
}; };

View File

@@ -26,20 +26,10 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QScrollArea" name="scrollArea"> <widget class="QTextBrowser" name="text">
<property name="widgetResizable"> <property name="lineWrapMode">
<bool>true</bool> <enum>QTextEdit::NoWrap</enum>
</property> </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> </widget>
</item> </item>
</layout> </layout>
@@ -49,7 +39,14 @@
<item> <item>
<widget class="QPushButton" name="clipboardButton"> <widget class="QPushButton" name="clipboardButton">
<property name="text"> <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> </property>
</widget> </widget>
</item> </item>