|
1 /* This file is part of the KDE project. |
|
2 |
|
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
|
5 This library is free software: you can redistribute it and/or modify |
|
6 it under the terms of the GNU Lesser General Public License as published by |
|
7 the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 GNU Lesser General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Lesser General Public License |
|
15 along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
|
17 */ |
|
18 |
|
19 #include "mediaobject.h" |
|
20 |
|
21 #include "mmf_medianode.h" |
|
22 |
|
23 QT_BEGIN_NAMESPACE |
|
24 |
|
25 using namespace Phonon; |
|
26 using namespace Phonon::MMF; |
|
27 |
|
28 /*! \class MMF::MediaNode |
|
29 \internal |
|
30 */ |
|
31 |
|
32 MMF::MediaNode::MediaNode(QObject *parent) : QObject::QObject(parent) |
|
33 , m_source(0) |
|
34 , m_target(0) |
|
35 , m_isApplied(false) |
|
36 { |
|
37 } |
|
38 |
|
39 bool MMF::MediaNode::connectMediaNode(MediaNode *target) |
|
40 { |
|
41 m_target = target; |
|
42 m_target->setSource(this); |
|
43 |
|
44 return applyNodesOnMediaObject(target); |
|
45 } |
|
46 |
|
47 bool MMF::MediaNode::disconnectMediaNode(MediaNode *target) |
|
48 { |
|
49 Q_UNUSED(target); |
|
50 m_target = 0; |
|
51 m_isApplied = false; |
|
52 return true; |
|
53 } |
|
54 |
|
55 void MMF::MediaNode::setSource(MediaNode *source) |
|
56 { |
|
57 m_source = source; |
|
58 } |
|
59 |
|
60 MMF::MediaNode *MMF::MediaNode::source() const |
|
61 { |
|
62 return m_source; |
|
63 } |
|
64 |
|
65 MMF::MediaNode *MMF::MediaNode::target() const |
|
66 { |
|
67 return m_target; |
|
68 } |
|
69 |
|
70 bool MMF::MediaNode::applyNodesOnMediaObject(MediaNode *) |
|
71 { |
|
72 // Algorithmically, this can be expressed in a more efficient way by |
|
73 // exercising available assumptions, but it complicates code for input |
|
74 // data(length of the graph) which typically is very small. |
|
75 |
|
76 // First, we go to the very beginning of the graph. |
|
77 MMF::MediaNode *current = this; |
|
78 do { |
|
79 MediaNode *const candidate = current->source(); |
|
80 if (candidate) |
|
81 current = candidate; |
|
82 else |
|
83 break; |
|
84 } |
|
85 while (current); |
|
86 |
|
87 // Now we do two things, while walking to the other end: |
|
88 // 1. Find the MediaObject, if present |
|
89 // 2. Collect a list of all unapplied MediaNodes |
|
90 |
|
91 QList<MediaNode *> unapplied; |
|
92 MMF::MediaObject *mo = 0; |
|
93 |
|
94 do { |
|
95 if (!current->m_isApplied) |
|
96 unapplied.append(current); |
|
97 |
|
98 if (!mo) |
|
99 mo = qobject_cast<MMF::MediaObject *>(current); |
|
100 |
|
101 current = current->target(); |
|
102 } |
|
103 while (current); |
|
104 |
|
105 // Now, lets activate all the objects, if we found the MediaObject. |
|
106 |
|
107 if (mo) { |
|
108 for (int i = 0; i < unapplied.count(); ++i) { |
|
109 MediaNode *const at = unapplied.at(i); |
|
110 |
|
111 // We don't want to apply MediaObject on itself. |
|
112 if (at != mo) |
|
113 at->activateOnMediaObject(mo); |
|
114 } |
|
115 } |
|
116 |
|
117 return true; |
|
118 } |
|
119 |
|
120 QT_END_NAMESPACE |
|
121 |