mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 23:39:42 +01:00
* More reliable and easier to read version check. Moved to TomahawkUtils, too.
This commit is contained in:
parent
f5d2251312
commit
30dcf3cebb
@ -151,6 +151,7 @@ AtticaManager::pathFromId( const QString& resolverId ) const
|
||||
return m_resolverStates.value( resolverId ).scriptPath;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::uploadRating( const Content& c )
|
||||
{
|
||||
@ -177,6 +178,7 @@ AtticaManager::uploadRating( const Content& c )
|
||||
emit resolverStateChanged( c.id() );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
AtticaManager::userHasRated( const Content& c ) const
|
||||
{
|
||||
@ -247,6 +249,7 @@ AtticaManager::resolverIconFetched()
|
||||
m_resolverStates[ resolverId ].pixmap = icon;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::syncServerData()
|
||||
{
|
||||
@ -273,7 +276,7 @@ AtticaManager::syncServerData()
|
||||
if ( ( r.state == Installed || r.state == NeedsUpgrade ) &&
|
||||
!upstream.version().isEmpty() )
|
||||
{
|
||||
if ( newerVersion( r.version, upstream.version() ) )
|
||||
if ( TomahawkUtils::newerVersion( r.version, upstream.version() ) )
|
||||
{
|
||||
m_resolverStates[ id ].state = NeedsUpgrade;
|
||||
QMetaObject::invokeMethod( this, "upgradeResolver", Qt::QueuedConnection, Q_ARG( Attica::Content, upstream ) );
|
||||
@ -283,57 +286,6 @@ AtticaManager::syncServerData()
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
AtticaManager::newerVersion( const QString& older, const QString& newer ) const
|
||||
{
|
||||
// Version comparison: turns X.Y.Z into XYZ (adding 0 to X.Y. and 00 to X respectively)
|
||||
if ( older.isEmpty() || newer.isEmpty() )
|
||||
return false;
|
||||
|
||||
QString oldDigits = older;
|
||||
oldDigits = oldDigits.replace( ".", "" );
|
||||
int oldDigitsInt;
|
||||
|
||||
if ( oldDigits.size() == 1 )
|
||||
{
|
||||
oldDigitsInt = oldDigits.append("00").toInt();
|
||||
}
|
||||
else if ( oldDigits.size() == 2 )
|
||||
{
|
||||
oldDigitsInt = oldDigits.append("0").toInt();
|
||||
}
|
||||
else if ( oldDigits.size() == 3 )
|
||||
{
|
||||
oldDigitsInt = oldDigits.toInt();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
QString newDigits = newer;
|
||||
newDigits = newDigits.replace( ".", "");
|
||||
int newDigitsInt;
|
||||
|
||||
if ( newDigits.size() == 1 )
|
||||
{
|
||||
newDigitsInt = newDigits.append("00").toInt();
|
||||
}
|
||||
else if ( newDigits.size() == 2 )
|
||||
{
|
||||
newDigitsInt = newDigits.append("0").toInt();
|
||||
}
|
||||
else if ( newDigits.size() == 3 )
|
||||
{
|
||||
newDigitsInt = newDigits.toInt();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
// Do the comparison
|
||||
if ( newDigitsInt > oldDigitsInt )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
AtticaManager::installResolver( const Content& resolver )
|
||||
@ -354,6 +306,7 @@ AtticaManager::installResolver( const Content& resolver )
|
||||
job->start();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AtticaManager::upgradeResolver( const Content& resolver )
|
||||
{
|
||||
|
@ -112,7 +112,6 @@ private slots:
|
||||
void resolverIconFetched();
|
||||
|
||||
void syncServerData();
|
||||
bool newerVersion( const QString& older, const QString& newer ) const;
|
||||
|
||||
private:
|
||||
QString extractPayload( const QString& filename, const QString& resolverId ) const;
|
||||
|
@ -500,7 +500,7 @@ setNam( QNetworkAccessManager* nam, bool noMutexLocker )
|
||||
if ( !s->proxyNoProxyHosts().isEmpty() )
|
||||
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
|
||||
}
|
||||
|
||||
|
||||
nam->setProxyFactory( proxyFactory );
|
||||
s_threadNamHash[ QThread::currentThread() ] = nam;
|
||||
s_threadProxyFactoryHash[ QThread::currentThread() ] = proxyFactory;
|
||||
@ -514,6 +514,35 @@ setNam( QNetworkAccessManager* nam, bool noMutexLocker )
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
newerVersion( const QString& oldVersion, const QString& newVersion )
|
||||
{
|
||||
if ( oldVersion.isEmpty() || newVersion.isEmpty() )
|
||||
return false;
|
||||
|
||||
QStringList oldVList = oldVersion.split( ".", QString::SkipEmptyParts );
|
||||
QStringList newVList = newVersion.split( ".", QString::SkipEmptyParts );
|
||||
|
||||
int i = 0;
|
||||
foreach ( const QString& nvPart, newVList )
|
||||
{
|
||||
if ( i + 1 > oldVList.count() )
|
||||
return true;
|
||||
|
||||
int nviPart = nvPart.toInt();
|
||||
int oviPart = oldVList.at( i++ ).toInt();
|
||||
|
||||
if ( nviPart > oviPart )
|
||||
return true;
|
||||
|
||||
if ( nviPart < oviPart )
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
crash()
|
||||
{
|
||||
@ -521,6 +550,7 @@ crash()
|
||||
*a = 1;
|
||||
}
|
||||
|
||||
|
||||
// taken from util/fileutils.cpp in kdevplatform
|
||||
bool
|
||||
removeDirectory( const QString& dir )
|
||||
|
@ -78,6 +78,7 @@ namespace TomahawkUtils
|
||||
DLLEXPORT QString ageToString( const QDateTime& time, bool appendAgoString = false );
|
||||
DLLEXPORT QString filesizeToString( unsigned int size );
|
||||
DLLEXPORT QString extensionToMimetype( const QString& extension );
|
||||
DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion );
|
||||
|
||||
DLLEXPORT NetworkProxyFactory* proxyFactory( bool noMutexLocker = false );
|
||||
DLLEXPORT QNetworkAccessManager* nam();
|
||||
|
Loading…
x
Reference in New Issue
Block a user