mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
* Fix GlobalActionManager's shortenUrl.
This commit is contained in:
@@ -55,24 +55,27 @@ GlobalActionManager* GlobalActionManager::s_instance = 0;
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
GlobalActionManager*
|
GlobalActionManager*
|
||||||
GlobalActionManager::instance()
|
GlobalActionManager::instance()
|
||||||
{
|
{
|
||||||
if( !s_instance )
|
if ( !s_instance )
|
||||||
s_instance = new GlobalActionManager;
|
s_instance = new GlobalActionManager;
|
||||||
|
|
||||||
return s_instance;
|
return s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GlobalActionManager::GlobalActionManager( QObject* parent )
|
GlobalActionManager::GlobalActionManager( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
{
|
{
|
||||||
newNam();
|
|
||||||
connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( newNam() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GlobalActionManager::~GlobalActionManager()
|
GlobalActionManager::~GlobalActionManager()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QUrl
|
QUrl
|
||||||
GlobalActionManager::openLinkFromQuery( const query_ptr& query ) const
|
GlobalActionManager::openLinkFromQuery( const query_ptr& query ) const
|
||||||
@@ -94,6 +97,7 @@ GlobalActionManager::openLinkFromQuery( const query_ptr& query ) const
|
|||||||
return openLink( title, artist, album );
|
return openLink( title, artist, album );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QUrl
|
QUrl
|
||||||
GlobalActionManager::openLink( const QString& title, const QString& artist, const QString& album ) const
|
GlobalActionManager::openLink( const QString& title, const QString& artist, const QString& album ) const
|
||||||
{
|
{
|
||||||
@@ -109,25 +113,26 @@ GlobalActionManager::openLink( const QString& title, const QString& artist, cons
|
|||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
GlobalActionManager::shortenLink( const QUrl& url ) const
|
|
||||||
{
|
|
||||||
qDebug() << Q_FUNC_INFO;
|
|
||||||
QNetworkRequest request;
|
|
||||||
request.setUrl( url );
|
|
||||||
|
|
||||||
if( m_nam.isNull() )
|
void
|
||||||
|
GlobalActionManager::shortenLink( const QUrl& url )
|
||||||
|
{
|
||||||
|
if ( QThread::currentThread() != thread() )
|
||||||
{
|
{
|
||||||
emit shortLinkReady( QUrl( "" ), QUrl( "" ) );
|
qDebug() << "Reinvoking in correct thread:" << Q_FUNC_INFO;
|
||||||
|
QMetaObject::invokeMethod( this, "shortenLink", Qt::QueuedConnection, Q_ARG( QUrl, url ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply *reply = m_nam.data()->get( request );
|
QNetworkRequest request;
|
||||||
connect( reply, SIGNAL( finished() ), this, SLOT( shortenLinkRequestFinished() ) );
|
request.setUrl( url );
|
||||||
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ),
|
|
||||||
this, SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) );
|
QNetworkReply *reply = TomahawkUtils::nam()->get( request );
|
||||||
|
connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) );
|
||||||
|
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
||||||
{
|
{
|
||||||
@@ -172,6 +177,7 @@ GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
|||||||
return link.toString();
|
return link.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::savePlaylistToFile( const playlist_ptr& playlist, const QString& filename )
|
GlobalActionManager::savePlaylistToFile( const playlist_ptr& playlist, const QString& filename )
|
||||||
{
|
{
|
||||||
@@ -181,6 +187,7 @@ GlobalActionManager::savePlaylistToFile( const playlist_ptr& playlist, const QSt
|
|||||||
connect( g, SIGNAL( generated( QByteArray ) ), this, SLOT( xspfCreated( QByteArray ) ) );
|
connect( g, SIGNAL( generated( QByteArray ) ), this, SLOT( xspfCreated( QByteArray ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::xspfCreated( const QByteArray& xspf )
|
GlobalActionManager::xspfCreated( const QByteArray& xspf )
|
||||||
{
|
{
|
||||||
@@ -274,6 +281,7 @@ GlobalActionManager::parseTomahawkLink( const QString& urlIn )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::handlePlaylistCommand( const QUrl& url )
|
GlobalActionManager::handlePlaylistCommand( const QUrl& url )
|
||||||
{
|
{
|
||||||
@@ -314,6 +322,7 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::handleCollectionCommand( const QUrl& url )
|
GlobalActionManager::handleCollectionCommand( const QUrl& url )
|
||||||
{
|
{
|
||||||
@@ -330,6 +339,7 @@ GlobalActionManager::handleCollectionCommand( const QUrl& url )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::handleOpenCommand(const QUrl& url)
|
GlobalActionManager::handleOpenCommand(const QUrl& url)
|
||||||
{
|
{
|
||||||
@@ -342,6 +352,7 @@ GlobalActionManager::handleOpenCommand(const QUrl& url)
|
|||||||
return doQueueAdd( parts, url.queryItems() );
|
return doQueueAdd( parts, url.queryItems() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::handleOpenTrack ( const query_ptr& q )
|
GlobalActionManager::handleOpenTrack ( const query_ptr& q )
|
||||||
{
|
{
|
||||||
@@ -374,6 +385,7 @@ GlobalActionManager::handleQueueCommand( const QUrl& url )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::doQueueAdd( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems )
|
GlobalActionManager::doQueueAdd( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems )
|
||||||
{
|
{
|
||||||
@@ -432,6 +444,7 @@ GlobalActionManager::doQueueAdd( const QStringList& parts, const QList< QPair< Q
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::queueSpotify( const QStringList& , const QList< QPair< QString, QString > >& queryItems )
|
GlobalActionManager::queueSpotify( const QStringList& , const QList< QPair< QString, QString > >& queryItems )
|
||||||
{
|
{
|
||||||
@@ -453,6 +466,7 @@ GlobalActionManager::queueSpotify( const QStringList& , const QList< QPair< QStr
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::queueRdio( const QStringList& , const QList< QPair< QString, QString > >& queryItems )
|
GlobalActionManager::queueRdio( const QStringList& , const QList< QPair< QString, QString > >& queryItems )
|
||||||
{
|
{
|
||||||
@@ -474,6 +488,7 @@ GlobalActionManager::queueRdio( const QStringList& , const QList< QPair< QString
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::handleSearchCommand( const QUrl& url )
|
GlobalActionManager::handleSearchCommand( const QUrl& url )
|
||||||
{
|
{
|
||||||
@@ -495,12 +510,14 @@ GlobalActionManager::handleSearchCommand( const QUrl& url )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::handleAutoPlaylistCommand( const QUrl& url )
|
GlobalActionManager::handleAutoPlaylistCommand( const QUrl& url )
|
||||||
{
|
{
|
||||||
return !loadDynamicPlaylist( url, false ).isNull();
|
return !loadDynamicPlaylist( url, false ).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dynplaylist_ptr
|
dynplaylist_ptr
|
||||||
GlobalActionManager::loadDynamicPlaylist( const QUrl& url, bool station )
|
GlobalActionManager::loadDynamicPlaylist( const QUrl& url, bool station )
|
||||||
{
|
{
|
||||||
@@ -651,6 +668,7 @@ GlobalActionManager::handleStationCommand( const QUrl& url )
|
|||||||
return !loadDynamicPlaylist( url, true ).isNull();
|
return !loadDynamicPlaylist( url, true ).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::handlePlayCommand( const QUrl& url )
|
GlobalActionManager::handlePlayCommand( const QUrl& url )
|
||||||
{
|
{
|
||||||
@@ -692,6 +710,7 @@ GlobalActionManager::handlePlayCommand( const QUrl& url )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::playSpotify( const QUrl& url )
|
GlobalActionManager::playSpotify( const QUrl& url )
|
||||||
{
|
{
|
||||||
@@ -705,6 +724,7 @@ GlobalActionManager::playSpotify( const QUrl& url )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::playNow( const query_ptr& q )
|
GlobalActionManager::playNow( const query_ptr& q )
|
||||||
{
|
{
|
||||||
@@ -714,36 +734,6 @@ GlobalActionManager::playNow( const query_ptr& q )
|
|||||||
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( waitingForResolved( bool ) ) );
|
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( waitingForResolved( bool ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
GlobalActionManager::newNam()
|
|
||||||
{
|
|
||||||
QNetworkAccessManager *oldNam = TomahawkUtils::nam();
|
|
||||||
|
|
||||||
// qDebug() << Q_FUNC_INFO << "No nam exists, or it's a different thread, creating a new one";
|
|
||||||
QNetworkAccessManager* newNam;
|
|
||||||
#ifdef LIBLASTFM_FOUND
|
|
||||||
newNam = new lastfm::NetworkAccessManager( this );
|
|
||||||
#else
|
|
||||||
newNam = new QNetworkAccessManager( this );
|
|
||||||
#endif
|
|
||||||
if ( !m_nam.isNull() )
|
|
||||||
delete m_nam.data();
|
|
||||||
|
|
||||||
if ( !oldNam )
|
|
||||||
oldNam = new QNetworkAccessManager();
|
|
||||||
|
|
||||||
TomahawkUtils::NetworkProxyFactory* oldProxyFactory = TomahawkUtils::proxyFactory();
|
|
||||||
if ( !oldProxyFactory )
|
|
||||||
oldProxyFactory = new TomahawkUtils::NetworkProxyFactory();
|
|
||||||
|
|
||||||
newNam->setConfiguration( oldNam->configuration() );
|
|
||||||
newNam->setNetworkAccessible( oldNam->networkAccessible() );
|
|
||||||
TomahawkUtils::NetworkProxyFactory* newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
|
|
||||||
newProxyFactory->setNoProxyHosts( oldProxyFactory->noProxyHosts() );
|
|
||||||
newProxyFactory->setProxy( oldProxyFactory->proxy() );
|
|
||||||
newNam->setProxyFactory( newProxyFactory );
|
|
||||||
m_nam = QWeakPointer< QNetworkAccessManager >( newNam );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::playRdio( const QUrl& url )
|
GlobalActionManager::playRdio( const QUrl& url )
|
||||||
@@ -804,6 +794,7 @@ bool GlobalActionManager::handleBookmarkCommand(const QUrl& url)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::shortenLinkRequestFinished()
|
GlobalActionManager::shortenLinkRequestFinished()
|
||||||
{
|
{
|
||||||
@@ -845,6 +836,7 @@ GlobalActionManager::shortenLinkRequestFinished()
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::shortenLinkRequestError( QNetworkReply::NetworkError error )
|
GlobalActionManager::shortenLinkRequestError( QNetworkReply::NetworkError error )
|
||||||
{
|
{
|
||||||
@@ -864,6 +856,7 @@ GlobalActionManager::shortenLinkRequestError( QNetworkReply::NetworkError error
|
|||||||
emit shortLinkReady( QUrl( "" ), QUrl( "" ) );
|
emit shortLinkReady( QUrl( "" ), QUrl( "" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::bookmarkPlaylistCreated( const playlist_ptr& pl )
|
GlobalActionManager::bookmarkPlaylistCreated( const playlist_ptr& pl )
|
||||||
{
|
{
|
||||||
@@ -871,6 +864,7 @@ GlobalActionManager::bookmarkPlaylistCreated( const playlist_ptr& pl )
|
|||||||
doBookmark( pl, m_waitingToBookmark );
|
doBookmark( pl, m_waitingToBookmark );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::doBookmark( const playlist_ptr& pl, const query_ptr& q )
|
GlobalActionManager::doBookmark( const playlist_ptr& pl, const query_ptr& q )
|
||||||
{
|
{
|
||||||
@@ -894,6 +888,7 @@ GlobalActionManager::doBookmark( const playlist_ptr& pl, const query_ptr& q )
|
|||||||
m_waitingToBookmark.clear();
|
m_waitingToBookmark.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::showPlaylist()
|
GlobalActionManager::showPlaylist()
|
||||||
{
|
{
|
||||||
@@ -905,6 +900,7 @@ GlobalActionManager::showPlaylist()
|
|||||||
m_toShow.clear();
|
m_toShow.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalActionManager::waitingForResolved( bool /* success */ )
|
GlobalActionManager::waitingForResolved( bool /* success */ )
|
||||||
{
|
{
|
||||||
@@ -924,6 +920,7 @@ GlobalActionManager::waitingForResolved( bool /* success */ )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
GlobalActionManager::hostname() const
|
GlobalActionManager::hostname() const
|
||||||
{
|
{
|
||||||
@@ -942,6 +939,7 @@ GlobalActionManager::openSpotifyLink( const QString& link )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::openRdioLink( const QString& link )
|
GlobalActionManager::openRdioLink( const QString& link )
|
||||||
{
|
{
|
||||||
|
@@ -45,7 +45,7 @@ public:
|
|||||||
QUrl openLinkFromQuery( const Tomahawk::query_ptr& query ) const;
|
QUrl openLinkFromQuery( const Tomahawk::query_ptr& query ) const;
|
||||||
QUrl openLink( const QString& title, const QString& artist, const QString& album ) const;
|
QUrl openLink( const QString& title, const QString& artist, const QString& album ) const;
|
||||||
|
|
||||||
void shortenLink( const QUrl& url ) const;
|
void shortenLink( const QUrl& url );
|
||||||
|
|
||||||
/// Takes a spotify link and performs the default open action on it
|
/// Takes a spotify link and performs the default open action on it
|
||||||
bool openSpotifyLink( const QString& link );
|
bool openSpotifyLink( const QString& link );
|
||||||
@@ -79,8 +79,6 @@ private slots:
|
|||||||
|
|
||||||
void playNow( const Tomahawk::query_ptr& );
|
void playNow( const Tomahawk::query_ptr& );
|
||||||
|
|
||||||
/// Network Access Manager
|
|
||||||
void newNam();
|
|
||||||
private:
|
private:
|
||||||
explicit GlobalActionManager( QObject* parent = 0 );
|
explicit GlobalActionManager( QObject* parent = 0 );
|
||||||
void doBookmark( const Tomahawk::playlist_ptr& pl, const Tomahawk::query_ptr& q );
|
void doBookmark( const Tomahawk::playlist_ptr& pl, const Tomahawk::query_ptr& q );
|
||||||
|
@@ -252,6 +252,9 @@ TomahawkApp::init()
|
|||||||
{
|
{
|
||||||
m_scanManager.data()->runScan( true );
|
m_scanManager.data()->runScan( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure to init GAM in the gui thread
|
||||||
|
GlobalActionManager::instance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user