diff --git a/src/accounts/xmpp/XmppInfoPlugin.cpp b/src/accounts/xmpp/XmppInfoPlugin.cpp index 141ca4869..c1b17f870 100644 --- a/src/accounts/xmpp/XmppInfoPlugin.cpp +++ b/src/accounts/xmpp/XmppInfoPlugin.cpp @@ -118,13 +118,17 @@ Tomahawk::InfoSystem::XmppInfoPlugin::audioStarted( const Tomahawk::InfoSystem:: Tomahawk::InfoSystem::InfoStringHash info = map[ "trackinfo" ].value< Tomahawk::InfoSystem::InfoStringHash >(); - QUrl url; - if ( pushInfoPair.first.contains( "shorturl" ) ) - url = pushInfoPair.first[ "shorturl" ].toUrl(); - else - url = Utils::LinkGenerator::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) ); + ScriptJob* job = Utils::LinkGenerator::instance()->openLink( info.value( "title" ), info.value( "artist" ), info.value( "album" ) ); + connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onQueryLinkReady( QVariantMap ) ) ); + job->setProperty( "infoStringHash", QVariant::fromValue( info ) ); + job->start(); +} - emit publishTune( url, info ); + +void +Tomahawk::InfoSystem::XmppInfoPlugin::onQueryLinkReady( const QVariantMap& data ) +{ + emit publishTune( data[ "url" ].toUrl(), sender()->property("infoStringHash").value< Tomahawk::InfoSystem::InfoStringHash >() ); } diff --git a/src/accounts/xmpp/XmppInfoPlugin.h b/src/accounts/xmpp/XmppInfoPlugin.h index 84c6c5555..72468943b 100644 --- a/src/accounts/xmpp/XmppInfoPlugin.h +++ b/src/accounts/xmpp/XmppInfoPlugin.h @@ -53,6 +53,7 @@ namespace Tomahawk { void audioStarted( const Tomahawk::InfoSystem::PushInfoPair& pushInfoPair ); void audioStopped(); void audioPaused(); + void onQueryLinkReady( const QVariantMap& data ); private: QPointer< XmppSipPlugin > m_sipPlugin; diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index e449a6522..188eba0a3 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -90,6 +90,7 @@ set( libGuiSources resolvers/JSResolverHelper.cpp resolvers/ScriptEngine.cpp resolvers/JSPlugin.cpp + resolvers/ScriptJob.cpp utils/DpiScaler.cpp utils/ImageRegistry.cpp diff --git a/src/libtomahawk/ContextMenu.cpp b/src/libtomahawk/ContextMenu.cpp index e5f82565d..7c1cb471f 100644 --- a/src/libtomahawk/ContextMenu.cpp +++ b/src/libtomahawk/ContextMenu.cpp @@ -421,7 +421,7 @@ ContextMenu::copyLink() { if ( m_queries.count() ) { - Utils::LinkGenerator::instance()->copyToClipboard( m_queries.first() ); + Utils::LinkGenerator::instance()->copyOpenLink( m_queries.first() ); } else if ( m_albums.count() ) { diff --git a/src/libtomahawk/infosystem/InfoSystemWorker.cpp b/src/libtomahawk/infosystem/InfoSystemWorker.cpp index db76e5358..592b09d82 100644 --- a/src/libtomahawk/infosystem/InfoSystemWorker.cpp +++ b/src/libtomahawk/infosystem/InfoSystemWorker.cpp @@ -291,19 +291,7 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) void InfoSystemWorker::pushInfo( Tomahawk::InfoSystem::InfoPushData pushData ) { - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "type is " << pushData.type; - - 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(); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "type is " << pushData.type << "number of matching plugins: " << m_infoPushMap[ pushData.type ].size(); 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 InfoSystemWorker::infoSlot( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) { diff --git a/src/libtomahawk/infosystem/InfoSystemWorker.h b/src/libtomahawk/infosystem/InfoSystemWorker.h index df966e064..0e3851f02 100644 --- a/src/libtomahawk/infosystem/InfoSystemWorker.h +++ b/src/libtomahawk/infosystem/InfoSystemWorker.h @@ -69,9 +69,6 @@ public slots: void addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ); void removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ); void loadInfoPlugins(); - - void getShortUrl( Tomahawk::InfoSystem::InfoPushData data ); - void shortLinkReady( QUrl longUrl, QUrl shortUrl, QVariant callbackObj ); private slots: void checkTimeoutsTimerFired(); diff --git a/src/libtomahawk/resolvers/JSPlugin.cpp b/src/libtomahawk/resolvers/JSPlugin.cpp index eb76d5663..1c03fe939 100644 --- a/src/libtomahawk/resolvers/JSPlugin.cpp +++ b/src/libtomahawk/resolvers/JSPlugin.cpp @@ -26,4 +26,4 @@ void JSPlugin::addToJavaScriptWindowObject( const QString& name, QObject* object ) { m_engine->mainFrame()->addToJavaScriptWindowObject( name, object ); -}; +} diff --git a/src/libtomahawk/resolvers/ScriptJob.cpp b/src/libtomahawk/resolvers/ScriptJob.cpp new file mode 100644 index 000000000..a41edc06a --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptJob.cpp @@ -0,0 +1,55 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2014, Dominik Schmidt + * + * 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 . + */ + +#include "ScriptJob.h" +#include + +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() +{ + +} + diff --git a/src/libtomahawk/resolvers/ScriptJob.h b/src/libtomahawk/resolvers/ScriptJob.h new file mode 100644 index 000000000..908f667bb --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptJob.h @@ -0,0 +1,60 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2012, Jeff Mitchell + * + * 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 . + */ + +#ifndef TOMAHAWK_SCRIPTJOB_H +#define TOMAHAWK_SCRIPTJOB_H + +#include +#include + +#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 diff --git a/src/libtomahawk/utils/LinkGenerator.cpp b/src/libtomahawk/utils/LinkGenerator.cpp index 328942cfb..0b3d4884d 100644 --- a/src/libtomahawk/utils/LinkGenerator.cpp +++ b/src/libtomahawk/utils/LinkGenerator.cpp @@ -27,21 +27,42 @@ #include "Logger.h" #include "ShortLinkHelper.h" -#include "playlist/dynamic/GeneratorInterface.h" -#include "playlist/dynamic/DynamicPlaylist.h" +#include "../playlist/dynamic/GeneratorInterface.h" +#include "../playlist/dynamic/DynamicPlaylist.h" #include "../Track.h" #include "../Artist.h" #include "../Album.h" +#include "../resolvers/ScriptJob.h" #include #include #include +#include using namespace Tomahawk; 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; @@ -73,8 +94,8 @@ LinkGenerator::hostname() const } -QUrl -LinkGenerator::openLinkFromQuery( const query_ptr& query ) const +ScriptJob* +LinkGenerator::openLink( const query_ptr& query ) const { QString title = query->track()->track(); QString artist = query->track()->artist(); @@ -84,34 +105,7 @@ LinkGenerator::openLinkFromQuery( const query_ptr& query ) const } -QUrl -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 +ScriptJob* LinkGenerator::openLink( const QString& title, const QString& artist, const QString& album ) const { 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() ) TomahawkUtils::urlAddQueryItem( link, "album", album ); - return link; + QVariantMap data; + data[ "url" ] = link; + + return new SyncScriptJob( data ); } -QString -LinkGenerator::copyPlaylistToClipboard( const dynplaylist_ptr& playlist ) +ScriptJob* +LinkGenerator::openLink( const Tomahawk::dynplaylist_ptr& playlist ) const { QUrl link( QString( "%1/%2/create/" ).arg( hostname() ).arg( playlist->mode() == OnDemand ? "station" : "autoplaylist" ) ); if ( playlist->generator()->type() != "echonest" ) { tLog() << "Only echonest generators are supported"; - return QString(); + return nullptr; } TomahawkUtils::urlAddQueryItem( link, "type", "echonest" ); @@ -170,18 +167,46 @@ LinkGenerator::copyPlaylistToClipboard( const dynplaylist_ptr& playlist ) } } - QClipboard* cb = QApplication::clipboard(); - QByteArray data = TomahawkUtils::percentEncode( link ); - cb->setText( data ); + QVariantMap data; + data[ "url" ] = link; - 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 -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(); connect( slh, SIGNAL( shortLinkReady( QUrl, QUrl, QVariant ) ), SLOT( copyToClipboardReady( QUrl, QUrl, QVariant ) ) ); @@ -189,6 +214,8 @@ LinkGenerator::copyToClipboard( const query_ptr& query ) slh, SLOT( deleteLater() ), Qt::QueuedConnection ); slh->shortenLink( m_clipboardLongUrl ); + + sender()->deleteLater(); } diff --git a/src/libtomahawk/utils/LinkGenerator.h b/src/libtomahawk/utils/LinkGenerator.h index 94e9028da..060f13430 100644 --- a/src/libtomahawk/utils/LinkGenerator.h +++ b/src/libtomahawk/utils/LinkGenerator.h @@ -21,13 +21,14 @@ #ifndef TOMAHAWK_UTILS_LINKGENERATOR_H #define TOMAHAWK_UTILS_LINKGENERATOR_H -#include "DllMacro.h" -#include "Typedefs.h" +#include "../resolvers/ScriptJob.h" + +#include "../DllMacro.h" +#include "../Typedefs.h" namespace Tomahawk { -namespace Utils { -class ShortLinkHelperPrivate; +namespace Utils { class DLLEXPORT LinkGenerator : public QObject { @@ -36,22 +37,34 @@ public: static LinkGenerator* instance(); 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; - QUrl copyOpenLink( const Tomahawk::album_ptr& album ) const; + // Fire and forget - 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 ); - - -public slots: - /// Creates a link from the requested data and copies it to the clipboard - void copyToClipboard( const Tomahawk::query_ptr& query ); + // all others are not + template void copyOpenLink( const T& item ) const + { + ScriptJob* job = openLink( item ); + connect( job, SIGNAL( done( QVariantMap ) ), SLOT( copyScriptJobResultToClipboard( QVariantMap ) ), Qt::QueuedConnection ); + job->start(); + } 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: explicit LinkGenerator( QObject* parent = 0 ); diff --git a/src/tomahawk/sourcetree/SourceTreeView.cpp b/src/tomahawk/sourcetree/SourceTreeView.cpp index a98c1049c..31f104b51 100644 --- a/src/tomahawk/sourcetree/SourceTreeView.cpp +++ b/src/tomahawk/sourcetree/SourceTreeView.cpp @@ -45,6 +45,7 @@ #include "utils/TomahawkUtilsGui.h" #include "widgets/SourceTreePopupDialog.h" #include "PlaylistEntry.h" +#include "resolvers/ScriptJob.h" #include "../../viewpages/dashboard/Dashboard.h" #include "../../viewpages/whatsnew_0_8/WhatsNew_0_8.h" @@ -503,7 +504,7 @@ SourceTreeView::copyPlaylistLink() { DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex ); dynplaylist_ptr playlist = item->dynPlaylist(); - Utils::LinkGenerator::instance()->copyPlaylistToClipboard( playlist ); + Utils::LinkGenerator::instance()->copyOpenLink( playlist ); } else if ( type == SourcesModel::StaticPlaylist ) { @@ -563,8 +564,14 @@ SourceTreeView::addToLocal() // copy to a link and then generate a new playlist from that // this way we cheaply regenerate the needed controls - QString link = Utils::LinkGenerator::instance()->copyPlaylistToClipboard( playlist ); - GlobalActionManager::instance()->parseTomahawkLink( link ); + ScriptJob* job = Utils::LinkGenerator::instance()->openLink( playlist ); + if( !job ) + { + // No supported generator + return; + } + connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onPlaylistLinkReady( QVariantMap ) ) ); + job->start(); } 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 SourceTreeView::latchOnOrCatchUp() { diff --git a/src/tomahawk/sourcetree/SourceTreeView.h b/src/tomahawk/sourcetree/SourceTreeView.h index 882a80df2..a271cdbb2 100644 --- a/src/tomahawk/sourcetree/SourceTreeView.h +++ b/src/tomahawk/sourcetree/SourceTreeView.h @@ -89,6 +89,7 @@ private slots: void onDeletePlaylistResult( bool result ); void shortLinkReady( const Tomahawk::playlist_ptr& playlist, const QUrl& shortUrl ); + void onPlaylistLinkReady( const QVariantMap& data ); protected: void drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; diff --git a/src/tomahawk/sourcetree/items/TemporaryPageItem.cpp b/src/tomahawk/sourcetree/items/TemporaryPageItem.cpp index 2c43f99ec..437d13c75 100644 --- a/src/tomahawk/sourcetree/items/TemporaryPageItem.cpp +++ b/src/tomahawk/sourcetree/items/TemporaryPageItem.cpp @@ -155,7 +155,7 @@ TemporaryPageItem::linkActionTriggered( QAction* action ) { TrackInfoWidget* tPage = dynamic_cast< TrackInfoWidget* >( m_page ); Q_ASSERT( tPage ); - Utils::LinkGenerator::instance()->copyToClipboard( tPage->query() ); + Utils::LinkGenerator::instance()->copyOpenLink( tPage->query() ); break; } diff --git a/src/tomahawk/widgets/SocialWidget.cpp b/src/tomahawk/widgets/SocialWidget.cpp index b3b75fc12..f0901279d 100644 --- a/src/tomahawk/widgets/SocialWidget.cpp +++ b/src/tomahawk/widgets/SocialWidget.cpp @@ -180,8 +180,18 @@ SocialWidget::setQuery( const Tomahawk::query_ptr& query ) onShortLinkReady( QString(), QString(), QVariant() ); onChanged(); - QUrl longUrl = Tomahawk::Utils::LinkGenerator::instance()->openLinkFromQuery( query ); - m_slh.shortenLink( longUrl ); + Tomahawk::ScriptJob* job = Tomahawk::Utils::LinkGenerator::instance()->openLink( query ); + connect( job, SIGNAL( done( QVariantMap ) ), SLOT( onQueryLinkReady( QVariantMap ) ) ); + job->start(); +} + + +void +SocialWidget::onQueryLinkReady( const QVariantMap& data ) +{ + m_slh.shortenLink( data[ "url" ].toUrl() ); + + sender()->deleteLater(); } diff --git a/src/tomahawk/widgets/SocialWidget.h b/src/tomahawk/widgets/SocialWidget.h index ecd070cde..c87b6bfd9 100644 --- a/src/tomahawk/widgets/SocialWidget.h +++ b/src/tomahawk/widgets/SocialWidget.h @@ -65,6 +65,7 @@ protected: private slots: void accept(); void onChanged(); + void onQueryLinkReady( const QVariantMap& data ); void onShortLinkReady( const QUrl& longUrl, const QUrl& shortUrl, const QVariant& callbackObj ); void onGeometryUpdate();