/src/diagnosticsdialog.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 188 lines · 139 code · 28 blank · 21 comment · 8 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. #include "DiagnosticsDialog.h"
  20. #include "ui_DiagnosticsDialog.h"
  21. #include "config.h"
  22. #include "TomahawkVersion.h"
  23. #include "SourceList.h"
  24. #include "accounts/AccountManager.h"
  25. #include "network/Servent.h"
  26. #include "sip/SipHandler.h"
  27. #include "utils/TomahawkUtilsGui.h"
  28. #include "utils/Logger.h"
  29. #include <QLabel>
  30. #include <QTextEdit>
  31. #include <QDialogButtonBox>
  32. #include <QPushButton>
  33. #include <QApplication>
  34. #include <QClipboard>
  35. #include <QDebug>
  36. DiagnosticsDialog::DiagnosticsDialog( QWidget *parent )
  37. : QDialog( parent )
  38. , ui( new Ui::DiagnosticsDialog )
  39. {
  40. ui->setupUi( this );
  41. connect( ui->clipboardButton, SIGNAL( clicked() ), SLOT( copyToClipboard() ) );
  42. connect( ui->logfileButton, SIGNAL( clicked() ), SLOT( openLogfile() ) );
  43. connect( ui->buttonBox, SIGNAL( rejected() ), SLOT( reject() ) );
  44. updateLogView();
  45. }
  46. void
  47. DiagnosticsDialog::updateLogView()
  48. {
  49. QString log;
  50. log.append( QString( "TOMAHAWK DIAGNOSTICS LOG -%1 \n\n" ).arg( QDateTime::currentDateTime().toString() ) );
  51. log.append( "TOMAHAWK-VERSION: " TOMAHAWK_VERSION "\n\n" );
  52. log.append( "NETWORK:\n General:\n" );
  53. if ( Servent::instance()->visibleExternally() )
  54. {
  55. log.append(
  56. QString(
  57. " visible: true\n"
  58. " host: %1\n"
  59. " port: %2\n"
  60. "\n"
  61. ).arg( Servent::instance()->externalAddress() )
  62. .arg( Servent::instance()->externalPort() )
  63. );
  64. }
  65. else
  66. {
  67. log.append( " visible: false\n" );
  68. }
  69. log.append( "ACCOUNTS:\n" );
  70. const QList< Tomahawk::source_ptr > sources = SourceList::instance()->sources( true );
  71. const QList< Tomahawk::Accounts::Account* > accounts = Tomahawk::Accounts::AccountManager::instance()->accounts( Tomahawk::Accounts::SipType );
  72. foreach ( Tomahawk::Accounts::Account* account, accounts )
  73. {
  74. Q_ASSERT( account && account->sipPlugin() );
  75. if ( !account || !account->sipPlugin() )
  76. continue;
  77. connect( account, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
  78. connect( account, SIGNAL( error( int, QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
  79. connect( account->sipPlugin(), SIGNAL( peerOnline( QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
  80. connect( account->sipPlugin(), SIGNAL( peerOffline( QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
  81. connect( account->sipPlugin(), SIGNAL( sipInfoReceived( QString, SipInfo ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
  82. connect( account->sipPlugin(), SIGNAL( softwareVersionReceived( QString, QString ) ), SLOT( updateLogView() ), Qt::UniqueConnection );
  83. log.append( accountLog( account ) + "\n" );
  84. }
  85. ui->text->setText( log );
  86. }
  87. void
  88. DiagnosticsDialog::copyToClipboard()
  89. {
  90. QApplication::clipboard()->setText( ui->text->toPlainText() );
  91. }
  92. void
  93. DiagnosticsDialog::openLogfile()
  94. {
  95. TomahawkUtils::openUrl( Logger::logFile() );
  96. }
  97. QString
  98. DiagnosticsDialog::accountLog( Tomahawk::Accounts::Account* account )
  99. {
  100. QString accountInfo;
  101. QString stateString;
  102. switch( account->connectionState() )
  103. {
  104. case Tomahawk::Accounts::Account::Connecting:
  105. stateString = "Connecting";
  106. break;
  107. case Tomahawk::Accounts::Account::Connected:
  108. stateString = "Connected";
  109. break;
  110. case Tomahawk::Accounts::Account::Disconnected:
  111. stateString = "Disconnected";
  112. break;
  113. case Tomahawk::Accounts::Account::Disconnecting:
  114. stateString = "Disconnecting";
  115. }
  116. accountInfo.append(
  117. QString( " %2 (%1): %3 (%4)\n" )
  118. .arg( account->accountServiceName() )
  119. .arg( account->sipPlugin()->friendlyName() )
  120. .arg( account->accountFriendlyName())
  121. .arg( stateString )
  122. );
  123. foreach( const QString& peerId, account->sipPlugin()->peersOnline() )
  124. {
  125. QString versionString = SipHandler::instance()->versionString( peerId );
  126. SipInfo sipInfo = SipHandler::instance()->sipInfo( peerId );
  127. if ( !sipInfo.isValid() )
  128. {
  129. accountInfo.append(
  130. QString(" %1: %2 %3" /*"(%4)"*/ "\n")
  131. .arg( peerId )
  132. .arg( "sipinfo invalid" )
  133. .arg( versionString )
  134. // .arg( connected ? "connected" : "not connected")
  135. );
  136. }
  137. else if ( sipInfo.isVisible() )
  138. {
  139. accountInfo.append(
  140. QString(" %1: %2:%3 %4" /*" (%5)"*/ "\n")
  141. .arg( peerId )
  142. .arg( sipInfo.host() )
  143. .arg( sipInfo.port() )
  144. .arg( versionString )
  145. // .arg( connected ? "connected" : "not connected")
  146. );
  147. }
  148. else
  149. {
  150. accountInfo.append(
  151. QString(" %1: visible: false %2" /*" (%3)"*/ "\n")
  152. .arg( peerId )
  153. .arg( versionString )
  154. // .arg( connected ? "connected" : "not connected")
  155. );
  156. }
  157. }
  158. accountInfo.append( "\n" );
  159. return accountInfo;
  160. }