From 15595b741e1700c30a6caa32bb961097b31fd054 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sat, 21 Apr 2012 14:42:52 -0400 Subject: [PATCH] some work --- src/libtomahawk/globalactionmanager.cpp | 36 ++++++++++++++++++++++++- src/libtomahawk/globalactionmanager.h | 1 + src/sourcetree/sourcetreeview.cpp | 25 +++++++++-------- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/libtomahawk/globalactionmanager.cpp b/src/libtomahawk/globalactionmanager.cpp index ffeb4dbc9..a9a117bab 100644 --- a/src/libtomahawk/globalactionmanager.cpp +++ b/src/libtomahawk/globalactionmanager.cpp @@ -144,6 +144,40 @@ GlobalActionManager::shortenLink( const QUrl& url, const QVariant& callbackObj ) } +void +GlobalActionManager::getShortLink( const playlist_ptr& pl ) +{ + QVariantMap m; + m[ "title" ] = playlist->title(); + QVariantList tracks; + foreach( const plentry_ptr& pl, playlist->entries() ) + { + if ( pl->query().isNull() ) + continue; + + QVariantMap track; + track[ "title" ] = pl->query()->track(); + track[ "artist" ] = pl->query()->artist(); + track[ "album" ] = pl->query()->album(); + + tracks << track; + } + m[ "tracks" ] = tracks; + + QJson::Parser p; + QByteArray msg = p.parse( m ); + qDebug() << "POSTING DATA:" << msg; + + const QUrl url( QString( "%1/playlist").arg( hostname() ) ); + QNetworkRequest req( url ); + req.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) ); + QNetworkReply *reply = TomahawkUtils::nam()->get( request ); + if ( callbackObj.isValid() ) + reply->setProperty( "callbackobj", callbackObj ); + connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) ); + connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) ); +} + QString GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist ) { @@ -1157,7 +1191,7 @@ GlobalActionManager::waitingForResolved( bool /* success */ ) QString GlobalActionManager::hostname() const { - return QString( "http://toma.hk" ); + return QString( "http://stage.toma.hk" ); } diff --git a/src/libtomahawk/globalactionmanager.h b/src/libtomahawk/globalactionmanager.h index 6a3f1b304..8b1bc5348 100644 --- a/src/libtomahawk/globalactionmanager.h +++ b/src/libtomahawk/globalactionmanager.h @@ -57,6 +57,7 @@ public: public slots: void shortenLink( const QUrl& url, const QVariant &callbackObj = QVariant() ); + void getShortLink( const playlist_ptr& playlist ); bool parseTomahawkLink( const QString& link ); void waitingForResolved( bool ); diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index a2c96e5d8..0be882670 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -226,8 +226,8 @@ SourceTreeView::setupMenus() } - if ( type == SourcesModel::StaticPlaylist ) - copyPlaylistAction->setText( tr( "&Export Playlist" ) ); + // if ( type == SourcesModel::StaticPlaylist ) + // copyPlaylistAction->setText( tr( "&Export Playlist" ) ); connect( loadPlaylistAction, SIGNAL( triggered() ), SLOT( loadPlaylist() ) ); connect( renamePlaylistAction, SIGNAL( triggered() ), SLOT( renamePlaylist() ) ); @@ -357,18 +357,21 @@ SourceTreeView::copyPlaylistLink() } else if ( type == SourcesModel::StaticPlaylist ) { + PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); playlist_ptr playlist = item->playlist(); - QString suggestedFilename = TomahawkSettings::instance()->playlistDefaultPath() + "/" + playlist->title(); - QString filename = QFileDialog::getSaveFileName( TomahawkUtils::tomahawkWindow(), tr( "Save XSPF" ), - suggestedFilename, tr( "Playlists (*.xspf)" ) ); - if ( !filename.isEmpty() ) - { - QFileInfo playlistAbsoluteFilePath = filename; - TomahawkSettings::instance()->setPlaylistDefaultPath( playlistAbsoluteFilePath.absolutePath() ); - GlobalActionManager::instance()->savePlaylistToFile( playlist, filename ); - } + GlobalActionManager::instance()->getShortLink( playlist ); + +// QString suggestedFilename = TomahawkSettings::instance()->playlistDefaultPath() + "/" + playlist->title(); +// QString filename = QFileDialog::getSaveFileName( TomahawkUtils::tomahawkWindow(), tr( "Save XSPF" ), +// suggestedFilename, tr( "Playlists (*.xspf)" ) ); +// if ( !filename.isEmpty() ) +// { +// QFileInfo playlistAbsoluteFilePath = filename; +// TomahawkSettings::instance()->setPlaylistDefaultPath( playlistAbsoluteFilePath.absolutePath() ); +// GlobalActionManager::instance()->savePlaylistToFile( playlist, filename ); +// } } }