From e0177f692cfa9e6a28799bf3f322c3193fa5d5e6 Mon Sep 17 00:00:00 2001 From: nhnielsen Date: Sat, 24 Nov 2007 10:39:52 +0000 Subject: [PATCH] Add a ServicePluginManager class to handle loading of services, and bring the Magnatune store back online. the ServicePluginManager class is still a work in progress, and I just added it to MainWindow in very hacky way to get something running for now. git-svn-id: svn+ssh://svn.kde.org/home/kde/trunk/extragear/multimedia/amarok@740886 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/CMakeLists.txt | 1 + src/MainWindow.cpp | 9 ++- src/servicebrowser/ServicePluginManager.cpp | 75 ++++++++++++++++++++++ src/servicebrowser/ServicePluginManager.h | 51 +++++++++++++++ .../magnatunestore/MagnatuneStore.cpp | 2 +- 5 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 src/servicebrowser/ServicePluginManager.cpp create mode 100644 src/servicebrowser/ServicePluginManager.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5b00839e8..62ed0033f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,6 +103,7 @@ set(libplugin_SRCS set(libservicebrowser_SRCS servicebrowser/servicebrowser.cpp servicebrowser/servicebase.cpp + servicebrowser/ServicePluginManager.cpp servicebrowser/servicemetabase.cpp servicebrowser/servicecollection.cpp servicebrowser/servicesqlquerymaker.cpp diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 854a67eea..660cdef75 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -39,7 +39,8 @@ #include "progressslider.h" #include "scriptmanager.h" #include "searchwidget.h" -#include "servicebrowser/magnatunestore/MagnatuneStore.h" +#include "servicebrowser/ServicePluginManager.h" +//#include "servicebrowser/magnatunestore/MagnatuneStore.h" #include "servicebrowser/scriptableservice/scriptableservice.h" #include "servicebrowser/servicebrowser.h" #include "servicebrowser/jamendo/jamendoservice.h" @@ -261,6 +262,12 @@ void MainWindow::init() m_browsers->addWidget( KIcon( Amarok::icon( "magnatune" ) ), i18n("Internet"), internetContentServiceBrowser ); m_browserNames.append( "Internet" ); + + //create a plugin manager + + ServicePluginManager * servicePluginManager = new ServicePluginManager( internetContentServiceBrowser ); + servicePluginManager->init(); + debug() << "Add me dammit!!!!!"; internetContentServiceBrowser->setScriptableServiceManager( new ScriptableServiceManager( 0 ) ); diff --git a/src/servicebrowser/ServicePluginManager.cpp b/src/servicebrowser/ServicePluginManager.cpp new file mode 100644 index 000000000..c36daa86a --- /dev/null +++ b/src/servicebrowser/ServicePluginManager.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2007 Maximilian Kossick + * 2007 Nikolaj Hald Nielsen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "ServicePluginManager.h" +#include "pluginmanager.h" + +#include + +ServicePluginManager::ServicePluginManager( ServiceBrowser * browser ) + : QObject() + , m_serviceBrowser( browser ) +{ +} + + +ServicePluginManager::~ServicePluginManager() +{ +} + +void ServicePluginManager::init() +{ + + DEBUG_BLOCK + KService::List plugins = PluginManager::query( "[X-KDE-Amarok-plugintype] == 'service'" ); + debug() << "Received [" << QString::number( plugins.count() ) << "] collection plugin offers"; + foreach( KService::Ptr service, plugins ) + { + Amarok::Plugin *plugin = PluginManager::createFromService( service ); + if ( plugin ) + { + debug() << "Got hold of a valid plugin"; + ServiceFactory* factory = dynamic_cast( plugin ); + if ( factory ) + { + debug() << "Got hold of a valid factory"; + connect( factory, SIGNAL( newService( ServiceBase * ) ), this, SLOT( slotNewService( ServiceBase * ) ) ); + factory->init(); + } + else + { + debug() << "Plugin has wrong factory class"; + continue; + } + } else { + debug() << "bad plugin"; + continue; + } + } +} + +void ServicePluginManager::slotNewService(ServiceBase * newService) +{ + DEBUG_BLOCK + m_serviceBrowser->addService( newService ); +} + +#include "ServicePluginManager.moc" + + diff --git a/src/servicebrowser/ServicePluginManager.h b/src/servicebrowser/ServicePluginManager.h new file mode 100644 index 000000000..e8b754b2b --- /dev/null +++ b/src/servicebrowser/ServicePluginManager.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (c) 2007 Nikolaj Hald Nielsen * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef SERVICEPLUGINMANAGER_H +#define SERVICEPLUGINMANAGER_H + +#include "servicebase.h" +#include "servicebrowser.h" + +#include + +/** +A class to keep track of available service plugins and load them as needed + + @author +*/ +class ServicePluginManager : public QObject { + Q_OBJECT +public: + ServicePluginManager( ServiceBrowser * browser ); + + ~ServicePluginManager(); + + void init(); + +private: + + ServiceBrowser * m_serviceBrowser; + +private slots: + void slotNewService( ServiceBase *newService); + +}; + +#endif diff --git a/src/servicebrowser/magnatunestore/MagnatuneStore.cpp b/src/servicebrowser/magnatunestore/MagnatuneStore.cpp index 3b4cb1881..045f427fe 100644 --- a/src/servicebrowser/magnatunestore/MagnatuneStore.cpp +++ b/src/servicebrowser/magnatunestore/MagnatuneStore.cpp @@ -54,7 +54,7 @@ using namespace Meta; - +AMAROK_EXPORT_PLUGIN( MagnatuneServiceFactory ) void MagnatuneServiceFactory::init() { -- 2.11.4.GIT