mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
Added database commands for Social action.
Love button in audiocontrols sends message through info system to sync love status with local database. The only social action that is currently setup is lastfm's "love".
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
#include "viewmanager.h"
|
||||
#include "utils/imagebutton.h"
|
||||
#include "utils/tomahawkutils.h"
|
||||
#include "database/database.h"
|
||||
#include "database/databasecommand_socialaction.h"
|
||||
|
||||
#include "album.h"
|
||||
|
||||
@@ -137,7 +139,6 @@ AudioControls::AudioControls( QWidget* parent )
|
||||
connect( ui->volumeLowButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( lowerVolume() ) );
|
||||
connect( ui->volumeHighButton, SIGNAL( clicked() ), AudioEngine::instance(), SLOT( raiseVolume() ) );
|
||||
|
||||
|
||||
connect( ui->playPauseButton, SIGNAL( clicked() ), this, SIGNAL( playPressed() ) );
|
||||
connect( ui->pauseButton, SIGNAL( clicked() ), this, SIGNAL( pausePressed() ) );
|
||||
|
||||
@@ -478,3 +479,21 @@ AudioControls::onTrackClicked()
|
||||
{
|
||||
ViewManager::instance()->showCurrentTrack();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioControls::onLoveButtonClicked()
|
||||
{
|
||||
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
|
||||
trackInfo["title"] = m_currentTrack->track();
|
||||
trackInfo["artist"] = m_currentTrack->artist()->name();
|
||||
trackInfo["album"] = m_currentTrack->album()->name();
|
||||
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
|
||||
s_acInfoIdentifier, Tomahawk::InfoSystem::InfoLove,
|
||||
QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ) );
|
||||
|
||||
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_currentTrack, QString( "Love" ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
|
||||
}
|
||||
|
||||
|
@@ -65,6 +65,7 @@ private slots:
|
||||
void onArtistClicked();
|
||||
void onAlbumClicked();
|
||||
void onTrackClicked();
|
||||
void onLoveButtonClicked();
|
||||
|
||||
void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
|
||||
void infoSystemFinished( QString target );
|
||||
|
@@ -79,6 +79,7 @@ set( libSources
|
||||
database/databasecommand_deletedynamicplaylist.cpp
|
||||
database/databasecommand_addclientauth.cpp
|
||||
database/databasecommand_clientauthvalid.cpp
|
||||
database/databasecommand_socialaction.cpp
|
||||
database/database.cpp
|
||||
|
||||
infosystem/infosystemcache.cpp
|
||||
@@ -245,6 +246,7 @@ set( libHeaders
|
||||
database/databasecommand_loadallstations.h
|
||||
database/databasecommand_addclientauth.h
|
||||
database/databasecommand_clientauthvalid.h
|
||||
database/databasecommand_socialaction.h
|
||||
|
||||
infosystem/infosystem.h
|
||||
infosystem/infosystemworker.h
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "databasecommand_createdynamicplaylist.h"
|
||||
#include "databasecommand_deletedynamicplaylist.h"
|
||||
#include "databasecommand_setdynamicplaylistrevision.h"
|
||||
#include "databasecommand_socialaction.h"
|
||||
|
||||
|
||||
DatabaseCommand::DatabaseCommand( QObject* parent )
|
||||
@@ -142,6 +143,13 @@ DatabaseCommand::factory( const QVariant& op, const source_ptr& source )
|
||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||
return cmd;
|
||||
}
|
||||
else if( name == "socialaction" )
|
||||
{
|
||||
DatabaseCommand_SocialAction * cmd = new DatabaseCommand_SocialAction;
|
||||
cmd->setSource( source );
|
||||
QJson::QObjectHelper::qvariant2qobject( op.toMap(), cmd );
|
||||
return cmd;
|
||||
}
|
||||
|
||||
qDebug() << "ERROR in" << Q_FUNC_INFO << name;
|
||||
// Q_ASSERT( false );
|
||||
|
71
src/libtomahawk/database/databasecommand_socialaction.cpp
Normal file
71
src/libtomahawk/database/databasecommand_socialaction.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christopher Reichert <creichert07@gmail.com>
|
||||
*
|
||||
* 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 "databasecommand_socialaction.h"
|
||||
|
||||
#include <QSqlQuery>
|
||||
|
||||
#include "database/database.h"
|
||||
#include "databaseimpl.h"
|
||||
#include "network/servent.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
void
|
||||
DatabaseCommand_SocialAction::postCommitHook()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if ( source()->isLocal() )
|
||||
{
|
||||
Servent::instance()->triggerDBSync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCommand_SocialAction::exec( DatabaseImpl* dbi )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
Q_ASSERT( !source().isNull() );
|
||||
|
||||
TomahawkSqlQuery query = dbi->newquery();
|
||||
|
||||
query.prepare( "INSERT INTO social_attributes(id, source, k, v, timestamp) "
|
||||
"VALUES (?, ?, ?, ?, ?)" );
|
||||
|
||||
QVariant srcid = source()->isLocal() ? QVariant( QVariant::Int ) : source()->id();
|
||||
|
||||
bool isnew;
|
||||
int artid = dbi->artistId( m_artist, isnew );
|
||||
if( artid < 1 )
|
||||
return;
|
||||
|
||||
int trkid = dbi->trackId( artid, m_track, isnew );
|
||||
if( trkid < 1 )
|
||||
return;
|
||||
|
||||
query.bindValue( 0, trkid );
|
||||
query.bindValue( 1, srcid );
|
||||
query.bindValue( 2, m_action );
|
||||
query.bindValue( 3, m_comment );
|
||||
query.bindValue( 4, m_timestamp );
|
||||
|
||||
query.exec();
|
||||
}
|
||||
|
88
src/libtomahawk/database/databasecommand_socialaction.h
Normal file
88
src/libtomahawk/database/databasecommand_socialaction.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2011, Christopher Reichert <creichert07@gmail.com>
|
||||
*
|
||||
* 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 DATABASECOMMAND_SOCIALACTION_H
|
||||
#define DATABASECOMMAND_SOCIALACTION_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include "database/databasecommand.h"
|
||||
|
||||
#include "sourcelist.h"
|
||||
#include "typedefs.h"
|
||||
#include "artist.h"
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
|
||||
class DLLEXPORT DatabaseCommand_SocialAction : public DatabaseCommand
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( QString action READ action WRITE setAction )
|
||||
Q_PROPERTY( QString comment READ comment WRITE setComment )
|
||||
Q_PROPERTY( int timestamp READ timestamp WRITE setTimestamp )
|
||||
|
||||
public:
|
||||
|
||||
explicit DatabaseCommand_SocialAction( QObject* parent = 0 )
|
||||
: DatabaseCommand( parent )
|
||||
{}
|
||||
|
||||
explicit DatabaseCommand_SocialAction( const Tomahawk::result_ptr& result, QString action, QString comment="", QObject* parent = 0 )
|
||||
: DatabaseCommand( parent ), m_result( result ), m_action( action )
|
||||
{
|
||||
setSource( SourceList::instance()->getLocal() );
|
||||
|
||||
setArtist( result->artist()->name() );
|
||||
setTrack( result->track() );
|
||||
setComment( comment );
|
||||
setTimestamp( QDateTime::currentDateTime().toTime_t() );
|
||||
}
|
||||
|
||||
virtual QString commandname() const { return "socialaction"; }
|
||||
|
||||
virtual void exec( DatabaseImpl* );
|
||||
virtual void postCommitHook();
|
||||
|
||||
QString artist() const { return m_artist; }
|
||||
void setArtist( const QString& s ) { m_artist = s; }
|
||||
|
||||
QString track() const { return m_track; }
|
||||
void setTrack( const QString& s ) { m_track = s; }
|
||||
|
||||
// key
|
||||
QString action() const { return m_action; }
|
||||
void setAction( QString a ) { m_action = a; }
|
||||
|
||||
// value
|
||||
QString comment() const { return m_comment; }
|
||||
void setComment( const QString& com ) { m_comment = com; }
|
||||
|
||||
int timestamp() const { return m_timestamp; }
|
||||
void setTimestamp( const int ts ) { m_timestamp = ts; }
|
||||
|
||||
private:
|
||||
Tomahawk::result_ptr m_result;
|
||||
|
||||
QString m_artist;
|
||||
QString m_track;
|
||||
int m_timestamp;
|
||||
QString m_comment;
|
||||
QString m_action;
|
||||
};
|
||||
|
||||
#endif // DATABASECOMMAND_SOCIALACTION_H
|
@@ -45,8 +45,8 @@ LastFmPlugin::LastFmPlugin()
|
||||
: InfoPlugin()
|
||||
, m_scrobbler( 0 )
|
||||
{
|
||||
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages;
|
||||
m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying;
|
||||
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages << InfoLove;
|
||||
m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying << InfoLove;
|
||||
|
||||
/*
|
||||
Your API Key is 7194b85b6d1f424fe1668173a78c0c4a
|
||||
@@ -145,11 +145,16 @@ LastFmPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoTy
|
||||
scrobble();
|
||||
break;
|
||||
|
||||
case InfoLove:
|
||||
sendLoveSong( input );
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LastFmPlugin::nowPlaying( const QVariant &input )
|
||||
{
|
||||
@@ -195,6 +200,34 @@ LastFmPlugin::scrobble()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LastFmPlugin::sendLoveSong( QVariant input )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
if ( !input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
|
||||
{
|
||||
qDebug() << "LastFmPlugin::nowPlaying cannot convert input!";
|
||||
return;
|
||||
}
|
||||
|
||||
InfoCriteriaHash hash = input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
||||
if ( !hash.contains( "title" ) || !hash.contains( "artist" ) || !hash.contains( "album" ) || !hash.contains( "duration" ) )
|
||||
return;
|
||||
|
||||
lastfm::MutableTrack track;
|
||||
track.stamp();
|
||||
|
||||
track.setTitle( hash["title"] );
|
||||
track.setArtist( hash["artist"] );
|
||||
track.setAlbum( hash["album"] );
|
||||
bool ok;
|
||||
track.setDuration( hash["duration"].toUInt( &ok ) );
|
||||
track.setSource( lastfm::Track::Player );
|
||||
track.love();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LastFmPlugin::fetchCoverArt( const QString &caller, const InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData )
|
||||
{
|
||||
@@ -504,3 +537,4 @@ LastFmPlugin::createScrobbler()
|
||||
m_scrobbler = new lastfm::Audioscrobbler( "thk" );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3,8 +3,7 @@
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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
|
||||
* 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,
|
||||
@@ -68,6 +67,7 @@ private:
|
||||
void scrobble();
|
||||
|
||||
void dataError( const QString &caller, const Tomahawk::InfoSystem::InfoType type, const QVariant &input, const Tomahawk::InfoSystem::InfoCustomData &customData );
|
||||
void sendLoveSong( QVariant input );
|
||||
|
||||
lastfm::MutableTrack m_track;
|
||||
lastfm::Audioscrobbler* m_scrobbler;
|
||||
|
@@ -100,7 +100,9 @@ enum InfoType { // as items are saved in cache, mark them here to not change the
|
||||
InfoNowResumed = 50,
|
||||
InfoNowStopped = 51,
|
||||
|
||||
InfoNoInfo = 52
|
||||
InfoNoInfo = 52,
|
||||
InfoLove = 53,
|
||||
InfoUnLove = 54
|
||||
};
|
||||
|
||||
typedef QMap< InfoType, QVariant > InfoMap;
|
||||
|
Reference in New Issue
Block a user