1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-24 14:42:53 +02:00

Database command for loading social actions.

Used for allowing a result to be aware of whether or not
it has various social attributes. e.g. loved.
This commit is contained in:
Christopher Reichert
2011-06-22 00:49:52 -05:00
parent 5429698661
commit 0685754481
8 changed files with 252 additions and 7 deletions

View File

@@ -80,6 +80,7 @@ AudioControls::AudioControls( QWidget* parent )
ui->volumeLowButton->setPixmap( RESPATH "images/volume-icon-muted.png" );
ui->volumeHighButton->setPixmap( RESPATH "images/volume-icon-full.png" );
ui->loveButton->setPixmap( RESPATH "images/not-loved.png" );
ui->loveButton->setCheckable( true );
ui->ownerLabel->setForegroundRole( QPalette::Dark );
ui->metaDataArea->setStyleSheet( "QWidget#metaDataArea {\nborder-width: 4px;\nborder-image: url(" RESPATH "images/now-playing-panel.png) 4 4 4 4 stretch stretch; }" );
@@ -151,7 +152,7 @@ AudioControls::AudioControls( QWidget* parent )
connect( ui->artistTrackLabel, SIGNAL( clickedArtist() ), SLOT( onArtistClicked() ) );
connect( ui->artistTrackLabel, SIGNAL( clickedTrack() ), SLOT( onTrackClicked() ) );
connect( ui->albumLabel, SIGNAL( clickedAlbum() ), SLOT( onAlbumClicked() ) );
connect( ui->loveButton, SIGNAL( clicked() ), SLOT( onLoveButtonClicked() ) );
connect( ui->loveButton, SIGNAL( clicked( bool ) ), SLOT( onLoveButtonClicked( bool ) ) );
// <From AudioEngine>
connect( AudioEngine::instance(), SIGNAL( loading( Tomahawk::result_ptr ) ), SLOT( onPlaybackLoading( Tomahawk::result_ptr ) ) );
@@ -282,7 +283,6 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
ui->albumLabel->setResult( result );
ui->ownerLabel->setText( result->friendlySource() );
ui->coverImage->setPixmap( m_defaultCover );
ui->loveButton->setVisible( true );
ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( result->duration() ) );
@@ -298,6 +298,19 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
ui->pauseButton->setVisible( true );
ui->playPauseButton->setVisible( false );
ui->playPauseButton->setEnabled( false );
result->loadSocialActions();
ui->loveButton->setVisible( true );
if ( result->loved() )
{
ui->loveButton->setPixmap( RESPATH "images/loved.png" );
ui->loveButton->setChecked( true );
}
else
{
ui->loveButton->setPixmap( RESPATH "images/not-loved.png" );
ui->loveButton->setChecked( false );
}
}
@@ -346,6 +359,7 @@ AudioControls::onPlaybackStopped()
ui->pauseButton->setEnabled( false );
ui->playPauseButton->setEnabled( true );
ui->playPauseButton->setVisible( true );
ui->loveButton->setVisible( false );
/* m_pauseAction->setEnabled( false );
m_playAction->setEnabled( true ); */
@@ -489,7 +503,7 @@ AudioControls::onTrackClicked()
void
AudioControls::onLoveButtonClicked()
AudioControls::onLoveButtonClicked( bool checked )
{
Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;
trackInfo["title"] = m_currentTrack->track();
@@ -500,7 +514,17 @@ AudioControls::onLoveButtonClicked()
s_acInfoIdentifier, Tomahawk::InfoSystem::InfoLove,
QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ) );
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_currentTrack, QString( "Love" ) );
if ( checked )
{
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_currentTrack, QString( "Love" ), QString( "true") );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
ui->loveButton->setPixmap( RESPATH "images/loved.png" );
}
else
{
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( m_currentTrack, QString( "Love" ), QString( "false" ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
ui->loveButton->setPixmap( RESPATH "images/not-loved.png" );
}
}

View File

@@ -65,7 +65,7 @@ private slots:
void onArtistClicked();
void onAlbumClicked();
void onTrackClicked();
void onLoveButtonClicked();
void onLoveButtonClicked( bool );
void infoSystemInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, QVariant output, Tomahawk::InfoSystem::InfoCustomData customData );
void infoSystemFinished( QString target );

View File

