Skip to content

Commit

Permalink
* Cleaned up DiagnosticsDialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jul 12, 2012
1 parent eb749b1 commit bf21398
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 183 deletions.
239 changes: 81 additions & 158 deletions src/DiagnosticsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@

#include "config.h"

#include "accounts/AccountManager.h"
#include "network/Servent.h"
#include "SourceList.h"

#include <QLabel>
#include <QTextEdit>
#include <QDialogButtonBox>
Expand All @@ -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 )
Expand All @@ -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();
}
Expand All @@ -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(
Expand All @@ -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 );
Expand All @@ -98,167 +90,98 @@ 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->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 ) ) );
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 );

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 );
}


void
DiagnosticsDialog::onAccountConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState /* state */ )
{
Tomahawk::Accounts::Account* account = qobject_cast< Tomahawk::Accounts::Account* >( sender() );
Q_ASSERT( account );

updateAccountLabel( account );
}


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 );
QApplication::clipboard()->setText( ui->text->toPlainText() );
}


void
DiagnosticsDialog::onSipInfoReceived( const QString& /* peerId */ , const SipInfo& /* info */ )
DiagnosticsDialog::openLogfile()
{
Tomahawk::Accounts::Account* account = qobject_cast< SipPlugin* >( sender() )->account();
Q_ASSERT( account );

updateAccountLabel( account );
TomahawkUtils::openUrl( Logger::logFile() );
}


void
DiagnosticsDialog::onSoftwareVersionReceived( const QString& /* peerId */ , const QString& /* versionString */ )
QString
DiagnosticsDialog::accountLog( Tomahawk::Accounts::Account* account )
{
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 );
QString accountInfo;
QString stateString;
switch( account->connectionState() )
{
case Tomahawk::Accounts::Account::Connecting:
stateString = "Connecting";
break;
case Tomahawk::Accounts::Account::Connected:
stateString = "Connected";
break;

case Tomahawk::Accounts::Account::Disconnected:
stateString = "Disconnected";
break;
case Tomahawk::Accounts::Account::Disconnecting:
stateString = "Disconnecting";
}
accountInfo.append(
QString( " %2 (%1): %3 (%4)\n" )
.arg( account->accountServiceName() )
.arg( account->sipPlugin()->friendlyName() )
.arg( account->accountFriendlyName())
.arg( stateString )
);

if ( accountInfoLabel )
foreach( const QString& peerId, account->sipPlugin()->peersOnline() )
{
QString accountInfo;
QString stateString;
switch( account->connectionState() )
QString versionString = SipHandler::instance()->versionString( peerId );
SipInfo sipInfo = SipHandler::instance()->sipInfo( peerId );
if ( !sipInfo.isValid() )
{
case Tomahawk::Accounts::Account::Connecting:
stateString = "Connecting";
break;
case Tomahawk::Accounts::Account::Connected:
stateString = "Connected";
break;

case Tomahawk::Accounts::Account::Disconnected:
stateString = "Disconnected";
break;
case Tomahawk::Accounts::Account::Disconnecting:
stateString = "Disconnecting";
accountInfo.append(
QString(" %1: %2 %3" /*"(%4)"*/ "\n")
.arg( peerId )
.arg( "sipinfo invalid" )
.arg( versionString )
// .arg( connected ? "connected" : "not connected")
);
}
accountInfo.append(
QString( " %2 (%1): %3 (%4)\n" )
.arg( account->accountServiceName() )
.arg( account->sipPlugin()->friendlyName() )
.arg( account->accountFriendlyName())
.arg( stateString )
);

foreach( const QString& peerId, account->sipPlugin()->peersOnline() )
else if ( sipInfo.isVisible() )
{
QString versionString = SipHandler::instance()->versionString( peerId );
SipInfo sipInfo = SipHandler::instance()->sipInfo( peerId );
if ( !sipInfo.isValid() )
{
accountInfo.append(
QString(" %1: %2 %3" /*"(%4)"*/ "\n")
.arg( peerId )
.arg( "sipinfo invalid" )
.arg( versionString )
// .arg( connected ? "connected" : "not connected")
);
}
else if ( sipInfo.isVisible() )
{
accountInfo.append(
QString(" %1: %2:%3 %4" /*" (%5)"*/ "\n")
.arg( peerId )
.arg( sipInfo.host() )
.arg( sipInfo.port() )
.arg( versionString )
// .arg( connected ? "connected" : "not connected")
);
}
else
{
accountInfo.append(
QString(" %1: visible: false %2" /*" (%3)"*/ "\n")
.arg( peerId )
.arg( versionString )
// .arg( connected ? "connected" : "not connected")
);
}
accountInfo.append(
QString(" %1: %2:%3 %4" /*" (%5)"*/ "\n")
.arg( peerId )
.arg( sipInfo.host() )
.arg( sipInfo.port() )
.arg( versionString )
// .arg( connected ? "connected" : "not connected")
);
}
else
{
accountInfo.append(
QString(" %1: visible: false %2" /*" (%3)"*/ "\n")
.arg( peerId )
.arg( versionString )
// .arg( connected ? "connected" : "not connected")
);
}
accountInfo.append( "\n" );

accountInfoLabel->setText( accountInfo );
}
accountInfo.append( "\n" );

return accountInfo;
}
14 changes: 3 additions & 11 deletions src/DiagnosticsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,11 @@ Q_OBJECT
private slots:
void updateLogView();
void copyToClipboard();

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 );
void openLogfile();

QString accountLog( Tomahawk::Accounts::Account* );

void updateAccountLabel( Tomahawk::Accounts::Account* );
private:

QMap< Tomahawk::Accounts::Account*, QLabel* > m_accountDescriptionStore;

Ui::DiagnosticsDialog* ui;
};

Expand Down
25 changes: 11 additions & 14 deletions src/DiagnosticsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit bf21398

Please sign in to comment.