~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/libtomahawk/utils/BinaryInstallerHelper.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2012 Leo Franchi <lfranchi@kde.org>
 
4
 *
 
5
 *   Tomahawk is free software: you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU General Public License as published by
 
7
 *   the Free Software Foundation, either version 3 of the License, or
 
8
 *   (at your option) any later version.
 
9
 *
 
10
 *   Tomahawk is distributed in the hope that it will be useful,
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
 *   GNU General Public License for more details.
 
14
 *
 
15
 *   You should have received a copy of the GNU General Public License
 
16
 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
#include "BinaryInstallerHelper.h"
 
20
 
 
21
#include "accounts/AccountManager.h"
 
22
#include "TomahawkSettingsGui.h"
 
23
#include <QTemporaryFile>
 
24
 
 
25
BinaryInstallerHelper::BinaryInstallerHelper( QTemporaryFile* tempFile, const QString& resolverId, bool createAccount, AtticaManager* manager )
 
26
    : QObject( manager )
 
27
    , m_tempFile( tempFile )
 
28
    , m_resolverId( resolverId )
 
29
    , m_createAccount( createAccount )
 
30
    , m_manager( QWeakPointer< AtticaManager >( manager ) )
 
31
{
 
32
    Q_ASSERT( m_tempFile );
 
33
    Q_ASSERT( !m_resolverId.isEmpty() );
 
34
    Q_ASSERT( !m_manager.isNull() );
 
35
 
 
36
    setProperty( "resolverid", m_resolverId );
 
37
}
 
38
 
 
39
 
 
40
BinaryInstallerHelper::~BinaryInstallerHelper()
 
41
{
 
42
    Q_ASSERT( m_tempFile );
 
43
    delete m_tempFile;
 
44
}
 
45
 
 
46
 
 
47
void
 
48
BinaryInstallerHelper::installSucceeded( const QString& path )
 
49
{
 
50
    qDebug() << Q_FUNC_INFO << "install of binary resolver succeeded, enabling: " << path;
 
51
 
 
52
    if ( m_manager.isNull() )
 
53
        return;
 
54
 
 
55
    if ( m_createAccount )
 
56
    {
 
57
        Tomahawk::Accounts::Account* acct = Tomahawk::Accounts::AccountManager::instance()->accountFromPath( path );
 
58
 
 
59
        Tomahawk::Accounts::AccountManager::instance()->addAccount( acct );
 
60
        TomahawkSettings::instance()->addAccount( acct->accountId() );
 
61
        Tomahawk::Accounts::AccountManager::instance()->enableAccount( acct );
 
62
    }
 
63
 
 
64
    m_manager.data()->m_resolverStates[ m_resolverId ].scriptPath = path;
 
65
    m_manager.data()->m_resolverStates[ m_resolverId ].state = AtticaManager::Installed;
 
66
 
 
67
    TomahawkSettingsGui::instanceGui()->setAtticaResolverStates( m_manager.data()->m_resolverStates );
 
68
    emit m_manager.data()->resolverInstalled( m_resolverId );
 
69
    emit m_manager.data()->resolverStateChanged( m_resolverId );
 
70
 
 
71
    deleteLater();
 
72
}
 
73
void BinaryInstallerHelper::installFailed()
 
74
{
 
75
    qDebug() << Q_FUNC_INFO << "install failed";
 
76
 
 
77
    if ( m_manager.isNull() )
 
78
        return;
 
79
 
 
80
    m_manager.data()->resolverInstallationFailed( m_resolverId );
 
81
 
 
82
    deleteLater();
 
83
}