1
/*  This file is part of the KDE project
2
    Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
3
    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). <thierry.bastian@trolltech.com>
4
5
    This library is free software; you can redistribute it and/or
6
    modify it under the terms of the GNU Lesser General Public
7
    License as published by the Free Software Foundation; either
8
    version 2.1 of the License, or (at your option) version 3, or any
9
    later version accepted by the membership of KDE e.V. (or its
10
    successor approved by the membership of KDE e.V.), Nokia Corporation
11
    (or its successors, if any) and the KDE Free Qt Foundation, which shall
12
    act as a proxy defined in Section 6 of version 3 of the license.
13
14
    This library is distributed in the hope that it will be useful,
15
    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
    Lesser General Public License for more details.
18
19
    You should have received a copy of the GNU Lesser General Public 
20
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
21
22
*/
23
24
#include "medianode.h"
25
#include "medianode_p.h"
26
#include "medianodedestructionhandler_p.h"
27
#include "factory_p.h"
28
29
QT_BEGIN_NAMESPACE
30
31
namespace Phonon
32
{
33
34
    MediaNode::MediaNode(MediaNodePrivate &dd)
35
        : k_ptr(&dd)
36
    {
37
        k_ptr->q_ptr = this;
38
    }
39
40
bool MediaNode::isValid() const
41
{
42
    return const_cast<MediaNodePrivate *>(k_ptr)->backendObject() != 0;
43
}
44
45
    QList<Path> MediaNode::inputPaths() const
46
    {
47
        return k_ptr->inputPaths;
48
    }
49
50
    QList<Path> MediaNode::outputPaths() const
51
    {
52
        return k_ptr->outputPaths;
53
    }
54
55
    MediaNode::~MediaNode()
56
    {
57
        delete k_ptr;
58
    }
59
60
    QObject *MediaNodePrivate::backendObject()
61
    {
62
        if (!m_backendObject && Factory::backend()) {
63
            createBackendObject();
64
        }
65
        return m_backendObject;
66
    }
67
68
    MediaNodePrivate::~MediaNodePrivate()
69
    {
70
        for (int i = 0 ; i < handlers.count(); ++i) {
71
            handlers.at(i)->phononObjectDestroyed(this);
72
        }
73
        Factory::deregisterFrontendObject(this);
74
        delete m_backendObject;
75
        m_backendObject = 0;
76
    }
77
78
void MediaNodePrivate::deleteBackendObject()
79
{
80
    if (m_backendObject && aboutToDeleteBackendObject()) {
81
        delete m_backendObject;
82
        m_backendObject = 0;
83
    }
84
}
85
86
    MediaNodePrivate::MediaNodePrivate(MediaNodePrivate::CastId _castId) : castId(_castId),
87
        m_backendObject(0)
88
    {
89
        Factory::registerFrontendObject(this);
90
    }
91
92
    void MediaNodePrivate::addDestructionHandler(MediaNodeDestructionHandler *handler)
93
    {
94
        handlers.append(handler);
95
    }
96
97
    void MediaNodePrivate::removeDestructionHandler(MediaNodeDestructionHandler *handler)
98
    {
99
        handlers.removeAll(handler);
100
    }
101
102
    void MediaNodePrivate::addOutputPath(const Path &p)
103
    {
104
        outputPaths.append(p);
105
    }
106
107
    void MediaNodePrivate::addInputPath(const Path &p)
108
    {
109
        inputPaths.append(p);
110
    }
111
112
    void MediaNodePrivate::removeOutputPath(const Path &p)
113
    {
114
        int ret = outputPaths.removeAll(p);
115
        Q_ASSERT(ret == 1);
116
        Q_UNUSED(ret);
117
    }
118
    
119
    void MediaNodePrivate::removeInputPath(const Path &p)
120
    {
121
        int ret = inputPaths.removeAll(p);
122
        Q_ASSERT(ret == 1);
123
        Q_UNUSED(ret);
124
    }
125
126
127
128
} // namespace Phonon
129
130
QT_END_NAMESPACE