1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02:00

Move SipHandler from application to library

This commit is contained in:
Dominik Schmidt
2011-04-20 20:22:06 +02:00
parent d87398c47a
commit def3e3d868
4 changed files with 84 additions and 8 deletions

View File

@@ -32,8 +32,6 @@ ENDIF()
#ENDFOREACH( moddir ) #ENDFOREACH( moddir )
SET( tomahawkSources ${tomahawkSources} SET( tomahawkSources ${tomahawkSources}
sip/SipHandler.cpp
web/api_v1.cpp web/api_v1.cpp
resolvers/scriptresolver.cpp resolvers/scriptresolver.cpp
@@ -71,7 +69,6 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
SET( tomahawkHeaders ${tomahawkHeaders} SET( tomahawkHeaders ${tomahawkHeaders}
"${TOMAHAWK_INC_DIR}/tomahawk/tomahawkapp.h" "${TOMAHAWK_INC_DIR}/tomahawk/tomahawkapp.h"
sip/SipHandler.h
web/api_v1.h web/api_v1.h

View File

@@ -29,6 +29,7 @@ set( libSources
viewpage.cpp viewpage.cpp
sip/SipPlugin.cpp sip/SipPlugin.cpp
sip/SipHandler.cpp
audio/madtranscode.cpp audio/madtranscode.cpp
audio/dummytranscode.cpp audio/dummytranscode.cpp
@@ -187,6 +188,7 @@ set( libHeaders
playlist.h playlist.h
sip/SipPlugin.h sip/SipPlugin.h
sip/SipHandler.h
audio/transcodeinterface.h audio/transcodeinterface.h
audio/madtranscode.h audio/madtranscode.h

View File

@@ -24,19 +24,33 @@
#include <QPluginLoader> #include <QPluginLoader>
#include <QMessageBox> #include <QMessageBox>
#include "functimeout.h"
#include "database/database.h" #include "database/database.h"
#include "network/controlconnection.h" #include "network/controlconnection.h"
#include "sourcelist.h" #include "sourcelist.h"
#include "tomahawksettings.h" #include "tomahawksettings.h"
#include "tomahawk/tomahawkapp.h" //#include "tomahawk/tomahawkapp.h"
#include "config.h" #include "config.h"
//remove
#include <QLabel>
SipHandler* SipHandler::s_instance = 0;
SipHandler* SipHandler::instance()
{
return s_instance;
}
SipHandler::SipHandler( QObject* parent ) SipHandler::SipHandler( QObject* parent )
: QObject( parent ) : QObject( parent )
, m_connected( false ) , m_connected( false )
{ {
s_instance = this;
loadPlugins( findPlugins() ); loadPlugins( findPlugins() );
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) ); connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
@@ -55,6 +69,23 @@ SipHandler::plugins() const
return m_plugins; return m_plugins;
} }
const QPixmap SipHandler::avatar( const QString& name ) const
{
qDebug() << Q_FUNC_INFO << "Getting avatar" << name << m_usernameAvatars.keys();
if( m_usernameAvatars.keys().contains( name ) )
{
qDebug() << Q_FUNC_INFO << "Getting avatar and avatar != null ";
Q_ASSERT(!m_usernameAvatars.value( name ).isNull());
return m_usernameAvatars.value( name );
}
else
{
qDebug() << Q_FUNC_INFO << "Getting avatar and avatar == null, GAAAAAH ";
return QPixmap();
}
}
void void
SipHandler::onSettingsChanged() SipHandler::onSettingsChanged()
@@ -147,6 +178,7 @@ SipHandler::loadPlugin( const QString& path )
QObject::connect( sip, SIGNAL( disconnected() ), SIGNAL( disconnected() ) ); QObject::connect( sip, SIGNAL( disconnected() ), SIGNAL( disconnected() ) );
QObject::connect( sip, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) ); QObject::connect( sip, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) );
QObject::connect( sip, SIGNAL( avatarReceived( QString, QPixmap ) ), SLOT( onAvatarReceived( QString, QPixmap ) ) );
m_plugins << sip; m_plugins << sip;
} }
} }
@@ -182,7 +214,8 @@ SipHandler::connectPlugins( bool startup, const QString &pluginName )
if ( !TomahawkSettings::instance()->acceptedLegalWarning() ) if ( !TomahawkSettings::instance()->acceptedLegalWarning() )
{ {
int result = QMessageBox::question( int result = QMessageBox::question(
TomahawkApp::instance()->mainWindow(), tr( "Legal Warning" ), //TomahawkApp::instance()->mainWindow(),
0, tr( "Legal Warning" ),
tr( "By pressing OK below, you agree that your use of Tomahawk will be in accordance with any applicable laws, including copyright and intellectual property laws, in effect in your country of residence, and indemnify the Tomahawk developers and project from liability should you choose to break those laws.\n\nFor more information, please see http://gettomahawk.com/legal" ), tr( "By pressing OK below, you agree that your use of Tomahawk will be in accordance with any applicable laws, including copyright and intellectual property laws, in effect in your country of residence, and indemnify the Tomahawk developers and project from liability should you choose to break those laws.\n\nFor more information, please see http://gettomahawk.com/legal" ),
tr( "I Do Not Agree" ), tr( "I Agree" ) tr( "I Do Not Agree" ), tr( "I Agree" )
); );
@@ -346,3 +379,35 @@ SipHandler::onError( int code, const QString& msg )
QTimer::singleShot( 10000, sip, SLOT( connectPlugin() ) ); QTimer::singleShot( 10000, sip, SLOT( connectPlugin() ) );
} }
} }
void SipHandler::onAvatarReceived( const QString& from, const QPixmap& avatar )
{
qDebug() << Q_FUNC_INFO << "Set avatar on source for " << from;
Q_ASSERT(!avatar.isNull());
m_usernameAvatars.insert( from, avatar );
//
//Tomahawk::source_ptr source = ->source();
ControlConnection *conn = Servent::instance()->lookupControlConnection( from );
if( conn )
{
qDebug() << Q_FUNC_INFO << from << "got control connection";
Tomahawk::source_ptr source = conn->source();
if( source )
{
qDebug() << Q_FUNC_INFO << from << "got source, setting avatar";
source->setAvatar( avatar );
}
else
{
qDebug() << Q_FUNC_INFO << from << "no source found, not setting avatar";
}
}
else
{
qDebug() << Q_FUNC_INFO << from << "no control connection setup yet";
}
}

