mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01:00
Only allow voting once; Show the user's set score if he has rated it over the server
This commit is contained in:
parent
52930918f2
commit
742f73f028
@ -113,11 +113,10 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int
|
||||
return false;
|
||||
|
||||
|
||||
Attica::Content resolver = m_contentList[ index.row() ];
|
||||
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
|
||||
if ( role == Qt::EditRole )
|
||||
{
|
||||
Attica::Content resolver = m_contentList[ index.row() ];
|
||||
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
|
||||
|
||||
switch( state )
|
||||
{
|
||||
case AtticaManager::Uninstalled:
|
||||
@ -141,6 +140,11 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int
|
||||
};
|
||||
} else if ( role == RatingRole )
|
||||
{
|
||||
// For now only allow rating if a resolver is installed!
|
||||
if ( state != AtticaManager::Installed && state != AtticaManager::NeedsUpgrade )
|
||||
return false;
|
||||
if ( AtticaManager::userHasRated( resolver ) )
|
||||
return false;
|
||||
m_contentList[ index.row() ].setRating( value.toInt() * 20 );
|
||||
AtticaManager::instance()->uploadRating( m_contentList[ index.row() ] );
|
||||
}
|
||||
|
@ -151,7 +151,20 @@ AtticaManager::pathFromId( const QString& resolverId ) const
|
||||
void
|
||||
AtticaManager::uploadRating( const Content& c )
|
||||
{
|
||||
m_resolverStates[ c.id() ].rating = c.rating();
|
||||
m_resolverStates[ c.id() ].userRating = c.rating();
|
||||
|
||||
for ( int i = 0; i < m_resolvers.count(); i++ )
|
||||
{
|
||||
if ( m_resolvers[ i ].id() == c.id() )
|
||||
{
|
||||
Attica::Content atticaContent = m_resolvers[ i ];
|
||||
atticaContent.setRating( c.rating() );
|
||||
m_resolvers[ i ] = atticaContent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TomahawkSettings::instance()->setAtticaResolverStates( m_resolverStates );
|
||||
|
||||
PostJob* job = m_resolverProvider.voteForContent( c.id(), (uint)c.rating() );
|
||||
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), job, SLOT( deleteLater() ) );
|
||||
@ -161,6 +174,12 @@ AtticaManager::uploadRating( const Content& c )
|
||||
emit resolverStateChanged( c.id() );
|
||||
}
|
||||
|
||||
bool
|
||||
AtticaManager::userHasRated( const Content& c ) const
|
||||
{
|
||||
return m_resolverStates[ c.id() ].userRating != -1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::providerAdded( const Provider& provider )
|
||||
@ -231,14 +250,20 @@ AtticaManager::syncServerData()
|
||||
foreach ( const QString& id, m_resolverStates.keys() )
|
||||
{
|
||||
Resolver r = m_resolverStates[ id ];
|
||||
foreach ( const Content& upstream, m_resolvers )
|
||||
for ( int i = 0; i < m_resolvers.size(); i++ )
|
||||
{
|
||||
Attica::Content upstream = m_resolvers[ i ];
|
||||
// same resolver
|
||||
if ( id != upstream.id() )
|
||||
continue;
|
||||
|
||||
// Update our rating with the server's idea of rating
|
||||
m_resolverStates[ id ].rating = upstream.rating();
|
||||
// Update our rating with the server's idea of rating if we haven't rated it
|
||||
if ( m_resolverStates[ id ].userRating != -1 )
|
||||
{
|
||||
upstream.setRating( m_resolverStates[ id ].userRating );
|
||||
m_resolvers[ i ] = upstream;
|
||||
}
|
||||
|
||||
// DO we need to upgrade?
|
||||
if ( ( r.state == Installed || r.state == NeedsUpgrade ) &&
|
||||
!upstream.version().isEmpty() )
|
||||
|
@ -48,13 +48,13 @@ public:
|
||||
|
||||
struct Resolver {
|
||||
QString version, scriptPath;
|
||||
int rating; // 0-100
|
||||
int userRating; // 0-100
|
||||
ResolverState state;
|
||||
QPixmap* pixmap;
|
||||
|
||||
Resolver( const QString& v, const QString& path, int r, ResolverState s )
|
||||
: version( v ), scriptPath( path ), rating( r ), state( s ), pixmap( 0 ) {}
|
||||
Resolver() : state( Uninstalled ), pixmap( 0 ) {}
|
||||
Resolver( const QString& v, const QString& path, int userR, ResolverState s )
|
||||
: version( v ), scriptPath( path ), userRating( userR ), state( s ), pixmap( 0 ) {}
|
||||
Resolver() : userRating( -1 ), state( Uninstalled ), pixmap( 0 ) {}
|
||||
};
|
||||
|
||||
typedef QHash< QString, AtticaManager::Resolver > StateHash;
|
||||
@ -90,6 +90,7 @@ public:
|
||||
QString pathFromId( const QString& resolverId ) const;
|
||||
|
||||
void uploadRating( const Attica::Content& c );
|
||||
bool userHasRated( const Attica::Content& c ) const;
|
||||
|
||||
static bool removeDirectory( const QString& dir );
|
||||
|
||||
|
@ -45,7 +45,7 @@ inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash&
|
||||
foreach( const QString& key, states.keys() )
|
||||
{
|
||||
AtticaManager::Resolver resolver = states[ key ];
|
||||
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << (quint32)resolver.rating;
|
||||
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << resolver.userRating;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@ -59,13 +59,13 @@ inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states
|
||||
for ( uint i = 0; i < count; i++ )
|
||||
{
|
||||
QString key, version, scriptPath;
|
||||
qint32 state, rating;
|
||||
qint32 state, userRating;
|
||||
in >> key;
|
||||
in >> version;
|
||||
in >> scriptPath;
|
||||
in >> state;
|
||||
in >> rating;
|
||||
states[ key ] = AtticaManager::Resolver( version, scriptPath, rating, (AtticaManager::ResolverState)state );
|
||||
in >> userRating;
|
||||
states[ key ] = AtticaManager::Resolver( version, scriptPath, userRating, (AtticaManager::ResolverState)state );
|
||||
}
|
||||
return in;
|
||||
}
|
||||
@ -183,7 +183,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
|
||||
addSipPlugin( "sipzeroconf_legacy" );
|
||||
} else if ( oldVersion == 3 )
|
||||
{
|
||||
if ( contains( "script/atticaResolverStates" ) )
|
||||
if ( contains( "script/atticaresolverstates" ) )
|
||||
{
|
||||
// Do messy binary upgrade. remove attica resolvers :(
|
||||
setValue( "script/atticaresolverstates", QVariant() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user