mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 15:16:34 +02:00
Streamline link generation api and make it async
getShortUrl or rather its result "shorturl" was only ever used in XmppInfo and even there was a fallback for creating the shorturl. As I could not trigger getShortUrl in the InfoSystem and as it was barely used, I removed it to reduce complexity.
This commit is contained in:
committed by
Dominik Schmidt
parent
9542aaffb4
commit
33d225233b
@@ -118,13 +118,17 @@ Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted( const Tomahawk::InfoSystem::
|
|||||||
|
|
||||||
Tomahawk::InfoSystem::InfoStringHash info = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >();
|
Tomahawk::InfoSystem::InfoStringHash info = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >();
|
||||||
|
|
||||||
QUrl url;
|
ScriptJob* job = Utils::LinkGenerator::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) );
|
||||||
if ( pushInfoPair.first.contains( "shorturl" ) )
|
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onQueryLinkReady( QVariantMap ) ) );
|
||||||
url = pushInfoPair.first[ "shorturl" ].toUrl();
|
job->setProperty( "infoStringHash", QVariant::fromValue( info ) );
|
||||||
else
|
job->start();
|
||||||
url = Utils::LinkGenerator::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) );
|
}
|
||||||
|
|
||||||
emit publishTune( url, info );
|
|
||||||
|
void
|
||||||
|
Tomahawk::InfoSystem::XmppInfoPlugin::onQueryLinkReady( const QVariantMap& data )
|
||||||
|
{
|
||||||
|
emit publishTune( data[ "url" ].toUrl(), sender()->property("infoStringHash").value< Tomahawk::InfoSystem::InfoStringHash >() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -53,6 +53,7 @@ namespace Tomahawk {
|
|||||||
void audioStarted( const Tomahawk::InfoSystem::PushInfoPair& pushInfoPair );
|
void audioStarted( const Tomahawk::InfoSystem::PushInfoPair& pushInfoPair );
|
||||||
void audioStopped();
|
void audioStopped();
|
||||||
void audioPaused();
|
void audioPaused();
|
||||||
|
void onQueryLinkReady( const QVariantMap& data );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer< XmppSipPlugin > m_sipPlugin;
|
QPointer< XmppSipPlugin > m_sipPlugin;
|
||||||
|
@@ -90,6 +90,7 @@ set( libGuiSources
|
|||||||
resolvers/JSResolverHelper.cpp
|
resolvers/JSResolverHelper.cpp
|
||||||
resolvers/ScriptEngine.cpp
|
resolvers/ScriptEngine.cpp
|
||||||
resolvers/JSPlugin.cpp
|
resolvers/JSPlugin.cpp
|
||||||
|
resolvers/ScriptJob.cpp
|
||||||
|
|
||||||
utils/DpiScaler.cpp
|
utils/DpiScaler.cpp
|
||||||
utils/ImageRegistry.cpp
|
utils/ImageRegistry.cpp
|
||||||
|
@@ -421,7 +421,7 @@ ContextMenu::copyLink()
|
|||||||
{
|
{
|
||||||
if ( m_queries.count() )
|
if ( m_queries.count() )
|
||||||
{
|
{
|
||||||
Utils::LinkGenerator::instance()->copyToClipboard( m_queries.first() );
|
Utils::LinkGenerator::instance()->copyOpenLink( m_queries.first() );
|
||||||
}
|
}
|
||||||
else if ( m_albums.count() )
|
else if ( m_albums.count() )
|
||||||
{
|
{
|
||||||
|
@@ -291,19 +291,7 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
|||||||
void
|
void
|
||||||
InfoSystemWorker::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
|
InfoSystemWorker::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "type is " << pushData.type;
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "type is " << pushData.type << "number of matching plugins: " << m_infoPushMap[ pushData.type ].size();
|
||||||
|
|
||||||
if ( pushData.pushFlags != PushNoFlag )
|
|
||||||
{
|
|
||||||
if ( pushData.pushFlags & PushShortUrlFlag )
|
|
||||||
{
|
|
||||||
pushData.pushFlags = Tomahawk::InfoSystem::PushInfoFlags( pushData.pushFlags & ~PushShortUrlFlag );
|
|
||||||
QMetaObject::invokeMethod( this, "getShortUrl", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoPushData, pushData ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "number of matching plugins: " << m_infoPushMap[ pushData.type ].size();
|
|
||||||
|
|
||||||
Q_FOREACH( InfoPluginPtr ptr, m_infoPushMap[ pushData.type ] )
|
Q_FOREACH( InfoPluginPtr ptr, m_infoPushMap[ pushData.type ] )
|
||||||
{
|
{
|
||||||
@@ -313,72 +301,6 @@ InfoSystemWorker::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
InfoSystemWorker::getShortUrl( Tomahawk::InfoSystem::InfoPushData pushData )
|
|
||||||
{
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "type is " << pushData.type;
|
|
||||||
if ( !pushData.infoPair.second.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod( this, "pushInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoPushData, pushData ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoStringHash hash = pushData.infoPair.second.value< Tomahawk::InfoSystem::InfoStringHash >();
|
|
||||||
|
|
||||||
if ( hash.isEmpty() || !hash.contains( "title" ) || !hash.contains( "artist" ) )
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod( this, "pushInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoPushData, pushData ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString title, artist, album;
|
|
||||||
title = hash[ "title" ];
|
|
||||||
artist = hash[ "artist" ];
|
|
||||||
if( hash.contains( "album" ) )
|
|
||||||
album = hash[ "album" ];
|
|
||||||
|
|
||||||
QUrl longUrl = Utils::LinkGenerator::instance()->openLink( title, artist, album );
|
|
||||||
|
|
||||||
Tomahawk::Utils::ShortLinkHelper* slh = new Tomahawk::Utils::ShortLinkHelper();
|
|
||||||
connect( slh, SIGNAL( shortLinkReady( QUrl, QUrl, QVariant ) ),
|
|
||||||
SLOT( shortLinkReady( QUrl, QUrl, QVariant ) ) );
|
|
||||||
connect( slh, SIGNAL( done() ),
|
|
||||||
slh, SLOT( deleteLater() ),
|
|
||||||
Qt::QueuedConnection );
|
|
||||||
slh->shortenLink( longUrl, QVariant::fromValue< Tomahawk::InfoSystem::InfoPushData >( pushData ) );
|
|
||||||
m_shortLinksWaiting++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
InfoSystemWorker::shortLinkReady( QUrl longUrl, QUrl shortUrl, QVariant callbackObj )
|
|
||||||
{
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "long url = " << longUrl << ", shortUrl = " << shortUrl;
|
|
||||||
m_shortLinksWaiting--;
|
|
||||||
if ( !m_shortLinksWaiting )
|
|
||||||
disconnect( Utils::LinkGenerator::instance(), SIGNAL( shortLinkReady( QUrl, QUrl, QVariant ) ) );
|
|
||||||
|
|
||||||
if ( !callbackObj.isValid() )
|
|
||||||
{
|
|
||||||
tDebug() << Q_FUNC_INFO << "callback object was not valid, cannot continue";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Tomahawk::InfoSystem::InfoPushData pushData = callbackObj.value< Tomahawk::InfoSystem::InfoPushData >();
|
|
||||||
|
|
||||||
if ( !shortUrl.isEmpty() && longUrl != shortUrl )
|
|
||||||
{
|
|
||||||
QVariantMap flagProps = pushData.infoPair.first;
|
|
||||||
flagProps[ "shorturl" ] = shortUrl;
|
|
||||||
pushData.infoPair.first = flagProps;
|
|
||||||
}
|
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "pushInfoPair first is: " << pushData.infoPair.first.keys();
|
|
||||||
|
|
||||||
QMetaObject::invokeMethod( this, "pushInfo", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoPushData, pushData ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
InfoSystemWorker::infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
InfoSystemWorker::infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
|
||||||
{
|
{
|
||||||
|
@@ -70,9 +70,6 @@ public slots:
|
|||||||
void removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin );
|
void removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin );
|
||||||
void loadInfoPlugins();
|
void loadInfoPlugins();
|
||||||
|
|
||||||
void getShortUrl( Tomahawk::InfoSystem::InfoPushData data );
|
|
||||||
void shortLinkReady( QUrl longUrl, QUrl shortUrl, QVariant callbackObj );
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void checkTimeoutsTimerFired();
|
void checkTimeoutsTimerFired();
|
||||||
|
|
||||||
|
@@ -26,4 +26,4 @@ void
|
|||||||
JSPlugin::addToJavaScriptWindowObject( const QString& name, QObject* object )
|
JSPlugin::addToJavaScriptWindowObject( const QString& name, QObject* object )
|
||||||
{
|
{
|
||||||
m_engine->mainFrame()->addToJavaScriptWindowObject( name, object );
|
m_engine->mainFrame()->addToJavaScriptWindowObject( name, object );
|
||||||
};
|
}
|
||||||
|
55
src/libtomahawk/resolvers/ScriptJob.cpp
Normal file
55
src/libtomahawk/resolvers/ScriptJob.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014, Dominik Schmidt <domme@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 "ScriptJob.h"
|
||||||
|
#include <QMetaObject>
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
ScriptJob::ScriptJob( ScriptObject* scriptObject, const QString& method, const QVariantMap& parameters )
|
||||||
|
: QObject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ScriptJob::~ScriptJob()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptJob::start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptJob::reportResults( const QVariantMap& data )
|
||||||
|
{
|
||||||
|
m_data = data;
|
||||||
|
emit done( data );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptJob::reportFailure()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
60
src/libtomahawk/resolvers/ScriptJob.h
Normal file
60
src/libtomahawk/resolvers/ScriptJob.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
|
* Copyright 2010-2012, Jeff Mitchell <jeff@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 TOMAHAWK_SCRIPTJOB_H
|
||||||
|
#define TOMAHAWK_SCRIPTJOB_H
|
||||||
|
|
||||||
|
#include <QVariantMap>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
class ScriptObject;
|
||||||
|
|
||||||
|
class DLLEXPORT ScriptJob : public QObject
|
||||||
|
{
|
||||||
|
friend class ScriptObject;
|
||||||
|
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ScriptJob( ScriptObject* scriptObject, const QString& method, const QVariantMap& parameters = QVariantMap() );
|
||||||
|
virtual ~ScriptJob();
|
||||||
|
|
||||||
|
virtual void start();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void reportResults( const QVariantMap& data );
|
||||||
|
void reportFailure();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void done( const QVariantMap& result );
|
||||||
|
void failed( const QVariantMap& reason );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// TODO: pimple
|
||||||
|
QVariantMap m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_SCRIPTJOB_H
|
@@ -27,21 +27,42 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "ShortLinkHelper.h"
|
#include "ShortLinkHelper.h"
|
||||||
|
|
||||||
#include "playlist/dynamic/GeneratorInterface.h"
|
#include "../playlist/dynamic/GeneratorInterface.h"
|
||||||
#include "playlist/dynamic/DynamicPlaylist.h"
|
#include "../playlist/dynamic/DynamicPlaylist.h"
|
||||||
#include "../Track.h"
|
#include "../Track.h"
|
||||||
#include "../Artist.h"
|
#include "../Artist.h"
|
||||||
#include "../Album.h"
|
#include "../Album.h"
|
||||||
|
#include "../resolvers/ScriptJob.h"
|
||||||
|
|
||||||
#include <echonest/Playlist.h>
|
#include <echonest/Playlist.h>
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QMetaObject>
|
||||||
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
using namespace Tomahawk::Utils;
|
using namespace Tomahawk::Utils;
|
||||||
|
|
||||||
|
|
||||||
|
// HACK: to prepare proper scripting
|
||||||
|
class SyncScriptJob : public ScriptJob
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
SyncScriptJob( const QVariantMap& resultData ) : ScriptJob( nullptr, "nomethod")
|
||||||
|
{
|
||||||
|
m_data = resultData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() override
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod( this, "reportResults", Qt::QueuedConnection, Q_ARG( QVariantMap, m_data ) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#include "LinkGenerator.moc"
|
||||||
|
|
||||||
LinkGenerator* LinkGenerator::s_instance = 0;
|
LinkGenerator* LinkGenerator::s_instance = 0;
|
||||||
|
|
||||||
|
|
||||||
@@ -73,8 +94,8 @@ LinkGenerator::hostname() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QUrl
|
ScriptJob*
|
||||||
LinkGenerator::openLinkFromQuery( const query_ptr& query ) const
|
LinkGenerator::openLink( const query_ptr& query ) const
|
||||||
{
|
{
|
||||||
QString title = query->track()->track();
|
QString title = query->track()->track();
|
||||||
QString artist = query->track()->artist();
|
QString artist = query->track()->artist();
|
||||||
@@ -84,34 +105,7 @@ LinkGenerator::openLinkFromQuery( const query_ptr& query ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QUrl
|
ScriptJob*
|
||||||
LinkGenerator::copyOpenLink( const artist_ptr& artist ) const
|
|
||||||
{
|
|
||||||
const QUrl link( QString( "%1/artist/%2" ).arg( hostname() ).arg( artist->name() ) );
|
|
||||||
|
|
||||||
QClipboard* cb = QApplication::clipboard();
|
|
||||||
QByteArray data = TomahawkUtils::percentEncode( link );
|
|
||||||
cb->setText( data );
|
|
||||||
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QUrl
|
|
||||||
LinkGenerator::copyOpenLink( const album_ptr& album ) const
|
|
||||||
{
|
|
||||||
const QUrl link = QUrl::fromUserInput( QString( "%1/album/%2/%3" ).arg( hostname() ).arg( album->artist().isNull() ? QString() : album->artist()->name() ).arg( album->name() ) );
|
|
||||||
|
|
||||||
QClipboard* cb = QApplication::clipboard();
|
|
||||||
QByteArray data = TomahawkUtils::percentEncode( link );
|
|
||||||
|
|
||||||
cb->setText( data );
|
|
||||||
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QUrl
|
|
||||||
LinkGenerator::openLink( const QString& title, const QString& artist, const QString& album ) const
|
LinkGenerator::openLink( const QString& title, const QString& artist, const QString& album ) const
|
||||||
{
|
{
|
||||||
QUrl link( QString( "%1/open/track/" ).arg( hostname() ) );
|
QUrl link( QString( "%1/open/track/" ).arg( hostname() ) );
|
||||||
@@ -123,19 +117,22 @@ LinkGenerator::openLink( const QString& title, const QString& artist, const QStr
|
|||||||
if ( !album.isEmpty() )
|
if ( !album.isEmpty() )
|
||||||
TomahawkUtils::urlAddQueryItem( link, "album", album );
|
TomahawkUtils::urlAddQueryItem( link, "album", album );
|
||||||
|
|
||||||
return link;
|
QVariantMap data;
|
||||||
|
data[ "url" ] = link;
|
||||||
|
|
||||||
|
return new SyncScriptJob( data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
ScriptJob*
|
||||||
LinkGenerator::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
LinkGenerator::openLink( const Tomahawk::dynplaylist_ptr& playlist ) const
|
||||||
{
|
{
|
||||||
QUrl link( QString( "%1/%2/create/" ).arg( hostname() ).arg( playlist->mode() == OnDemand ? "station" : "autoplaylist" ) );
|
QUrl link( QString( "%1/%2/create/" ).arg( hostname() ).arg( playlist->mode() == OnDemand ? "station" : "autoplaylist" ) );
|
||||||
|
|
||||||
if ( playlist->generator()->type() != "echonest" )
|
if ( playlist->generator()->type() != "echonest" )
|
||||||
{
|
{
|
||||||
tLog() << "Only echonest generators are supported";
|
tLog() << "Only echonest generators are supported";
|
||||||
return QString();
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
TomahawkUtils::urlAddQueryItem( link, "type", "echonest" );
|
TomahawkUtils::urlAddQueryItem( link, "type", "echonest" );
|
||||||
@@ -170,18 +167,46 @@ LinkGenerator::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QClipboard* cb = QApplication::clipboard();
|
QVariantMap data;
|
||||||
QByteArray data = TomahawkUtils::percentEncode( link );
|
data[ "url" ] = link;
|
||||||
cb->setText( data );
|
|
||||||
|
|
||||||
return link.toString();
|
return new SyncScriptJob( data );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ScriptJob*
|
||||||
|
LinkGenerator::openLink( const Tomahawk::artist_ptr& artist ) const
|
||||||
|
{
|
||||||
|
QVariantMap data;
|
||||||
|
data[ "url" ] = QString( "%1/artist/%2" ).arg( hostname() ).arg( artist->name() );
|
||||||
|
return new SyncScriptJob( data );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ScriptJob*
|
||||||
|
LinkGenerator::openLink( const Tomahawk::album_ptr& album ) const
|
||||||
|
{
|
||||||
|
QVariantMap data;
|
||||||
|
data[ "url" ] = QUrl::fromUserInput( QString( "%1/album/%2/%3" ).arg( hostname() ).arg( album->artist().isNull() ? QString() : album->artist()->name() ).arg( album->name() ) );;
|
||||||
|
return new SyncScriptJob( data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LinkGenerator::copyToClipboard( const query_ptr& query )
|
LinkGenerator::copyScriptJobResultToClipboard( const QVariantMap& data )
|
||||||
{
|
{
|
||||||
m_clipboardLongUrl = openLinkFromQuery( query );
|
m_clipboardLongUrl = data[ "url" ].toUrl();
|
||||||
|
copyToClipboardReady( m_clipboardLongUrl, m_clipboardLongUrl );
|
||||||
|
|
||||||
|
sender()->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LinkGenerator::copyScriptJobResultToClipboardShortened( const QVariantMap& data )
|
||||||
|
{
|
||||||
|
m_clipboardLongUrl = data[ "url" ].toUrl();
|
||||||
|
|
||||||
Tomahawk::Utils::ShortLinkHelper* slh = new Tomahawk::Utils::ShortLinkHelper();
|
Tomahawk::Utils::ShortLinkHelper* slh = new Tomahawk::Utils::ShortLinkHelper();
|
||||||
connect( slh, SIGNAL( shortLinkReady( QUrl, QUrl, QVariant ) ),
|
connect( slh, SIGNAL( shortLinkReady( QUrl, QUrl, QVariant ) ),
|
||||||
SLOT( copyToClipboardReady( QUrl, QUrl, QVariant ) ) );
|
SLOT( copyToClipboardReady( QUrl, QUrl, QVariant ) ) );
|
||||||
@@ -189,6 +214,8 @@ LinkGenerator::copyToClipboard( const query_ptr& query )
|
|||||||
slh, SLOT( deleteLater() ),
|
slh, SLOT( deleteLater() ),
|
||||||
Qt::QueuedConnection );
|
Qt::QueuedConnection );
|
||||||
slh->shortenLink( m_clipboardLongUrl );
|
slh->shortenLink( m_clipboardLongUrl );
|
||||||
|
|
||||||
|
sender()->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -21,13 +21,14 @@
|
|||||||
#ifndef TOMAHAWK_UTILS_LINKGENERATOR_H
|
#ifndef TOMAHAWK_UTILS_LINKGENERATOR_H
|
||||||
#define TOMAHAWK_UTILS_LINKGENERATOR_H
|
#define TOMAHAWK_UTILS_LINKGENERATOR_H
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "../resolvers/ScriptJob.h"
|
||||||
#include "Typedefs.h"
|
|
||||||
|
#include "../DllMacro.h"
|
||||||
|
#include "../Typedefs.h"
|
||||||
|
|
||||||
namespace Tomahawk {
|
namespace Tomahawk {
|
||||||
namespace Utils {
|
|
||||||
|
|
||||||
class ShortLinkHelperPrivate;
|
namespace Utils {
|
||||||
|
|
||||||
class DLLEXPORT LinkGenerator : public QObject
|
class DLLEXPORT LinkGenerator : public QObject
|
||||||
{
|
{
|
||||||
@@ -36,22 +37,34 @@ public:
|
|||||||
static LinkGenerator* instance();
|
static LinkGenerator* instance();
|
||||||
virtual ~LinkGenerator();
|
virtual ~LinkGenerator();
|
||||||
|
|
||||||
QUrl openLinkFromQuery( const Tomahawk::query_ptr& query ) const;
|
ScriptJob* openLink( const QString& title, const QString& artist, const QString& album ) const;
|
||||||
|
ScriptJob* openLink( const Tomahawk::query_ptr& query ) const;
|
||||||
|
ScriptJob* openLink( const Tomahawk::artist_ptr& artist ) const;
|
||||||
|
ScriptJob* openLink( const Tomahawk::album_ptr& album ) const;
|
||||||
|
ScriptJob* openLink( const Tomahawk::dynplaylist_ptr& playlist ) const;
|
||||||
|
|
||||||
QUrl copyOpenLink( const Tomahawk::artist_ptr& artist ) const;
|
// Fire and forget
|
||||||
QUrl copyOpenLink( const Tomahawk::album_ptr& album ) const;
|
|
||||||
|
|
||||||
QUrl openLink( const QString& title, const QString& artist, const QString& album ) const;
|
// the query link is shortened automatically
|
||||||
|
void copyOpenLink( const query_ptr& query ) const
|
||||||
|
{
|
||||||
|
ScriptJob* job = openLink( query );
|
||||||
|
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( copyScriptJobResultToClipboardShortened( QVariantMap ) ), Qt::QueuedConnection );
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
|
||||||
QString copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
|
// all others are not
|
||||||
|
template <typename T> void copyOpenLink( const T& item ) const
|
||||||
|
{
|
||||||
public slots:
|
ScriptJob* job = openLink( item );
|
||||||
/// Creates a link from the requested data and copies it to the clipboard
|
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( copyScriptJobResultToClipboard( QVariantMap ) ), Qt::QueuedConnection );
|
||||||
void copyToClipboard( const Tomahawk::query_ptr& query );
|
job->start();
|
||||||
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void copyToClipboardReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj );
|
void copyToClipboardReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj = QVariant() );
|
||||||
|
void copyScriptJobResultToClipboard( const QVariantMap& data );
|
||||||
|
void copyScriptJobResultToClipboardShortened( const QVariantMap& data );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit LinkGenerator( QObject* parent = 0 );
|
explicit LinkGenerator( QObject* parent = 0 );
|
||||||
|
@@ -45,6 +45,7 @@
|
|||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "widgets/SourceTreePopupDialog.h"
|
#include "widgets/SourceTreePopupDialog.h"
|
||||||
#include "PlaylistEntry.h"
|
#include "PlaylistEntry.h"
|
||||||
|
#include "resolvers/ScriptJob.h"
|
||||||
|
|
||||||
#include "../../viewpages/dashboard/Dashboard.h"
|
#include "../../viewpages/dashboard/Dashboard.h"
|
||||||
#include "../../viewpages/whatsnew_0_8/WhatsNew_0_8.h"
|
#include "../../viewpages/whatsnew_0_8/WhatsNew_0_8.h"
|
||||||
@@ -503,7 +504,7 @@ SourceTreeView::copyPlaylistLink()
|
|||||||
{
|
{
|
||||||
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
||||||
dynplaylist_ptr playlist = item->dynPlaylist();
|
dynplaylist_ptr playlist = item->dynPlaylist();
|
||||||
Utils::LinkGenerator::instance()->copyPlaylistToClipboard( playlist );
|
Utils::LinkGenerator::instance()->copyOpenLink( playlist );
|
||||||
}
|
}
|
||||||
else if ( type == SourcesModel::StaticPlaylist )
|
else if ( type == SourcesModel::StaticPlaylist )
|
||||||
{
|
{
|
||||||
@@ -563,8 +564,14 @@ SourceTreeView::addToLocal()
|
|||||||
|
|
||||||
// copy to a link and then generate a new playlist from that
|
// copy to a link and then generate a new playlist from that
|
||||||
// this way we cheaply regenerate the needed controls
|
// this way we cheaply regenerate the needed controls
|
||||||
QString link = Utils::LinkGenerator::instance()->copyPlaylistToClipboard( playlist );
|
ScriptJob* job = Utils::LinkGenerator::instance()->openLink( playlist );
|
||||||
GlobalActionManager::instance()->parseTomahawkLink( link );
|
if( !job )
|
||||||
|
{
|
||||||
|
// No supported generator
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onPlaylistLinkReady( QVariantMap ) ) );
|
||||||
|
job->start();
|
||||||
}
|
}
|
||||||
else if ( type == SourcesModel::StaticPlaylist )
|
else if ( type == SourcesModel::StaticPlaylist )
|
||||||
{
|
{
|
||||||
@@ -581,6 +588,15 @@ SourceTreeView::addToLocal()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SourceTreeView::onPlaylistLinkReady(const QVariantMap& data)
|
||||||
|
{
|
||||||
|
GlobalActionManager::instance()->parseTomahawkLink( data[ "url" ].toString() );
|
||||||
|
|
||||||
|
sender()->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceTreeView::latchOnOrCatchUp()
|
SourceTreeView::latchOnOrCatchUp()
|
||||||
{
|
{
|
||||||
|
@@ -89,6 +89,7 @@ private slots:
|
|||||||
void onDeletePlaylistResult( bool result );
|
void onDeletePlaylistResult( bool result );
|
||||||
|
|
||||||
void shortLinkReady( const Tomahawk::playlist_ptr& playlist, const QUrl& shortUrl );
|
void shortLinkReady( const Tomahawk::playlist_ptr& playlist, const QUrl& shortUrl );
|
||||||
|
void onPlaylistLinkReady( const QVariantMap& data );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
void drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
@@ -155,7 +155,7 @@ TemporaryPageItem::linkActionTriggered( QAction* action )
|
|||||||
{
|
{
|
||||||
TrackInfoWidget* tPage = dynamic_cast< TrackInfoWidget* >( m_page );
|
TrackInfoWidget* tPage = dynamic_cast< TrackInfoWidget* >( m_page );
|
||||||
Q_ASSERT( tPage );
|
Q_ASSERT( tPage );
|
||||||
Utils::LinkGenerator::instance()->copyToClipboard( tPage->query() );
|
Utils::LinkGenerator::instance()->copyOpenLink( tPage->query() );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -180,8 +180,18 @@ SocialWidget::setQuery( const Tomahawk::query_ptr& query )
|
|||||||
onShortLinkReady( QString(), QString(), QVariant() );
|
onShortLinkReady( QString(), QString(), QVariant() );
|
||||||
onChanged();
|
onChanged();
|
||||||
|
|
||||||
QUrl longUrl = Tomahawk::Utils::LinkGenerator::instance()->openLinkFromQuery( query );
|
Tomahawk::ScriptJob* job = Tomahawk::Utils::LinkGenerator::instance()->openLink( query );
|
||||||
m_slh.shortenLink( longUrl );
|
connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onQueryLinkReady( QVariantMap ) ) );
|
||||||
|
job->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SocialWidget::onQueryLinkReady( const QVariantMap& data )
|
||||||
|
{
|
||||||
|
m_slh.shortenLink( data[ "url" ].toUrl() );
|
||||||
|
|
||||||
|
sender()->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -65,6 +65,7 @@ protected:
|
|||||||
private slots:
|
private slots:
|
||||||
void accept();
|
void accept();
|
||||||
void onChanged();
|
void onChanged();
|
||||||
|
void onQueryLinkReady( const QVariantMap& data );
|
||||||
void onShortLinkReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj );
|
void onShortLinkReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj );
|
||||||
|
|
||||||
void onGeometryUpdate();
|
void onGeometryUpdate();
|
||||||
|
Reference in New Issue
Block a user