View File

@@ -23,19 +23,24 @@
#include <QDebug> #include <QDebug>
#include <QObject> #include <QObject>
#include <QHash>
#include <QPixmap>
#include <QString>
class SipHandler : public QObject class SipHandler : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
// static SipHandler* instance() { return s_instance ? s_instance : new SipHandler(); } static SipHandler* instance();
SipHandler( QObject* parent ); SipHandler( QObject* parent );
~SipHandler(); ~SipHandler();
QList< SipPlugin* > plugins() const; QList< SipPlugin* > plugins() const;
const QPixmap avatar( const QString& name ) const;
public slots: public slots:
void addContact( const QString& id ) { qDebug() << Q_FUNC_INFO << id; } void addContact( const QString& id ) { qDebug() << Q_FUNC_INFO << id; }
@@ -57,7 +62,11 @@ private slots:
void onSettingsChanged(); void onSettingsChanged();
void onAvatarReceived( const QString& from, const QPixmap& avatar = QPixmap());
private: private:
static SipHandler *s_instance;
QStringList findPlugins(); QStringList findPlugins();
bool pluginLoaded( const QString& name ) const; bool pluginLoaded( const QString& name ) const;
@@ -66,6 +75,9 @@ private:
QList< SipPlugin* > m_plugins; QList< SipPlugin* > m_plugins;
bool m_connected; bool m_connected;
QHash<QString, QPixmap> m_usernameAvatars;
}; };
#endif #endif