defuze.me
Client
|
00001 /************************************************************************** 00002 ** defuze.me Epitech Innovative Project 00003 ** 00004 ** Copyright 2010-2011 00005 ** Athena Calmettes - Jocelyn De La Rosa - Francois Gaillard 00006 ** Adrien Jarthon - Alexandre Moore - Luc Peres - Arnaud Sellier 00007 ** 00008 ** All rights reserved. 00009 **************************************************************************/ 00010 00011 #include "plugins.hpp" 00012 #include "exception.hpp" 00013 #include "logger.hpp" 00014 #include "playqueue.hpp" 00015 #include "library.hpp" 00016 #include "playlists.hpp" 00017 #include "listsplugin.hpp" 00018 #include "scheduler.hpp" 00019 #include "remotecontrol.hpp" 00020 #include "mainplayer.hpp" 00021 #include "servicesync.hpp" 00022 #include "audiomixerplugin.hpp" 00023 #include "status.hpp" 00024 #include "lastfmplugin.hpp" 00025 00026 Plugins::Plugins(Cores *c) : QObject(NULL), cores(*c) 00027 { 00028 add("player", new Player::MainPlayer("Player")); 00029 add("queue", new Queue::PlayQueue); 00030 add("mixer", new Mixer::AudioMixerPlugin); 00031 add("library", new Library::LibraryPlugin); 00032 add("playlists", new Playlists::PlaylistsPlugin); 00033 add("lists", new Lists::ListsPlugin); 00034 add("remote", new Remote::RemoteControl); 00035 add("web_service", new WebService::ServiceSync); 00036 add("status", new Notification::Status); 00037 add("scheduler", new Scheduler::SchedulerPlugin); 00038 add("lastfm", new Lastfm::LastfmPlugin); 00039 } 00040 00041 Plugins::~Plugins() 00042 { 00043 QHash<QString, Plugin*>::iterator it; 00044 for (it = plugins.begin(); it != plugins.end(); it++) 00045 { 00046 Logger::log(QString("Deleting plugin: %1").arg(it.key())); 00047 delete it.value(); 00048 } 00049 } 00050 00051 void Plugins::add(const QString& name, Plugin* plugin) 00052 { 00053 if (plugins.contains(name)) 00054 throw_exception(0x01, tr("2 plugins added with the same name: %1").arg(name)); 00055 plugins[name] = plugin; 00056 plugin->setReferences(cores, *this); 00057 } 00058 00059 Plugin* Plugins::get(const QString& name) 00060 { 00061 return plugins.value(name); 00062 } 00063 00064 void Plugins::init() 00065 { 00066 QHash<QString, Plugin*>::iterator it; 00067 for (it = plugins.begin(); it != plugins.end(); it++) 00068 { 00069 QString msg = QString("Initializing plugin: %1").arg(it.key()); 00070 Logger::log(msg); 00071 emit message(msg); 00072 it.value()->init(); 00073 } 00074 } 00075 00076 void Plugins::aboutToQuit() 00077 { 00078 QHash<QString, Plugin*>::iterator it; 00079 for (it = plugins.begin(); it != plugins.end(); it++) 00080 { 00081 Logger::log(QString("Exiting plugin: %1").arg(it.key())); 00082 it.value()->aboutToQuit(); 00083 } 00084 deleteLater(); 00085 }