1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-22 16:59:58 +01:00

More work on handling binary resolver install

This commit is contained in:
Leo Franchi 2012-05-16 18:07:56 -04:00
parent d60b8bda3e
commit ff431b1183
9 changed files with 104 additions and 30 deletions

View File

@ -738,6 +738,7 @@ void
AccountDelegate::errorInstalling( const QPersistentModelIndex& idx )
{
// Just hide the loading spinner as we do after a successful install
qDebug() << "ERROR INSTALLING index:" << idx;
doneInstalling( idx );
}

View File

@ -45,6 +45,14 @@ using namespace Accounts;
static QPixmap* s_icon = 0;
#ifdef Q_OS_MAC
static QString s_resolverId = "spotify-osx";
#elif defined(Q_OS_WIN)
static QString s_resolverId = "spotify-win";
#else
static QString s_resolverId = "spotify-linux"
#endif
Account*
SpotifyAccountFactory::createAccount( const QString& accountId )
{
@ -80,14 +88,21 @@ SpotifyAccount::init()
{
qRegisterMetaType< Tomahawk::Accounts::SpotifyPlaylistInfo* >( "Tomahawk::Accounts::SpotifyPlaylist*" );
AtticaManager::instance()->registerCustomAccount( "spotify", this );
setAccountFriendlyName( "Spotify" );
AtticaManager::instance()->registerCustomAccount( s_resolverId, this );
connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( resolverInstalled( QString ) ) );
const Attica::Content res = AtticaManager::instance()->resolverForId( "spotify" );
const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId );
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
if ( state == AtticaManager::Installed )
if ( !checkForResolver() && state != AtticaManager::Uninstalled )
{
// If the user manually deleted the resolver, mark it as uninstalled, so we re-fetch for the user
AtticaManager::instance()->uninstallResolver( res );
}
else if ( state == AtticaManager::Installed )
{
hookupResolver();
}
@ -100,7 +115,7 @@ SpotifyAccount::hookupResolver()
// initialize the resolver itself. this is called if the account actually has an installed spotify resolver,
// as it might not.
// If there is a last.fm resolver from attica installed, create the corresponding ExternalResolver* and hook up to it
const Attica::Content res = AtticaManager::instance()->resolverForId( "spotify" );
const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId );
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
Q_ASSERT( state == AtticaManager::Installed );
Q_UNUSED( state );
@ -124,6 +139,17 @@ SpotifyAccount::hookupResolver()
}
bool SpotifyAccount::checkForResolver()
{
#ifdef Q_OS_MAC
const QDir path = QCoreApplication::applicationDirPath();
QFile file( path.absoluteFilePath( "spotify_tomahawkresolver" ) );
return file.exists();
#endif
return false;
}
void
SpotifyAccount::resolverChanged()
{
@ -135,7 +161,7 @@ SpotifyAccount::resolverChanged()
Attica::Content
SpotifyAccount::atticaContent() const
{
return AtticaManager::instance()->resolverForId( "spotify" );
return AtticaManager::instance()->resolverForId( s_resolverId );
}
@ -149,7 +175,7 @@ SpotifyAccount::authenticate()
return;
}
const Attica::Content res = AtticaManager::instance()->resolverForId( "spotify" );
const Attica::Content res = AtticaManager::instance()->resolverForId( s_resolverId );
const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res );
qDebug() << "Spotify account authenticating...";

View File

@ -118,6 +118,8 @@ private slots:
private:
void init();
void hookupResolver();
bool checkForResolver();
void loadPlaylists();
void clearUser( bool permanentlyDelete = false );

View File

@ -43,10 +43,11 @@ class BinaryInstallerHelper : public QObject
{
Q_OBJECT
public:
explicit BinaryInstallerHelper( const QString& resolverId, AtticaManager* manager)
explicit BinaryInstallerHelper( const QString& resolverId, bool createAccount, AtticaManager* manager)
: QObject( manager )
, m_manager( QWeakPointer< AtticaManager >( manager ) )
, m_resolverId( resolverId )
, m_createAccount( createAccount )
{
Q_ASSERT( !m_resolverId.isEmpty() );
Q_ASSERT( !m_manager.isNull() );
@ -55,17 +56,21 @@ public:
virtual ~BinaryInstallerHelper() {}
public slots:
void extractSucceeded( const QString& path )
void installSucceeded( const QString& path )
{
qDebug() << Q_FUNC_INFO << "install of binary resolver succeeded, enabling";
if ( m_manager.isNull() )
return;
Tomahawk::Accounts::Account* acct = Tomahawk::Accounts::AccountManager::instance()->accountFromPath( path );
Tomahawk::Accounts::AccountManager::instance()->addAccount( acct );
TomahawkSettings::instance()->addAccount( acct->accountId() );
Tomahawk::Accounts::AccountManager::instance()->enableAccount( acct );
if ( m_createAccount )
{
Tomahawk::Accounts::Account* acct = Tomahawk::Accounts::AccountManager::instance()->accountFromPath( path );
Tomahawk::Accounts::AccountManager::instance()->addAccount( acct );
TomahawkSettings::instance()->addAccount( acct->accountId() );
Tomahawk::Accounts::AccountManager::instance()->enableAccount( acct );
}
m_manager.data()->m_resolverStates[ m_resolverId ].state = AtticaManager::Installed;
TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_manager.data()->m_resolverStates );
@ -74,8 +79,10 @@ public slots:
deleteLater();
}
void extractFailed()
void installFailed()
{
qDebug() << Q_FUNC_INFO << "install failed";
if ( m_manager.isNull() )
return;
@ -86,6 +93,7 @@ public slots:
private:
QString m_resolverId;
bool m_createAccount;
QWeakPointer<AtticaManager> m_manager;
};
@ -267,11 +275,8 @@ AtticaManager::userHasRated( const Content& c ) const
bool
AtticaManager::hasCustomAccountForAttica( const QString &id ) const
{
// Only last.fm at the moment contains a custom account
if ( id == "lastfm" )
return true;
return false;
qDebug() << "Got custom account for?" << id << m_customAccounts.keys();
return m_customAccounts.keys().contains( id );
}
@ -417,6 +422,10 @@ AtticaManager::binaryResolversList( BaseJob* j )
r.binary = true;
m_resolverStates.insert( c.id(), r );
}
else if ( m_resolverStates[ c.id() ].binary != true )
{ // HACK workaround... why is this not set in the first place sometimes? Migration issue?
m_resolverStates[ c.id() ].binary = true;
}
}
@ -580,10 +589,13 @@ AtticaManager::payloadFetched()
if ( !TomahawkUtils::verifyFile( f.fileName(), signature ) )
{
qWarning() << "FILE SIGNATURE FAILED FOR BINARY RESOLVER! WARNING! :" << f.fileName() << signature;
return;
}
TomahawkUtils::extractBinaryResolver( f.fileName(), new BinaryInstallerHelper( resolverId, this ) );
else
{
TomahawkUtils::extractBinaryResolver( f.fileName(), new BinaryInstallerHelper( resolverId, reply->property( "createAccount" ).toBool(), this ) );
// Don't emit failed yet
installedSuccessfully = true;
}
}
else
{
@ -702,4 +714,4 @@ AtticaManager::doResolverRemove( const QString& id ) const
TomahawkUtils::removeDirectory( resolverDir.absolutePath() );
}
#include "AtticaManager.moc"
#include "AtticaManager.moc"

