mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 22:26:32 +02:00
Add upgrade support for resolvers
This commit is contained in:
@@ -114,12 +114,18 @@ GetNewStuffDelegate::paint( QPainter* painter, const QStyleOptionViewItem& optio
|
|||||||
case AtticaManager::Installing:
|
case AtticaManager::Installing:
|
||||||
actionText = tr( "Installing" );
|
actionText = tr( "Installing" );
|
||||||
break;
|
break;
|
||||||
|
case AtticaManager::Upgrading:
|
||||||
|
actionText = tr( "Upgrading" );
|
||||||
|
break;
|
||||||
case AtticaManager::Failed:
|
case AtticaManager::Failed:
|
||||||
actionText = tr( "Failed" );
|
actionText = tr( "Failed" );
|
||||||
break;
|
break;
|
||||||
case AtticaManager::Installed:
|
case AtticaManager::Installed:
|
||||||
actionText = tr( "Uninstall" );
|
actionText = tr( "Uninstall" );
|
||||||
break;
|
break;
|
||||||
|
case AtticaManager::NeedsUpgrade:
|
||||||
|
actionText = tr( "Upgrade" );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int btnWidth = m_widestTextWidth + 7;
|
const int btnWidth = m_widestTextWidth + 7;
|
||||||
|
@@ -130,7 +130,7 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int
|
|||||||
AtticaManager::instance()->uninstallResolver( resolver );
|
AtticaManager::instance()->uninstallResolver( resolver );
|
||||||
break;
|
break;
|
||||||
case AtticaManager::NeedsUpgrade:
|
case AtticaManager::NeedsUpgrade:
|
||||||
// TODO
|
AtticaManager::instance()->upgradeResolver( resolver );
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
emit dataChanged( index, index );
|
emit dataChanged( index, index );
|
||||||
|
@@ -206,8 +206,73 @@ AtticaManager::resolverIconFetched()
|
|||||||
void
|
void
|
||||||
AtticaManager::checkForUpdates()
|
AtticaManager::checkForUpdates()
|
||||||
{
|
{
|
||||||
// look for any newever
|
// look for any newer. m_resolvers has list from server, and m_resolverStates will contain any locally installed ones
|
||||||
|
foreach ( const QString& id, m_resolverStates.keys() )
|
||||||
|
{
|
||||||
|
Resolver r = m_resolverStates[ id ];
|
||||||
|
if ( r.state == Installed || r.state == NeedsUpgrade )
|
||||||
|
{
|
||||||
|
foreach ( const Content& upstream, m_resolvers )
|
||||||
|
{
|
||||||
|
if ( id == upstream.id() && // the right one
|
||||||
|
!upstream.version().isEmpty() ) // valid version
|
||||||
|
{
|
||||||
|
if ( newerVersion( r.version, upstream.version() ) )
|
||||||
|
{
|
||||||
|
m_resolverStates[ id ].state = NeedsUpgrade;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
AtticaManager::newerVersion( const QString& older, const QString& newer ) const
|
||||||
|
{
|
||||||
|
// Dumb version comparison. Expects two strings, X.Y and Z.V. Returns true if Z > v || Z == V && V > Y
|
||||||
|
// DOES NOT support X.Y.Z version strings
|
||||||
|
if ( older.isEmpty() || newer.isEmpty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QPair<int, int> oldVer, newVer;
|
||||||
|
QStringList parts = older.split( "." );
|
||||||
|
|
||||||
|
if ( parts.size() == 1 )
|
||||||
|
{
|
||||||
|
oldVer.first = parts[ 0 ].toInt();
|
||||||
|
oldVer.second = 0;
|
||||||
|
}
|
||||||
|
else if ( parts.size() == 2 )
|
||||||
|
{
|
||||||
|
oldVer.first = parts[ 0 ].toInt();
|
||||||
|
oldVer.second = parts[ 1 ].toInt();;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
parts = newer.split( "." );
|
||||||
|
if ( parts.size() == 1 )
|
||||||
|
{
|
||||||
|
newVer.first = parts[ 0 ].toInt();
|
||||||
|
newVer.second = 0;
|
||||||
|
}
|
||||||
|
else if ( parts.size() == 2 )
|
||||||
|
{
|
||||||
|
newVer.first = parts[ 0 ].toInt();
|
||||||
|
newVer.second = parts[ 1 ].toInt();;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Do the comparison
|
||||||
|
if ( newVer.first > oldVer.first )
|
||||||
|
return true;
|
||||||
|
if ( newVer.first == oldVer.first &&
|
||||||
|
newVer.second > oldVer.second )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -215,7 +280,9 @@ AtticaManager::installResolver( const Content& resolver )
|
|||||||
{
|
{
|
||||||
Q_ASSERT( !resolver.id().isNull() );
|
Q_ASSERT( !resolver.id().isNull() );
|
||||||
|
|
||||||
|
if ( m_resolverStates[ resolver.id() ].state != Upgrading )
|
||||||
m_resolverStates[ resolver.id() ].state = Installing;
|
m_resolverStates[ resolver.id() ].state = Installing;
|
||||||
|
|
||||||
m_resolverStates[ resolver.id() ].scriptPath = resolver.attribute( "mainscript" );
|
m_resolverStates[ resolver.id() ].scriptPath = resolver.attribute( "mainscript" );
|
||||||
m_resolverStates[ resolver.id() ].version = resolver.version();
|
m_resolverStates[ resolver.id() ].version = resolver.version();
|
||||||
emit resolverStateChanged( resolver.id() );
|
emit resolverStateChanged( resolver.id() );
|
||||||
@@ -227,6 +294,22 @@ AtticaManager::installResolver( const Content& resolver )
|
|||||||
job->start();
|
job->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AtticaManager::upgradeResolver( const Content& resolver )
|
||||||
|
{
|
||||||
|
Q_ASSERT( m_resolverStates.contains( resolver.id() ) );
|
||||||
|
Q_ASSERT( m_resolverStates[ resolver.id() ].state == NeedsUpgrade );
|
||||||
|
|
||||||
|
if ( !m_resolverStates.contains( resolver.id() ) || m_resolverStates[ resolver.id() ].state != NeedsUpgrade )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_resolverStates[ resolver.id() ].state = Upgrading;
|
||||||
|
emit resolverStateChanged( resolver.id() );
|
||||||
|
|
||||||
|
uninstallResolver( resolver );
|
||||||
|
installResolver( resolver );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AtticaManager::resolverDownloadFinished ( BaseJob* j )
|
AtticaManager::resolverDownloadFinished ( BaseJob* j )
|
||||||
@@ -279,7 +362,7 @@ AtticaManager::payloadFetched()
|
|||||||
// Do the install / add to tomahawk
|
// Do the install / add to tomahawk
|
||||||
Tomahawk::Pipeline::instance()->addScriptResolver( resolverPath, true );
|
Tomahawk::Pipeline::instance()->addScriptResolver( resolverPath, true );
|
||||||
m_resolverStates[ resolverId ].state = Installed;
|
m_resolverStates[ resolverId ].state = Installed;
|
||||||
TomahawkSettings::instance()->setAtticaResolverState( resolverId, Installed );
|
TomahawkSettings::instance()->setAtticaResolverStates( m_resolverStates );
|
||||||
emit resolverInstalled( resolverId );
|
emit resolverInstalled( resolverId );
|
||||||
emit resolverStateChanged( resolverId );
|
emit resolverStateChanged( resolverId );
|
||||||
}
|
}
|
||||||
@@ -387,13 +470,16 @@ AtticaManager::uninstallResolver( const QString& pathToResolver )
|
|||||||
void
|
void
|
||||||
AtticaManager::uninstallResolver( const Content& resolver )
|
AtticaManager::uninstallResolver( const Content& resolver )
|
||||||
{
|
{
|
||||||
|
if ( m_resolverStates[ resolver.id() ].state != Upgrading )
|
||||||
|
{
|
||||||
emit resolverUninstalled( resolver.id() );
|
emit resolverUninstalled( resolver.id() );
|
||||||
emit resolverStateChanged( resolver.id() );
|
emit resolverStateChanged( resolver.id() );
|
||||||
|
|
||||||
Tomahawk::Pipeline::instance()->removeScriptResolver( pathFromId( resolver.id() ) );
|
|
||||||
m_resolverStates[ resolver.id() ].state = Uninstalled;
|
m_resolverStates[ resolver.id() ].state = Uninstalled;
|
||||||
TomahawkSettings::instance()->setAtticaResolverState( resolver.id(), Uninstalled );
|
TomahawkSettings::instance()->setAtticaResolverState( resolver.id(), Uninstalled );
|
||||||
|
}
|
||||||
|
|
||||||
|
Tomahawk::Pipeline::instance()->removeScriptResolver( pathFromId( resolver.id() ) );
|
||||||
doResolverRemove( resolver.id() );
|
doResolverRemove( resolver.id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -83,6 +83,7 @@ public:
|
|||||||
QPixmap iconForResolver( const Attica::Content& id ); // Looks up in icon cache
|
QPixmap iconForResolver( const Attica::Content& id ); // Looks up in icon cache
|
||||||
|
|
||||||
void installResolver( const Attica::Content& resolver );
|
void installResolver( const Attica::Content& resolver );
|
||||||
|
void upgradeResolver( const Attica::Content& resolver );
|
||||||
void uninstallResolver( const Attica::Content& resolver );
|
void uninstallResolver( const Attica::Content& resolver );
|
||||||
void uninstallResolver( const QString& pathToResolver );
|
void uninstallResolver( const QString& pathToResolver );
|
||||||
QString pathFromId( const QString& resolverId ) const;
|
QString pathFromId( const QString& resolverId ) const;
|
||||||
@@ -105,6 +106,7 @@ private slots:
|
|||||||
void resolverIconFetched();
|
void resolverIconFetched();
|
||||||
|
|
||||||
void checkForUpdates();
|
void checkForUpdates();
|
||||||
|
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;
|
||||||
|
Reference in New Issue
Block a user