1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-02-23 03:15:39 +01:00

Initial commit for resolver bundles: proof of concept.

This commit is contained in:
Teo Mrnjavac 2013-03-10 13:02:14 +01:00
parent 3dd1db1aed
commit 70baca7711
3 changed files with 46 additions and 9 deletions

View File

@ -451,16 +451,51 @@ SettingsDialog::openAccountConfig( Account* account, bool showDelete )
void
SettingsDialog::installFromFile()
{
const QString resolver = QFileDialog::getOpenFileName( 0, tr( "Install resolver from file" ), TomahawkSettings::instance()->scriptDefaultPath() );
QString resolver = QFileDialog::getOpenFileName( 0, tr( "Install resolver from file" ),
TomahawkSettings::instance()->scriptDefaultPath(),
tr( "Tomahawk Resolvers (*.axe *.js);;"
"All files (*)" ),
0,
QFileDialog::ReadOnly );
if( !resolver.isEmpty() )
{
const QFileInfo resolverAbsoluteFilePath( resolver );
//I'm still a little proof of concept, refactor me into a proper class
QFileInfo resolverAbsoluteFilePath( resolver );
TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );
if ( resolverAbsoluteFilePath.suffix() == "axe" )
{
QDir dir( TomahawkUtils::extractScriptPayload( resolverAbsoluteFilePath.filePath(),
resolverAbsoluteFilePath.baseName(),
"manualresolvers" ) );
dir.cd( "content" );
QFile desktopFile( dir.absoluteFilePath( "metadata.desktop" ) );
if ( desktopFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
QTextStream desktopFileStream( &desktopFile );
while ( !desktopFileStream.atEnd() )
{
QString line = desktopFileStream.readLine().trimmed();
//TODO: correct baseName
if ( line.startsWith( "X-Synchrotron-MainScript" ) )
{
line.remove( QRegExp( "^X-Synchrotron-MainScript\\s*=\\s*" ) );
resolver = dir.absoluteFilePath( line ); //this is our path to the JS
}
}
}
}
resolverAbsoluteFilePath = QFileInfo( resolver );
//TODO: if the new path has a metadata file in the dir structure, read it, check the config
// and act accordingly for multi-account resolvers
if ( resolverAbsoluteFilePath.baseName() == "spotify_tomahawkresolver" )
{
// HACK if this is a spotify resolver, we treat is specially.
// HACK if this is a spotify resolver, we treat it specially.
// usually we expect the user to just download the spotify resolver from attica,
// however developers, those who build their own tomahawk, can't do that, or linux
// users can't do that. However, we have an already-existing SpotifyAccount that we

View File

@ -911,16 +911,17 @@ verifyFile( const QString& filePath, const QString& signature )
QString
extractScriptPayload( const QString& filename, const QString& resolverId )
extractScriptPayload( const QString& filename, const QString& resolverId, const QString& dirName )
{
// uses QuaZip to extract the temporary zip file to the user's tomahawk data/resolvers directory
QDir resolverDir = appDataDir();
if ( !resolverDir.mkpath( QString( "atticaresolvers/%1" ).arg( resolverId ) ) )
if ( !resolverDir.mkpath( QString( "%1/%2" ).arg( dirName )
.arg( resolverId ) ) )
{
tLog() << "Failed to mkdir resolver save dir:" << TomahawkUtils::appDataDir().absoluteFilePath( QString( "atticaresolvers/%1" ).arg( resolverId ) );
tLog() << "Failed to mkdir resolver save dir:" << TomahawkUtils::appDataDir().absoluteFilePath( QString( "%1/%2" ).arg( dirName ).arg( resolverId ) );
return QString();
}
resolverDir.cd( QString( "atticaresolvers/%1" ).arg( resolverId ) );
resolverDir.cd( QString( "%1/%2" ).arg( dirName ).arg( resolverId ) );
if ( !unzipFileInFolder( filename, resolverDir ) )
{
@ -941,7 +942,8 @@ unzipFileInFolder( const QString& zipFileName, const QDir& folder )
QuaZip zipFile( zipFileName );
if ( !zipFile.open( QuaZip::mdUnzip ) )
{
qWarning() << "Failed to QuaZip open:" << zipFile.getZipError();
qWarning() << "Failed to QuaZip open" << zipFileName
<< "with error:" << zipFile.getZipError();
return false;
}

View File

@ -193,7 +193,7 @@ namespace TomahawkUtils
DLLEXPORT bool isLocalResult( const QString& url );
DLLEXPORT bool verifyFile( const QString& filePath, const QString& signature );
DLLEXPORT QString extractScriptPayload( const QString& filename, const QString& resolverId );
DLLEXPORT QString extractScriptPayload( const QString& filename, const QString& resolverId, const QString& dirName = "atticaresolvers" );
DLLEXPORT bool unzipFileInFolder( const QString& zipFileName, const QDir& folder );
// Extracting may be asynchronous, pass in a receiver object with the following slots: