diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45cf481d1..47a058c81 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,6 +64,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui} tomahawktrayicon.cpp audiocontrols.cpp settingsdialog.cpp + diagnosticsdialog.cpp configdelegatebase.cpp sipconfigdelegate.cpp resolverconfigdelegate.cpp @@ -106,6 +107,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui} tomahawktrayicon.h audiocontrols.h settingsdialog.h + diagnosticsdialog.h configdelegatebase.h resolverconfigdelegate.h sipconfigdelegate.h @@ -117,6 +119,7 @@ SET( tomahawkHeadersGui ${tomahawkHeadersGui} SET( tomahawkUI ${tomahawkUI} tomahawkwindow.ui settingsdialog.ui + diagnosticsdialog.ui stackedsettingsdialog.ui proxydialog.ui diff --git a/src/diagnosticsdialog.cpp b/src/diagnosticsdialog.cpp new file mode 100644 index 000000000..865cce92f --- /dev/null +++ b/src/diagnosticsdialog.cpp @@ -0,0 +1,151 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "diagnosticsdialog.h" +#include "ui_diagnosticsdialog.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +DiagnosticsDialog::DiagnosticsDialog( QWidget *parent ) + : QDialog( parent ) + , ui( new Ui::DiagnosticsDialog ) +{ + ui->setupUi( this ); + + connect( ui->updateButton, SIGNAL( clicked() ), this, SLOT( updateLogView() ) ); + connect( ui->clipboardButton, SIGNAL( clicked() ), this, SLOT( copyToClipboard() ) ); + connect( ui->buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) ); + + updateLogView(); +} + +void DiagnosticsDialog::updateLogView() +{ + QString log; + + log.append( + QString("TOMAHAWK DIAGNOSTICS LOG -%1 \n\n") + .arg( QDateTime::currentDateTime().toString() ) + ); + + // network + log.append( + "NETWORK:\n" + " General:\n" + ); + if( Servent::instance()->visibleExternally() ) + { + log.append( + QString( + " visible: true\n" + " host: %1\n" + " port: %2\n" + "\n" + ).arg( Servent::instance()->externalAddress() ) + .arg( Servent::instance()->externalPort() ) + + ); + } + else + { + log.append( + QString( + " visible: false" + ) + ); + } + log.append("\n\n"); + + + // Peers + log.append("SIP PLUGINS:\n"); + QList< Tomahawk::source_ptr > sources = SourceList::instance()->sources( true ); + Q_FOREACH(SipPlugin *sip, SipHandler::instance()->allPlugins()) + { + Q_ASSERT(sip); + QString stateString; + switch( sip->connectionState() ) + { + case SipPlugin::Connecting: + stateString = "Connecting"; + break; + + case SipPlugin::Connected: + stateString = "Connected"; + break; + + case SipPlugin::Disconnected: + stateString = "Disconnected"; + break; + } + log.append( + QString(" %2 (%1): %3 (%4)\n") + .arg(sip->name()) + .arg(sip->friendlyName()) + .arg(sip->accountName()) + .arg(stateString) + ); + + Q_FOREACH( const QString &peerId, sip->peersOnline() ) + { + bool connected = false; + Q_FOREACH( const Tomahawk::source_ptr &source, sources ) + { + if( source->controlConnection() ) + { + connected = true; + break; + } + } + + QVariantMap sipInfo = SipHandler::instance()->sipInfo( peerId ); + if( sipInfo.value( "visible").toBool() ) + log.append( + QString(" %1: %2:%3 (%4)\n") + .arg( peerId ) + .arg( sipInfo.value( "ip" ).toString() ) + .arg( sipInfo.value( "port" ).toString() ) + .arg( connected ? "connected" : "not connected") + ); + else + log.append( + QString(" %1: visible: false (%2)\n") + .arg( peerId ) + .arg( connected ? "connected" : "not connected") + ); + } + log.append("\n"); + } + + ui->logView->setPlainText(log); +} + +void DiagnosticsDialog::copyToClipboard() +{ + QApplication::clipboard()->setText( ui->logView->toPlainText() ); +} + diff --git a/src/diagnosticsdialog.h b/src/diagnosticsdialog.h new file mode 100644 index 000000000..dac82aef3 --- /dev/null +++ b/src/diagnosticsdialog.h @@ -0,0 +1,46 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef DIGANOSTICSDIALOG_H +#define DIAGNOSTICSDIALOG_H + +#include +#include + +namespace Ui +{ + class DiagnosticsDialog; +} + +class DiagnosticsDialog : public QDialog +{ +Q_OBJECT + +public: + explicit DiagnosticsDialog( QWidget* parent = 0 ); + ~DiagnosticsDialog() {}; + +private slots: + void updateLogView(); + void copyToClipboard(); + +private: + Ui::DiagnosticsDialog* ui; +}; + +#endif // DIAGNOSTICSDIALOG_H diff --git a/src/diagnosticsdialog.ui b/src/diagnosticsdialog.ui new file mode 100644 index 000000000..fa7d7cfba --- /dev/null +++ b/src/diagnosticsdialog.ui @@ -0,0 +1,64 @@ + + + DiagnosticsDialog + + + + 0 + 0 + 621 + 434 + + + + + 0 + 353 + + + + Tomahawk Diagnostics + + + + + + + + + + + + + + + Update + + + + + + + Copy to Clipboard + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + + + + diff --git a/src/libtomahawk/sip/SipHandler.cpp b/src/libtomahawk/sip/SipHandler.cpp index b1889c74e..2907ddb8e 100644 --- a/src/libtomahawk/sip/SipHandler.cpp +++ b/src/libtomahawk/sip/SipHandler.cpp @@ -80,7 +80,11 @@ const QPixmap SipHandler::avatar( const QString& name ) const } } - +const QVariantMap +SipHandler::sipInfo(const QString& peerId) const +{ + return m_peersSipInfos.value( peerId ); +} void SipHandler::onSettingsChanged() @@ -510,6 +514,8 @@ SipHandler::onMessage( const QString& from, const QString& msg ) { qDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm"; } + + m_peersSipInfos.insert( from, m ); } diff --git a/src/libtomahawk/sip/SipHandler.h b/src/libtomahawk/sip/SipHandler.h index e108c1d28..8fc7a222b 100644 --- a/src/libtomahawk/sip/SipHandler.h +++ b/src/libtomahawk/sip/SipHandler.h @@ -51,6 +51,8 @@ public: SipPluginFactory* factoryFromPlugin( SipPlugin* p ) const; const QPixmap avatar( const QString& name ) const; + //TODO: implement a proper SipInfo class and maybe attach it to the source + const QVariantMap sipInfo( const QString& peerId ) const; public slots: void checkSettings(); @@ -115,7 +117,8 @@ private: QList< SipPlugin* > m_connectedPlugins; bool m_connected; - + //TODO: move this to source + QHash m_peersSipInfos; QHash m_usernameAvatars; }; diff --git a/src/libtomahawk/sip/SipPlugin.cpp b/src/libtomahawk/sip/SipPlugin.cpp index 57d81588a..7f835a0fe 100644 --- a/src/libtomahawk/sip/SipPlugin.cpp +++ b/src/libtomahawk/sip/SipPlugin.cpp @@ -34,6 +34,8 @@ SipPlugin::SipPlugin( const QString& pluginId, QObject* parent ) { connect( this, SIGNAL( error( int, QString ) ), this, SLOT( onError( int,QString ) ) ); connect( this, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), this, SLOT( onStateChange( SipPlugin::ConnectionState ) ) ); + connect( this, SIGNAL( peerOnline( QString ) ), this, SLOT( onPeerOnline( QString ) ) ); + connect( this, SIGNAL( peerOffline( QString ) ), this, SLOT( onPeerOffline( QString ) ) ); } QString SipPlugin::pluginId() const @@ -67,6 +69,13 @@ SipPlugin::icon() const return QIcon(); } +const QStringList +SipPlugin::peersOnline() const +{ + return m_peersOnline; +} + + void SipPlugin::setProxy( const QNetworkProxy& proxy ) { @@ -85,3 +94,18 @@ SipPlugin::onStateChange( SipPlugin::ConnectionState state ) m_cachedError.clear(); } +void +SipPlugin::onPeerOnline(const QString& peerId) +{ + if( !m_peersOnline.contains( peerId ) ) + { + m_peersOnline.append( peerId ); + } +} + +void +SipPlugin::onPeerOffline(const QString& peerId) +{ + m_peersOnline.removeAll( peerId ); +} + diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index 0903d980d..156944e21 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -76,6 +76,9 @@ public: virtual void saveConfig() {} // called when the widget has been edited virtual QIcon icon() const; + // peer infos + virtual const QStringList peersOnline() const; + public slots: virtual bool connectPlugin( bool startup = false ) = 0; virtual void disconnectPlugin() = 0; @@ -108,9 +111,13 @@ private slots: void onError( int, const QString& ); void onStateChange( SipPlugin::ConnectionState state ); + void onPeerOnline( const QString &peerId ); + void onPeerOffline( const QString &peerId ); + private: QString m_pluginId; QString m_cachedError; + QStringList m_peersOnline; }; Q_DECLARE_INTERFACE( SipPluginFactory, "tomahawk.SipFactory/1.0" ) diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index b2c67e6d5..9b2b7eeb1 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -233,12 +233,6 @@ JabberPlugin::disconnectPlugin() return; } - foreach(const Jreen::JID &peer, m_peers.keys()) - { - handlePeerStatus(peer, Jreen::Presence::Unavailable); - } - - //m_roster->deleteLater(); //m_roster = 0; //m_room->deleteLater(); @@ -326,6 +320,11 @@ JabberPlugin::onDisconnect( Jreen::Client::DisconnectReason reason ) emit stateChanged( m_state ); removeMenuHelper(); + + Q_FOREACH(const Jreen::JID &peer, m_peers.keys()) + { + handlePeerStatus(peer, Jreen::Presence::Unavailable); + } } QString diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 041989bcf..47e5b8394 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -52,6 +52,7 @@ #include "audiocontrols.h" #include "settingsdialog.h" +#include "diagnosticsdialog.h" #include "tomahawksettings.h" #include "sourcelist.h" #include "transferview.h" @@ -261,6 +262,7 @@ TomahawkWindow::setupSignals() // connect( ui->actionPreferences, SIGNAL( triggered() ), SLOT( showSettingsDialog() ) ); + connect( ui->actionDiagnostics, SIGNAL( triggered() ), SLOT( showDiagnosticsDialog() ) ); connect( ui->actionToggleConnect, SIGNAL( triggered() ), APP->sipHandler(), SLOT( toggleConnect() ) ); // connect( ui->actionAddPeerManually, SIGNAL( triggered() ), SLOT( addPeerManually() ) ); connect( ui->actionRescanCollection, SIGNAL( triggered() ), SLOT( updateCollectionManually() ) ); @@ -349,6 +351,13 @@ TomahawkWindow::showSettingsDialog() win.exec(); } +void TomahawkWindow::showDiagnosticsDialog() +{ + qDebug() << Q_FUNC_INFO; + DiagnosticsDialog win; + win.exec(); +} + void TomahawkWindow::updateCollectionManually() diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index f86a5b54d..730ba47ce 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -66,6 +66,7 @@ public slots: void createPlaylist(); void loadSpiff(); void showSettingsDialog(); + void showDiagnosticsDialog(); void updateCollectionManually(); void pluginMenuAdded(QMenu*); void pluginMenuRemoved(QMenu*); diff --git a/src/tomahawkwindow.ui b/src/tomahawkwindow.ui index c4fee4d69..ece2c6407 100644 --- a/src/tomahawkwindow.ui +++ b/src/tomahawkwindow.ui @@ -83,6 +83,8 @@ &Help + + @@ -181,6 +183,11 @@ Meta+Ctrl+Z + + + Diagnostics... + +