mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-20 07:52:30 +02:00
First commit towards new accounts system. Shouldn't work, but compiles.
This commit is contained in:
parent
999e0ad4c2
commit
c7f6144bfe
@ -34,6 +34,8 @@ set( libSources
|
||||
dropjob.cpp
|
||||
playlistinterface.cpp
|
||||
|
||||
accounts/accountmanager.cpp
|
||||
|
||||
sip/SipPlugin.cpp
|
||||
sip/SipHandler.cpp
|
||||
sip/SipModel.cpp
|
||||
@ -251,6 +253,8 @@ set( libHeaders
|
||||
album.h
|
||||
playlist.h
|
||||
|
||||
accounts/accountmanager.h
|
||||
|
||||
sip/SipPlugin.h
|
||||
sip/SipHandler.h
|
||||
sip/SipModel.h
|
||||
@ -443,6 +447,8 @@ set( libHeaders
|
||||
set( libHeaders_NoMOC
|
||||
viewpage.h
|
||||
|
||||
accounts/account.h
|
||||
|
||||
infosystem/infoplugins/unix/imageconverter.h
|
||||
|
||||
playlist/dynamic/GeneratorInterface.h
|
||||
|
@ -22,53 +22,100 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QVariantMap>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "dllmacro.h"
|
||||
#include "infosystem/infosystem.h"
|
||||
#include "sip/SipPlugin.h"
|
||||
#include <tomahawksettings.h>
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
class DLLEXPORT Account
|
||||
namespace Accounts
|
||||
{
|
||||
|
||||
typedef QMap< QString, bool > ACLMap;
|
||||
typedef QMap< QString, bool > ACLMap;
|
||||
|
||||
enum AccountType { InfoType, SipType };
|
||||
|
||||
class DLLEXPORT Account : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum AccountTypes { InfoType, SipType };
|
||||
|
||||
explicit Account();
|
||||
explicit Account()
|
||||
: QObject()
|
||||
{
|
||||
m_autoConnect = false;
|
||||
}
|
||||
virtual ~Account();
|
||||
|
||||
QString accountServiceName(); // e.g. "Twitter", "Last.fm"
|
||||
QString accountServiceName() const; // e.g. "Twitter", "Last.fm"
|
||||
void setAccountServiceName( const QString &serviceName );
|
||||
|
||||
QString accountFriendlyName(); // e.g. screen name on the service, JID, etc.
|
||||
QString accountFriendlyName() const; // e.g. screen name on the service, JID, etc.
|
||||
void setAccountFriendlyName( const QString &friendlyName );
|
||||
|
||||
bool autoConnect();
|
||||
void setAutoConnect( bool autoConnect );
|
||||
bool autoConnect() const { return m_autoConnect; }
|
||||
void setAutoConnect( bool autoConnect ) { m_autoConnect = autoConnect; }
|
||||
|
||||
QStringMap credentials();
|
||||
void setCredentials( const QStringMap &credentialMap );
|
||||
QHash< QString, QString > credentials() { return m_credentials; }
|
||||
void setCredentials( const QHash< QString, QString > &credentialMap );
|
||||
|
||||
QIcon icon() const;
|
||||
|
||||
QVariantMap configuration();
|
||||
QVariantMap configuration() const;
|
||||
void setConfiguration( const QVariantMap &configuration );
|
||||
QWidget* configurationWidget();
|
||||
|
||||
ACLMap acl();
|
||||
ACLMap acl() const;
|
||||
void setAcl( const ACLMap &acl );
|
||||
QWidget* aclWidget();
|
||||
|
||||
QSet< AccountTypes > types();
|
||||
void setTypes( const QSet< AccountTypes > types );
|
||||
QSet< AccountType > types() const;
|
||||
void setTypes( const QSet< AccountType > types );
|
||||
|
||||
Tomahawk::InfoSystem::InfoPlugin* infoPlugin();
|
||||
SipPlugin* sipPlugin();
|
||||
|
||||
private:
|
||||
bool m_autoConnect;
|
||||
QHash< QString, QString > m_credentials;
|
||||
};
|
||||
|
||||
class DLLEXPORT AccountFactory : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AccountFactory() {}
|
||||
virtual ~AccountFactory() {}
|
||||
|
||||
// display name for plugin
|
||||
virtual QString prettyName() const = 0;
|
||||
// internal name
|
||||
virtual QString factoryId() const = 0;
|
||||
// if the user can create multiple
|
||||
virtual QIcon icon() const { return QIcon(); }
|
||||
virtual bool isUnique() const { return false; }
|
||||
|
||||
virtual Account* createAccount( const QString& pluginId = QString() ) = 0;
|
||||
|
||||
protected:
|
||||
QString generateId()
|
||||
{
|
||||
QString uniq = QUuid::createUuid().toString().mid( 1, 8 );
|
||||
return factoryId() + "_" + uniq;
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // ACCOUNT_H
|
||||
};
|
||||
|
||||
Q_DECLARE_INTERFACE( Tomahawk::Accounts::AccountFactory, "tomahawk.AccountFactory/1.0" )
|
||||
|
||||
#endif
|
174
src/libtomahawk/accounts/accountmanager.cpp
Normal file
174
src/libtomahawk/accounts/accountmanager.cpp
Normal file
@ -0,0 +1,174 @@
|
||||
/* === 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
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "accountmanager.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <QtCore/QLibrary>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QPluginLoader>
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
namespace Accounts
|
||||
{
|
||||
|
||||
|
||||
AccountManager::AccountManager()
|
||||
: QObject()
|
||||
{
|
||||
loadPluginFactories( findPluginFactories() );
|
||||
}
|
||||
|
||||
|
||||
AccountManager::~AccountManager()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
AccountManager::findPluginFactories()
|
||||
{
|
||||
QStringList paths;
|
||||
QList< QDir > pluginDirs;
|
||||
|
||||
QDir appDir( qApp->applicationDirPath() );
|
||||
#ifdef Q_WS_MAC
|
||||
if ( appDir.dirName() == "MacOS" )
|
||||
{
|
||||
// Development convenience-hack
|
||||
appDir.cdUp();
|
||||
appDir.cdUp();
|
||||
appDir.cdUp();
|
||||
}
|
||||
#endif
|
||||
|
||||
QDir libDir( CMAKE_INSTALL_PREFIX "/lib" );
|
||||
|
||||
QDir lib64Dir( appDir );
|
||||
lib64Dir.cdUp();
|
||||
lib64Dir.cd( "lib64" );
|
||||
|
||||
pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() );
|
||||
foreach ( const QDir& pluginDir, pluginDirs )
|
||||
{
|
||||
qDebug() << "Checking directory for plugins:" << pluginDir;
|
||||
foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_account_*.so" << "*tomahawk_account_*.dylib" << "*tomahawk_account_*.dll", QDir::Files ) )
|
||||
{
|
||||
if ( fileName.startsWith( "libtomahawk_account" ) )
|
||||
{
|
||||
const QString path = pluginDir.absoluteFilePath( fileName );
|
||||
if ( !paths.contains( path ) )
|
||||
paths << path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountManager::loadPluginFactories( const QStringList& paths )
|
||||
{
|
||||
foreach ( QString fileName, paths )
|
||||
{
|
||||
if ( !QLibrary::isLibrary( fileName ) )
|
||||
continue;
|
||||
|
||||
qDebug() << "Trying to load plugin:" << fileName;
|
||||
loadPluginFactory( fileName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
AccountManager::factoryFromId( const QString& pluginId ) const
|
||||
{
|
||||
return pluginId.split( "_" ).first();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountManager::loadPluginFactory( const QString& path )
|
||||
{
|
||||
QPluginLoader loader( path );
|
||||
QObject* plugin = loader.instance();
|
||||
if ( !plugin )
|
||||
{
|
||||
qDebug() << "Error loading plugin:" << loader.errorString();
|
||||
}
|
||||
|
||||
AccountFactory* accountfactory = qobject_cast<AccountFactory*>( plugin );
|
||||
if ( accountfactory )
|
||||
{
|
||||
qDebug() << "Loaded plugin factory:" << loader.fileName() << accountfactory->factoryId() << accountfactory->prettyName();
|
||||
m_accountFactories[ accountfactory->factoryId() ] = accountfactory;
|
||||
} else
|
||||
{
|
||||
qDebug() << "Loaded invalid plugin.." << loader.fileName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AccountManager::loadFromConfig()
|
||||
{
|
||||
QStringList pluginIds = TomahawkSettings::instance()->accountPlugins();
|
||||
foreach( const QString& pluginId, pluginIds )
|
||||
{
|
||||
QString pluginFactory = factoryFromId( pluginId );
|
||||
if( m_accountFactories.contains( pluginFactory ) )
|
||||
{
|
||||
Account* a = loadPlugin( pluginId );
|
||||
addAccountPlugin( a );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Account*
|
||||
AccountManager::loadPlugin( const QString& pluginId )
|
||||
{
|
||||
QString factoryName = factoryFromId( pluginId );
|
||||
|
||||
Q_ASSERT( m_accountFactories.contains( factoryName ) );
|
||||
|
||||
Account* account = m_accountFactories[ factoryName ]->createAccount( pluginId );
|
||||
|
||||
// caller responsible for calling pluginAdded() and hookupPlugin
|
||||
return account;
|
||||
}
|
||||
|
||||
void
|
||||
AccountManager::addAccountPlugin( Account* account )
|
||||
{
|
||||
m_accounts << account;
|
||||
|
||||
//FIXME:
|
||||
//emit pluginAdded( account );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
};
|
65
src/libtomahawk/accounts/accountmanager.h
Normal file
65
src/libtomahawk/accounts/accountmanager.h
Normal file
@ -0,0 +1,65 @@
|
||||
/* === 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
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ACCOUNTMANAGER_H
|
||||
#define ACCOUNTMANAGER_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "dllmacro.h"
|
||||
#include "infosystem/infosystem.h"
|
||||
#include "sip/SipPlugin.h"
|
||||
#include "account.h"
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
namespace Accounts
|
||||
{
|
||||
|
||||
class DLLEXPORT AccountManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AccountManager();
|
||||
virtual ~AccountManager();
|
||||
|
||||
QStringList findPluginFactories();
|
||||
void loadPluginFactories( const QStringList &paths );
|
||||
|
||||
void loadFromConfig();
|
||||
void loadPluginFactory( const QString &path );
|
||||
void addAccountPlugin( Account* account );
|
||||
Account* loadPlugin( const QString &pluginId );
|
||||
QString factoryFromId( const QString& pluginId ) const;
|
||||
|
||||
//QSet< Account > getAccounts( Tomahawk::Accounts::AccountType type );
|
||||
|
||||
private:
|
||||
QSet< Account* > m_accounts;
|
||||
QHash< QString, AccountFactory* > m_accountFactories;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -266,14 +266,14 @@ SipHandler::checkSettings()
|
||||
|
||||
|
||||
void
|
||||
SipHandler::addSipPlugin( SipPlugin* p, bool enabled, bool startup )
|
||||
SipHandler::addSipPlugin( SipPlugin* p, bool enabled )
|
||||
{
|
||||
m_allPlugins << p;
|
||||
|
||||
hookUpPlugin( p );
|
||||
if ( enabled )
|
||||
{
|
||||
p->connectPlugin( startup );
|
||||
p->connectPlugin();
|
||||
m_enabledPlugins << p;
|
||||
}
|
||||
|
||||
@ -308,7 +308,7 @@ SipHandler::hasPluginType( const QString& factoryId ) const
|
||||
|
||||
|
||||
void
|
||||
SipHandler::loadFromConfig( bool startup )
|
||||
SipHandler::loadFromConfig()
|
||||
{
|
||||
QStringList pluginIds = TomahawkSettings::instance()->sipPlugins();
|
||||
QStringList enabled = TomahawkSettings::instance()->enabledSipPlugins();
|
||||
@ -318,7 +318,7 @@ SipHandler::loadFromConfig( bool startup )
|
||||
if( m_pluginFactories.contains( pluginFactory ) )
|
||||
{
|
||||
SipPlugin* p = loadPlugin( pluginId );
|
||||
addSipPlugin( p, enabled.contains( pluginId ), startup );
|
||||
addSipPlugin( p, enabled.contains( pluginId ) );
|
||||
}
|
||||
}
|
||||
m_connected = true;
|
||||
@ -371,7 +371,7 @@ SipHandler::enablePlugin( SipPlugin* p )
|
||||
|
||||
|
||||
void
|
||||
SipHandler::connectPlugin( bool startup, const QString &pluginId )
|
||||
SipHandler::connectPlugin( const QString &pluginId )
|
||||
{
|
||||
#ifndef TOMAHAWK_HEADLESS
|
||||
if ( !TomahawkSettings::instance()->acceptedLegalWarning() )
|
||||
@ -394,7 +394,7 @@ SipHandler::connectPlugin( bool startup, const QString &pluginId )
|
||||
{
|
||||
Q_ASSERT( m_enabledPlugins.contains( sip ) ); // make sure the plugin we're connecting is enabled. should always be the case
|
||||
//each sip should refreshProxy() or take care of that function in some other way during connection
|
||||
sip->connectPlugin( startup );
|
||||
sip->connectPlugin();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,9 @@ public:
|
||||
QList< SipPlugin* > allPlugins() const;
|
||||
QList< SipPlugin* > enabledPlugins() const;
|
||||
QList< SipPlugin* > connectedPlugins() const;
|
||||
void loadFromConfig( bool startup = false );
|
||||
void loadFromConfig();
|
||||
|
||||
void addSipPlugin( SipPlugin* p, bool enable = true, bool connectImmediately = true );
|
||||
void addSipPlugin( SipPlugin* p, bool enable = true );
|
||||
void removeSipPlugin( SipPlugin* p );
|
||||
|
||||
bool hasPluginType( const QString& factoryId ) const;
|
||||
@ -60,7 +60,7 @@ public slots:
|
||||
void enablePlugin( SipPlugin* p );
|
||||
void disablePlugin( SipPlugin* p );
|
||||
|
||||
void connectPlugin( bool startup = false, const QString &pluginId = QString() );
|
||||
void connectPlugin( const QString &pluginId = QString() );
|
||||
void disconnectPlugin( const QString &pluginId = QString() );
|
||||
void connectAll();
|
||||
void disconnectAll();
|
||||
|
@ -82,7 +82,7 @@ public:
|
||||
virtual const QStringList peersOnline() const;
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin( bool startup = false ) = 0;
|
||||
virtual bool connectPlugin() = 0;
|
||||
virtual void disconnectPlugin() = 0;
|
||||
virtual void checkSettings() = 0;
|
||||
|
||||
|
@ -650,6 +650,38 @@ TomahawkSettings::removeSipPlugin( const QString& pluginId )
|
||||
}
|
||||
|
||||
|
||||
QStringList
|
||||
TomahawkSettings::accountPlugins() const
|
||||
{
|
||||
return value( "accounts/allplugins", QStringList() ).toStringList();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSettings::setAccountPlugins( const QStringList& plugins )
|
||||
{
|
||||
setValue( "accounts/allplugins", plugins );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSettings::addAccountPlugin( const QString& pluginId )
|
||||
{
|
||||
QStringList list = accountPlugins();
|
||||
list << pluginId;
|
||||
setAccountPlugins( list );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TomahawkSettings::removeAccountPlugin( const QString& pluginId )
|
||||
{
|
||||
QStringList list = accountPlugins();
|
||||
list.removeAll( pluginId );
|
||||
setAccountPlugins( list );
|
||||
}
|
||||
|
||||
|
||||
TomahawkSettings::ExternalAddressMode
|
||||
TomahawkSettings::externalAddressMode() const
|
||||
{
|
||||
|
@ -97,9 +97,6 @@ public:
|
||||
void setSipPlugins( const QStringList& plugins );
|
||||
QStringList sipPlugins() const;
|
||||
|
||||
void setBookmarkPlaylist( const QString& guid );
|
||||
QString bookmarkPlaylist() const;
|
||||
|
||||
// just the enabled sip plugins.
|
||||
void setEnabledSipPlugins( const QStringList& list );
|
||||
QStringList enabledSipPlugins() const;
|
||||
@ -109,6 +106,15 @@ public:
|
||||
void addSipPlugin( const QString& pluginId, bool enable = true );
|
||||
void removeSipPlugin( const QString& pluginId );
|
||||
|
||||
void setAccountPlugins( const QStringList& plugins );
|
||||
QStringList accountPlugins() const;
|
||||
void addAccountPlugin( const QString& pluginId );
|
||||
void removeAccountPlugin( const QString& pluginId );
|
||||
|
||||
|
||||
void setBookmarkPlaylist( const QString& guid );
|
||||
QString bookmarkPlaylist() const;
|
||||
|
||||
/// Network settings
|
||||
enum ExternalAddressMode { Lan, Upnp };
|
||||
ExternalAddressMode externalAddressMode() const;
|
||||
|
@ -193,9 +193,8 @@ JabberPlugin::icon() const
|
||||
|
||||
|
||||
bool
|
||||
JabberPlugin::connectPlugin( bool startup )
|
||||
JabberPlugin::connectPlugin()
|
||||
{
|
||||
Q_UNUSED( startup );
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if(m_client->isConnected())
|
||||
@ -527,7 +526,7 @@ JabberPlugin::checkSettings()
|
||||
setupClientHelper();
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Updated settings";
|
||||
connectPlugin( false );
|
||||
connectPlugin();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ signals:
|
||||
void jidChanged( const QString& );
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin( bool startup );
|
||||
virtual bool connectPlugin();
|
||||
void disconnectPlugin();
|
||||
void checkSettings();
|
||||
void sendMsg( const QString& to, const QString& msg );
|
||||
|
@ -7,13 +7,13 @@ add_definitions( -DQT_SHARED )
|
||||
add_definitions( -DSIPDLLEXPORT_PRO )
|
||||
|
||||
set( twitterSources
|
||||
twitter.cpp
|
||||
twittersip.cpp
|
||||
twitterconfigwidget.cpp
|
||||
tomahawkoauthtwitter.cpp
|
||||
)
|
||||
|
||||
set( twitterHeaders
|
||||
twitter.h
|
||||
twittersip.h
|
||||
twitterconfigwidget.h
|
||||
tomahawkoauthtwitter.h
|
||||
)
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "twitterconfigwidget.h"
|
||||
#include "twitter.h"
|
||||
#include "twittersip.h"
|
||||
#include "ui_twitterconfigwidget.h"
|
||||
|
||||
#include "tomahawksettings.h"
|
||||
@ -123,7 +123,7 @@ TwitterConfigWidget::authenticateVerifyReply( const QTweetUser &user )
|
||||
ui->twitterUserTweetLineEdit->setVisible( false );
|
||||
ui->twitterTweetGotTomahawkButton->setText( tr( "Tweet!" ) );
|
||||
|
||||
m_plugin->connectPlugin( false );
|
||||
m_plugin->connectPlugin();
|
||||
|
||||
emit twitterAuthed( true );
|
||||
emit sizeHintChanged();
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "twitter.h"
|
||||
#include "twittersip.h"
|
||||
|
||||
#include "twitterconfigwidget.h"
|
||||
|
||||
@ -158,9 +158,8 @@ QWidget* TwitterPlugin::configWidget()
|
||||
}
|
||||
|
||||
bool
|
||||
TwitterPlugin::connectPlugin( bool startup )
|
||||
TwitterPlugin::connectPlugin()
|
||||
{
|
||||
Q_UNUSED( startup );
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
m_cachedPeers = twitterCachedPeers();
|
||||
@ -810,7 +809,7 @@ TwitterPlugin::checkSettings()
|
||||
if ( m_state == Disconnected )
|
||||
return;
|
||||
disconnectPlugin();
|
||||
connectPlugin( false );
|
||||
connectPlugin();
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
virtual QWidget* configWidget();
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin( bool startup );
|
||||
virtual bool connectPlugin();
|
||||
void disconnectPlugin();
|
||||
void checkSettings();
|
||||
void refreshProxy();
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <QtPlugin>
|
||||
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#include "tomahawksettings.h"
|
||||
#include "utils/logger.h"
|
||||
|
||||
@ -39,6 +41,9 @@ ZeroconfPlugin::ZeroconfPlugin ( const QString& pluginId )
|
||||
, m_cachedNodes()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
m_advertisementTimer.setInterval( 60000 );
|
||||
m_advertisementTimer.setSingleShot( false );
|
||||
connect( &m_advertisementTimer, SIGNAL( timeout() ), this, SLOT( advertise() ) );
|
||||
}
|
||||
|
||||
ZeroconfPlugin::~ZeroconfPlugin() {}
|
||||
@ -75,16 +80,14 @@ ZeroconfFactory::icon() const
|
||||
|
||||
|
||||
bool
|
||||
ZeroconfPlugin::connectPlugin( bool startup )
|
||||
ZeroconfPlugin::connectPlugin()
|
||||
{
|
||||
Q_UNUSED( startup );
|
||||
|
||||
delete m_zeroconf;
|
||||
m_zeroconf = new TomahawkZeroconf( Servent::instance()->port(), this );
|
||||
QObject::connect( m_zeroconf, SIGNAL( tomahawkHostFound( QString, int, QString, QString ) ),
|
||||
SLOT( lanHostFound( QString, int, QString, QString ) ) );
|
||||
|
||||
m_zeroconf->advertise();
|
||||
advertise();
|
||||
m_state = Connected;
|
||||
|
||||
foreach( const QStringList& nodeSet, m_cachedNodes )
|
||||
@ -93,12 +96,16 @@ ZeroconfPlugin::connectPlugin( bool startup )
|
||||
Servent::instance()->connectToPeer( nodeSet[0], nodeSet[1].toInt(), "whitelist", nodeSet[2], nodeSet[3] );
|
||||
}
|
||||
m_cachedNodes.clear();
|
||||
|
||||
m_advertisementTimer.start();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ZeroconfPlugin::disconnectPlugin()
|
||||
{
|
||||
m_advertisementTimer.stop();
|
||||
m_state = Disconnected;
|
||||
|
||||
delete m_zeroconf;
|
||||
@ -112,6 +119,13 @@ ZeroconfPlugin::icon() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ZeroconfPlugin::advertise()
|
||||
{
|
||||
m_zeroconf->advertise();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ZeroconfPlugin::lanHostFound( const QString& host, int port, const QString& name, const QString& nodeid )
|
||||
{
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
#include "../sipdllmacro.h"
|
||||
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#define MYNAME "Local Network"
|
||||
|
||||
class SIPDLLEXPORT ZeroconfFactory : public SipPluginFactory
|
||||
@ -62,9 +64,11 @@ public:
|
||||
virtual void checkSettings() {}
|
||||
|
||||
public slots:
|
||||
virtual bool connectPlugin( bool startup );
|
||||
virtual bool connectPlugin();
|
||||
void disconnectPlugin();
|
||||
|
||||
void advertise();
|
||||
|
||||
void sendMsg( const QString& , const QString& ) {}
|
||||
void broadcastMsg( const QString & ) {}
|
||||
void addContact( const QString &, const QString& ) {}
|
||||
@ -76,6 +80,7 @@ private:
|
||||
TomahawkZeroconf* m_zeroconf;
|
||||
ConnectionState m_state;
|
||||
QVector<QStringList> m_cachedNodes;
|
||||
QTimer m_advertisementTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -508,7 +508,7 @@ TomahawkApp::initSIP()
|
||||
|
||||
tDebug( LOGINFO ) << "Connecting SIP classes";
|
||||
//SipHandler::instance()->refreshProxy();
|
||||
SipHandler::instance()->loadFromConfig( true );
|
||||
SipHandler::instance()->loadFromConfig();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user