@@ -82,6 +82,7 @@ set( libSources
database/databasecommand_addclientauth.cpp
database/databasecommand_clientauthvalid.cpp
database/databasecommand_socialaction.cpp
database/databasecommand_loadsocialactions.cpp
database/database.cpp
infosystem/infosystemcache.cpp
@@ -250,6 +251,7 @@ set( libHeaders
database/databasecommand_addclientauth.h
database/databasecommand_clientauthvalid.h
database/databasecommand_socialaction.h
database/databasecommand_loadsocialactions.h
infosystem/infosystem.h
infosystem/infosystemworker.h

View File

@@ -31,6 +31,7 @@
#include "databasecommand_deletedynamicplaylist.h"
#include "databasecommand_setdynamicplaylistrevision.h"
#include "databasecommand_socialaction.h"
#include "databasecommand_loadsocialactions.h"
DatabaseCommand::DatabaseCommand( QObject* parent )

View File

@@ -0,0 +1,74 @@
/* === 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_loadsocialactions.h"
#include <QSqlQuery>
#include "database/database.h"
#include "databaseimpl.h"
#include "network/servent.h"
#include "result.h"
using namespace Tomahawk;
void
DatabaseCommand_LoadSocialActions::exec( DatabaseImpl* dbi )
{
qDebug() << Q_FUNC_INFO;
Q_ASSERT( !source().isNull() );
TomahawkSqlQuery query = dbi->newquery();
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;
QString whereToken;
whereToken = QString( "WHERE id IS %1" ).arg( trkid );
QString sql = QString(
"SELECT k, v, timestamp, source "
"FROM social_attributes %1 "
"ORDER BY timestamp ASC" ).arg( whereToken );
query.prepare( sql );
query.exec();
QList< Tomahawk::SocialAction > allSocialActions;
while ( query.next() ) {
Tomahawk::SocialAction action;
action.action = query.value( 0 ); // action
action.value = query.value( 1 ); // comment
action.timestamp = query.value( 2 ); // timestamp
action.source = query.value( 3 ); // source
allSocialActions.append( action );
}
m_result->setAllSocialActions( allSocialActions );
}

View File

@@ -0,0 +1,73 @@
/* === 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_LOADSOCIALACTIONS_H
#define DATABASECOMMAND_LOADSOCIALACTIONS_H
#include <QDateTime>
#include <QList>
#include "database/databasecommand.h"
#include "sourcelist.h"
#include "typedefs.h"
#include "artist.h"
#include "result.h"
#include "dllmacro.h"
class DLLEXPORT DatabaseCommand_LoadSocialActions : public DatabaseCommand
{
Q_OBJECT
public:
explicit DatabaseCommand_LoadSocialActions( QObject* parent = 0 )
: DatabaseCommand( parent )
{}
explicit DatabaseCommand_LoadSocialActions( Tomahawk::Result* result, QObject* parent = 0 )
: DatabaseCommand( parent ), m_result( result )
{
setSource( SourceList::instance()->getLocal() );
setArtist( result->artist()->name() );
setTrack( result->track() );
}
virtual QString commandname() const { return "loadsocialactions"; }
virtual void exec( DatabaseImpl* );
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; }
signals:
void done( QList< Tomahawk::SocialAction >& allSocialActions );
private:
Tomahawk::Result* m_result;
QString m_artist;
QString m_track;
};
#endif // DATABASECOMMAND_LOADSOCIALACTIONS_H

View File

@@ -20,10 +20,12 @@
#include "album.h"
#include "collection.h"
#include "database/database.h"
#include "database/databasecommand_resolve.h"
#include "database/databasecommand_alltracks.h"
#include "database/databasecommand_addfiles.h"
#include "database/databasecommand_loadfile.h"
#include "database/databasecommand_loadsocialactions.h"
using namespace Tomahawk;
@@ -166,6 +168,53 @@ Result::onOffline()
}
void
Result::loadSocialActions()
{
DatabaseCommand_LoadSocialActions* cmd = new DatabaseCommand_LoadSocialActions( this );
connect( cmd, SIGNAL( finished() ), SLOT( onSocialActionsLoaded() ));
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
}
void Result::onSocialActionsLoaded()
{
parseSocialActions();
}
void
Result::setAllSocialActions(QList< SocialAction > socialActions)
{
m_allSocialActions = socialActions;
}
QList< SocialAction >
Result::allSocialActions()
{
return m_allSocialActions;
}
void
Result::parseSocialActions()
{
QListIterator< Tomahawk::SocialAction > it( m_allSocialActions );
unsigned int highestTimestamp = 0;
while ( it.hasNext() )
{
Tomahawk::SocialAction socialAction;
socialAction = it.next();
if ( socialAction.timestamp.toUInt() > highestTimestamp )
{
m_currentSocialActions[ socialAction.action.toString() ] = socialAction.value.toBool();
}
}
}
void
Result::setArtist( const Tomahawk::artist_ptr& artist )
{

View File

@@ -36,6 +36,16 @@ class DatabaseCommand_LoadFile;
namespace Tomahawk
{
struct SocialAction
{
QVariant action;
QVariant value;
QVariant timestamp;
QVariant source;
};
class DLLEXPORT Result : public QObject
{
Q_OBJECT
@@ -71,6 +81,8 @@ public:
unsigned int albumpos() const { return m_albumpos; }
unsigned int modificationTime() const { return m_modtime; }
int year() const { return m_year; }
bool loved() { return m_currentSocialActions[ "Love" ].toBool(); }
QList< Tomahawk::SocialAction > allSocialActions();
void setScore( float score ) { m_score = score; }
void setId( unsigned int id ) { m_id = id; }
@@ -88,12 +100,18 @@ public:
void setAlbumPos( unsigned int albumpos ) { m_albumpos = albumpos; }
void setModificationTime( unsigned int modtime ) { m_modtime = modtime; }
void setYear( unsigned int year ) { m_year = year; }
void setLoved( bool loved ) { m_currentSocialActions[ "Loved" ] = loved; }
void setAllSocialActions( QList< Tomahawk::SocialAction > socialActions );
void loadSocialActions();
QVariantMap attributes() const { return m_attributes; }
void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); }
unsigned int dbid() const { return m_id; }
public slots:
void onSocialActionsLoaded();
signals:
// emitted when the collection this result comes from is going offline/online:
void statusChanged();
@@ -104,6 +122,7 @@ private slots:
private:
void updateAttributes();
void parseSocialActions();
mutable RID m_rid;
collection_ptr m_collection;
@@ -126,6 +145,9 @@ private:
QVariantMap m_attributes;
unsigned int m_id;
QHash< QString, QVariant > m_currentSocialActions;
QList< SocialAction > m_allSocialActions;
};
}; //ns