1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Changes to the DiagnosticsDialog that updates when any changes happens

This commit is contained in:
Ahmed 2012-05-25 21:29:45 +02:00 committed by Christian Muehlhaeuser
parent b62b9c3531
commit 65710f9d51
3 changed files with 182 additions and 13 deletions

View File

@ -26,11 +26,13 @@
#include "network/Servent.h"
#include "SourceList.h"
#include <QLabel>
#include <QTextEdit>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include "utils/Logger.h"
#include "sip/SipHandler.h"
@ -42,10 +44,12 @@ DiagnosticsDialog::DiagnosticsDialog( QWidget *parent )
{
ui->setupUi( this );
connect( ui->updateButton, SIGNAL( clicked() ), this, SLOT( updateLogView() ) );
//connect( ui->updateButton, SIGNAL( clicked() ), this, SLOT( updateLogView() ) );
connect( ui->clipboardButton, SIGNAL( clicked() ), this, SLOT( copyToClipboard() ) );
connect( ui->buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
ui->scrollAreaWidgetContents->setLayout( new QVBoxLayout() );
updateLogView();
}
@ -60,7 +64,7 @@ void DiagnosticsDialog::updateLogView()
// network
log.append(
"TOMAHAWK-VERSION: " TOMAHAWK_VERSION "\n\n\n"
"TOMAHAWK-VERSION: " TOMAHAWK_VERSION "\n\n"
);
// network
@ -89,11 +93,15 @@ void DiagnosticsDialog::updateLogView()
)
);
}
log.append("\n\n");
//log.append("\n\n");
ui->scrollAreaWidgetContents->layout()->addWidget( new QLabel( log, this ) );
// Peers / Accounts, TODO
log.append("ACCOUNTS:\n");
ui->scrollAreaWidgetContents->layout()->addWidget( new QLabel( "ACCOUNTS:\n", this ) );
QString accountInfo;
const QList< Tomahawk::source_ptr > sources = SourceList::instance()->sources( true );
const QList< Tomahawk::Accounts::Account* > accounts = Tomahawk::Accounts::AccountManager::instance()->accounts( Tomahawk::Accounts::SipType );
foreach ( Tomahawk::Accounts::Account* account, accounts )
@ -102,6 +110,13 @@ void 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)) );
QString stateString;
switch( account->connectionState() )
{
@ -118,7 +133,7 @@ void DiagnosticsDialog::updateLogView()
case Tomahawk::Accounts::Account::Disconnecting:
stateString = "Disconnecting";
}
log.append(
accountInfo.append(
QString( " %2 (%1): %3 (%4)\n" )
.arg( account->accountServiceName() )
.arg( account->sipPlugin()->friendlyName() )
@ -142,7 +157,7 @@ void DiagnosticsDialog::updateLogView()
QString versionString = SipHandler::instance()->versionString( peerId );
SipInfo sipInfo = SipHandler::instance()->sipInfo( peerId );
if( !sipInfo.isValid() )
log.append(
accountInfo.append(
QString(" %1: %2 %3" /*"(%4)"*/ "\n")
.arg( peerId )
.arg( "sipinfo invalid" )
@ -150,7 +165,7 @@ void DiagnosticsDialog::updateLogView()
// .arg( connected ? "connected" : "not connected")
);
else if( sipInfo.isVisible() )
log.append(
accountInfo.append(
QString(" %1: %2:%3 %4" /*" (%5)"*/ "\n")
.arg( peerId )
.arg( sipInfo.host().hostName() )
@ -160,7 +175,7 @@ void DiagnosticsDialog::updateLogView()
);
else
log.append(
accountInfo.append(
QString(" %1: visible: false %2" /*" (%3)"*/ "\n")
.arg( peerId )
.arg( versionString )
@ -168,13 +183,134 @@ void DiagnosticsDialog::updateLogView()
);
}
log.append("\n");
accountInfo.append("\n");
QLabel *accountInfoLabel = new QLabel( accountInfo, this );
ui->scrollAreaWidgetContents->layout()->addWidget( accountInfoLabel );
m_accountDescriptionStore.insert( account, accountInfoLabel );
accountInfo.clear();
}
ui->logView->setPlainText(log);
//ui->logView->setPlainText(log);
}
void DiagnosticsDialog::copyToClipboard()
{
QApplication::clipboard()->setText( ui->logView->toPlainText() );
//QApplication::clipboard()->setText( ui->logView->toPlainText() );
}
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 );
}
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 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 )
);
foreach( const QString &peerId, account->sipPlugin()->peersOnline() )
{
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().hostName() )
.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 );
}
}

View File

@ -19,7 +19,15 @@
#ifndef DIGANOSTICSDIALOG_H
#define DIAGNOSTICSDIALOG_H
#include "accounts/Account.h"
#include <QDialog>
#include <QMap>
class QLabel;
class SipInfo;
namespace Ui
{
@ -37,8 +45,19 @@ public:
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 updateAccountLabel( Tomahawk::Accounts::Account* );
private:
QMap< Tomahawk::Accounts::Account*, QLabel* > m_accountDescriptionStore;
Ui::DiagnosticsDialog* ui;
};

View File

@ -26,7 +26,21 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="logView"/>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</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>
</item>