View File

@ -516,6 +516,35 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
remove( "playlistupdaters" );
}
else if ( oldVersion == 11 )
{
// If the user doesn't have a spotify account, create one, since now it
// is like the last.fm account and always exists
QStringList allAccounts = value( "accounts/allaccounts" ).toStringList();
bool found = false;
foreach ( const QString& account, allAccounts )
{
if ( account.startsWith( "spotifyaccount_" ) )
{
found = true;
break;
}
}
if ( !found )
{
const QString accountKey = QString( "spotifyaccount_%1" ).arg( QUuid::createUuid().toString().mid( 1, 8 ) );
beginGroup( "accounts/" + accountKey );
setValue( "enabled", false );
setValue( "types", QStringList() << "ResolverType" );
setValue( "credentials", QVariantHash() );
setValue( "configuration", QVariantHash() );
endGroup();
allAccounts << accountKey;
setValue( "accounts/allaccounts", allAccounts );
}
}
}

View File

@ -30,7 +30,7 @@
#include "DllMacro.h"
#define TOMAHAWK_SETTINGS_VERSION 11
#define TOMAHAWK_SETTINGS_VERSION 12
/**
* Convenience wrapper around QSettings for tomahawk-specific config

View File

@ -38,7 +38,7 @@ AccountModelFilterProxy::setSourceModel( QAbstractItemModel* sourceModel )
connect( sourceModel, SIGNAL( scrollTo( QModelIndex ) ), this, SLOT( onScrollTo( QModelIndex ) ) );
connect( sourceModel, SIGNAL( startInstalling( QPersistentModelIndex ) ), this, SLOT( onStartInstalling( QPersistentModelIndex ) ) );
connect( sourceModel, SIGNAL( doneInstalling( QPersistentModelIndex ) ), this, SLOT( onDoneInstalling( QPersistentModelIndex ) ) );
connect( sourceModel, SIGNAL( doneInstalling( QPersistentModelIndex ) ), this, SLOT( errorInstalling( QPersistentModelIndex ) ) );
connect( sourceModel, SIGNAL( errorInstalling( QPersistentModelIndex ) ), this, SLOT( onErrorInstalling( QPersistentModelIndex ) ) );
QSortFilterProxyModel::setSourceModel( sourceModel );
}

View File

@ -845,7 +845,7 @@ unzipFileInFolder( const QString &zipFileName, const QDir &folder )
void
extractBinaryResolver( const QString& zipFilename, QObject* )
extractBinaryResolver( const QString& zipFilename, QObject* receiver )
{
#if !defined(Q_OS_MAC) && !defined (Q_OS_WIN)
Q_ASSERT( false );
@ -877,7 +877,7 @@ extractBinaryResolver( const QString& zipFilename, QObject* )
const QString src = toList.absoluteFilePath( files.first() );
qDebug() << "OS X: Copying binary resolver from to:" << src << dest;
copyWithAuthentication( src, dest, 0 );
copyWithAuthentication( src, dest, receiver );
#elif defined(Q_OS_WIN)
#endif

View File

@ -42,12 +42,11 @@
- (void)moveFinished
{
if ( receiver )
QMetaObject::invokeMethod(receiver, "installSucceeded", Qt::DirectConnection, Q_ARG(QString, path));
// HACK since I can't figure out how to get QuaZip to maintain executable permissions after unzip (nor find the info)
// we set the binary to executable here
NSLog(@"Move succeeded!, handling result");
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
NSError* error;
NSDictionary* attrs = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0755], NSFilePosixPermissions, nil];
@ -58,10 +57,15 @@
if (!success) {
NSLog( @"Failed to do chmod +x of moved resolver! %@", [[error userInfo] objectForKey: NSLocalizedDescriptionKey] );
}
if ( receiver )
QMetaObject::invokeMethod(receiver, "installSucceeded", Qt::DirectConnection, Q_ARG(QString, path));
}
- (void)moveFailedWithError:(NSError *)error
{
NSLog(@"Move failed, handling result");
if ( receiver )
QMetaObject::invokeMethod(receiver, "installFailed", Qt::DirectConnection);
}