void GlobalActionManager::getShortLink( const playlist_ptr& pl ) { QVariantMap m; m[ "title" ] = pl->title(); m[ "creator" ] = pl->author().isNull() ? "" : pl->author()->friendlyName(); QVariantList tracks; foreach( const plentry_ptr& pl, pl->entries() ) { if ( pl->query().isNull() ) continue; QVariantMap track; track[ "title" ] = pl->query()->track(); track[ "creator" ] = pl->query()->artist(); track[ "album" ] = pl->query()->album(); tracks << track; } m[ "track" ] = tracks; QVariantMap jspf; jspf["playlist"] = m; QJson::Serializer s; QByteArray msg = s.serialize( jspf ); // No built-in Qt facilities for doing a FORM POST. So we build the payload ourselves... const QByteArray boundary = "----------------------------2434992cccab"; QByteArray data(QByteArray("--" + boundary + "\r\n")); data += "Content-Disposition: form-data; name=\"data\"; filename=\"playlist.jspf\"\r\n"; data += "Content-Type: application/octet-stream\r\n\r\n"; data += msg; data += "\r\n\r\n"; data += "--" + boundary + "--\r\n\r\n"; const QUrl url( QString( "%1/p/").arg( hostname() ) ); QNetworkRequest req( url ); req.setHeader( QNetworkRequest::ContentTypeHeader, QString( "multipart/form-data; boundary=%1" ).arg( QString::fromLatin1( boundary ) ) ); QNetworkReply *reply = TomahawkUtils::nam()->post( req, data ); connect( reply, SIGNAL( finished() ), SLOT( postShortenFinished() ) ); connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) ); }
void SourceTreeView::setupMenus() { m_playlistMenu.clear(); m_roPlaylistMenu.clear(); m_latchMenu.clear(); m_privacyMenu.clear(); bool readonly = true; SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt(); if ( type == SourcesModel::StaticPlaylist || type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station ) { const PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); const playlist_ptr playlist = item->playlist(); if ( !playlist.isNull() ) { readonly = !playlist->author()->isLocal(); } } QAction* latchOnAction = ActionCollection::instance()->getAction( "latchOn" ); m_latchMenu.addAction( latchOnAction ); m_privacyMenu.addAction( ActionCollection::instance()->getAction( "togglePrivacy" ) ); if ( type == SourcesModel::Collection ) { SourceItem* item = itemFromIndex< SourceItem >( m_contextMenuIndex ); source_ptr source = item->source(); if ( !source.isNull() ) { if ( m_latchManager->isLatched( source ) ) { QAction *latchOffAction = ActionCollection::instance()->getAction( "latchOff" ); m_latchMenu.addAction( latchOffAction ); connect( latchOffAction, SIGNAL( triggered() ), SLOT( latchOff() ) ); m_latchMenu.addSeparator(); QAction *latchRealtimeAction = ActionCollection::instance()->getAction( "realtimeFollowingAlong" ); latchRealtimeAction->setChecked( source->playlistInterface()->latchMode() == Tomahawk::PlaylistModes::RealTime ); m_latchMenu.addAction( latchRealtimeAction ); connect( latchRealtimeAction, SIGNAL( toggled( bool ) ), SLOT( latchModeToggled( bool ) ) ); } } } QAction *loadPlaylistAction = ActionCollection::instance()->getAction( "loadPlaylist" ); m_playlistMenu.addAction( loadPlaylistAction ); QAction *renamePlaylistAction = ActionCollection::instance()->getAction( "renamePlaylist" ); m_playlistMenu.addAction( renamePlaylistAction ); m_playlistMenu.addSeparator(); QAction *copyPlaylistAction = m_playlistMenu.addAction( tr( "&Copy Link" ) ); QAction *deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete %1" ).arg( SourcesModel::rowTypeToString( type ) ) ); QString addToText; if ( type == SourcesModel::StaticPlaylist ) addToText = tr( "Add to my Playlists" ); if ( type == SourcesModel::AutomaticPlaylist ) addToText = tr( "Add to my Automatic Playlists" ); else if ( type == SourcesModel::Station ) addToText = tr( "Add to my Stations" ); QAction *addToLocalAction = m_roPlaylistMenu.addAction( addToText ); m_roPlaylistMenu.addAction( copyPlaylistAction ); deletePlaylistAction->setEnabled( !readonly ); renamePlaylistAction->setEnabled( !readonly ); addToLocalAction->setEnabled( readonly ); // Handle any custom actions registered for playlists if ( type == SourcesModel::StaticPlaylist && !readonly && !ActionCollection::instance()->getAction( ActionCollection::LocalPlaylists ).isEmpty() ) { m_playlistMenu.addSeparator(); const PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); const playlist_ptr playlist = item->playlist(); foreach ( QAction* action, ActionCollection::instance()->getAction( ActionCollection::LocalPlaylists ) ) { if ( QObject* notifier = ActionCollection::instance()->actionNotifier( action ) ) { QMetaObject::invokeMethod( notifier, "aboutToShow", Qt::DirectConnection, Q_ARG( QAction*, action ), Q_ARG( Tomahawk::playlist_ptr, playlist ) ); } action->setProperty( "payload", QVariant::fromValue< playlist_ptr >( playlist ) ); m_playlistMenu.addAction( action ); }