File indexing completed on 2024-05-05 04:49:18

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
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 "DefaultApplicationController.h"
0018 
0019 #include "core/support/Components.h"
0020 #include "EngineController.h"
0021 
0022 #include "core-impl/collections/support/CollectionLocationDelegateImpl.h"
0023 
0024 #include <QMetaObject>
0025 
0026 using namespace Amarok;
0027 
0028 DefaultApplicationController::DefaultApplicationController( QObject *parent )
0029     : ApplicationController( parent )
0030 {
0031     //there can be only one applicationcontroller
0032     ApplicationController *oldController = Components::setApplicationController( this );
0033     Q_ASSERT( !oldController );
0034     Q_UNUSED( oldController );
0035 }
0036 
0037 DefaultApplicationController::~DefaultApplicationController()
0038 {
0039     Components::setApplicationController( nullptr );
0040 }
0041 
0042 void
0043 DefaultApplicationController::start()
0044 {
0045     //construct all central components
0046     initSqlStorage();
0047     initEngineController();
0048     initCollectionManager();
0049     initCollectionLocationDelegate();
0050 
0051 }
0052 
0053 void
0054 DefaultApplicationController::shutdown()
0055 {
0056     //destroy all central components instead of letting them be
0057     //destroyed in a random order as static objects
0058 
0059     delete Components::setEngineController( nullptr );
0060     delete Components::setCollectionLocationDelegate( nullptr );
0061 }
0062 
0063 void
0064 DefaultApplicationController::initSqlStorage()
0065 {
0066     //SqlStorage should really be moved out of SqlCollection and into a separate plugin that
0067     //can be loaded independently of the collection
0068 }
0069 
0070 void
0071 DefaultApplicationController::initEngineController()
0072 {
0073     EngineController *controller = new EngineController();
0074     Components::setEngineController( controller );
0075     bool invoked = QMetaObject::invokeMethod( controller, "initializePhonon", Qt::DirectConnection );
0076     Q_ASSERT( invoked );
0077     Q_UNUSED( invoked );
0078 }
0079 
0080 void
0081 DefaultApplicationController::initCollectionManager()
0082 {
0083 
0084 }
0085 
0086 void
0087 DefaultApplicationController::initCollectionLocationDelegate()
0088 {
0089     Components::setCollectionLocationDelegate( new Collections::CollectionLocationDelegateImpl() );
0090 }
0091