void
SettingsDialog::installFromFile()
{
    const 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 );
        TomahawkSettings::instance()->setScriptDefaultPath( resolverAbsoluteFilePath.absolutePath() );

        if ( resolverAbsoluteFilePath.baseName() == "spotify_tomahawkresolver" )
        {
            // 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
            // know exists that we need to use this resolver path.
            //
            // Hence, we special-case the spotify resolver and directly set the path on it here.
            SpotifyAccount* acct = 0;
            foreach ( Account* account, AccountManager::instance()->accounts() )
            {
                if ( SpotifyAccount* spotify = qobject_cast< SpotifyAccount* >( account ) )
                {
                    acct = spotify;
                    break;
                }
            }

            if ( acct )
            {
                acct->setManualResolverPath( resolver );
                return;
            }
        }

        Account* acct = AccountManager::instance()->accountFromPath( resolver );

        if ( !acct )
        {
            QFileInfo fi( resolver );

            JobStatusView::instance()->model()->addJob( new ErrorStatusMessage(
                                    tr( "Resolver installation from file %1 failed." )
                                    .arg( fi.fileName() ) ) );

            tDebug() << "Resolver was not installed:" << resolver;
            return;
        }

        AccountManager::instance()->addAccount( acct );
        TomahawkSettings::instance()->addAccount( acct->accountId() );
        AccountManager::instance()->enableAccount( acct );
    }
Beispiel #2
0
void
AccountModel::loadData()
{
    beginResetModel();

    qDeleteAll( m_accounts );
    m_accounts.clear();

    // Add all factories
    QList< AccountFactory* > factories = AccountManager::instance()->factories();
    QList< Account* > allAccounts = AccountManager::instance()->accounts();
#if ACCOUNTMODEL_DEBUG
    qDebug() << Q_FUNC_INFO;
    qDebug() << "All accounts:";
    foreach ( Account* acct, allAccounts )
        qDebug() << acct->accountFriendlyName() << "\t" << acct->accountId();
#endif
    foreach ( AccountFactory* fac, factories )
    {
        if ( !fac->allowUserCreation() )
            continue;

        qDebug() << "Creating factory node:" << fac->prettyName();
        m_accounts << new AccountModelNode( fac );

        // remove the accounts we are dealing with
        foreach ( Account* acct, allAccounts )
        {
            if ( AccountManager::instance()->factoryForAccount( acct ) == fac )
                allAccounts.removeAll( acct );
        }
    }

    // add all attica resolvers (installed or uninstalled)
    Attica::Content::List fromAttica = AtticaManager::instance()->resolvers();
    foreach ( const Attica::Content& content, fromAttica )
    {
        qDebug() << "Loading ATTICA ACCOUNT with content:" << content.id() << content.name();
        if ( AtticaManager::instance()->hasCustomAccountForAttica( content.id() ) )
        {
            Account* acct = AtticaManager::instance()->customAccountForAttica( content.id() );
            Q_ASSERT( acct );
            if ( acct )
            {
                m_accounts << new AccountModelNode( acct );
                const int removed = allAccounts.removeAll( acct );
#if ACCOUNTMODEL_DEBUG
                qDebug() << "Removed custom account from misc accounts list, found:" << removed;
                qDebug() << "All accounts after remove:";
                foreach ( Account* acct, allAccounts )
                    qDebug() << acct->accountFriendlyName() << "\t" << acct->accountId();    // All other accounts we haven't dealt with yet
#else
                Q_UNUSED( removed );
#endif
            }
        } else
        {
            m_accounts << new AccountModelNode( content );

            foreach ( Account* acct, AccountManager::instance()->accounts( Accounts::ResolverType ) )
            {
#if ACCOUNTMODEL_DEBUG
                qDebug() << "Found ResolverAccount" << acct->accountFriendlyName();
#endif
                if ( AtticaResolverAccount* resolver = qobject_cast< AtticaResolverAccount* >( acct ) )
                {
#if ACCOUNTMODEL_DEBUG
                    qDebug() << "Which is an attica resolver with id:" << resolver->atticaId();
#endif
                    if ( resolver->atticaId() == content.id() )
                    {
                        allAccounts.removeAll( acct );
                    }
                }
            }
        }