mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 18:30:20 +01:00
Move SipHandler from application to library
This commit is contained in:
parent
d87398c47a
commit
def3e3d868
@ -32,8 +32,6 @@ ENDIF()
|
||||
#ENDFOREACH( moddir )
|
||||
|
||||
SET( tomahawkSources ${tomahawkSources}
|
||||
sip/SipHandler.cpp
|
||||
|
||||
web/api_v1.cpp
|
||||
|
||||
resolvers/scriptresolver.cpp
|
||||
@ -71,7 +69,6 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
|
||||
SET( tomahawkHeaders ${tomahawkHeaders}
|
||||
"${TOMAHAWK_INC_DIR}/tomahawk/tomahawkapp.h"
|
||||
|
||||
sip/SipHandler.h
|
||||
|
||||
web/api_v1.h
|
||||
|
||||
|
@ -29,6 +29,7 @@ set( libSources
|
||||
viewpage.cpp
|
||||
|
||||
sip/SipPlugin.cpp
|
||||
sip/SipHandler.cpp
|
||||
|
||||
audio/madtranscode.cpp
|
||||
audio/dummytranscode.cpp
|
||||
@ -187,6 +188,7 @@ set( libHeaders
|
||||
playlist.h
|
||||
|
||||
sip/SipPlugin.h
|
||||
sip/SipHandler.h
|
||||
|
||||
audio/transcodeinterface.h
|
||||
audio/madtranscode.h
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
@ -24,19 +24,33 @@
|
||||
#include <QPluginLoader>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "functimeout.h"
|
||||
|
||||
#include "database/database.h"
|
||||
#include "network/controlconnection.h"
|
||||
#include "sourcelist.h"
|
||||
#include "tomahawksettings.h"
|
||||
#include "tomahawk/tomahawkapp.h"
|
||||
//#include "tomahawk/tomahawkapp.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
|
||||
//remove
|
||||
#include <QLabel>
|
||||
|
||||
SipHandler* SipHandler::s_instance = 0;
|
||||
|
||||
SipHandler* SipHandler::instance()
|
||||
{
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
SipHandler::SipHandler( QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_connected( false )
|
||||
{
|
||||
s_instance = this;
|
||||
|
||||
loadPlugins( findPlugins() );
|
||||
|
||||
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) );
|
||||
@ -55,6 +69,23 @@ SipHandler::plugins() const
|
||||
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
|
||||
SipHandler::onSettingsChanged()
|
||||
@ -147,6 +178,7 @@ SipHandler::loadPlugin( const QString& path )
|
||||
QObject::connect( sip, SIGNAL( disconnected() ), SIGNAL( disconnected() ) );
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -182,7 +214,8 @@ SipHandler::connectPlugins( bool startup, const QString &pluginName )
|
||||
if ( !TomahawkSettings::instance()->acceptedLegalWarning() )
|
||||
{
|
||||
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( "I Do Not Agree" ), tr( "I Agree" )
|
||||
);
|
||||
@ -346,3 +379,35 @@ SipHandler::onError( int code, const QString& msg )
|
||||
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";
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
@ -23,19 +23,24 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QHash>
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
|
||||
class SipHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// static SipHandler* instance() { return s_instance ? s_instance : new SipHandler(); }
|
||||
static SipHandler* instance();
|
||||
|
||||
SipHandler( QObject* parent );
|
||||
~SipHandler();
|
||||
|
||||
QList< SipPlugin* > plugins() const;
|
||||
|
||||
const QPixmap avatar( const QString& name ) const;
|
||||
|
||||
public slots:
|
||||
void addContact( const QString& id ) { qDebug() << Q_FUNC_INFO << id; }
|
||||
|
||||
@ -57,7 +62,11 @@ private slots:
|
||||
|
||||
void onSettingsChanged();
|
||||
|
||||
void onAvatarReceived( const QString& from, const QPixmap& avatar = QPixmap());
|
||||
|
||||
private:
|
||||
static SipHandler *s_instance;
|
||||
|
||||
QStringList findPlugins();
|
||||
bool pluginLoaded( const QString& name ) const;
|
||||
|
||||
@ -66,6 +75,9 @@ private:
|
||||
|
||||
QList< SipPlugin* > m_plugins;
|
||||
bool m_connected;
|
||||
|
||||
|
||||
QHash<QString, QPixmap> m_usernameAvatars;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user