File indexing completed on 2024-04-21 04:43:16

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
0003     Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). <thierry.bastian@trolltech.com>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Lesser General Public
0007     License as published by the Free Software Foundation; either
0008     version 2.1 of the License, or (at your option) version 3, or any
0009     later version accepted by the membership of KDE e.V. (or its
0010     successor approved by the membership of KDE e.V.), Nokia Corporation
0011     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0012     act as a proxy defined in Section 6 of version 3 of the license.
0013 
0014     This library is distributed in the hope that it will be useful,
0015     but WITHOUT ANY WARRANTY; without even the implied warranty of
0016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017     Lesser General Public License for more details.
0018 
0019     You should have received a copy of the GNU Lesser General Public 
0020     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 */
0023 
0024 #include "medianode.h"
0025 #include "medianode_p.h"
0026 #include "medianodedestructionhandler_p.h"
0027 #include "factory_p.h"
0028 
0029 namespace Phonon
0030 {
0031 
0032     MediaNode::MediaNode(MediaNodePrivate &dd)
0033         : k_ptr(&dd)
0034     {
0035         k_ptr->q_ptr = this;
0036     }
0037 
0038 bool MediaNode::isValid() const
0039 {
0040     return const_cast<MediaNodePrivate *>(k_ptr)->backendObject() != nullptr;
0041 }
0042 
0043     QList<Path> MediaNode::inputPaths() const
0044     {
0045         return k_ptr->inputPaths;
0046     }
0047 
0048     QList<Path> MediaNode::outputPaths() const
0049     {
0050         return k_ptr->outputPaths;
0051     }
0052 
0053     MediaNode::~MediaNode()
0054     {
0055         delete k_ptr;
0056     }
0057 
0058     QObject *MediaNodePrivate::backendObject()
0059     {
0060         if (!m_backendObject && Factory::backend()) {
0061             createBackendObject();
0062         }
0063         return m_backendObject;
0064     }
0065 
0066     MediaNodePrivate::~MediaNodePrivate()
0067     {
0068         for (int i = 0 ; i < handlers.count(); ++i) {
0069             handlers.at(i)->phononObjectDestroyed(this);
0070         }
0071         Factory::deregisterFrontendObject(this);
0072         delete m_backendObject;
0073         m_backendObject = nullptr;
0074     }
0075 
0076 void MediaNodePrivate::deleteBackendObject()
0077 {
0078     if (m_backendObject && aboutToDeleteBackendObject()) {
0079         delete m_backendObject;
0080         m_backendObject = nullptr;
0081     }
0082 }
0083 
0084     MediaNodePrivate::MediaNodePrivate(MediaNodePrivate::CastId _castId) : castId(_castId),
0085         m_backendObject(nullptr)
0086     {
0087         Factory::registerFrontendObject(this);
0088     }
0089 
0090     void MediaNodePrivate::addDestructionHandler(MediaNodeDestructionHandler *handler)
0091     {
0092         handlers.append(handler);
0093     }
0094 
0095     void MediaNodePrivate::removeDestructionHandler(MediaNodeDestructionHandler *handler)
0096     {
0097         handlers.removeAll(handler);
0098     }
0099 
0100     void MediaNodePrivate::addOutputPath(const Path &p)
0101     {
0102         outputPaths.append(p);
0103     }
0104 
0105     void MediaNodePrivate::addInputPath(const Path &p)
0106     {
0107         inputPaths.append(p);
0108     }
0109 
0110     void MediaNodePrivate::removeOutputPath(const Path &p)
0111     {
0112         int ret = outputPaths.removeAll(p);
0113         Q_ASSERT(ret == 1);
0114         Q_UNUSED(ret);
0115     }
0116     
0117     void MediaNodePrivate::removeInputPath(const Path &p)
0118     {
0119         int ret = inputPaths.removeAll(p);
0120         Q_ASSERT(ret == 1);
0121         Q_UNUSED(ret);
0122     }
0123 
0124 
0125 
0126 } // namespace Phonon