File indexing completed on 2024-05-05 04:48:44

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org>                                        *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "PlaylistModelStack.h"
0018 
0019 #include "core/support/Debug.h"
0020 #include "PlaylistActions.h"
0021 #include "amarokconfig.h"
0022 
0023 
0024 namespace The
0025 {
0026     AMAROK_EXPORT Playlist::AbstractModel* playlist()
0027     {
0028         return Playlist::ModelStack::instance()->groupingProxy();
0029     }
0030 }
0031 
0032 namespace Playlist
0033 {
0034 
0035 ModelStack* ModelStack::s_instance = nullptr;
0036 
0037 ModelStack*
0038 ModelStack::instance()
0039 {
0040     if( s_instance == nullptr )
0041         s_instance = new ModelStack();
0042     return s_instance;
0043 }
0044 
0045 void
0046 ModelStack::destroy()
0047 {
0048     if( s_instance )
0049     {
0050         delete s_instance;
0051         s_instance = nullptr;
0052     }
0053 }
0054 
0055 ModelStack::ModelStack()
0056     : QObject()
0057 {
0058     DEBUG_BLOCK
0059     m_model = new Model( this );
0060     m_sortfilter = new SortFilterProxy( m_model, this );
0061     m_search = new SearchProxy( m_sortfilter, this );
0062     m_grouping = new GroupingProxy( m_search, this );
0063 }
0064 
0065 ModelStack::~ModelStack()
0066 {
0067     delete m_grouping;
0068     delete m_search;
0069     delete m_sortfilter;
0070     delete m_model;
0071 }
0072 
0073 GroupingProxy *
0074 ModelStack::groupingProxy()
0075 {
0076     return m_grouping;
0077 }
0078 
0079 SortFilterProxy *
0080 ModelStack::sortProxy()
0081 {
0082     return m_sortfilter;
0083 }
0084 
0085 SortFilterProxy *
0086 ModelStack::filterProxy()
0087 {
0088     return m_sortfilter;
0089 }
0090 
0091 Playlist::Model *
0092 ModelStack::bottom()
0093 {
0094     return m_model;
0095 }
0096 
0097 }   //namespace Playlist