PageRenderTime 164ms CodeModel.GetById 40ms app.highlight 61ms RepoModel.GetById 60ms app.codeStats 0ms

/src/diagnosticsdialog.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 188 lines | 139 code | 28 blank | 21 comment | 7 complexity | 6373683eb0fa8ebdbffe57c0a7b9ae4d MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2011, Dominik Schmidt <dev@dominik-schmidt.de>
  4 *   Copyright 2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#include "DiagnosticsDialog.h"
 21#include "ui_DiagnosticsDialog.h"
 22
 23#include "config.h"
 24#include "TomahawkVersion.h"
 25
 26#include "SourceList.h"
 27
 28#include "accounts/AccountManager.h"
 29#include "network/Servent.h"
 30#include "sip/SipHandler.h"
 31#include "utils/TomahawkUtilsGui.h"
 32#include "utils/Logger.h"
 33
 34#include <QLabel>
 35#include <QTextEdit>
 36#include <QDialogButtonBox>
 37#include <QPushButton>
 38#include <QApplication>
 39#include <QClipboard>
 40#include <QDebug>
 41
 42
 43DiagnosticsDialog::DiagnosticsDialog( QWidget *parent )
 44    : QDialog( parent )
 45    , ui( new Ui::DiagnosticsDialog )
 46{
 47    ui->setupUi( this );
 48
 49    connect( ui->clipboardButton, SIGNAL( clicked() ), SLOT( copyToClipboard() ) );
 50    connect( ui->logfileButton, SIGNAL( clicked() ), SLOT( openLogfile() ) );
 51    connect( ui->buttonBox, SIGNAL( rejected() ), SLOT( reject() ) );
 52
 53    updateLogView();
 54}
 55
 56
 57void
 58DiagnosticsDialog::updateLogView()
 59{
 60    QString log;
 61
 62    log.append( QString( "TOMAHAWK DIAGNOSTICS LOG -%1 \n\n" ).arg( QDateTime::currentDateTime().toString() ) );
 63    log.append( "TOMAHAWK-VERSION: " TOMAHAWK_VERSION "\n\n" );
 64    log.append( "NETWORK:\n    General:\n" );
 65
 66    if ( Servent::instance()->visibleExternally() )
 67    {
 68        log.append(
 69            QString(
 70                "      visible: true\n"
 71                "      host: %1\n"
 72                "      port: %2\n"
 73                "\n"
 74            ).arg( Servent::instance()->externalAddress() )
 75             .arg( Servent::instance()->externalPort() )
 76
 77        );
 78    }
 79    else
 80    {
 81        log.append( "      visible: false\n" );
 82    }
 83
 84    log.append( "ACCOUNTS:\n" );
 85
 86    const QList< Tomahawk::source_ptr > sources = SourceList::instance()->sources( true );
 87    const QList< Tomahawk::Accounts::Account* > accounts = Tomahawk::Accounts::AccountManager::instance()->accounts( Tomahawk::Accounts::SipType );
 88    foreach ( Tomahawk::Accounts::Account* account, accounts )
 89    {
 90        Q_ASSERT( account && account->sipPlugin() );
 91        if ( !account || !account->sipPlugin() )
 92            continue;
 93
 94        connect( account, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
 95        connect( account, SIGNAL( error( int, QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
 96        connect( account->sipPlugin(), SIGNAL( peerOnline( QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
 97        connect( account->sipPlugin(), SIGNAL( peerOffline( QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
 98        connect( account->sipPlugin(), SIGNAL( sipInfoReceived( QString, SipInfo ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
 99        connect( account->sipPlugin(), SIGNAL( softwareVersionReceived( QString, QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
100
101        log.append( accountLog( account ) + "\n" );
102    }
103
104    ui->text->setText( log );
105}
106
107
108void
109DiagnosticsDialog::copyToClipboard()
110{
111    QApplication::clipboard()->setText( ui->text->toPlainText() );
112}
113
114
115void
116DiagnosticsDialog::openLogfile()
117{
118    TomahawkUtils::openUrl( Logger::logFile() );
119}
120
121
122QString
123DiagnosticsDialog::accountLog( Tomahawk::Accounts::Account* account )
124{
125    QString accountInfo;
126    QString stateString;
127    switch( account->connectionState() )
128    {
129        case Tomahawk::Accounts::Account::Connecting:
130            stateString = "Connecting";
131            break;
132        case Tomahawk::Accounts::Account::Connected:
133            stateString = "Connected";
134            break;
135
136        case Tomahawk::Accounts::Account::Disconnected:
137            stateString = "Disconnected";
138            break;
139        case Tomahawk::Accounts::Account::Disconnecting:
140            stateString = "Disconnecting";
141    }
142    accountInfo.append(
143        QString( "  %2 (%1): %3 (%4)\n" )
144            .arg( account->accountServiceName() )
145            .arg( account->sipPlugin()->friendlyName() )
146            .arg( account->accountFriendlyName())
147            .arg( stateString )
148    );
149
150    foreach( const QString& peerId, account->sipPlugin()->peersOnline() )
151    {
152        QString versionString = SipHandler::instance()->versionString( peerId );
153        SipInfo sipInfo = SipHandler::instance()->sipInfo( peerId );
154        if ( !sipInfo.isValid() )
155        {
156            accountInfo.append(
157                QString("       %1: %2 %3" /*"(%4)"*/ "\n")
158                    .arg( peerId )
159                    .arg( "sipinfo invalid" )
160                    .arg( versionString )
161                    // .arg( connected ? "connected" : "not connected")
162            );
163        }
164        else if ( sipInfo.isVisible() )
165        {
166            accountInfo.append(
167                QString("       %1: %2:%3 %4" /*" (%5)"*/ "\n")
168                    .arg( peerId )
169                    .arg( sipInfo.host() )
170                    .arg( sipInfo.port() )
171                    .arg( versionString )
172                    // .arg( connected ? "connected" : "not connected")
173            );
174        }
175        else
176        {
177            accountInfo.append(
178                QString("       %1: visible: false %2" /*" (%3)"*/ "\n")
179                    .arg( peerId )
180                    .arg( versionString )
181                    // .arg( connected ? "connected" : "not connected")
182            );
183        }
184    }
185    accountInfo.append( "\n" );
186
187    return accountInfo;
188}