mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Tomahawk-side support for resolver rating
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "GetNewStuffModel.h"
|
#include "GetNewStuffModel.h"
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
#include <QtGui/QPainter>
|
#include <QtGui/QPainter>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
#include "AtticaManager.h"
|
#include "AtticaManager.h"
|
||||||
|
|
||||||
#define PADDING 4
|
#define PADDING 4
|
||||||
|
#define PADDING_BETWEEN_STARS 2
|
||||||
|
|
||||||
#ifdef Q_WS_MAC
|
#ifdef Q_WS_MAC
|
||||||
#define SIZEHINT_HEIGHT 70
|
#define SIZEHINT_HEIGHT 70
|
||||||
@@ -175,17 +177,19 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio
|
|||||||
painter->setPen( saved );
|
painter->setPen( saved );
|
||||||
// rating stars
|
// rating stars
|
||||||
int rating = index.data( GetNewStuffModel::RatingRole ).toInt();
|
int rating = index.data( GetNewStuffModel::RatingRole ).toInt();
|
||||||
const int paddingBetweenStars = 2;
|
const int ratingWidth = 5 * ( m_ratingStarPositive.width() + PADDING_BETWEEN_STARS );
|
||||||
const int ratingWidth = 5 * ( m_ratingStarPositive.width() + paddingBetweenStars );
|
|
||||||
int runningEdge = ( btnRect.right() - btnRect.width() / 2 ) - ratingWidth / 2;
|
int runningEdge = ( btnRect.right() - btnRect.width() / 2 ) - ratingWidth / 2;
|
||||||
for ( int i = 1; i < 6; i++ )
|
for ( int i = 1; i < 6; i++ )
|
||||||
{
|
{
|
||||||
QRect r( runningEdge, btnRect.top() - m_ratingStarPositive.height() - PADDING, m_ratingStarPositive.width(), m_ratingStarPositive.height() );
|
QRect r( runningEdge, btnRect.top() - m_ratingStarPositive.height() - PADDING, m_ratingStarPositive.width(), m_ratingStarPositive.height() );
|
||||||
|
if ( i == 1 )
|
||||||
|
m_cachedStarRects[ QPair<int, int>(index.row(), index.column()) ] = r;
|
||||||
|
|
||||||
if ( i <= rating ) // positive star
|
if ( i <= rating ) // positive star
|
||||||
painter->drawPixmap( r, m_ratingStarPositive );
|
painter->drawPixmap( r, m_ratingStarPositive );
|
||||||
else
|
else
|
||||||
painter->drawPixmap( r, m_ratingStarNegative );
|
painter->drawPixmap( r, m_ratingStarNegative );
|
||||||
runningEdge += m_ratingStarPositive.width() + paddingBetweenStars;
|
runningEdge += m_ratingStarPositive.width() + PADDING_BETWEEN_STARS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloaded num times, underneath button
|
// downloaded num times, underneath button
|
||||||
@@ -238,7 +242,10 @@ bool
|
|||||||
GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
|
||||||
{
|
{
|
||||||
Q_UNUSED( option );
|
Q_UNUSED( option );
|
||||||
if ( event->type() == QEvent::MouseButtonRelease && m_cachedButtonRects.contains( QPair<int, int>( index.row(), index.column() ) ) )
|
if ( event->type() != QEvent::MouseButtonRelease )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ( m_cachedButtonRects.contains( QPair<int, int>( index.row(), index.column() ) ) )
|
||||||
{
|
{
|
||||||
QRect rect = m_cachedButtonRects[ QPair<int, int>( index.row(), index.column() ) ];
|
QRect rect = m_cachedButtonRects[ QPair<int, int>( index.row(), index.column() ) ];
|
||||||
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
||||||
@@ -250,5 +257,27 @@ GetNewStuffDelegate::editorEvent( QEvent* event, QAbstractItemModel* model, cons
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( m_cachedStarRects.contains( QPair<int, int>( index.row(), index.column() ) ) )
|
||||||
|
{
|
||||||
|
QRect fullStars = m_cachedStarRects[ QPair<int, int>( index.row(), index.column() ) ];
|
||||||
|
const int starsWidth = 5 * ( m_ratingStarPositive.width() + PADDING_BETWEEN_STARS );
|
||||||
|
fullStars.setWidth( starsWidth );
|
||||||
|
|
||||||
|
QMouseEvent* me = static_cast< QMouseEvent* >( event );
|
||||||
|
|
||||||
|
if ( fullStars.contains( me->pos() ) )
|
||||||
|
{
|
||||||
|
tDebug() << "A star was pressed...which one?";
|
||||||
|
|
||||||
|
const int eachStar = starsWidth / 5;
|
||||||
|
const int clickOffset = me->pos().x() - fullStars.x();
|
||||||
|
const int whichStar = (clickOffset / eachStar) + 1;
|
||||||
|
tDebug() << "Clicked on:" << whichStar;
|
||||||
|
model->setData( index, whichStar, GetNewStuffModel::RatingRole );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,7 @@ private:
|
|||||||
|
|
||||||
int m_widestTextWidth;
|
int m_widestTextWidth;
|
||||||
mutable QHash< QPair<int, int>, QRect > m_cachedButtonRects;
|
mutable QHash< QPair<int, int>, QRect > m_cachedButtonRects;
|
||||||
|
mutable QHash< QPair<int, int>, QRect > m_cachedStarRects;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GETNEWSTUFFDELEGATE_H
|
#endif // GETNEWSTUFFDELEGATE_H
|
||||||
|
@@ -109,13 +109,13 @@ bool
|
|||||||
GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int role )
|
GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int role )
|
||||||
{
|
{
|
||||||
Q_UNUSED( value );
|
Q_UNUSED( value );
|
||||||
Q_UNUSED( role );
|
|
||||||
if ( !hasIndex( index.row(), index.column(), index.parent() ) )
|
if ( !hasIndex( index.row(), index.column(), index.parent() ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// the install/uninstall button was clicked
|
|
||||||
const Attica::Content resolver = m_contentList[ index.row() ];
|
|
||||||
|
|
||||||
|
if ( role == Qt::EditRole )
|
||||||
|
{
|
||||||
|
Attica::Content resolver = m_contentList[ index.row() ];
|
||||||
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
|
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
|
||||||
|
|
||||||
switch( state )
|
switch( state )
|
||||||
@@ -139,6 +139,11 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int
|
|||||||
//FIXME -- this handles e.g. Failed
|
//FIXME -- this handles e.g. Failed
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
} else if ( role == RatingRole )
|
||||||
|
{
|
||||||
|
m_contentList[ index.row() ].setRating( value.toInt() * 20 );
|
||||||
|
AtticaManager::instance()->uploadRating( m_contentList[ index.row() ] );
|
||||||
|
}
|
||||||
emit dataChanged( index, index );
|
emit dataChanged( index, index );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -148,6 +148,19 @@ AtticaManager::pathFromId( const QString& resolverId ) const
|
|||||||
return m_resolverStates.value( resolverId ).scriptPath;
|
return m_resolverStates.value( resolverId ).scriptPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AtticaManager::uploadRating( const Content& c )
|
||||||
|
{
|
||||||
|
m_resolverStates[ c.id() ].rating = c.rating();
|
||||||
|
|
||||||
|
PostJob* job = m_resolverProvider.voteForContent( c.id(), (uint)c.rating() );
|
||||||
|
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), job, SLOT( deleteLater() ) );
|
||||||
|
|
||||||
|
job->start();
|
||||||
|
|
||||||
|
emit resolverStateChanged( c.id() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AtticaManager::providerAdded( const Provider& provider )
|
AtticaManager::providerAdded( const Provider& provider )
|
||||||
@@ -186,7 +199,7 @@ AtticaManager::resolversList( BaseJob* j )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkForUpdates();
|
syncServerData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -211,18 +224,24 @@ AtticaManager::resolverIconFetched()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AtticaManager::checkForUpdates()
|
AtticaManager::syncServerData()
|
||||||
{
|
{
|
||||||
// look for any newer. m_resolvers has list from server, and m_resolverStates will contain any locally installed ones
|
// look for any newer. m_resolvers has list from server, and m_resolverStates will contain any locally installed ones
|
||||||
|
// also update ratings
|
||||||
foreach ( const QString& id, m_resolverStates.keys() )
|
foreach ( const QString& id, m_resolverStates.keys() )
|
||||||
{
|
{
|
||||||
Resolver r = m_resolverStates[ id ];
|
Resolver r = m_resolverStates[ id ];
|
||||||
if ( r.state == Installed || r.state == NeedsUpgrade )
|
|
||||||
{
|
|
||||||
foreach ( const Content& upstream, m_resolvers )
|
foreach ( const Content& upstream, m_resolvers )
|
||||||
{
|
{
|
||||||
if ( id == upstream.id() && // the right one
|
// same resolver
|
||||||
!upstream.version().isEmpty() ) // valid version
|
if ( id != upstream.id() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Update our rating with the server's idea of rating
|
||||||
|
m_resolverStates[ id ].rating = upstream.rating();
|
||||||
|
// DO we need to upgrade?
|
||||||
|
if ( ( r.state == Installed || r.state == NeedsUpgrade ) &&
|
||||||
|
!upstream.version().isEmpty() )
|
||||||
{
|
{
|
||||||
if ( newerVersion( r.version, upstream.version() ) )
|
if ( newerVersion( r.version, upstream.version() ) )
|
||||||
{
|
{
|
||||||
@@ -232,7 +251,6 @@ AtticaManager::checkForUpdates()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
AtticaManager::newerVersion( const QString& older, const QString& newer ) const
|
AtticaManager::newerVersion( const QString& older, const QString& newer ) const
|
||||||
@@ -513,7 +531,7 @@ AtticaManager::doResolverRemove( const QString& id ) const
|
|||||||
|
|
||||||
// taken from util/fileutils.cpp in kdevplatform
|
// taken from util/fileutils.cpp in kdevplatform
|
||||||
bool
|
bool
|
||||||
AtticaManager::removeDirectory( const QString& dir ) const
|
AtticaManager::removeDirectory( const QString& dir )
|
||||||
{
|
{
|
||||||
const QDir aDir(dir);
|
const QDir aDir(dir);
|
||||||
|
|
||||||
|
@@ -48,11 +48,12 @@ public:
|
|||||||
|
|
||||||
struct Resolver {
|
struct Resolver {
|
||||||
QString version, scriptPath;
|
QString version, scriptPath;
|
||||||
|
int rating; // 0-100
|
||||||
ResolverState state;
|
ResolverState state;
|
||||||
QPixmap* pixmap;
|
QPixmap* pixmap;
|
||||||
|
|
||||||
Resolver( const QString& v, const QString& path, ResolverState s )
|
Resolver( const QString& v, const QString& path, int r, ResolverState s )
|
||||||
: version( v ), scriptPath( path ), state( s ), pixmap( 0 ) {}
|
: version( v ), scriptPath( path ), rating( r ), state( s ), pixmap( 0 ) {}
|
||||||
Resolver() : state( Uninstalled ), pixmap( 0 ) {}
|
Resolver() : state( Uninstalled ), pixmap( 0 ) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,6 +89,10 @@ public:
|
|||||||
void uninstallResolver( const QString& pathToResolver );
|
void uninstallResolver( const QString& pathToResolver );
|
||||||
QString pathFromId( const QString& resolverId ) const;
|
QString pathFromId( const QString& resolverId ) const;
|
||||||
|
|
||||||
|
void uploadRating( const Attica::Content& c );
|
||||||
|
|
||||||
|
static bool removeDirectory( const QString& dir );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void resolversReloaded( const Attica::Content::List& resolvers );
|
void resolversReloaded( const Attica::Content::List& resolvers );
|
||||||
|
|
||||||
@@ -105,13 +110,12 @@ private slots:
|
|||||||
void savePixmapsToCache();
|
void savePixmapsToCache();
|
||||||
void resolverIconFetched();
|
void resolverIconFetched();
|
||||||
|
|
||||||
void checkForUpdates();
|
void syncServerData();
|
||||||
bool newerVersion( const QString& older, const QString& newer ) const;
|
bool newerVersion( const QString& older, const QString& newer ) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString extractPayload( const QString& filename, const QString& resolverId ) const;
|
QString extractPayload( const QString& filename, const QString& resolverId ) const;
|
||||||
void doResolverRemove( const QString& id ) const;
|
void doResolverRemove( const QString& id ) const;
|
||||||
bool removeDirectory( const QString& dir ) const;
|
|
||||||
|
|
||||||
Attica::ProviderManager m_manager;
|
Attica::ProviderManager m_manager;
|
||||||
|
|
||||||
|
@@ -29,8 +29,9 @@
|
|||||||
#include "playlistinterface.h"
|
#include "playlistinterface.h"
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
#include "utils/tomahawkutils.h"
|
||||||
|
|
||||||
#define VERSION 3
|
#define VERSION 4
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -39,11 +40,12 @@ TomahawkSettings* TomahawkSettings::s_instance = 0;
|
|||||||
|
|
||||||
inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash& states)
|
inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash& states)
|
||||||
{
|
{
|
||||||
|
out << VERSION;
|
||||||
out << (quint32)states.count();
|
out << (quint32)states.count();
|
||||||
foreach( const QString& key, states.keys() )
|
foreach( const QString& key, states.keys() )
|
||||||
{
|
{
|
||||||
AtticaManager::Resolver resolver = states[ key ];
|
AtticaManager::Resolver resolver = states[ key ];
|
||||||
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state;
|
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << (quint32)resolver.rating;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@@ -51,22 +53,23 @@ inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash&
|
|||||||
|
|
||||||
inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states)
|
inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states)
|
||||||
{
|
{
|
||||||
quint32 count = 0;
|
quint32 count = 0, version = 0;
|
||||||
|
in >> version;
|
||||||
in >> count;
|
in >> count;
|
||||||
for ( uint i = 0; i < count; i++ )
|
for ( uint i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
QString key, version, scriptPath;
|
QString key, version, scriptPath;
|
||||||
qint32 state;
|
qint32 state, rating;
|
||||||
in >> key;
|
in >> key;
|
||||||
in >> version;
|
in >> version;
|
||||||
in >> scriptPath;
|
in >> scriptPath;
|
||||||
in >> state;
|
in >> state;
|
||||||
states[ key ] = AtticaManager::Resolver( version, scriptPath, (AtticaManager::ResolverState)state );
|
in >> rating;
|
||||||
|
states[ key ] = AtticaManager::Resolver( version, scriptPath, rating, (AtticaManager::ResolverState)state );
|
||||||
}
|
}
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TomahawkSettings*
|
TomahawkSettings*
|
||||||
TomahawkSettings::instance()
|
TomahawkSettings::instance()
|
||||||
{
|
{
|
||||||
@@ -178,6 +181,45 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
|
|||||||
}
|
}
|
||||||
// create a zeroconf plugin too
|
// create a zeroconf plugin too
|
||||||
addSipPlugin( "sipzeroconf_legacy" );
|
addSipPlugin( "sipzeroconf_legacy" );
|
||||||
|
} else if ( oldVersion == 3 )
|
||||||
|
{
|
||||||
|
if ( contains( "script/atticaResolverStates" ) )
|
||||||
|
{
|
||||||
|
// Do messy binary upgrade. remove attica resolvers :(
|
||||||
|
setValue( "script/atticaresolverstates", QVariant() );
|
||||||
|
|
||||||
|
QDir resolverDir = TomahawkUtils::appDataDir();
|
||||||
|
if ( !resolverDir.cd( QString( "atticaresolvers" ) ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QStringList toremove;
|
||||||
|
QStringList resolvers = resolverDir.entryList( QDir::Dirs | QDir::NoDotAndDotDot );
|
||||||
|
QStringList listedResolvers = allScriptResolvers();
|
||||||
|
QStringList enabledResolvers = enabledScriptResolvers();
|
||||||
|
foreach ( const QString& resolver, resolvers )
|
||||||
|
{
|
||||||
|
foreach ( const QString& r, listedResolvers )
|
||||||
|
{
|
||||||
|
if ( r.contains( resolver ) )
|
||||||
|
{
|
||||||
|
tDebug() << "Deleting listed resolver:" << r;
|
||||||
|
listedResolvers.removeAll( r );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ( const QString& r, enabledResolvers )
|
||||||
|
{
|
||||||
|
if ( r.contains( resolver ) )
|
||||||
|
{
|
||||||
|
tDebug() << "Deleting enabled resolver:" << r;
|
||||||
|
enabledResolvers.removeAll( r );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setAllScriptResolvers( listedResolvers );
|
||||||
|
setEnabledScriptResolvers( enabledResolvers );
|
||||||
|
tDebug() << "UPGRADING AND DELETING:" << resolverDir.absolutePath();
|
||||||
|
AtticaManager::removeDirectory( resolverDir.absolutePath() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user