diff --git a/CMakeModules/FindCLucene.cmake b/CMakeModules/FindCLucene.cmake index c4ea7850c..19dba8277 100644 --- a/CMakeModules/FindCLucene.cmake +++ b/CMakeModules/FindCLucene.cmake @@ -75,7 +75,7 @@ FIND_PATH(CLUCENE_LIBRARY_DIR PATHS ${TRIAL_LIBRARY_PATHS} ${TRIAL_INCLUDE_PATHS} NO_DEFAULT_PATH) IF (CLUCENE_LIBRARY_DIR) MESSAGE(STATUS "Found CLucene library dir: ${CLUCENE_LIBRARY_DIR}") - #INCLUDE(${CLUCENE_LIBRARY_DIR}/CLuceneConfig.cmake/CLuceneConfig.cmake) + INCLUDE(${CLUCENE_LIBRARY_DIR}/CLuceneConfig.cmake/CLuceneConfig.cmake) IF (CLUCENE_VERSION STRLESS "${CLUCENE_MIN_VERSION}") MESSAGE(ERROR " CLucene version ${CLUCENE_VERSION} is less than the required minimum ${CLUCENE_MIN_VERSION}") SET(CLUCENE_GOOD_VERSION FALSE) diff --git a/src/libtomahawk/database/databaseresolver.h b/src/libtomahawk/database/databaseresolver.h index ff929efad..fa553a118 100644 --- a/src/libtomahawk/database/databaseresolver.h +++ b/src/libtomahawk/database/databaseresolver.h @@ -18,7 +18,7 @@ public: virtual QString name() const; virtual unsigned int weight() const { return m_weight; } virtual unsigned int preference() const { return 100; } - virtual unsigned int timeout() const { return 1000; } + virtual unsigned int timeout() const { return 2500; } virtual void resolve( const Tomahawk::query_ptr& query ); diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index b94989511..0fa150ba6 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -38,6 +38,9 @@ signals: void peerOnline( const QString& ); void peerOffline( const QString& ); void msgReceived( const QString& from, const QString& msg ); + + void addMenu( QMenu* menu ); + void removeMenu( QMenu* menu ); }; Q_DECLARE_INTERFACE( SipPlugin, "tomahawk.Sip/1.0" ) diff --git a/src/scriptresolver.cpp b/src/scriptresolver.cpp index 2c6583abb..1dd0b68b1 100644 --- a/src/scriptresolver.cpp +++ b/src/scriptresolver.cpp @@ -6,6 +6,7 @@ #include "album.h" #include "pipeline.h" #include "sourcelist.h" +#include "functimeout.h" ScriptResolver::ScriptResolver( const QString& exe ) @@ -104,10 +105,19 @@ ScriptResolver::handleMsg( const QByteArray& msg ) if( msgtype == "results" ) { - QList< Tomahawk::result_ptr > results; const QString qid = m.value( "qid" ).toString(); + if ( !m_queryState.contains( qid ) ) + { + //FIXME: We should always accept results, even if they arrive too late. Needs some work in Pipeline. + qDebug() << "Ignoring results for" << qid << "- arrived after timeout."; + return; + } + m_queryState.remove( qid ); + + QList< Tomahawk::result_ptr > results; const QVariantList reslist = m.value( "results" ).toList(); Tomahawk::collection_ptr coll = SourceList::instance()->getLocal()->collection(); + foreach( const QVariant& rv, reslist ) { QVariantMap m = rv.toMap(); @@ -127,6 +137,7 @@ ScriptResolver::handleMsg( const QByteArray& msg ) rp->setCollection( coll ); results << rp; } + Tomahawk::Pipeline::instance()->reportResults( qid, results ); } } @@ -172,6 +183,9 @@ ScriptResolver::resolve( const Tomahawk::query_ptr& query ) const QByteArray msg = m_serializer.serialize( QVariant( m ) ); qDebug() << "ASKING SCRIPT RESOLVER TO RESOLVE:" << msg; sendMsg( msg ); + + m_queryState.insert( query->id(), 1 ); + new Tomahawk::FuncTimeout( m_timeout, boost::bind( &ScriptResolver::onTimeout, this, query ) ); } @@ -201,3 +215,16 @@ ScriptResolver::stop() m_proc.kill(); } + +void +ScriptResolver::onTimeout( const Tomahawk::query_ptr& query ) +{ + // check if this query has already been processed + if ( !m_queryState.contains( query->id() ) ) + return; + + // if not, it's time to emit an empty result list + m_queryState.remove( query->id() ); + QList< Tomahawk::result_ptr > results; + Tomahawk::Pipeline::instance()->reportResults( query->id(), results ); +} diff --git a/src/scriptresolver.h b/src/scriptresolver.h index 6a43199d6..c349936ff 100644 --- a/src/scriptresolver.h +++ b/src/scriptresolver.h @@ -40,6 +40,8 @@ private slots: void readStdout(); void cmdExited( int code, QProcess::ExitStatus status ); + void onTimeout( const Tomahawk::query_ptr& query ); + private: void handleMsg( const QByteArray& msg ); void sendMsg( const QByteArray& msg ); @@ -54,6 +56,8 @@ private: bool m_ready, m_stopped; + QHash< QString /* QID */, unsigned int /* state */ > m_queryState; + QJson::Parser m_parser; QJson::Serializer m_serializer; }; diff --git a/src/sip/SipHandler.cpp b/src/sip/SipHandler.cpp index 061720a5e..b4f5297a8 100644 --- a/src/sip/SipHandler.cpp +++ b/src/sip/SipHandler.cpp @@ -286,6 +286,6 @@ SipHandler::onError( int code, const QString& msg ) else { SipPlugin* sip = qobject_cast(sender()); - QTimer::singleShot( 10000, sip, SLOT( connect() ) ); + QTimer::singleShot( 10000, sip, SLOT( connectPlugin() ) ); } } diff --git a/src/sip/jabber/jabber.cpp b/src/sip/jabber/jabber.cpp index 40c948b02..89c5cfcbe 100644 --- a/src/sip/jabber/jabber.cpp +++ b/src/sip/jabber/jabber.cpp @@ -9,15 +9,9 @@ JabberPlugin::JabberPlugin() : p( 0 ), - m_menu ( 0 ) + m_menu ( 0 ), + m_addFriendAction( 0 ) { - if( !accountName().isEmpty() ) - m_menu = new QMenu(QString("Jabber (").append(accountName()).append(")")); - - m_addFriendAction = m_menu->addAction("Add Friend..."); - - connect(m_addFriendAction, SIGNAL(triggered()), - this, SLOT(showAddFriendDialog())); } void @@ -86,8 +80,8 @@ JabberPlugin::connectPlugin( bool startup ) QObject::connect( p, SIGNAL( peerOffline( QString ) ), SIGNAL( peerOffline( QString ) ) ); QObject::connect( p, SIGNAL( msgReceived( QString, QString ) ), SIGNAL( msgReceived( QString, QString ) ) ); - QObject::connect( p, SIGNAL( connected() ), SIGNAL( connected() ) ); - QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( disconnected() ) ); + QObject::connect( p, SIGNAL( connected() ), SLOT( onConnected() ) ); + QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( onDisconnected() ) ); QObject::connect( p, SIGNAL( authError( int, QString ) ), SLOT( onAuthError( int, QString ) ) ); p->resolveHostSRV(); @@ -95,6 +89,38 @@ JabberPlugin::connectPlugin( bool startup ) return true; } +void +JabberPlugin::onConnected() +{ + if( !m_menu ) { + m_menu = new QMenu( QString( "Jabber (").append( accountName() ).append( ")" ) ); + + m_addFriendAction = m_menu->addAction( "Add Friend..." ); + + connect( m_addFriendAction, SIGNAL( triggered() ), + this, SLOT( showAddFriendDialog() ) ) ; + + emit addMenu( m_menu ); + } + + emit connected(); +} + +void +JabberPlugin::onDisconnected() +{ + if( m_menu && m_addFriendAction ) { + emit removeMenu( m_menu ); + + delete m_menu; + m_menu = 0; + m_addFriendAction = 0; + } + + emit disconnected(); +} + + void JabberPlugin::onAuthError( int code, const QString& message ) diff --git a/src/sip/jabber/jabber.h b/src/sip/jabber/jabber.h index 1ea95e52a..025cb03c1 100644 --- a/src/sip/jabber/jabber.h +++ b/src/sip/jabber/jabber.h @@ -32,6 +32,8 @@ public slots: void disconnectPlugin() { + onDisconnected(); + if ( p ) p->disconnect(); @@ -60,7 +62,9 @@ public slots: private slots: void onAuthError( int, const QString& ); void showAddFriendDialog(); - + void onConnected(); + void onDisconnected(); + private: Jabber_p* p; QMenu* m_menu; diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index 6f02e7af2..147f59d0d 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -10,14 +10,9 @@ JabberPlugin::JabberPlugin() : p( 0 ) + , m_menu( 0 ) + , m_addFriendAction( 0 ) { - m_menu = new QMenu(QString("JREEN (").append(accountName()).append(")")); - m_addFriendAction = m_menu->addAction("Add Friend..."); - QAction *connectAction = m_menu->addAction("Connect"); - - connect(m_addFriendAction, SIGNAL(triggered()), - this, SLOT(showAddFriendDialog())); - connect(connectAction, SIGNAL(triggered()), SLOT(connectPlugin())); } JabberPlugin::~JabberPlugin() @@ -92,8 +87,8 @@ JabberPlugin::connectPlugin( bool startup ) QObject::connect( p, SIGNAL( peerOffline( QString ) ), SIGNAL( peerOffline( QString ) ) ); QObject::connect( p, SIGNAL( msgReceived( QString, QString ) ), SIGNAL( msgReceived( QString, QString ) ) ); - QObject::connect( p, SIGNAL( connected() ), SIGNAL( connected() ) ); - QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( disconnected() ) ); + QObject::connect( p, SIGNAL( connected() ), SIGNAL( onConnected() ) ); + QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( onDisconnected() ) ); return true; } @@ -101,6 +96,8 @@ JabberPlugin::connectPlugin( bool startup ) void JabberPlugin::disconnectPlugin() { + onDisconnected(); + if ( p ) p->disconnect(); @@ -108,6 +105,38 @@ JabberPlugin::disconnectPlugin() p = 0; } +void +JabberPlugin::onConnected() +{ + if( !m_menu ) { + m_menu = new QMenu( QString( "JREEN (" ).append( accountName() ).append(")" ) ); + m_addFriendAction = m_menu->addAction( "Add Friend..." ); + QAction *connectAction = m_menu->addAction( "Connect" ); + + connect( m_addFriendAction, SIGNAL(triggered() ), + this, SLOT( showAddFriendDialog() ) ); + connect( connectAction, SIGNAL( triggered() ), SLOT( connectPlugin() ) ); + + emit addMenu( m_menu ); + } + + emit connected(); +} + +void +JabberPlugin::onDisconnected() +{ + if( m_menu && m_addFriendAction ) { + emit removeMenu( m_menu ); + + delete m_menu; + m_menu = 0; + m_addFriendAction = 0; // deleted by menu + } + + emit disconnected(); +} + void JabberPlugin::sendMsg(const QString& to, const QString& msg) { diff --git a/src/sip/jreen/jabber.h b/src/sip/jreen/jabber.h index 32a38b588..430c69058 100644 --- a/src/sip/jreen/jabber.h +++ b/src/sip/jreen/jabber.h @@ -35,6 +35,8 @@ public slots: private slots: void showAddFriendDialog(); + void onConnected(); + void onDisconnected(); private: Jabber_p* p; diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index 1265b01e7..4f04f84a6 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -157,10 +157,8 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) // propagate sip menu foreach( SipPlugin *plugin, APP->sipHandler()->plugins() ) { - if ( plugin->menu() ) - { - ui->menuNetwork->addMenu( plugin->menu() ); - } + connect( plugin, SIGNAL( addMenu( QMenu* ) ), this, SLOT( pluginMenuAdded( QMenu* ) ) ); + connect( plugin, SIGNAL( removeMenu( QMenu* ) ), this, SLOT( pluginMenuRemoved( QMenu* ) ) ); } loadSettings(); @@ -337,6 +335,25 @@ TomahawkWindow::addPeerManually() Servent::instance()->connectToPeer( addr, port, key ); } +void +TomahawkWindow::pluginMenuAdded( QMenu* menu ) +{ + ui->menuNetwork->addMenu( menu ); +} + +void +TomahawkWindow::pluginMenuRemoved( QMenu* menu ) +{ + foreach( QAction* action, ui->menuNetwork->actions() ) + { + if( action->menu() == menu ) + { + ui->menuNetwork->removeAction( action ); + return; + } + } +} + void TomahawkWindow::loadSpiff() diff --git a/src/tomahawkwindow.h b/src/tomahawkwindow.h index 9e1d2df87..4d729186c 100644 --- a/src/tomahawkwindow.h +++ b/src/tomahawkwindow.h @@ -45,6 +45,8 @@ public slots: void loadSpiff(); void showSettingsDialog(); void updateCollectionManually(); + void pluginMenuAdded(QMenu*); + void pluginMenuRemoved(QMenu*); private slots: void onSipConnected();